worker_tree_example.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #if !defined(STARPU_HAVE_HWLOC)
  20. #warning hwloc is not enabled. Skipping test
  21. int main(int argc, char **argv)
  22. {
  23. return 77;
  24. }
  25. #else
  26. int main()
  27. {
  28. int ret;
  29. ret = starpu_init(NULL);
  30. if (ret == -ENODEV)
  31. return 77;
  32. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  33. int procs[STARPU_NMAXWORKERS];
  34. unsigned ncpus = starpu_cpu_worker_get_count();
  35. starpu_worker_get_ids_by_type(STARPU_CPU_WORKER, procs, ncpus);
  36. struct starpu_worker_collection *co = (struct starpu_worker_collection*)malloc(sizeof(struct starpu_worker_collection));
  37. co->has_next = worker_tree.has_next;
  38. co->get_next = worker_tree.get_next;
  39. co->add = worker_tree.add;
  40. co->remove = worker_tree.remove;
  41. co->init = worker_tree.init;
  42. co->deinit = worker_tree.deinit;
  43. co->init_iterator = worker_tree.init_iterator;
  44. co->type = STARPU_WORKER_TREE;
  45. FPRINTF(stderr, "ncpus %d \n", ncpus);
  46. double start_time;
  47. double end_time;
  48. start_time = starpu_timing_now();
  49. co->init(co);
  50. end_time = starpu_timing_now();
  51. double timing = (end_time - start_time) / 1000;
  52. int i;
  53. for(i = 0; i < ncpus; i++)
  54. {
  55. int added = co->add(co, procs[i]);
  56. // FPRINTF(stderr, "added proc %d to the tree \n", added);
  57. }
  58. struct starpu_sched_ctx_iterator it;
  59. if(co->init_iterator)
  60. co->init_iterator(co, &it);
  61. int pu;
  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. for(i = 0; i < 6; i++)
  68. {
  69. co->remove(co, i);
  70. // FPRINTF(stderr, "remove %d out of %d workers\n", i, co->nworkers);
  71. }
  72. while(co->has_next(co, &it))
  73. {
  74. pu = co->get_next(co, &it);
  75. // FPRINTF(stderr, "pu = %d out of %d workers \n", pu, co->nworkers);
  76. }
  77. FPRINTF(stderr, "timing init = %lf \n", timing);
  78. co->deinit(co);
  79. starpu_shutdown();
  80. return 0;
  81. }
  82. #endif