starpu_mpi_private.h 7.7 KB

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