starpu_mpi.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
  4. *
  5. * This program 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. * This program 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 <stdlib.h>
  17. #include <starpu_mpi.h>
  18. #include <starpu_mpi_datatype.h>
  19. #include <starpu_mpi_private.h>
  20. #define VERBOSE_STARPU_MPI 1
  21. /* TODO find a better way to select the polling method (perhaps during the
  22. * configuration) */
  23. //#define USE_STARPU_ACTIVITY 1
  24. static void submit_mpi_req(void *arg);
  25. static void handle_request_termination(struct starpu_mpi_req_s *req);
  26. /* The list of requests that have been newly submitted by the application */
  27. static starpu_mpi_req_list_t new_requests;
  28. /* The list of detached requests that have already been submitted to MPI */
  29. static starpu_mpi_req_list_t detached_requests;
  30. static pthread_mutex_t detached_requests_mutex;
  31. static pthread_cond_t cond;
  32. static pthread_mutex_t mutex;
  33. static pthread_t progress_thread;
  34. static int running = 0;
  35. /*
  36. * Isend
  37. */
  38. static void starpu_mpi_isend_func(struct starpu_mpi_req_s *req)
  39. {
  40. void *ptr = starpu_mpi_handle_to_ptr(req->data_handle);
  41. #ifdef VERBOSE_STARPU_MPI
  42. int rank;
  43. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  44. fprintf(stderr, "<<<< STARPU MPI >>>> : Rank %d post MPI isend tag %x dst %d ptr %p req %p\n", rank, req->mpi_tag, req->srcdst, ptr, &req->request);
  45. #endif
  46. starpu_mpi_handle_to_datatype(req->data_handle, &req->datatype);
  47. //MPI_Isend(ptr, 1, req->datatype, req->srcdst, req->mpi_tag, req->comm, &req->request);
  48. MPI_Isend(ptr, 1, req->datatype, req->srcdst, req->mpi_tag, req->comm, &req->request);
  49. TRACE_MPI_ISEND(req->srcdst, req->mpi_tag, 0);
  50. /* somebody is perhaps waiting for the MPI request to be posted */
  51. PTHREAD_MUTEX_LOCK(&req->req_mutex);
  52. req->submitted = 1;
  53. PTHREAD_COND_BROADCAST(&req->req_cond);
  54. PTHREAD_MUTEX_UNLOCK(&req->req_mutex);
  55. }
  56. static struct starpu_mpi_req_s *_starpu_mpi_isend_common(starpu_data_handle data_handle,
  57. int dest, int mpi_tag, MPI_Comm comm,
  58. unsigned detached, void (*callback)(void *), void *arg)
  59. {
  60. struct starpu_mpi_req_s *req = calloc(1, sizeof(struct starpu_mpi_req_s));
  61. STARPU_ASSERT(req);
  62. /* Initialize the request structure */
  63. req->submitted = 0;
  64. req->completed = 0;
  65. PTHREAD_MUTEX_INIT(&req->req_mutex, NULL);
  66. PTHREAD_COND_INIT(&req->req_cond, NULL);
  67. req->request_type = SEND_REQ;
  68. req->data_handle = data_handle;
  69. req->srcdst = dest;
  70. req->mpi_tag = mpi_tag;
  71. req->comm = comm;
  72. req->func = starpu_mpi_isend_func;
  73. req->detached = detached;
  74. req->callback = callback;
  75. req->callback_arg = arg;
  76. /* Asynchronously request StarPU to fetch the data in main memory: when
  77. * it is available in main memory, submit_mpi_req(req) is called and
  78. * the request is actually submitted */
  79. starpu_data_sync_with_mem_non_blocking(data_handle, STARPU_R,
  80. submit_mpi_req, (void *)req);
  81. return req;
  82. }
  83. int starpu_mpi_isend(starpu_data_handle data_handle, starpu_mpi_req *public_req, int dest, int mpi_tag, MPI_Comm comm)
  84. {
  85. STARPU_ASSERT(public_req);
  86. struct starpu_mpi_req_s *req;
  87. req = _starpu_mpi_isend_common(data_handle, dest, mpi_tag, comm, 0, NULL, NULL);
  88. STARPU_ASSERT(req);
  89. *public_req = req;
  90. return 0;
  91. }
  92. /*
  93. * Isend (detached)
  94. */
  95. int starpu_mpi_isend_detached(starpu_data_handle data_handle,
  96. int dest, int mpi_tag, MPI_Comm comm, void (*callback)(void *), void *arg)
  97. {
  98. _starpu_mpi_isend_common(data_handle, dest, mpi_tag, comm, 1, callback, arg);
  99. return 0;
  100. }
  101. /*
  102. * Irecv
  103. */
  104. static void starpu_mpi_irecv_func(struct starpu_mpi_req_s *req)
  105. {
  106. void *ptr = starpu_mpi_handle_to_ptr(req->data_handle);
  107. STARPU_ASSERT(ptr);
  108. starpu_mpi_handle_to_datatype(req->data_handle, &req->datatype);
  109. #ifdef VERBOSE_STARPU_MPI
  110. int rank;
  111. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  112. fprintf(stderr, "<<<< STARPU MPI >>>> : Rank %d post MPI irecv tag %x src %d ptr %p req %p datatype %d\n", rank, req->mpi_tag, req->srcdst, ptr, &req->request, req->datatype);
  113. #endif
  114. MPI_Irecv(ptr, 1, req->datatype, req->srcdst, req->mpi_tag, req->comm, &req->request);
  115. /* somebody is perhaps waiting for the MPI request to be posted */
  116. PTHREAD_MUTEX_LOCK(&req->req_mutex);
  117. req->submitted = 1;
  118. PTHREAD_COND_BROADCAST(&req->req_cond);
  119. PTHREAD_MUTEX_UNLOCK(&req->req_mutex);
  120. }
  121. static struct starpu_mpi_req_s *_starpu_mpi_irecv_common(starpu_data_handle data_handle, int source, int mpi_tag, MPI_Comm comm, unsigned detached, void (*callback)(void *), void *arg)
  122. {
  123. struct starpu_mpi_req_s *req = calloc(1, sizeof(struct starpu_mpi_req_s));
  124. STARPU_ASSERT(req);
  125. /* Initialize the request structure */
  126. req->submitted = 0;
  127. PTHREAD_MUTEX_INIT(&req->req_mutex, NULL);
  128. PTHREAD_COND_INIT(&req->req_cond, NULL);
  129. req->request_type = RECV_REQ;
  130. req->data_handle = data_handle;
  131. req->srcdst = source;
  132. req->mpi_tag = mpi_tag;
  133. req->comm = comm;
  134. req->detached = detached;
  135. req->callback = callback;
  136. req->callback_arg = arg;
  137. req->func = starpu_mpi_irecv_func;
  138. /* Asynchronously request StarPU to fetch the data in main memory: when
  139. * it is available in main memory, submit_mpi_req(req) is called and
  140. * the request is actually submitted */
  141. starpu_data_sync_with_mem_non_blocking(data_handle, STARPU_W,
  142. submit_mpi_req, (void *)req);
  143. return req;
  144. }
  145. int starpu_mpi_irecv(starpu_data_handle data_handle, starpu_mpi_req *public_req, int source, int mpi_tag, MPI_Comm comm)
  146. {
  147. STARPU_ASSERT(public_req);
  148. struct starpu_mpi_req_s *req;
  149. req = _starpu_mpi_irecv_common(data_handle, source, mpi_tag, comm, 0, NULL, NULL);
  150. STARPU_ASSERT(req);
  151. *public_req = req;
  152. return 0;
  153. }
  154. /*
  155. * Irecv (detached)
  156. */
  157. int starpu_mpi_irecv_detached(starpu_data_handle data_handle, int source, int mpi_tag, MPI_Comm comm, void (*callback)(void *), void *arg)
  158. {
  159. _starpu_mpi_irecv_common(data_handle, source, mpi_tag, comm, 1, callback, arg);
  160. return 0;
  161. }
  162. /*
  163. * Recv
  164. */
  165. int starpu_mpi_recv(starpu_data_handle data_handle,
  166. int source, int mpi_tag, MPI_Comm comm, MPI_Status *status)
  167. {
  168. starpu_mpi_req req;
  169. starpu_mpi_irecv(data_handle, &req, source, mpi_tag, comm);
  170. starpu_mpi_wait(&req, status);
  171. return 0;
  172. }
  173. /*
  174. * Send
  175. */
  176. int starpu_mpi_send(starpu_data_handle data_handle,
  177. int dest, int mpi_tag, MPI_Comm comm)
  178. {
  179. starpu_mpi_req req;
  180. MPI_Status status;
  181. memset(&status, 0, sizeof(MPI_Status));
  182. starpu_mpi_isend(data_handle, &req, dest, mpi_tag, comm);
  183. starpu_mpi_wait(&req, &status);
  184. return 0;
  185. }
  186. /*
  187. * Wait
  188. */
  189. static void starpu_mpi_wait_func(struct starpu_mpi_req_s *waiting_req)
  190. {
  191. /* Which is the mpi request we are waiting for ? */
  192. struct starpu_mpi_req_s *req = waiting_req->other_request;
  193. req->ret = MPI_Wait(&req->request, waiting_req->status);
  194. handle_request_termination(req);
  195. }
  196. int starpu_mpi_wait(starpu_mpi_req *public_req, MPI_Status *status)
  197. {
  198. int ret;
  199. struct starpu_mpi_req_s waiting_req;
  200. memset(&waiting_req, 0, sizeof(struct starpu_mpi_req_s));
  201. struct starpu_mpi_req_s *req = *public_req;
  202. /* We cannot try to complete a MPI request that was not actually posted
  203. * to MPI yet. */
  204. PTHREAD_MUTEX_LOCK(&req->req_mutex);
  205. while (!req->submitted)
  206. PTHREAD_COND_WAIT(&req->req_cond, &req->req_mutex);
  207. PTHREAD_MUTEX_UNLOCK(&req->req_mutex);
  208. /* Initialize the request structure */
  209. PTHREAD_MUTEX_INIT(&waiting_req.req_mutex, NULL);
  210. PTHREAD_COND_INIT(&waiting_req.req_cond, NULL);
  211. waiting_req.status = status;
  212. waiting_req.other_request = req;
  213. waiting_req.func = starpu_mpi_wait_func;
  214. submit_mpi_req(&waiting_req);
  215. /* We wait for the MPI request to finish */
  216. PTHREAD_MUTEX_LOCK(&req->req_mutex);
  217. while (!req->completed)
  218. PTHREAD_COND_WAIT(&req->req_cond, &req->req_mutex);
  219. PTHREAD_MUTEX_UNLOCK(&req->req_mutex);
  220. ret = req->ret;
  221. /* The internal request structure was automatically allocated */
  222. *public_req = NULL;
  223. free(req);
  224. return ret;
  225. }
  226. /*
  227. * Test
  228. */
  229. static void starpu_mpi_test_func(struct starpu_mpi_req_s *testing_req)
  230. {
  231. /* Which is the mpi request we are testing for ? */
  232. struct starpu_mpi_req_s *req = testing_req->other_request;
  233. // fprintf(stderr, "<<<< STARPU MPI >>>> Test request %p - mpitag %x - TYPE %s %d\n", &req->request, req->mpi_tag, (req->request_type == RECV_REQ)?"recv : source":"send : dest", req->srcdst);
  234. int ret = MPI_Test(&req->request, testing_req->flag, testing_req->status);
  235. if (*testing_req->flag)
  236. {
  237. testing_req->ret = ret;
  238. handle_request_termination(req);
  239. }
  240. PTHREAD_MUTEX_LOCK(&testing_req->req_mutex);
  241. testing_req->completed = 1;
  242. pthread_cond_signal(&testing_req->req_cond);
  243. PTHREAD_MUTEX_UNLOCK(&testing_req->req_mutex);
  244. }
  245. int starpu_mpi_test(starpu_mpi_req *public_req, int *flag, MPI_Status *status)
  246. {
  247. int ret = 0;
  248. STARPU_ASSERT(public_req);
  249. struct starpu_mpi_req_s *req = *public_req;
  250. STARPU_ASSERT(!req->detached);
  251. PTHREAD_MUTEX_LOCK(&req->req_mutex);
  252. unsigned submitted = req->submitted;
  253. PTHREAD_MUTEX_UNLOCK(&req->req_mutex);
  254. if (submitted)
  255. {
  256. struct starpu_mpi_req_s testing_req;
  257. memset(&testing_req, 0, sizeof(struct starpu_mpi_req_s));
  258. /* Initialize the request structure */
  259. PTHREAD_MUTEX_INIT(&testing_req.req_mutex, NULL);
  260. PTHREAD_COND_INIT(&testing_req.req_cond, NULL);
  261. testing_req.flag = flag;
  262. testing_req.status = status;
  263. testing_req.other_request = req;
  264. testing_req.func = starpu_mpi_test_func;
  265. testing_req.completed = 0;
  266. submit_mpi_req(&testing_req);
  267. /* We wait for the test request to finish */
  268. PTHREAD_MUTEX_LOCK(&testing_req.req_mutex);
  269. while (!testing_req.completed)
  270. PTHREAD_COND_WAIT(&testing_req.req_cond, &testing_req.req_mutex);
  271. PTHREAD_MUTEX_UNLOCK(&testing_req.req_mutex);
  272. ret = testing_req.ret;
  273. if (*testing_req.flag)
  274. {
  275. /* The request was completed so we free the internal
  276. * request structure which was automatically allocated
  277. * */
  278. *public_req = NULL;
  279. free(req);
  280. }
  281. }
  282. else {
  283. *flag = 0;
  284. }
  285. return ret;
  286. }
  287. /*
  288. * Requests
  289. */
  290. static void handle_request_termination(struct starpu_mpi_req_s *req)
  291. {
  292. MPI_Type_free(&req->datatype);
  293. starpu_data_release_from_mem(req->data_handle);
  294. #ifdef VERBOSE_STARPU_MPI
  295. int rank;
  296. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  297. fprintf(stderr, "<<<< STARPU MPI >>>> Rank %d : complete MPI (%s %d) req %p - tag %x\n", rank, (req->request_type == RECV_REQ)?"recv : source":"send : dest", req->srcdst, &req->request, req->mpi_tag);
  298. #endif
  299. if (req->request_type == RECV_REQ)
  300. {
  301. TRACE_MPI_IRECV_END(req->srcdst, req->mpi_tag);
  302. }
  303. /* Execute the specified callback, if any */
  304. if (req->callback)
  305. req->callback(req->callback_arg);
  306. /* tell anyone potentiallly waiting on the request that it is
  307. * terminated now */
  308. PTHREAD_MUTEX_LOCK(&req->req_mutex);
  309. req->completed = 1;
  310. PTHREAD_COND_BROADCAST(&req->req_cond);
  311. PTHREAD_MUTEX_UNLOCK(&req->req_mutex);
  312. }
  313. static void submit_mpi_req(void *arg)
  314. {
  315. struct starpu_mpi_req_s *req = arg;
  316. PTHREAD_MUTEX_LOCK(&mutex);
  317. starpu_mpi_req_list_push_front(new_requests, req);
  318. PTHREAD_COND_BROADCAST(&cond);
  319. PTHREAD_MUTEX_UNLOCK(&mutex);
  320. }
  321. /*
  322. * Scheduler hook
  323. */
  324. static unsigned progression_hook_func(void *arg __attribute__((unused)))
  325. {
  326. unsigned may_block = 1;
  327. PTHREAD_MUTEX_LOCK(&mutex);
  328. if (!starpu_mpi_req_list_empty(detached_requests))
  329. {
  330. pthread_cond_signal(&cond);
  331. may_block = 0;
  332. }
  333. PTHREAD_MUTEX_UNLOCK(&mutex);
  334. return may_block;
  335. }
  336. /*
  337. * Progression loop
  338. */
  339. static void test_detached_requests(void)
  340. {
  341. int flag;
  342. MPI_Status status;
  343. struct starpu_mpi_req_s *req, *next_req;
  344. PTHREAD_MUTEX_LOCK(&detached_requests_mutex);
  345. for (req = starpu_mpi_req_list_begin(detached_requests);
  346. req != starpu_mpi_req_list_end(detached_requests);
  347. req = next_req)
  348. {
  349. next_req = starpu_mpi_req_list_next(req);
  350. PTHREAD_MUTEX_UNLOCK(&detached_requests_mutex);
  351. int ret = MPI_Test(&req->request, &flag, &status);
  352. STARPU_ASSERT(ret == MPI_SUCCESS);
  353. #ifdef VERBOSE_STARPU_MPI
  354. // if ((req->mpi_tag == 0x20003) || (req->mpi_tag == 0x30003))
  355. // if (0)
  356. if ((req->mpi_tag == 0x20003))
  357. {
  358. int rank;
  359. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  360. fprintf(stderr, "<<<< STARPU MPI >>>> Rank %d Test request %p - mpitag %x - TYPE %s %d\n", rank, &req->request, req->mpi_tag, (req->request_type == RECV_REQ)?"recv : source":"send : dest", req->srcdst);
  361. }
  362. #endif
  363. if (flag)
  364. {
  365. handle_request_termination(req);
  366. }
  367. PTHREAD_MUTEX_LOCK(&detached_requests_mutex);
  368. if (flag)
  369. starpu_mpi_req_list_erase(detached_requests, req);
  370. #warning TODO fix memleak
  371. /* Detached requests are automatically allocated by the lib */
  372. //if (req->detached)
  373. // free(req);
  374. }
  375. PTHREAD_MUTEX_UNLOCK(&detached_requests_mutex);
  376. }
  377. static void handle_new_request(struct starpu_mpi_req_s *req)
  378. {
  379. STARPU_ASSERT(req);
  380. /* submit the request to MPI */
  381. req->func(req);
  382. if (req->detached)
  383. {
  384. PTHREAD_MUTEX_LOCK(&mutex);
  385. starpu_mpi_req_list_push_front(detached_requests, req);
  386. PTHREAD_MUTEX_UNLOCK(&mutex);
  387. starpu_wake_all_blocked_workers();
  388. /* put the submitted request into the list of pending requests
  389. * so that it can be handled by the progression mechanisms */
  390. PTHREAD_MUTEX_LOCK(&mutex);
  391. pthread_cond_signal(&cond);
  392. PTHREAD_MUTEX_UNLOCK(&mutex);
  393. }
  394. }
  395. static void *progress_thread_func(void *arg __attribute__((unused)))
  396. {
  397. /* notify the main thread that the progression thread is ready */
  398. PTHREAD_MUTEX_LOCK(&mutex);
  399. running = 1;
  400. pthread_cond_signal(&cond);
  401. PTHREAD_MUTEX_UNLOCK(&mutex);
  402. PTHREAD_MUTEX_LOCK(&mutex);
  403. while (running) {
  404. /* shall we block ? */
  405. unsigned block = starpu_mpi_req_list_empty(new_requests);
  406. #ifndef USE_STARPU_ACTIVITY
  407. block = block && starpu_mpi_req_list_empty(detached_requests);
  408. #endif
  409. if (block)
  410. {
  411. // int rank;
  412. // MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  413. // if (rank == 3)
  414. // fprintf(stderr, "<<<< STARPU MPI >>>> Rank %d NO MORE REQUESTS TO HANDLE\n", rank);
  415. PTHREAD_COND_WAIT(&cond, &mutex);
  416. }
  417. if (!running)
  418. break;
  419. /* test whether there are some terminated "detached request" */
  420. PTHREAD_MUTEX_UNLOCK(&mutex);
  421. test_detached_requests();
  422. PTHREAD_MUTEX_LOCK(&mutex);
  423. /* get one request */
  424. struct starpu_mpi_req_s *req;
  425. while (!starpu_mpi_req_list_empty(new_requests))
  426. {
  427. req = starpu_mpi_req_list_pop_back(new_requests);
  428. /* handling a request is likely to block for a while
  429. * (on a sync_data_with_mem call), we want to let the
  430. * application submit requests in the meantime, so we
  431. * release the lock. */
  432. PTHREAD_MUTEX_UNLOCK(&mutex);
  433. handle_new_request(req);
  434. PTHREAD_MUTEX_LOCK(&mutex);
  435. }
  436. }
  437. PTHREAD_MUTEX_UNLOCK(&mutex);
  438. return NULL;
  439. }
  440. /*
  441. * (De)Initialization methods
  442. */
  443. #ifdef USE_STARPU_ACTIVITY
  444. static int hookid = - 1;
  445. #endif
  446. static void _starpu_mpi_add_sync_point_in_fxt(void)
  447. {
  448. #ifdef STARPU_USE_FXT
  449. int rank;
  450. int worldsize;
  451. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  452. MPI_Comm_size(MPI_COMM_WORLD, &worldsize);
  453. int barrier_ret = MPI_Barrier(MPI_COMM_WORLD);
  454. STARPU_ASSERT(barrier_ret == MPI_SUCCESS);
  455. /* We generate a "unique" key so that we can make sure that different
  456. * FxT traces come from the same MPI run. */
  457. int random_number;
  458. /* XXX perhaps we don't want to generate a new seed if the application
  459. * specified some reproductible behaviour ? */
  460. if (rank == 0)
  461. {
  462. srand(time(NULL));
  463. random_number = rand();
  464. }
  465. MPI_Bcast(&random_number, 1, MPI_INT, 0, MPI_COMM_WORLD);
  466. TRACE_MPI_BARRIER(rank, worldsize, random_number);
  467. #ifdef STARPU_VERBOSE
  468. fprintf(stderr, "StarPU MPI (rank %d): unique key %x\n", rank, random_number);
  469. #endif
  470. #endif
  471. }
  472. int starpu_mpi_initialize(void)
  473. {
  474. PTHREAD_MUTEX_INIT(&mutex, NULL);
  475. PTHREAD_COND_INIT(&cond, NULL);
  476. new_requests = starpu_mpi_req_list_new();
  477. PTHREAD_MUTEX_INIT(&detached_requests_mutex, NULL);
  478. detached_requests = starpu_mpi_req_list_new();
  479. int ret = pthread_create(&progress_thread, NULL, progress_thread_func, NULL);
  480. PTHREAD_MUTEX_LOCK(&mutex);
  481. while (!running)
  482. PTHREAD_COND_WAIT(&cond, &mutex);
  483. PTHREAD_MUTEX_UNLOCK(&mutex);
  484. #ifdef USE_STARPU_ACTIVITY
  485. hookid = starpu_progression_hook_register(progression_hook_func, NULL);
  486. STARPU_ASSERT(hookid >= 0);
  487. #endif
  488. _starpu_mpi_add_sync_point_in_fxt();
  489. return 0;
  490. }
  491. int starpu_mpi_shutdown(void)
  492. {
  493. void *value;
  494. /* kill the progression thread */
  495. PTHREAD_MUTEX_LOCK(&mutex);
  496. running = 0;
  497. PTHREAD_COND_BROADCAST(&cond);
  498. PTHREAD_MUTEX_UNLOCK(&mutex);
  499. pthread_join(progress_thread, &value);
  500. #ifdef USE_STARPU_ACTIVITY
  501. starpu_progression_hook_deregister(hookid);
  502. #endif
  503. /* free the request queues */
  504. starpu_mpi_req_list_delete(detached_requests);
  505. starpu_mpi_req_list_delete(new_requests);
  506. return 0;
  507. }