worker_list_example.c 2.4 KB

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