implicit-stencil-tasks.c 6.0 KB

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