worker_list_example.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2014 Université de Bordeaux 1
  4. * Copyright (C) 2010-2014 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. #define FPRINTF(ofile, fmt, ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ## __VA_ARGS__); }} while(0)
  19. int main()
  20. {
  21. int ret;
  22. ret = starpu_init(NULL);
  23. if (ret == -ENODEV)
  24. return 77;
  25. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  26. int procs[STARPU_NMAXWORKERS];
  27. unsigned ncpus = starpu_cpu_worker_get_count();
  28. starpu_worker_get_ids_by_type(STARPU_CPU_WORKER, procs, ncpus);
  29. struct starpu_worker_collection *co = (struct starpu_worker_collection*)malloc(sizeof(struct starpu_worker_collection));
  30. co->has_next = worker_list.has_next;
  31. co->get_next = worker_list.get_next;
  32. co->add = worker_list.add;
  33. co->remove = worker_list.remove;
  34. co->init = worker_list.init;
  35. co->deinit = worker_list.deinit;
  36. co->init_iterator = worker_list.init_iterator;
  37. co->type = STARPU_WORKER_LIST;
  38. FPRINTF(stderr, "ncpus %d \n", ncpus);
  39. double start_time;
  40. double end_time;
  41. start_time = starpu_timing_now();
  42. co->init(co);
  43. end_time = starpu_timing_now();
  44. double timing = (end_time - start_time) / 1000;
  45. int i;
  46. for(i = 0; i < ncpus; i++)
  47. {
  48. int added = co->add(co, procs[i]);
  49. FPRINTF(stderr, "added proc %d to the tree \n", added);
  50. }
  51. struct starpu_sched_ctx_iterator it;
  52. if(co->init_iterator)
  53. co->init_iterator(co, &it);
  54. int pu;
  55. while(co->has_next(co, &it))
  56. {
  57. pu = co->get_next(co, &it);
  58. FPRINTF(stderr, "pu = %d out of %d workers \n", pu, co->nworkers);
  59. }
  60. for(i = 0; i < 6; i++)
  61. {
  62. co->remove(co, i);
  63. FPRINTF(stderr, "remove %d out of %d workers\n", i, co->nworkers);
  64. }
  65. while(co->has_next(co, &it))
  66. {
  67. pu = co->get_next(co, &it);
  68. FPRINTF(stderr, "pu = %d out of %d workers \n", pu, co->nworkers);
  69. }
  70. FPRINTF(stderr, "timing init = %lf \n", timing);
  71. co->deinit(co);
  72. free(co);
  73. starpu_shutdown();
  74. return 0;
  75. }