starpu_mpi_private.h 7.5 KB

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