worker_list_example.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2014 Université de Bordeaux
  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. unsigned 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. int pu;
  53. co->init_iterator(co, &it);
  54. while(co->has_next(co, &it))
  55. {
  56. pu = co->get_next(co, &it);
  57. FPRINTF(stderr, "pu = %d out of %d workers \n", pu, co->nworkers);
  58. }
  59. for(i = 0; i < 6; i++)
  60. {
  61. co->remove(co, i);
  62. FPRINTF(stderr, "remove %d out of %d workers\n", i, co->nworkers);
  63. }
  64. while(co->has_next(co, &it))
  65. {
  66. pu = co->get_next(co, &it);
  67. FPRINTF(stderr, "pu = %d out of %d workers \n", pu, co->nworkers);
  68. }
  69. FPRINTF(stderr, "timing init = %lf \n", timing);
  70. co->deinit(co);
  71. free(co);
  72. starpu_shutdown();
  73. return 0;
  74. }