worker_tree_example.c 2.8 KB

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