|
| 1 | +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ |
| 2 | +/* |
| 3 | + * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana |
| 4 | + * University Research and Technology |
| 5 | + * Corporation. All rights reserved. |
| 6 | + * Copyright (c) 2004-2021 The University of Tennessee and The University |
| 7 | + * of Tennessee Research Foundation. All rights |
| 8 | + * reserved. |
| 9 | + * Copyright (c) 2004-2008 High Performance Computing Center Stuttgart, |
| 10 | + * University of Stuttgart. All rights reserved. |
| 11 | + * Copyright (c) 2004-2005 The Regents of the University of California. |
| 12 | + * All rights reserved. |
| 13 | + * Copyright (c) 2010-2012 Oak Ridge National Labs. All rights reserved. |
| 14 | + * Copyright (c) 2013 Los Alamos National Security, LLC. All rights |
| 15 | + * reserved. |
| 16 | + * Copyright (c) 2015 Research Organization for Information Science |
| 17 | + * and Technology (RIST). All rights reserved. |
| 18 | + * Copyright (c) 2021 Nanook Consulting. All rights reserved. |
| 19 | + * Copyright (c) 2021 Triad National Security, LLC. All rights |
| 20 | + * reserved. |
| 21 | + * $COPYRIGHT$ |
| 22 | + * |
| 23 | + * Additional copyrights may follow |
| 24 | + * |
| 25 | + * $HEADER$ |
| 26 | + */ |
| 27 | +#include "ompi_config.h" |
| 28 | + |
| 29 | +#include "ompi/mpi/c/bindings.h" |
| 30 | +#include "ompi/runtime/params.h" |
| 31 | +#include "ompi/communicator/communicator.h" |
| 32 | +#include "ompi/communicator/comm_request.h" |
| 33 | +#include "ompi/errhandler/errhandler.h" |
| 34 | +#include "ompi/mca/pml/pml.h" |
| 35 | +#include "ompi/request/request.h" |
| 36 | +#include "ompi/memchecker.h" |
| 37 | +#include "ompi/runtime/ompi_spc.h" |
| 38 | + |
| 39 | +#if OMPI_BUILD_MPI_PROFILING |
| 40 | +#if OPAL_HAVE_WEAK_SYMBOLS |
| 41 | +#pragma weak MPI_Isendrecv = PMPI_Isendrecv |
| 42 | +#endif |
| 43 | +#define MPI_Isendrecv PMPI_Isendrecv |
| 44 | +#endif |
| 45 | + |
| 46 | +static const char FUNC_NAME[] = "MPI_Isendrecv"; |
| 47 | + |
| 48 | +struct ompi_isendrecv_context_t { |
| 49 | + opal_object_t super; |
| 50 | + int nreqs; |
| 51 | + int source; |
| 52 | + ompi_request_t *subreq[2]; |
| 53 | +}; |
| 54 | + |
| 55 | +typedef struct ompi_isendrecv_context_t ompi_isendrecv_context_t; |
| 56 | +OBJ_CLASS_INSTANCE(ompi_isendrecv_context_t, opal_object_t, NULL, NULL); |
| 57 | + |
| 58 | +static int ompi_isendrecv_complete_func (ompi_comm_request_t *request) |
| 59 | +{ |
| 60 | + ompi_isendrecv_context_t *context = |
| 61 | + (ompi_isendrecv_context_t *) request->context; |
| 62 | + |
| 63 | + /* |
| 64 | + * Copy the status from the receive side of the sendrecv request? |
| 65 | + * But what if the send failed? |
| 66 | + * |
| 67 | + * Probably need to bring up in the MPI forum. |
| 68 | + */ |
| 69 | + |
| 70 | + if (MPI_PROC_NULL != context->source) { |
| 71 | + OMPI_COPY_STATUS(&request->super.req_status, |
| 72 | + context->subreq[0]->req_status, false); |
| 73 | + } else { |
| 74 | + OMPI_COPY_STATUS(&request->super.req_status, |
| 75 | + ompi_request_empty.req_status, false); |
| 76 | + } |
| 77 | + |
| 78 | + if(NULL != context->subreq[0]) { |
| 79 | + ompi_request_free(&context->subreq[0]); |
| 80 | + } |
| 81 | + if(NULL != context->subreq[1]) { |
| 82 | + ompi_request_free(&context->subreq[1]); |
| 83 | + } |
| 84 | + |
| 85 | + return OMPI_SUCCESS; |
| 86 | +} |
| 87 | + |
| 88 | + |
| 89 | +int MPI_Isendrecv(const void *sendbuf, int sendcount, MPI_Datatype sendtype, |
| 90 | + int dest, int sendtag, void *recvbuf, int recvcount, |
| 91 | + MPI_Datatype recvtype, int source, int recvtag, |
| 92 | + MPI_Comm comm, MPI_Request *request) |
| 93 | +{ |
| 94 | + ompi_isendrecv_context_t *context = NULL; |
| 95 | + ompi_comm_request_t *crequest; |
| 96 | + int rc = MPI_SUCCESS; |
| 97 | + int nreqs = 0; |
| 98 | + uint32_t flags; |
| 99 | + |
| 100 | + SPC_RECORD(OMPI_SPC_ISENDRECV, 1); |
| 101 | + |
| 102 | + MEMCHECKER( |
| 103 | + memchecker_datatype(sendtype); |
| 104 | + memchecker_datatype(recvtype); |
| 105 | + memchecker_call(&opal_memchecker_base_isdefined, sendbuf, sendcount, sendtype); |
| 106 | + memchecker_comm(comm); |
| 107 | + ); |
| 108 | + |
| 109 | + if ( MPI_PARAM_CHECK ) { |
| 110 | + OMPI_ERR_INIT_FINALIZE(FUNC_NAME); |
| 111 | + OMPI_CHECK_DATATYPE_FOR_SEND(rc, sendtype, sendcount); |
| 112 | + OMPI_CHECK_DATATYPE_FOR_RECV(rc, recvtype, recvcount); |
| 113 | + OMPI_CHECK_USER_BUFFER(rc, sendbuf, sendtype, sendcount); |
| 114 | + OMPI_CHECK_USER_BUFFER(rc, recvbuf, recvtype, recvcount); |
| 115 | + |
| 116 | + if (ompi_comm_invalid(comm)) { |
| 117 | + return OMPI_ERRHANDLER_NOHANDLE_INVOKE(MPI_ERR_COMM, FUNC_NAME); |
| 118 | + } else if (dest != MPI_PROC_NULL && ompi_comm_peer_invalid(comm, dest)) { |
| 119 | + rc = MPI_ERR_RANK; |
| 120 | + } else if (sendtag < 0 || sendtag > mca_pml.pml_max_tag) { |
| 121 | + rc = MPI_ERR_TAG; |
| 122 | + } else if (source != MPI_PROC_NULL && source != MPI_ANY_SOURCE && ompi_comm_peer_invalid(comm, source)) { |
| 123 | + rc = MPI_ERR_RANK; |
| 124 | + } else if (((recvtag < 0) && (recvtag != MPI_ANY_TAG)) || (recvtag > mca_pml.pml_max_tag)) { |
| 125 | + rc = MPI_ERR_TAG; |
| 126 | + } else if (request == NULL) { |
| 127 | + rc = MPI_ERR_REQUEST; |
| 128 | + } |
| 129 | + |
| 130 | + OMPI_ERRHANDLER_CHECK(rc, comm, rc, FUNC_NAME); |
| 131 | + } |
| 132 | + |
| 133 | + crequest = ompi_comm_request_get (); |
| 134 | + if (NULL == crequest) { |
| 135 | + return OMPI_ERR_OUT_OF_RESOURCE; |
| 136 | + } |
| 137 | + |
| 138 | + context = OBJ_NEW(ompi_isendrecv_context_t); |
| 139 | + if (NULL == context) { |
| 140 | + ompi_comm_request_return (crequest); |
| 141 | + return OMPI_ERR_OUT_OF_RESOURCE; |
| 142 | + } |
| 143 | + |
| 144 | + crequest->context = &context->super; |
| 145 | + context->subreq[0] = NULL; |
| 146 | + context->subreq[1] = NULL; |
| 147 | + context->source = source; |
| 148 | + |
| 149 | + if (source != MPI_PROC_NULL) { /* post recv */ |
| 150 | + rc = MCA_PML_CALL(irecv(recvbuf, recvcount, recvtype, |
| 151 | + source, recvtag, comm, &context->subreq[nreqs++])); |
| 152 | + if (MPI_SUCCESS != rc) { |
| 153 | + OBJ_RELEASE(context); |
| 154 | + ompi_comm_request_return (crequest); |
| 155 | + } |
| 156 | + OMPI_ERRHANDLER_CHECK(rc, comm, rc, FUNC_NAME); |
| 157 | + } |
| 158 | + |
| 159 | + if (dest != MPI_PROC_NULL) { /* send */ |
| 160 | + rc = MCA_PML_CALL(isend(sendbuf, sendcount, sendtype, dest, |
| 161 | + sendtag, MCA_PML_BASE_SEND_STANDARD, comm, &context->subreq[nreqs++])); |
| 162 | + if (MPI_SUCCESS != rc) { |
| 163 | + OBJ_RELEASE(context); |
| 164 | + ompi_comm_request_return (crequest); |
| 165 | + } |
| 166 | + OMPI_ERRHANDLER_CHECK(rc, comm, rc, FUNC_NAME); |
| 167 | + } |
| 168 | + |
| 169 | + /* |
| 170 | + * schedule the operation |
| 171 | + */ |
| 172 | + |
| 173 | + context->nreqs = nreqs; |
| 174 | + assert(nreqs <= 2); |
| 175 | + |
| 176 | + flags = OMPI_COMM_REQ_FLAG_RETAIN_SUBREQ; |
| 177 | + |
| 178 | + rc = ompi_comm_request_schedule_append_w_flags(crequest, ompi_isendrecv_complete_func, |
| 179 | + context->subreq, nreqs, flags); |
| 180 | + if (MPI_SUCCESS != rc) { |
| 181 | + OBJ_RELEASE(context); |
| 182 | + ompi_comm_request_return (crequest); |
| 183 | + } |
| 184 | + |
| 185 | + OMPI_ERRHANDLER_CHECK(rc, comm, rc, FUNC_NAME); |
| 186 | + |
| 187 | + /* kick off the request */ |
| 188 | + |
| 189 | + ompi_comm_request_start (crequest); |
| 190 | + *request = &crequest->super; |
| 191 | + |
| 192 | + return rc; |
| 193 | +} |
0 commit comments