[1381] | 1 | #ifndef EP_TYPE_HPP_INCLUDED |
---|
| 2 | #define EP_TYPE_HPP_INCLUDED |
---|
| 3 | |
---|
| 4 | |
---|
| 5 | #include <iostream> |
---|
| 6 | #include <stdlib.h> |
---|
| 7 | #include <stdio.h> |
---|
| 8 | #include <list> |
---|
| 9 | #include <map> |
---|
| 10 | #include <omp.h> |
---|
| 11 | #include <vector> |
---|
| 12 | #include <numeric> |
---|
| 13 | #include <bitset> |
---|
| 14 | //#include <memory.h> |
---|
| 15 | #include <algorithm> |
---|
| 16 | #include <assert.h> |
---|
| 17 | #include <math.h> |
---|
| 18 | #include <string.h> |
---|
| 19 | |
---|
| 20 | #ifdef _Debug |
---|
| 21 | #define Debug(x) std::cout << x << std::endl |
---|
| 22 | #else |
---|
| 23 | #define Debug(x) |
---|
| 24 | #endif |
---|
| 25 | |
---|
| 26 | #define BUFFER_SIZE 10000 |
---|
| 27 | |
---|
| 28 | //#define NUM_THREADS 12 |
---|
| 29 | |
---|
| 30 | typedef std::pair< int, int > SIZE_RANK_INFO; // < rank, size> |
---|
| 31 | |
---|
| 32 | typedef std::vector< std::pair<int, int> > RANK_MAP; // at(ep_rank) = <ep_rank_local, mpi_rank> |
---|
| 33 | |
---|
| 34 | typedef std::vector<std::pair< std::pair<int, int>, std::pair<int, int> > > INTERCOMM_RANK_MAP; |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | typedef struct |
---|
| 38 | { |
---|
| 39 | int first; |
---|
| 40 | int second; |
---|
| 41 | int third; |
---|
| 42 | } Triple_int; |
---|
| 43 | |
---|
| 44 | namespace ep_lib |
---|
| 45 | { |
---|
| 46 | //#define EP_UNDEFINED -32766 |
---|
| 47 | |
---|
| 48 | class ep_communicator; |
---|
| 49 | class ep_intercomm; |
---|
| 50 | class OMPbarrier; |
---|
| 51 | typedef ep_communicator* EP_Comm; |
---|
| 52 | class MPI_Comm; |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | class MPI_Status |
---|
| 56 | { |
---|
| 57 | public: |
---|
| 58 | |
---|
| 59 | void* ep_datatype; |
---|
| 60 | int ep_src; |
---|
| 61 | int ep_tag; |
---|
| 62 | void* mpi_status; |
---|
| 63 | }; |
---|
| 64 | |
---|
| 65 | class MPI_Message |
---|
| 66 | { |
---|
| 67 | public: |
---|
| 68 | |
---|
| 69 | void* mpi_message; |
---|
| 70 | int ep_src; |
---|
| 71 | int ep_tag; |
---|
| 72 | void* mpi_status; |
---|
| 73 | |
---|
| 74 | MPI_Message() {} |
---|
| 75 | MPI_Message(void* message); |
---|
| 76 | }; |
---|
| 77 | |
---|
| 78 | typedef std::list<MPI_Message > Message_list; |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | class OMPbarrier |
---|
| 82 | { |
---|
| 83 | private: |
---|
| 84 | int nbThreads; //<The number of threads for this barrier |
---|
| 85 | int currentNbThread; //<The current number of threads waiting |
---|
| 86 | bool sense; //<Direct barrier feedback protection |
---|
| 87 | omp_lock_t mutex; //<To have an atomic int |
---|
| 88 | |
---|
| 89 | OMPbarrier(OMPbarrier&){} |
---|
| 90 | OMPbarrier& operator=(OMPbarrier&){return *this;} |
---|
| 91 | |
---|
| 92 | public: |
---|
| 93 | /** Constructor with the number of threads */ |
---|
| 94 | explicit OMPbarrier(const int inNbThreads) |
---|
| 95 | : nbThreads(inNbThreads), currentNbThread(0), sense(false) { |
---|
| 96 | omp_init_lock( &mutex ); |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | /** Destructor, release the omp lock */ |
---|
| 100 | ~OMPbarrier(){ |
---|
| 101 | omp_destroy_lock( &mutex ); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | /** Perform a barrier */ |
---|
| 105 | void wait(){ |
---|
| 106 | const bool mySense = sense; |
---|
| 107 | omp_set_lock( &mutex ); |
---|
| 108 | const int nbThreadsArrived = (++currentNbThread); |
---|
| 109 | omp_unset_lock( &mutex ); |
---|
| 110 | |
---|
| 111 | if(nbThreadsArrived == nbThreads) { |
---|
| 112 | currentNbThread = 0; |
---|
| 113 | sense = !sense; |
---|
| 114 | #pragma omp flush |
---|
| 115 | } |
---|
| 116 | else { |
---|
| 117 | volatile const bool* const ptSense = &sense; |
---|
| 118 | while( (*ptSense) == mySense){ |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | /** Change the number of threads */ |
---|
| 125 | void setNbThreads(const int inNbThread){ |
---|
| 126 | omp_set_lock( &mutex ); |
---|
| 127 | nbThreads = inNbThread; |
---|
| 128 | omp_unset_lock( &mutex ); |
---|
| 129 | } |
---|
| 130 | }; |
---|
| 131 | |
---|
| 132 | class ep_intercomm |
---|
| 133 | { |
---|
| 134 | public: |
---|
| 135 | |
---|
| 136 | void *mpi_inter_comm; |
---|
| 137 | |
---|
| 138 | RANK_MAP *intercomm_rank_map; |
---|
| 139 | RANK_MAP *local_rank_map; |
---|
| 140 | RANK_MAP *remote_rank_map; |
---|
| 141 | |
---|
| 142 | |
---|
| 143 | SIZE_RANK_INFO size_rank_info[3]; |
---|
| 144 | |
---|
| 145 | |
---|
| 146 | MPI_Comm *local_comm; |
---|
| 147 | int intercomm_tag; |
---|
| 148 | |
---|
| 149 | ep_intercomm(); |
---|
| 150 | //~ep_intercomm(){delete mpi_inter_comm;} |
---|
| 151 | bool operator == (ep_intercomm right); |
---|
| 152 | bool operator != (ep_intercomm right); |
---|
| 153 | |
---|
| 154 | |
---|
| 155 | |
---|
| 156 | }; |
---|
| 157 | |
---|
| 158 | |
---|
| 159 | class ep_communicator |
---|
| 160 | { |
---|
| 161 | public: |
---|
| 162 | |
---|
| 163 | SIZE_RANK_INFO size_rank_info[3]; // 0: ep_rank, ep_size |
---|
| 164 | // 1: ep_rank_loc, num_ep |
---|
| 165 | // 2: mpi_rank, mpi_size |
---|
| 166 | |
---|
| 167 | |
---|
| 168 | MPI_Comm *comm_list; |
---|
| 169 | |
---|
| 170 | Message_list *message_queue; |
---|
| 171 | |
---|
| 172 | |
---|
| 173 | int comm_label; |
---|
| 174 | |
---|
| 175 | ep_intercomm *intercomm; |
---|
| 176 | |
---|
| 177 | ep_communicator(); |
---|
| 178 | bool operator == (ep_communicator right); |
---|
| 179 | bool operator != (ep_communicator right); |
---|
| 180 | |
---|
| 181 | }; |
---|
| 182 | |
---|
| 183 | |
---|
| 184 | struct BUFFER |
---|
| 185 | { |
---|
[1499] | 186 | void * void_buffer[12]; |
---|
[1381] | 187 | }; |
---|
| 188 | |
---|
| 189 | |
---|
| 190 | class MPI_Comm |
---|
| 191 | { |
---|
| 192 | public: |
---|
| 193 | |
---|
| 194 | bool is_ep; |
---|
| 195 | bool is_intercomm; |
---|
| 196 | |
---|
| 197 | BUFFER *my_buffer; |
---|
| 198 | OMPbarrier *ep_barrier; |
---|
| 199 | RANK_MAP *rank_map; |
---|
| 200 | void* mpi_comm; |
---|
| 201 | EP_Comm ep_comm_ptr; |
---|
| 202 | MPI_Comm *mem_bridge; |
---|
| 203 | void* mpi_bridge; |
---|
| 204 | |
---|
| 205 | MPI_Comm(); |
---|
| 206 | MPI_Comm(void* comm); |
---|
| 207 | //~MPI_Comm(){delete mpi_comm;} |
---|
| 208 | |
---|
| 209 | |
---|
| 210 | bool operator == (MPI_Comm right); |
---|
| 211 | bool operator != (MPI_Comm right); |
---|
| 212 | bool is_null(); |
---|
| 213 | |
---|
| 214 | }; |
---|
| 215 | |
---|
| 216 | |
---|
| 217 | class MPI_Info |
---|
| 218 | { |
---|
| 219 | public: |
---|
| 220 | |
---|
| 221 | void* mpi_info; |
---|
| 222 | |
---|
| 223 | MPI_Info(); |
---|
| 224 | MPI_Info(void* info); |
---|
| 225 | }; |
---|
| 226 | |
---|
| 227 | |
---|
| 228 | class MPI_Request |
---|
| 229 | { |
---|
| 230 | public: |
---|
| 231 | |
---|
| 232 | void* mpi_request; |
---|
| 233 | |
---|
| 234 | int type; //! type of the non-blocking communication. 1: Isend; 2:Irecv; 3:Imrecv; 4:Issend |
---|
| 235 | void* buf; |
---|
| 236 | |
---|
| 237 | int ep_src; |
---|
| 238 | int ep_tag; |
---|
| 239 | void* ep_datatype; |
---|
| 240 | |
---|
| 241 | MPI_Comm comm; //! EP communicator related to the communication |
---|
| 242 | |
---|
| 243 | MPI_Request() {} |
---|
| 244 | MPI_Request(void* request); |
---|
| 245 | bool operator == (MPI_Request right); |
---|
| 246 | |
---|
| 247 | }; |
---|
| 248 | |
---|
| 249 | |
---|
[1499] | 250 | |
---|
[1381] | 251 | class MPI_Aint |
---|
| 252 | { |
---|
| 253 | public: |
---|
| 254 | |
---|
| 255 | void* mpi_aint; |
---|
| 256 | |
---|
| 257 | MPI_Aint() {} |
---|
| 258 | MPI_Aint(void* aint); |
---|
| 259 | MPI_Aint(int aint); |
---|
[1385] | 260 | MPI_Aint operator=(int a); |
---|
[1381] | 261 | //MPI_Aint(int a): mpi_aint(a) {} |
---|
| 262 | }; |
---|
| 263 | |
---|
| 264 | class MPI_Fint |
---|
| 265 | { |
---|
| 266 | public: |
---|
[1499] | 267 | |
---|
[1381] | 268 | void* mpi_fint; |
---|
[1499] | 269 | |
---|
[1381] | 270 | MPI_Fint() {} |
---|
| 271 | MPI_Fint(void* fint); |
---|
| 272 | //MPI_Fint(int f): mpi_fint(f) {} |
---|
[1499] | 273 | |
---|
[1381] | 274 | }; |
---|
[1499] | 275 | |
---|
[1381] | 276 | class MPI_Win |
---|
| 277 | { |
---|
| 278 | public: |
---|
[1499] | 279 | bool is_ep; |
---|
| 280 | MPI_Comm comm; |
---|
[1381] | 281 | |
---|
[1499] | 282 | void* server_win[16]; |
---|
| 283 | void* client_win; |
---|
| 284 | void* null_win[16]; |
---|
[1381] | 285 | }; |
---|
| 286 | |
---|
[1499] | 287 | |
---|
[1381] | 288 | static MPI_Comm *passage; |
---|
| 289 | |
---|
| 290 | static int TAG = 40000; |
---|
| 291 | |
---|
| 292 | static std::list<std::pair<std::pair<int, int>, MPI_Comm * > > tag_list; |
---|
| 293 | |
---|
| 294 | static std::map<std::pair<int, int>, MPI_Comm > fc_comm_map; |
---|
| 295 | |
---|
| 296 | // static std::map<std::pair<int, int>, MPI_Comm > *fc_comm_map_ptr; |
---|
| 297 | // #pragma omp threadprivate(fc_comm_map_ptr) |
---|
| 298 | // // <MPI_Fint,thread_num> EP_Comm |
---|
[1499] | 299 | |
---|
[1381] | 300 | } |
---|
| 301 | |
---|
| 302 | |
---|
| 303 | |
---|
| 304 | #endif // EP_TYPE_HPP_INCLUDED |
---|
| 305 | |
---|