starpu_mpi_private.h 8.3 KB

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