starpu_mpi.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013,2016 Inria
  4. * Copyright (C) 2010-2019 CNRS
  5. * Copyright (C) 2009-2012,2014-2018 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #ifndef __STARPU_MPI_H__
  19. #define __STARPU_MPI_H__
  20. #include <starpu.h>
  21. #if defined(STARPU_USE_MPI)
  22. #include <mpi.h>
  23. #include <stdint.h>
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. /**
  29. @defgroup API_MPI_Support MPI Support
  30. @{
  31. */
  32. /**
  33. @name Initialisation
  34. @{
  35. */
  36. /**
  37. Initialize the StarPU library with the given \p conf, and
  38. initialize the StarPU-MPI library with the given MPI communicator
  39. \p comm. \p initialize_mpi indicates if MPI should be initialized
  40. or not by StarPU. StarPU-MPI takes the opportunity to modify \p
  41. conf to either reserve a core for its MPI thread (by default), or
  42. execute MPI calls on the CPU driver 0 between tasks.
  43. */
  44. int starpu_mpi_init_conf(int *argc, char ***argv, int initialize_mpi, MPI_Comm comm, struct starpu_conf *conf);
  45. /**
  46. Same as starpu_mpi_init_conf(), except that this does not
  47. initialize the StarPU library. The caller thus has to call
  48. starpu_init() before this.
  49. */
  50. int starpu_mpi_init_comm(int *argc, char ***argv, int initialize_mpi, MPI_Comm comm);
  51. /**
  52. Call starpu_mpi_init_comm() with the MPI communicator \c MPI_COMM_WORLD.
  53. */
  54. int starpu_mpi_init(int *argc, char ***argv, int initialize_mpi);
  55. /**
  56. @deprecated
  57. This function has been made deprecated. One should use instead the
  58. function starpu_mpi_init(). This function does not call \c
  59. MPI_Init(), it should be called beforehand.
  60. */
  61. int starpu_mpi_initialize(void) STARPU_DEPRECATED;
  62. /**
  63. @deprecated
  64. This function has been made deprecated. One should use instead the
  65. function starpu_mpi_init(). MPI will be initialized by starpumpi by
  66. calling <c>MPI_Init_Thread(argc, argv, MPI_THREAD_SERIALIZED,
  67. ...)</c>.
  68. */
  69. int starpu_mpi_initialize_extended(int *rank, int *world_size) STARPU_DEPRECATED;
  70. /**
  71. Clean the starpumpi library. This must be called after calling any
  72. \c starpu_mpi functions and before the call to starpu_shutdown(),
  73. if any. \c MPI_Finalize() will be called if StarPU-MPI has been
  74. initialized by starpu_mpi_init().
  75. */
  76. int starpu_mpi_shutdown(void);
  77. /**
  78. Retrieve the current amount of communications from the current node
  79. in the array \p comm_amounts which must have a size greater or
  80. equal to the world size. Communications statistics must be enabled
  81. (see \ref STARPU_COMM_STATS).
  82. */
  83. void starpu_mpi_comm_amounts_retrieve(size_t *comm_amounts);
  84. /**
  85. Return in \p size the size of the communicator \p comm
  86. */
  87. int starpu_mpi_comm_size(MPI_Comm comm, int *size);
  88. /**
  89. Return in \p rank the rank of the calling process in the
  90. communicator \p comm
  91. */
  92. int starpu_mpi_comm_rank(MPI_Comm comm, int *rank);
  93. /**
  94. Return the rank of the calling process in the communicator \c
  95. MPI_COMM_WORLD
  96. */
  97. int starpu_mpi_world_rank(void);
  98. /**
  99. Return the size of the communicator \c MPI_COMM_WORLD
  100. */
  101. int starpu_mpi_world_size(void);
  102. /**
  103. When given to the function starpu_mpi_comm_get_attr(), retrieve the
  104. value for the upper bound for tag value.
  105. */
  106. #define STARPU_MPI_TAG_UB MPI_TAG_UB
  107. /**
  108. Retrieve an attribute value by key, similarly to the MPI function
  109. \c MPI_comm_get_attr(), except that the value is a pointer to
  110. int64_t instead of int. If an attribute is attached on \p comm to
  111. \p keyval, then the call returns \p flag equal to \c 1, and the
  112. attribute value in \p attribute_val. Otherwise, \p flag is set to
  113. \0.
  114. */
  115. int starpu_mpi_comm_get_attr(MPI_Comm comm, int keyval, void *attribute_val, int *flag);
  116. int starpu_mpi_get_communication_tag(void);
  117. void starpu_mpi_set_communication_tag(int tag);
  118. /** @} */
  119. /**
  120. @name Communication
  121. \anchor MPIPtpCommunication
  122. @{
  123. */
  124. /**
  125. Opaque type for communication request
  126. */
  127. typedef void *starpu_mpi_req;
  128. /**
  129. Define the type which can be used to set communication tag when exchanging data.
  130. */
  131. typedef int64_t starpu_mpi_tag_t;
  132. /**
  133. Post a standard-mode, non blocking send of \p data_handle to the
  134. node \p dest using the message tag \p data_tag within the
  135. communicator \p comm. After the call, the pointer to the request \p
  136. req can be used to test or to wait for the completion of the
  137. communication.
  138. */
  139. int starpu_mpi_isend(starpu_data_handle_t data_handle, starpu_mpi_req *req, int dest, starpu_mpi_tag_t data_tag, MPI_Comm comm);
  140. /**
  141. Similar to starpu_mpi_isend(), but take a priority \p prio.
  142. */
  143. int starpu_mpi_isend_prio(starpu_data_handle_t data_handle, starpu_mpi_req *req, int dest, starpu_mpi_tag_t data_tag, int prio, MPI_Comm comm);
  144. /**
  145. Post a nonblocking receive in \p data_handle from the node \p
  146. source using the message tag \p data_tag within the communicator \p
  147. comm. After the call, the pointer to the request \p req can be used
  148. to test or to wait for the completion of the communication.
  149. */
  150. int starpu_mpi_irecv(starpu_data_handle_t data_handle, starpu_mpi_req *req, int source, starpu_mpi_tag_t data_tag, MPI_Comm comm);
  151. /**
  152. Perform a standard-mode, blocking send of \p data_handle to the
  153. node \p dest using the message tag \p data_tag within the
  154. communicator \p comm.
  155. */
  156. int starpu_mpi_send(starpu_data_handle_t data_handle, int dest, starpu_mpi_tag_t data_tag, MPI_Comm comm);
  157. /**
  158. Similar to starpu_mpi_send(), but take a priority \p prio.
  159. */
  160. int starpu_mpi_send_prio(starpu_data_handle_t data_handle, int dest, starpu_mpi_tag_t data_tag, int prio, MPI_Comm comm);
  161. /**
  162. Perform a standard-mode, blocking receive in \p data_handle from
  163. the node \p source using the message tag \p data_tag within the
  164. communicator \p comm.
  165. */
  166. int starpu_mpi_recv(starpu_data_handle_t data_handle, int source, starpu_mpi_tag_t data_tag, MPI_Comm comm, MPI_Status *status);
  167. /**
  168. Post a standard-mode, non blocking send of \p data_handle to the
  169. node \p dest using the message tag \p data_tag within the
  170. communicator \p comm. On completion, the \p callback function is
  171. called with the argument \p arg.
  172. Similarly to the pthread detached functionality, when a detached
  173. communication completes, its resources are automatically released
  174. back to the system, there is no need to test or to wait for the
  175. completion of the request.
  176. */
  177. int starpu_mpi_isend_detached(starpu_data_handle_t data_handle, int dest, starpu_mpi_tag_t data_tag, MPI_Comm comm, void (*callback)(void *), void *arg);
  178. /**
  179. Similar to starpu_mpi_isend_detached, but take a priority \p prio.
  180. */
  181. int starpu_mpi_isend_detached_prio(starpu_data_handle_t data_handle, int dest, starpu_mpi_tag_t data_tag, int prio, MPI_Comm comm, void (*callback)(void *), void *arg);
  182. /**
  183. Post a nonblocking receive in \p data_handle from the node \p
  184. source using the message tag \p data_tag within the communicator \p
  185. comm. On completion, the \p callback function is called with the
  186. argument \p arg.
  187. Similarly to the pthread detached functionality, when a detached
  188. communication completes, its resources are automatically released
  189. back to the system, there is no need to test or to wait for the
  190. completion of the request.
  191. */
  192. int starpu_mpi_irecv_detached(starpu_data_handle_t data_handle, int source, starpu_mpi_tag_t data_tag, MPI_Comm comm, void (*callback)(void *), void *arg);
  193. /**
  194. Post a nonblocking receive in \p data_handle from the node \p
  195. source using the message tag \p data_tag within the communicator \p
  196. comm. On completion, the \p callback function is called with the
  197. argument \p arg.
  198. The parameter \p sequential_consistency allows to enable or disable
  199. the sequential consistency for \p data handle (sequential
  200. consistency will be enabled or disabled based on the value of the
  201. parameter \p sequential_consistency and the value of the sequential
  202. consistency defined for \p data_handle).
  203. Similarly to the pthread detached functionality, when a detached
  204. communication completes, its resources are automatically released
  205. back to the system, there is no need to test or to wait for the
  206. completion of the request.
  207. */
  208. int starpu_mpi_irecv_detached_sequential_consistency(starpu_data_handle_t data_handle, int source, starpu_mpi_tag_t data_tag, MPI_Comm comm, void (*callback)(void *), void *arg, int sequential_consistency);
  209. /**
  210. Perform a synchronous-mode, non-blocking send of \p data_handle to
  211. the node \p dest using the message tag \p data_tag within the
  212. communicator \p comm.
  213. */
  214. int starpu_mpi_issend(starpu_data_handle_t data_handle, starpu_mpi_req *req, int dest, starpu_mpi_tag_t data_tag, MPI_Comm comm);
  215. /**
  216. Similar to starpu_mpi_issend(), but take a priority \p prio.
  217. */
  218. int starpu_mpi_issend_prio(starpu_data_handle_t data_handle, starpu_mpi_req *req, int dest, starpu_mpi_tag_t data_tag, int prio, MPI_Comm comm);
  219. /**
  220. Perform a synchronous-mode, non-blocking send of \p data_handle to
  221. the node \p dest using the message tag \p data_tag within the
  222. communicator \p comm. On completion, the \p callback function is
  223. called with the argument \p arg.
  224. Similarly to the pthread detached functionality, when a detached
  225. communication completes, its resources are automatically released
  226. back to the system, there is no need to test or to wait for the
  227. completion of the request.
  228. */
  229. int starpu_mpi_issend_detached(starpu_data_handle_t data_handle, int dest, starpu_mpi_tag_t data_tag, MPI_Comm comm, void (*callback)(void *), void *arg);
  230. /**
  231. Similar to starpu_mpi_issend_detached(), but take a priority \p prio.
  232. */
  233. int starpu_mpi_issend_detached_prio(starpu_data_handle_t data_handle, int dest, starpu_mpi_tag_t data_tag, int prio, MPI_Comm comm, void (*callback)(void *), void *arg);
  234. /**
  235. Return when the operation identified by request \p req is complete.
  236. */
  237. int starpu_mpi_wait(starpu_mpi_req *req, MPI_Status *status);
  238. /**
  239. If the operation identified by \p req is complete, set \p flag to
  240. 1. The \p status object is set to contain information on the
  241. completed operation.
  242. */
  243. int starpu_mpi_test(starpu_mpi_req *req, int *flag, MPI_Status *status);
  244. /**
  245. Block the caller until all group members of the communicator \p
  246. comm have called it.
  247. */
  248. int starpu_mpi_barrier(MPI_Comm comm);
  249. /**
  250. Wait until all StarPU tasks and communications for the given
  251. communicator are completed.
  252. */
  253. int starpu_mpi_wait_for_all(MPI_Comm comm);
  254. /**
  255. Post a standard-mode, non blocking send of \p data_handle to the
  256. node \p dest using the message tag \p data_tag within the
  257. communicator \p comm. On completion, \p tag is unlocked.
  258. */
  259. int starpu_mpi_isend_detached_unlock_tag(starpu_data_handle_t data_handle, int dest, starpu_mpi_tag_t data_tag, MPI_Comm comm, starpu_tag_t tag);
  260. /**
  261. Similar to starpu_mpi_isend_detached_unlock_tag(), but take a
  262. priority \p prio.
  263. */
  264. int starpu_mpi_isend_detached_unlock_tag_prio(starpu_data_handle_t data_handle, int dest, starpu_mpi_tag_t data_tag, int prio, MPI_Comm comm, starpu_tag_t tag);
  265. /**
  266. Post a nonblocking receive in \p data_handle from the node \p
  267. source using the message tag \p data_tag within the communicator \p
  268. comm. On completion, \p tag is unlocked.
  269. */
  270. int starpu_mpi_irecv_detached_unlock_tag(starpu_data_handle_t data_handle, int source, starpu_mpi_tag_t data_tag, MPI_Comm comm, starpu_tag_t tag);
  271. /**
  272. Post \p array_size standard-mode, non blocking send. Each post
  273. sends the n-th data of the array \p data_handle to the n-th node of
  274. the array \p dest using the n-th message tag of the array \p
  275. data_tag within the n-th communicator of the array \p comm. On
  276. completion of the all the requests, \p tag is unlocked.
  277. */
  278. int starpu_mpi_isend_array_detached_unlock_tag(unsigned array_size, starpu_data_handle_t *data_handle, int *dest, starpu_mpi_tag_t *data_tag, MPI_Comm *comm, starpu_tag_t tag);
  279. /**
  280. Similar to starpu_mpi_isend_array_detached_unlock_tag(), but take a
  281. priority \p prio.
  282. */
  283. int starpu_mpi_isend_array_detached_unlock_tag_prio(unsigned array_size, starpu_data_handle_t *data_handle, int *dest, starpu_mpi_tag_t *data_tag, int *prio, MPI_Comm *comm, starpu_tag_t tag);
  284. /**
  285. Post \p array_size nonblocking receive. Each post receives in the
  286. n-th data of the array \p data_handle from the n-th node of the
  287. array \p source using the n-th message tag of the array \p data_tag
  288. within the n-th communicator of the array \p comm. On completion of
  289. the all the requests, \p tag is unlocked.
  290. */
  291. int starpu_mpi_irecv_array_detached_unlock_tag(unsigned array_size, starpu_data_handle_t *data_handle, int *source, starpu_mpi_tag_t *data_tag, MPI_Comm *comm, starpu_tag_t tag);
  292. typedef void (*starpu_mpi_datatype_allocate_func_t)(starpu_data_handle_t, MPI_Datatype *);
  293. typedef void (*starpu_mpi_datatype_free_func_t)(MPI_Datatype *);
  294. /**
  295. Register functions to create and free a MPI datatype for the given
  296. handle.
  297. It is important that the function is called before any
  298. communication can take place for a data with the given handle. See
  299. \ref ExchangingUserDefinedDataInterface for an example.
  300. */
  301. int starpu_mpi_datatype_register(starpu_data_handle_t handle, starpu_mpi_datatype_allocate_func_t allocate_datatype_func, starpu_mpi_datatype_free_func_t free_datatype_func);
  302. /**
  303. Unregister the MPI datatype functions stored for the interface of
  304. the given handle.
  305. */
  306. int starpu_mpi_datatype_unregister(starpu_data_handle_t handle);
  307. /** @} */
  308. /**
  309. @name Communication Cache
  310. @{
  311. */
  312. /**
  313. Return 1 if the communication cache is enabled, 0 otherwise
  314. */
  315. int starpu_mpi_cache_is_enabled();
  316. /**
  317. If \p enabled is 1, enable the communication cache. Otherwise,
  318. clean the cache if it was enabled and disable it.
  319. */
  320. int starpu_mpi_cache_set(int enabled);
  321. /**
  322. Clear the send and receive communication cache for the data \p
  323. data_handle and invalidate the value. The function has to be called
  324. at the same point of task graph submission by all the MPI nodes on
  325. which the handle was registered. The function does nothing if the
  326. cache mechanism is disabled (see \ref STARPU_MPI_CACHE).
  327. */
  328. void starpu_mpi_cache_flush(MPI_Comm comm, starpu_data_handle_t data_handle);
  329. /**
  330. Clear the send and receive communication cache for all data and
  331. invalidate their values. The function has to be called at the same
  332. point of task graph submission by all the MPI nodes. The function
  333. does nothing if the cache mechanism is disabled (see \ref
  334. STARPU_MPI_CACHE).
  335. */
  336. void starpu_mpi_cache_flush_all_data(MPI_Comm comm);
  337. /**
  338. Test whether \p data_handle is cached for reception, i.e. the value
  339. was previously received from the owner node, and not flushed since
  340. then.
  341. */
  342. int starpu_mpi_cached_receive(starpu_data_handle_t data_handle);
  343. /**
  344. Test whether \p data_handle is cached for emission to node \p dest,
  345. i.e. the value was previously sent to \p dest, and not flushed
  346. since then.
  347. */
  348. int starpu_mpi_cached_send(starpu_data_handle_t data_handle, int dest);
  349. /** @} */
  350. /**
  351. @name MPI Insert Task
  352. @{
  353. */
  354. /**
  355. Can be used as rank when calling starpu_mpi_data_register() and
  356. alike, to specify that the data is per-node: each node will have
  357. its own value. Tasks writing to such data will be replicated on all
  358. nodes (and all parameters then have to be per-node). Tasks not
  359. writing to such data will just take the node-local value without
  360. any MPI communication.
  361. */
  362. #define STARPU_MPI_PER_NODE -2
  363. /**
  364. Register to MPI a StarPU data handle with the given tag, rank and
  365. MPI communicator. It also automatically clears the MPI
  366. communication cache when unregistering the data.
  367. */
  368. void starpu_mpi_data_register_comm(starpu_data_handle_t data_handle, starpu_mpi_tag_t data_tag, int rank, MPI_Comm comm);
  369. /**
  370. Register to MPI a StarPU data handle with the given tag, rank and
  371. the MPI communicator \c MPI_COMM_WORLD.
  372. It also automatically clears the MPI communication cache when
  373. unregistering the data.
  374. */
  375. #define starpu_mpi_data_register(data_handle, data_tag, rank) starpu_mpi_data_register_comm(data_handle, data_tag, rank, MPI_COMM_WORLD)
  376. /**
  377. Register to MPI a StarPU data handle with the given tag. No rank
  378. will be defined.
  379. It also automatically clears the MPI communication cache when
  380. unregistering the data.
  381. */
  382. void starpu_mpi_data_set_tag(starpu_data_handle_t handle, starpu_mpi_tag_t data_tag);
  383. /**
  384. Symbol kept for backward compatibility. Call function starpu_mpi_data_set_tag()
  385. */
  386. #define starpu_data_set_tag starpu_mpi_data_set_tag
  387. /**
  388. Register to MPI a StarPU data handle with the given rank and given
  389. communicator. No tag will be defined.
  390. It also automatically clears the MPI communication cache when
  391. unregistering the data.
  392. */
  393. void starpu_mpi_data_set_rank_comm(starpu_data_handle_t handle, int rank, MPI_Comm comm);
  394. /**
  395. Register to MPI a StarPU data handle with the given rank and the
  396. MPI communicator \c MPI_COMM_WORLD. No tag will be defined.
  397. It also automatically clears the MPI communication cache when
  398. unregistering the data.
  399. */
  400. #define starpu_mpi_data_set_rank(handle, rank) starpu_mpi_data_set_rank_comm(handle, rank, MPI_COMM_WORLD)
  401. /**
  402. Symbol kept for backward compatibility. Call function starpu_mpi_data_set_rank()
  403. */
  404. #define starpu_data_set_rank starpu_mpi_data_set_rank
  405. /**
  406. Return the rank of the given data.
  407. */
  408. int starpu_mpi_data_get_rank(starpu_data_handle_t handle);
  409. /**
  410. Symbol kept for backward compatibility. Call function starpu_mpi_data_get_rank()
  411. */
  412. #define starpu_data_get_rank starpu_mpi_data_get_rank
  413. /**
  414. Return the tag of the given data.
  415. */
  416. starpu_mpi_tag_t starpu_mpi_data_get_tag(starpu_data_handle_t handle);
  417. /**
  418. Symbol kept for backward compatibility. Call function starpu_mpi_data_get_tag()
  419. */
  420. #define starpu_data_get_tag starpu_mpi_data_get_tag
  421. /**
  422. Create and submit a task corresponding to codelet with the
  423. following arguments. The argument list must be zero-terminated.
  424. The arguments following the codelet are the same types as for the
  425. function starpu_task_insert().
  426. Access modes for data can also be
  427. set with ::STARPU_SSEND to specify the data has to be sent using a
  428. synchronous and non-blocking mode (see starpu_mpi_issend()).
  429. The extra argument ::STARPU_EXECUTE_ON_NODE followed by an integer
  430. allows to specify the MPI node to execute the codelet. It is also
  431. possible to specify that the node owning a specific data will
  432. execute the codelet, by using ::STARPU_EXECUTE_ON_DATA followed by
  433. a data handle.
  434. The internal algorithm is as follows:
  435. <ol>
  436. <li>
  437. Find out which MPI node is going to execute the codelet.
  438. <ul>
  439. <li>
  440. If there is only one node owning data in ::STARPU_W mode, it
  441. will be selected;
  442. <li>
  443. If there is several nodes owning data in ::STARPU_W mode, a
  444. node will be selected according to a given node selection
  445. policy (see ::STARPU_NODE_SELECTION_POLICY or
  446. starpu_mpi_node_selection_set_current_policy())
  447. <li>
  448. The argument ::STARPU_EXECUTE_ON_NODE followed by an integer
  449. can be used to specify the node;
  450. <li>
  451. The argument ::STARPU_EXECUTE_ON_DATA followed by a data handle can be used to specify that the node owing the given data will execute the codelet.
  452. </ul>
  453. </li>
  454. <li>
  455. Send and receive data as requested. Nodes owning data which need to
  456. be read by the task are sending them to the MPI node which will
  457. execute it. The latter receives them.
  458. </li>
  459. <li>
  460. Execute the codelet. This is done by the MPI node selected in the
  461. 1st step of the algorithm.
  462. </li>
  463. <li>
  464. If several MPI nodes own data to be written to, send written data
  465. back to their owners.
  466. </li>
  467. </ol>
  468. The algorithm also includes a communication cache mechanism that
  469. allows not to send data twice to the same MPI node, unless the data
  470. has been modified. The cache can be disabled (see \ref
  471. STARPU_MPI_CACHE).
  472. */
  473. int starpu_mpi_task_insert(MPI_Comm comm, struct starpu_codelet *codelet, ...);
  474. /**
  475. Call starpu_mpi_task_insert(). Symbol kept for backward compatibility.
  476. */
  477. int starpu_mpi_insert_task(MPI_Comm comm, struct starpu_codelet *codelet, ...);
  478. /**
  479. Create a task corresponding to \p codelet with the following given
  480. arguments. The argument list must be zero-terminated. The function
  481. performs the first two steps of the function
  482. starpu_mpi_task_insert(), i.e. submitting the MPI communications
  483. needed before the execution of the task, and the creation of the
  484. task on one node. Only the MPI node selected in the first step of
  485. the algorithm will return a valid task structure which can then be
  486. submitted, others will return <c>NULL</c>. The function
  487. starpu_mpi_task_post_build() MUST be called after that on all
  488. nodes, and after the submission of the task on the node which
  489. creates it, with the SAME list of arguments.
  490. */
  491. struct starpu_task *starpu_mpi_task_build(MPI_Comm comm, struct starpu_codelet *codelet, ...);
  492. /**
  493. MUST be called after a call to starpu_mpi_task_build(),
  494. with the SAME list of arguments. Perform the fourth -- last -- step of
  495. the algorithm described in starpu_mpi_task_insert().
  496. */
  497. int starpu_mpi_task_post_build(MPI_Comm comm, struct starpu_codelet *codelet, ...);
  498. /**
  499. Transfer data \p data_handle to MPI node \p node, sending it from
  500. its owner if needed. At least the target node and the owner have to
  501. call the function.
  502. */
  503. void starpu_mpi_get_data_on_node(MPI_Comm comm, starpu_data_handle_t data_handle, int node);
  504. /**
  505. Transfer data \p data_handle to MPI node \p node, sending it from
  506. its owner if needed. At least the target node and the owner have to
  507. call the function. On reception, the \p callback function is called
  508. with the argument \p arg.
  509. */
  510. void starpu_mpi_get_data_on_node_detached(MPI_Comm comm, starpu_data_handle_t data_handle, int node, void (*callback)(void*), void *arg);
  511. /**
  512. Transfer data \p data_handle to all MPI nodes, sending it from its
  513. owner if needed. All nodes have to call the function.
  514. */
  515. void starpu_mpi_get_data_on_all_nodes_detached(MPI_Comm comm, starpu_data_handle_t data_handle);
  516. /**
  517. Submit migration of the data onto the \p new_rank MPI node. This
  518. means both submitting the transfer of the data to node \p new_rank
  519. if it hasn't been submitted already, and setting the home node of
  520. the data to the new node. Further data transfers submitted by
  521. starpu_mpi_task_insert() will be done from that new node. This
  522. function thus needs to be called on all nodes which have registered
  523. the data at the same point of tasks submissions. This also flushes
  524. the cache for this data to avoid incoherencies.
  525. */
  526. void starpu_mpi_data_migrate(MPI_Comm comm, starpu_data_handle_t handle, int new_rank);
  527. /** @} */
  528. /**
  529. @name Node Selection Policy
  530. \anchor MPINodeSelectionPolicy
  531. @{
  532. */
  533. #define STARPU_MPI_NODE_SELECTION_CURRENT_POLICY -1
  534. #define STARPU_MPI_NODE_SELECTION_MOST_R_DATA 0
  535. typedef int (*starpu_mpi_select_node_policy_func_t)(int me, int nb_nodes, struct starpu_data_descr *descr, int nb_data);
  536. /**
  537. Register a new policy which can then be used when there is several
  538. nodes owning data in ::STARPU_W mode.
  539. Here an example of function defining a node selection policy.
  540. The codelet will be executed on the node owing the first data with
  541. a size bigger than 1M, or on the node 0 if no data fits the given
  542. size.
  543. \code{.c}
  544. int my_node_selection_policy(int me, int nb_nodes, struct starpu_data_descr *descr, int nb_data)
  545. {
  546. // me is the current MPI rank
  547. // nb_nodes is the number of MPI nodes
  548. // descr is the description of the data specified when calling starpu_mpi_task_insert
  549. // nb_data is the number of data in descr
  550. int i;
  551. for(i= 0 ; i<nb_data ; i++)
  552. {
  553. starpu_data_handle_t data = descr[i].handle;
  554. enum starpu_data_access_mode mode = descr[i].mode;
  555. if (mode & STARPU_R)
  556. {
  557. int rank = starpu_data_get_rank(data);
  558. size_t size = starpu_data_get_size(data);
  559. if (size > 1024*1024) return rank;
  560. }
  561. }
  562. return 0;
  563. }
  564. \endcode
  565. */
  566. int starpu_mpi_node_selection_register_policy(starpu_mpi_select_node_policy_func_t policy_func);
  567. /**
  568. Unregister a previously registered policy.
  569. */
  570. int starpu_mpi_node_selection_unregister_policy(int policy);
  571. /**
  572. Return the current policy used to select the node which will
  573. execute the codelet
  574. */
  575. int starpu_mpi_node_selection_get_current_policy();
  576. /**
  577. Set the current policy used to select the node which will execute
  578. the codelet. The policy ::STARPU_MPI_NODE_SELECTION_MOST_R_DATA
  579. selects the node having the most data in ::STARPU_R mode so as to
  580. minimize the amount of data to be transfered.
  581. */
  582. int starpu_mpi_node_selection_set_current_policy(int policy);
  583. /** @} */
  584. /**
  585. @name Collective Operations
  586. \anchor MPICollectiveOperations
  587. @{
  588. */
  589. /**
  590. Perform a reduction on the given data \p handle. All nodes send the
  591. data to its owner node which will perform a reduction.
  592. */
  593. void starpu_mpi_redux_data(MPI_Comm comm, starpu_data_handle_t data_handle);
  594. /**
  595. Similar to starpu_mpi_redux_data, but take a priority \p prio.
  596. */
  597. void starpu_mpi_redux_data_prio(MPI_Comm comm, starpu_data_handle_t data_handle, int prio);
  598. /**
  599. Scatter data among processes of the communicator based on the
  600. ownership of the data. For each data of the array \p data_handles,
  601. the process \p root sends the data to the process owning this data.
  602. Processes receiving data must have valid data handles to receive
  603. them. On completion of the collective communication, the \p
  604. scallback function is called with the argument \p sarg on the
  605. process \p root, the \p rcallback function is called with the
  606. argument \p rarg on any other process.
  607. */
  608. int starpu_mpi_scatter_detached(starpu_data_handle_t *data_handles, int count, int root, MPI_Comm comm, void (*scallback)(void *), void *sarg, void (*rcallback)(void *), void *rarg);
  609. /**
  610. Gather data from the different processes of the communicator onto
  611. the process \p root. Each process owning data handle in the array
  612. \p data_handles will send them to the process \p root. The process
  613. \p root must have valid data handles to receive the data. On
  614. completion of the collective communication, the \p rcallback
  615. function is called with the argument \p rarg on the process root,
  616. the \p scallback function is called with the argument \p sarg on
  617. any other process.
  618. */
  619. int starpu_mpi_gather_detached(starpu_data_handle_t *data_handles, int count, int root, MPI_Comm comm, void (*scallback)(void *), void *sarg, void (*rcallback)(void *), void *rarg);
  620. /** @} */
  621. int starpu_mpi_pre_submit_hook_register(void (*f)(struct starpu_task *));
  622. int starpu_mpi_pre_submit_hook_unregister();
  623. /** @} */
  624. #ifdef __cplusplus
  625. }
  626. #endif
  627. #endif // STARPU_USE_MPI
  628. #endif // __STARPU_MPI_H__