starpu_mpi_private.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2012-2017 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 CNRS
  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. #ifndef __STARPU_MPI_PRIVATE_H__
  18. #define __STARPU_MPI_PRIVATE_H__
  19. #include <starpu.h>
  20. #include <common/config.h>
  21. #include <common/uthash.h>
  22. #include "starpu_mpi.h"
  23. #include "starpu_mpi_fxt.h"
  24. #include <common/list.h>
  25. #include <core/simgrid.h>
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #ifdef STARPU_SIMGRID
  30. starpu_pthread_wait_t wait;
  31. starpu_pthread_queue_t dontsleep;
  32. struct _starpu_simgrid_mpi_req
  33. {
  34. MPI_Request *request;
  35. MPI_Status *status;
  36. starpu_pthread_queue_t *queue;
  37. unsigned *done;
  38. };
  39. int _starpu_mpi_simgrid_mpi_test(unsigned *done, int *flag);
  40. void _starpu_mpi_simgrid_wait_req(MPI_Request *request, MPI_Status *status, starpu_pthread_queue_t *queue, unsigned *done);
  41. #endif
  42. extern int _starpu_debug_rank;
  43. char *_starpu_mpi_get_mpi_error_code(int code);
  44. extern int _starpu_mpi_comm;
  45. #ifdef STARPU_VERBOSE
  46. extern int _starpu_debug_level_min;
  47. extern int _starpu_debug_level_max;
  48. void _starpu_mpi_set_debug_level_min(int level);
  49. void _starpu_mpi_set_debug_level_max(int level);
  50. #endif
  51. extern int _starpu_mpi_fake_world_size;
  52. extern int _starpu_mpi_fake_world_rank;
  53. #ifdef STARPU_NO_ASSERT
  54. # define STARPU_MPI_ASSERT_MSG(x, msg, ...) do { if (0) { (void) (x); }} while(0)
  55. #else
  56. # if defined(__CUDACC__) && defined(STARPU_HAVE_WINDOWS)
  57. int _starpu_debug_rank;
  58. # define STARPU_MPI_ASSERT_MSG(x, msg, ...) \
  59. do \
  60. { \
  61. if (STARPU_UNLIKELY(!(x))) \
  62. { \
  63. if (_starpu_debug_rank == -1) starpu_mpi_comm_rank(MPI_COMM_WORLD, &_starpu_debug_rank); \
  64. fprintf(stderr, "\n[%d][starpu_mpi][%s][assert failure] " msg "\n\n", _starpu_debug_rank, __starpu_func__, ## __VA_ARGS__); *(int*)NULL = 0; \
  65. } \
  66. } while(0)
  67. # else
  68. # define STARPU_MPI_ASSERT_MSG(x, msg, ...) \
  69. do \
  70. { \
  71. if (STARPU_UNLIKELY(!(x))) \
  72. { \
  73. if (_starpu_debug_rank == -1) starpu_mpi_comm_rank(MPI_COMM_WORLD, &_starpu_debug_rank); \
  74. fprintf(stderr, "\n[%d][starpu_mpi][%s][assert failure] " msg "\n\n", _starpu_debug_rank, __starpu_func__, ## __VA_ARGS__); \
  75. } \
  76. assert(x); \
  77. } while(0)
  78. # endif
  79. #endif
  80. #define _STARPU_MPI_MALLOC(ptr, size) do { ptr = malloc(size); STARPU_MPI_ASSERT_MSG(ptr != NULL, "Cannot allocate %ld bytes\n", (long) size); } while (0)
  81. #define _STARPU_MPI_CALLOC(ptr, nmemb, size) do { ptr = calloc(nmemb, size); STARPU_MPI_ASSERT_MSG(ptr != NULL, "Cannot allocate %ld bytes\n", (long) (nmemb*size)); } while (0)
  82. #define _STARPU_MPI_REALLOC(ptr, size) do { ptr = realloc(ptr, size); STARPU_MPI_ASSERT_MSG(ptr != NULL, "Cannot reallocate %ld bytes\n", (long) size); } while (0)
  83. #ifdef STARPU_VERBOSE
  84. # define _STARPU_MPI_COMM_DEBUG(count, datatype, node, tag, utag, comm, way) \
  85. do \
  86. { \
  87. if (_starpu_mpi_comm) \
  88. { \
  89. int __size; \
  90. char _comm_name[128]; \
  91. int _comm_name_len; \
  92. int _rank; \
  93. starpu_mpi_comm_rank(comm, &_rank); \
  94. MPI_Type_size(datatype, &__size); \
  95. MPI_Comm_get_name(comm, _comm_name, &_comm_name_len); \
  96. fprintf(stderr, "[%d][starpu_mpi] %s %d:%d(%d):%s %12s %ld [%s:%d]\n", _rank, way, node, tag, utag, _comm_name, " ", count*__size, __starpu_func__ , __LINE__); \
  97. fflush(stderr); \
  98. } \
  99. } while(0);
  100. # define _STARPU_MPI_COMM_TO_DEBUG(count, datatype, dest, tag, utag, comm) _STARPU_MPI_COMM_DEBUG(count, datatype, dest, tag, utag, comm, "-->")
  101. # define _STARPU_MPI_COMM_FROM_DEBUG(count, datatype, source, tag, utag, comm) _STARPU_MPI_COMM_DEBUG(count, datatype, source, tag, utag, comm, "<--")
  102. # define _STARPU_MPI_DEBUG(level, fmt, ...) \
  103. do \
  104. { \
  105. if (!_starpu_silent && _starpu_debug_level_min <= level && level <= _starpu_debug_level_max) \
  106. { \
  107. if (_starpu_debug_rank == -1) starpu_mpi_comm_rank(MPI_COMM_WORLD, &_starpu_debug_rank); \
  108. fprintf(stderr, "%*s[%d][starpu_mpi][%s:%d] " fmt , (_starpu_debug_rank+1)*4, "", _starpu_debug_rank, __starpu_func__ , __LINE__,## __VA_ARGS__); \
  109. fflush(stderr); \
  110. } \
  111. } while(0);
  112. #else
  113. # define _STARPU_MPI_COMM_DEBUG(count, datatype, node, tag, utag, comm, way) do { } while(0)
  114. # define _STARPU_MPI_COMM_TO_DEBUG(count, datatype, dest, tag, comm, utag) do { } while(0)
  115. # define _STARPU_MPI_COMM_FROM_DEBUG(count, datatype, source, tag, comm, utag) do { } while(0)
  116. # define _STARPU_MPI_DEBUG(level, fmt, ...) do { } while(0)
  117. #endif
  118. #define _STARPU_MPI_DISP(fmt, ...) do { if (!_starpu_silent) { \
  119. if (_starpu_debug_rank == -1) starpu_mpi_comm_rank(MPI_COMM_WORLD, &_starpu_debug_rank); \
  120. fprintf(stderr, "%*s[%d][starpu_mpi][%s:%d] " fmt , (_starpu_debug_rank+1)*4, "", _starpu_debug_rank, __starpu_func__ , __LINE__ ,## __VA_ARGS__); \
  121. fflush(stderr); }} while(0);
  122. #define _STARPU_MPI_MSG(fmt, ...) do { if (_starpu_debug_rank == -1) starpu_mpi_comm_rank(MPI_COMM_WORLD, &_starpu_debug_rank); \
  123. fprintf(stderr, "[%d][starpu_mpi][%s:%d] " fmt , _starpu_debug_rank, __starpu_func__ , __LINE__ ,## __VA_ARGS__); \
  124. fflush(stderr); } while(0);
  125. #ifdef STARPU_VERBOSE
  126. # define _STARPU_MPI_LOG_IN() do { if (!_starpu_silent) { \
  127. if (_starpu_debug_rank == -1) starpu_mpi_comm_rank(MPI_COMM_WORLD, &_starpu_debug_rank); \
  128. fprintf(stderr, "%*s[%d][starpu_mpi][%s:%d] -->\n", (_starpu_debug_rank+1)*4, "", _starpu_debug_rank, __starpu_func__ , __LINE__); \
  129. fflush(stderr); }} while(0)
  130. # define _STARPU_MPI_LOG_OUT() do { if (!_starpu_silent) { \
  131. if (_starpu_debug_rank == -1) starpu_mpi_comm_rank(MPI_COMM_WORLD, &_starpu_debug_rank); \
  132. fprintf(stderr, "%*s[%d][starpu_mpi][%s:%d] <--\n", (_starpu_debug_rank+1)*4, "", _starpu_debug_rank, __starpu_func__, __LINE__ ); \
  133. fflush(stderr); }} while(0)
  134. #else
  135. # define _STARPU_MPI_LOG_IN()
  136. # define _STARPU_MPI_LOG_OUT()
  137. #endif
  138. extern int _starpu_mpi_tag;
  139. #define _STARPU_MPI_TAG_ENVELOPE _starpu_mpi_tag
  140. #define _STARPU_MPI_TAG_DATA _starpu_mpi_tag+1
  141. #define _STARPU_MPI_TAG_SYNC_DATA _starpu_mpi_tag+2
  142. enum _starpu_mpi_request_type
  143. {
  144. SEND_REQ=0,
  145. RECV_REQ=1,
  146. WAIT_REQ=2,
  147. TEST_REQ=3,
  148. BARRIER_REQ=4,
  149. PROBE_REQ=5,
  150. UNKNOWN_REQ=6,
  151. };
  152. #define _STARPU_MPI_ENVELOPE_DATA 0
  153. #define _STARPU_MPI_ENVELOPE_SYNC_READY 1
  154. struct _starpu_mpi_envelope
  155. {
  156. int mode;
  157. starpu_ssize_t size;
  158. int data_tag;
  159. unsigned sync;
  160. };
  161. struct _starpu_mpi_req;
  162. struct _starpu_mpi_node_tag
  163. {
  164. MPI_Comm comm;
  165. int rank;
  166. int data_tag;
  167. };
  168. LIST_TYPE(_starpu_mpi_req,
  169. /* description of the data at StarPU level */
  170. starpu_data_handle_t data_handle;
  171. /* description of the data to be sent/received */
  172. MPI_Datatype datatype;
  173. char *datatype_name;
  174. void *ptr;
  175. starpu_ssize_t count;
  176. int registered_datatype;
  177. /* who are we talking to ? */
  178. struct _starpu_mpi_node_tag node_tag;
  179. void (*func)(struct _starpu_mpi_req *);
  180. MPI_Status *status;
  181. MPI_Request data_request;
  182. int *flag;
  183. unsigned sync;
  184. int ret;
  185. starpu_pthread_mutex_t req_mutex;
  186. starpu_pthread_cond_t req_cond;
  187. starpu_pthread_mutex_t posted_mutex;
  188. starpu_pthread_cond_t posted_cond;
  189. enum _starpu_mpi_request_type request_type; /* 0 send, 1 recv */
  190. unsigned submitted;
  191. unsigned completed;
  192. unsigned posted;
  193. /* In the case of a Wait/Test request, we are going to post a request
  194. * to test the completion of another request */
  195. struct _starpu_mpi_req *other_request;
  196. /* in the case of detached requests */
  197. int detached;
  198. void *callback_arg;
  199. void (*callback)(void *);
  200. /* in the case of user-defined datatypes, we need to send the size of the data */
  201. MPI_Request size_req;
  202. struct _starpu_mpi_envelope* envelope;
  203. int is_internal_req;
  204. struct _starpu_mpi_req *internal_req;
  205. struct _starpu_mpi_early_data_handle *early_data_handle;
  206. int sequential_consistency;
  207. UT_hash_handle hh;
  208. #ifdef STARPU_SIMGRID
  209. MPI_Status status_store;
  210. starpu_pthread_queue_t queue;
  211. unsigned done;
  212. #endif
  213. );
  214. struct _starpu_mpi_argc_argv
  215. {
  216. int initialize_mpi;
  217. int *argc;
  218. char ***argv;
  219. MPI_Comm comm;
  220. int fargc; // Fortran argc
  221. char **fargv; // Fortran argv
  222. };
  223. #ifdef __cplusplus
  224. }
  225. #endif
  226. #endif // __STARPU_MPI_PRIVATE_H__