worker_tree_example.c 2.5 KB

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