[1134] | 1 | #include "ep_lib.hpp" |
---|
| 2 | #include <mpi.h> |
---|
| 3 | #include "ep_declaration.hpp" |
---|
| 4 | #include <iostream> |
---|
| 5 | #include <fstream> |
---|
[1520] | 6 | #include "ep_mpi.hpp" |
---|
[1134] | 7 | |
---|
| 8 | using namespace std; |
---|
| 9 | |
---|
[1220] | 10 | std::list< ep_lib::MPI_Request* > * EP_PendingRequests = 0; |
---|
[1196] | 11 | #pragma omp threadprivate(EP_PendingRequests) |
---|
[1134] | 12 | |
---|
[1328] | 13 | |
---|
[1539] | 14 | std::map<std::pair<int, int>, MPI_Group* > * tag_group_map = 0; |
---|
[1328] | 15 | |
---|
[1539] | 16 | std::map<int, std::pair<ep_lib::MPI_Comm*, std::pair<int, int> > > * tag_comm_map = 0; |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | MPI_Group MPI_GROUP_WORLD; |
---|
| 20 | |
---|
[1134] | 21 | namespace ep_lib |
---|
[1187] | 22 | { |
---|
[1134] | 23 | |
---|
| 24 | int tag_combine(int real_tag, int src, int dest) |
---|
| 25 | { |
---|
| 26 | int a = real_tag << 16; |
---|
| 27 | int b = src << 8; |
---|
| 28 | int c = dest; |
---|
| 29 | |
---|
| 30 | return a+b+c; |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | int get_ep_rank(MPI_Comm comm, int ep_rank_loc, int mpi_rank) |
---|
[1539] | 34 | { |
---|
[1520] | 35 | for(std::map<int, std::pair<int, int> >::iterator it = comm->ep_rank_map->begin(); it != comm->ep_rank_map->end(); it++) |
---|
[1134] | 36 | { |
---|
[1520] | 37 | if( ( it->second.first == ep_rank_loc ) |
---|
| 38 | && ( it->second.second == mpi_rank ) ) |
---|
[1134] | 39 | { |
---|
[1520] | 40 | return it->first; |
---|
[1134] | 41 | } |
---|
| 42 | } |
---|
[1520] | 43 | printf("rank not find for EP_intracomm\n"); |
---|
[1539] | 44 | return MPI_Abort(comm, 0); |
---|
[1134] | 45 | } |
---|
[1520] | 46 | |
---|
[1134] | 47 | |
---|
| 48 | int MPI_Get_count(const MPI_Status *status, MPI_Datatype datatype, int *count) |
---|
| 49 | { |
---|
[1520] | 50 | return ::MPI_Get_count(to_mpi_status_ptr(*status), to_mpi_type(datatype), count); |
---|
[1134] | 51 | } |
---|
| 52 | |
---|
| 53 | double MPI_Wtime() |
---|
| 54 | { |
---|
| 55 | return ::MPI_Wtime(); |
---|
[1539] | 56 | } |
---|
[1134] | 57 | |
---|
[1539] | 58 | int MPI_Comm_test_inter(MPI_Comm comm, int *flag) |
---|
| 59 | { |
---|
| 60 | if(comm->is_ep) return *flag = comm->is_intercomm; |
---|
| 61 | else return ::MPI_Comm_test_inter(to_mpi_comm(comm->mpi_comm), flag); |
---|
[1134] | 62 | } |
---|
| 63 | |
---|
| 64 | void check_sum_send(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, int type) |
---|
| 65 | { |
---|
[1520] | 66 | |
---|
[1134] | 67 | int src_rank; |
---|
| 68 | int int_count; |
---|
| 69 | ::MPI_Aint datasize, intsize, charsize, lb; |
---|
| 70 | |
---|
[1365] | 71 | ::MPI_Type_get_extent(*(static_cast< ::MPI_Datatype*>(datatype)), &lb, &datasize); |
---|
| 72 | ::MPI_Type_get_extent(*(static_cast< ::MPI_Datatype*>(MPI_CHAR)), &lb, &intsize); |
---|
[1134] | 73 | |
---|
| 74 | int_count = count * datasize / intsize ; |
---|
| 75 | |
---|
| 76 | char *buffer = static_cast< char* >(const_cast< void*> (buf)); |
---|
| 77 | |
---|
| 78 | unsigned long sum = 0; |
---|
| 79 | for(int i = 0; i<int_count; i++) |
---|
| 80 | sum += *(buffer+i); |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | MPI_Comm_rank(comm, &src_rank); |
---|
| 84 | |
---|
| 85 | ofstream myfile; |
---|
| 86 | myfile.open ("send_log.txt", ios::app); |
---|
| 87 | if (myfile.is_open()) |
---|
| 88 | { |
---|
| 89 | myfile << "type = " << type << " src = "<< src_rank<< " dest = "<< dest <<" tag = "<< tag << " count = "<< count << " sum = "<< sum << "\n"; |
---|
| 90 | myfile.close(); |
---|
| 91 | } |
---|
| 92 | else printf("Unable to open file\n"); |
---|
| 93 | |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | void check_sum_recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, int type) |
---|
| 98 | { |
---|
[1520] | 99 | |
---|
[1134] | 100 | int dest_rank; |
---|
| 101 | int int_count; |
---|
| 102 | ::MPI_Aint datasize, intsize, charsize, lb; |
---|
| 103 | |
---|
[1365] | 104 | ::MPI_Type_get_extent(*(static_cast< ::MPI_Datatype*>(datatype)), &lb, &datasize); |
---|
| 105 | ::MPI_Type_get_extent(*(static_cast< ::MPI_Datatype*>(MPI_CHAR)), &lb, &intsize); |
---|
[1134] | 106 | |
---|
| 107 | int_count = count * datasize / intsize ; |
---|
| 108 | |
---|
| 109 | char *buffer = static_cast< char* >(buf); |
---|
| 110 | |
---|
| 111 | unsigned long sum = 0; |
---|
| 112 | for(int i = 0; i<int_count; i++) |
---|
| 113 | sum += *(buffer+i); |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | MPI_Comm_rank(comm, &dest_rank); |
---|
| 117 | |
---|
| 118 | ofstream myfile; |
---|
| 119 | myfile.open ("recv_log.txt", ios::app); |
---|
| 120 | if (myfile.is_open()) |
---|
| 121 | { |
---|
| 122 | myfile << "type = " << type << " src = "<< src << " dest = "<< dest_rank <<" tag = "<< tag << " count = "<< count << " sum = "<< sum << "\n"; |
---|
| 123 | myfile.close(); |
---|
| 124 | } |
---|
| 125 | else printf("Unable to open file\n"); |
---|
| 126 | |
---|
[1520] | 127 | |
---|
[1134] | 128 | } |
---|
[1187] | 129 | |
---|
| 130 | |
---|
[1287] | 131 | bool valid_type(MPI_Datatype datatype) |
---|
| 132 | { |
---|
[1642] | 133 | if( datatype == EP_INT |
---|
| 134 | || datatype == EP_FLOAT |
---|
| 135 | || datatype == EP_DOUBLE |
---|
| 136 | || datatype == EP_CHAR |
---|
| 137 | || datatype == EP_LONG |
---|
| 138 | || datatype == EP_UNSIGNED_LONG |
---|
| 139 | || datatype == EP_LONG_LONG) |
---|
[1287] | 140 | { |
---|
| 141 | return true; |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | return false; |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | bool valid_op(MPI_Op op) |
---|
| 149 | { |
---|
[1642] | 150 | if( op == EP_MAX |
---|
| 151 | || op == EP_MIN |
---|
| 152 | || op == EP_SUM |
---|
| 153 | || op == EP_LOR) |
---|
[1287] | 154 | { |
---|
| 155 | return true; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | return false; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | |
---|
[1134] | 162 | } |
---|
| 163 | |
---|
| 164 | |
---|
[1287] | 165 | MPI_Datatype to_mpi_type(ep_lib::MPI_Datatype type) |
---|
| 166 | { |
---|
[1365] | 167 | return *static_cast< MPI_Datatype* >(type); |
---|
[1287] | 168 | } |
---|
[1134] | 169 | |
---|
[1287] | 170 | MPI_Op to_mpi_op(ep_lib::MPI_Op op) |
---|
| 171 | { |
---|
[1368] | 172 | return *static_cast< MPI_Op* >(op); |
---|
[1287] | 173 | } |
---|
[1134] | 174 | |
---|
[1356] | 175 | MPI_Comm to_mpi_comm(void* comm) |
---|
[1287] | 176 | { |
---|
[1356] | 177 | return *(static_cast< MPI_Comm* >(comm)); |
---|
[1520] | 178 | } |
---|
| 179 | |
---|
| 180 | MPI_Comm* to_mpi_comm_ptr(void* comm) |
---|
| 181 | { |
---|
| 182 | return static_cast< MPI_Comm* >(comm); |
---|
[1287] | 183 | } |
---|
[1134] | 184 | |
---|
[1362] | 185 | MPI_Message to_mpi_message(void* message) |
---|
| 186 | { |
---|
| 187 | return *(static_cast< MPI_Message* >(message)); |
---|
| 188 | } |
---|
[1134] | 189 | |
---|
[1520] | 190 | MPI_Message* to_mpi_message_ptr(ep_lib::MPI_Message message) |
---|
[1362] | 191 | { |
---|
[1520] | 192 | return static_cast< MPI_Message* >(message->mpi_message); |
---|
[1362] | 193 | } |
---|
[1196] | 194 | |
---|
[1520] | 195 | MPI_Info to_mpi_info(ep_lib::MPI_Info info) |
---|
| 196 | { |
---|
| 197 | return *(static_cast< MPI_Info* >(info->mpi_info)); |
---|
| 198 | } |
---|
[1287] | 199 | |
---|
[1520] | 200 | MPI_Win to_mpi_win(void* win) |
---|
| 201 | { |
---|
| 202 | return *(static_cast< MPI_Win* >(win)); |
---|
| 203 | } |
---|
[1287] | 204 | |
---|
[1520] | 205 | MPI_Aint to_mpi_aint(ep_lib::MPI_Aint aint) |
---|
| 206 | { |
---|
| 207 | return *(static_cast< MPI_Aint* >(aint.mpi_aint)); |
---|
| 208 | } |
---|
[1287] | 209 | |
---|
[1520] | 210 | MPI_Status* to_mpi_status_ptr(ep_lib::MPI_Status status) |
---|
| 211 | { |
---|
| 212 | return static_cast< MPI_Status* >(status.mpi_status); |
---|
| 213 | } |
---|
[1362] | 214 | |
---|
[1520] | 215 | MPI_Request* to_mpi_request_ptr(ep_lib::MPI_Request request) |
---|
| 216 | { |
---|
| 217 | return static_cast< MPI_Request* >(request->mpi_request); |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | |
---|
| 221 | |
---|