starpu_mpi_private.h 7.5 KB

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