testCommute.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2015 INRIA
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. /*
  17. * for i from 0 to nbA
  18. * insert task handles[i] in STARPU_RW|STARPU_COMMUTE
  19. * for j from 0 to nbA
  20. * if i != j
  21. insert task handles[i] in STARPU_RW|STARPU_COMMUTE, and handles[j] in STARPU_RW|STARPU_COMMUTE
  22. */
  23. // @FUSE_STARPU
  24. #ifdef STARPU_QUICK_CHECK
  25. #define SLEEP_SLOW 6000
  26. #define SLEEP_FAST 1000
  27. #else
  28. #define SLEEP_SLOW 600000
  29. #define SLEEP_FAST 100000
  30. #endif
  31. #include <starpu.h>
  32. #include "../helper.h"
  33. #include <vector>
  34. #include <unistd.h>
  35. void callback(void * /*buffers*/[], void * /*cl_arg*/)
  36. {
  37. usleep(SLEEP_FAST);
  38. FPRINTF(stdout,"COMMUTE_LOG] callback\n"); fflush(stdout);
  39. }
  40. void callback_slow(void * /*buffers*/[], void * /*cl_arg*/)
  41. {
  42. usleep(SLEEP_SLOW);
  43. FPRINTF(stdout,"COMMUTE_LOG] callback_slow\n"); fflush(stdout);
  44. }
  45. int main(int /*argc*/, char** /*argv*/)
  46. {
  47. unsigned ret;
  48. struct starpu_conf conf;
  49. ret = starpu_conf_init(&conf);
  50. STARPU_ASSERT(ret == 0);
  51. //conf.ncpus = 1;//// 4
  52. ret = starpu_init(&conf);
  53. STARPU_ASSERT(ret == 0);
  54. FPRINTF(stdout, "Max Thread %d\n", starpu_worker_get_count());
  55. //////////////////////////////////////////////////////
  56. starpu_codelet normalCodelete;
  57. {
  58. memset(&normalCodelete, 0, sizeof(normalCodelete));
  59. normalCodelete.where = STARPU_CPU;
  60. normalCodelete.cpu_funcs[0] = callback;
  61. normalCodelete.nbuffers = 2;
  62. normalCodelete.modes[0] = starpu_data_access_mode(STARPU_RW|STARPU_COMMUTE);
  63. normalCodelete.modes[1] = starpu_data_access_mode(STARPU_RW|STARPU_COMMUTE);
  64. normalCodelete.name = "normalCodelete";
  65. }
  66. starpu_codelet slowCodelete;
  67. {
  68. memset(&slowCodelete, 0, sizeof(slowCodelete));
  69. slowCodelete.where = STARPU_CPU;
  70. slowCodelete.cpu_funcs[0] = callback_slow;
  71. slowCodelete.nbuffers = 1;
  72. slowCodelete.modes[0] = starpu_data_access_mode (STARPU_RW|STARPU_COMMUTE);
  73. slowCodelete.name = "slowCodelete";
  74. }
  75. //////////////////////////////////////////////////////
  76. //////////////////////////////////////////////////////
  77. ///const int nbA = 3;
  78. const int nbA = 10;
  79. FPRINTF(stdout, "Nb A = %d\n", nbA);
  80. std::vector<starpu_data_handle_t> handleA(nbA);
  81. std::vector<int> dataA(nbA);
  82. for(int idx = 0 ; idx < nbA ; ++idx)
  83. {
  84. dataA[idx] = idx;
  85. }
  86. for(int idxHandle = 0 ; idxHandle < nbA ; ++idxHandle)
  87. {
  88. starpu_variable_data_register(&handleA[idxHandle], 0, (uintptr_t)&dataA[idxHandle], sizeof(dataA[idxHandle]));
  89. }
  90. //////////////////////////////////////////////////////
  91. //////////////////////////////////////////////////////
  92. FPRINTF(stdout,"Submit tasks\n");
  93. for(int idxHandleA1 = 0 ; idxHandleA1 < nbA ; ++idxHandleA1)
  94. {
  95. starpu_insert_task(&slowCodelete,
  96. (STARPU_RW|STARPU_COMMUTE), handleA[idxHandleA1],
  97. 0);
  98. for(int idxHandleA2 = 0 ; idxHandleA2 < nbA ; ++idxHandleA2)
  99. {
  100. if(idxHandleA1 != idxHandleA2)
  101. {
  102. starpu_insert_task(&normalCodelete,
  103. (STARPU_RW|STARPU_COMMUTE), handleA[idxHandleA1],
  104. (STARPU_RW|STARPU_COMMUTE), handleA[idxHandleA2],
  105. 0);
  106. }
  107. }
  108. }
  109. //////////////////////////////////////////////////////
  110. FPRINTF(stdout,"Wait task\n");
  111. starpu_task_wait_for_all();
  112. //////////////////////////////////////////////////////
  113. FPRINTF(stdout,"Release data\n");
  114. for(int idxHandle = 0 ; idxHandle < nbA ; ++idxHandle)
  115. {
  116. starpu_data_unregister(handleA[idxHandle]);
  117. }
  118. //////////////////////////////////////////////////////
  119. FPRINTF(stdout,"Shutdown\n");
  120. starpu_shutdown();
  121. return 0;
  122. }