worker_list_example.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #include <sys/time.h>
  19. #define FPRINTF(ofile, fmt, ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ## __VA_ARGS__); }} while(0)
  20. int main()
  21. {
  22. starpu_init(NULL);
  23. int procs[STARPU_NMAXWORKERS];
  24. unsigned ncpus = starpu_cpu_worker_get_count();
  25. starpu_worker_get_ids_by_type(STARPU_CPU_WORKER, procs, ncpus);
  26. struct starpu_worker_collection *co = (struct starpu_worker_collection*)malloc(sizeof(struct starpu_worker_collection));
  27. co->has_next = worker_list.has_next;
  28. co->get_next = worker_list.get_next;
  29. co->add = worker_list.add;
  30. co->remove = worker_list.remove;
  31. co->init = worker_list.init;
  32. co->deinit = worker_list.deinit;
  33. co->init_iterator = worker_list.init_iterator;
  34. co->type = STARPU_WORKER_LIST;
  35. FPRINTF(stderr, "ncpus %d \n", ncpus);
  36. double start_time;
  37. double end_time;
  38. start_time = starpu_timing_now();
  39. co->init(co);
  40. end_time = starpu_timing_now();
  41. double timing = (end_time - start_time) / 1000;
  42. int i;
  43. for(i = 0; i < ncpus; i++)
  44. {
  45. int added = co->add(co, procs[i]);
  46. FPRINTF(stderr, "added proc %d to the tree \n", added);
  47. }
  48. struct starpu_sched_ctx_iterator it;
  49. if(co->init_iterator)
  50. co->init_iterator(co, &it);
  51. int pu;
  52. while(co->has_next(co, &it))
  53. {
  54. pu = co->get_next(co, &it);
  55. FPRINTF(stderr, "pu = %d out of %d workers \n", pu, co->nworkers);
  56. }
  57. for(i = 0; i < 6; i++)
  58. {
  59. co->remove(co, i);
  60. FPRINTF(stderr, "remove %d out of %d workers\n", i, co->nworkers);
  61. }
  62. while(co->has_next(co, &it))
  63. {
  64. pu = co->get_next(co, &it);
  65. FPRINTF(stderr, "pu = %d out of %d workers \n", pu, co->nworkers);
  66. }
  67. FPRINTF(stderr, "timing init = %lf \n", timing);
  68. co->deinit(co);
  69. free(co);
  70. starpu_shutdown();
  71. return 0;
  72. }