[1651] | 1 | #ifdef _usingEP |
---|
| 2 | /*! |
---|
| 3 | \file ep_send.hpp |
---|
| 4 | \since 2 may 2016 |
---|
| 5 | |
---|
| 6 | \brief Definitions of MPI send functions: MPI_Send, MPI_Ssend, MPI_Isend, MPI_Issend |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | #include "ep_lib.hpp" |
---|
| 10 | #include <mpi.h> |
---|
| 11 | #include "ep_declaration.hpp" |
---|
| 12 | #include "ep_mpi.hpp" |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | namespace ep_lib |
---|
| 16 | { |
---|
| 17 | |
---|
| 18 | int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) |
---|
| 19 | { |
---|
| 20 | if(comm->is_intercomm) dest = comm->inter_rank_map->at(dest); |
---|
| 21 | |
---|
| 22 | Debug("\nMPI_Send with EP\n"); |
---|
| 23 | |
---|
| 24 | int ep_src_loc = comm->ep_comm_ptr->size_rank_info[1].first; |
---|
| 25 | int ep_dest_loc = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).first; |
---|
| 26 | int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc); |
---|
| 27 | int mpi_dest = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).second; |
---|
| 28 | |
---|
| 29 | //printf("proc %d send to proc %d\n", comm->ep_comm_ptr->size_rank_info[0].first, dest); |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | return ::MPI_Send(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->mpi_comm)); |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | int MPI_Isend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request) |
---|
| 40 | { |
---|
| 41 | if(comm->is_intercomm) dest = comm->inter_rank_map->at(dest); |
---|
| 42 | |
---|
| 43 | Debug("\nMPI_Isend with EP\n"); |
---|
| 44 | |
---|
| 45 | int src_rank; |
---|
| 46 | MPI_Comm_rank(comm, &src_rank); |
---|
| 47 | |
---|
| 48 | *request = new ep_request; |
---|
| 49 | //printf("MPI_Isend : *request = new ep_request => *request = %p\n", *request); |
---|
| 50 | |
---|
| 51 | (*request)->mpi_request = new ::MPI_Request; |
---|
| 52 | //printf("MPI_Isend : (*request)->mpi_request = new ::MPI_Request => (*request)->mpi_request = %p\n", (*request)->mpi_request); |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | int ep_src_loc = comm->ep_comm_ptr->size_rank_info[1].first; |
---|
| 56 | int ep_dest_loc = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).first; |
---|
| 57 | int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc); |
---|
| 58 | int mpi_dest = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).second; |
---|
| 59 | |
---|
| 60 | //printf("proc %d send to proc %d\n", comm->ep_comm_ptr->size_rank_info[0].first, dest); |
---|
| 61 | return ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request)); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | int MPI_Issend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request) |
---|
| 68 | { |
---|
| 69 | |
---|
| 70 | if(comm->is_intercomm) dest = comm->inter_rank_map->at(dest); |
---|
| 71 | |
---|
| 72 | Debug("\nMPI_Isend with EP\n"); |
---|
| 73 | |
---|
| 74 | int src_rank; |
---|
| 75 | MPI_Comm_rank(comm, &src_rank); |
---|
| 76 | |
---|
| 77 | *request = new ep_request; |
---|
| 78 | //printf("MPI_Issend : *request = new ep_request => *request = %p\n", *request); |
---|
| 79 | |
---|
| 80 | (*request)->mpi_request = new ::MPI_Request; |
---|
| 81 | //printf("MPI_Issend : (*request)->mpi_request = new ::MPI_Request => (*request)->mpi_request = %p\n", (*request)->mpi_request); |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | int ep_src_loc = comm->ep_comm_ptr->size_rank_info[1].first; |
---|
| 85 | int ep_dest_loc = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).first; |
---|
| 86 | int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc); |
---|
| 87 | int mpi_dest = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).second; |
---|
| 88 | |
---|
| 89 | //printf("proc %d send to proc %d\n", comm->ep_comm_ptr->size_rank_info[0].first, dest); |
---|
| 90 | return ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request)); |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | |
---|
| 95 | int MPI_Sendrecv(const void *sendbuf, int sendcount, MPI_Datatype sendtype, int dest, int sendtag, |
---|
| 96 | void *recvbuf, int recvcount, MPI_Datatype recvtype, int source, int recvtag, |
---|
| 97 | MPI_Comm comm, MPI_Status *status) |
---|
| 98 | { |
---|
| 99 | int mpi_dest = comm->ep_rank_map->at(dest).second; |
---|
| 100 | int mpi_src = comm->ep_rank_map->at(source).second; |
---|
| 101 | int rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; |
---|
| 102 | int mpi_sendtag = tag_combine(sendtag, rank_loc, comm->ep_rank_map->at(dest).first); |
---|
| 103 | int mpi_recvtag = tag_combine(sendtag, comm->ep_rank_map->at(source).first, rank_loc); |
---|
| 104 | |
---|
| 105 | status->mpi_status = new ::MPI_Status; |
---|
| 106 | //printf("MPI_Sendrecv : status->mpi_status = new ::MPI_Status => status->mpi_status = %p\n", status->mpi_status); |
---|
| 107 | |
---|
| 108 | return ::MPI_Sendrecv(sendbuf, sendcount, to_mpi_type(sendtype), mpi_dest, mpi_sendtag, recvbuf, recvcount, to_mpi_type(recvtype), mpi_src, mpi_recvtag, to_mpi_comm(comm->mpi_comm), to_mpi_status_ptr(*status)); |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | int MPI_Send_mpi(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) |
---|
| 114 | { |
---|
| 115 | Debug("\nMPI_Send with MPI\n"); |
---|
| 116 | return ::MPI_Send(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm->mpi_comm)); |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | int MPI_Ssend_mpi(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) |
---|
| 121 | { |
---|
| 122 | Debug("\nMPI_Ssend with MPI\n"); |
---|
| 123 | return ::MPI_Ssend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm->mpi_comm)); |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | int MPI_Isend_mpi(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request) |
---|
| 128 | { |
---|
| 129 | Debug("\nMPI_Isend with MPI\n"); |
---|
| 130 | |
---|
| 131 | int src_rank; |
---|
| 132 | MPI_Comm_rank(comm, &src_rank); |
---|
| 133 | |
---|
| 134 | *request = new ep_request; |
---|
| 135 | memcheck("new "<< *request <<" : in ep_lib::MPI_Isend_mpi, *request = new ep_request"); |
---|
| 136 | |
---|
| 137 | (*request)->mpi_request = new ::MPI_Request; |
---|
| 138 | memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Isend_mpi, (*request)->mpi_request = new ::MPI_Request"); |
---|
| 139 | |
---|
| 140 | (*request)->ep_src = src_rank; |
---|
| 141 | (*request)->ep_tag = tag; |
---|
| 142 | (*request)->ep_datatype = datatype; |
---|
| 143 | (*request)->type = 1; |
---|
| 144 | (*request)->comm = comm; |
---|
| 145 | |
---|
| 146 | return ::MPI_Isend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request)); |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | |
---|
| 150 | |
---|
| 151 | |
---|
| 152 | int MPI_Issend_mpi(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request) |
---|
| 153 | { |
---|
| 154 | Debug("\nMPI_Issend with MPI\n"); |
---|
| 155 | |
---|
| 156 | int src_rank; |
---|
| 157 | MPI_Comm_rank(comm, &src_rank); |
---|
| 158 | |
---|
| 159 | *request = new ep_request; |
---|
| 160 | memcheck("new "<< *request <<" : in ep_lib::MPI_Issend_mpi, *request = new ep_request"); |
---|
| 161 | |
---|
| 162 | (*request)->mpi_request = new ::MPI_Request; |
---|
| 163 | memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Issend_mpi, (*request)->mpi_request = new ::MPI_Request"); |
---|
| 164 | |
---|
| 165 | (*request)->ep_src = src_rank; |
---|
| 166 | (*request)->ep_tag = tag; |
---|
| 167 | (*request)->ep_datatype = datatype; |
---|
| 168 | (*request)->type = 1; |
---|
| 169 | (*request)->comm = comm; |
---|
| 170 | |
---|
| 171 | return ::MPI_Issend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request)); |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | |
---|
| 175 | } |
---|
| 176 | #endif |
---|
| 177 | |
---|
| 178 | |
---|
| 179 | |
---|
| 180 | |
---|
| 181 | |
---|