starpu_mpi.c 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010-2013 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012, 2013 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 <stdlib.h>
  18. #include <starpu_mpi.h>
  19. #include <starpu_mpi_datatype.h>
  20. #include <starpu_mpi_private.h>
  21. #include <starpu_profiling.h>
  22. #include <starpu_mpi_stats.h>
  23. #include <starpu_mpi_insert_task.h>
  24. #include <common/config.h>
  25. #include <common/thread.h>
  26. static void _starpu_mpi_submit_new_mpi_request(void *arg);
  27. static void _starpu_mpi_handle_request_termination(struct _starpu_mpi_req *req);
  28. #ifdef STARPU_VERBOSE
  29. static char *_starpu_mpi_request_type(enum _starpu_mpi_request_type request_type);
  30. #endif
  31. static struct _starpu_mpi_req *_starpu_mpi_isend_common(starpu_data_handle_t data_handle,
  32. int dest, int mpi_tag, MPI_Comm comm,
  33. unsigned detached, void (*callback)(void *), void *arg,
  34. int sequential_consistency);
  35. static struct _starpu_mpi_req *_starpu_mpi_irecv_common(starpu_data_handle_t data_handle,
  36. int source, int mpi_tag, MPI_Comm comm,
  37. unsigned detached, void (*callback)(void *), void *arg,
  38. int sequential_consistency, int is_internal_req,
  39. ssize_t count);
  40. static void _starpu_mpi_handle_detached_request(struct _starpu_mpi_req *req);
  41. /* The list of requests that have been newly submitted by the application */
  42. static struct _starpu_mpi_req_list *new_requests;
  43. /* The list of detached requests that have already been submitted to MPI */
  44. static struct _starpu_mpi_req_list *detached_requests;
  45. static starpu_pthread_mutex_t detached_requests_mutex;
  46. /* Condition to wake up progression thread */
  47. static starpu_pthread_cond_t cond_progression;
  48. /* Condition to wake up waiting for all current MPI requests to finish */
  49. static starpu_pthread_cond_t cond_finished;
  50. static starpu_pthread_mutex_t mutex;
  51. static starpu_pthread_t progress_thread;
  52. static int running = 0;
  53. /* Count requests posted by the application and not yet submitted to MPI, i.e pushed into the new_requests list */
  54. static starpu_pthread_mutex_t mutex_posted_requests;
  55. static int posted_requests = 0, newer_requests, barrier_running = 0;
  56. #define _STARPU_MPI_INC_POSTED_REQUESTS(value) { STARPU_PTHREAD_MUTEX_LOCK(&mutex_posted_requests); posted_requests += value; STARPU_PTHREAD_MUTEX_UNLOCK(&mutex_posted_requests); }
  57. struct _starpu_mpi_copy_handle
  58. {
  59. starpu_data_handle_t handle;
  60. struct _starpu_mpi_envelope *env;
  61. int mpi_tag;
  62. int source;
  63. UT_hash_handle hh;
  64. struct _starpu_mpi_req *req;
  65. void *buffer;
  66. };
  67. /********************************************************/
  68. /* */
  69. /* Hashmap's requests functionalities */
  70. /* */
  71. /********************************************************/
  72. /** stores application requests for which data have not been received yet */
  73. static struct _starpu_mpi_req **_starpu_mpi_app_req_hashmap = NULL;
  74. static int _starpu_mpi_app_req_hashmap_count = 0;
  75. /** stores data which have been received by MPI but have not been requested by the application */
  76. static struct _starpu_mpi_copy_handle **_starpu_mpi_copy_handle_hashmap = NULL;
  77. static int _starpu_mpi_copy_handle_hashmap_count = 0;
  78. static struct _starpu_mpi_req* find_app_req(int mpi_tag, int source)
  79. {
  80. struct _starpu_mpi_req* req;
  81. HASH_FIND_INT(_starpu_mpi_app_req_hashmap[source], &mpi_tag, req);
  82. return req;
  83. }
  84. static void add_app_req(struct _starpu_mpi_req *req)
  85. {
  86. struct _starpu_mpi_req *test_req;
  87. test_req = find_app_req(req->mpi_tag, req->srcdst);
  88. if (test_req == NULL)
  89. {
  90. HASH_ADD_INT(_starpu_mpi_app_req_hashmap[req->srcdst], mpi_tag, req);
  91. _starpu_mpi_app_req_hashmap_count ++;
  92. _STARPU_MPI_DEBUG(3, "Adding request %p with tag %d in the application request hashmap[%d]\n", req, req->mpi_tag, req->srcdst);
  93. }
  94. else
  95. {
  96. _STARPU_MPI_DEBUG(3, "[Error] request %p with tag %d already in the application request hashmap[%d]\n", req, req->mpi_tag, req->srcdst);
  97. int seq_const = starpu_data_get_sequential_consistency_flag(req->data_handle);
  98. if (seq_const && req->sequential_consistency)
  99. {
  100. STARPU_ASSERT_MSG(!test_req, "[Error] request %p with tag %d wanted to be added to the application request hashmap[%d], while another request %p with the same tag is already in it. \n Sequential consistency is activated : this is not supported by StarPU.", req, req->mpi_tag, req->srcdst, test_req);
  101. }
  102. else
  103. {
  104. STARPU_ASSERT_MSG(!test_req, "[Error] request %p with tag %d wanted to be added to the application request hashmap[%d], while another request %p with the same tag is already in it. \n Sequential consistency isn't activated for this handle : you should want to add dependencies between requests for which the sequential consistency is deactivated.", req, req->mpi_tag, req->srcdst, test_req);
  105. }
  106. }
  107. }
  108. static void delete_app_req(struct _starpu_mpi_req *req)
  109. {
  110. struct _starpu_mpi_req *test_req;
  111. test_req = find_app_req(req->mpi_tag, req->srcdst);
  112. if (test_req != NULL)
  113. {
  114. HASH_DEL(_starpu_mpi_app_req_hashmap[req->srcdst], req);
  115. _starpu_mpi_app_req_hashmap_count --;
  116. _STARPU_MPI_DEBUG(3, "Deleting application request %p with tag %d from the application request hashmap[%d]\n", req, req->mpi_tag, req->srcdst);
  117. }
  118. else
  119. {
  120. _STARPU_MPI_DEBUG(3, "[Warning] request %p with tag %d is NOT in the application request hashmap[%d]\n", req, req->mpi_tag, req->srcdst);
  121. }
  122. }
  123. static struct _starpu_mpi_copy_handle* find_chandle(int mpi_tag, int source)
  124. {
  125. struct _starpu_mpi_copy_handle* chandle;
  126. _STARPU_MPI_DEBUG(60, "Looking for chandle with tag %d in the hashmap[%d]\n", mpi_tag, source);
  127. HASH_FIND_INT(_starpu_mpi_copy_handle_hashmap[source], &mpi_tag, chandle);
  128. return chandle;
  129. }
  130. static void add_chandle(struct _starpu_mpi_copy_handle *chandle)
  131. {
  132. _STARPU_MPI_DEBUG(60, "Trying to add chandle %p with tag %d in the hashmap[%d]\n", chandle, chandle->mpi_tag, chandle->source);
  133. STARPU_ASSERT_MSG(find_chandle(chandle->mpi_tag, chandle->source) == NULL,
  134. "Error add_chandle : chandle %p with tag %d already in the hashmap[%d]\n", chandle, chandle->mpi_tag, chandle->source);
  135. HASH_ADD_INT(_starpu_mpi_copy_handle_hashmap[chandle->source], mpi_tag, chandle);
  136. _starpu_mpi_copy_handle_hashmap_count ++;
  137. }
  138. static void delete_chandle(struct _starpu_mpi_copy_handle *chandle)
  139. {
  140. struct _starpu_mpi_copy_handle *test_chandle;
  141. _STARPU_MPI_DEBUG(60, "Trying to delete chandle %p with tag %d in the hashmap[%d]\n", chandle, chandle->mpi_tag, chandle->source);
  142. STARPU_ASSERT_MSG(find_chandle(chandle->mpi_tag, chandle->source) != NULL,
  143. "Error delete_chandle : chandle %p with tag %d is NOT in the hashmap[%d]\n", chandle, chandle->mpi_tag, chandle->source);
  144. HASH_DEL(_starpu_mpi_copy_handle_hashmap[chandle->source], chandle);
  145. _starpu_mpi_copy_handle_hashmap_count --;
  146. }
  147. static void _starpu_mpi_request_init(struct _starpu_mpi_req *req)
  148. {
  149. /* Initialize the request structure */
  150. req->data_handle = NULL;
  151. req->datatype = NULL;
  152. req->ptr = NULL;
  153. req->count = -1;
  154. req->user_datatype = -1;
  155. req->srcdst = -1;
  156. req->mpi_tag = -1;
  157. req->comm = 0;
  158. req->func = NULL;
  159. req->status = NULL;
  160. req->request = NULL;
  161. req->flag = NULL;
  162. req->ret = -1;
  163. STARPU_PTHREAD_MUTEX_INIT(&req->req_mutex, NULL);
  164. STARPU_PTHREAD_COND_INIT(&req->req_cond, NULL);
  165. STARPU_PTHREAD_MUTEX_INIT(&req->posted_mutex, NULL);
  166. STARPU_PTHREAD_COND_INIT(&req->posted_cond, NULL);
  167. req->request_type = UNKNOWN_REQ;
  168. req->submitted = 0;
  169. req->completed = 0;
  170. req->posted = 0;
  171. req->other_request = NULL;
  172. req->detached = -1;
  173. req->callback = NULL;
  174. req->callback_arg = NULL;
  175. req->size_req = NULL;
  176. req->internal_req = NULL;
  177. req->is_internal_req = 0;
  178. req->envelope = NULL;
  179. req->sequential_consistency = 1;
  180. }
  181. /********************************************************/
  182. /* */
  183. /* Send/Receive functionalities */
  184. /* */
  185. /********************************************************/
  186. static struct _starpu_mpi_req *_starpu_mpi_isend_irecv_common(starpu_data_handle_t data_handle,
  187. int srcdst, int mpi_tag, MPI_Comm comm,
  188. unsigned detached, void (*callback)(void *), void *arg,
  189. enum _starpu_mpi_request_type request_type, void (*func)(struct _starpu_mpi_req *),
  190. enum starpu_data_access_mode mode,
  191. int sequential_consistency,
  192. int is_internal_req,
  193. ssize_t count)
  194. {
  195. _STARPU_MPI_LOG_IN();
  196. struct _starpu_mpi_req *req = malloc(sizeof(struct _starpu_mpi_req));
  197. STARPU_ASSERT_MSG(req, "Invalid request");
  198. _STARPU_MPI_INC_POSTED_REQUESTS(1);
  199. /* Initialize the request structure */
  200. _starpu_mpi_request_init(req);
  201. req->request_type = request_type;
  202. req->data_handle = data_handle;
  203. req->srcdst = srcdst;
  204. req->mpi_tag = mpi_tag;
  205. req->comm = comm;
  206. req->detached = detached;
  207. req->callback = callback;
  208. req->callback_arg = arg;
  209. req->func = func;
  210. req->sequential_consistency = sequential_consistency;
  211. req->is_internal_req = is_internal_req;
  212. req->count = count;
  213. /* Asynchronously request StarPU to fetch the data in main memory: when
  214. * it is available in main memory, _starpu_mpi_submit_new_mpi_request(req) is called and
  215. * the request is actually submitted */
  216. starpu_data_acquire_cb_sequential_consistency(data_handle, mode, _starpu_mpi_submit_new_mpi_request, (void *)req, sequential_consistency);
  217. _STARPU_MPI_LOG_OUT();
  218. return req;
  219. }
  220. /********************************************************/
  221. /* */
  222. /* Send functionalities */
  223. /* */
  224. /********************************************************/
  225. static void _starpu_mpi_isend_data_func(struct _starpu_mpi_req *req)
  226. {
  227. _STARPU_MPI_LOG_IN();
  228. STARPU_ASSERT_MSG(req->ptr, "Pointer containing data to send is invalid");
  229. _STARPU_MPI_DEBUG(2, "post MPI isend request %p type %s tag %d src %d data %p datasize %ld ptr %p datatype '%s' count %d user_datatype %d \n", req, _starpu_mpi_request_type(req->request_type), req->mpi_tag, req->srcdst, req->data_handle, starpu_data_get_size(req->data_handle), req->ptr, _starpu_mpi_datatype(req->datatype), (int)req->count, req->user_datatype);
  230. _starpu_mpi_comm_amounts_inc(req->comm, req->srcdst, req->datatype, req->count);
  231. TRACE_MPI_ISEND_SUBMIT_BEGIN(req->srcdst, req->mpi_tag, 0);
  232. req->ret = MPI_Isend(req->ptr, req->count, req->datatype, req->srcdst, _starpu_mpi_tag, req->comm, &req->request);
  233. STARPU_ASSERT_MSG(req->ret == MPI_SUCCESS, "MPI_Isend returning %d", req->ret);
  234. TRACE_MPI_ISEND_SUBMIT_END(req->srcdst, req->mpi_tag, 0);
  235. /* somebody is perhaps waiting for the MPI request to be posted */
  236. STARPU_PTHREAD_MUTEX_LOCK(&req->req_mutex);
  237. req->submitted = 1;
  238. STARPU_PTHREAD_COND_BROADCAST(&req->req_cond);
  239. STARPU_PTHREAD_MUTEX_UNLOCK(&req->req_mutex);
  240. _starpu_mpi_handle_detached_request(req);
  241. _STARPU_MPI_LOG_OUT();
  242. }
  243. static void _starpu_mpi_isend_size_func(struct _starpu_mpi_req *req)
  244. {
  245. _starpu_mpi_handle_allocate_datatype(req->data_handle, &req->datatype, &req->user_datatype);
  246. req->envelope = calloc(1,sizeof(struct _starpu_mpi_envelope));
  247. req->envelope->mpi_tag = req->mpi_tag;
  248. if (req->user_datatype == 0)
  249. {
  250. int size;
  251. req->count = 1;
  252. req->ptr = starpu_data_get_local_ptr(req->data_handle);
  253. MPI_Type_size(req->datatype, &size);
  254. req->envelope->size = (ssize_t)req->count * size;
  255. _STARPU_MPI_DEBUG(1, "Post MPI isend count (%ld) datatype_size %ld request to %d with tag %d\n",req->count,starpu_data_get_size(req->data_handle),req->srcdst, _starpu_mpi_tag);
  256. MPI_Isend(req->envelope, sizeof(struct _starpu_mpi_envelope), MPI_BYTE, req->srcdst, _starpu_mpi_tag, req->comm, &req->size_req);
  257. }
  258. else
  259. {
  260. int ret;
  261. // Do not pack the data, just try to find out the size
  262. starpu_data_pack(req->data_handle, NULL, &(req->envelope->size));
  263. if (req->envelope->size != -1)
  264. {
  265. // We already know the size of the data, let's send it to overlap with the packing of the data
  266. _STARPU_MPI_DEBUG(1, "Sending size %ld (%ld %s) with tag %d to node %d (first call to pack)\n", req->envelope->size, sizeof(req->count), _starpu_mpi_datatype(MPI_BYTE), _starpu_mpi_tag, req->srcdst);
  267. req->count = req->envelope->size;
  268. ret = MPI_Isend(req->envelope, sizeof(struct _starpu_mpi_envelope), MPI_BYTE, req->srcdst, _starpu_mpi_tag, req->comm, &req->size_req);
  269. STARPU_ASSERT_MSG(ret == MPI_SUCCESS, "when sending size, MPI_Isend returning %d", ret);
  270. }
  271. // Pack the data
  272. starpu_data_pack(req->data_handle, &req->ptr, &req->count);
  273. if (req->envelope->size == -1)
  274. {
  275. // We know the size now, let's send it
  276. _STARPU_MPI_DEBUG(1, "Sending size %ld (%ld %s) with tag %d to node %d (second call to pack)\n", req->envelope->size, sizeof(req->count), _starpu_mpi_datatype(MPI_BYTE), _starpu_mpi_tag, req->srcdst);
  277. ret = MPI_Isend(req->envelope, sizeof(struct _starpu_mpi_envelope), MPI_BYTE, req->srcdst, _starpu_mpi_tag, req->comm, &req->size_req);
  278. STARPU_ASSERT_MSG(ret == MPI_SUCCESS, "when sending size, MPI_Isend returning %d", ret);
  279. }
  280. else
  281. {
  282. // We check the size returned with the 2 calls to pack is the same
  283. STARPU_ASSERT_MSG(req->count == req->envelope->size, "Calls to pack_data returned different sizes %ld != %ld", req->count, req->envelope->size);
  284. }
  285. // We can send the data now
  286. }
  287. _starpu_mpi_isend_data_func(req);
  288. }
  289. static struct _starpu_mpi_req *_starpu_mpi_isend_common(starpu_data_handle_t data_handle,
  290. int dest, int mpi_tag, MPI_Comm comm,
  291. unsigned detached, void (*callback)(void *), void *arg,
  292. int sequential_consistency)
  293. {
  294. return _starpu_mpi_isend_irecv_common(data_handle, dest, mpi_tag, comm, detached, callback, arg, SEND_REQ, _starpu_mpi_isend_size_func, STARPU_R, sequential_consistency, 0, 0);
  295. }
  296. int starpu_mpi_isend(starpu_data_handle_t data_handle, starpu_mpi_req *public_req, int dest, int mpi_tag, MPI_Comm comm)
  297. {
  298. _STARPU_MPI_LOG_IN();
  299. STARPU_ASSERT_MSG(public_req, "starpu_mpi_isend needs a valid starpu_mpi_req");
  300. struct _starpu_mpi_req *req;
  301. req = _starpu_mpi_isend_common(data_handle, dest, mpi_tag, comm, 0, NULL, NULL, 1);
  302. STARPU_ASSERT_MSG(req, "Invalid return for _starpu_mpi_isend_common");
  303. *public_req = req;
  304. _STARPU_MPI_LOG_OUT();
  305. return 0;
  306. }
  307. int starpu_mpi_isend_detached(starpu_data_handle_t data_handle,
  308. int dest, int mpi_tag, MPI_Comm comm, void (*callback)(void *), void *arg)
  309. {
  310. _STARPU_MPI_LOG_IN();
  311. _starpu_mpi_isend_common(data_handle, dest, mpi_tag, comm, 1, callback, arg, 1);
  312. _STARPU_MPI_LOG_OUT();
  313. return 0;
  314. }
  315. int starpu_mpi_send(starpu_data_handle_t data_handle, int dest, int mpi_tag, MPI_Comm comm)
  316. {
  317. starpu_mpi_req req;
  318. MPI_Status status;
  319. _STARPU_MPI_LOG_IN();
  320. memset(&status, 0, sizeof(MPI_Status));
  321. starpu_mpi_isend(data_handle, &req, dest, mpi_tag, comm);
  322. starpu_mpi_wait(&req, &status);
  323. _STARPU_MPI_LOG_OUT();
  324. return 0;
  325. }
  326. /********************************************************/
  327. /* */
  328. /* receive functionalities */
  329. /* */
  330. /********************************************************/
  331. static void _starpu_mpi_irecv_data_func(struct _starpu_mpi_req *req)
  332. {
  333. _STARPU_MPI_LOG_IN();
  334. STARPU_ASSERT_MSG(req->ptr, "Invalid pointer to receive data");
  335. _STARPU_MPI_DEBUG(20, "post MPI irecv request %p type %s tag %d src %d data %p ptr %p datatype '%s' count %d user_datatype %d \n", req, _starpu_mpi_request_type(req->request_type), req->mpi_tag, req->srcdst, req->data_handle, req->ptr, _starpu_mpi_datatype(req->datatype), (int)req->count, req->user_datatype);
  336. TRACE_MPI_IRECV_SUBMIT_BEGIN(req->srcdst, req->mpi_tag);
  337. req->ret = MPI_Irecv(req->ptr, req->count, req->datatype, req->srcdst, _starpu_mpi_tag, req->comm, &req->request);
  338. STARPU_ASSERT_MSG(req->ret == MPI_SUCCESS, "MPI_IRecv returning %d", req->ret);
  339. TRACE_MPI_IRECV_SUBMIT_END(req->srcdst, req->mpi_tag);
  340. /* somebody is perhaps waiting for the MPI request to be posted */
  341. STARPU_PTHREAD_MUTEX_LOCK(&req->req_mutex);
  342. req->submitted = 1;
  343. STARPU_PTHREAD_COND_BROADCAST(&req->req_cond);
  344. STARPU_PTHREAD_MUTEX_UNLOCK(&req->req_mutex);
  345. _starpu_mpi_handle_detached_request(req);
  346. _STARPU_MPI_LOG_OUT();
  347. }
  348. static struct _starpu_mpi_req *_starpu_mpi_irecv_common(starpu_data_handle_t data_handle, int source, int mpi_tag, MPI_Comm comm, unsigned detached, void (*callback)(void *), void *arg, int sequential_consistency, int is_internal_req, ssize_t count)
  349. {
  350. return _starpu_mpi_isend_irecv_common(data_handle, source, mpi_tag, comm, detached, callback, arg, RECV_REQ, _starpu_mpi_irecv_data_func, STARPU_W, sequential_consistency, is_internal_req, count);
  351. }
  352. int starpu_mpi_irecv(starpu_data_handle_t data_handle, starpu_mpi_req *public_req, int source, int mpi_tag, MPI_Comm comm)
  353. {
  354. _STARPU_MPI_LOG_IN();
  355. STARPU_ASSERT_MSG(public_req, "starpu_mpi_irecv needs a valid starpu_mpi_req");
  356. // We check if a tag is defined for the data handle, if not,
  357. // we define the one given for the communication.
  358. // A tag is necessary for the internal mpi engine.
  359. int tag = starpu_data_get_tag(data_handle);
  360. if (tag == -1)
  361. starpu_data_set_tag(data_handle, mpi_tag);
  362. struct _starpu_mpi_req *req;
  363. req = _starpu_mpi_irecv_common(data_handle, source, mpi_tag, comm, 0, NULL, NULL, 1, 0, 0);
  364. STARPU_ASSERT_MSG(req, "Invalid return for _starpu_mpi_irecv_common");
  365. *public_req = req;
  366. _STARPU_MPI_LOG_OUT();
  367. return 0;
  368. }
  369. int starpu_mpi_irecv_detached(starpu_data_handle_t data_handle, int source, int mpi_tag, MPI_Comm comm, void (*callback)(void *), void *arg)
  370. {
  371. _STARPU_MPI_LOG_IN();
  372. // We check if a tag is defined for the data handle, if not,
  373. // we define the one given for the communication.
  374. // A tag is necessary for the internal mpi engine.
  375. int tag = starpu_data_get_tag(data_handle);
  376. if (tag == -1)
  377. starpu_data_set_tag(data_handle, mpi_tag);
  378. _starpu_mpi_irecv_common(data_handle, source, mpi_tag, comm, 1, callback, arg, 1, 0, 0);
  379. _STARPU_MPI_LOG_OUT();
  380. return 0;
  381. }
  382. int starpu_mpi_irecv_detached_sequential_consistency(starpu_data_handle_t data_handle, int source, int mpi_tag, MPI_Comm comm, void (*callback)(void *), void *arg, int sequential_consistency)
  383. {
  384. _STARPU_MPI_LOG_IN();
  385. _starpu_mpi_irecv_common(data_handle, source, mpi_tag, comm, 1, callback, arg, sequential_consistency, 0, 0);
  386. _STARPU_MPI_LOG_OUT();
  387. return 0;
  388. }
  389. int starpu_mpi_recv(starpu_data_handle_t data_handle, int source, int mpi_tag, MPI_Comm comm, MPI_Status *status)
  390. {
  391. starpu_mpi_req req;
  392. _STARPU_MPI_LOG_IN();
  393. // We check if a tag is defined for the data handle, if not,
  394. // we define the one given for the communication.
  395. // A tag is necessary for the internal mpi engine.
  396. int tag = starpu_data_get_tag(data_handle);
  397. if (tag == -1)
  398. starpu_data_set_tag(data_handle, mpi_tag);
  399. starpu_mpi_irecv(data_handle, &req, source, mpi_tag, comm);
  400. starpu_mpi_wait(&req, status);
  401. _STARPU_MPI_LOG_OUT();
  402. return 0;
  403. }
  404. /********************************************************/
  405. /* */
  406. /* Wait functionalities */
  407. /* */
  408. /********************************************************/
  409. static void _starpu_mpi_wait_func(struct _starpu_mpi_req *waiting_req)
  410. {
  411. _STARPU_MPI_LOG_IN();
  412. /* Which is the mpi request we are waiting for ? */
  413. struct _starpu_mpi_req *req = waiting_req->other_request;
  414. TRACE_MPI_UWAIT_BEGIN(req->srcdst, req->mpi_tag);
  415. req->ret = MPI_Wait(&req->request, waiting_req->status);
  416. STARPU_ASSERT_MSG(req->ret == MPI_SUCCESS, "MPI_Wait returning %d", req->ret);
  417. TRACE_MPI_UWAIT_END(req->srcdst, req->mpi_tag);
  418. _starpu_mpi_handle_request_termination(req);
  419. _STARPU_MPI_LOG_OUT();
  420. }
  421. int starpu_mpi_wait(starpu_mpi_req *public_req, MPI_Status *status)
  422. {
  423. _STARPU_MPI_LOG_IN();
  424. int ret;
  425. struct _starpu_mpi_req *waiting_req = malloc(sizeof(struct _starpu_mpi_req));
  426. _starpu_mpi_request_init(waiting_req);
  427. STARPU_ASSERT_MSG(waiting_req, "Allocation failed");
  428. struct _starpu_mpi_req *req = *public_req;
  429. _STARPU_MPI_INC_POSTED_REQUESTS(1);
  430. /* We cannot try to complete a MPI request that was not actually posted
  431. * to MPI yet. */
  432. STARPU_PTHREAD_MUTEX_LOCK(&(req->req_mutex));
  433. while (!(req->submitted))
  434. STARPU_PTHREAD_COND_WAIT(&(req->req_cond), &(req->req_mutex));
  435. STARPU_PTHREAD_MUTEX_UNLOCK(&(req->req_mutex));
  436. /* Initialize the request structure */
  437. _starpu_mpi_request_init(waiting_req);
  438. waiting_req->status = status;
  439. waiting_req->other_request = req;
  440. waiting_req->func = _starpu_mpi_wait_func;
  441. waiting_req->request_type = WAIT_REQ;
  442. _starpu_mpi_submit_new_mpi_request(waiting_req);
  443. /* We wait for the MPI request to finish */
  444. STARPU_PTHREAD_MUTEX_LOCK(&req->req_mutex);
  445. while (!req->completed)
  446. STARPU_PTHREAD_COND_WAIT(&req->req_cond, &req->req_mutex);
  447. STARPU_PTHREAD_MUTEX_UNLOCK(&req->req_mutex);
  448. ret = req->ret;
  449. /* The internal request structure was automatically allocated */
  450. *public_req = NULL;
  451. free(req);
  452. free(waiting_req);
  453. _STARPU_MPI_LOG_OUT();
  454. return ret;
  455. }
  456. /********************************************************/
  457. /* */
  458. /* Test functionalities */
  459. /* */
  460. /********************************************************/
  461. static void _starpu_mpi_test_func(struct _starpu_mpi_req *testing_req)
  462. {
  463. _STARPU_MPI_LOG_IN();
  464. /* Which is the mpi request we are testing for ? */
  465. struct _starpu_mpi_req *req = testing_req->other_request;
  466. _STARPU_MPI_DEBUG(2, "Test request %p type %s tag %d src %d data %p ptr %p datatype '%s' count %d user_datatype %d \n",
  467. req, _starpu_mpi_request_type(req->request_type), req->mpi_tag, req->srcdst, req->data_handle, req->ptr, _starpu_mpi_datatype(req->datatype), (int)req->count, req->user_datatype);
  468. TRACE_MPI_UTESTING_BEGIN(req->srcdst, req->mpi_tag);
  469. req->ret = MPI_Test(&req->request, testing_req->flag, testing_req->status);
  470. STARPU_ASSERT_MSG(req->ret == MPI_SUCCESS, "MPI_Test returning %d", req->ret);
  471. TRACE_MPI_UTESTING_END(req->srcdst, req->mpi_tag);
  472. if (*testing_req->flag)
  473. {
  474. testing_req->ret = req->ret;
  475. _starpu_mpi_handle_request_termination(req);
  476. }
  477. STARPU_PTHREAD_MUTEX_LOCK(&testing_req->req_mutex);
  478. testing_req->completed = 1;
  479. STARPU_PTHREAD_COND_SIGNAL(&testing_req->req_cond);
  480. STARPU_PTHREAD_MUTEX_UNLOCK(&testing_req->req_mutex);
  481. _STARPU_MPI_LOG_OUT();
  482. }
  483. int starpu_mpi_test(starpu_mpi_req *public_req, int *flag, MPI_Status *status)
  484. {
  485. _STARPU_MPI_LOG_IN();
  486. int ret = 0;
  487. STARPU_ASSERT_MSG(public_req, "starpu_mpi_test needs a valid starpu_mpi_req");
  488. struct _starpu_mpi_req *req = *public_req;
  489. STARPU_ASSERT_MSG(!req->detached, "MPI_Test cannot be called on a detached request");
  490. STARPU_PTHREAD_MUTEX_LOCK(&req->req_mutex);
  491. unsigned submitted = req->submitted;
  492. STARPU_PTHREAD_MUTEX_UNLOCK(&req->req_mutex);
  493. if (submitted)
  494. {
  495. struct _starpu_mpi_req *testing_req = malloc(sizeof(struct _starpu_mpi_req));
  496. STARPU_ASSERT_MSG(testing_req, "allocation failed");
  497. _starpu_mpi_request_init(testing_req);
  498. /* Initialize the request structure */
  499. STARPU_PTHREAD_MUTEX_INIT(&(testing_req->req_mutex), NULL);
  500. STARPU_PTHREAD_COND_INIT(&(testing_req->req_cond), NULL);
  501. testing_req->flag = flag;
  502. testing_req->status = status;
  503. testing_req->other_request = req;
  504. testing_req->func = _starpu_mpi_test_func;
  505. testing_req->completed = 0;
  506. testing_req->request_type = TEST_REQ;
  507. _STARPU_MPI_INC_POSTED_REQUESTS(1);
  508. _starpu_mpi_submit_new_mpi_request(testing_req);
  509. /* We wait for the test request to finish */
  510. STARPU_PTHREAD_MUTEX_LOCK(&(testing_req->req_mutex));
  511. while (!(testing_req->completed))
  512. STARPU_PTHREAD_COND_WAIT(&(testing_req->req_cond), &(testing_req->req_mutex));
  513. STARPU_PTHREAD_MUTEX_UNLOCK(&(testing_req->req_mutex));
  514. ret = testing_req->ret;
  515. if (*(testing_req->flag))
  516. {
  517. /* The request was completed so we free the internal
  518. * request structure which was automatically allocated
  519. * */
  520. *public_req = NULL;
  521. free(req);
  522. }
  523. free(testing_req);
  524. }
  525. else
  526. {
  527. *flag = 0;
  528. }
  529. _STARPU_MPI_LOG_OUT();
  530. return ret;
  531. }
  532. /********************************************************/
  533. /* */
  534. /* Barrier functionalities */
  535. /* */
  536. /********************************************************/
  537. static void _starpu_mpi_barrier_func(struct _starpu_mpi_req *barrier_req)
  538. {
  539. _STARPU_MPI_LOG_IN();
  540. barrier_req->ret = MPI_Barrier(barrier_req->comm);
  541. STARPU_ASSERT_MSG(barrier_req->ret == MPI_SUCCESS, "MPI_Barrier returning %d", barrier_req->ret);
  542. _starpu_mpi_handle_request_termination(barrier_req);
  543. _STARPU_MPI_LOG_OUT();
  544. }
  545. int starpu_mpi_barrier(MPI_Comm comm)
  546. {
  547. _STARPU_MPI_LOG_IN();
  548. int ret;
  549. struct _starpu_mpi_req *barrier_req = malloc(sizeof(struct _starpu_mpi_req));
  550. STARPU_ASSERT_MSG(barrier_req, "allocation failed");
  551. _starpu_mpi_request_init(barrier_req);
  552. /* First wait for *both* all tasks and MPI requests to finish, in case
  553. * some tasks generate MPI requests, MPI requests generate tasks, etc.
  554. */
  555. STARPU_PTHREAD_MUTEX_LOCK(&mutex);
  556. STARPU_ASSERT_MSG(!barrier_running, "Concurrent starpu_mpi_barrier is not implemented, even on different communicators");
  557. barrier_running = 1;
  558. do
  559. {
  560. while (posted_requests)
  561. /* Wait for all current MPI requests to finish */
  562. STARPU_PTHREAD_COND_WAIT(&cond_finished, &mutex);
  563. /* No current request, clear flag */
  564. newer_requests = 0;
  565. STARPU_PTHREAD_MUTEX_UNLOCK(&mutex);
  566. /* Now wait for all tasks */
  567. starpu_task_wait_for_all();
  568. STARPU_PTHREAD_MUTEX_LOCK(&mutex);
  569. /* Check newer_requests again, in case some MPI requests
  570. * triggered by tasks completed and triggered tasks between
  571. * wait_for_all finished and we take the lock */
  572. } while (posted_requests || newer_requests);
  573. barrier_running = 0;
  574. STARPU_PTHREAD_MUTEX_UNLOCK(&mutex);
  575. /* Initialize the request structure */
  576. STARPU_PTHREAD_MUTEX_INIT(&(barrier_req->req_mutex), NULL);
  577. STARPU_PTHREAD_COND_INIT(&(barrier_req->req_cond), NULL);
  578. barrier_req->func = _starpu_mpi_barrier_func;
  579. barrier_req->request_type = BARRIER_REQ;
  580. barrier_req->comm = comm;
  581. _STARPU_MPI_INC_POSTED_REQUESTS(1);
  582. _starpu_mpi_submit_new_mpi_request(barrier_req);
  583. /* We wait for the MPI request to finish */
  584. STARPU_PTHREAD_MUTEX_LOCK(&barrier_req->req_mutex);
  585. while (!barrier_req->completed)
  586. STARPU_PTHREAD_COND_WAIT(&barrier_req->req_cond, &barrier_req->req_mutex);
  587. STARPU_PTHREAD_MUTEX_UNLOCK(&barrier_req->req_mutex);
  588. ret = barrier_req->ret;
  589. free(barrier_req);
  590. _STARPU_MPI_LOG_OUT();
  591. return ret;
  592. }
  593. /********************************************************/
  594. /* */
  595. /* Progression */
  596. /* */
  597. /********************************************************/
  598. #ifdef STARPU_VERBOSE
  599. static char *_starpu_mpi_request_type(enum _starpu_mpi_request_type request_type)
  600. {
  601. switch (request_type)
  602. {
  603. case SEND_REQ: return "SEND_REQ";
  604. case RECV_REQ: return "RECV_REQ";
  605. case WAIT_REQ: return "WAIT_REQ";
  606. case TEST_REQ: return "TEST_REQ";
  607. case BARRIER_REQ: return "BARRIER_REQ";
  608. case UNKNOWN_REQ: return "UNSET_REQ";
  609. default: return "unknown request type";
  610. }
  611. }
  612. #endif
  613. static void _starpu_mpi_handle_request_termination(struct _starpu_mpi_req *req)
  614. {
  615. int ret;
  616. _STARPU_MPI_LOG_IN();
  617. _STARPU_MPI_DEBUG(2, "complete MPI request %p type %s tag %d src %d data %p ptr %p datatype '%s' count %d user_datatype %d internal_req %p\n",
  618. req, _starpu_mpi_request_type(req->request_type), req->mpi_tag, req->srcdst, req->data_handle, req->ptr,
  619. _starpu_mpi_datatype(req->datatype), (int)req->count, req->user_datatype, req->internal_req);
  620. if (req->internal_req)
  621. {
  622. struct _starpu_mpi_copy_handle *chandle = find_chandle(starpu_data_get_tag(req->data_handle), req->srcdst);
  623. STARPU_ASSERT_MSG(chandle, "Could not find a copy data handle with the tag %d and the node %d\n", starpu_data_get_tag(req->data_handle), req->srcdst);
  624. _STARPU_MPI_DEBUG(3, "Handling deleting of copy_handle structure from the hashmap..\n");
  625. delete_chandle(chandle);
  626. free(chandle);
  627. }
  628. else
  629. {
  630. if (req->request_type == RECV_REQ || req->request_type == SEND_REQ)
  631. {
  632. if (req->user_datatype == 1)
  633. {
  634. if (req->request_type == SEND_REQ)
  635. {
  636. // We need to make sure the communication for sending the size
  637. // has completed, as MPI can re-order messages, let's call
  638. // MPI_Wait to make sure data have been sent
  639. ret = MPI_Wait(&req->size_req, MPI_STATUS_IGNORE);
  640. STARPU_ASSERT_MSG(ret == MPI_SUCCESS, "MPI_Wait returning %d", ret);
  641. free(req->ptr);
  642. }
  643. if (req->request_type == RECV_REQ)
  644. {
  645. // req->ptr is freed by starpu_data_unpack
  646. starpu_data_unpack(req->data_handle, req->ptr, req->count);
  647. }
  648. }
  649. else
  650. {
  651. _starpu_mpi_handle_free_datatype(req->data_handle, &req->datatype);
  652. }
  653. }
  654. }
  655. if (req->data_handle)
  656. starpu_data_release(req->data_handle);
  657. if (req->envelope)
  658. {
  659. free(req->envelope);
  660. req->envelope = NULL;
  661. }
  662. /* Execute the specified callback, if any */
  663. if (req->callback)
  664. req->callback(req->callback_arg);
  665. /* tell anyone potentially waiting on the request that it is
  666. * terminated now */
  667. STARPU_PTHREAD_MUTEX_LOCK(&req->req_mutex);
  668. req->completed = 1;
  669. STARPU_PTHREAD_COND_BROADCAST(&req->req_cond);
  670. STARPU_PTHREAD_MUTEX_UNLOCK(&req->req_mutex);
  671. _STARPU_MPI_LOG_OUT();
  672. }
  673. struct _starpu_mpi_copy_cb_args
  674. {
  675. starpu_data_handle_t data_handle;
  676. starpu_data_handle_t copy_handle;
  677. struct _starpu_mpi_req *req;
  678. void *buffer;
  679. };
  680. static void _starpu_mpi_copy_cb(void* arg)
  681. {
  682. struct _starpu_mpi_copy_cb_args *args = arg;
  683. // We store in the application request the internal MPI
  684. // request so that it can be used by starpu_mpi_wait
  685. args->req->request = args->req->internal_req->request;
  686. args->req->submitted = 1;
  687. if (args->buffer)
  688. {
  689. /* Data has been received as a raw memory, it has to be unpacked */
  690. struct starpu_data_interface_ops *itf_src = starpu_data_get_interface_ops(args->copy_handle);
  691. struct starpu_data_interface_ops *itf_dst = starpu_data_get_interface_ops(args->data_handle);
  692. itf_dst->unpack_data(args->data_handle, 0, args->buffer, itf_src->get_size(args->copy_handle));
  693. free(args->buffer);
  694. }
  695. else
  696. {
  697. struct starpu_data_interface_ops *itf = starpu_data_get_interface_ops(args->copy_handle);
  698. void* itf_src = starpu_data_get_interface_on_node(args->copy_handle,0);
  699. void* itf_dst = starpu_data_get_interface_on_node(args->data_handle,0);
  700. if (!itf->copy_methods->ram_to_ram)
  701. {
  702. _STARPU_MPI_DEBUG(3, "Initiating any_to_any copy..\n");
  703. itf->copy_methods->any_to_any(itf_src, 0, itf_dst, 0, NULL);
  704. }
  705. else
  706. {
  707. _STARPU_MPI_DEBUG(3, "Initiating ram_to_ram copy..\n");
  708. itf->copy_methods->ram_to_ram(itf_src, 0, itf_dst, 0);
  709. }
  710. }
  711. _STARPU_MPI_DEBUG(3, "Done, handling release of copy_handle..\n");
  712. starpu_data_release(args->copy_handle);
  713. _STARPU_MPI_DEBUG(3, "Done, handling unregister of copy_handle..\n");
  714. starpu_data_unregister_submit(args->copy_handle);
  715. _STARPU_MPI_DEBUG(3, "Done, handling request %p termination of the already received request\n",args->req);
  716. // If the request is detached, we need to call _starpu_mpi_handle_request_termination
  717. // as it will not be called automatically as the request is not in the list detached_requests
  718. if (args->req->detached)
  719. _starpu_mpi_handle_request_termination(args->req);
  720. // else: If the request is not detached its termination will
  721. // be handled when calling starpu_mpi_wait
  722. free(args);
  723. }
  724. static void _starpu_mpi_submit_new_mpi_request(void *arg)
  725. {
  726. _STARPU_MPI_LOG_IN();
  727. struct _starpu_mpi_req *req = arg;
  728. _STARPU_MPI_INC_POSTED_REQUESTS(-1);
  729. _STARPU_MPI_DEBUG(3, "calling _starpu_mpi_submit_new_mpi_request with req %p srcdst %d tag %d and type %s\n", req, req->srcdst, req->mpi_tag, _starpu_mpi_request_type(req->request_type));
  730. STARPU_PTHREAD_MUTEX_LOCK(&mutex);
  731. if (req->request_type == RECV_REQ)
  732. {
  733. /* Case : the request is the internal receive request submitted by StarPU-MPI to receive
  734. * incoming data without a matching pending receive already submitted by the application.
  735. * We immediately allocate the pointer associated to the data_handle, and pushing it into
  736. * the list of new_requests, so as the real MPI request can be submitted before the next
  737. * submission of the envelope-catching request. */
  738. if (req->is_internal_req)
  739. {
  740. _starpu_mpi_handle_allocate_datatype(req->data_handle, &req->datatype, &req->user_datatype);
  741. if (req->user_datatype == 0)
  742. {
  743. req->count = 1;
  744. req->ptr = starpu_data_get_local_ptr(req->data_handle);
  745. }
  746. else
  747. {
  748. STARPU_ASSERT(req->count);
  749. req->ptr = malloc(req->count);
  750. STARPU_ASSERT_MSG(req->ptr, "cannot allocate message of size %ld\n", req->count);
  751. }
  752. _STARPU_MPI_DEBUG(3, "Pushing internal starpu_mpi_irecv request %p type %s tag %d src %d data %p ptr %p datatype '%s' count %d user_datatype %d \n", req, _starpu_mpi_request_type(req->request_type), req->mpi_tag, req->srcdst, req->data_handle, req->ptr, _starpu_mpi_datatype(req->datatype), (int)req->count, req->user_datatype);
  753. _starpu_mpi_req_list_push_front(new_requests, req);
  754. /* inform the starpu mpi thread that the request has beenbe pushed in the new_requests list */
  755. STARPU_PTHREAD_MUTEX_UNLOCK(&mutex);
  756. STARPU_PTHREAD_MUTEX_LOCK(&req->posted_mutex);
  757. req->posted = 1;
  758. STARPU_PTHREAD_COND_BROADCAST(&req->posted_cond);
  759. STARPU_PTHREAD_MUTEX_UNLOCK(&req->posted_mutex);
  760. STARPU_PTHREAD_MUTEX_LOCK(&mutex);
  761. }
  762. else
  763. {
  764. /* test whether the receive request has already been submitted internally by StarPU-MPI*/
  765. struct _starpu_mpi_copy_handle *chandle = find_chandle(req->mpi_tag, req->srcdst);
  766. /* Case : the request has already been submitted internally by StarPU.
  767. * We'll asynchronously ask a Read permission over the temporary handle, so as when
  768. * the internal receive will be over, the _starpu_mpi_copy_cb function will be called to
  769. * bring the data back to the original data handle associated to the request.*/
  770. if (chandle)
  771. {
  772. _STARPU_MPI_DEBUG(3, "The RECV request %p with tag %d has already been received, copying previously received data into handle's pointer..\n", req, req->mpi_tag);
  773. STARPU_ASSERT(req->data_handle != chandle->handle);
  774. req->internal_req = chandle->req;
  775. struct _starpu_mpi_copy_cb_args *cb_args = malloc(sizeof(struct _starpu_mpi_copy_cb_args));
  776. cb_args->data_handle = req->data_handle;
  777. cb_args->copy_handle = chandle->handle;
  778. cb_args->buffer = chandle->buffer;
  779. cb_args->req = req;
  780. _STARPU_MPI_DEBUG(3, "Calling data_acquire_cb on starpu_mpi_copy_cb..\n");
  781. starpu_data_acquire_cb(chandle->handle,STARPU_R,_starpu_mpi_copy_cb,(void*) cb_args);
  782. }
  783. /* Case : a classic receive request with no send received earlier than expected.
  784. * We just add the pending receive request to the requests' hashmap. */
  785. else
  786. {
  787. _STARPU_MPI_DEBUG(3, "Adding the pending receive request %p (srcdst %d tag %d) into the request hashmap\n", req, req->srcdst, req->mpi_tag);
  788. add_app_req(req);
  789. }
  790. }
  791. }
  792. else
  793. {
  794. _starpu_mpi_req_list_push_front(new_requests, req);
  795. _STARPU_MPI_DEBUG(3, "Pushing new request %p type %s tag %d src %d data %p ptr %p datatype '%s' count %d user_datatype %d \n",
  796. req, _starpu_mpi_request_type(req->request_type), req->mpi_tag, req->srcdst, req->data_handle, req->ptr, _starpu_mpi_datatype(req->datatype), (int)req->count, req->user_datatype);
  797. }
  798. newer_requests = 1;
  799. STARPU_PTHREAD_COND_BROADCAST(&cond_progression);
  800. STARPU_PTHREAD_MUTEX_UNLOCK(&mutex);
  801. _STARPU_MPI_LOG_OUT();
  802. }
  803. #ifdef STARPU_MPI_ACTIVITY
  804. static unsigned _starpu_mpi_progression_hook_func(void *arg STARPU_ATTRIBUTE_UNUSED)
  805. {
  806. unsigned may_block = 1;
  807. STARPU_PTHREAD_MUTEX_LOCK(&detached_requests_mutex);
  808. if (!_starpu_mpi_req_list_empty(detached_requests))
  809. {
  810. STARPU_PTHREAD_MUTEX_UNLOCK(&detached_requests_mutex);
  811. STARPU_PTHREAD_MUTEX_LOCK(&mutex);
  812. STARPU_PTHREAD_COND_SIGNAL(&cond_progression);
  813. STARPU_PTHREAD_MUTEX_UNLOCK(&mutex);
  814. may_block = 0;
  815. }
  816. else
  817. STARPU_PTHREAD_MUTEX_UNLOCK(&detached_requests_mutex);
  818. return may_block;
  819. }
  820. #endif /* STARPU_MPI_ACTIVITY */
  821. static void _starpu_mpi_test_detached_requests(void)
  822. {
  823. _STARPU_MPI_LOG_IN();
  824. int flag;
  825. MPI_Status status;
  826. struct _starpu_mpi_req *req, *next_req;
  827. STARPU_PTHREAD_MUTEX_LOCK(&detached_requests_mutex);
  828. for (req = _starpu_mpi_req_list_begin(detached_requests);
  829. req != _starpu_mpi_req_list_end(detached_requests);
  830. req = next_req)
  831. {
  832. next_req = _starpu_mpi_req_list_next(req);
  833. STARPU_PTHREAD_MUTEX_UNLOCK(&detached_requests_mutex);
  834. //_STARPU_MPI_DEBUG(3, "Test detached request %p - mpitag %d - TYPE %s %d\n", &req->request, req->mpi_tag, _starpu_mpi_request_type(req->request_type), req->srcdst);
  835. req->ret = MPI_Test(&req->request, &flag, &status);
  836. STARPU_ASSERT_MSG(req->ret == MPI_SUCCESS, "MPI_Test returning %d", req->ret);
  837. if (flag)
  838. {
  839. if (req->request_type == RECV_REQ)
  840. {
  841. TRACE_MPI_IRECV_COMPLETE_BEGIN(req->srcdst, req->mpi_tag);
  842. }
  843. else if (req->request_type == SEND_REQ)
  844. {
  845. TRACE_MPI_ISEND_COMPLETE_BEGIN(req->srcdst, req->mpi_tag, 0);
  846. }
  847. _starpu_mpi_handle_request_termination(req);
  848. if (req->request_type == RECV_REQ)
  849. {
  850. TRACE_MPI_IRECV_COMPLETE_END(req->srcdst, req->mpi_tag);
  851. }
  852. else if (req->request_type == SEND_REQ)
  853. {
  854. TRACE_MPI_ISEND_COMPLETE_END(req->srcdst, req->mpi_tag, 0);
  855. }
  856. }
  857. STARPU_PTHREAD_MUTEX_LOCK(&detached_requests_mutex);
  858. if (flag)
  859. {
  860. _starpu_mpi_req_list_erase(detached_requests, req);
  861. #ifdef STARPU_DEVEL
  862. #warning FIXME: when do we free internal requests
  863. #endif
  864. if (!req->is_internal_req)
  865. free(req);
  866. }
  867. }
  868. STARPU_PTHREAD_MUTEX_UNLOCK(&detached_requests_mutex);
  869. _STARPU_MPI_LOG_OUT();
  870. }
  871. static void _starpu_mpi_handle_detached_request(struct _starpu_mpi_req *req)
  872. {
  873. if (req->detached)
  874. {
  875. /* put the submitted request into the list of pending requests
  876. * so that it can be handled by the progression mechanisms */
  877. STARPU_PTHREAD_MUTEX_LOCK(&detached_requests_mutex);
  878. _starpu_mpi_req_list_push_front(detached_requests, req);
  879. STARPU_PTHREAD_MUTEX_UNLOCK(&detached_requests_mutex);
  880. starpu_wake_all_blocked_workers();
  881. STARPU_PTHREAD_MUTEX_LOCK(&mutex);
  882. STARPU_PTHREAD_COND_SIGNAL(&cond_progression);
  883. STARPU_PTHREAD_MUTEX_UNLOCK(&mutex);
  884. }
  885. }
  886. static void _starpu_mpi_handle_new_request(struct _starpu_mpi_req *req)
  887. {
  888. _STARPU_MPI_LOG_IN();
  889. STARPU_ASSERT_MSG(req, "Invalid request");
  890. /* submit the request to MPI */
  891. _STARPU_MPI_DEBUG(2, "Handling new request %p type %s tag %d src %d data %p ptr %p datatype '%s' count %d user_datatype %d \n",
  892. req, _starpu_mpi_request_type(req->request_type), req->mpi_tag, req->srcdst, req->data_handle, req->ptr, _starpu_mpi_datatype(req->datatype), (int)req->count, req->user_datatype);
  893. req->func(req);
  894. _STARPU_MPI_LOG_OUT();
  895. }
  896. struct _starpu_mpi_argc_argv
  897. {
  898. int initialize_mpi;
  899. int *argc;
  900. char ***argv;
  901. };
  902. static void _starpu_mpi_print_thread_level_support(int thread_level, char *msg)
  903. {
  904. switch (thread_level)
  905. {
  906. case MPI_THREAD_SERIALIZED:
  907. {
  908. _STARPU_DISP("MPI%s MPI_THREAD_SERIALIZED; Multiple threads may make MPI calls, but only one at a time.\n", msg);
  909. break;
  910. }
  911. case MPI_THREAD_FUNNELED:
  912. {
  913. _STARPU_DISP("MPI%s MPI_THREAD_FUNNELED; The application can safely make calls to StarPU-MPI functions, but should not call directly MPI communication functions.\n", msg);
  914. break;
  915. }
  916. case MPI_THREAD_SINGLE:
  917. {
  918. _STARPU_DISP("MPI%s MPI_THREAD_SINGLE; MPI does not have multi-thread support, this might cause problems. The application can make calls to StarPU-MPI functions, but not call directly MPI Communication functions.\n", msg);
  919. break;
  920. }
  921. }
  922. }
  923. static void *_starpu_mpi_progress_thread_func(void *arg)
  924. {
  925. struct _starpu_mpi_argc_argv *argc_argv = (struct _starpu_mpi_argc_argv *) arg;
  926. if (argc_argv->initialize_mpi)
  927. {
  928. int thread_support;
  929. _STARPU_DEBUG("Calling MPI_Init_thread\n");
  930. if (MPI_Init_thread(argc_argv->argc, argc_argv->argv, MPI_THREAD_SERIALIZED, &thread_support) != MPI_SUCCESS)
  931. {
  932. _STARPU_ERROR("MPI_Init_thread failed\n");
  933. }
  934. _starpu_mpi_print_thread_level_support(thread_support, "_Init_thread level =");
  935. }
  936. else
  937. {
  938. int provided;
  939. MPI_Query_thread(&provided);
  940. _starpu_mpi_print_thread_level_support(provided, " has been initialized with");
  941. }
  942. {
  943. int rank, worldsize;
  944. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  945. MPI_Comm_size(MPI_COMM_WORLD, &worldsize);
  946. TRACE_MPI_START(rank, worldsize);
  947. #ifdef STARPU_USE_FXT
  948. starpu_profiling_set_id(rank);
  949. #endif //STARPU_USE_FXT
  950. }
  951. /* notify the main thread that the progression thread is ready */
  952. STARPU_PTHREAD_MUTEX_LOCK(&mutex);
  953. running = 1;
  954. STARPU_PTHREAD_COND_SIGNAL(&cond_progression);
  955. STARPU_PTHREAD_MUTEX_UNLOCK(&mutex);
  956. STARPU_PTHREAD_MUTEX_LOCK(&mutex);
  957. struct _starpu_mpi_envelope *recv_env = calloc(1,sizeof(struct _starpu_mpi_envelope));
  958. int header_req_submitted = 0;
  959. while (running || posted_requests || !(_starpu_mpi_req_list_empty(new_requests)) || !(_starpu_mpi_req_list_empty(detached_requests)))
  960. {
  961. /* shall we block ? */
  962. unsigned block = _starpu_mpi_req_list_empty(new_requests) && (_starpu_mpi_app_req_hashmap_count == 0);
  963. #ifndef STARPU_MPI_ACTIVITY
  964. STARPU_PTHREAD_MUTEX_LOCK(&detached_requests_mutex);
  965. block = block && _starpu_mpi_req_list_empty(detached_requests);
  966. STARPU_PTHREAD_MUTEX_UNLOCK(&detached_requests_mutex);
  967. #endif /* STARPU_MPI_ACTIVITY */
  968. if (block)
  969. {
  970. _STARPU_MPI_DEBUG(3, "NO MORE REQUESTS TO HANDLE\n");
  971. TRACE_MPI_SLEEP_BEGIN();
  972. if (barrier_running)
  973. /* Tell mpi_barrier */
  974. STARPU_PTHREAD_COND_SIGNAL(&cond_finished);
  975. STARPU_PTHREAD_COND_WAIT(&cond_progression, &mutex);
  976. TRACE_MPI_SLEEP_END();
  977. }
  978. /* get one request */
  979. struct _starpu_mpi_req *req;
  980. while (!_starpu_mpi_req_list_empty(new_requests))
  981. {
  982. req = _starpu_mpi_req_list_pop_back(new_requests);
  983. /* handling a request is likely to block for a while
  984. * (on a sync_data_with_mem call), we want to let the
  985. * application submit requests in the meantime, so we
  986. * release the lock. */
  987. STARPU_PTHREAD_MUTEX_UNLOCK(&mutex);
  988. _starpu_mpi_handle_new_request(req);
  989. STARPU_PTHREAD_MUTEX_LOCK(&mutex);
  990. }
  991. /* If there is no currently submitted header_req submitted to catch envelopes from senders, and there is some pending receive
  992. * requests in our side, we resubmit a header request. */
  993. MPI_Request header_req;
  994. if ((_starpu_mpi_app_req_hashmap_count > 0) && (header_req_submitted == 0))// && (HASH_COUNT(_starpu_mpi_copy_handle_hashmap) == 0))
  995. {
  996. _STARPU_MPI_DEBUG(3, "Posting a receive to get a data envelop\n");
  997. MPI_Irecv(recv_env, sizeof(struct _starpu_mpi_envelope), MPI_BYTE, MPI_ANY_SOURCE, _starpu_mpi_tag, MPI_COMM_WORLD, &header_req);
  998. header_req_submitted = 1;
  999. }
  1000. /* test whether there are some terminated "detached request" */
  1001. STARPU_PTHREAD_MUTEX_UNLOCK(&mutex);
  1002. _starpu_mpi_test_detached_requests();
  1003. STARPU_PTHREAD_MUTEX_LOCK(&mutex);
  1004. if (header_req_submitted == 1)
  1005. {
  1006. int flag,res;
  1007. MPI_Status status;
  1008. _STARPU_MPI_DEBUG(4, "Test of header_req\n");
  1009. /* test whether an envelope has arrived. */
  1010. res = MPI_Test(&header_req, &flag, &status);
  1011. STARPU_ASSERT(res == MPI_SUCCESS);
  1012. if (flag)
  1013. {
  1014. _STARPU_MPI_DEBUG(3, "Searching for application request with tag %d and source %d (size %ld)\n", recv_env->mpi_tag, status.MPI_SOURCE, recv_env->size);
  1015. struct _starpu_mpi_req *found_req = find_app_req(recv_env->mpi_tag, status.MPI_SOURCE);
  1016. /* Case : a data will arrive before the matching receive has been submitted in our side of the application.
  1017. * We will allow a temporary handle to store the incoming data, by submitting a starpu_mpi_irecv_detached
  1018. * on this handle, and register this so as the StarPU-MPI layer can remember it.*/
  1019. if (!found_req)
  1020. {
  1021. _STARPU_MPI_DEBUG(3, "Request with tag %d and source %d not found, creating a copy_handle to receive incoming data..\n", recv_env->mpi_tag, status.MPI_SOURCE);
  1022. starpu_data_handle_t data_handle = NULL;
  1023. STARPU_PTHREAD_MUTEX_UNLOCK(&mutex);
  1024. data_handle = starpu_data_get_data_handle_from_tag(recv_env->mpi_tag);
  1025. STARPU_PTHREAD_MUTEX_LOCK(&mutex);
  1026. struct _starpu_mpi_copy_handle* chandle = malloc(sizeof(struct _starpu_mpi_copy_handle));
  1027. STARPU_ASSERT(chandle);
  1028. chandle->mpi_tag = recv_env->mpi_tag;
  1029. chandle->env = recv_env;
  1030. chandle->source = status.MPI_SOURCE;
  1031. if (data_handle)
  1032. {
  1033. chandle->buffer = NULL;
  1034. starpu_data_register_same(&chandle->handle, data_handle);
  1035. add_chandle(chandle);
  1036. }
  1037. else
  1038. {
  1039. /* The application has not registered yet a data with the tag,
  1040. * we are going to receive the data as a raw memory, and give it
  1041. * to the application when it post a receive for this tag
  1042. */
  1043. _STARPU_MPI_DEBUG(20, "Posting a receive for a data of size %d which has not yet been registered\n", (int)chandle->env->size);
  1044. chandle->buffer = malloc(chandle->env->size);
  1045. starpu_vector_data_register(&chandle->handle, 0, (uintptr_t) chandle->buffer, chandle->env->size, 1);
  1046. add_chandle(chandle);
  1047. }
  1048. _STARPU_MPI_DEBUG(20, "Posting internal detached irecv on copy_handle with tag %d from src %d ..\n", chandle->mpi_tag, status.MPI_SOURCE);
  1049. STARPU_PTHREAD_MUTEX_UNLOCK(&mutex);
  1050. chandle->req = _starpu_mpi_irecv_common(chandle->handle, status.MPI_SOURCE, chandle->mpi_tag, MPI_COMM_WORLD, 1, NULL, NULL, 1, 1, recv_env->size);
  1051. STARPU_PTHREAD_MUTEX_LOCK(&mutex);
  1052. // We wait until the request is pushed in the
  1053. // new_request list, that ensures that the next loop
  1054. // will call _starpu_mpi_handle_new_request
  1055. // on the request and post the corresponding mpi_irecv,
  1056. // otherwise, it may lead to read data as envelop
  1057. STARPU_PTHREAD_MUTEX_UNLOCK(&mutex);
  1058. STARPU_PTHREAD_MUTEX_LOCK(&(chandle->req->posted_mutex));
  1059. while (!(chandle->req->posted))
  1060. STARPU_PTHREAD_COND_WAIT(&(chandle->req->posted_cond), &(chandle->req->posted_mutex));
  1061. STARPU_PTHREAD_MUTEX_UNLOCK(&(chandle->req->posted_mutex));
  1062. STARPU_PTHREAD_MUTEX_LOCK(&mutex);
  1063. }
  1064. /* Case : a matching receive has been found for the incoming data, we handle the correct allocation of the pointer associated to
  1065. * the data handle, then submit the corresponding receive with _starpu_mpi_handle_new_request. */
  1066. else
  1067. {
  1068. _STARPU_MPI_DEBUG(3, "A matching receive has been found for the incoming data with tag %d\n", recv_env->mpi_tag);
  1069. delete_app_req(found_req);
  1070. _starpu_mpi_handle_allocate_datatype(found_req->data_handle, &found_req->datatype, &found_req->user_datatype);
  1071. if (found_req->user_datatype == 0)
  1072. {
  1073. found_req->count = 1;
  1074. found_req->ptr = starpu_data_get_local_ptr(found_req->data_handle);
  1075. }
  1076. else
  1077. {
  1078. found_req->count = recv_env->size;
  1079. found_req->ptr = malloc(found_req->count);
  1080. STARPU_ASSERT_MSG(found_req->ptr, "cannot allocate message of size %ld\n", found_req->count);
  1081. }
  1082. _STARPU_MPI_DEBUG(3, "Handling new request... \n");
  1083. /* handling a request is likely to block for a while
  1084. * (on a sync_data_with_mem call), we want to let the
  1085. * application submit requests in the meantime, so we
  1086. * release the lock. */
  1087. STARPU_PTHREAD_MUTEX_UNLOCK(&mutex);
  1088. _starpu_mpi_handle_new_request(found_req);
  1089. STARPU_PTHREAD_MUTEX_LOCK(&mutex);
  1090. }
  1091. header_req_submitted = 0;
  1092. }
  1093. else
  1094. {
  1095. _STARPU_MPI_DEBUG(4, "Nothing received, continue ..\n");
  1096. }
  1097. }
  1098. }
  1099. STARPU_ASSERT_MSG(_starpu_mpi_req_list_empty(detached_requests), "List of detached requests not empty");
  1100. STARPU_ASSERT_MSG(_starpu_mpi_req_list_empty(new_requests), "List of new requests not empty");
  1101. STARPU_ASSERT_MSG(posted_requests == 0, "Number of posted request is not zero");
  1102. STARPU_ASSERT_MSG(_starpu_mpi_app_req_hashmap_count == 0, "Number of receive requests left is not zero");
  1103. STARPU_ASSERT_MSG(_starpu_mpi_copy_handle_hashmap_count == 0, "Number of copy requests left is not zero");
  1104. if (argc_argv->initialize_mpi)
  1105. {
  1106. _STARPU_MPI_DEBUG(3, "Calling MPI_Finalize()\n");
  1107. MPI_Finalize();
  1108. }
  1109. STARPU_PTHREAD_MUTEX_UNLOCK(&mutex);
  1110. free(_starpu_mpi_app_req_hashmap);
  1111. free(_starpu_mpi_copy_handle_hashmap);
  1112. free(argc_argv);
  1113. free(recv_env);
  1114. return NULL;
  1115. }
  1116. /********************************************************/
  1117. /* */
  1118. /* (De)Initialization methods */
  1119. /* */
  1120. /********************************************************/
  1121. #ifdef STARPU_MPI_ACTIVITY
  1122. static int hookid = - 1;
  1123. #endif /* STARPU_MPI_ACTIVITY */
  1124. static void _starpu_mpi_add_sync_point_in_fxt(void)
  1125. {
  1126. #ifdef STARPU_USE_FXT
  1127. int rank;
  1128. int worldsize;
  1129. int ret;
  1130. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  1131. MPI_Comm_size(MPI_COMM_WORLD, &worldsize);
  1132. ret = MPI_Barrier(MPI_COMM_WORLD);
  1133. STARPU_ASSERT_MSG(ret == MPI_SUCCESS, "MPI_Barrier returning %d", ret);
  1134. /* We generate a "unique" key so that we can make sure that different
  1135. * FxT traces come from the same MPI run. */
  1136. int random_number;
  1137. /* XXX perhaps we don't want to generate a new seed if the application
  1138. * specified some reproductible behaviour ? */
  1139. if (rank == 0)
  1140. {
  1141. srand(time(NULL));
  1142. random_number = rand();
  1143. }
  1144. ret = MPI_Bcast(&random_number, 1, MPI_INT, 0, MPI_COMM_WORLD);
  1145. STARPU_ASSERT_MSG(ret == MPI_SUCCESS, "MPI_Bcast returning %d", ret);
  1146. TRACE_MPI_BARRIER(rank, worldsize, random_number);
  1147. _STARPU_MPI_DEBUG(3, "unique key %x\n", random_number);
  1148. #endif
  1149. }
  1150. static
  1151. int _starpu_mpi_initialize(int *argc, char ***argv, int initialize_mpi)
  1152. {
  1153. STARPU_PTHREAD_MUTEX_INIT(&mutex, NULL);
  1154. STARPU_PTHREAD_COND_INIT(&cond_progression, NULL);
  1155. STARPU_PTHREAD_COND_INIT(&cond_finished, NULL);
  1156. new_requests = _starpu_mpi_req_list_new();
  1157. STARPU_PTHREAD_MUTEX_INIT(&detached_requests_mutex, NULL);
  1158. detached_requests = _starpu_mpi_req_list_new();
  1159. STARPU_PTHREAD_MUTEX_INIT(&mutex_posted_requests, NULL);
  1160. struct _starpu_mpi_argc_argv *argc_argv = malloc(sizeof(struct _starpu_mpi_argc_argv));
  1161. argc_argv->initialize_mpi = initialize_mpi;
  1162. argc_argv->argc = argc;
  1163. argc_argv->argv = argv;
  1164. STARPU_PTHREAD_CREATE(&progress_thread, NULL, _starpu_mpi_progress_thread_func, argc_argv);
  1165. STARPU_PTHREAD_MUTEX_LOCK(&mutex);
  1166. while (!running)
  1167. STARPU_PTHREAD_COND_WAIT(&cond_progression, &mutex);
  1168. STARPU_PTHREAD_MUTEX_UNLOCK(&mutex);
  1169. #ifdef STARPU_MPI_ACTIVITY
  1170. hookid = starpu_progression_hook_register(progression_hook_func, NULL);
  1171. STARPU_ASSERT_MSG(hookid >= 0, "starpu_progression_hook_register failed");
  1172. #endif /* STARPU_MPI_ACTIVITY */
  1173. _starpu_mpi_add_sync_point_in_fxt();
  1174. _starpu_mpi_comm_amounts_init(MPI_COMM_WORLD);
  1175. _starpu_mpi_cache_init(MPI_COMM_WORLD);
  1176. {
  1177. int nb_nodes, k;
  1178. MPI_Comm_size(MPI_COMM_WORLD, &nb_nodes);
  1179. _starpu_mpi_app_req_hashmap = malloc(nb_nodes * sizeof(struct _starpu_mpi_req *));
  1180. for(k=0 ; k<nb_nodes ; k++) _starpu_mpi_app_req_hashmap[k] = NULL;
  1181. _starpu_mpi_copy_handle_hashmap = malloc(nb_nodes * sizeof(struct _starpu_mpi_copy_handle *));
  1182. for(k=0 ; k<nb_nodes ; k++) _starpu_mpi_copy_handle_hashmap[k] = NULL;
  1183. }
  1184. return 0;
  1185. }
  1186. int starpu_mpi_init(int *argc, char ***argv, int initialize_mpi)
  1187. {
  1188. return _starpu_mpi_initialize(argc, argv, initialize_mpi);
  1189. }
  1190. int starpu_mpi_initialize(void)
  1191. {
  1192. return _starpu_mpi_initialize(NULL, NULL, 0);
  1193. }
  1194. int starpu_mpi_initialize_extended(int *rank, int *world_size)
  1195. {
  1196. int ret;
  1197. ret = _starpu_mpi_initialize(NULL, NULL, 1);
  1198. if (ret == 0)
  1199. {
  1200. _STARPU_DEBUG("Calling MPI_Comm_rank\n");
  1201. MPI_Comm_rank(MPI_COMM_WORLD, rank);
  1202. MPI_Comm_size(MPI_COMM_WORLD, world_size);
  1203. }
  1204. return ret;
  1205. }
  1206. int starpu_mpi_shutdown(void)
  1207. {
  1208. void *value;
  1209. int rank, world_size;
  1210. /* We need to get the rank before calling MPI_Finalize to pass to _starpu_mpi_comm_amounts_display() */
  1211. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  1212. MPI_Comm_size(MPI_COMM_WORLD, &world_size);
  1213. /* kill the progression thread */
  1214. STARPU_PTHREAD_MUTEX_LOCK(&mutex);
  1215. running = 0;
  1216. STARPU_PTHREAD_COND_BROADCAST(&cond_progression);
  1217. STARPU_PTHREAD_MUTEX_UNLOCK(&mutex);
  1218. starpu_pthread_join(progress_thread, &value);
  1219. #ifdef STARPU_MPI_ACTIVITY
  1220. starpu_progression_hook_deregister(hookid);
  1221. #endif /* STARPU_MPI_ACTIVITY */
  1222. TRACE_MPI_STOP(rank, world_size);
  1223. /* free the request queues */
  1224. _starpu_mpi_req_list_delete(detached_requests);
  1225. _starpu_mpi_req_list_delete(new_requests);
  1226. _starpu_mpi_comm_amounts_display(rank);
  1227. _starpu_mpi_comm_amounts_free();
  1228. _starpu_mpi_cache_free(world_size);
  1229. return 0;
  1230. }