implicit-stencil-tasks.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2013-2015 Université de Bordeaux
  4. * Copyright (C) 2012, 2013, 2015, 2016 CNRS
  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 "implicit-stencil.h"
  18. #define BIND_LAST 1
  19. /*
  20. * Schedule tasks for updates and saves
  21. */
  22. /*
  23. * NB: iter = 0: initialization phase, TAG_U(z, 0) = TAG_INIT
  24. *
  25. * dir is -1 or +1.
  26. */
  27. #if 0
  28. # define DEBUG(fmt, ...) fprintf(stderr,fmt,##__VA_ARGS__)
  29. #else
  30. # define DEBUG(fmt, ...)
  31. #endif
  32. #if defined(STARPU_USE_MPI) && !defined(STARPU_USE_MPI_MASTER_SLAVE)
  33. #include <starpu_mpi.h>
  34. #define starpu_insert_task(...) starpu_mpi_insert_task(MPI_COMM_WORLD, __VA_ARGS__)
  35. #endif
  36. /*
  37. * Schedule initialization tasks
  38. */
  39. void create_task_memset(unsigned sizex, unsigned sizey, unsigned z)
  40. {
  41. struct block_description *descr = get_block_description(z);
  42. struct starpu_codelet *codelet = &cl_memset;
  43. int ret = starpu_insert_task(
  44. codelet,
  45. STARPU_VALUE, &sizex, sizeof(unsigned),
  46. STARPU_VALUE, &sizey, sizeof(unsigned),
  47. STARPU_VALUE, &z, sizeof(unsigned),
  48. STARPU_W, descr->layers_handle[0],
  49. STARPU_W, descr->layers_handle[1],
  50. STARPU_W, descr->boundaries_handle[T][0],
  51. STARPU_W, descr->boundaries_handle[T][1],
  52. STARPU_W, descr->boundaries_handle[B][0],
  53. STARPU_W, descr->boundaries_handle[B][1],
  54. 0);
  55. if (ret)
  56. {
  57. FPRINTF(stderr, "Could not submit task save: %d\n", ret);
  58. if (ret == -ENODEV)
  59. exit(77);
  60. STARPU_ABORT();
  61. }
  62. }
  63. void create_task_initlayer(unsigned sizex, unsigned sizey, unsigned z)
  64. {
  65. struct block_description *descr = get_block_description(z);
  66. struct starpu_codelet *codelet = &cl_initlayer;
  67. int ret = starpu_insert_task(
  68. codelet,
  69. STARPU_VALUE, &sizex, sizeof(unsigned),
  70. STARPU_VALUE, &sizey, sizeof(unsigned),
  71. STARPU_VALUE, &z, sizeof(unsigned),
  72. STARPU_W, descr->layers_handle[0],
  73. 0);
  74. if (ret)
  75. {
  76. FPRINTF(stderr, "Could not submit task save: %d\n", ret);
  77. if (ret == -ENODEV)
  78. exit(77);
  79. STARPU_ABORT();
  80. }
  81. }
  82. /*
  83. * Schedule saving boundaries of blocks to communication buffers
  84. */
  85. static void create_task_save_local(unsigned iter, unsigned z, int dir, int local_rank)
  86. {
  87. struct block_description *descr = get_block_description(z);
  88. struct starpu_codelet *codelet;
  89. int ret;
  90. codelet = (dir == -1)?&save_cl_bottom:&save_cl_top;
  91. ret = starpu_insert_task(
  92. codelet,
  93. STARPU_VALUE, &z, sizeof(unsigned),
  94. STARPU_R, descr->layers_handle[0],
  95. STARPU_R, descr->layers_handle[1],
  96. STARPU_W, descr->boundaries_handle[(1-dir)/2][0],
  97. STARPU_W, descr->boundaries_handle[(1-dir)/2][1],
  98. STARPU_PRIORITY, STARPU_MAX_PRIO,
  99. 0);
  100. if (ret)
  101. {
  102. FPRINTF(stderr, "Could not submit task save: %d\n", ret);
  103. if (ret == -ENODEV)
  104. exit(77);
  105. STARPU_ABORT();
  106. }
  107. }
  108. /*
  109. * Schedule update computation in computation buffer
  110. */
  111. void create_task_update(unsigned iter, unsigned z, int local_rank)
  112. {
  113. STARPU_ASSERT(iter != 0);
  114. unsigned old_layer = (K*(iter-1)) % 2;
  115. unsigned new_layer = (old_layer + 1) % 2;
  116. struct block_description *descr = get_block_description(z);
  117. struct block_description *bottom_neighbour = descr->boundary_blocks[B];
  118. struct block_description *top_neighbour = descr->boundary_blocks[T];
  119. struct starpu_codelet *codelet = &cl_update;
  120. // Simple-level prio
  121. //int prio = ((bottom_neighbour->mpi_node != local_rank) || (top_neighbour->mpi_node != local_rank )) ? STARPU_MAX_PRIO : STARPU_DEFAULT_PRIO;
  122. // Two-level prio
  123. int prio = ((bottom_neighbour->mpi_node != local_rank) || (top_neighbour->mpi_node != local_rank )) ? STARPU_MAX_PRIO :
  124. ((bottom_neighbour->boundary_blocks[B]->mpi_node != local_rank) || (top_neighbour->boundary_blocks[T]->mpi_node != local_rank )) ? STARPU_MAX_PRIO-1 : STARPU_DEFAULT_PRIO;
  125. int ret = starpu_insert_task(
  126. codelet,
  127. STARPU_VALUE, &z, sizeof(unsigned),
  128. STARPU_RW, descr->layers_handle[old_layer],
  129. STARPU_RW, descr->layers_handle[new_layer],
  130. STARPU_R, bottom_neighbour->boundaries_handle[T][old_layer],
  131. STARPU_R, bottom_neighbour->boundaries_handle[T][new_layer],
  132. STARPU_R, top_neighbour->boundaries_handle[B][old_layer],
  133. STARPU_R, top_neighbour->boundaries_handle[B][new_layer],
  134. STARPU_PRIORITY, prio,
  135. 0);
  136. if (ret)
  137. {
  138. FPRINTF(stderr, "Could not submit task update block: %d\n", ret);
  139. if (ret == -ENODEV)
  140. exit(77);
  141. STARPU_ABORT();
  142. }
  143. }
  144. /*
  145. * Create all the tasks
  146. */
  147. void create_tasks(int rank)
  148. {
  149. int iter;
  150. int bz;
  151. int niter = get_niter();
  152. int nbz = get_nbz();
  153. for (iter = 0; iter <= niter; iter++)
  154. {
  155. for (bz = 0; bz < nbz; bz++)
  156. {
  157. if ((iter > 0) && ((get_block_mpi_node(bz) == rank)|| (get_block_mpi_node(bz+1) == rank)|| (get_block_mpi_node(bz-1) == rank)))
  158. create_task_update(iter, bz, rank);
  159. }
  160. for (bz = 0; bz < nbz; bz++)
  161. {
  162. if (iter != niter)
  163. {
  164. int node_z = get_block_mpi_node(bz);
  165. int node_z_and_b = get_block_mpi_node(bz-1);
  166. int node_z_and_t = get_block_mpi_node(bz+1);
  167. if ((node_z == rank) || ((node_z != node_z_and_b) && (node_z_and_b == rank)))
  168. create_task_save_local(iter, bz, +1, rank);
  169. if ((node_z == rank) || ((node_z != node_z_and_t) && (node_z_and_t == rank)))
  170. create_task_save_local(iter, bz, -1, rank);
  171. }
  172. }
  173. }
  174. }