starpu_mpi.c 17 KB

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