starpu_mpi_req.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012-2013,2016-2017 Inria
  4. * Copyright (C) 2009-2018 Université de Bordeaux
  5. * Copyright (C) 2017 Guillaume Beauchamp
  6. * Copyright (C) 2010-2018 CNRS
  7. *
  8. * StarPU is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation; either version 2.1 of the License, or (at
  11. * your option) any later version.
  12. *
  13. * StarPU is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  17. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  18. */
  19. #include <starpu.h>
  20. #include <starpu_mpi_private.h>
  21. #if defined(STARPU_USE_MPI_MPI)
  22. #include <mpi/starpu_mpi_comm.h>
  23. #endif
  24. #if defined(STARPU_USE_MPI_NMAD)
  25. #include <pioman.h>
  26. #include <nm_mpi_nmad.h>
  27. #endif
  28. void _starpu_mpi_request_init(struct _starpu_mpi_req **req)
  29. {
  30. _STARPU_MPI_CALLOC(*req, 1, sizeof(struct _starpu_mpi_req));
  31. /* Initialize the request structure */
  32. (*req)->data_handle = NULL;
  33. (*req)->prio = 0;
  34. (*req)->datatype = 0;
  35. (*req)->datatype_name = NULL;
  36. (*req)->ptr = NULL;
  37. (*req)->count = -1;
  38. (*req)->registered_datatype = -1;
  39. (*req)->node_tag.rank = -1;
  40. (*req)->node_tag.data_tag = -1;
  41. (*req)->node_tag.comm = 0;
  42. (*req)->func = NULL;
  43. (*req)->status = NULL;
  44. #ifdef STARPU_USE_MPI_MPI
  45. (*req)->data_request = 0;
  46. #endif
  47. (*req)->flag = NULL;
  48. _starpu_mpi_req_multilist_init_coop_sends(*req);
  49. (*req)->ret = -1;
  50. #ifdef STARPU_USE_MPI_NMAD
  51. piom_cond_init(&((*req)->req_cond), 0);
  52. #elif defined(STARPU_USE_MPI_MPI)
  53. STARPU_PTHREAD_MUTEX_INIT(&((*req)->req_mutex), NULL);
  54. STARPU_PTHREAD_COND_INIT(&((*req)->req_cond), NULL);
  55. STARPU_PTHREAD_MUTEX_INIT(&((*req)->posted_mutex), NULL);
  56. STARPU_PTHREAD_COND_INIT(&((*req)->posted_cond), NULL);
  57. #endif
  58. (*req)->request_type = UNKNOWN_REQ;
  59. (*req)->submitted = 0;
  60. (*req)->completed = 0;
  61. (*req)->posted = 0;
  62. #ifdef STARPU_USE_MPI_MPI
  63. (*req)->other_request = NULL;
  64. #endif
  65. (*req)->sync = 0;
  66. (*req)->detached = -1;
  67. (*req)->callback = NULL;
  68. (*req)->callback_arg = NULL;
  69. #ifdef STARPU_USE_MPI_MPI
  70. (*req)->size_req = 0;
  71. (*req)->internal_req = NULL;
  72. (*req)->is_internal_req = 0;
  73. (*req)->to_destroy = 1;
  74. (*req)->early_data_handle = NULL;
  75. (*req)->envelope = NULL;
  76. #endif
  77. (*req)->sequential_consistency = 1;
  78. (*req)->pre_sync_jobid = -1;
  79. (*req)->post_sync_jobid = -1;
  80. #ifdef STARPU_SIMGRID
  81. starpu_pthread_queue_init(&((*req)->queue));
  82. starpu_pthread_queue_register(&wait, &((*req)->queue));
  83. (*req)->done = 0;
  84. #endif
  85. }
  86. struct _starpu_mpi_req *_starpu_mpi_request_fill(starpu_data_handle_t data_handle,
  87. int srcdst, starpu_mpi_tag_t data_tag, MPI_Comm comm,
  88. unsigned detached, unsigned sync, int prio, void (*callback)(void *), void *arg,
  89. enum _starpu_mpi_request_type request_type, void (*func)(struct _starpu_mpi_req *),
  90. int sequential_consistency,
  91. int is_internal_req,
  92. starpu_ssize_t count)
  93. {
  94. struct _starpu_mpi_req *req;
  95. #ifdef STARPU_USE_MPI_MPI
  96. _starpu_mpi_comm_register(comm);
  97. #endif
  98. /* Initialize the request structure */
  99. _starpu_mpi_request_init(&req);
  100. req->request_type = request_type;
  101. /* prio_list is sorted by increasing values */
  102. if (_starpu_mpi_use_prio)
  103. req->prio = prio;
  104. req->data_handle = data_handle;
  105. req->node_tag.rank = srcdst;
  106. req->node_tag.data_tag = data_tag;
  107. req->node_tag.comm = comm;
  108. req->detached = detached;
  109. req->sync = sync;
  110. req->callback = callback;
  111. req->callback_arg = arg;
  112. req->func = func;
  113. req->sequential_consistency = sequential_consistency;
  114. #ifdef STARPU_USE_MPI_NMAD
  115. nm_mpi_nmad_dest(&req->session, &req->gate, comm, req->node_tag.rank);
  116. #elif defined(STARPU_USE_MPI_MPI)
  117. req->is_internal_req = is_internal_req;
  118. /* For internal requests, we wait for both the request completion and the matching application request completion */
  119. req->to_destroy = !is_internal_req;
  120. req->count = count;
  121. #endif
  122. return req;
  123. }
  124. void _starpu_mpi_request_destroy(struct _starpu_mpi_req *req)
  125. {
  126. #ifdef STARPU_USE_MPI_NMAD
  127. piom_cond_destroy(&(req->req_cond));
  128. #elif defined(STARPU_USE_MPI_MPI)
  129. STARPU_PTHREAD_MUTEX_DESTROY(&req->req_mutex);
  130. STARPU_PTHREAD_COND_DESTROY(&req->req_cond);
  131. STARPU_PTHREAD_MUTEX_DESTROY(&req->posted_mutex);
  132. STARPU_PTHREAD_COND_DESTROY(&req->posted_cond);
  133. free(req->datatype_name);
  134. req->datatype_name = NULL;
  135. #endif
  136. #ifdef STARPU_SIMGRID
  137. starpu_pthread_queue_unregister(&wait, &req->queue);
  138. starpu_pthread_queue_destroy(&req->queue);
  139. #endif
  140. free(req);
  141. }