Scippy

UG

Ubiquity Generator framework

paraIsendRequest.h
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the program and software framework */
4/* UG --- Ubquity Generator Framework */
5/* */
6/* Copyright Written by Yuji Shinano <shinano@zib.de>, */
7/* Copyright (C) 2021-2024 by Zuse Institute Berlin, */
8/* licensed under LGPL version 3 or later. */
9/* Commercial licenses are available through <licenses@zib.de> */
10/* */
11/* This code is free software; you can redistribute it and/or */
12/* modify it under the terms of the GNU Lesser General Public License */
13/* as published by the Free Software Foundation; either version 3 */
14/* of the License, or (at your option) any later version. */
15/* */
16/* This program is distributed in the hope that it will be useful, */
17/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
19/* GNU Lesser General Public License for more details. */
20/* */
21/* You should have received a copy of the GNU Lesser General Public License */
22/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
23/* */
24/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
25
26/**@file paraIsendRequest.h
27 * @brief iSend request data structure
28 * @author Yuji Shinano
29 *
30 *
31 *
32 */
33
34/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35#ifndef __PARA_ISEND_REQUEST_H__
36#define __PARA_ISEND_REQUEST_H__
37#include <cassert>
38#include "mpi.h"
39#include "paraCommMpi.h"
40
41namespace UG
42{
43
45{
46public:
48 {
66 MPI_Request *req;
68 char *pChar;
69 short *pShort;
70 int *pInt;
71 long *pLong;
72 long long *pLongLong;
73 signed char *pSignedChar;
74 unsigned char *pUnsignedChar;
75 unsigned short *pUnsignedShort;
76 unsigned *pUnsigned;
77 unsigned long *pUnsignedLong;
78 unsigned long long *pUnsignedLongLong;
79 float *pFloat;
80 double *pDouble;
81 long double *pLongDouble;
82 bool *pBool;
83 char *pByte; // must be always NULL
85
86 ///
87 /// Constructor
88 ///
90 ) : dataType(ParaCHAR), req(0) /// ParaCHAR type is dummy and req = 0 means that message is not basic type
91 {
92 }
93
94 ///
95 /// Constructor
96 ///
98 DataType inDataType,
99 MPI_Request *inReq,
100 void *inObjectPointer
101 ) : dataType(inDataType), req(inReq)
102 {
103 switch ( dataType )
104 {
105 case ParaCHAR:
106 {
107 objectPointer.pChar = reinterpret_cast<char *>(inObjectPointer);
108 break;
109 }
110 case ParaSHORT:
111 {
112 objectPointer.pShort = reinterpret_cast<short *>(inObjectPointer);
113 break;
114 }
115 case ParaINT:
116 {
117 objectPointer.pInt = reinterpret_cast<int *>(inObjectPointer);
118 break;
119 }
120 case ParaLONG:
121 {
122 objectPointer.pLong = reinterpret_cast<long *>(inObjectPointer);
123 break;
124 }
125 case ParaLONG_LONG:
126 {
127 objectPointer.pLongLong = reinterpret_cast<long long *>(inObjectPointer);
128 break;
129 }
130 case ParaSIGNED_CHAR:
131 {
132 objectPointer.pSignedChar = reinterpret_cast<signed char *>(inObjectPointer);
133 break;
134 }
136 {
137 objectPointer.pUnsignedChar = reinterpret_cast<unsigned char *>(inObjectPointer);
138 break;
139 }
141 {
142 objectPointer.pUnsignedShort = reinterpret_cast<unsigned short *>(inObjectPointer);
143 break;
144 }
145 case ParaUNSIGNED:
146 {
147 objectPointer.pUnsigned = reinterpret_cast<unsigned *>(inObjectPointer);
148 break;
149 }
151 {
152 objectPointer.pUnsignedLong = reinterpret_cast<unsigned long *>(inObjectPointer);
153 break;
154 }
156 {
157 objectPointer.pUnsignedLongLong = reinterpret_cast<unsigned long long *>(inObjectPointer);
158 break;
159 }
160 case ParaFLOAT:
161 {
162 objectPointer.pFloat = reinterpret_cast<float *>(inObjectPointer);
163 break;
164 }
165 case ParaDOUBLE:
166 {
167 objectPointer.pDouble = reinterpret_cast<double *>(inObjectPointer);
168 break;
169 }
170 case ParaLONG_DOUBLE:
171 {
172 objectPointer.pLongDouble = reinterpret_cast<long double *>(inObjectPointer);
173 break;
174 }
175 case ParaBOOL:
176 {
177 objectPointer.pBool = reinterpret_cast<bool *>(inObjectPointer);
178 break;
179 }
180 case ParaBYTE:
181 {
182 objectPointer.pByte = reinterpret_cast<char *>(inObjectPointer);
183 break;
184 }
185 default:
186 {
187 std::cerr << "Invalid dataType = " << static_cast<int>(dataType) << std::endl;
188 abort();
189 }
190 }
191 }
192
193 ///
194 /// deconstructor
195 /// delete the object after sending, however, only paraTask is not deleted
196 /// because the object is saved in Pool after sending.
197 ///
199 )
200 {
201 if( req ) // req is a kind of switch to show if the Isend is for basic datatype or not
202 {
203 delete req;
204 switch ( dataType )
205 {
206 case ParaCHAR:
207 {
208 if( objectPointer.pChar ) delete [] objectPointer.pChar;
209 break;
210 }
211 case ParaSHORT:
212 {
214 break;
215 }
216 case ParaINT:
217 {
218 if( objectPointer.pInt ) delete [] objectPointer.pInt;
219 break;
220 }
221 case ParaLONG:
222 {
223 if( objectPointer.pLong ) delete [] objectPointer.pLong;
224 break;
225 }
226 case ParaLONG_LONG:
227 {
229 break;
230 }
231 case ParaSIGNED_CHAR:
232 {
234 break;
235 }
237 {
239 break;
240 }
242 {
244 break;
245 }
246 case ParaUNSIGNED:
247 {
249 break;
250 }
252 {
254 break;
255 }
257 {
259 break;
260 }
261 case ParaFLOAT:
262 {
264 break;
265 }
266 case ParaDOUBLE:
267 {
269 break;
270 }
271 case ParaLONG_DOUBLE:
272 {
274 break;
275 }
276 case ParaBOOL:
277 {
278 if( objectPointer.pBool ) delete [] objectPointer.pBool;
279 break;
280 }
281 case ParaBYTE:
282 {
283 assert( !objectPointer.pByte );
284 break;
285 }
286 default:
287 {
288 std::cerr << "Invalid dataType = " << static_cast<int>(dataType) << std::endl;
289 abort();
290 }
291 }
292 }
293 }
294
295 ///
296 /// getter of pointer of object buffer
297 ///
298 virtual void* buffer(
299 )
300 {
301 switch ( dataType )
302 {
303 case ParaCHAR:
304 {
305 return objectPointer.pChar;
306 }
307 case ParaSHORT:
308 {
309 return objectPointer.pShort;
310 }
311 case ParaINT:
312 {
313 return objectPointer.pInt;
314 }
315 case ParaLONG:
316 {
317 return objectPointer.pLong;
318 }
319 case ParaLONG_LONG:
320 {
322 }
323 case ParaSIGNED_CHAR:
324 {
326 }
328 {
330 }
332 {
334 }
335 case ParaUNSIGNED:
336 {
338 }
340 {
342 }
344 {
346 }
347 case ParaFLOAT:
348 {
349 return objectPointer.pFloat;
350 }
351 case ParaDOUBLE:
352 {
353 return objectPointer.pDouble;
354 }
355 case ParaLONG_DOUBLE:
356 {
358 }
359 case ParaBOOL:
360 {
361 return objectPointer.pBool;
362 }
363 case ParaBYTE:
364 {
365 return objectPointer.pByte;
366 }
367 default:
368 {
369 std::cerr << "Invalid dataType = " << static_cast<int>(dataType) << std::endl;
370 abort();
371 }
372 }
373 }
374
375 virtual bool test(
376 )
377 {
378 assert( req );
379 int flag = 0;
380 MPI_CALL(
381 MPI_Test(req, &flag, MPI_STATUS_IGNORE)
382 );
383 if( flag ) return true;
384 else return false;
385 }
386
387 virtual void wait(
388 )
389 {
390 assert( req );
391 MPI_CALL(
392 MPI_Wait(req, MPI_STATUS_IGNORE)
393 );
394 }
395};
396
397}
398
399#endif // __PARA_ISEND_REQUEST_H__
400
401
virtual ~ParaIsendRequest()
deconstructor delete the object after sending, however, only paraTask is not deleted because the obje...
ParaIsendRequest()
Constructor.
enum UG::ParaIsendRequest::DataType dataType
union UG::ParaIsendRequest::ObjectPointer objectPointer
virtual void * buffer()
getter of pointer of object buffer
ParaIsendRequest(DataType inDataType, MPI_Request *inReq, void *inObjectPointer)
Constructor.
ParaComm extension for MPI communication.
#define MPI_CALL(mpicall)
Definition: paraCommMpi.h:68
unsigned long long * pUnsignedLongLong