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 <algorithm> |
---|
15 | #include <assert.h> |
---|
16 | #include <math.h> |
---|
17 | #include <string.h> |
---|
18 | |
---|
19 | #ifdef _Debug |
---|
20 | #define Debug(x) std::cout << x << std::endl |
---|
21 | #else |
---|
22 | #define Debug(x) |
---|
23 | #endif |
---|
24 | |
---|
25 | #define BUFFER_SIZE 10000 |
---|
26 | |
---|
27 | #include "ep_status.hpp" |
---|
28 | #include "ep_request.hpp" |
---|
29 | #include "ep_info.hpp" |
---|
30 | #include "ep_message.hpp" |
---|
31 | #include "ep_barrier.hpp" |
---|
32 | #include "ep_comm.hpp" |
---|
33 | #include "ep_intercomm.hpp" |
---|
34 | #include "ep_window.hpp" |
---|
35 | |
---|
36 | |
---|
37 | //typedef std::pair< int, int > SIZE_RANK_INFO; // < rank, size> |
---|
38 | |
---|
39 | //typedef std::vector< std::pair<int, int> > RANK_MAP; // at(ep_rank) = <ep_rank_local, mpi_rank> |
---|
40 | //typedef std::map<int, std::pair<int, int> > EP_RANK_MAP; // key(ep_rank) = <ep_rank_local, mpi_rank> |
---|
41 | |
---|
42 | //typedef std::vector<std::pair< std::pair<int, int>, std::pair<int, int> > > INTERCOMM_RANK_MAP; |
---|
43 | |
---|
44 | |
---|
45 | namespace ep_lib |
---|
46 | { |
---|
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 | /* |
---|
133 | class ep_intercomm |
---|
134 | { |
---|
135 | public: |
---|
136 | |
---|
137 | void *mpi_inter_comm; |
---|
138 | |
---|
139 | RANK_MAP *intercomm_rank_map; |
---|
140 | RANK_MAP *local_rank_map; |
---|
141 | RANK_MAP *remote_rank_map; |
---|
142 | |
---|
143 | |
---|
144 | SIZE_RANK_INFO size_rank_info[3]; |
---|
145 | |
---|
146 | |
---|
147 | MPI_Comm *local_comm; |
---|
148 | int intercomm_tag; |
---|
149 | |
---|
150 | ep_intercomm(); |
---|
151 | //~ep_intercomm(){delete mpi_inter_comm;} |
---|
152 | bool operator == (ep_intercomm right); |
---|
153 | bool operator != (ep_intercomm right); |
---|
154 | |
---|
155 | }; |
---|
156 | |
---|
157 | class ep_communicator |
---|
158 | { |
---|
159 | public: |
---|
160 | |
---|
161 | SIZE_RANK_INFO size_rank_info[3]; // 0: ep_rank, ep_size |
---|
162 | // 1: ep_rank_loc, num_ep |
---|
163 | // 2: mpi_rank, mpi_size |
---|
164 | |
---|
165 | |
---|
166 | MPI_Comm *comm_list; |
---|
167 | |
---|
168 | Message_list *message_queue; |
---|
169 | |
---|
170 | |
---|
171 | int comm_label; |
---|
172 | |
---|
173 | ep_intercomm *intercomm; |
---|
174 | |
---|
175 | ep_communicator(); |
---|
176 | bool operator == (ep_communicator right); |
---|
177 | bool operator != (ep_communicator right); |
---|
178 | |
---|
179 | }; |
---|
180 | |
---|
181 | |
---|
182 | struct BUFFER |
---|
183 | { |
---|
184 | void * void_buffer[12]; |
---|
185 | }; |
---|
186 | |
---|
187 | |
---|
188 | class MPI_Comm |
---|
189 | { |
---|
190 | public: |
---|
191 | |
---|
192 | bool is_ep; |
---|
193 | bool is_intercomm; |
---|
194 | |
---|
195 | BUFFER *my_buffer; |
---|
196 | OMPbarrier *ep_barrier; |
---|
197 | RANK_MAP *rank_map; |
---|
198 | void* mpi_comm; |
---|
199 | EP_Comm ep_comm_ptr; |
---|
200 | MPI_Comm *mem_bridge; |
---|
201 | void* mpi_bridge; |
---|
202 | |
---|
203 | MPI_Comm(); |
---|
204 | MPI_Comm(void* comm); |
---|
205 | //~MPI_Comm(){delete mpi_comm;} |
---|
206 | |
---|
207 | |
---|
208 | bool operator == (MPI_Comm right); |
---|
209 | bool operator != (MPI_Comm right); |
---|
210 | bool is_null(); |
---|
211 | |
---|
212 | }; |
---|
213 | |
---|
214 | |
---|
215 | class MPI_Info |
---|
216 | { |
---|
217 | public: |
---|
218 | |
---|
219 | void* mpi_info; |
---|
220 | |
---|
221 | MPI_Info(); |
---|
222 | MPI_Info(void* info); |
---|
223 | }; |
---|
224 | |
---|
225 | |
---|
226 | class MPI_Request |
---|
227 | { |
---|
228 | public: |
---|
229 | |
---|
230 | void* mpi_request; |
---|
231 | |
---|
232 | int type; //! type of the non-blocking communication. 1: Isend; 2:Irecv; 3:Imrecv; 4:Issend |
---|
233 | void* buf; |
---|
234 | |
---|
235 | int ep_src; |
---|
236 | int ep_tag; |
---|
237 | void* ep_datatype; |
---|
238 | |
---|
239 | MPI_Comm comm; //! EP communicator related to the communication |
---|
240 | |
---|
241 | MPI_Request() {} |
---|
242 | MPI_Request(void* request); |
---|
243 | bool operator == (MPI_Request right); |
---|
244 | |
---|
245 | }; |
---|
246 | |
---|
247 | */ |
---|
248 | |
---|
249 | class MPI_Aint |
---|
250 | { |
---|
251 | public: |
---|
252 | |
---|
253 | void* mpi_aint; |
---|
254 | |
---|
255 | MPI_Aint() {} |
---|
256 | MPI_Aint(void* aint); |
---|
257 | MPI_Aint(int aint); |
---|
258 | MPI_Aint operator=(int a); |
---|
259 | //MPI_Aint(int a): mpi_aint(a) {} |
---|
260 | }; |
---|
261 | |
---|
262 | class MPI_Fint |
---|
263 | { |
---|
264 | public: |
---|
265 | |
---|
266 | void* mpi_fint; |
---|
267 | |
---|
268 | MPI_Fint() {} |
---|
269 | MPI_Fint(void* fint); |
---|
270 | //MPI_Fint(int f): mpi_fint(f) {} |
---|
271 | |
---|
272 | }; |
---|
273 | |
---|
274 | |
---|
275 | |
---|
276 | |
---|
277 | static MPI_Comm *passage; |
---|
278 | |
---|
279 | static int TAG = 40000; |
---|
280 | |
---|
281 | static std::list<std::pair<std::pair<int, int>, MPI_Comm * > > tag_list; |
---|
282 | |
---|
283 | static std::map<std::pair<int, int>, MPI_Comm > fc_comm_map; |
---|
284 | |
---|
285 | // static std::map<std::pair<int, int>, MPI_Comm > *fc_comm_map_ptr; |
---|
286 | // #pragma omp threadprivate(fc_comm_map_ptr) |
---|
287 | // // <MPI_Fint,thread_num> EP_Comm |
---|
288 | |
---|
289 | } |
---|
290 | |
---|
291 | |
---|
292 | |
---|
293 | #endif // EP_TYPE_HPP_INCLUDED |
---|
294 | |
---|