MeDiPack  1.3.0
A Message Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
ampiFunctions.hpp
Go to the documentation of this file.
1/*
2 * MeDiPack, a Message Differentiation Package
3 *
4 * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
5 * Homepage: http://scicomp.rptu.de
6 * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de)
7 *
8 * Lead developers: Max Sagebaum (SciComp, University of Kaiserslautern-Landau)
9 *
10 * This file is part of MeDiPack (http://scicomp.rptu.de/software/codi).
11 *
12 * MeDiPack is free software: you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation, either
15 * version 3 of the License, or (at your option) any later version.
16 *
17 * MeDiPack is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * See the GNU Lesser General Public License for more details.
22 * You should have received a copy of the GNU
23 * Lesser General Public License along with MeDiPack.
24 * If not, see <http://www.gnu.org/licenses/>.
25 *
26 * Authors: Max Sagebaum, Tim Albring (SciComp, University of Kaiserslautern-Landau)
27 */
28
29#pragma once
30
31#include "../ampi/async.hpp"
32#include "../ampi/message.hpp"
37#include "../mpiTools.h"
38
42namespace medi {
43#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
44 template<typename DATATYPE>
47 typename DATATYPE::IndexType* bufIndices;
48 typename DATATYPE::PrimalType* bufPrimals;
49 /* required for async */ void* bufAdjoints;
52 int count;
53 DATATYPE* datatype;
54 int dest;
55 int tag;
57
59 if(nullptr != bufIndices) {
60 datatype->getADTool().deleteIndexTypeBuffer(bufIndices);
61 bufIndices = nullptr;
62 }
63 if(nullptr != bufPrimals) {
64 datatype->getADTool().deletePrimalTypeBuffer(bufPrimals);
65 bufPrimals = nullptr;
66 }
67 }
68 };
69
70
71 template<typename DATATYPE>
72 void AMPI_Bsend_p(HandleBase* handle, AdjointInterface* adjointInterface) {
74
75 h->bufAdjoints = nullptr;
76 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
77 adjointInterface->createPrimalTypeBuffer((void*&)h->bufPrimals, h->bufTotalSize );
78 // Primal buffers are always linear in space so we can accesses them in one sweep
79 adjointInterface->getPrimals(h->bufIndices, h->bufPrimals, h->bufTotalSize);
80
81
82 AMPI_Bsend_pri<DATATYPE>(h->bufPrimals, h->bufCountVec, h->count, h->datatype, h->dest, h->tag, h->comm);
83
84 adjointInterface->deletePrimalTypeBuffer((void*&)h->bufPrimals);
85 }
86
87 template<typename DATATYPE>
88 void AMPI_Bsend_d(HandleBase* handle, AdjointInterface* adjointInterface) {
90
91 h->bufAdjoints = nullptr;
92 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
93 adjointInterface->createAdjointTypeBuffer(h->bufAdjoints, h->bufTotalSize );
94 // Adjoint buffers are always linear in space so we can accesses them in one sweep
95 adjointInterface->getAdjoints(h->bufIndices, h->bufAdjoints, h->bufTotalSize);
96
97
98 AMPI_Bsend_fwd<DATATYPE>(h->bufAdjoints, h->bufCountVec, h->count, h->datatype, h->dest, h->tag, h->comm);
99
100 adjointInterface->deleteAdjointTypeBuffer(h->bufAdjoints);
101 }
102
103 template<typename DATATYPE>
104 void AMPI_Bsend_b(HandleBase* handle, AdjointInterface* adjointInterface) {
106
107 h->bufAdjoints = nullptr;
108 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
109 adjointInterface->createAdjointTypeBuffer(h->bufAdjoints, h->bufTotalSize );
110
111 AMPI_Bsend_adj<DATATYPE>(h->bufAdjoints, h->bufCountVec, h->count, h->datatype, h->dest, h->tag, h->comm);
112
113 // Adjoint buffers are always linear in space so we can accesses them in one sweep
114 adjointInterface->updateAdjoints(h->bufIndices, h->bufAdjoints, h->bufTotalSize);
115 adjointInterface->deleteAdjointTypeBuffer(h->bufAdjoints);
116 }
117
118 template<typename DATATYPE>
119 int AMPI_Bsend(MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf, int count, DATATYPE* datatype, int dest, int tag,
120 AMPI_Comm comm) {
121 int rStatus;
122
123 if(!datatype->getADTool().isActiveType()) {
124 // call the regular function if the type is not active
125 rStatus = MPI_Bsend(buf, count, datatype->getMpiType(), dest, tag, comm);
126 } else {
127
128 // the type is an AD type so handle the buffers
130 typename DATATYPE::ModifiedType* bufMod = nullptr;
131 int bufElements = 0;
132
133 // compute the total size of the buffer
134 bufElements = count;
135
136 if(datatype->isModifiedBufferRequired() ) {
137 datatype->createModifiedTypeBuffer(bufMod, bufElements);
138 } else {
139 bufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(buf));
140 }
141
142 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
143 if(datatype->getADTool().isHandleRequired()) {
145 }
146 datatype->getADTool().startAssembly(h);
147 if(datatype->isModifiedBufferRequired()) {
148 datatype->copyIntoModifiedBuffer(buf, 0, bufMod, 0, count);
149 }
150
151 if(nullptr != h) {
152 // gather the information for the reverse sweep
153
154 // create the index buffers
155 h->bufCount = datatype->computeActiveElements(count);
156 h->bufTotalSize = datatype->computeActiveElements(bufElements);
157 datatype->getADTool().createIndexTypeBuffer(h->bufIndices, h->bufTotalSize);
158
159
160
161
162 datatype->getIndices(buf, 0, h->bufIndices, 0, count);
163
164
165 // pack all the variables in the handle
166 h->funcReverse = AMPI_Bsend_b<DATATYPE>;
167 h->funcForward = AMPI_Bsend_d<DATATYPE>;
168 h->funcPrimal = AMPI_Bsend_p<DATATYPE>;
169 h->count = count;
170 h->datatype = datatype;
171 h->dest = dest;
172 h->tag = tag;
173 h->comm = comm;
174 }
175
176
177 rStatus = MPI_Bsend(bufMod, count, datatype->getModifiedMpiType(), dest, tag, comm);
178 datatype->getADTool().addToolAction(h);
179
180
181 if(nullptr != h) {
182 // handle the recv buffers
183 }
184
185 datatype->getADTool().stopAssembly(h);
186
187 if(datatype->isModifiedBufferRequired() ) {
188 datatype->deleteModifiedTypeBuffer(bufMod);
189 }
190
191 // handle is deleted by the AD tool
192 }
193
194 return rStatus;
195 }
196
197#endif
198#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
199 template<typename DATATYPE>
202 typename DATATYPE::IndexType* bufIndices;
203 typename DATATYPE::PrimalType* bufPrimals;
204 /* required for async */ void* bufAdjoints;
207 int count;
208 DATATYPE* datatype;
209 int dest;
210 int tag;
212
214 if(nullptr != bufIndices) {
215 datatype->getADTool().deleteIndexTypeBuffer(bufIndices);
216 bufIndices = nullptr;
217 }
218 if(nullptr != bufPrimals) {
219 datatype->getADTool().deletePrimalTypeBuffer(bufPrimals);
220 bufPrimals = nullptr;
221 }
222 }
223 };
224
225 template<typename DATATYPE>
227 MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf;
228 typename DATATYPE::ModifiedType* bufMod;
229 int count;
230 DATATYPE* datatype;
231 int dest;
232 int tag;
235 };
236
237 template<typename DATATYPE>
238 void AMPI_Ibsend_p(HandleBase* handle, AdjointInterface* adjointInterface) {
240
241 h->bufAdjoints = nullptr;
242 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
243 adjointInterface->createPrimalTypeBuffer((void*&)h->bufPrimals, h->bufTotalSize );
244 // Primal buffers are always linear in space so we can accesses them in one sweep
245 adjointInterface->getPrimals(h->bufIndices, h->bufPrimals, h->bufTotalSize);
246
247
248 AMPI_Ibsend_pri<DATATYPE>(h->bufPrimals, h->bufCountVec, h->count, h->datatype, h->dest, h->tag, h->comm,
249 &h->requestReverse);
250
251 }
252
253 template<typename DATATYPE>
254 void AMPI_Ibsend_p_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
255
257 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
258
259 adjointInterface->deletePrimalTypeBuffer((void*&)h->bufPrimals);
260 }
261
262 template<typename DATATYPE>
263 void AMPI_Ibsend_d(HandleBase* handle, AdjointInterface* adjointInterface) {
265
266 h->bufAdjoints = nullptr;
267 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
268 adjointInterface->createAdjointTypeBuffer(h->bufAdjoints, h->bufTotalSize );
269 // Adjoint buffers are always linear in space so we can accesses them in one sweep
270 adjointInterface->getAdjoints(h->bufIndices, h->bufAdjoints, h->bufTotalSize);
271
272
273 AMPI_Ibsend_fwd<DATATYPE>(h->bufAdjoints, h->bufCountVec, h->count, h->datatype, h->dest, h->tag, h->comm,
274 &h->requestReverse);
275
276 }
277
278 template<typename DATATYPE>
279 void AMPI_Ibsend_d_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
280
282 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
283
284 adjointInterface->deleteAdjointTypeBuffer(h->bufAdjoints);
285 }
286
287 template<typename DATATYPE>
288 void AMPI_Ibsend_b(HandleBase* handle, AdjointInterface* adjointInterface) {
290
291 h->bufAdjoints = nullptr;
292 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
293 adjointInterface->createAdjointTypeBuffer(h->bufAdjoints, h->bufTotalSize );
294
295 AMPI_Ibsend_adj<DATATYPE>(h->bufAdjoints, h->bufCountVec, h->count, h->datatype, h->dest, h->tag, h->comm,
296 &h->requestReverse);
297
298 }
299
300 template<typename DATATYPE>
301 void AMPI_Ibsend_b_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
302
304 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
305
306 // Adjoint buffers are always linear in space so we can accesses them in one sweep
307 adjointInterface->updateAdjoints(h->bufIndices, h->bufAdjoints, h->bufTotalSize);
308 adjointInterface->deleteAdjointTypeBuffer(h->bufAdjoints);
309 }
310
311 template<typename DATATYPE>
312 int AMPI_Ibsend_finish(HandleBase* handle);
313 template<typename DATATYPE>
314 int AMPI_Ibsend(MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf, int count, DATATYPE* datatype, int dest, int tag,
315 AMPI_Comm comm, AMPI_Request* request) {
316 int rStatus;
317
318 if(!datatype->getADTool().isActiveType()) {
319 // call the regular function if the type is not active
320 rStatus = MPI_Ibsend(buf, count, datatype->getMpiType(), dest, tag, comm, &request->request);
321 } else {
322
323 // the type is an AD type so handle the buffers
325 typename DATATYPE::ModifiedType* bufMod = nullptr;
326 int bufElements = 0;
327
328 // compute the total size of the buffer
329 bufElements = count;
330
331 if(datatype->isModifiedBufferRequired() ) {
332 datatype->createModifiedTypeBuffer(bufMod, bufElements);
333 } else {
334 bufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(buf));
335 }
336
337 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
338 if(datatype->getADTool().isHandleRequired()) {
340 }
341 datatype->getADTool().startAssembly(h);
342 if(datatype->isModifiedBufferRequired()) {
343 datatype->copyIntoModifiedBuffer(buf, 0, bufMod, 0, count);
344 }
345
346 if(nullptr != h) {
347 // gather the information for the reverse sweep
348
349 // create the index buffers
350 h->bufCount = datatype->computeActiveElements(count);
351 h->bufTotalSize = datatype->computeActiveElements(bufElements);
352 datatype->getADTool().createIndexTypeBuffer(h->bufIndices, h->bufTotalSize);
353
354
355
356
357 datatype->getIndices(buf, 0, h->bufIndices, 0, count);
358
359
360 // pack all the variables in the handle
361 h->funcReverse = AMPI_Ibsend_b<DATATYPE>;
362 h->funcForward = AMPI_Ibsend_d_finish<DATATYPE>;
363 h->funcPrimal = AMPI_Ibsend_p_finish<DATATYPE>;
364 h->count = count;
365 h->datatype = datatype;
366 h->dest = dest;
367 h->tag = tag;
368 h->comm = comm;
369 }
370
371
372 rStatus = MPI_Ibsend(bufMod, count, datatype->getModifiedMpiType(), dest, tag, comm, &request->request);
373
375 asyncHandle->buf = buf;
376 asyncHandle->bufMod = bufMod;
377 asyncHandle->count = count;
378 asyncHandle->datatype = datatype;
379 asyncHandle->dest = dest;
380 asyncHandle->tag = tag;
381 asyncHandle->comm = comm;
382 asyncHandle->toolHandle = h;
383 request->handle = asyncHandle;
384 request->func = (ContinueFunction)AMPI_Ibsend_finish<DATATYPE>;
385
386 // create adjoint wait
387 if(nullptr != h) {
388 WaitHandle* waitH = new WaitHandle((ReverseFunction)AMPI_Ibsend_b_finish<DATATYPE>,
389 (ForwardFunction)AMPI_Ibsend_d<DATATYPE>, h);
390 datatype->getADTool().addToolAction(waitH);
391 }
392 }
393
394 return rStatus;
395 }
396
397 template<typename DATATYPE>
399 int rStatus = 0;
400
401 AMPI_Ibsend_AsyncHandle<DATATYPE>* asyncHandle = static_cast<AMPI_Ibsend_AsyncHandle<DATATYPE>*>(handle);
402 MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf = asyncHandle->buf;
403 typename DATATYPE::ModifiedType* bufMod = asyncHandle->bufMod;
404 int count = asyncHandle->count;
405 DATATYPE* datatype = asyncHandle->datatype;
406 int dest = asyncHandle->dest;
407 int tag = asyncHandle->tag;
408 AMPI_Comm comm = asyncHandle->comm;
409 AMPI_Request* request = asyncHandle->request;
411 MEDI_UNUSED(h); // Unused generated to ignore warnings
412 MEDI_UNUSED(buf); // Unused generated to ignore warnings
413 MEDI_UNUSED(bufMod); // Unused generated to ignore warnings
414 MEDI_UNUSED(count); // Unused generated to ignore warnings
415 MEDI_UNUSED(datatype); // Unused generated to ignore warnings
416 MEDI_UNUSED(dest); // Unused generated to ignore warnings
417 MEDI_UNUSED(tag); // Unused generated to ignore warnings
418 MEDI_UNUSED(comm); // Unused generated to ignore warnings
419 MEDI_UNUSED(request); // Unused generated to ignore warnings
420
421 delete asyncHandle;
422
423 if(datatype->getADTool().isActiveType()) {
424
425 datatype->getADTool().addToolAction(h);
426
427
428 if(nullptr != h) {
429 // handle the recv buffers
430 }
431
432 datatype->getADTool().stopAssembly(h);
433
434 if(datatype->isModifiedBufferRequired() ) {
435 datatype->deleteModifiedTypeBuffer(bufMod);
436 }
437
438 // handle is deleted by the AD tool
439 }
440
441 return rStatus;
442 }
443
444#endif
445#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
446
447 template<typename DATATYPE>
449 MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf;
450 typename DATATYPE::ModifiedType* bufMod;
451 int count;
452 DATATYPE* datatype;
453 int dest;
454 int tag;
457 };
458
459
460 template<typename DATATYPE>
462 template<typename DATATYPE>
464 template<typename DATATYPE>
466 template<typename DATATYPE>
467 int AMPI_Bsend_init(MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf, int count, DATATYPE* datatype, int dest, int tag,
468 AMPI_Comm comm, AMPI_Request* request) {
469 int rStatus;
470
471 if(!datatype->getADTool().isActiveType()) {
472 // call the regular function if the type is not active
473 rStatus = MPI_Bsend_init(buf, count, datatype->getMpiType(), dest, tag, comm, &request->request);
474 } else {
475
476 // the type is an AD type so handle the buffers
478 typename DATATYPE::ModifiedType* bufMod = nullptr;
479 int bufElements = 0;
480
481 // compute the total size of the buffer
482 bufElements = count;
483
484 if(datatype->isModifiedBufferRequired() ) {
485 datatype->createModifiedTypeBuffer(bufMod, bufElements);
486 } else {
487 bufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(buf));
488 }
489
490 rStatus = MPI_Bsend_init(bufMod, count, datatype->getModifiedMpiType(), dest, tag, comm, &request->request);
491
493 asyncHandle->buf = buf;
494 asyncHandle->bufMod = bufMod;
495 asyncHandle->count = count;
496 asyncHandle->datatype = datatype;
497 asyncHandle->dest = dest;
498 asyncHandle->tag = tag;
499 asyncHandle->comm = comm;
500 asyncHandle->toolHandle = h;
501 request->handle = asyncHandle;
502 request->func = (ContinueFunction)AMPI_Bsend_init_finish<DATATYPE>;
503 request->start = (ContinueFunction)AMPI_Bsend_init_preStart<DATATYPE>;
504 request->end = (ContinueFunction)AMPI_Bsend_init_postEnd<DATATYPE>;
505 }
506
507 return rStatus;
508 }
509
510 template<typename DATATYPE>
512 int rStatus = 0;
513
515 MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf = asyncHandle->buf;
516 typename DATATYPE::ModifiedType* bufMod = asyncHandle->bufMod;
517 int count = asyncHandle->count;
518 DATATYPE* datatype = asyncHandle->datatype;
519 int dest = asyncHandle->dest;
520 int tag = asyncHandle->tag;
521 AMPI_Comm comm = asyncHandle->comm;
522 AMPI_Request* request = asyncHandle->request;
524 MEDI_UNUSED(h); // Unused generated to ignore warnings
525 MEDI_UNUSED(buf); // Unused generated to ignore warnings
526 MEDI_UNUSED(bufMod); // Unused generated to ignore warnings
527 MEDI_UNUSED(count); // Unused generated to ignore warnings
528 MEDI_UNUSED(datatype); // Unused generated to ignore warnings
529 MEDI_UNUSED(dest); // Unused generated to ignore warnings
530 MEDI_UNUSED(tag); // Unused generated to ignore warnings
531 MEDI_UNUSED(comm); // Unused generated to ignore warnings
532 MEDI_UNUSED(request); // Unused generated to ignore warnings
533
534
535 if(datatype->getADTool().isActiveType()) {
536
537 int bufElements = 0;
538
539 // recompute the total size of the buffer
540 bufElements = count;
541 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
542 if(datatype->getADTool().isHandleRequired()) {
544 }
545 datatype->getADTool().startAssembly(h);
546 if(datatype->isModifiedBufferRequired()) {
547 datatype->copyIntoModifiedBuffer(buf, 0, bufMod, 0, count);
548 }
549
550 if(nullptr != h) {
551 // gather the information for the reverse sweep
552
553 // create the index buffers
554 h->bufCount = datatype->computeActiveElements(count);
555 h->bufTotalSize = datatype->computeActiveElements(bufElements);
556 datatype->getADTool().createIndexTypeBuffer(h->bufIndices, h->bufTotalSize);
557
558
559
560
561 datatype->getIndices(buf, 0, h->bufIndices, 0, count);
562
563
564 // pack all the variables in the handle
565 h->funcReverse = AMPI_Ibsend_b<DATATYPE>;
566 h->funcForward = AMPI_Ibsend_d_finish<DATATYPE>;
567 h->funcPrimal = AMPI_Ibsend_p_finish<DATATYPE>;
568 h->count = count;
569 h->datatype = datatype;
570 h->dest = dest;
571 h->tag = tag;
572 h->comm = comm;
573 }
574
575
576 asyncHandle->toolHandle = h;
577
578 // create adjoint wait
579 if(nullptr != h) {
580 WaitHandle* waitH = new WaitHandle((ReverseFunction)AMPI_Ibsend_b_finish<DATATYPE>,
581 (ForwardFunction)AMPI_Ibsend_d<DATATYPE>, h);
582 datatype->getADTool().addToolAction(waitH);
583 }
584 }
585
586 return rStatus;
587 }
588
589 template<typename DATATYPE>
591 int rStatus = 0;
592
594 MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf = asyncHandle->buf;
595 typename DATATYPE::ModifiedType* bufMod = asyncHandle->bufMod;
596 int count = asyncHandle->count;
597 DATATYPE* datatype = asyncHandle->datatype;
598 int dest = asyncHandle->dest;
599 int tag = asyncHandle->tag;
600 AMPI_Comm comm = asyncHandle->comm;
601 AMPI_Request* request = asyncHandle->request;
603 MEDI_UNUSED(h); // Unused generated to ignore warnings
604 MEDI_UNUSED(buf); // Unused generated to ignore warnings
605 MEDI_UNUSED(bufMod); // Unused generated to ignore warnings
606 MEDI_UNUSED(count); // Unused generated to ignore warnings
607 MEDI_UNUSED(datatype); // Unused generated to ignore warnings
608 MEDI_UNUSED(dest); // Unused generated to ignore warnings
609 MEDI_UNUSED(tag); // Unused generated to ignore warnings
610 MEDI_UNUSED(comm); // Unused generated to ignore warnings
611 MEDI_UNUSED(request); // Unused generated to ignore warnings
612
613
614 if(datatype->getADTool().isActiveType()) {
615
616 datatype->getADTool().addToolAction(h);
617
618
619 if(nullptr != h) {
620 // handle the recv buffers
621 }
622
623 datatype->getADTool().stopAssembly(h);
624 }
625
626 return rStatus;
627 }
628
629 template<typename DATATYPE>
631 int rStatus = 0;
632
634 MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf = asyncHandle->buf;
635 typename DATATYPE::ModifiedType* bufMod = asyncHandle->bufMod;
636 int count = asyncHandle->count;
637 DATATYPE* datatype = asyncHandle->datatype;
638 int dest = asyncHandle->dest;
639 int tag = asyncHandle->tag;
640 AMPI_Comm comm = asyncHandle->comm;
641 AMPI_Request* request = asyncHandle->request;
643 MEDI_UNUSED(h); // Unused generated to ignore warnings
644 MEDI_UNUSED(buf); // Unused generated to ignore warnings
645 MEDI_UNUSED(bufMod); // Unused generated to ignore warnings
646 MEDI_UNUSED(count); // Unused generated to ignore warnings
647 MEDI_UNUSED(datatype); // Unused generated to ignore warnings
648 MEDI_UNUSED(dest); // Unused generated to ignore warnings
649 MEDI_UNUSED(tag); // Unused generated to ignore warnings
650 MEDI_UNUSED(comm); // Unused generated to ignore warnings
651 MEDI_UNUSED(request); // Unused generated to ignore warnings
652
653 delete asyncHandle;
654
655 if(datatype->getADTool().isActiveType()) {
656
657
658 if(datatype->isModifiedBufferRequired() ) {
659 datatype->deleteModifiedTypeBuffer(bufMod);
660 }
661
662 // handle is deleted by the AD tool
663 }
664
665 return rStatus;
666 }
667
668#endif
669#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
670 template<typename DATATYPE>
673 typename DATATYPE::IndexType* bufIndices;
674 typename DATATYPE::PrimalType* bufPrimals;
675 typename DATATYPE::PrimalType* bufOldPrimals;
676 /* required for async */ void* bufAdjoints;
679 int count;
680 DATATYPE* datatype;
683
685 if(nullptr != bufIndices) {
686 datatype->getADTool().deleteIndexTypeBuffer(bufIndices);
687 bufIndices = nullptr;
688 }
689 if(nullptr != bufPrimals) {
690 datatype->getADTool().deletePrimalTypeBuffer(bufPrimals);
691 bufPrimals = nullptr;
692 }
693 if(nullptr != bufOldPrimals) {
694 datatype->getADTool().deletePrimalTypeBuffer(bufOldPrimals);
695 bufOldPrimals = nullptr;
696 }
697 }
698 };
699
700 template<typename DATATYPE>
702 typename DATATYPE::Type* buf;
703 typename DATATYPE::ModifiedType* bufMod;
704 int count;
705 DATATYPE* datatype;
709 };
710
711 template<typename DATATYPE>
712 void AMPI_Imrecv_p(HandleBase* handle, AdjointInterface* adjointInterface) {
714
715 h->bufAdjoints = nullptr;
716 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
717 adjointInterface->createPrimalTypeBuffer((void*&)h->bufPrimals, h->bufTotalSize );
718
719 AMPI_Imrecv_pri<DATATYPE>(h->bufPrimals, h->bufCountVec, h->count, h->datatype, &h->message, &h->requestReverse,
720 h->reverse_send);
721
722 }
723
724 template<typename DATATYPE>
725 void AMPI_Imrecv_p_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
726
728 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
729
730 if(h->datatype->getADTool().isOldPrimalsRequired()) {
731 adjointInterface->getPrimals(h->bufIndices, h->bufOldPrimals, h->bufTotalSize);
732 }
733 // Primal buffers are always linear in space so we can accesses them in one sweep
734 adjointInterface->setPrimals(h->bufIndices, h->bufPrimals, h->bufTotalSize);
735 adjointInterface->deletePrimalTypeBuffer((void*&)h->bufPrimals);
736 }
737
738 template<typename DATATYPE>
739 void AMPI_Imrecv_d(HandleBase* handle, AdjointInterface* adjointInterface) {
741
742 h->bufAdjoints = nullptr;
743 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
744 adjointInterface->createAdjointTypeBuffer(h->bufAdjoints, h->bufTotalSize );
745
746 AMPI_Imrecv_fwd<DATATYPE>(h->bufAdjoints, h->bufCountVec, h->count, h->datatype, &h->message, &h->requestReverse,
747 h->reverse_send);
748
749 }
750
751 template<typename DATATYPE>
752 void AMPI_Imrecv_d_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
753
755 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
756
757 // Adjoint buffers are always linear in space so we can accesses them in one sweep
758 adjointInterface->updateAdjoints(h->bufIndices, h->bufAdjoints, h->bufTotalSize);
759 adjointInterface->deleteAdjointTypeBuffer(h->bufAdjoints);
760 }
761
762 template<typename DATATYPE>
763 void AMPI_Imrecv_b(HandleBase* handle, AdjointInterface* adjointInterface) {
765
766 h->bufAdjoints = nullptr;
767 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
768 adjointInterface->createAdjointTypeBuffer(h->bufAdjoints, h->bufTotalSize );
769 // Adjoint buffers are always linear in space so we can accesses them in one sweep
770 adjointInterface->getAdjoints(h->bufIndices, h->bufAdjoints, h->bufTotalSize);
771
772 if(h->datatype->getADTool().isOldPrimalsRequired()) {
773 adjointInterface->setPrimals(h->bufIndices, h->bufOldPrimals, h->bufTotalSize);
774 }
775
776 AMPI_Imrecv_adj<DATATYPE>(h->bufAdjoints, h->bufCountVec, h->count, h->datatype, &h->message, &h->requestReverse,
777 h->reverse_send);
778
779 }
780
781 template<typename DATATYPE>
782 void AMPI_Imrecv_b_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
783
785 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
786
787 adjointInterface->deleteAdjointTypeBuffer(h->bufAdjoints);
788 }
789
790 template<typename DATATYPE>
791 int AMPI_Imrecv_finish(HandleBase* handle);
792 template<typename DATATYPE>
793 int AMPI_Imrecv(typename DATATYPE::Type* buf, int count, DATATYPE* datatype, AMPI_Message* message,
794 AMPI_Request* request, IrecvAdjCall reverse_send = IrecvAdjCall::Isend) {
795 int rStatus;
796
797 if(!datatype->getADTool().isActiveType()) {
798 // call the regular function if the type is not active
799 rStatus = MPI_Imrecv(buf, count, datatype->getMpiType(), &message->message, &request->request);
800 } else {
801
802 // the type is an AD type so handle the buffers
804 typename DATATYPE::ModifiedType* bufMod = nullptr;
805 int bufElements = 0;
806
807 // compute the total size of the buffer
808 bufElements = count;
809
810 if(datatype->isModifiedBufferRequired() ) {
811 datatype->createModifiedTypeBuffer(bufMod, bufElements);
812 } else {
813 bufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(buf));
814 }
815
816 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
817 if(datatype->getADTool().isHandleRequired()) {
819 }
820 datatype->getADTool().startAssembly(h);
821
822 if(nullptr != h) {
823 // gather the information for the reverse sweep
824
825 // create the index buffers
826 h->bufCount = datatype->computeActiveElements(count);
827 h->bufTotalSize = datatype->computeActiveElements(bufElements);
828 datatype->getADTool().createIndexTypeBuffer(h->bufIndices, h->bufTotalSize);
829
830
831 // extract the old primal values from the recv buffer if the AD tool
832 // needs the primal values reset
833 if(datatype->getADTool().isOldPrimalsRequired()) {
834 datatype->getADTool().createPrimalTypeBuffer(h->bufOldPrimals, h->bufTotalSize);
835 datatype->getValues(buf, 0, h->bufOldPrimals, 0, count);
836 }
837
838
839
840 datatype->createIndices(buf, 0, h->bufIndices, 0, count);
841
842 // pack all the variables in the handle
843 h->funcReverse = AMPI_Imrecv_b<DATATYPE>;
844 h->funcForward = AMPI_Imrecv_d_finish<DATATYPE>;
845 h->funcPrimal = AMPI_Imrecv_p_finish<DATATYPE>;
846 h->count = count;
847 h->datatype = datatype;
848 h->message = *message;
849 h->reverse_send = reverse_send;
850 }
851
852 if(!datatype->isModifiedBufferRequired()) {
853 datatype->clearIndices(buf, 0, count);
854 }
855
856 rStatus = MPI_Imrecv(bufMod, count, datatype->getModifiedMpiType(), &message->message, &request->request);
857
859 asyncHandle->buf = buf;
860 asyncHandle->bufMod = bufMod;
861 asyncHandle->count = count;
862 asyncHandle->datatype = datatype;
863 asyncHandle->message = message;
864 asyncHandle->reverse_send = reverse_send;
865 asyncHandle->toolHandle = h;
866 request->handle = asyncHandle;
867 request->func = (ContinueFunction)AMPI_Imrecv_finish<DATATYPE>;
868
869 // create adjoint wait
870 if(nullptr != h) {
871 WaitHandle* waitH = new WaitHandle((ReverseFunction)AMPI_Imrecv_b_finish<DATATYPE>,
872 (ForwardFunction)AMPI_Imrecv_d<DATATYPE>, h);
873 datatype->getADTool().addToolAction(waitH);
874 }
875 }
876
877 return rStatus;
878 }
879
880 template<typename DATATYPE>
882 int rStatus = 0;
883
884 AMPI_Imrecv_AsyncHandle<DATATYPE>* asyncHandle = static_cast<AMPI_Imrecv_AsyncHandle<DATATYPE>*>(handle);
885 typename DATATYPE::Type* buf = asyncHandle->buf;
886 typename DATATYPE::ModifiedType* bufMod = asyncHandle->bufMod;
887 int count = asyncHandle->count;
888 DATATYPE* datatype = asyncHandle->datatype;
889 AMPI_Message* message = asyncHandle->message;
890 AMPI_Request* request = asyncHandle->request;
891 IrecvAdjCall reverse_send = asyncHandle->reverse_send;
893 MEDI_UNUSED(h); // Unused generated to ignore warnings
894 MEDI_UNUSED(buf); // Unused generated to ignore warnings
895 MEDI_UNUSED(bufMod); // Unused generated to ignore warnings
896 MEDI_UNUSED(count); // Unused generated to ignore warnings
897 MEDI_UNUSED(datatype); // Unused generated to ignore warnings
898 MEDI_UNUSED(message); // Unused generated to ignore warnings
899 MEDI_UNUSED(request); // Unused generated to ignore warnings
900 MEDI_UNUSED(reverse_send); // Unused generated to ignore warnings
901
902 delete asyncHandle;
903
904 if(datatype->getADTool().isActiveType()) {
905
906 datatype->getADTool().addToolAction(h);
907
908 if(datatype->isModifiedBufferRequired()) {
909 datatype->copyFromModifiedBuffer(buf, 0, bufMod, 0, count);
910 }
911
912 if(nullptr != h) {
913 // handle the recv buffers
914 datatype->registerValue(buf, 0, h->bufIndices, h->bufOldPrimals, 0, count);
915 }
916
917 datatype->getADTool().stopAssembly(h);
918
919 if(datatype->isModifiedBufferRequired() ) {
920 datatype->deleteModifiedTypeBuffer(bufMod);
921 }
922
923 // handle is deleted by the AD tool
924 }
925
926 return rStatus;
927 }
928
929#endif
930#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
931 template<typename DATATYPE>
934 typename DATATYPE::IndexType* bufIndices;
935 typename DATATYPE::PrimalType* bufPrimals;
936 typename DATATYPE::PrimalType* bufOldPrimals;
937 /* required for async */ void* bufAdjoints;
940 int count;
941 DATATYPE* datatype;
943 int tag;
946
948 if(nullptr != bufIndices) {
949 datatype->getADTool().deleteIndexTypeBuffer(bufIndices);
950 bufIndices = nullptr;
951 }
952 if(nullptr != bufPrimals) {
953 datatype->getADTool().deletePrimalTypeBuffer(bufPrimals);
954 bufPrimals = nullptr;
955 }
956 if(nullptr != bufOldPrimals) {
957 datatype->getADTool().deletePrimalTypeBuffer(bufOldPrimals);
958 bufOldPrimals = nullptr;
959 }
960 }
961 };
962
963 template<typename DATATYPE>
965 typename DATATYPE::Type* buf;
966 typename DATATYPE::ModifiedType* bufMod;
967 int count;
968 DATATYPE* datatype;
970 int tag;
974 };
975
976 template<typename DATATYPE>
977 void AMPI_Irecv_p(HandleBase* handle, AdjointInterface* adjointInterface) {
979
980 h->bufAdjoints = nullptr;
981 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
982 adjointInterface->createPrimalTypeBuffer((void*&)h->bufPrimals, h->bufTotalSize );
983
984 AMPI_Irecv_pri<DATATYPE>(h->bufPrimals, h->bufCountVec, h->count, h->datatype, h->source, h->tag, h->comm,
986
987 }
988
989 template<typename DATATYPE>
990 void AMPI_Irecv_p_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
991
993 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
994
995 if(h->datatype->getADTool().isOldPrimalsRequired()) {
996 adjointInterface->getPrimals(h->bufIndices, h->bufOldPrimals, h->bufTotalSize);
997 }
998 // Primal buffers are always linear in space so we can accesses them in one sweep
999 adjointInterface->setPrimals(h->bufIndices, h->bufPrimals, h->bufTotalSize);
1000 adjointInterface->deletePrimalTypeBuffer((void*&)h->bufPrimals);
1001 }
1002
1003 template<typename DATATYPE>
1004 void AMPI_Irecv_d(HandleBase* handle, AdjointInterface* adjointInterface) {
1006
1007 h->bufAdjoints = nullptr;
1008 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
1009 adjointInterface->createAdjointTypeBuffer(h->bufAdjoints, h->bufTotalSize );
1010
1011 AMPI_Irecv_fwd<DATATYPE>(h->bufAdjoints, h->bufCountVec, h->count, h->datatype, h->source, h->tag, h->comm,
1013
1014 }
1015
1016 template<typename DATATYPE>
1017 void AMPI_Irecv_d_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
1018
1020 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
1021
1022 // Adjoint buffers are always linear in space so we can accesses them in one sweep
1023 adjointInterface->updateAdjoints(h->bufIndices, h->bufAdjoints, h->bufTotalSize);
1024 adjointInterface->deleteAdjointTypeBuffer(h->bufAdjoints);
1025 }
1026
1027 template<typename DATATYPE>
1028 void AMPI_Irecv_b(HandleBase* handle, AdjointInterface* adjointInterface) {
1030
1031 h->bufAdjoints = nullptr;
1032 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
1033 adjointInterface->createAdjointTypeBuffer(h->bufAdjoints, h->bufTotalSize );
1034 // Adjoint buffers are always linear in space so we can accesses them in one sweep
1035 adjointInterface->getAdjoints(h->bufIndices, h->bufAdjoints, h->bufTotalSize);
1036
1037 if(h->datatype->getADTool().isOldPrimalsRequired()) {
1038 adjointInterface->setPrimals(h->bufIndices, h->bufOldPrimals, h->bufTotalSize);
1039 }
1040
1041 AMPI_Irecv_adj<DATATYPE>(h->bufAdjoints, h->bufCountVec, h->count, h->datatype, h->source, h->tag, h->comm,
1043
1044 }
1045
1046 template<typename DATATYPE>
1047 void AMPI_Irecv_b_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
1048
1050 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
1051
1052 adjointInterface->deleteAdjointTypeBuffer(h->bufAdjoints);
1053 }
1054
1055 template<typename DATATYPE>
1056 int AMPI_Irecv_finish(HandleBase* handle);
1057 template<typename DATATYPE>
1058 int AMPI_Irecv(typename DATATYPE::Type* buf, int count, DATATYPE* datatype, int source, int tag, AMPI_Comm comm,
1059 AMPI_Request* request, IrecvAdjCall reverse_send = IrecvAdjCall::Isend) {
1060 int rStatus;
1061
1062 if(!datatype->getADTool().isActiveType()) {
1063 // call the regular function if the type is not active
1064 rStatus = MPI_Irecv(buf, count, datatype->getMpiType(), source, tag, comm, &request->request);
1065 } else {
1066
1067 // the type is an AD type so handle the buffers
1069 typename DATATYPE::ModifiedType* bufMod = nullptr;
1070 int bufElements = 0;
1071
1072 // compute the total size of the buffer
1073 bufElements = count;
1074
1075 if(datatype->isModifiedBufferRequired() ) {
1076 datatype->createModifiedTypeBuffer(bufMod, bufElements);
1077 } else {
1078 bufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(buf));
1079 }
1080
1081 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
1082 if(datatype->getADTool().isHandleRequired()) {
1084 }
1085 datatype->getADTool().startAssembly(h);
1086
1087 if(nullptr != h) {
1088 // gather the information for the reverse sweep
1089
1090 // create the index buffers
1091 h->bufCount = datatype->computeActiveElements(count);
1092 h->bufTotalSize = datatype->computeActiveElements(bufElements);
1093 datatype->getADTool().createIndexTypeBuffer(h->bufIndices, h->bufTotalSize);
1094
1095
1096 // extract the old primal values from the recv buffer if the AD tool
1097 // needs the primal values reset
1098 if(datatype->getADTool().isOldPrimalsRequired()) {
1099 datatype->getADTool().createPrimalTypeBuffer(h->bufOldPrimals, h->bufTotalSize);
1100 datatype->getValues(buf, 0, h->bufOldPrimals, 0, count);
1101 }
1102
1103
1104
1105 datatype->createIndices(buf, 0, h->bufIndices, 0, count);
1106
1107 // pack all the variables in the handle
1108 h->funcReverse = AMPI_Irecv_b<DATATYPE>;
1109 h->funcForward = AMPI_Irecv_d_finish<DATATYPE>;
1110 h->funcPrimal = AMPI_Irecv_p_finish<DATATYPE>;
1111 h->count = count;
1112 h->datatype = datatype;
1113 h->source = source;
1114 h->tag = tag;
1115 h->comm = comm;
1116 h->reverse_send = reverse_send;
1117 }
1118
1119 if(!datatype->isModifiedBufferRequired()) {
1120 datatype->clearIndices(buf, 0, count);
1121 }
1122
1123 rStatus = MPI_Irecv(bufMod, count, datatype->getModifiedMpiType(), source, tag, comm, &request->request);
1124
1126 asyncHandle->buf = buf;
1127 asyncHandle->bufMod = bufMod;
1128 asyncHandle->count = count;
1129 asyncHandle->datatype = datatype;
1130 asyncHandle->source = source;
1131 asyncHandle->tag = tag;
1132 asyncHandle->comm = comm;
1133 asyncHandle->reverse_send = reverse_send;
1134 asyncHandle->toolHandle = h;
1135 request->handle = asyncHandle;
1136 request->func = (ContinueFunction)AMPI_Irecv_finish<DATATYPE>;
1137
1138 // create adjoint wait
1139 if(nullptr != h) {
1140 WaitHandle* waitH = new WaitHandle((ReverseFunction)AMPI_Irecv_b_finish<DATATYPE>,
1141 (ForwardFunction)AMPI_Irecv_d<DATATYPE>, h);
1142 datatype->getADTool().addToolAction(waitH);
1143 }
1144 }
1145
1146 return rStatus;
1147 }
1148
1149 template<typename DATATYPE>
1151 int rStatus = 0;
1152
1153 AMPI_Irecv_AsyncHandle<DATATYPE>* asyncHandle = static_cast<AMPI_Irecv_AsyncHandle<DATATYPE>*>(handle);
1154 typename DATATYPE::Type* buf = asyncHandle->buf;
1155 typename DATATYPE::ModifiedType* bufMod = asyncHandle->bufMod;
1156 int count = asyncHandle->count;
1157 DATATYPE* datatype = asyncHandle->datatype;
1158 int source = asyncHandle->source;
1159 int tag = asyncHandle->tag;
1160 AMPI_Comm comm = asyncHandle->comm;
1161 AMPI_Request* request = asyncHandle->request;
1162 IrecvAdjCall reverse_send = asyncHandle->reverse_send;
1164 MEDI_UNUSED(h); // Unused generated to ignore warnings
1165 MEDI_UNUSED(buf); // Unused generated to ignore warnings
1166 MEDI_UNUSED(bufMod); // Unused generated to ignore warnings
1167 MEDI_UNUSED(count); // Unused generated to ignore warnings
1168 MEDI_UNUSED(datatype); // Unused generated to ignore warnings
1169 MEDI_UNUSED(source); // Unused generated to ignore warnings
1170 MEDI_UNUSED(tag); // Unused generated to ignore warnings
1171 MEDI_UNUSED(comm); // Unused generated to ignore warnings
1172 MEDI_UNUSED(request); // Unused generated to ignore warnings
1173 MEDI_UNUSED(reverse_send); // Unused generated to ignore warnings
1174
1175 delete asyncHandle;
1176
1177 if(datatype->getADTool().isActiveType()) {
1178
1179 datatype->getADTool().addToolAction(h);
1180
1181 if(datatype->isModifiedBufferRequired()) {
1182 datatype->copyFromModifiedBuffer(buf, 0, bufMod, 0, count);
1183 }
1184
1185 if(nullptr != h) {
1186 // handle the recv buffers
1187 datatype->registerValue(buf, 0, h->bufIndices, h->bufOldPrimals, 0, count);
1188 }
1189
1190 datatype->getADTool().stopAssembly(h);
1191
1192 if(datatype->isModifiedBufferRequired() ) {
1193 datatype->deleteModifiedTypeBuffer(bufMod);
1194 }
1195
1196 // handle is deleted by the AD tool
1197 }
1198
1199 return rStatus;
1200 }
1201
1202#endif
1203#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
1204 template<typename DATATYPE>
1207 typename DATATYPE::IndexType* bufIndices;
1208 typename DATATYPE::PrimalType* bufPrimals;
1209 /* required for async */ void* bufAdjoints;
1213 DATATYPE* datatype;
1214 int dest;
1215 int tag;
1217
1219 if(nullptr != bufIndices) {
1220 datatype->getADTool().deleteIndexTypeBuffer(bufIndices);
1221 bufIndices = nullptr;
1222 }
1223 if(nullptr != bufPrimals) {
1224 datatype->getADTool().deletePrimalTypeBuffer(bufPrimals);
1225 bufPrimals = nullptr;
1226 }
1227 }
1228 };
1229
1230 template<typename DATATYPE>
1232 MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf;
1233 typename DATATYPE::ModifiedType* bufMod;
1235 DATATYPE* datatype;
1236 int dest;
1237 int tag;
1240 };
1241
1242 template<typename DATATYPE>
1243 void AMPI_Irsend_p(HandleBase* handle, AdjointInterface* adjointInterface) {
1245
1246 h->bufAdjoints = nullptr;
1247 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
1248 adjointInterface->createPrimalTypeBuffer((void*&)h->bufPrimals, h->bufTotalSize );
1249 // Primal buffers are always linear in space so we can accesses them in one sweep
1250 adjointInterface->getPrimals(h->bufIndices, h->bufPrimals, h->bufTotalSize);
1251
1252
1253 AMPI_Irsend_pri<DATATYPE>(h->bufPrimals, h->bufCountVec, h->count, h->datatype, h->dest, h->tag, h->comm,
1254 &h->requestReverse);
1255
1256 }
1257
1258 template<typename DATATYPE>
1259 void AMPI_Irsend_p_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
1260
1262 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
1263
1264 adjointInterface->deletePrimalTypeBuffer((void*&)h->bufPrimals);
1265 }
1266
1267 template<typename DATATYPE>
1268 void AMPI_Irsend_d(HandleBase* handle, AdjointInterface* adjointInterface) {
1270
1271 h->bufAdjoints = nullptr;
1272 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
1273 adjointInterface->createAdjointTypeBuffer(h->bufAdjoints, h->bufTotalSize );
1274 // Adjoint buffers are always linear in space so we can accesses them in one sweep
1275 adjointInterface->getAdjoints(h->bufIndices, h->bufAdjoints, h->bufTotalSize);
1276
1277
1278 AMPI_Irsend_fwd<DATATYPE>(h->bufAdjoints, h->bufCountVec, h->count, h->datatype, h->dest, h->tag, h->comm,
1279 &h->requestReverse);
1280
1281 }
1282
1283 template<typename DATATYPE>
1284 void AMPI_Irsend_d_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
1285
1287 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
1288
1289 adjointInterface->deleteAdjointTypeBuffer(h->bufAdjoints);
1290 }
1291
1292 template<typename DATATYPE>
1293 void AMPI_Irsend_b(HandleBase* handle, AdjointInterface* adjointInterface) {
1295
1296 h->bufAdjoints = nullptr;
1297 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
1298 adjointInterface->createAdjointTypeBuffer(h->bufAdjoints, h->bufTotalSize );
1299
1300 AMPI_Irsend_adj<DATATYPE>(h->bufAdjoints, h->bufCountVec, h->count, h->datatype, h->dest, h->tag, h->comm,
1301 &h->requestReverse);
1302
1303 }
1304
1305 template<typename DATATYPE>
1306 void AMPI_Irsend_b_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
1307
1309 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
1310
1311 // Adjoint buffers are always linear in space so we can accesses them in one sweep
1312 adjointInterface->updateAdjoints(h->bufIndices, h->bufAdjoints, h->bufTotalSize);
1313 adjointInterface->deleteAdjointTypeBuffer(h->bufAdjoints);
1314 }
1315
1316 template<typename DATATYPE>
1317 int AMPI_Irsend_finish(HandleBase* handle);
1318 template<typename DATATYPE>
1319 int AMPI_Irsend(MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf, int count, DATATYPE* datatype, int dest, int tag,
1320 AMPI_Comm comm, AMPI_Request* request) {
1321 int rStatus;
1322
1323 if(!datatype->getADTool().isActiveType()) {
1324 // call the regular function if the type is not active
1325 rStatus = MPI_Irsend(buf, count, datatype->getMpiType(), dest, tag, comm, &request->request);
1326 } else {
1327
1328 // the type is an AD type so handle the buffers
1330 typename DATATYPE::ModifiedType* bufMod = nullptr;
1331 int bufElements = 0;
1332
1333 // compute the total size of the buffer
1334 bufElements = count;
1335
1336 if(datatype->isModifiedBufferRequired() ) {
1337 datatype->createModifiedTypeBuffer(bufMod, bufElements);
1338 } else {
1339 bufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(buf));
1340 }
1341
1342 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
1343 if(datatype->getADTool().isHandleRequired()) {
1345 }
1346 datatype->getADTool().startAssembly(h);
1347 if(datatype->isModifiedBufferRequired()) {
1348 datatype->copyIntoModifiedBuffer(buf, 0, bufMod, 0, count);
1349 }
1350
1351 if(nullptr != h) {
1352 // gather the information for the reverse sweep
1353
1354 // create the index buffers
1355 h->bufCount = datatype->computeActiveElements(count);
1356 h->bufTotalSize = datatype->computeActiveElements(bufElements);
1357 datatype->getADTool().createIndexTypeBuffer(h->bufIndices, h->bufTotalSize);
1358
1359
1360
1361
1362 datatype->getIndices(buf, 0, h->bufIndices, 0, count);
1363
1364
1365 // pack all the variables in the handle
1366 h->funcReverse = AMPI_Irsend_b<DATATYPE>;
1367 h->funcForward = AMPI_Irsend_d_finish<DATATYPE>;
1368 h->funcPrimal = AMPI_Irsend_p_finish<DATATYPE>;
1369 h->count = count;
1370 h->datatype = datatype;
1371 h->dest = dest;
1372 h->tag = tag;
1373 h->comm = comm;
1374 }
1375
1376
1377 rStatus = MPI_Irsend(bufMod, count, datatype->getModifiedMpiType(), dest, tag, comm, &request->request);
1378
1380 asyncHandle->buf = buf;
1381 asyncHandle->bufMod = bufMod;
1382 asyncHandle->count = count;
1383 asyncHandle->datatype = datatype;
1384 asyncHandle->dest = dest;
1385 asyncHandle->tag = tag;
1386 asyncHandle->comm = comm;
1387 asyncHandle->toolHandle = h;
1388 request->handle = asyncHandle;
1389 request->func = (ContinueFunction)AMPI_Irsend_finish<DATATYPE>;
1390
1391 // create adjoint wait
1392 if(nullptr != h) {
1393 WaitHandle* waitH = new WaitHandle((ReverseFunction)AMPI_Irsend_b_finish<DATATYPE>,
1394 (ForwardFunction)AMPI_Irsend_d<DATATYPE>, h);
1395 datatype->getADTool().addToolAction(waitH);
1396 }
1397 }
1398
1399 return rStatus;
1400 }
1401
1402 template<typename DATATYPE>
1404 int rStatus = 0;
1405
1406 AMPI_Irsend_AsyncHandle<DATATYPE>* asyncHandle = static_cast<AMPI_Irsend_AsyncHandle<DATATYPE>*>(handle);
1407 MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf = asyncHandle->buf;
1408 typename DATATYPE::ModifiedType* bufMod = asyncHandle->bufMod;
1409 int count = asyncHandle->count;
1410 DATATYPE* datatype = asyncHandle->datatype;
1411 int dest = asyncHandle->dest;
1412 int tag = asyncHandle->tag;
1413 AMPI_Comm comm = asyncHandle->comm;
1414 AMPI_Request* request = asyncHandle->request;
1416 MEDI_UNUSED(h); // Unused generated to ignore warnings
1417 MEDI_UNUSED(buf); // Unused generated to ignore warnings
1418 MEDI_UNUSED(bufMod); // Unused generated to ignore warnings
1419 MEDI_UNUSED(count); // Unused generated to ignore warnings
1420 MEDI_UNUSED(datatype); // Unused generated to ignore warnings
1421 MEDI_UNUSED(dest); // Unused generated to ignore warnings
1422 MEDI_UNUSED(tag); // Unused generated to ignore warnings
1423 MEDI_UNUSED(comm); // Unused generated to ignore warnings
1424 MEDI_UNUSED(request); // Unused generated to ignore warnings
1425
1426 delete asyncHandle;
1427
1428 if(datatype->getADTool().isActiveType()) {
1429
1430 datatype->getADTool().addToolAction(h);
1431
1432
1433 if(nullptr != h) {
1434 // handle the recv buffers
1435 }
1436
1437 datatype->getADTool().stopAssembly(h);
1438
1439 if(datatype->isModifiedBufferRequired() ) {
1440 datatype->deleteModifiedTypeBuffer(bufMod);
1441 }
1442
1443 // handle is deleted by the AD tool
1444 }
1445
1446 return rStatus;
1447 }
1448
1449#endif
1450#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
1451 template<typename DATATYPE>
1454 typename DATATYPE::IndexType* bufIndices;
1455 typename DATATYPE::PrimalType* bufPrimals;
1456 /* required for async */ void* bufAdjoints;
1460 DATATYPE* datatype;
1461 int dest;
1462 int tag;
1464
1466 if(nullptr != bufIndices) {
1467 datatype->getADTool().deleteIndexTypeBuffer(bufIndices);
1468 bufIndices = nullptr;
1469 }
1470 if(nullptr != bufPrimals) {
1471 datatype->getADTool().deletePrimalTypeBuffer(bufPrimals);
1472 bufPrimals = nullptr;
1473 }
1474 }
1475 };
1476
1477 template<typename DATATYPE>
1479 MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf;
1480 typename DATATYPE::ModifiedType* bufMod;
1482 DATATYPE* datatype;
1483 int dest;
1484 int tag;
1487 };
1488
1489 template<typename DATATYPE>
1490 void AMPI_Isend_p(HandleBase* handle, AdjointInterface* adjointInterface) {
1492
1493 h->bufAdjoints = nullptr;
1494 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
1495 adjointInterface->createPrimalTypeBuffer((void*&)h->bufPrimals, h->bufTotalSize );
1496 // Primal buffers are always linear in space so we can accesses them in one sweep
1497 adjointInterface->getPrimals(h->bufIndices, h->bufPrimals, h->bufTotalSize);
1498
1499
1500 AMPI_Isend_pri<DATATYPE>(h->bufPrimals, h->bufCountVec, h->count, h->datatype, h->dest, h->tag, h->comm,
1501 &h->requestReverse);
1502
1503 }
1504
1505 template<typename DATATYPE>
1506 void AMPI_Isend_p_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
1507
1509 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
1510
1511 adjointInterface->deletePrimalTypeBuffer((void*&)h->bufPrimals);
1512 }
1513
1514 template<typename DATATYPE>
1515 void AMPI_Isend_d(HandleBase* handle, AdjointInterface* adjointInterface) {
1517
1518 h->bufAdjoints = nullptr;
1519 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
1520 adjointInterface->createAdjointTypeBuffer(h->bufAdjoints, h->bufTotalSize );
1521 // Adjoint buffers are always linear in space so we can accesses them in one sweep
1522 adjointInterface->getAdjoints(h->bufIndices, h->bufAdjoints, h->bufTotalSize);
1523
1524
1525 AMPI_Isend_fwd<DATATYPE>(h->bufAdjoints, h->bufCountVec, h->count, h->datatype, h->dest, h->tag, h->comm,
1526 &h->requestReverse);
1527
1528 }
1529
1530 template<typename DATATYPE>
1531 void AMPI_Isend_d_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
1532
1534 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
1535
1536 adjointInterface->deleteAdjointTypeBuffer(h->bufAdjoints);
1537 }
1538
1539 template<typename DATATYPE>
1540 void AMPI_Isend_b(HandleBase* handle, AdjointInterface* adjointInterface) {
1542
1543 h->bufAdjoints = nullptr;
1544 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
1545 adjointInterface->createAdjointTypeBuffer(h->bufAdjoints, h->bufTotalSize );
1546
1547 AMPI_Isend_adj<DATATYPE>(h->bufAdjoints, h->bufCountVec, h->count, h->datatype, h->dest, h->tag, h->comm,
1548 &h->requestReverse);
1549
1550 }
1551
1552 template<typename DATATYPE>
1553 void AMPI_Isend_b_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
1554
1556 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
1557
1558 // Adjoint buffers are always linear in space so we can accesses them in one sweep
1559 adjointInterface->updateAdjoints(h->bufIndices, h->bufAdjoints, h->bufTotalSize);
1560 adjointInterface->deleteAdjointTypeBuffer(h->bufAdjoints);
1561 }
1562
1563 template<typename DATATYPE>
1564 int AMPI_Isend_finish(HandleBase* handle);
1565 template<typename DATATYPE>
1566 int AMPI_Isend(MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf, int count, DATATYPE* datatype, int dest, int tag,
1567 AMPI_Comm comm, AMPI_Request* request) {
1568 int rStatus;
1569
1570 if(!datatype->getADTool().isActiveType()) {
1571 // call the regular function if the type is not active
1572 rStatus = MPI_Isend(buf, count, datatype->getMpiType(), dest, tag, comm, &request->request);
1573 } else {
1574
1575 // the type is an AD type so handle the buffers
1577 typename DATATYPE::ModifiedType* bufMod = nullptr;
1578 int bufElements = 0;
1579
1580 // compute the total size of the buffer
1581 bufElements = count;
1582
1583 if(datatype->isModifiedBufferRequired() ) {
1584 datatype->createModifiedTypeBuffer(bufMod, bufElements);
1585 } else {
1586 bufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(buf));
1587 }
1588
1589 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
1590 if(datatype->getADTool().isHandleRequired()) {
1592 }
1593 datatype->getADTool().startAssembly(h);
1594 if(datatype->isModifiedBufferRequired()) {
1595 datatype->copyIntoModifiedBuffer(buf, 0, bufMod, 0, count);
1596 }
1597
1598 if(nullptr != h) {
1599 // gather the information for the reverse sweep
1600
1601 // create the index buffers
1602 h->bufCount = datatype->computeActiveElements(count);
1603 h->bufTotalSize = datatype->computeActiveElements(bufElements);
1604 datatype->getADTool().createIndexTypeBuffer(h->bufIndices, h->bufTotalSize);
1605
1606
1607
1608
1609 datatype->getIndices(buf, 0, h->bufIndices, 0, count);
1610
1611
1612 // pack all the variables in the handle
1613 h->funcReverse = AMPI_Isend_b<DATATYPE>;
1614 h->funcForward = AMPI_Isend_d_finish<DATATYPE>;
1615 h->funcPrimal = AMPI_Isend_p_finish<DATATYPE>;
1616 h->count = count;
1617 h->datatype = datatype;
1618 h->dest = dest;
1619 h->tag = tag;
1620 h->comm = comm;
1621 }
1622
1623
1624 rStatus = MPI_Isend(bufMod, count, datatype->getModifiedMpiType(), dest, tag, comm, &request->request);
1625
1627 asyncHandle->buf = buf;
1628 asyncHandle->bufMod = bufMod;
1629 asyncHandle->count = count;
1630 asyncHandle->datatype = datatype;
1631 asyncHandle->dest = dest;
1632 asyncHandle->tag = tag;
1633 asyncHandle->comm = comm;
1634 asyncHandle->toolHandle = h;
1635 request->handle = asyncHandle;
1636 request->func = (ContinueFunction)AMPI_Isend_finish<DATATYPE>;
1637
1638 // create adjoint wait
1639 if(nullptr != h) {
1640 WaitHandle* waitH = new WaitHandle((ReverseFunction)AMPI_Isend_b_finish<DATATYPE>,
1641 (ForwardFunction)AMPI_Isend_d<DATATYPE>, h);
1642 datatype->getADTool().addToolAction(waitH);
1643 }
1644 }
1645
1646 return rStatus;
1647 }
1648
1649 template<typename DATATYPE>
1651 int rStatus = 0;
1652
1653 AMPI_Isend_AsyncHandle<DATATYPE>* asyncHandle = static_cast<AMPI_Isend_AsyncHandle<DATATYPE>*>(handle);
1654 MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf = asyncHandle->buf;
1655 typename DATATYPE::ModifiedType* bufMod = asyncHandle->bufMod;
1656 int count = asyncHandle->count;
1657 DATATYPE* datatype = asyncHandle->datatype;
1658 int dest = asyncHandle->dest;
1659 int tag = asyncHandle->tag;
1660 AMPI_Comm comm = asyncHandle->comm;
1661 AMPI_Request* request = asyncHandle->request;
1663 MEDI_UNUSED(h); // Unused generated to ignore warnings
1664 MEDI_UNUSED(buf); // Unused generated to ignore warnings
1665 MEDI_UNUSED(bufMod); // Unused generated to ignore warnings
1666 MEDI_UNUSED(count); // Unused generated to ignore warnings
1667 MEDI_UNUSED(datatype); // Unused generated to ignore warnings
1668 MEDI_UNUSED(dest); // Unused generated to ignore warnings
1669 MEDI_UNUSED(tag); // Unused generated to ignore warnings
1670 MEDI_UNUSED(comm); // Unused generated to ignore warnings
1671 MEDI_UNUSED(request); // Unused generated to ignore warnings
1672
1673 delete asyncHandle;
1674
1675 if(datatype->getADTool().isActiveType()) {
1676
1677 datatype->getADTool().addToolAction(h);
1678
1679
1680 if(nullptr != h) {
1681 // handle the recv buffers
1682 }
1683
1684 datatype->getADTool().stopAssembly(h);
1685
1686 if(datatype->isModifiedBufferRequired() ) {
1687 datatype->deleteModifiedTypeBuffer(bufMod);
1688 }
1689
1690 // handle is deleted by the AD tool
1691 }
1692
1693 return rStatus;
1694 }
1695
1696#endif
1697#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
1698 template<typename DATATYPE>
1701 typename DATATYPE::IndexType* bufIndices;
1702 typename DATATYPE::PrimalType* bufPrimals;
1703 /* required for async */ void* bufAdjoints;
1707 DATATYPE* datatype;
1708 int dest;
1709 int tag;
1711
1713 if(nullptr != bufIndices) {
1714 datatype->getADTool().deleteIndexTypeBuffer(bufIndices);
1715 bufIndices = nullptr;
1716 }
1717 if(nullptr != bufPrimals) {
1718 datatype->getADTool().deletePrimalTypeBuffer(bufPrimals);
1719 bufPrimals = nullptr;
1720 }
1721 }
1722 };
1723
1724 template<typename DATATYPE>
1726 MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf;
1727 typename DATATYPE::ModifiedType* bufMod;
1729 DATATYPE* datatype;
1730 int dest;
1731 int tag;
1734 };
1735
1736 template<typename DATATYPE>
1737 void AMPI_Issend_p(HandleBase* handle, AdjointInterface* adjointInterface) {
1739
1740 h->bufAdjoints = nullptr;
1741 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
1742 adjointInterface->createPrimalTypeBuffer((void*&)h->bufPrimals, h->bufTotalSize );
1743 // Primal buffers are always linear in space so we can accesses them in one sweep
1744 adjointInterface->getPrimals(h->bufIndices, h->bufPrimals, h->bufTotalSize);
1745
1746
1747 AMPI_Issend_pri<DATATYPE>(h->bufPrimals, h->bufCountVec, h->count, h->datatype, h->dest, h->tag, h->comm,
1748 &h->requestReverse);
1749
1750 }
1751
1752 template<typename DATATYPE>
1753 void AMPI_Issend_p_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
1754
1756 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
1757
1758 adjointInterface->deletePrimalTypeBuffer((void*&)h->bufPrimals);
1759 }
1760
1761 template<typename DATATYPE>
1762 void AMPI_Issend_d(HandleBase* handle, AdjointInterface* adjointInterface) {
1764
1765 h->bufAdjoints = nullptr;
1766 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
1767 adjointInterface->createAdjointTypeBuffer(h->bufAdjoints, h->bufTotalSize );
1768 // Adjoint buffers are always linear in space so we can accesses them in one sweep
1769 adjointInterface->getAdjoints(h->bufIndices, h->bufAdjoints, h->bufTotalSize);
1770
1771
1772 AMPI_Issend_fwd<DATATYPE>(h->bufAdjoints, h->bufCountVec, h->count, h->datatype, h->dest, h->tag, h->comm,
1773 &h->requestReverse);
1774
1775 }
1776
1777 template<typename DATATYPE>
1778 void AMPI_Issend_d_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
1779
1781 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
1782
1783 adjointInterface->deleteAdjointTypeBuffer(h->bufAdjoints);
1784 }
1785
1786 template<typename DATATYPE>
1787 void AMPI_Issend_b(HandleBase* handle, AdjointInterface* adjointInterface) {
1789
1790 h->bufAdjoints = nullptr;
1791 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
1792 adjointInterface->createAdjointTypeBuffer(h->bufAdjoints, h->bufTotalSize );
1793
1794 AMPI_Issend_adj<DATATYPE>(h->bufAdjoints, h->bufCountVec, h->count, h->datatype, h->dest, h->tag, h->comm,
1795 &h->requestReverse);
1796
1797 }
1798
1799 template<typename DATATYPE>
1800 void AMPI_Issend_b_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
1801
1803 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
1804
1805 // Adjoint buffers are always linear in space so we can accesses them in one sweep
1806 adjointInterface->updateAdjoints(h->bufIndices, h->bufAdjoints, h->bufTotalSize);
1807 adjointInterface->deleteAdjointTypeBuffer(h->bufAdjoints);
1808 }
1809
1810 template<typename DATATYPE>
1811 int AMPI_Issend_finish(HandleBase* handle);
1812 template<typename DATATYPE>
1813 int AMPI_Issend(MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf, int count, DATATYPE* datatype, int dest, int tag,
1814 AMPI_Comm comm, AMPI_Request* request) {
1815 int rStatus;
1816
1817 if(!datatype->getADTool().isActiveType()) {
1818 // call the regular function if the type is not active
1819 rStatus = MPI_Issend(buf, count, datatype->getMpiType(), dest, tag, comm, &request->request);
1820 } else {
1821
1822 // the type is an AD type so handle the buffers
1824 typename DATATYPE::ModifiedType* bufMod = nullptr;
1825 int bufElements = 0;
1826
1827 // compute the total size of the buffer
1828 bufElements = count;
1829
1830 if(datatype->isModifiedBufferRequired() ) {
1831 datatype->createModifiedTypeBuffer(bufMod, bufElements);
1832 } else {
1833 bufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(buf));
1834 }
1835
1836 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
1837 if(datatype->getADTool().isHandleRequired()) {
1839 }
1840 datatype->getADTool().startAssembly(h);
1841 if(datatype->isModifiedBufferRequired()) {
1842 datatype->copyIntoModifiedBuffer(buf, 0, bufMod, 0, count);
1843 }
1844
1845 if(nullptr != h) {
1846 // gather the information for the reverse sweep
1847
1848 // create the index buffers
1849 h->bufCount = datatype->computeActiveElements(count);
1850 h->bufTotalSize = datatype->computeActiveElements(bufElements);
1851 datatype->getADTool().createIndexTypeBuffer(h->bufIndices, h->bufTotalSize);
1852
1853
1854
1855
1856 datatype->getIndices(buf, 0, h->bufIndices, 0, count);
1857
1858
1859 // pack all the variables in the handle
1860 h->funcReverse = AMPI_Issend_b<DATATYPE>;
1861 h->funcForward = AMPI_Issend_d_finish<DATATYPE>;
1862 h->funcPrimal = AMPI_Issend_p_finish<DATATYPE>;
1863 h->count = count;
1864 h->datatype = datatype;
1865 h->dest = dest;
1866 h->tag = tag;
1867 h->comm = comm;
1868 }
1869
1870
1871 rStatus = MPI_Issend(bufMod, count, datatype->getModifiedMpiType(), dest, tag, comm, &request->request);
1872
1874 asyncHandle->buf = buf;
1875 asyncHandle->bufMod = bufMod;
1876 asyncHandle->count = count;
1877 asyncHandle->datatype = datatype;
1878 asyncHandle->dest = dest;
1879 asyncHandle->tag = tag;
1880 asyncHandle->comm = comm;
1881 asyncHandle->toolHandle = h;
1882 request->handle = asyncHandle;
1883 request->func = (ContinueFunction)AMPI_Issend_finish<DATATYPE>;
1884
1885 // create adjoint wait
1886 if(nullptr != h) {
1887 WaitHandle* waitH = new WaitHandle((ReverseFunction)AMPI_Issend_b_finish<DATATYPE>,
1888 (ForwardFunction)AMPI_Issend_d<DATATYPE>, h);
1889 datatype->getADTool().addToolAction(waitH);
1890 }
1891 }
1892
1893 return rStatus;
1894 }
1895
1896 template<typename DATATYPE>
1898 int rStatus = 0;
1899
1900 AMPI_Issend_AsyncHandle<DATATYPE>* asyncHandle = static_cast<AMPI_Issend_AsyncHandle<DATATYPE>*>(handle);
1901 MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf = asyncHandle->buf;
1902 typename DATATYPE::ModifiedType* bufMod = asyncHandle->bufMod;
1903 int count = asyncHandle->count;
1904 DATATYPE* datatype = asyncHandle->datatype;
1905 int dest = asyncHandle->dest;
1906 int tag = asyncHandle->tag;
1907 AMPI_Comm comm = asyncHandle->comm;
1908 AMPI_Request* request = asyncHandle->request;
1910 MEDI_UNUSED(h); // Unused generated to ignore warnings
1911 MEDI_UNUSED(buf); // Unused generated to ignore warnings
1912 MEDI_UNUSED(bufMod); // Unused generated to ignore warnings
1913 MEDI_UNUSED(count); // Unused generated to ignore warnings
1914 MEDI_UNUSED(datatype); // Unused generated to ignore warnings
1915 MEDI_UNUSED(dest); // Unused generated to ignore warnings
1916 MEDI_UNUSED(tag); // Unused generated to ignore warnings
1917 MEDI_UNUSED(comm); // Unused generated to ignore warnings
1918 MEDI_UNUSED(request); // Unused generated to ignore warnings
1919
1920 delete asyncHandle;
1921
1922 if(datatype->getADTool().isActiveType()) {
1923
1924 datatype->getADTool().addToolAction(h);
1925
1926
1927 if(nullptr != h) {
1928 // handle the recv buffers
1929 }
1930
1931 datatype->getADTool().stopAssembly(h);
1932
1933 if(datatype->isModifiedBufferRequired() ) {
1934 datatype->deleteModifiedTypeBuffer(bufMod);
1935 }
1936
1937 // handle is deleted by the AD tool
1938 }
1939
1940 return rStatus;
1941 }
1942
1943#endif
1944#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
1945 template<typename DATATYPE>
1948 typename DATATYPE::IndexType* bufIndices;
1949 typename DATATYPE::PrimalType* bufPrimals;
1950 typename DATATYPE::PrimalType* bufOldPrimals;
1951 /* required for async */ void* bufAdjoints;
1955 DATATYPE* datatype;
1959
1961 if(nullptr != bufIndices) {
1962 datatype->getADTool().deleteIndexTypeBuffer(bufIndices);
1963 bufIndices = nullptr;
1964 }
1965 if(nullptr != bufPrimals) {
1966 datatype->getADTool().deletePrimalTypeBuffer(bufPrimals);
1967 bufPrimals = nullptr;
1968 }
1969 if(nullptr != bufOldPrimals) {
1970 datatype->getADTool().deletePrimalTypeBuffer(bufOldPrimals);
1971 bufOldPrimals = nullptr;
1972 }
1973 }
1974 };
1975
1976
1977 template<typename DATATYPE>
1978 void AMPI_Mrecv_p(HandleBase* handle, AdjointInterface* adjointInterface) {
1980
1981 h->bufAdjoints = nullptr;
1982 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
1983 adjointInterface->createPrimalTypeBuffer((void*&)h->bufPrimals, h->bufTotalSize );
1984
1985 AMPI_Mrecv_pri<DATATYPE>(h->bufPrimals, h->bufCountVec, h->count, h->datatype, &h->message, h->status, h->reverse_send);
1986
1987 if(h->datatype->getADTool().isOldPrimalsRequired()) {
1988 adjointInterface->getPrimals(h->bufIndices, h->bufOldPrimals, h->bufTotalSize);
1989 }
1990 // Primal buffers are always linear in space so we can accesses them in one sweep
1991 adjointInterface->setPrimals(h->bufIndices, h->bufPrimals, h->bufTotalSize);
1992 adjointInterface->deletePrimalTypeBuffer((void*&)h->bufPrimals);
1993 }
1994
1995 template<typename DATATYPE>
1996 void AMPI_Mrecv_d(HandleBase* handle, AdjointInterface* adjointInterface) {
1998
1999 h->bufAdjoints = nullptr;
2000 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
2001 adjointInterface->createAdjointTypeBuffer(h->bufAdjoints, h->bufTotalSize );
2002
2003 AMPI_Mrecv_fwd<DATATYPE>(h->bufAdjoints, h->bufCountVec, h->count, h->datatype, &h->message, h->status,
2004 h->reverse_send);
2005
2006 // Adjoint buffers are always linear in space so we can accesses them in one sweep
2007 adjointInterface->updateAdjoints(h->bufIndices, h->bufAdjoints, h->bufTotalSize);
2008 adjointInterface->deleteAdjointTypeBuffer(h->bufAdjoints);
2009 }
2010
2011 template<typename DATATYPE>
2012 void AMPI_Mrecv_b(HandleBase* handle, AdjointInterface* adjointInterface) {
2014
2015 h->bufAdjoints = nullptr;
2016 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
2017 adjointInterface->createAdjointTypeBuffer(h->bufAdjoints, h->bufTotalSize );
2018 // Adjoint buffers are always linear in space so we can accesses them in one sweep
2019 adjointInterface->getAdjoints(h->bufIndices, h->bufAdjoints, h->bufTotalSize);
2020
2021 if(h->datatype->getADTool().isOldPrimalsRequired()) {
2022 adjointInterface->setPrimals(h->bufIndices, h->bufOldPrimals, h->bufTotalSize);
2023 }
2024
2025 AMPI_Mrecv_adj<DATATYPE>(h->bufAdjoints, h->bufCountVec, h->count, h->datatype, &h->message, h->status,
2026 h->reverse_send);
2027
2028 adjointInterface->deleteAdjointTypeBuffer(h->bufAdjoints);
2029 }
2030
2031 template<typename DATATYPE>
2032 int AMPI_Mrecv(typename DATATYPE::Type* buf, int count, DATATYPE* datatype, AMPI_Message* message, AMPI_Status* status,
2033 RecvAdjCall reverse_send = RecvAdjCall::Send) {
2034 int rStatus;
2035
2036 if(!datatype->getADTool().isActiveType()) {
2037 // call the regular function if the type is not active
2038 rStatus = MPI_Mrecv(buf, count, datatype->getMpiType(), &message->message, status);
2039 } else {
2040
2041 // the type is an AD type so handle the buffers
2043 typename DATATYPE::ModifiedType* bufMod = nullptr;
2044 int bufElements = 0;
2045
2046 // compute the total size of the buffer
2047 bufElements = count;
2048
2049 if(datatype->isModifiedBufferRequired() ) {
2050 datatype->createModifiedTypeBuffer(bufMod, bufElements);
2051 } else {
2052 bufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(buf));
2053 }
2054
2055 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
2056 if(datatype->getADTool().isHandleRequired()) {
2058 }
2059 datatype->getADTool().startAssembly(h);
2060
2061 if(nullptr != h) {
2062 // gather the information for the reverse sweep
2063
2064 // create the index buffers
2065 h->bufCount = datatype->computeActiveElements(count);
2066 h->bufTotalSize = datatype->computeActiveElements(bufElements);
2067 datatype->getADTool().createIndexTypeBuffer(h->bufIndices, h->bufTotalSize);
2068
2069
2070 // extract the old primal values from the recv buffer if the AD tool
2071 // needs the primal values reset
2072 if(datatype->getADTool().isOldPrimalsRequired()) {
2073 datatype->getADTool().createPrimalTypeBuffer(h->bufOldPrimals, h->bufTotalSize);
2074 datatype->getValues(buf, 0, h->bufOldPrimals, 0, count);
2075 }
2076
2077
2078
2079 datatype->createIndices(buf, 0, h->bufIndices, 0, count);
2080
2081 // pack all the variables in the handle
2082 h->funcReverse = AMPI_Mrecv_b<DATATYPE>;
2083 h->funcForward = AMPI_Mrecv_d<DATATYPE>;
2084 h->funcPrimal = AMPI_Mrecv_p<DATATYPE>;
2085 h->count = count;
2086 h->datatype = datatype;
2087 h->message = *message;
2088 h->status = status;
2089 h->reverse_send = reverse_send;
2090 }
2091
2092 if(!datatype->isModifiedBufferRequired()) {
2093 datatype->clearIndices(buf, 0, count);
2094 }
2095
2096 rStatus = MPI_Mrecv(bufMod, count, datatype->getModifiedMpiType(), &message->message, status);
2097 datatype->getADTool().addToolAction(h);
2098
2099 if(datatype->isModifiedBufferRequired()) {
2100 datatype->copyFromModifiedBuffer(buf, 0, bufMod, 0, count);
2101 }
2102
2103 if(nullptr != h) {
2104 // handle the recv buffers
2105 datatype->registerValue(buf, 0, h->bufIndices, h->bufOldPrimals, 0, count);
2106 }
2107
2108 datatype->getADTool().stopAssembly(h);
2109
2110 if(datatype->isModifiedBufferRequired() ) {
2111 datatype->deleteModifiedTypeBuffer(bufMod);
2112 }
2113
2114 // handle is deleted by the AD tool
2115 }
2116
2117 return rStatus;
2118 }
2119
2120#endif
2121#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
2122 template<typename DATATYPE>
2125 typename DATATYPE::IndexType* bufIndices;
2126 typename DATATYPE::PrimalType* bufPrimals;
2127 typename DATATYPE::PrimalType* bufOldPrimals;
2128 /* required for async */ void* bufAdjoints;
2132 DATATYPE* datatype;
2134 int tag;
2137
2139 if(nullptr != bufIndices) {
2140 datatype->getADTool().deleteIndexTypeBuffer(bufIndices);
2141 bufIndices = nullptr;
2142 }
2143 if(nullptr != bufPrimals) {
2144 datatype->getADTool().deletePrimalTypeBuffer(bufPrimals);
2145 bufPrimals = nullptr;
2146 }
2147 if(nullptr != bufOldPrimals) {
2148 datatype->getADTool().deletePrimalTypeBuffer(bufOldPrimals);
2149 bufOldPrimals = nullptr;
2150 }
2151 }
2152 };
2153
2154
2155 template<typename DATATYPE>
2156 void AMPI_Recv_p(HandleBase* handle, AdjointInterface* adjointInterface) {
2158
2159 MPI_Status status;
2160 h->bufAdjoints = nullptr;
2161 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
2162 adjointInterface->createPrimalTypeBuffer((void*&)h->bufPrimals, h->bufTotalSize );
2163
2164 AMPI_Recv_pri<DATATYPE>(h->bufPrimals, h->bufCountVec, h->count, h->datatype, h->source, h->tag, h->comm, &status,
2165 h->reverse_send);
2166
2167 if(h->datatype->getADTool().isOldPrimalsRequired()) {
2168 adjointInterface->getPrimals(h->bufIndices, h->bufOldPrimals, h->bufTotalSize);
2169 }
2170 // Primal buffers are always linear in space so we can accesses them in one sweep
2171 adjointInterface->setPrimals(h->bufIndices, h->bufPrimals, h->bufTotalSize);
2172 adjointInterface->deletePrimalTypeBuffer((void*&)h->bufPrimals);
2173 }
2174
2175 template<typename DATATYPE>
2176 void AMPI_Recv_d(HandleBase* handle, AdjointInterface* adjointInterface) {
2178
2179 MPI_Status status;
2180 h->bufAdjoints = nullptr;
2181 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
2182 adjointInterface->createAdjointTypeBuffer(h->bufAdjoints, h->bufTotalSize );
2183
2184 AMPI_Recv_fwd<DATATYPE>(h->bufAdjoints, h->bufCountVec, h->count, h->datatype, h->source, h->tag, h->comm, &status,
2185 h->reverse_send);
2186
2187 // Adjoint buffers are always linear in space so we can accesses them in one sweep
2188 adjointInterface->updateAdjoints(h->bufIndices, h->bufAdjoints, h->bufTotalSize);
2189 adjointInterface->deleteAdjointTypeBuffer(h->bufAdjoints);
2190 }
2191
2192 template<typename DATATYPE>
2193 void AMPI_Recv_b(HandleBase* handle, AdjointInterface* adjointInterface) {
2195
2196 MPI_Status status;
2197 h->bufAdjoints = nullptr;
2198 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
2199 adjointInterface->createAdjointTypeBuffer(h->bufAdjoints, h->bufTotalSize );
2200 // Adjoint buffers are always linear in space so we can accesses them in one sweep
2201 adjointInterface->getAdjoints(h->bufIndices, h->bufAdjoints, h->bufTotalSize);
2202
2203 if(h->datatype->getADTool().isOldPrimalsRequired()) {
2204 adjointInterface->setPrimals(h->bufIndices, h->bufOldPrimals, h->bufTotalSize);
2205 }
2206
2207 AMPI_Recv_adj<DATATYPE>(h->bufAdjoints, h->bufCountVec, h->count, h->datatype, h->source, h->tag, h->comm, &status,
2208 h->reverse_send);
2209
2210 adjointInterface->deleteAdjointTypeBuffer(h->bufAdjoints);
2211 }
2212
2213 template<typename DATATYPE>
2214 int AMPI_Recv(typename DATATYPE::Type* buf, int count, DATATYPE* datatype, int source, int tag, AMPI_Comm comm,
2215 AMPI_Status* status, RecvAdjCall reverse_send = RecvAdjCall::Send) {
2216 int rStatus;
2217
2218 if(!datatype->getADTool().isActiveType()) {
2219 // call the regular function if the type is not active
2220 rStatus = MPI_Recv(buf, count, datatype->getMpiType(), source, tag, comm, status);
2221 } else {
2222
2223 // the type is an AD type so handle the buffers
2225 typename DATATYPE::ModifiedType* bufMod = nullptr;
2226 int bufElements = 0;
2227
2228 // compute the total size of the buffer
2229 bufElements = count;
2230
2231 if(datatype->isModifiedBufferRequired() ) {
2232 datatype->createModifiedTypeBuffer(bufMod, bufElements);
2233 } else {
2234 bufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(buf));
2235 }
2236
2237 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
2238 if(datatype->getADTool().isHandleRequired()) {
2240 }
2241 datatype->getADTool().startAssembly(h);
2242
2243 if(nullptr != h) {
2244 // gather the information for the reverse sweep
2245
2246 // create the index buffers
2247 h->bufCount = datatype->computeActiveElements(count);
2248 h->bufTotalSize = datatype->computeActiveElements(bufElements);
2249 datatype->getADTool().createIndexTypeBuffer(h->bufIndices, h->bufTotalSize);
2250
2251
2252 // extract the old primal values from the recv buffer if the AD tool
2253 // needs the primal values reset
2254 if(datatype->getADTool().isOldPrimalsRequired()) {
2255 datatype->getADTool().createPrimalTypeBuffer(h->bufOldPrimals, h->bufTotalSize);
2256 datatype->getValues(buf, 0, h->bufOldPrimals, 0, count);
2257 }
2258
2259
2260
2261 datatype->createIndices(buf, 0, h->bufIndices, 0, count);
2262
2263 // pack all the variables in the handle
2264 h->funcReverse = AMPI_Recv_b<DATATYPE>;
2265 h->funcForward = AMPI_Recv_d<DATATYPE>;
2266 h->funcPrimal = AMPI_Recv_p<DATATYPE>;
2267 h->count = count;
2268 h->datatype = datatype;
2269 h->source = source;
2270 h->tag = tag;
2271 h->comm = comm;
2272 h->reverse_send = reverse_send;
2273 }
2274
2275 if(!datatype->isModifiedBufferRequired()) {
2276 datatype->clearIndices(buf, 0, count);
2277 }
2278
2279 rStatus = MPI_Recv(bufMod, count, datatype->getModifiedMpiType(), source, tag, comm, status);
2280 datatype->getADTool().addToolAction(h);
2281
2282 if(datatype->isModifiedBufferRequired()) {
2283 datatype->copyFromModifiedBuffer(buf, 0, bufMod, 0, count);
2284 }
2285
2286 if(nullptr != h) {
2287 // handle the recv buffers
2288 datatype->registerValue(buf, 0, h->bufIndices, h->bufOldPrimals, 0, count);
2289 }
2290
2291 datatype->getADTool().stopAssembly(h);
2292
2293 if(datatype->isModifiedBufferRequired() ) {
2294 datatype->deleteModifiedTypeBuffer(bufMod);
2295 }
2296
2297 // handle is deleted by the AD tool
2298 }
2299
2300 return rStatus;
2301 }
2302
2303#endif
2304#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
2305
2306 template<typename DATATYPE>
2308 typename DATATYPE::Type* buf;
2309 typename DATATYPE::ModifiedType* bufMod;
2311 DATATYPE* datatype;
2313 int tag;
2317 };
2318
2319
2320 template<typename DATATYPE>
2322 template<typename DATATYPE>
2323 int AMPI_Recv_init_finish(HandleBase* handle);
2324 template<typename DATATYPE>
2326 template<typename DATATYPE>
2327 int AMPI_Recv_init(typename DATATYPE::Type* buf, int count, DATATYPE* datatype, int source, int tag, AMPI_Comm comm,
2328 AMPI_Request* request, IrecvAdjCall reverse_send = IrecvAdjCall::Isend) {
2329 int rStatus;
2330
2331 if(!datatype->getADTool().isActiveType()) {
2332 // call the regular function if the type is not active
2333 rStatus = MPI_Recv_init(buf, count, datatype->getMpiType(), source, tag, comm, &request->request);
2334 } else {
2335
2336 // the type is an AD type so handle the buffers
2338 typename DATATYPE::ModifiedType* bufMod = nullptr;
2339 int bufElements = 0;
2340
2341 // compute the total size of the buffer
2342 bufElements = count;
2343
2344 if(datatype->isModifiedBufferRequired() ) {
2345 datatype->createModifiedTypeBuffer(bufMod, bufElements);
2346 } else {
2347 bufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(buf));
2348 }
2349
2350 rStatus = MPI_Recv_init(bufMod, count, datatype->getModifiedMpiType(), source, tag, comm, &request->request);
2351
2353 asyncHandle->buf = buf;
2354 asyncHandle->bufMod = bufMod;
2355 asyncHandle->count = count;
2356 asyncHandle->datatype = datatype;
2357 asyncHandle->source = source;
2358 asyncHandle->tag = tag;
2359 asyncHandle->comm = comm;
2360 asyncHandle->reverse_send = reverse_send;
2361 asyncHandle->toolHandle = h;
2362 request->handle = asyncHandle;
2363 request->func = (ContinueFunction)AMPI_Recv_init_finish<DATATYPE>;
2364 request->start = (ContinueFunction)AMPI_Recv_init_preStart<DATATYPE>;
2365 request->end = (ContinueFunction)AMPI_Recv_init_postEnd<DATATYPE>;
2366 }
2367
2368 return rStatus;
2369 }
2370
2371 template<typename DATATYPE>
2373 int rStatus = 0;
2374
2376 typename DATATYPE::Type* buf = asyncHandle->buf;
2377 typename DATATYPE::ModifiedType* bufMod = asyncHandle->bufMod;
2378 int count = asyncHandle->count;
2379 DATATYPE* datatype = asyncHandle->datatype;
2380 int source = asyncHandle->source;
2381 int tag = asyncHandle->tag;
2382 AMPI_Comm comm = asyncHandle->comm;
2383 AMPI_Request* request = asyncHandle->request;
2384 IrecvAdjCall reverse_send = asyncHandle->reverse_send;
2386 MEDI_UNUSED(h); // Unused generated to ignore warnings
2387 MEDI_UNUSED(buf); // Unused generated to ignore warnings
2388 MEDI_UNUSED(bufMod); // Unused generated to ignore warnings
2389 MEDI_UNUSED(count); // Unused generated to ignore warnings
2390 MEDI_UNUSED(datatype); // Unused generated to ignore warnings
2391 MEDI_UNUSED(source); // Unused generated to ignore warnings
2392 MEDI_UNUSED(tag); // Unused generated to ignore warnings
2393 MEDI_UNUSED(comm); // Unused generated to ignore warnings
2394 MEDI_UNUSED(request); // Unused generated to ignore warnings
2395 MEDI_UNUSED(reverse_send); // Unused generated to ignore warnings
2396
2397
2398 if(datatype->getADTool().isActiveType()) {
2399
2400 int bufElements = 0;
2401
2402 // recompute the total size of the buffer
2403 bufElements = count;
2404 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
2405 if(datatype->getADTool().isHandleRequired()) {
2407 }
2408 datatype->getADTool().startAssembly(h);
2409
2410 if(nullptr != h) {
2411 // gather the information for the reverse sweep
2412
2413 // create the index buffers
2414 h->bufCount = datatype->computeActiveElements(count);
2415 h->bufTotalSize = datatype->computeActiveElements(bufElements);
2416 datatype->getADTool().createIndexTypeBuffer(h->bufIndices, h->bufTotalSize);
2417
2418
2419 // extract the old primal values from the recv buffer if the AD tool
2420 // needs the primal values reset
2421 if(datatype->getADTool().isOldPrimalsRequired()) {
2422 datatype->getADTool().createPrimalTypeBuffer(h->bufOldPrimals, h->bufTotalSize);
2423 datatype->getValues(buf, 0, h->bufOldPrimals, 0, count);
2424 }
2425
2426
2427
2428 datatype->createIndices(buf, 0, h->bufIndices, 0, count);
2429
2430 // pack all the variables in the handle
2431 h->funcReverse = AMPI_Irecv_b<DATATYPE>;
2432 h->funcForward = AMPI_Irecv_d_finish<DATATYPE>;
2433 h->funcPrimal = AMPI_Irecv_p_finish<DATATYPE>;
2434 h->count = count;
2435 h->datatype = datatype;
2436 h->source = source;
2437 h->tag = tag;
2438 h->comm = comm;
2439 h->reverse_send = reverse_send;
2440 }
2441
2442 if(!datatype->isModifiedBufferRequired()) {
2443 datatype->clearIndices(buf, 0, count);
2444 }
2445
2446 asyncHandle->toolHandle = h;
2447
2448 // create adjoint wait
2449 if(nullptr != h) {
2450 WaitHandle* waitH = new WaitHandle((ReverseFunction)AMPI_Irecv_b_finish<DATATYPE>,
2451 (ForwardFunction)AMPI_Irecv_d<DATATYPE>, h);
2452 datatype->getADTool().addToolAction(waitH);
2453 }
2454 }
2455
2456 return rStatus;
2457 }
2458
2459 template<typename DATATYPE>
2461 int rStatus = 0;
2462
2464 typename DATATYPE::Type* buf = asyncHandle->buf;
2465 typename DATATYPE::ModifiedType* bufMod = asyncHandle->bufMod;
2466 int count = asyncHandle->count;
2467 DATATYPE* datatype = asyncHandle->datatype;
2468 int source = asyncHandle->source;
2469 int tag = asyncHandle->tag;
2470 AMPI_Comm comm = asyncHandle->comm;
2471 AMPI_Request* request = asyncHandle->request;
2472 IrecvAdjCall reverse_send = asyncHandle->reverse_send;
2474 MEDI_UNUSED(h); // Unused generated to ignore warnings
2475 MEDI_UNUSED(buf); // Unused generated to ignore warnings
2476 MEDI_UNUSED(bufMod); // Unused generated to ignore warnings
2477 MEDI_UNUSED(count); // Unused generated to ignore warnings
2478 MEDI_UNUSED(datatype); // Unused generated to ignore warnings
2479 MEDI_UNUSED(source); // Unused generated to ignore warnings
2480 MEDI_UNUSED(tag); // Unused generated to ignore warnings
2481 MEDI_UNUSED(comm); // Unused generated to ignore warnings
2482 MEDI_UNUSED(request); // Unused generated to ignore warnings
2483 MEDI_UNUSED(reverse_send); // Unused generated to ignore warnings
2484
2485
2486 if(datatype->getADTool().isActiveType()) {
2487
2488 datatype->getADTool().addToolAction(h);
2489
2490 if(datatype->isModifiedBufferRequired()) {
2491 datatype->copyFromModifiedBuffer(buf, 0, bufMod, 0, count);
2492 }
2493
2494 if(nullptr != h) {
2495 // handle the recv buffers
2496 datatype->registerValue(buf, 0, h->bufIndices, h->bufOldPrimals, 0, count);
2497 }
2498
2499 datatype->getADTool().stopAssembly(h);
2500 }
2501
2502 return rStatus;
2503 }
2504
2505 template<typename DATATYPE>
2507 int rStatus = 0;
2508
2510 typename DATATYPE::Type* buf = asyncHandle->buf;
2511 typename DATATYPE::ModifiedType* bufMod = asyncHandle->bufMod;
2512 int count = asyncHandle->count;
2513 DATATYPE* datatype = asyncHandle->datatype;
2514 int source = asyncHandle->source;
2515 int tag = asyncHandle->tag;
2516 AMPI_Comm comm = asyncHandle->comm;
2517 AMPI_Request* request = asyncHandle->request;
2518 IrecvAdjCall reverse_send = asyncHandle->reverse_send;
2520 MEDI_UNUSED(h); // Unused generated to ignore warnings
2521 MEDI_UNUSED(buf); // Unused generated to ignore warnings
2522 MEDI_UNUSED(bufMod); // Unused generated to ignore warnings
2523 MEDI_UNUSED(count); // Unused generated to ignore warnings
2524 MEDI_UNUSED(datatype); // Unused generated to ignore warnings
2525 MEDI_UNUSED(source); // Unused generated to ignore warnings
2526 MEDI_UNUSED(tag); // Unused generated to ignore warnings
2527 MEDI_UNUSED(comm); // Unused generated to ignore warnings
2528 MEDI_UNUSED(request); // Unused generated to ignore warnings
2529 MEDI_UNUSED(reverse_send); // Unused generated to ignore warnings
2530
2531 delete asyncHandle;
2532
2533 if(datatype->getADTool().isActiveType()) {
2534
2535
2536 if(datatype->isModifiedBufferRequired() ) {
2537 datatype->deleteModifiedTypeBuffer(bufMod);
2538 }
2539
2540 // handle is deleted by the AD tool
2541 }
2542
2543 return rStatus;
2544 }
2545
2546#endif
2547#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
2548 template<typename DATATYPE>
2551 typename DATATYPE::IndexType* bufIndices;
2552 typename DATATYPE::PrimalType* bufPrimals;
2553 /* required for async */ void* bufAdjoints;
2557 DATATYPE* datatype;
2558 int dest;
2559 int tag;
2561
2563 if(nullptr != bufIndices) {
2564 datatype->getADTool().deleteIndexTypeBuffer(bufIndices);
2565 bufIndices = nullptr;
2566 }
2567 if(nullptr != bufPrimals) {
2568 datatype->getADTool().deletePrimalTypeBuffer(bufPrimals);
2569 bufPrimals = nullptr;
2570 }
2571 }
2572 };
2573
2574
2575 template<typename DATATYPE>
2576 void AMPI_Rsend_p(HandleBase* handle, AdjointInterface* adjointInterface) {
2578
2579 h->bufAdjoints = nullptr;
2580 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
2581 adjointInterface->createPrimalTypeBuffer((void*&)h->bufPrimals, h->bufTotalSize );
2582 // Primal buffers are always linear in space so we can accesses them in one sweep
2583 adjointInterface->getPrimals(h->bufIndices, h->bufPrimals, h->bufTotalSize);
2584
2585
2586 AMPI_Rsend_pri<DATATYPE>(h->bufPrimals, h->bufCountVec, h->count, h->datatype, h->dest, h->tag, h->comm);
2587
2588 adjointInterface->deletePrimalTypeBuffer((void*&)h->bufPrimals);
2589 }
2590
2591 template<typename DATATYPE>
2592 void AMPI_Rsend_d(HandleBase* handle, AdjointInterface* adjointInterface) {
2594
2595 h->bufAdjoints = nullptr;
2596 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
2597 adjointInterface->createAdjointTypeBuffer(h->bufAdjoints, h->bufTotalSize );
2598 // Adjoint buffers are always linear in space so we can accesses them in one sweep
2599 adjointInterface->getAdjoints(h->bufIndices, h->bufAdjoints, h->bufTotalSize);
2600
2601
2602 AMPI_Rsend_fwd<DATATYPE>(h->bufAdjoints, h->bufCountVec, h->count, h->datatype, h->dest, h->tag, h->comm);
2603
2604 adjointInterface->deleteAdjointTypeBuffer(h->bufAdjoints);
2605 }
2606
2607 template<typename DATATYPE>
2608 void AMPI_Rsend_b(HandleBase* handle, AdjointInterface* adjointInterface) {
2610
2611 h->bufAdjoints = nullptr;
2612 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
2613 adjointInterface->createAdjointTypeBuffer(h->bufAdjoints, h->bufTotalSize );
2614
2615 AMPI_Rsend_adj<DATATYPE>(h->bufAdjoints, h->bufCountVec, h->count, h->datatype, h->dest, h->tag, h->comm);
2616
2617 // Adjoint buffers are always linear in space so we can accesses them in one sweep
2618 adjointInterface->updateAdjoints(h->bufIndices, h->bufAdjoints, h->bufTotalSize);
2619 adjointInterface->deleteAdjointTypeBuffer(h->bufAdjoints);
2620 }
2621
2622 template<typename DATATYPE>
2623 int AMPI_Rsend(MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf, int count, DATATYPE* datatype, int dest, int tag,
2624 AMPI_Comm comm) {
2625 int rStatus;
2626
2627 if(!datatype->getADTool().isActiveType()) {
2628 // call the regular function if the type is not active
2629 rStatus = MPI_Rsend(buf, count, datatype->getMpiType(), dest, tag, comm);
2630 } else {
2631
2632 // the type is an AD type so handle the buffers
2634 typename DATATYPE::ModifiedType* bufMod = nullptr;
2635 int bufElements = 0;
2636
2637 // compute the total size of the buffer
2638 bufElements = count;
2639
2640 if(datatype->isModifiedBufferRequired() ) {
2641 datatype->createModifiedTypeBuffer(bufMod, bufElements);
2642 } else {
2643 bufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(buf));
2644 }
2645
2646 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
2647 if(datatype->getADTool().isHandleRequired()) {
2649 }
2650 datatype->getADTool().startAssembly(h);
2651 if(datatype->isModifiedBufferRequired()) {
2652 datatype->copyIntoModifiedBuffer(buf, 0, bufMod, 0, count);
2653 }
2654
2655 if(nullptr != h) {
2656 // gather the information for the reverse sweep
2657
2658 // create the index buffers
2659 h->bufCount = datatype->computeActiveElements(count);
2660 h->bufTotalSize = datatype->computeActiveElements(bufElements);
2661 datatype->getADTool().createIndexTypeBuffer(h->bufIndices, h->bufTotalSize);
2662
2663
2664
2665
2666 datatype->getIndices(buf, 0, h->bufIndices, 0, count);
2667
2668
2669 // pack all the variables in the handle
2670 h->funcReverse = AMPI_Rsend_b<DATATYPE>;
2671 h->funcForward = AMPI_Rsend_d<DATATYPE>;
2672 h->funcPrimal = AMPI_Rsend_p<DATATYPE>;
2673 h->count = count;
2674 h->datatype = datatype;
2675 h->dest = dest;
2676 h->tag = tag;
2677 h->comm = comm;
2678 }
2679
2680
2681 rStatus = MPI_Rsend(bufMod, count, datatype->getModifiedMpiType(), dest, tag, comm);
2682 datatype->getADTool().addToolAction(h);
2683
2684
2685 if(nullptr != h) {
2686 // handle the recv buffers
2687 }
2688
2689 datatype->getADTool().stopAssembly(h);
2690
2691 if(datatype->isModifiedBufferRequired() ) {
2692 datatype->deleteModifiedTypeBuffer(bufMod);
2693 }
2694
2695 // handle is deleted by the AD tool
2696 }
2697
2698 return rStatus;
2699 }
2700
2701#endif
2702#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
2703
2704 template<typename DATATYPE>
2706 MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf;
2707 typename DATATYPE::ModifiedType* bufMod;
2709 DATATYPE* datatype;
2710 int dest;
2711 int tag;
2714 };
2715
2716
2717 template<typename DATATYPE>
2719 template<typename DATATYPE>
2721 template<typename DATATYPE>
2723 template<typename DATATYPE>
2724 int AMPI_Rsend_init(MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf, int count, DATATYPE* datatype, int dest, int tag,
2725 AMPI_Comm comm, AMPI_Request* request) {
2726 int rStatus;
2727
2728 if(!datatype->getADTool().isActiveType()) {
2729 // call the regular function if the type is not active
2730 rStatus = MPI_Rsend_init(buf, count, datatype->getMpiType(), dest, tag, comm, &request->request);
2731 } else {
2732
2733 // the type is an AD type so handle the buffers
2735 typename DATATYPE::ModifiedType* bufMod = nullptr;
2736 int bufElements = 0;
2737
2738 // compute the total size of the buffer
2739 bufElements = count;
2740
2741 if(datatype->isModifiedBufferRequired() ) {
2742 datatype->createModifiedTypeBuffer(bufMod, bufElements);
2743 } else {
2744 bufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(buf));
2745 }
2746
2747 rStatus = MPI_Rsend_init(bufMod, count, datatype->getModifiedMpiType(), dest, tag, comm, &request->request);
2748
2750 asyncHandle->buf = buf;
2751 asyncHandle->bufMod = bufMod;
2752 asyncHandle->count = count;
2753 asyncHandle->datatype = datatype;
2754 asyncHandle->dest = dest;
2755 asyncHandle->tag = tag;
2756 asyncHandle->comm = comm;
2757 asyncHandle->toolHandle = h;
2758 request->handle = asyncHandle;
2759 request->func = (ContinueFunction)AMPI_Rsend_init_finish<DATATYPE>;
2760 request->start = (ContinueFunction)AMPI_Rsend_init_preStart<DATATYPE>;
2761 request->end = (ContinueFunction)AMPI_Rsend_init_postEnd<DATATYPE>;
2762 }
2763
2764 return rStatus;
2765 }
2766
2767 template<typename DATATYPE>
2769 int rStatus = 0;
2770
2772 MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf = asyncHandle->buf;
2773 typename DATATYPE::ModifiedType* bufMod = asyncHandle->bufMod;
2774 int count = asyncHandle->count;
2775 DATATYPE* datatype = asyncHandle->datatype;
2776 int dest = asyncHandle->dest;
2777 int tag = asyncHandle->tag;
2778 AMPI_Comm comm = asyncHandle->comm;
2779 AMPI_Request* request = asyncHandle->request;
2781 MEDI_UNUSED(h); // Unused generated to ignore warnings
2782 MEDI_UNUSED(buf); // Unused generated to ignore warnings
2783 MEDI_UNUSED(bufMod); // Unused generated to ignore warnings
2784 MEDI_UNUSED(count); // Unused generated to ignore warnings
2785 MEDI_UNUSED(datatype); // Unused generated to ignore warnings
2786 MEDI_UNUSED(dest); // Unused generated to ignore warnings
2787 MEDI_UNUSED(tag); // Unused generated to ignore warnings
2788 MEDI_UNUSED(comm); // Unused generated to ignore warnings
2789 MEDI_UNUSED(request); // Unused generated to ignore warnings
2790
2791
2792 if(datatype->getADTool().isActiveType()) {
2793
2794 int bufElements = 0;
2795
2796 // recompute the total size of the buffer
2797 bufElements = count;
2798 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
2799 if(datatype->getADTool().isHandleRequired()) {
2801 }
2802 datatype->getADTool().startAssembly(h);
2803 if(datatype->isModifiedBufferRequired()) {
2804 datatype->copyIntoModifiedBuffer(buf, 0, bufMod, 0, count);
2805 }
2806
2807 if(nullptr != h) {
2808 // gather the information for the reverse sweep
2809
2810 // create the index buffers
2811 h->bufCount = datatype->computeActiveElements(count);
2812 h->bufTotalSize = datatype->computeActiveElements(bufElements);
2813 datatype->getADTool().createIndexTypeBuffer(h->bufIndices, h->bufTotalSize);
2814
2815
2816
2817
2818 datatype->getIndices(buf, 0, h->bufIndices, 0, count);
2819
2820
2821 // pack all the variables in the handle
2822 h->funcReverse = AMPI_Irsend_b<DATATYPE>;
2823 h->funcForward = AMPI_Irsend_d_finish<DATATYPE>;
2824 h->funcPrimal = AMPI_Irsend_p_finish<DATATYPE>;
2825 h->count = count;
2826 h->datatype = datatype;
2827 h->dest = dest;
2828 h->tag = tag;
2829 h->comm = comm;
2830 }
2831
2832
2833 asyncHandle->toolHandle = h;
2834
2835 // create adjoint wait
2836 if(nullptr != h) {
2837 WaitHandle* waitH = new WaitHandle((ReverseFunction)AMPI_Irsend_b_finish<DATATYPE>,
2838 (ForwardFunction)AMPI_Irsend_d<DATATYPE>, h);
2839 datatype->getADTool().addToolAction(waitH);
2840 }
2841 }
2842
2843 return rStatus;
2844 }
2845
2846 template<typename DATATYPE>
2848 int rStatus = 0;
2849
2851 MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf = asyncHandle->buf;
2852 typename DATATYPE::ModifiedType* bufMod = asyncHandle->bufMod;
2853 int count = asyncHandle->count;
2854 DATATYPE* datatype = asyncHandle->datatype;
2855 int dest = asyncHandle->dest;
2856 int tag = asyncHandle->tag;
2857 AMPI_Comm comm = asyncHandle->comm;
2858 AMPI_Request* request = asyncHandle->request;
2860 MEDI_UNUSED(h); // Unused generated to ignore warnings
2861 MEDI_UNUSED(buf); // Unused generated to ignore warnings
2862 MEDI_UNUSED(bufMod); // Unused generated to ignore warnings
2863 MEDI_UNUSED(count); // Unused generated to ignore warnings
2864 MEDI_UNUSED(datatype); // Unused generated to ignore warnings
2865 MEDI_UNUSED(dest); // Unused generated to ignore warnings
2866 MEDI_UNUSED(tag); // Unused generated to ignore warnings
2867 MEDI_UNUSED(comm); // Unused generated to ignore warnings
2868 MEDI_UNUSED(request); // Unused generated to ignore warnings
2869
2870
2871 if(datatype->getADTool().isActiveType()) {
2872
2873 datatype->getADTool().addToolAction(h);
2874
2875
2876 if(nullptr != h) {
2877 // handle the recv buffers
2878 }
2879
2880 datatype->getADTool().stopAssembly(h);
2881 }
2882
2883 return rStatus;
2884 }
2885
2886 template<typename DATATYPE>
2888 int rStatus = 0;
2889
2891 MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf = asyncHandle->buf;
2892 typename DATATYPE::ModifiedType* bufMod = asyncHandle->bufMod;
2893 int count = asyncHandle->count;
2894 DATATYPE* datatype = asyncHandle->datatype;
2895 int dest = asyncHandle->dest;
2896 int tag = asyncHandle->tag;
2897 AMPI_Comm comm = asyncHandle->comm;
2898 AMPI_Request* request = asyncHandle->request;
2900 MEDI_UNUSED(h); // Unused generated to ignore warnings
2901 MEDI_UNUSED(buf); // Unused generated to ignore warnings
2902 MEDI_UNUSED(bufMod); // Unused generated to ignore warnings
2903 MEDI_UNUSED(count); // Unused generated to ignore warnings
2904 MEDI_UNUSED(datatype); // Unused generated to ignore warnings
2905 MEDI_UNUSED(dest); // Unused generated to ignore warnings
2906 MEDI_UNUSED(tag); // Unused generated to ignore warnings
2907 MEDI_UNUSED(comm); // Unused generated to ignore warnings
2908 MEDI_UNUSED(request); // Unused generated to ignore warnings
2909
2910 delete asyncHandle;
2911
2912 if(datatype->getADTool().isActiveType()) {
2913
2914
2915 if(datatype->isModifiedBufferRequired() ) {
2916 datatype->deleteModifiedTypeBuffer(bufMod);
2917 }
2918
2919 // handle is deleted by the AD tool
2920 }
2921
2922 return rStatus;
2923 }
2924
2925#endif
2926#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
2927 template<typename DATATYPE>
2930 typename DATATYPE::IndexType* bufIndices;
2931 typename DATATYPE::PrimalType* bufPrimals;
2932 /* required for async */ void* bufAdjoints;
2936 DATATYPE* datatype;
2937 int dest;
2938 int tag;
2940
2942 if(nullptr != bufIndices) {
2943 datatype->getADTool().deleteIndexTypeBuffer(bufIndices);
2944 bufIndices = nullptr;
2945 }
2946 if(nullptr != bufPrimals) {
2947 datatype->getADTool().deletePrimalTypeBuffer(bufPrimals);
2948 bufPrimals = nullptr;
2949 }
2950 }
2951 };
2952
2953
2954 template<typename DATATYPE>
2955 void AMPI_Send_p(HandleBase* handle, AdjointInterface* adjointInterface) {
2957
2958 h->bufAdjoints = nullptr;
2959 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
2960 adjointInterface->createPrimalTypeBuffer((void*&)h->bufPrimals, h->bufTotalSize );
2961 // Primal buffers are always linear in space so we can accesses them in one sweep
2962 adjointInterface->getPrimals(h->bufIndices, h->bufPrimals, h->bufTotalSize);
2963
2964
2965 AMPI_Send_pri<DATATYPE>(h->bufPrimals, h->bufCountVec, h->count, h->datatype, h->dest, h->tag, h->comm);
2966
2967 adjointInterface->deletePrimalTypeBuffer((void*&)h->bufPrimals);
2968 }
2969
2970 template<typename DATATYPE>
2971 void AMPI_Send_d(HandleBase* handle, AdjointInterface* adjointInterface) {
2973
2974 h->bufAdjoints = nullptr;
2975 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
2976 adjointInterface->createAdjointTypeBuffer(h->bufAdjoints, h->bufTotalSize );
2977 // Adjoint buffers are always linear in space so we can accesses them in one sweep
2978 adjointInterface->getAdjoints(h->bufIndices, h->bufAdjoints, h->bufTotalSize);
2979
2980
2981 AMPI_Send_fwd<DATATYPE>(h->bufAdjoints, h->bufCountVec, h->count, h->datatype, h->dest, h->tag, h->comm);
2982
2983 adjointInterface->deleteAdjointTypeBuffer(h->bufAdjoints);
2984 }
2985
2986 template<typename DATATYPE>
2987 void AMPI_Send_b(HandleBase* handle, AdjointInterface* adjointInterface) {
2989
2990 h->bufAdjoints = nullptr;
2991 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
2992 adjointInterface->createAdjointTypeBuffer(h->bufAdjoints, h->bufTotalSize );
2993
2994 AMPI_Send_adj<DATATYPE>(h->bufAdjoints, h->bufCountVec, h->count, h->datatype, h->dest, h->tag, h->comm);
2995
2996 // Adjoint buffers are always linear in space so we can accesses them in one sweep
2997 adjointInterface->updateAdjoints(h->bufIndices, h->bufAdjoints, h->bufTotalSize);
2998 adjointInterface->deleteAdjointTypeBuffer(h->bufAdjoints);
2999 }
3000
3001 template<typename DATATYPE>
3002 int AMPI_Send(MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf, int count, DATATYPE* datatype, int dest, int tag,
3003 AMPI_Comm comm) {
3004 int rStatus;
3005
3006 if(!datatype->getADTool().isActiveType()) {
3007 // call the regular function if the type is not active
3008 rStatus = MPI_Send(buf, count, datatype->getMpiType(), dest, tag, comm);
3009 } else {
3010
3011 // the type is an AD type so handle the buffers
3013 typename DATATYPE::ModifiedType* bufMod = nullptr;
3014 int bufElements = 0;
3015
3016 // compute the total size of the buffer
3017 bufElements = count;
3018
3019 if(datatype->isModifiedBufferRequired() ) {
3020 datatype->createModifiedTypeBuffer(bufMod, bufElements);
3021 } else {
3022 bufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(buf));
3023 }
3024
3025 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
3026 if(datatype->getADTool().isHandleRequired()) {
3028 }
3029 datatype->getADTool().startAssembly(h);
3030 if(datatype->isModifiedBufferRequired()) {
3031 datatype->copyIntoModifiedBuffer(buf, 0, bufMod, 0, count);
3032 }
3033
3034 if(nullptr != h) {
3035 // gather the information for the reverse sweep
3036
3037 // create the index buffers
3038 h->bufCount = datatype->computeActiveElements(count);
3039 h->bufTotalSize = datatype->computeActiveElements(bufElements);
3040 datatype->getADTool().createIndexTypeBuffer(h->bufIndices, h->bufTotalSize);
3041
3042
3043
3044
3045 datatype->getIndices(buf, 0, h->bufIndices, 0, count);
3046
3047
3048 // pack all the variables in the handle
3049 h->funcReverse = AMPI_Send_b<DATATYPE>;
3050 h->funcForward = AMPI_Send_d<DATATYPE>;
3051 h->funcPrimal = AMPI_Send_p<DATATYPE>;
3052 h->count = count;
3053 h->datatype = datatype;
3054 h->dest = dest;
3055 h->tag = tag;
3056 h->comm = comm;
3057 }
3058
3059
3060 rStatus = MPI_Send(bufMod, count, datatype->getModifiedMpiType(), dest, tag, comm);
3061 datatype->getADTool().addToolAction(h);
3062
3063
3064 if(nullptr != h) {
3065 // handle the recv buffers
3066 }
3067
3068 datatype->getADTool().stopAssembly(h);
3069
3070 if(datatype->isModifiedBufferRequired() ) {
3071 datatype->deleteModifiedTypeBuffer(bufMod);
3072 }
3073
3074 // handle is deleted by the AD tool
3075 }
3076
3077 return rStatus;
3078 }
3079
3080#endif
3081#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
3082
3083 template<typename DATATYPE>
3085 MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf;
3086 typename DATATYPE::ModifiedType* bufMod;
3088 DATATYPE* datatype;
3089 int dest;
3090 int tag;
3093 };
3094
3095
3096 template<typename DATATYPE>
3098 template<typename DATATYPE>
3099 int AMPI_Send_init_finish(HandleBase* handle);
3100 template<typename DATATYPE>
3102 template<typename DATATYPE>
3103 int AMPI_Send_init(MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf, int count, DATATYPE* datatype, int dest, int tag,
3104 AMPI_Comm comm, AMPI_Request* request) {
3105 int rStatus;
3106
3107 if(!datatype->getADTool().isActiveType()) {
3108 // call the regular function if the type is not active
3109 rStatus = MPI_Send_init(buf, count, datatype->getMpiType(), dest, tag, comm, &request->request);
3110 } else {
3111
3112 // the type is an AD type so handle the buffers
3114 typename DATATYPE::ModifiedType* bufMod = nullptr;
3115 int bufElements = 0;
3116
3117 // compute the total size of the buffer
3118 bufElements = count;
3119
3120 if(datatype->isModifiedBufferRequired() ) {
3121 datatype->createModifiedTypeBuffer(bufMod, bufElements);
3122 } else {
3123 bufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(buf));
3124 }
3125
3126 rStatus = MPI_Send_init(bufMod, count, datatype->getModifiedMpiType(), dest, tag, comm, &request->request);
3127
3129 asyncHandle->buf = buf;
3130 asyncHandle->bufMod = bufMod;
3131 asyncHandle->count = count;
3132 asyncHandle->datatype = datatype;
3133 asyncHandle->dest = dest;
3134 asyncHandle->tag = tag;
3135 asyncHandle->comm = comm;
3136 asyncHandle->toolHandle = h;
3137 request->handle = asyncHandle;
3138 request->func = (ContinueFunction)AMPI_Send_init_finish<DATATYPE>;
3139 request->start = (ContinueFunction)AMPI_Send_init_preStart<DATATYPE>;
3140 request->end = (ContinueFunction)AMPI_Send_init_postEnd<DATATYPE>;
3141 }
3142
3143 return rStatus;
3144 }
3145
3146 template<typename DATATYPE>
3148 int rStatus = 0;
3149
3151 MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf = asyncHandle->buf;
3152 typename DATATYPE::ModifiedType* bufMod = asyncHandle->bufMod;
3153 int count = asyncHandle->count;
3154 DATATYPE* datatype = asyncHandle->datatype;
3155 int dest = asyncHandle->dest;
3156 int tag = asyncHandle->tag;
3157 AMPI_Comm comm = asyncHandle->comm;
3158 AMPI_Request* request = asyncHandle->request;
3160 MEDI_UNUSED(h); // Unused generated to ignore warnings
3161 MEDI_UNUSED(buf); // Unused generated to ignore warnings
3162 MEDI_UNUSED(bufMod); // Unused generated to ignore warnings
3163 MEDI_UNUSED(count); // Unused generated to ignore warnings
3164 MEDI_UNUSED(datatype); // Unused generated to ignore warnings
3165 MEDI_UNUSED(dest); // Unused generated to ignore warnings
3166 MEDI_UNUSED(tag); // Unused generated to ignore warnings
3167 MEDI_UNUSED(comm); // Unused generated to ignore warnings
3168 MEDI_UNUSED(request); // Unused generated to ignore warnings
3169
3170
3171 if(datatype->getADTool().isActiveType()) {
3172
3173 int bufElements = 0;
3174
3175 // recompute the total size of the buffer
3176 bufElements = count;
3177 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
3178 if(datatype->getADTool().isHandleRequired()) {
3180 }
3181 datatype->getADTool().startAssembly(h);
3182 if(datatype->isModifiedBufferRequired()) {
3183 datatype->copyIntoModifiedBuffer(buf, 0, bufMod, 0, count);
3184 }
3185
3186 if(nullptr != h) {
3187 // gather the information for the reverse sweep
3188
3189 // create the index buffers
3190 h->bufCount = datatype->computeActiveElements(count);
3191 h->bufTotalSize = datatype->computeActiveElements(bufElements);
3192 datatype->getADTool().createIndexTypeBuffer(h->bufIndices, h->bufTotalSize);
3193
3194
3195
3196
3197 datatype->getIndices(buf, 0, h->bufIndices, 0, count);
3198
3199
3200 // pack all the variables in the handle
3201 h->funcReverse = AMPI_Isend_b<DATATYPE>;
3202 h->funcForward = AMPI_Isend_d_finish<DATATYPE>;
3203 h->funcPrimal = AMPI_Isend_p_finish<DATATYPE>;
3204 h->count = count;
3205 h->datatype = datatype;
3206 h->dest = dest;
3207 h->tag = tag;
3208 h->comm = comm;
3209 }
3210
3211
3212 asyncHandle->toolHandle = h;
3213
3214 // create adjoint wait
3215 if(nullptr != h) {
3216 WaitHandle* waitH = new WaitHandle((ReverseFunction)AMPI_Isend_b_finish<DATATYPE>,
3217 (ForwardFunction)AMPI_Isend_d<DATATYPE>, h);
3218 datatype->getADTool().addToolAction(waitH);
3219 }
3220 }
3221
3222 return rStatus;
3223 }
3224
3225 template<typename DATATYPE>
3227 int rStatus = 0;
3228
3230 MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf = asyncHandle->buf;
3231 typename DATATYPE::ModifiedType* bufMod = asyncHandle->bufMod;
3232 int count = asyncHandle->count;
3233 DATATYPE* datatype = asyncHandle->datatype;
3234 int dest = asyncHandle->dest;
3235 int tag = asyncHandle->tag;
3236 AMPI_Comm comm = asyncHandle->comm;
3237 AMPI_Request* request = asyncHandle->request;
3239 MEDI_UNUSED(h); // Unused generated to ignore warnings
3240 MEDI_UNUSED(buf); // Unused generated to ignore warnings
3241 MEDI_UNUSED(bufMod); // Unused generated to ignore warnings
3242 MEDI_UNUSED(count); // Unused generated to ignore warnings
3243 MEDI_UNUSED(datatype); // Unused generated to ignore warnings
3244 MEDI_UNUSED(dest); // Unused generated to ignore warnings
3245 MEDI_UNUSED(tag); // Unused generated to ignore warnings
3246 MEDI_UNUSED(comm); // Unused generated to ignore warnings
3247 MEDI_UNUSED(request); // Unused generated to ignore warnings
3248
3249
3250 if(datatype->getADTool().isActiveType()) {
3251
3252 datatype->getADTool().addToolAction(h);
3253
3254
3255 if(nullptr != h) {
3256 // handle the recv buffers
3257 }
3258
3259 datatype->getADTool().stopAssembly(h);
3260 }
3261
3262 return rStatus;
3263 }
3264
3265 template<typename DATATYPE>
3267 int rStatus = 0;
3268
3270 MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf = asyncHandle->buf;
3271 typename DATATYPE::ModifiedType* bufMod = asyncHandle->bufMod;
3272 int count = asyncHandle->count;
3273 DATATYPE* datatype = asyncHandle->datatype;
3274 int dest = asyncHandle->dest;
3275 int tag = asyncHandle->tag;
3276 AMPI_Comm comm = asyncHandle->comm;
3277 AMPI_Request* request = asyncHandle->request;
3279 MEDI_UNUSED(h); // Unused generated to ignore warnings
3280 MEDI_UNUSED(buf); // Unused generated to ignore warnings
3281 MEDI_UNUSED(bufMod); // Unused generated to ignore warnings
3282 MEDI_UNUSED(count); // Unused generated to ignore warnings
3283 MEDI_UNUSED(datatype); // Unused generated to ignore warnings
3284 MEDI_UNUSED(dest); // Unused generated to ignore warnings
3285 MEDI_UNUSED(tag); // Unused generated to ignore warnings
3286 MEDI_UNUSED(comm); // Unused generated to ignore warnings
3287 MEDI_UNUSED(request); // Unused generated to ignore warnings
3288
3289 delete asyncHandle;
3290
3291 if(datatype->getADTool().isActiveType()) {
3292
3293
3294 if(datatype->isModifiedBufferRequired() ) {
3295 datatype->deleteModifiedTypeBuffer(bufMod);
3296 }
3297
3298 // handle is deleted by the AD tool
3299 }
3300
3301 return rStatus;
3302 }
3303
3304#endif
3305#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
3306 template<typename SENDTYPE, typename RECVTYPE>
3309 typename SENDTYPE::IndexType* sendbufIndices;
3310 typename SENDTYPE::PrimalType* sendbufPrimals;
3311 /* required for async */ void* sendbufAdjoints;
3315 SENDTYPE* sendtype;
3316 int dest;
3319 typename RECVTYPE::IndexType* recvbufIndices;
3320 typename RECVTYPE::PrimalType* recvbufPrimals;
3321 typename RECVTYPE::PrimalType* recvbufOldPrimals;
3322 /* required for async */ void* recvbufAdjoints;
3326 RECVTYPE* recvtype;
3330
3332 if(nullptr != sendbufIndices) {
3333 sendtype->getADTool().deleteIndexTypeBuffer(sendbufIndices);
3334 sendbufIndices = nullptr;
3335 }
3336 if(nullptr != sendbufPrimals) {
3337 sendtype->getADTool().deletePrimalTypeBuffer(sendbufPrimals);
3338 sendbufPrimals = nullptr;
3339 }
3340 if(nullptr != recvbufIndices) {
3341 recvtype->getADTool().deleteIndexTypeBuffer(recvbufIndices);
3342 recvbufIndices = nullptr;
3343 }
3344 if(nullptr != recvbufPrimals) {
3345 recvtype->getADTool().deletePrimalTypeBuffer(recvbufPrimals);
3346 recvbufPrimals = nullptr;
3347 }
3348 if(nullptr != recvbufOldPrimals) {
3349 recvtype->getADTool().deletePrimalTypeBuffer(recvbufOldPrimals);
3350 recvbufOldPrimals = nullptr;
3351 }
3352 }
3353 };
3354
3355
3356 template<typename SENDTYPE, typename RECVTYPE>
3357 void AMPI_Sendrecv_p(HandleBase* handle, AdjointInterface* adjointInterface) {
3359 (handle);
3360
3361 MPI_Status status;
3362 h->recvbufAdjoints = nullptr;
3363 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
3364 adjointInterface->createPrimalTypeBuffer((void*&)h->recvbufPrimals, h->recvbufTotalSize );
3365 h->sendbufAdjoints = nullptr;
3366 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
3367 adjointInterface->createPrimalTypeBuffer((void*&)h->sendbufPrimals, h->sendbufTotalSize );
3368 // Primal buffers are always linear in space so we can accesses them in one sweep
3369 adjointInterface->getPrimals(h->sendbufIndices, h->sendbufPrimals, h->sendbufTotalSize);
3370
3371
3372 AMPI_Sendrecv_pri<SENDTYPE, RECVTYPE>(h->sendbufPrimals, h->sendbufCountVec, h->sendcount, h->sendtype, h->dest,
3373 h->sendtag, h->recvbufPrimals, h->recvbufCountVec, h->recvcount, h->recvtype, h->source, h->recvtag, h->comm, &status);
3374
3375 adjointInterface->deletePrimalTypeBuffer((void*&)h->sendbufPrimals);
3376 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
3377 adjointInterface->getPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
3378 }
3379 // Primal buffers are always linear in space so we can accesses them in one sweep
3380 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufPrimals, h->recvbufTotalSize);
3381 adjointInterface->deletePrimalTypeBuffer((void*&)h->recvbufPrimals);
3382 }
3383
3384 template<typename SENDTYPE, typename RECVTYPE>
3385 void AMPI_Sendrecv_d(HandleBase* handle, AdjointInterface* adjointInterface) {
3387 (handle);
3388
3389 MPI_Status status;
3390 h->recvbufAdjoints = nullptr;
3391 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
3392 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
3393 h->sendbufAdjoints = nullptr;
3394 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
3395 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
3396 // Adjoint buffers are always linear in space so we can accesses them in one sweep
3397 adjointInterface->getAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
3398
3399
3400 AMPI_Sendrecv_fwd<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype, h->dest,
3401 h->sendtag, h->recvbufAdjoints, h->recvbufCountVec, h->recvcount, h->recvtype, h->source, h->recvtag, h->comm, &status);
3402
3403 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
3404 // Adjoint buffers are always linear in space so we can accesses them in one sweep
3405 adjointInterface->updateAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
3406 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
3407 }
3408
3409 template<typename SENDTYPE, typename RECVTYPE>
3410 void AMPI_Sendrecv_b(HandleBase* handle, AdjointInterface* adjointInterface) {
3412 (handle);
3413
3414 MPI_Status status;
3415 h->recvbufAdjoints = nullptr;
3416 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
3417 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
3418 // Adjoint buffers are always linear in space so we can accesses them in one sweep
3419 adjointInterface->getAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
3420
3421 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
3422 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
3423 }
3424 h->sendbufAdjoints = nullptr;
3425 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
3426 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
3427
3428 AMPI_Sendrecv_adj<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype, h->dest,
3429 h->sendtag, h->recvbufAdjoints, h->recvbufCountVec, h->recvcount, h->recvtype, h->source, h->recvtag, h->comm, &status);
3430
3431 // Adjoint buffers are always linear in space so we can accesses them in one sweep
3432 adjointInterface->updateAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
3433 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
3434 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
3435 }
3436
3437 template<typename SENDTYPE, typename RECVTYPE>
3438 int AMPI_Sendrecv(MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf, int sendcount, SENDTYPE* sendtype, int dest,
3439 int sendtag, typename RECVTYPE::Type* recvbuf, int recvcount, RECVTYPE* recvtype, int source, int recvtag,
3440 AMPI_Comm comm, AMPI_Status* status) {
3441 int rStatus;
3442
3443 if(!recvtype->getADTool().isActiveType()) {
3444 // call the regular function if the type is not active
3445 rStatus = MPI_Sendrecv(sendbuf, sendcount, sendtype->getMpiType(), dest, sendtag, recvbuf, recvcount,
3446 recvtype->getMpiType(), source, recvtag, comm, status);
3447 } else {
3448
3449 // the type is an AD type so handle the buffers
3451 typename SENDTYPE::ModifiedType* sendbufMod = nullptr;
3452 int sendbufElements = 0;
3453
3454 // compute the total size of the buffer
3455 sendbufElements = sendcount;
3456
3457 if(sendtype->isModifiedBufferRequired() ) {
3458 sendtype->createModifiedTypeBuffer(sendbufMod, sendbufElements);
3459 } else {
3460 sendbufMod = reinterpret_cast<typename SENDTYPE::ModifiedType*>(const_cast<typename SENDTYPE::Type*>(sendbuf));
3461 }
3462 typename RECVTYPE::ModifiedType* recvbufMod = nullptr;
3463 int recvbufElements = 0;
3464
3465 // compute the total size of the buffer
3466 recvbufElements = recvcount;
3467
3468 if(recvtype->isModifiedBufferRequired() ) {
3469 recvtype->createModifiedTypeBuffer(recvbufMod, recvbufElements);
3470 } else {
3471 recvbufMod = reinterpret_cast<typename RECVTYPE::ModifiedType*>(const_cast<typename RECVTYPE::Type*>(recvbuf));
3472 }
3473
3474 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
3475 if(recvtype->getADTool().isHandleRequired()) {
3477 }
3478 recvtype->getADTool().startAssembly(h);
3479 if(sendtype->isModifiedBufferRequired()) {
3480 sendtype->copyIntoModifiedBuffer(sendbuf, 0, sendbufMod, 0, sendcount);
3481 }
3482
3483 if(nullptr != h) {
3484 // gather the information for the reverse sweep
3485
3486 // create the index buffers
3487 h->sendbufCount = sendtype->computeActiveElements(sendcount);
3488 h->sendbufTotalSize = sendtype->computeActiveElements(sendbufElements);
3489 recvtype->getADTool().createIndexTypeBuffer(h->sendbufIndices, h->sendbufTotalSize);
3490 h->recvbufCount = recvtype->computeActiveElements(recvcount);
3491 h->recvbufTotalSize = recvtype->computeActiveElements(recvbufElements);
3492 recvtype->getADTool().createIndexTypeBuffer(h->recvbufIndices, h->recvbufTotalSize);
3493
3494
3495 // extract the old primal values from the recv buffer if the AD tool
3496 // needs the primal values reset
3497 if(recvtype->getADTool().isOldPrimalsRequired()) {
3498 recvtype->getADTool().createPrimalTypeBuffer(h->recvbufOldPrimals, h->recvbufTotalSize);
3499 recvtype->getValues(recvbuf, 0, h->recvbufOldPrimals, 0, recvcount);
3500 }
3501
3502
3503 sendtype->getIndices(sendbuf, 0, h->sendbufIndices, 0, sendcount);
3504
3505 recvtype->createIndices(recvbuf, 0, h->recvbufIndices, 0, recvcount);
3506
3507 // pack all the variables in the handle
3508 h->funcReverse = AMPI_Sendrecv_b<SENDTYPE, RECVTYPE>;
3509 h->funcForward = AMPI_Sendrecv_d<SENDTYPE, RECVTYPE>;
3510 h->funcPrimal = AMPI_Sendrecv_p<SENDTYPE, RECVTYPE>;
3511 h->sendcount = sendcount;
3512 h->sendtype = sendtype;
3513 h->dest = dest;
3514 h->sendtag = sendtag;
3515 h->recvcount = recvcount;
3516 h->recvtype = recvtype;
3517 h->source = source;
3518 h->recvtag = recvtag;
3519 h->comm = comm;
3520 }
3521
3522 if(!recvtype->isModifiedBufferRequired()) {
3523 recvtype->clearIndices(recvbuf, 0, recvcount);
3524 }
3525
3526 rStatus = MPI_Sendrecv(sendbufMod, sendcount, sendtype->getModifiedMpiType(), dest, sendtag, recvbufMod, recvcount,
3527 recvtype->getModifiedMpiType(), source, recvtag, comm, status);
3528 recvtype->getADTool().addToolAction(h);
3529
3530 if(recvtype->isModifiedBufferRequired()) {
3531 recvtype->copyFromModifiedBuffer(recvbuf, 0, recvbufMod, 0, recvcount);
3532 }
3533
3534 if(nullptr != h) {
3535 // handle the recv buffers
3536 recvtype->registerValue(recvbuf, 0, h->recvbufIndices, h->recvbufOldPrimals, 0, recvcount);
3537 }
3538
3539 recvtype->getADTool().stopAssembly(h);
3540
3541 if(sendtype->isModifiedBufferRequired() ) {
3542 sendtype->deleteModifiedTypeBuffer(sendbufMod);
3543 }
3544 if(recvtype->isModifiedBufferRequired() ) {
3545 recvtype->deleteModifiedTypeBuffer(recvbufMod);
3546 }
3547
3548 // handle is deleted by the AD tool
3549 }
3550
3551 return rStatus;
3552 }
3553
3554#endif
3555#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
3556 template<typename DATATYPE>
3559 typename DATATYPE::IndexType* bufIndices;
3560 typename DATATYPE::PrimalType* bufPrimals;
3561 /* required for async */ void* bufAdjoints;
3565 DATATYPE* datatype;
3566 int dest;
3567 int tag;
3569
3571 if(nullptr != bufIndices) {
3572 datatype->getADTool().deleteIndexTypeBuffer(bufIndices);
3573 bufIndices = nullptr;
3574 }
3575 if(nullptr != bufPrimals) {
3576 datatype->getADTool().deletePrimalTypeBuffer(bufPrimals);
3577 bufPrimals = nullptr;
3578 }
3579 }
3580 };
3581
3582
3583 template<typename DATATYPE>
3584 void AMPI_Ssend_p(HandleBase* handle, AdjointInterface* adjointInterface) {
3586
3587 h->bufAdjoints = nullptr;
3588 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
3589 adjointInterface->createPrimalTypeBuffer((void*&)h->bufPrimals, h->bufTotalSize );
3590 // Primal buffers are always linear in space so we can accesses them in one sweep
3591 adjointInterface->getPrimals(h->bufIndices, h->bufPrimals, h->bufTotalSize);
3592
3593
3594 AMPI_Ssend_pri<DATATYPE>(h->bufPrimals, h->bufCountVec, h->count, h->datatype, h->dest, h->tag, h->comm);
3595
3596 adjointInterface->deletePrimalTypeBuffer((void*&)h->bufPrimals);
3597 }
3598
3599 template<typename DATATYPE>
3600 void AMPI_Ssend_d(HandleBase* handle, AdjointInterface* adjointInterface) {
3602
3603 h->bufAdjoints = nullptr;
3604 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
3605 adjointInterface->createAdjointTypeBuffer(h->bufAdjoints, h->bufTotalSize );
3606 // Adjoint buffers are always linear in space so we can accesses them in one sweep
3607 adjointInterface->getAdjoints(h->bufIndices, h->bufAdjoints, h->bufTotalSize);
3608
3609
3610 AMPI_Ssend_fwd<DATATYPE>(h->bufAdjoints, h->bufCountVec, h->count, h->datatype, h->dest, h->tag, h->comm);
3611
3612 adjointInterface->deleteAdjointTypeBuffer(h->bufAdjoints);
3613 }
3614
3615 template<typename DATATYPE>
3616 void AMPI_Ssend_b(HandleBase* handle, AdjointInterface* adjointInterface) {
3618
3619 h->bufAdjoints = nullptr;
3620 h->bufCountVec = adjointInterface->getVectorSize() * h->bufCount;
3621 adjointInterface->createAdjointTypeBuffer(h->bufAdjoints, h->bufTotalSize );
3622
3623 AMPI_Ssend_adj<DATATYPE>(h->bufAdjoints, h->bufCountVec, h->count, h->datatype, h->dest, h->tag, h->comm);
3624
3625 // Adjoint buffers are always linear in space so we can accesses them in one sweep
3626 adjointInterface->updateAdjoints(h->bufIndices, h->bufAdjoints, h->bufTotalSize);
3627 adjointInterface->deleteAdjointTypeBuffer(h->bufAdjoints);
3628 }
3629
3630 template<typename DATATYPE>
3631 int AMPI_Ssend(MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf, int count, DATATYPE* datatype, int dest, int tag,
3632 AMPI_Comm comm) {
3633 int rStatus;
3634
3635 if(!datatype->getADTool().isActiveType()) {
3636 // call the regular function if the type is not active
3637 rStatus = MPI_Ssend(buf, count, datatype->getMpiType(), dest, tag, comm);
3638 } else {
3639
3640 // the type is an AD type so handle the buffers
3642 typename DATATYPE::ModifiedType* bufMod = nullptr;
3643 int bufElements = 0;
3644
3645 // compute the total size of the buffer
3646 bufElements = count;
3647
3648 if(datatype->isModifiedBufferRequired() ) {
3649 datatype->createModifiedTypeBuffer(bufMod, bufElements);
3650 } else {
3651 bufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(buf));
3652 }
3653
3654 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
3655 if(datatype->getADTool().isHandleRequired()) {
3657 }
3658 datatype->getADTool().startAssembly(h);
3659 if(datatype->isModifiedBufferRequired()) {
3660 datatype->copyIntoModifiedBuffer(buf, 0, bufMod, 0, count);
3661 }
3662
3663 if(nullptr != h) {
3664 // gather the information for the reverse sweep
3665
3666 // create the index buffers
3667 h->bufCount = datatype->computeActiveElements(count);
3668 h->bufTotalSize = datatype->computeActiveElements(bufElements);
3669 datatype->getADTool().createIndexTypeBuffer(h->bufIndices, h->bufTotalSize);
3670
3671
3672
3673
3674 datatype->getIndices(buf, 0, h->bufIndices, 0, count);
3675
3676
3677 // pack all the variables in the handle
3678 h->funcReverse = AMPI_Ssend_b<DATATYPE>;
3679 h->funcForward = AMPI_Ssend_d<DATATYPE>;
3680 h->funcPrimal = AMPI_Ssend_p<DATATYPE>;
3681 h->count = count;
3682 h->datatype = datatype;
3683 h->dest = dest;
3684 h->tag = tag;
3685 h->comm = comm;
3686 }
3687
3688
3689 rStatus = MPI_Ssend(bufMod, count, datatype->getModifiedMpiType(), dest, tag, comm);
3690 datatype->getADTool().addToolAction(h);
3691
3692
3693 if(nullptr != h) {
3694 // handle the recv buffers
3695 }
3696
3697 datatype->getADTool().stopAssembly(h);
3698
3699 if(datatype->isModifiedBufferRequired() ) {
3700 datatype->deleteModifiedTypeBuffer(bufMod);
3701 }
3702
3703 // handle is deleted by the AD tool
3704 }
3705
3706 return rStatus;
3707 }
3708
3709#endif
3710#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
3711
3712 template<typename DATATYPE>
3714 MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf;
3715 typename DATATYPE::ModifiedType* bufMod;
3717 DATATYPE* datatype;
3718 int dest;
3719 int tag;
3722 };
3723
3724
3725 template<typename DATATYPE>
3727 template<typename DATATYPE>
3729 template<typename DATATYPE>
3731 template<typename DATATYPE>
3732 int AMPI_Ssend_init(MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf, int count, DATATYPE* datatype, int dest, int tag,
3733 AMPI_Comm comm, AMPI_Request* request) {
3734 int rStatus;
3735
3736 if(!datatype->getADTool().isActiveType()) {
3737 // call the regular function if the type is not active
3738 rStatus = MPI_Ssend_init(buf, count, datatype->getMpiType(), dest, tag, comm, &request->request);
3739 } else {
3740
3741 // the type is an AD type so handle the buffers
3743 typename DATATYPE::ModifiedType* bufMod = nullptr;
3744 int bufElements = 0;
3745
3746 // compute the total size of the buffer
3747 bufElements = count;
3748
3749 if(datatype->isModifiedBufferRequired() ) {
3750 datatype->createModifiedTypeBuffer(bufMod, bufElements);
3751 } else {
3752 bufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(buf));
3753 }
3754
3755 rStatus = MPI_Ssend_init(bufMod, count, datatype->getModifiedMpiType(), dest, tag, comm, &request->request);
3756
3758 asyncHandle->buf = buf;
3759 asyncHandle->bufMod = bufMod;
3760 asyncHandle->count = count;
3761 asyncHandle->datatype = datatype;
3762 asyncHandle->dest = dest;
3763 asyncHandle->tag = tag;
3764 asyncHandle->comm = comm;
3765 asyncHandle->toolHandle = h;
3766 request->handle = asyncHandle;
3767 request->func = (ContinueFunction)AMPI_Ssend_init_finish<DATATYPE>;
3768 request->start = (ContinueFunction)AMPI_Ssend_init_preStart<DATATYPE>;
3769 request->end = (ContinueFunction)AMPI_Ssend_init_postEnd<DATATYPE>;
3770 }
3771
3772 return rStatus;
3773 }
3774
3775 template<typename DATATYPE>
3777 int rStatus = 0;
3778
3780 MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf = asyncHandle->buf;
3781 typename DATATYPE::ModifiedType* bufMod = asyncHandle->bufMod;
3782 int count = asyncHandle->count;
3783 DATATYPE* datatype = asyncHandle->datatype;
3784 int dest = asyncHandle->dest;
3785 int tag = asyncHandle->tag;
3786 AMPI_Comm comm = asyncHandle->comm;
3787 AMPI_Request* request = asyncHandle->request;
3789 MEDI_UNUSED(h); // Unused generated to ignore warnings
3790 MEDI_UNUSED(buf); // Unused generated to ignore warnings
3791 MEDI_UNUSED(bufMod); // Unused generated to ignore warnings
3792 MEDI_UNUSED(count); // Unused generated to ignore warnings
3793 MEDI_UNUSED(datatype); // Unused generated to ignore warnings
3794 MEDI_UNUSED(dest); // Unused generated to ignore warnings
3795 MEDI_UNUSED(tag); // Unused generated to ignore warnings
3796 MEDI_UNUSED(comm); // Unused generated to ignore warnings
3797 MEDI_UNUSED(request); // Unused generated to ignore warnings
3798
3799
3800 if(datatype->getADTool().isActiveType()) {
3801
3802 int bufElements = 0;
3803
3804 // recompute the total size of the buffer
3805 bufElements = count;
3806 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
3807 if(datatype->getADTool().isHandleRequired()) {
3809 }
3810 datatype->getADTool().startAssembly(h);
3811 if(datatype->isModifiedBufferRequired()) {
3812 datatype->copyIntoModifiedBuffer(buf, 0, bufMod, 0, count);
3813 }
3814
3815 if(nullptr != h) {
3816 // gather the information for the reverse sweep
3817
3818 // create the index buffers
3819 h->bufCount = datatype->computeActiveElements(count);
3820 h->bufTotalSize = datatype->computeActiveElements(bufElements);
3821 datatype->getADTool().createIndexTypeBuffer(h->bufIndices, h->bufTotalSize);
3822
3823
3824
3825
3826 datatype->getIndices(buf, 0, h->bufIndices, 0, count);
3827
3828
3829 // pack all the variables in the handle
3830 h->funcReverse = AMPI_Issend_b<DATATYPE>;
3831 h->funcForward = AMPI_Issend_d_finish<DATATYPE>;
3832 h->funcPrimal = AMPI_Issend_p_finish<DATATYPE>;
3833 h->count = count;
3834 h->datatype = datatype;
3835 h->dest = dest;
3836 h->tag = tag;
3837 h->comm = comm;
3838 }
3839
3840
3841 asyncHandle->toolHandle = h;
3842
3843 // create adjoint wait
3844 if(nullptr != h) {
3845 WaitHandle* waitH = new WaitHandle((ReverseFunction)AMPI_Issend_b_finish<DATATYPE>,
3846 (ForwardFunction)AMPI_Issend_d<DATATYPE>, h);
3847 datatype->getADTool().addToolAction(waitH);
3848 }
3849 }
3850
3851 return rStatus;
3852 }
3853
3854 template<typename DATATYPE>
3856 int rStatus = 0;
3857
3859 MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf = asyncHandle->buf;
3860 typename DATATYPE::ModifiedType* bufMod = asyncHandle->bufMod;
3861 int count = asyncHandle->count;
3862 DATATYPE* datatype = asyncHandle->datatype;
3863 int dest = asyncHandle->dest;
3864 int tag = asyncHandle->tag;
3865 AMPI_Comm comm = asyncHandle->comm;
3866 AMPI_Request* request = asyncHandle->request;
3868 MEDI_UNUSED(h); // Unused generated to ignore warnings
3869 MEDI_UNUSED(buf); // Unused generated to ignore warnings
3870 MEDI_UNUSED(bufMod); // Unused generated to ignore warnings
3871 MEDI_UNUSED(count); // Unused generated to ignore warnings
3872 MEDI_UNUSED(datatype); // Unused generated to ignore warnings
3873 MEDI_UNUSED(dest); // Unused generated to ignore warnings
3874 MEDI_UNUSED(tag); // Unused generated to ignore warnings
3875 MEDI_UNUSED(comm); // Unused generated to ignore warnings
3876 MEDI_UNUSED(request); // Unused generated to ignore warnings
3877
3878
3879 if(datatype->getADTool().isActiveType()) {
3880
3881 datatype->getADTool().addToolAction(h);
3882
3883
3884 if(nullptr != h) {
3885 // handle the recv buffers
3886 }
3887
3888 datatype->getADTool().stopAssembly(h);
3889 }
3890
3891 return rStatus;
3892 }
3893
3894 template<typename DATATYPE>
3896 int rStatus = 0;
3897
3899 MEDI_OPTIONAL_CONST typename DATATYPE::Type* buf = asyncHandle->buf;
3900 typename DATATYPE::ModifiedType* bufMod = asyncHandle->bufMod;
3901 int count = asyncHandle->count;
3902 DATATYPE* datatype = asyncHandle->datatype;
3903 int dest = asyncHandle->dest;
3904 int tag = asyncHandle->tag;
3905 AMPI_Comm comm = asyncHandle->comm;
3906 AMPI_Request* request = asyncHandle->request;
3908 MEDI_UNUSED(h); // Unused generated to ignore warnings
3909 MEDI_UNUSED(buf); // Unused generated to ignore warnings
3910 MEDI_UNUSED(bufMod); // Unused generated to ignore warnings
3911 MEDI_UNUSED(count); // Unused generated to ignore warnings
3912 MEDI_UNUSED(datatype); // Unused generated to ignore warnings
3913 MEDI_UNUSED(dest); // Unused generated to ignore warnings
3914 MEDI_UNUSED(tag); // Unused generated to ignore warnings
3915 MEDI_UNUSED(comm); // Unused generated to ignore warnings
3916 MEDI_UNUSED(request); // Unused generated to ignore warnings
3917
3918 delete asyncHandle;
3919
3920 if(datatype->getADTool().isActiveType()) {
3921
3922
3923 if(datatype->isModifiedBufferRequired() ) {
3924 datatype->deleteModifiedTypeBuffer(bufMod);
3925 }
3926
3927 // handle is deleted by the AD tool
3928 }
3929
3930 return rStatus;
3931 }
3932
3933#endif
3934#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
3935 template<typename SENDTYPE, typename RECVTYPE>
3938 typename SENDTYPE::IndexType* sendbufIndices;
3939 typename SENDTYPE::PrimalType* sendbufPrimals;
3940 /* required for async */ void* sendbufAdjoints;
3944 SENDTYPE* sendtype;
3946 typename RECVTYPE::IndexType* recvbufIndices;
3947 typename RECVTYPE::PrimalType* recvbufPrimals;
3948 typename RECVTYPE::PrimalType* recvbufOldPrimals;
3949 /* required for async */ void* recvbufAdjoints;
3953 RECVTYPE* recvtype;
3955
3957 if(nullptr != sendbufIndices) {
3958 sendtype->getADTool().deleteIndexTypeBuffer(sendbufIndices);
3959 sendbufIndices = nullptr;
3960 }
3961 if(nullptr != sendbufPrimals) {
3962 sendtype->getADTool().deletePrimalTypeBuffer(sendbufPrimals);
3963 sendbufPrimals = nullptr;
3964 }
3965 if(nullptr != recvbufIndices) {
3966 recvtype->getADTool().deleteIndexTypeBuffer(recvbufIndices);
3967 recvbufIndices = nullptr;
3968 }
3969 if(nullptr != recvbufPrimals) {
3970 recvtype->getADTool().deletePrimalTypeBuffer(recvbufPrimals);
3971 recvbufPrimals = nullptr;
3972 }
3973 if(nullptr != recvbufOldPrimals) {
3974 recvtype->getADTool().deletePrimalTypeBuffer(recvbufOldPrimals);
3975 recvbufOldPrimals = nullptr;
3976 }
3977 }
3978 };
3979
3980
3981 template<typename SENDTYPE, typename RECVTYPE>
3982 void AMPI_Allgather_p(HandleBase* handle, AdjointInterface* adjointInterface) {
3984 (handle);
3985
3986 h->recvbufAdjoints = nullptr;
3987 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
3988 adjointInterface->createPrimalTypeBuffer((void*&)h->recvbufPrimals, h->recvbufTotalSize );
3989 h->sendbufAdjoints = nullptr;
3990 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
3991 adjointInterface->createPrimalTypeBuffer((void*&)h->sendbufPrimals, h->sendbufTotalSize );
3992 // Primal buffers are always linear in space so we can accesses them in one sweep
3993 adjointInterface->getPrimals(h->sendbufIndices, h->sendbufPrimals, h->sendbufTotalSize);
3994
3995
3996 AMPI_Allgather_pri<SENDTYPE, RECVTYPE>(h->sendbufPrimals, h->sendbufCountVec, h->sendcount, h->sendtype,
3998
3999 adjointInterface->deletePrimalTypeBuffer((void*&)h->sendbufPrimals);
4000 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
4001 adjointInterface->getPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
4002 }
4003 // Primal buffers are always linear in space so we can accesses them in one sweep
4004 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufPrimals, h->recvbufTotalSize);
4005 adjointInterface->deletePrimalTypeBuffer((void*&)h->recvbufPrimals);
4006 }
4007
4008 template<typename SENDTYPE, typename RECVTYPE>
4009 void AMPI_Allgather_d(HandleBase* handle, AdjointInterface* adjointInterface) {
4011 (handle);
4012
4013 h->recvbufAdjoints = nullptr;
4014 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
4015 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
4016 h->sendbufAdjoints = nullptr;
4017 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
4018 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
4019 // Adjoint buffers are always linear in space so we can accesses them in one sweep
4020 adjointInterface->getAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
4021
4022
4023 AMPI_Allgather_fwd<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype,
4025
4026 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
4027 // Adjoint buffers are always linear in space so we can accesses them in one sweep
4028 adjointInterface->updateAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
4029 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
4030 }
4031
4032 template<typename SENDTYPE, typename RECVTYPE>
4033 void AMPI_Allgather_b(HandleBase* handle, AdjointInterface* adjointInterface) {
4035 (handle);
4036
4037 h->recvbufAdjoints = nullptr;
4038 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
4039 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
4040 // Adjoint buffers are always linear in space so we can accesses them in one sweep
4041 adjointInterface->getAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
4042
4043 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
4044 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
4045 }
4046 h->sendbufAdjoints = nullptr;
4047 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
4049
4050 AMPI_Allgather_adj<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype,
4052
4053 adjointInterface->combineAdjoints(h->sendbufAdjoints, h->sendbufTotalSize, getCommSize(h->comm));
4054 // Adjoint buffers are always linear in space so we can accesses them in one sweep
4055 adjointInterface->updateAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
4056 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
4057 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
4058 }
4059
4060 template<typename SENDTYPE, typename RECVTYPE>
4061 int AMPI_Allgather(MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf, int sendcount, SENDTYPE* sendtype,
4062 typename RECVTYPE::Type* recvbuf, int recvcount, RECVTYPE* recvtype, AMPI_Comm comm) {
4063 int rStatus;
4064
4065 if(!recvtype->getADTool().isActiveType()) {
4066 // call the regular function if the type is not active
4067 rStatus = MPI_Allgather(sendbuf, sendcount, sendtype->getMpiType(), recvbuf, recvcount, recvtype->getMpiType(), comm);
4068 } else {
4069
4070 // the type is an AD type so handle the buffers
4072 typename SENDTYPE::ModifiedType* sendbufMod = nullptr;
4073 int sendbufElements = 0;
4074
4075 // compute the total size of the buffer
4076 if(AMPI_IN_PLACE != sendbuf) {
4077 sendbufElements = sendcount;
4078 } else {
4079 sendbufElements = recvcount;
4080 }
4081
4082 if(sendtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
4083 sendtype->createModifiedTypeBuffer(sendbufMod, sendbufElements);
4084 } else {
4085 sendbufMod = reinterpret_cast<typename SENDTYPE::ModifiedType*>(const_cast<typename SENDTYPE::Type*>(sendbuf));
4086 }
4087 typename RECVTYPE::ModifiedType* recvbufMod = nullptr;
4088 int recvbufElements = 0;
4089
4090 // compute the total size of the buffer
4091 recvbufElements = recvcount * getCommSize(comm);
4092
4093 if(recvtype->isModifiedBufferRequired() ) {
4094 recvtype->createModifiedTypeBuffer(recvbufMod, recvbufElements);
4095 } else {
4096 recvbufMod = reinterpret_cast<typename RECVTYPE::ModifiedType*>(const_cast<typename RECVTYPE::Type*>(recvbuf));
4097 }
4098
4099 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
4100 if(recvtype->getADTool().isHandleRequired()) {
4102 }
4103 recvtype->getADTool().startAssembly(h);
4104 if(sendtype->isModifiedBufferRequired()) {
4105 if(AMPI_IN_PLACE != sendbuf) {
4106 sendtype->copyIntoModifiedBuffer(sendbuf, 0, sendbufMod, 0, sendcount);
4107 } else {
4108 recvtype->copyIntoModifiedBuffer(recvbuf, recvcount * getCommRank(comm), recvbufMod, recvcount * getCommRank(comm),
4109 recvcount);
4110 }
4111 }
4112
4113 if(nullptr != h) {
4114 // gather the information for the reverse sweep
4115
4116 // create the index buffers
4117 if(AMPI_IN_PLACE != sendbuf) {
4118 h->sendbufCount = sendtype->computeActiveElements(sendcount);
4119 } else {
4120 h->sendbufCount = recvtype->computeActiveElements(recvcount);
4121 }
4122 h->sendbufTotalSize = sendtype->computeActiveElements(sendbufElements);
4123 recvtype->getADTool().createIndexTypeBuffer(h->sendbufIndices, h->sendbufTotalSize);
4124 h->recvbufCount = recvtype->computeActiveElements(recvcount);
4125 h->recvbufTotalSize = recvtype->computeActiveElements(recvbufElements);
4126 recvtype->getADTool().createIndexTypeBuffer(h->recvbufIndices, h->recvbufTotalSize);
4127
4128
4129 // extract the old primal values from the recv buffer if the AD tool
4130 // needs the primal values reset
4131 if(recvtype->getADTool().isOldPrimalsRequired()) {
4132 recvtype->getADTool().createPrimalTypeBuffer(h->recvbufOldPrimals, h->recvbufTotalSize);
4133 recvtype->getValues(recvbuf, 0, h->recvbufOldPrimals, 0, recvcount * getCommSize(comm));
4134 }
4135
4136
4137 if(AMPI_IN_PLACE != sendbuf) {
4138 sendtype->getIndices(sendbuf, 0, h->sendbufIndices, 0, sendcount);
4139 } else {
4140 recvtype->getIndices(recvbuf, recvcount * getCommRank(comm), h->sendbufIndices, 0, recvcount);
4141 }
4142
4143 recvtype->createIndices(recvbuf, 0, h->recvbufIndices, 0, recvcount * getCommSize(comm));
4144
4145 // pack all the variables in the handle
4146 h->funcReverse = AMPI_Allgather_b<SENDTYPE, RECVTYPE>;
4147 h->funcForward = AMPI_Allgather_d<SENDTYPE, RECVTYPE>;
4148 h->funcPrimal = AMPI_Allgather_p<SENDTYPE, RECVTYPE>;
4149 h->sendcount = sendcount;
4150 h->sendtype = sendtype;
4151 h->recvcount = recvcount;
4152 h->recvtype = recvtype;
4153 h->comm = comm;
4154 }
4155
4156 if(!recvtype->isModifiedBufferRequired()) {
4157 recvtype->clearIndices(recvbuf, 0, recvcount * getCommSize(comm));
4158 }
4159
4160 rStatus = MPI_Allgather(sendbufMod, sendcount, sendtype->getModifiedMpiType(), recvbufMod, recvcount,
4161 recvtype->getModifiedMpiType(), comm);
4162 recvtype->getADTool().addToolAction(h);
4163
4164 if(recvtype->isModifiedBufferRequired()) {
4165 recvtype->copyFromModifiedBuffer(recvbuf, 0, recvbufMod, 0, recvcount * getCommSize(comm));
4166 }
4167
4168 if(nullptr != h) {
4169 // handle the recv buffers
4170 recvtype->registerValue(recvbuf, 0, h->recvbufIndices, h->recvbufOldPrimals, 0, recvcount * getCommSize(comm));
4171 }
4172
4173 recvtype->getADTool().stopAssembly(h);
4174
4175 if(sendtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
4176 sendtype->deleteModifiedTypeBuffer(sendbufMod);
4177 }
4178 if(recvtype->isModifiedBufferRequired() ) {
4179 recvtype->deleteModifiedTypeBuffer(recvbufMod);
4180 }
4181
4182 // handle is deleted by the AD tool
4183 }
4184
4185 return rStatus;
4186 }
4187
4188#endif
4189#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
4190 template<typename SENDTYPE, typename RECVTYPE>
4193 typename SENDTYPE::IndexType* sendbufIndices;
4194 typename SENDTYPE::PrimalType* sendbufPrimals;
4195 /* required for async */ void* sendbufAdjoints;
4199 SENDTYPE* sendtype;
4201 typename RECVTYPE::IndexType* recvbufIndices;
4202 typename RECVTYPE::PrimalType* recvbufPrimals;
4203 typename RECVTYPE::PrimalType* recvbufOldPrimals;
4204 /* required for async */ void* recvbufAdjoints;
4206 /* required for async */ int* recvbufCountVec;
4207 /* required for async */ int* recvbufDisplsVec;
4210 RECVTYPE* recvtype;
4212
4214 if(nullptr != sendbufIndices) {
4215 sendtype->getADTool().deleteIndexTypeBuffer(sendbufIndices);
4216 sendbufIndices = nullptr;
4217 }
4218 if(nullptr != sendbufPrimals) {
4219 sendtype->getADTool().deletePrimalTypeBuffer(sendbufPrimals);
4220 sendbufPrimals = nullptr;
4221 }
4222 if(nullptr != recvbufIndices) {
4223 recvtype->getADTool().deleteIndexTypeBuffer(recvbufIndices);
4224 recvbufIndices = nullptr;
4225 }
4226 if(nullptr != recvbufPrimals) {
4227 recvtype->getADTool().deletePrimalTypeBuffer(recvbufPrimals);
4228 recvbufPrimals = nullptr;
4229 }
4230 if(nullptr != recvbufOldPrimals) {
4231 recvtype->getADTool().deletePrimalTypeBuffer(recvbufOldPrimals);
4232 recvbufOldPrimals = nullptr;
4233 }
4234 if(nullptr != recvbufCount) {
4235 delete [] recvbufCount;
4236 recvbufCount = nullptr;
4237 }
4238 }
4239 };
4240
4241
4242 template<typename SENDTYPE, typename RECVTYPE>
4243 void AMPI_Allgatherv_p(HandleBase* handle, AdjointInterface* adjointInterface) {
4245 (handle);
4246
4247 h->recvbufAdjoints = nullptr;
4249 adjointInterface->getVectorSize());
4250 adjointInterface->createPrimalTypeBuffer((void*&)h->recvbufPrimals, h->recvbufTotalSize );
4251 h->sendbufAdjoints = nullptr;
4252 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
4253 adjointInterface->createPrimalTypeBuffer((void*&)h->sendbufPrimals, h->sendbufTotalSize );
4254 // Primal buffers are always linear in space so we can accesses them in one sweep
4255 adjointInterface->getPrimals(h->sendbufIndices, h->sendbufPrimals, h->sendbufTotalSize);
4256
4257
4258 AMPI_Allgatherv_pri<SENDTYPE, RECVTYPE>(h->sendbufPrimals, h->sendbufCountVec, h->sendcount, h->sendtype,
4260
4261 adjointInterface->deletePrimalTypeBuffer((void*&)h->sendbufPrimals);
4262 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
4263 adjointInterface->getPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
4264 }
4265 // Primal buffers are always linear in space so we can accesses them in one sweep
4266 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufPrimals, h->recvbufTotalSize);
4267 adjointInterface->deletePrimalTypeBuffer((void*&)h->recvbufPrimals);
4268 delete [] h->recvbufCountVec;
4269 delete [] h->recvbufDisplsVec;
4270 }
4271
4272 template<typename SENDTYPE, typename RECVTYPE>
4273 void AMPI_Allgatherv_d(HandleBase* handle, AdjointInterface* adjointInterface) {
4275 (handle);
4276
4277 h->recvbufAdjoints = nullptr;
4279 adjointInterface->getVectorSize());
4280 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
4281 h->sendbufAdjoints = nullptr;
4282 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
4283 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
4284 // Adjoint buffers are always linear in space so we can accesses them in one sweep
4285 adjointInterface->getAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
4286
4287
4288 AMPI_Allgatherv_fwd<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype,
4290
4291 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
4292 // Adjoint buffers are always linear in space so we can accesses them in one sweep
4293 adjointInterface->updateAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
4294 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
4295 delete [] h->recvbufCountVec;
4296 delete [] h->recvbufDisplsVec;
4297 }
4298
4299 template<typename SENDTYPE, typename RECVTYPE>
4300 void AMPI_Allgatherv_b(HandleBase* handle, AdjointInterface* adjointInterface) {
4302 (handle);
4303
4304 h->recvbufAdjoints = nullptr;
4306 adjointInterface->getVectorSize());
4307 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
4308 // Adjoint buffers are always linear in space so we can accesses them in one sweep
4309 adjointInterface->getAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
4310
4311 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
4312 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
4313 }
4314 h->sendbufAdjoints = nullptr;
4315 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
4317
4318 AMPI_Allgatherv_adj<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype,
4320
4321 adjointInterface->combineAdjoints(h->sendbufAdjoints, h->sendbufTotalSize, getCommSize(h->comm));
4322 // Adjoint buffers are always linear in space so we can accesses them in one sweep
4323 adjointInterface->updateAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
4324 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
4325 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
4326 delete [] h->recvbufCountVec;
4327 delete [] h->recvbufDisplsVec;
4328 }
4329
4330 template<typename SENDTYPE, typename RECVTYPE>
4331 int AMPI_Allgatherv(MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf, int sendcount, SENDTYPE* sendtype,
4332 typename RECVTYPE::Type* recvbuf, MEDI_OPTIONAL_CONST int* recvcounts, MEDI_OPTIONAL_CONST int* displs,
4333 RECVTYPE* recvtype, AMPI_Comm comm) {
4334 int rStatus;
4335
4336 if(!recvtype->getADTool().isActiveType()) {
4337 // call the regular function if the type is not active
4338 rStatus = MPI_Allgatherv(sendbuf, sendcount, sendtype->getMpiType(), recvbuf, recvcounts, displs,
4339 recvtype->getMpiType(), comm);
4340 } else {
4341
4342 // the type is an AD type so handle the buffers
4344 MEDI_OPTIONAL_CONST int* displsMod = displs;
4345 int displsTotalSize = 0;
4346 if(nullptr != displs) {
4347 displsTotalSize = computeDisplacementsTotalSize(recvcounts, getCommSize(comm));
4348 if(recvtype->isModifiedBufferRequired()) {
4349 displsMod = createLinearDisplacements(recvcounts, getCommSize(comm));
4350 }
4351 }
4352 typename SENDTYPE::ModifiedType* sendbufMod = nullptr;
4353 int sendbufElements = 0;
4354
4355 // compute the total size of the buffer
4356 if(AMPI_IN_PLACE != sendbuf) {
4357 sendbufElements = sendcount;
4358 } else {
4359 sendbufElements = recvcounts[getCommRank(comm)];
4360 }
4361
4362 if(sendtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
4363 sendtype->createModifiedTypeBuffer(sendbufMod, sendbufElements);
4364 } else {
4365 sendbufMod = reinterpret_cast<typename SENDTYPE::ModifiedType*>(const_cast<typename SENDTYPE::Type*>(sendbuf));
4366 }
4367 typename RECVTYPE::ModifiedType* recvbufMod = nullptr;
4368 int recvbufElements = 0;
4369
4370 // compute the total size of the buffer
4371 recvbufElements = displsTotalSize;
4372
4373 if(recvtype->isModifiedBufferRequired() ) {
4374 recvtype->createModifiedTypeBuffer(recvbufMod, recvbufElements);
4375 } else {
4376 recvbufMod = reinterpret_cast<typename RECVTYPE::ModifiedType*>(const_cast<typename RECVTYPE::Type*>(recvbuf));
4377 }
4378
4379 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
4380 if(recvtype->getADTool().isHandleRequired()) {
4382 }
4383 recvtype->getADTool().startAssembly(h);
4384 if(sendtype->isModifiedBufferRequired()) {
4385 if(AMPI_IN_PLACE != sendbuf) {
4386 sendtype->copyIntoModifiedBuffer(sendbuf, 0, sendbufMod, 0, sendcount);
4387 } else {
4388 {
4389 const int rank = getCommRank(comm);
4390 recvtype->copyIntoModifiedBuffer(recvbuf, displs[rank], recvbufMod, displsMod[rank], recvcounts[rank]);
4391 }
4392 }
4393 }
4394
4395 if(nullptr != h) {
4396 // gather the information for the reverse sweep
4397
4398 // create the index buffers
4399 if(AMPI_IN_PLACE != sendbuf) {
4400 h->sendbufCount = sendtype->computeActiveElements(sendcount);
4401 } else {
4402 h->sendbufCount = recvtype->computeActiveElements(displs[getCommRank(comm)] + recvcounts[getCommRank(
4403 comm)]) - recvtype->computeActiveElements(displs[getCommRank(comm)]);
4404 }
4405 h->sendbufTotalSize = sendtype->computeActiveElements(sendbufElements);
4406 recvtype->getADTool().createIndexTypeBuffer(h->sendbufIndices, h->sendbufTotalSize);
4407 createLinearIndexCounts(h->recvbufCount, recvcounts, displs, getCommSize(comm), recvtype);
4408 h->recvbufTotalSize = recvtype->computeActiveElements(recvbufElements);
4409 recvtype->getADTool().createIndexTypeBuffer(h->recvbufIndices, h->recvbufTotalSize);
4410
4411
4412 // extract the old primal values from the recv buffer if the AD tool
4413 // needs the primal values reset
4414 if(recvtype->getADTool().isOldPrimalsRequired()) {
4415 recvtype->getADTool().createPrimalTypeBuffer(h->recvbufOldPrimals, h->recvbufTotalSize);
4416 for(int i = 0; i < getCommSize(comm); ++i) {
4417 recvtype->getValues(recvbuf, displs[i], h->recvbufOldPrimals, displsMod[i], recvcounts[i]);
4418 }
4419 }
4420
4421
4422 if(AMPI_IN_PLACE != sendbuf) {
4423 sendtype->getIndices(sendbuf, 0, h->sendbufIndices, 0, sendcount);
4424 } else {
4425 {
4426 const int rank = getCommRank(comm);
4427 recvtype->getIndices(recvbuf, displs[rank], h->sendbufIndices, 0, recvcounts[rank]);
4428 }
4429 }
4430
4431 for(int i = 0; i < getCommSize(comm); ++i) {
4432 recvtype->createIndices(recvbuf, displs[i], h->recvbufIndices, displsMod[i], recvcounts[i]);
4433 }
4434
4435 // pack all the variables in the handle
4436 h->funcReverse = AMPI_Allgatherv_b<SENDTYPE, RECVTYPE>;
4437 h->funcForward = AMPI_Allgatherv_d<SENDTYPE, RECVTYPE>;
4438 h->funcPrimal = AMPI_Allgatherv_p<SENDTYPE, RECVTYPE>;
4439 h->sendcount = sendcount;
4440 h->sendtype = sendtype;
4441 h->recvcounts = recvcounts;
4442 h->displs = displs;
4443 h->recvtype = recvtype;
4444 h->comm = comm;
4445 }
4446
4447 if(!recvtype->isModifiedBufferRequired()) {
4448 for(int i = 0; i < getCommSize(comm); ++i) {
4449 recvtype->clearIndices(recvbuf, displs[i], recvcounts[i]);
4450 }
4451 }
4452
4453 rStatus = MPI_Allgatherv(sendbufMod, sendcount, sendtype->getModifiedMpiType(), recvbufMod, recvcounts, displsMod,
4454 recvtype->getModifiedMpiType(), comm);
4455 recvtype->getADTool().addToolAction(h);
4456
4457 if(recvtype->isModifiedBufferRequired()) {
4458 for(int i = 0; i < getCommSize(comm); ++i) {
4459 recvtype->copyFromModifiedBuffer(recvbuf, displs[i], recvbufMod, displsMod[i], recvcounts[i]);
4460 }
4461 }
4462
4463 if(nullptr != h) {
4464 // handle the recv buffers
4465 for(int i = 0; i < getCommSize(comm); ++i) {
4466 recvtype->registerValue(recvbuf, displs[i], h->recvbufIndices, h->recvbufOldPrimals, displsMod[i], recvcounts[i]);
4467 }
4468 }
4469
4470 recvtype->getADTool().stopAssembly(h);
4471 if(recvtype->isModifiedBufferRequired()) {
4472 delete [] displsMod;
4473 }
4474
4475 if(sendtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
4476 sendtype->deleteModifiedTypeBuffer(sendbufMod);
4477 }
4478 if(recvtype->isModifiedBufferRequired() ) {
4479 recvtype->deleteModifiedTypeBuffer(recvbufMod);
4480 }
4481
4482 // handle is deleted by the AD tool
4483 }
4484
4485 return rStatus;
4486 }
4487
4488#endif
4489#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
4490 template<typename DATATYPE>
4493 typename DATATYPE::IndexType* sendbufIndices;
4494 typename DATATYPE::PrimalType* sendbufPrimals;
4495 /* required for async */ void* sendbufAdjoints;
4499 typename DATATYPE::IndexType* recvbufIndices;
4500 typename DATATYPE::PrimalType* recvbufPrimals;
4501 typename DATATYPE::PrimalType* recvbufOldPrimals;
4502 /* required for async */ void* recvbufAdjoints;
4506 DATATYPE* datatype;
4509
4511 if(nullptr != sendbufIndices) {
4512 datatype->getADTool().deleteIndexTypeBuffer(sendbufIndices);
4513 sendbufIndices = nullptr;
4514 }
4515 if(nullptr != sendbufPrimals) {
4516 datatype->getADTool().deletePrimalTypeBuffer(sendbufPrimals);
4517 sendbufPrimals = nullptr;
4518 }
4519 if(nullptr != recvbufIndices) {
4520 datatype->getADTool().deleteIndexTypeBuffer(recvbufIndices);
4521 recvbufIndices = nullptr;
4522 }
4523 if(nullptr != recvbufPrimals) {
4524 datatype->getADTool().deletePrimalTypeBuffer(recvbufPrimals);
4525 recvbufPrimals = nullptr;
4526 }
4527 if(nullptr != recvbufOldPrimals) {
4528 datatype->getADTool().deletePrimalTypeBuffer(recvbufOldPrimals);
4529 recvbufOldPrimals = nullptr;
4530 }
4531 }
4532 };
4533
4534
4535 template<typename DATATYPE>
4536 void AMPI_Allreduce_global_p(HandleBase* handle, AdjointInterface* adjointInterface) {
4538
4539 AMPI_Op convOp = h->datatype->getADTool().convertOperator(h->op);
4540 (void)convOp;
4541 h->recvbufAdjoints = nullptr;
4542 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
4543 adjointInterface->createPrimalTypeBuffer((void*&)h->recvbufPrimals, h->recvbufTotalSize );
4544 h->sendbufAdjoints = nullptr;
4545 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
4546 adjointInterface->createPrimalTypeBuffer((void*&)h->sendbufPrimals, h->sendbufTotalSize );
4547 // Primal buffers are always linear in space so we can accesses them in one sweep
4548 adjointInterface->getPrimals(h->sendbufIndices, h->sendbufPrimals, h->sendbufTotalSize);
4549
4550
4551 AMPI_Allreduce_global_pri<DATATYPE>(h->sendbufPrimals, h->sendbufCountVec, h->recvbufPrimals, h->recvbufCountVec,
4552 h->count, h->datatype, h->op, h->comm);
4553
4554 adjointInterface->deletePrimalTypeBuffer((void*&)h->sendbufPrimals);
4555 if(h->datatype->getADTool().isOldPrimalsRequired()) {
4556 adjointInterface->getPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
4557 }
4558 // Primal buffers are always linear in space so we can accesses them in one sweep
4559 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufPrimals, h->recvbufTotalSize);
4560 adjointInterface->deletePrimalTypeBuffer((void*&)h->recvbufPrimals);
4561 }
4562
4563 template<typename DATATYPE>
4564 void AMPI_Allreduce_global_d(HandleBase* handle, AdjointInterface* adjointInterface) {
4566
4567 AMPI_Op convOp = h->datatype->getADTool().convertOperator(h->op);
4568 (void)convOp;
4569 h->recvbufAdjoints = nullptr;
4570 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
4571 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
4572 h->sendbufAdjoints = nullptr;
4573 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
4574 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
4575 // Adjoint buffers are always linear in space so we can accesses them in one sweep
4576 adjointInterface->getAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
4577
4578
4579 AMPI_Allreduce_global_fwd<DATATYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->recvbufAdjoints, h->recvbufCountVec,
4580 h->count, h->datatype, h->op, h->comm);
4581
4582 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
4583 // Adjoint buffers are always linear in space so we can accesses them in one sweep
4584 adjointInterface->updateAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
4585 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
4586 }
4587
4588 template<typename DATATYPE>
4589 void AMPI_Allreduce_global_b(HandleBase* handle, AdjointInterface* adjointInterface) {
4591
4592 AMPI_Op convOp = h->datatype->getADTool().convertOperator(h->op);
4593 (void)convOp;
4594 h->recvbufAdjoints = nullptr;
4595 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
4596 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
4597 // Adjoint buffers are always linear in space so we can accesses them in one sweep
4598 adjointInterface->getAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
4599
4600 convOp.preAdjointOperation(h->recvbufAdjoints, h->recvbufPrimals, h->recvbufCount, adjointInterface->getVectorSize());
4601 if(h->datatype->getADTool().isOldPrimalsRequired()) {
4602 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
4603 }
4604 h->sendbufAdjoints = nullptr;
4605 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
4607
4608 AMPI_Allreduce_global_adj<DATATYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->recvbufAdjoints, h->recvbufCountVec,
4609 h->count, h->datatype, h->op, h->comm);
4610
4611 adjointInterface->combineAdjoints(h->sendbufAdjoints, h->sendbufTotalSize, getCommSize(h->comm));
4612 // the primals of the recive buffer are always given to the function. The operator should ignore them if not needed.
4613 // The wrapper functions make sure that for operators that need the primals an all* action is perfomed (e.g. Allreduce instead of Reduce)
4614 convOp.postAdjointOperation(h->sendbufAdjoints, h->sendbufPrimals, h->recvbufPrimals, h->sendbufTotalSize,
4615 adjointInterface->getVectorSize());
4616 // Adjoint buffers are always linear in space so we can accesses them in one sweep
4617 adjointInterface->updateAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
4618 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
4619 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
4620 }
4621
4622 template<typename DATATYPE>
4623 int AMPI_Allreduce_global(MEDI_OPTIONAL_CONST typename DATATYPE::Type* sendbuf, typename DATATYPE::Type* recvbuf,
4624 int count, DATATYPE* datatype, AMPI_Op op, AMPI_Comm comm) {
4625 int rStatus;
4626 AMPI_Op convOp = datatype->getADTool().convertOperator(op);
4627 (void)convOp;
4628
4629 if(!datatype->getADTool().isActiveType()) {
4630 // call the regular function if the type is not active
4631 rStatus = MPI_Allreduce(sendbuf, recvbuf, count, datatype->getMpiType(), convOp.primalFunction, comm);
4632 } else {
4633
4634 // the type is an AD type so handle the buffers
4636 typename DATATYPE::ModifiedType* sendbufMod = nullptr;
4637 int sendbufElements = 0;
4638
4639 // compute the total size of the buffer
4640 if(AMPI_IN_PLACE != sendbuf) {
4641 sendbufElements = count;
4642 } else {
4643 sendbufElements = count;
4644 }
4645
4646 if(datatype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
4647 datatype->createModifiedTypeBuffer(sendbufMod, sendbufElements);
4648 } else {
4649 sendbufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(sendbuf));
4650 }
4651 typename DATATYPE::ModifiedType* recvbufMod = nullptr;
4652 int recvbufElements = 0;
4653
4654 // compute the total size of the buffer
4655 recvbufElements = count;
4656
4657 if(datatype->isModifiedBufferRequired() ) {
4658 datatype->createModifiedTypeBuffer(recvbufMod, recvbufElements);
4659 } else {
4660 recvbufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(recvbuf));
4661 }
4662
4663 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
4664 if(datatype->getADTool().isHandleRequired()) {
4666 }
4667 datatype->getADTool().startAssembly(h);
4668 if(datatype->isModifiedBufferRequired()) {
4669 if(AMPI_IN_PLACE != sendbuf) {
4670 datatype->copyIntoModifiedBuffer(sendbuf, 0, sendbufMod, 0, count);
4671 } else {
4672 datatype->copyIntoModifiedBuffer(recvbuf, 0, recvbufMod, 0, count);
4673 }
4674 }
4675
4676 if(nullptr != h) {
4677 // gather the information for the reverse sweep
4678
4679 // create the index buffers
4680 if(AMPI_IN_PLACE != sendbuf) {
4681 h->sendbufCount = datatype->computeActiveElements(count);
4682 } else {
4683 h->sendbufCount = datatype->computeActiveElements(count);
4684 }
4685 h->sendbufTotalSize = datatype->computeActiveElements(sendbufElements);
4686 datatype->getADTool().createIndexTypeBuffer(h->sendbufIndices, h->sendbufTotalSize);
4687 h->recvbufCount = datatype->computeActiveElements(count);
4688 h->recvbufTotalSize = datatype->computeActiveElements(recvbufElements);
4689 datatype->getADTool().createIndexTypeBuffer(h->recvbufIndices, h->recvbufTotalSize);
4690
4691 // extract the primal values for the operator if required
4692 if(convOp.requiresPrimal) {
4693 datatype->getADTool().createPrimalTypeBuffer(h->sendbufPrimals, h->sendbufTotalSize);
4694 if(AMPI_IN_PLACE != sendbuf) {
4695 datatype->getValues(sendbuf, 0, h->sendbufPrimals, 0, count);
4696 } else {
4697 datatype->getValues(recvbuf, 0, h->sendbufPrimals, 0, count);
4698 }
4699 }
4700
4701 // extract the old primal values from the recv buffer if the AD tool
4702 // needs the primal values reset
4703 if(datatype->getADTool().isOldPrimalsRequired()) {
4704 datatype->getADTool().createPrimalTypeBuffer(h->recvbufOldPrimals, h->recvbufTotalSize);
4705 datatype->getValues(recvbuf, 0, h->recvbufOldPrimals, 0, count);
4706 }
4707
4708
4709 if(AMPI_IN_PLACE != sendbuf) {
4710 datatype->getIndices(sendbuf, 0, h->sendbufIndices, 0, count);
4711 } else {
4712 datatype->getIndices(recvbuf, 0, h->sendbufIndices, 0, count);
4713 }
4714
4715 datatype->createIndices(recvbuf, 0, h->recvbufIndices, 0, count);
4716
4717 // pack all the variables in the handle
4718 h->funcReverse = AMPI_Allreduce_global_b<DATATYPE>;
4719 h->funcForward = AMPI_Allreduce_global_d<DATATYPE>;
4720 h->funcPrimal = AMPI_Allreduce_global_p<DATATYPE>;
4721 h->count = count;
4722 h->datatype = datatype;
4723 h->op = op;
4724 h->comm = comm;
4725 }
4726
4727 if(!datatype->isModifiedBufferRequired()) {
4728 datatype->clearIndices(recvbuf, 0, count);
4729 }
4730
4731 rStatus = MPI_Allreduce(sendbufMod, recvbufMod, count, datatype->getModifiedMpiType(), convOp.modifiedPrimalFunction,
4732 comm);
4733 datatype->getADTool().addToolAction(h);
4734
4735 if(datatype->isModifiedBufferRequired()) {
4736 datatype->copyFromModifiedBuffer(recvbuf, 0, recvbufMod, 0, count);
4737 }
4738
4739 if(nullptr != h) {
4740 // handle the recv buffers
4741 datatype->registerValue(recvbuf, 0, h->recvbufIndices, h->recvbufOldPrimals, 0, count);
4742 }
4743 // extract the primal values for the operator if required
4744 if(nullptr != h && convOp.requiresPrimal) {
4745 datatype->getADTool().createPrimalTypeBuffer(h->recvbufPrimals, h->recvbufTotalSize);
4746 datatype->getValues(recvbuf, 0, h->recvbufPrimals, 0, count);
4747 }
4748
4749 datatype->getADTool().stopAssembly(h);
4750
4751 if(datatype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
4752 datatype->deleteModifiedTypeBuffer(sendbufMod);
4753 }
4754 if(datatype->isModifiedBufferRequired() ) {
4755 datatype->deleteModifiedTypeBuffer(recvbufMod);
4756 }
4757
4758 // handle is deleted by the AD tool
4759 }
4760
4761 return rStatus;
4762 }
4763
4764#endif
4765#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
4766 template<typename SENDTYPE, typename RECVTYPE>
4769 typename SENDTYPE::IndexType* sendbufIndices;
4770 typename SENDTYPE::PrimalType* sendbufPrimals;
4771 /* required for async */ void* sendbufAdjoints;
4775 SENDTYPE* sendtype;
4777 typename RECVTYPE::IndexType* recvbufIndices;
4778 typename RECVTYPE::PrimalType* recvbufPrimals;
4779 typename RECVTYPE::PrimalType* recvbufOldPrimals;
4780 /* required for async */ void* recvbufAdjoints;
4784 RECVTYPE* recvtype;
4786
4788 if(nullptr != sendbufIndices) {
4789 sendtype->getADTool().deleteIndexTypeBuffer(sendbufIndices);
4790 sendbufIndices = nullptr;
4791 }
4792 if(nullptr != sendbufPrimals) {
4793 sendtype->getADTool().deletePrimalTypeBuffer(sendbufPrimals);
4794 sendbufPrimals = nullptr;
4795 }
4796 if(nullptr != recvbufIndices) {
4797 recvtype->getADTool().deleteIndexTypeBuffer(recvbufIndices);
4798 recvbufIndices = nullptr;
4799 }
4800 if(nullptr != recvbufPrimals) {
4801 recvtype->getADTool().deletePrimalTypeBuffer(recvbufPrimals);
4802 recvbufPrimals = nullptr;
4803 }
4804 if(nullptr != recvbufOldPrimals) {
4805 recvtype->getADTool().deletePrimalTypeBuffer(recvbufOldPrimals);
4806 recvbufOldPrimals = nullptr;
4807 }
4808 }
4809 };
4810
4811
4812 template<typename SENDTYPE, typename RECVTYPE>
4813 void AMPI_Alltoall_p(HandleBase* handle, AdjointInterface* adjointInterface) {
4815 (handle);
4816
4817 h->recvbufAdjoints = nullptr;
4818 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
4819 adjointInterface->createPrimalTypeBuffer((void*&)h->recvbufPrimals, h->recvbufTotalSize );
4820 h->sendbufAdjoints = nullptr;
4821 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
4822 adjointInterface->createPrimalTypeBuffer((void*&)h->sendbufPrimals, h->sendbufTotalSize );
4823 // Primal buffers are always linear in space so we can accesses them in one sweep
4824 adjointInterface->getPrimals(h->sendbufIndices, h->sendbufPrimals, h->sendbufTotalSize);
4825
4826
4827 AMPI_Alltoall_pri<SENDTYPE, RECVTYPE>(h->sendbufPrimals, h->sendbufCountVec, h->sendcount, h->sendtype,
4829
4830 adjointInterface->deletePrimalTypeBuffer((void*&)h->sendbufPrimals);
4831 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
4832 adjointInterface->getPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
4833 }
4834 // Primal buffers are always linear in space so we can accesses them in one sweep
4835 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufPrimals, h->recvbufTotalSize);
4836 adjointInterface->deletePrimalTypeBuffer((void*&)h->recvbufPrimals);
4837 }
4838
4839 template<typename SENDTYPE, typename RECVTYPE>
4840 void AMPI_Alltoall_d(HandleBase* handle, AdjointInterface* adjointInterface) {
4842 (handle);
4843
4844 h->recvbufAdjoints = nullptr;
4845 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
4846 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
4847 h->sendbufAdjoints = nullptr;
4848 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
4849 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
4850 // Adjoint buffers are always linear in space so we can accesses them in one sweep
4851 adjointInterface->getAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
4852
4853
4854 AMPI_Alltoall_fwd<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype,
4856
4857 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
4858 // Adjoint buffers are always linear in space so we can accesses them in one sweep
4859 adjointInterface->updateAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
4860 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
4861 }
4862
4863 template<typename SENDTYPE, typename RECVTYPE>
4864 void AMPI_Alltoall_b(HandleBase* handle, AdjointInterface* adjointInterface) {
4866 (handle);
4867
4868 h->recvbufAdjoints = nullptr;
4869 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
4870 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
4871 // Adjoint buffers are always linear in space so we can accesses them in one sweep
4872 adjointInterface->getAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
4873
4874 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
4875 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
4876 }
4877 h->sendbufAdjoints = nullptr;
4878 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
4879 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
4880
4881 AMPI_Alltoall_adj<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype,
4883
4884 // Adjoint buffers are always linear in space so we can accesses them in one sweep
4885 adjointInterface->updateAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
4886 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
4887 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
4888 }
4889
4890 template<typename SENDTYPE, typename RECVTYPE>
4891 int AMPI_Alltoall(MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf, int sendcount, SENDTYPE* sendtype,
4892 typename RECVTYPE::Type* recvbuf, int recvcount, RECVTYPE* recvtype, AMPI_Comm comm) {
4893 int rStatus;
4894
4895 if(!recvtype->getADTool().isActiveType()) {
4896 // call the regular function if the type is not active
4897 rStatus = MPI_Alltoall(sendbuf, sendcount, sendtype->getMpiType(), recvbuf, recvcount, recvtype->getMpiType(), comm);
4898 } else {
4899
4900 // the type is an AD type so handle the buffers
4902 typename SENDTYPE::ModifiedType* sendbufMod = nullptr;
4903 int sendbufElements = 0;
4904
4905 // compute the total size of the buffer
4906 if(AMPI_IN_PLACE != sendbuf) {
4907 sendbufElements = sendcount * getCommSize(comm);
4908 } else {
4909 sendbufElements = recvcount * getCommSize(comm);
4910 }
4911
4912 if(sendtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
4913 sendtype->createModifiedTypeBuffer(sendbufMod, sendbufElements);
4914 } else {
4915 sendbufMod = reinterpret_cast<typename SENDTYPE::ModifiedType*>(const_cast<typename SENDTYPE::Type*>(sendbuf));
4916 }
4917 typename RECVTYPE::ModifiedType* recvbufMod = nullptr;
4918 int recvbufElements = 0;
4919
4920 // compute the total size of the buffer
4921 recvbufElements = recvcount * getCommSize(comm);
4922
4923 if(recvtype->isModifiedBufferRequired() ) {
4924 recvtype->createModifiedTypeBuffer(recvbufMod, recvbufElements);
4925 } else {
4926 recvbufMod = reinterpret_cast<typename RECVTYPE::ModifiedType*>(const_cast<typename RECVTYPE::Type*>(recvbuf));
4927 }
4928
4929 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
4930 if(recvtype->getADTool().isHandleRequired()) {
4932 }
4933 recvtype->getADTool().startAssembly(h);
4934 if(sendtype->isModifiedBufferRequired()) {
4935 if(AMPI_IN_PLACE != sendbuf) {
4936 sendtype->copyIntoModifiedBuffer(sendbuf, 0, sendbufMod, 0, sendcount * getCommSize(comm));
4937 } else {
4938 recvtype->copyIntoModifiedBuffer(recvbuf, 0, recvbufMod, 0, recvcount * getCommSize(comm));
4939 }
4940 }
4941
4942 if(nullptr != h) {
4943 // gather the information for the reverse sweep
4944
4945 // create the index buffers
4946 if(AMPI_IN_PLACE != sendbuf) {
4947 h->sendbufCount = sendtype->computeActiveElements(sendcount);
4948 } else {
4949 h->sendbufCount = recvtype->computeActiveElements(recvcount);
4950 }
4951 h->sendbufTotalSize = sendtype->computeActiveElements(sendbufElements);
4952 recvtype->getADTool().createIndexTypeBuffer(h->sendbufIndices, h->sendbufTotalSize);
4953 h->recvbufCount = recvtype->computeActiveElements(recvcount);
4954 h->recvbufTotalSize = recvtype->computeActiveElements(recvbufElements);
4955 recvtype->getADTool().createIndexTypeBuffer(h->recvbufIndices, h->recvbufTotalSize);
4956
4957
4958 // extract the old primal values from the recv buffer if the AD tool
4959 // needs the primal values reset
4960 if(recvtype->getADTool().isOldPrimalsRequired()) {
4961 recvtype->getADTool().createPrimalTypeBuffer(h->recvbufOldPrimals, h->recvbufTotalSize);
4962 recvtype->getValues(recvbuf, 0, h->recvbufOldPrimals, 0, recvcount * getCommSize(comm));
4963 }
4964
4965
4966 if(AMPI_IN_PLACE != sendbuf) {
4967 sendtype->getIndices(sendbuf, 0, h->sendbufIndices, 0, sendcount * getCommSize(comm));
4968 } else {
4969 recvtype->getIndices(recvbuf, 0, h->sendbufIndices, 0, recvcount * getCommSize(comm));
4970 }
4971
4972 recvtype->createIndices(recvbuf, 0, h->recvbufIndices, 0, recvcount * getCommSize(comm));
4973
4974 // pack all the variables in the handle
4975 h->funcReverse = AMPI_Alltoall_b<SENDTYPE, RECVTYPE>;
4976 h->funcForward = AMPI_Alltoall_d<SENDTYPE, RECVTYPE>;
4977 h->funcPrimal = AMPI_Alltoall_p<SENDTYPE, RECVTYPE>;
4978 h->sendcount = sendcount;
4979 h->sendtype = sendtype;
4980 h->recvcount = recvcount;
4981 h->recvtype = recvtype;
4982 h->comm = comm;
4983 }
4984
4985 if(!recvtype->isModifiedBufferRequired()) {
4986 recvtype->clearIndices(recvbuf, 0, recvcount * getCommSize(comm));
4987 }
4988
4989 rStatus = MPI_Alltoall(sendbufMod, sendcount, sendtype->getModifiedMpiType(), recvbufMod, recvcount,
4990 recvtype->getModifiedMpiType(), comm);
4991 recvtype->getADTool().addToolAction(h);
4992
4993 if(recvtype->isModifiedBufferRequired()) {
4994 recvtype->copyFromModifiedBuffer(recvbuf, 0, recvbufMod, 0, recvcount * getCommSize(comm));
4995 }
4996
4997 if(nullptr != h) {
4998 // handle the recv buffers
4999 recvtype->registerValue(recvbuf, 0, h->recvbufIndices, h->recvbufOldPrimals, 0, recvcount * getCommSize(comm));
5000 }
5001
5002 recvtype->getADTool().stopAssembly(h);
5003
5004 if(sendtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
5005 sendtype->deleteModifiedTypeBuffer(sendbufMod);
5006 }
5007 if(recvtype->isModifiedBufferRequired() ) {
5008 recvtype->deleteModifiedTypeBuffer(recvbufMod);
5009 }
5010
5011 // handle is deleted by the AD tool
5012 }
5013
5014 return rStatus;
5015 }
5016
5017#endif
5018#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
5019 template<typename SENDTYPE, typename RECVTYPE>
5022 typename SENDTYPE::IndexType* sendbufIndices;
5023 typename SENDTYPE::PrimalType* sendbufPrimals;
5024 /* required for async */ void* sendbufAdjoints;
5026 /* required for async */ int* sendbufCountVec;
5027 /* required for async */ int* sendbufDisplsVec;
5030 SENDTYPE* sendtype;
5032 typename RECVTYPE::IndexType* recvbufIndices;
5033 typename RECVTYPE::PrimalType* recvbufPrimals;
5034 typename RECVTYPE::PrimalType* recvbufOldPrimals;
5035 /* required for async */ void* recvbufAdjoints;
5037 /* required for async */ int* recvbufCountVec;
5038 /* required for async */ int* recvbufDisplsVec;
5041 RECVTYPE* recvtype;
5043
5045 if(nullptr != sendbufIndices) {
5046 sendtype->getADTool().deleteIndexTypeBuffer(sendbufIndices);
5047 sendbufIndices = nullptr;
5048 }
5049 if(nullptr != sendbufPrimals) {
5050 sendtype->getADTool().deletePrimalTypeBuffer(sendbufPrimals);
5051 sendbufPrimals = nullptr;
5052 }
5053 if(nullptr != sendbufCount) {
5054 delete [] sendbufCount;
5055 sendbufCount = nullptr;
5056 }
5057 if(nullptr != recvbufIndices) {
5058 recvtype->getADTool().deleteIndexTypeBuffer(recvbufIndices);
5059 recvbufIndices = nullptr;
5060 }
5061 if(nullptr != recvbufPrimals) {
5062 recvtype->getADTool().deletePrimalTypeBuffer(recvbufPrimals);
5063 recvbufPrimals = nullptr;
5064 }
5065 if(nullptr != recvbufOldPrimals) {
5066 recvtype->getADTool().deletePrimalTypeBuffer(recvbufOldPrimals);
5067 recvbufOldPrimals = nullptr;
5068 }
5069 if(nullptr != recvbufCount) {
5070 delete [] recvbufCount;
5071 recvbufCount = nullptr;
5072 }
5073 }
5074 };
5075
5076
5077 template<typename SENDTYPE, typename RECVTYPE>
5078 void AMPI_Alltoallv_p(HandleBase* handle, AdjointInterface* adjointInterface) {
5080 (handle);
5081
5082 h->recvbufAdjoints = nullptr;
5084 adjointInterface->getVectorSize());
5085 adjointInterface->createPrimalTypeBuffer((void*&)h->recvbufPrimals, h->recvbufTotalSize );
5086 h->sendbufAdjoints = nullptr;
5088 adjointInterface->getVectorSize());
5089 adjointInterface->createPrimalTypeBuffer((void*&)h->sendbufPrimals, h->sendbufTotalSize );
5090 // Primal buffers are always linear in space so we can accesses them in one sweep
5091 adjointInterface->getPrimals(h->sendbufIndices, h->sendbufPrimals, h->sendbufTotalSize);
5092
5093
5094 AMPI_Alltoallv_pri<SENDTYPE, RECVTYPE>(h->sendbufPrimals, h->sendbufCountVec, h->sendbufDisplsVec, h->sendcounts,
5096 h->recvtype, h->comm);
5097
5098 adjointInterface->deletePrimalTypeBuffer((void*&)h->sendbufPrimals);
5099 delete [] h->sendbufCountVec;
5100 delete [] h->sendbufDisplsVec;
5101 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
5102 adjointInterface->getPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
5103 }
5104 // Primal buffers are always linear in space so we can accesses them in one sweep
5105 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufPrimals, h->recvbufTotalSize);
5106 adjointInterface->deletePrimalTypeBuffer((void*&)h->recvbufPrimals);
5107 delete [] h->recvbufCountVec;
5108 delete [] h->recvbufDisplsVec;
5109 }
5110
5111 template<typename SENDTYPE, typename RECVTYPE>
5112 void AMPI_Alltoallv_d(HandleBase* handle, AdjointInterface* adjointInterface) {
5114 (handle);
5115
5116 h->recvbufAdjoints = nullptr;
5118 adjointInterface->getVectorSize());
5119 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
5120 h->sendbufAdjoints = nullptr;
5122 adjointInterface->getVectorSize());
5123 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
5124 // Adjoint buffers are always linear in space so we can accesses them in one sweep
5125 adjointInterface->getAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
5126
5127
5128 AMPI_Alltoallv_fwd<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendbufDisplsVec, h->sendcounts,
5130 h->recvtype, h->comm);
5131
5132 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
5133 delete [] h->sendbufCountVec;
5134 delete [] h->sendbufDisplsVec;
5135 // Adjoint buffers are always linear in space so we can accesses them in one sweep
5136 adjointInterface->updateAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
5137 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
5138 delete [] h->recvbufCountVec;
5139 delete [] h->recvbufDisplsVec;
5140 }
5141
5142 template<typename SENDTYPE, typename RECVTYPE>
5143 void AMPI_Alltoallv_b(HandleBase* handle, AdjointInterface* adjointInterface) {
5145 (handle);
5146
5147 h->recvbufAdjoints = nullptr;
5149 adjointInterface->getVectorSize());
5150 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
5151 // Adjoint buffers are always linear in space so we can accesses them in one sweep
5152 adjointInterface->getAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
5153
5154 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
5155 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
5156 }
5157 h->sendbufAdjoints = nullptr;
5159 adjointInterface->getVectorSize());
5160 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
5161
5162 AMPI_Alltoallv_adj<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendbufDisplsVec, h->sendcounts,
5164 h->recvtype, h->comm);
5165
5166 // Adjoint buffers are always linear in space so we can accesses them in one sweep
5167 adjointInterface->updateAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
5168 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
5169 delete [] h->sendbufCountVec;
5170 delete [] h->sendbufDisplsVec;
5171 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
5172 delete [] h->recvbufCountVec;
5173 delete [] h->recvbufDisplsVec;
5174 }
5175
5176 template<typename SENDTYPE, typename RECVTYPE>
5177 int AMPI_Alltoallv(MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf, MEDI_OPTIONAL_CONST int* sendcounts,
5178 MEDI_OPTIONAL_CONST int* sdispls, SENDTYPE* sendtype, typename RECVTYPE::Type* recvbuf,
5179 MEDI_OPTIONAL_CONST int* recvcounts, MEDI_OPTIONAL_CONST int* rdispls, RECVTYPE* recvtype, AMPI_Comm comm) {
5180 int rStatus;
5181
5182 if(!recvtype->getADTool().isActiveType()) {
5183 // call the regular function if the type is not active
5184 rStatus = MPI_Alltoallv(sendbuf, sendcounts, sdispls, sendtype->getMpiType(), recvbuf, recvcounts, rdispls,
5185 recvtype->getMpiType(), comm);
5186 } else {
5187
5188 // the type is an AD type so handle the buffers
5190 MEDI_OPTIONAL_CONST int* sdisplsMod = sdispls;
5191 int sdisplsTotalSize = 0;
5192 if(nullptr != sdispls) {
5193 sdisplsTotalSize = computeDisplacementsTotalSize(sendcounts, getCommSize(comm));
5194 if(recvtype->isModifiedBufferRequired()) {
5195 sdisplsMod = createLinearDisplacements(sendcounts, getCommSize(comm));
5196 }
5197 }
5198 MEDI_OPTIONAL_CONST int* rdisplsMod = rdispls;
5199 int rdisplsTotalSize = 0;
5200 if(nullptr != rdispls) {
5201 rdisplsTotalSize = computeDisplacementsTotalSize(recvcounts, getCommSize(comm));
5202 if(recvtype->isModifiedBufferRequired()) {
5203 rdisplsMod = createLinearDisplacements(recvcounts, getCommSize(comm));
5204 }
5205 }
5206 typename SENDTYPE::ModifiedType* sendbufMod = nullptr;
5207 int sendbufElements = 0;
5208
5209 // compute the total size of the buffer
5210 if(AMPI_IN_PLACE != sendbuf) {
5211 sendbufElements = sdisplsTotalSize;
5212 } else {
5213 sendbufElements = rdisplsTotalSize;
5214 }
5215
5216 if(sendtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
5217 sendtype->createModifiedTypeBuffer(sendbufMod, sendbufElements);
5218 } else {
5219 sendbufMod = reinterpret_cast<typename SENDTYPE::ModifiedType*>(const_cast<typename SENDTYPE::Type*>(sendbuf));
5220 }
5221 typename RECVTYPE::ModifiedType* recvbufMod = nullptr;
5222 int recvbufElements = 0;
5223
5224 // compute the total size of the buffer
5225 recvbufElements = rdisplsTotalSize;
5226
5227 if(recvtype->isModifiedBufferRequired() ) {
5228 recvtype->createModifiedTypeBuffer(recvbufMod, recvbufElements);
5229 } else {
5230 recvbufMod = reinterpret_cast<typename RECVTYPE::ModifiedType*>(const_cast<typename RECVTYPE::Type*>(recvbuf));
5231 }
5232
5233 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
5234 if(recvtype->getADTool().isHandleRequired()) {
5236 }
5237 recvtype->getADTool().startAssembly(h);
5238 if(sendtype->isModifiedBufferRequired()) {
5239 if(AMPI_IN_PLACE != sendbuf) {
5240 for(int i = 0; i < getCommSize(comm); ++i) {
5241 sendtype->copyIntoModifiedBuffer(sendbuf, sdispls[i], sendbufMod, sdisplsMod[i], sendcounts[i]);
5242 }
5243 } else {
5244 for(int i = 0; i < getCommSize(comm); ++i) {
5245 recvtype->copyIntoModifiedBuffer(recvbuf, rdispls[i], recvbufMod, rdisplsMod[i], recvcounts[i]);
5246 }
5247 }
5248 }
5249
5250 if(nullptr != h) {
5251 // gather the information for the reverse sweep
5252
5253 // create the index buffers
5254 if(AMPI_IN_PLACE != sendbuf) {
5255 createLinearIndexCounts(h->sendbufCount, sendcounts, sdispls, getCommSize(comm), sendtype);
5256 } else {
5257 createLinearIndexCounts(h->sendbufCount, recvcounts, rdispls, getCommSize(comm), recvtype);
5258 }
5259 h->sendbufTotalSize = sendtype->computeActiveElements(sendbufElements);
5260 recvtype->getADTool().createIndexTypeBuffer(h->sendbufIndices, h->sendbufTotalSize);
5261 createLinearIndexCounts(h->recvbufCount, recvcounts, rdispls, getCommSize(comm), recvtype);
5262 h->recvbufTotalSize = recvtype->computeActiveElements(recvbufElements);
5263 recvtype->getADTool().createIndexTypeBuffer(h->recvbufIndices, h->recvbufTotalSize);
5264
5265
5266 // extract the old primal values from the recv buffer if the AD tool
5267 // needs the primal values reset
5268 if(recvtype->getADTool().isOldPrimalsRequired()) {
5269 recvtype->getADTool().createPrimalTypeBuffer(h->recvbufOldPrimals, h->recvbufTotalSize);
5270 for(int i = 0; i < getCommSize(comm); ++i) {
5271 recvtype->getValues(recvbuf, rdispls[i], h->recvbufOldPrimals, rdisplsMod[i], recvcounts[i]);
5272 }
5273 }
5274
5275
5276 if(AMPI_IN_PLACE != sendbuf) {
5277 for(int i = 0; i < getCommSize(comm); ++i) {
5278 sendtype->getIndices(sendbuf, sdispls[i], h->sendbufIndices, sdisplsMod[i], sendcounts[i]);
5279 }
5280 } else {
5281 for(int i = 0; i < getCommSize(comm); ++i) {
5282 recvtype->getIndices(recvbuf, rdispls[i], h->sendbufIndices, rdisplsMod[i], recvcounts[i]);
5283 }
5284 }
5285
5286 for(int i = 0; i < getCommSize(comm); ++i) {
5287 recvtype->createIndices(recvbuf, rdispls[i], h->recvbufIndices, rdisplsMod[i], recvcounts[i]);
5288 }
5289
5290 // pack all the variables in the handle
5291 h->funcReverse = AMPI_Alltoallv_b<SENDTYPE, RECVTYPE>;
5292 h->funcForward = AMPI_Alltoallv_d<SENDTYPE, RECVTYPE>;
5293 h->funcPrimal = AMPI_Alltoallv_p<SENDTYPE, RECVTYPE>;
5294 h->sendcounts = sendcounts;
5295 h->sdispls = sdispls;
5296 h->sendtype = sendtype;
5297 h->recvcounts = recvcounts;
5298 h->rdispls = rdispls;
5299 h->recvtype = recvtype;
5300 h->comm = comm;
5301 }
5302
5303 if(!recvtype->isModifiedBufferRequired()) {
5304 for(int i = 0; i < getCommSize(comm); ++i) {
5305 recvtype->clearIndices(recvbuf, rdispls[i], recvcounts[i]);
5306 }
5307 }
5308
5309 rStatus = MPI_Alltoallv(sendbufMod, sendcounts, sdisplsMod, sendtype->getModifiedMpiType(), recvbufMod, recvcounts,
5310 rdisplsMod, recvtype->getModifiedMpiType(), comm);
5311 recvtype->getADTool().addToolAction(h);
5312
5313 if(recvtype->isModifiedBufferRequired()) {
5314 for(int i = 0; i < getCommSize(comm); ++i) {
5315 recvtype->copyFromModifiedBuffer(recvbuf, rdispls[i], recvbufMod, rdisplsMod[i], recvcounts[i]);
5316 }
5317 }
5318
5319 if(nullptr != h) {
5320 // handle the recv buffers
5321 for(int i = 0; i < getCommSize(comm); ++i) {
5322 recvtype->registerValue(recvbuf, rdispls[i], h->recvbufIndices, h->recvbufOldPrimals, rdisplsMod[i], recvcounts[i]);
5323 }
5324 }
5325
5326 recvtype->getADTool().stopAssembly(h);
5327 if(recvtype->isModifiedBufferRequired()) {
5328 delete [] sdisplsMod;
5329 }
5330 if(recvtype->isModifiedBufferRequired()) {
5331 delete [] rdisplsMod;
5332 }
5333
5334 if(sendtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
5335 sendtype->deleteModifiedTypeBuffer(sendbufMod);
5336 }
5337 if(recvtype->isModifiedBufferRequired() ) {
5338 recvtype->deleteModifiedTypeBuffer(recvbufMod);
5339 }
5340
5341 // handle is deleted by the AD tool
5342 }
5343
5344 return rStatus;
5345 }
5346
5347#endif
5348#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
5349 template<typename DATATYPE>
5352 typename DATATYPE::IndexType* bufferSendIndices;
5353 typename DATATYPE::PrimalType* bufferSendPrimals;
5354 /* required for async */ void* bufferSendAdjoints;
5358 typename DATATYPE::IndexType* bufferRecvIndices;
5359 typename DATATYPE::PrimalType* bufferRecvPrimals;
5360 typename DATATYPE::PrimalType* bufferRecvOldPrimals;
5361 /* required for async */ void* bufferRecvAdjoints;
5365 DATATYPE* datatype;
5366 int root;
5368
5370 if(nullptr != bufferSendIndices) {
5371 datatype->getADTool().deleteIndexTypeBuffer(bufferSendIndices);
5372 bufferSendIndices = nullptr;
5373 }
5374 if(nullptr != bufferSendPrimals) {
5375 datatype->getADTool().deletePrimalTypeBuffer(bufferSendPrimals);
5376 bufferSendPrimals = nullptr;
5377 }
5378 if(nullptr != bufferRecvIndices) {
5379 datatype->getADTool().deleteIndexTypeBuffer(bufferRecvIndices);
5380 bufferRecvIndices = nullptr;
5381 }
5382 if(nullptr != bufferRecvPrimals) {
5383 datatype->getADTool().deletePrimalTypeBuffer(bufferRecvPrimals);
5384 bufferRecvPrimals = nullptr;
5385 }
5386 if(nullptr != bufferRecvOldPrimals) {
5387 datatype->getADTool().deletePrimalTypeBuffer(bufferRecvOldPrimals);
5388 bufferRecvOldPrimals = nullptr;
5389 }
5390 }
5391 };
5392
5393
5394 template<typename DATATYPE>
5395 void AMPI_Bcast_wrap_p(HandleBase* handle, AdjointInterface* adjointInterface) {
5397
5398 h->bufferRecvAdjoints = nullptr;
5399 h->bufferRecvCountVec = adjointInterface->getVectorSize() * h->bufferRecvCount;
5400 adjointInterface->createPrimalTypeBuffer((void*&)h->bufferRecvPrimals, h->bufferRecvTotalSize );
5401 h->bufferSendAdjoints = nullptr;
5402 if(h->root == getCommRank(h->comm)) {
5403 h->bufferSendCountVec = adjointInterface->getVectorSize() * h->bufferSendCount;
5404 adjointInterface->createPrimalTypeBuffer((void*&)h->bufferSendPrimals, h->bufferSendTotalSize );
5405 // Primal buffers are always linear in space so we can accesses them in one sweep
5407
5408 }
5409
5410 AMPI_Bcast_wrap_pri<DATATYPE>(h->bufferSendPrimals, h->bufferSendCountVec, h->bufferRecvPrimals, h->bufferRecvCountVec,
5411 h->count, h->datatype, h->root, h->comm);
5412
5413 if(h->root == getCommRank(h->comm)) {
5414 adjointInterface->deletePrimalTypeBuffer((void*&)h->bufferSendPrimals);
5415 }
5416 if(h->datatype->getADTool().isOldPrimalsRequired()) {
5418 }
5419 // Primal buffers are always linear in space so we can accesses them in one sweep
5421 adjointInterface->deletePrimalTypeBuffer((void*&)h->bufferRecvPrimals);
5422 }
5423
5424 template<typename DATATYPE>
5425 void AMPI_Bcast_wrap_d(HandleBase* handle, AdjointInterface* adjointInterface) {
5427
5428 h->bufferRecvAdjoints = nullptr;
5429 h->bufferRecvCountVec = adjointInterface->getVectorSize() * h->bufferRecvCount;
5431 h->bufferSendAdjoints = nullptr;
5432 if(h->root == getCommRank(h->comm)) {
5433 h->bufferSendCountVec = adjointInterface->getVectorSize() * h->bufferSendCount;
5435 // Adjoint buffers are always linear in space so we can accesses them in one sweep
5437
5438 }
5439
5440 AMPI_Bcast_wrap_fwd<DATATYPE>(h->bufferSendAdjoints, h->bufferSendCountVec, h->bufferRecvAdjoints,
5441 h->bufferRecvCountVec, h->count, h->datatype, h->root, h->comm);
5442
5443 if(h->root == getCommRank(h->comm)) {
5444 adjointInterface->deleteAdjointTypeBuffer(h->bufferSendAdjoints);
5445 }
5446 // Adjoint buffers are always linear in space so we can accesses them in one sweep
5448 adjointInterface->deleteAdjointTypeBuffer(h->bufferRecvAdjoints);
5449 }
5450
5451 template<typename DATATYPE>
5452 void AMPI_Bcast_wrap_b(HandleBase* handle, AdjointInterface* adjointInterface) {
5454
5455 h->bufferRecvAdjoints = nullptr;
5456 h->bufferRecvCountVec = adjointInterface->getVectorSize() * h->bufferRecvCount;
5458 // Adjoint buffers are always linear in space so we can accesses them in one sweep
5460
5461 if(h->datatype->getADTool().isOldPrimalsRequired()) {
5463 }
5464 h->bufferSendAdjoints = nullptr;
5465 if(h->root == getCommRank(h->comm)) {
5466 h->bufferSendCountVec = adjointInterface->getVectorSize() * h->bufferSendCount;
5468 }
5469
5470 AMPI_Bcast_wrap_adj<DATATYPE>(h->bufferSendAdjoints, h->bufferSendCountVec, h->bufferRecvAdjoints,
5471 h->bufferRecvCountVec, h->count, h->datatype, h->root, h->comm);
5472
5473 if(h->root == getCommRank(h->comm)) {
5475 // Adjoint buffers are always linear in space so we can accesses them in one sweep
5477 adjointInterface->deleteAdjointTypeBuffer(h->bufferSendAdjoints);
5478 }
5479 adjointInterface->deleteAdjointTypeBuffer(h->bufferRecvAdjoints);
5480 }
5481
5482 template<typename DATATYPE>
5483 int AMPI_Bcast_wrap(typename DATATYPE::Type* bufferSend, typename DATATYPE::Type* bufferRecv, int count,
5484 DATATYPE* datatype, int root, AMPI_Comm comm) {
5485 int rStatus;
5486
5487 if(!datatype->getADTool().isActiveType()) {
5488 // call the regular function if the type is not active
5489 rStatus = MPI_Bcast_wrap(bufferSend, bufferRecv, count, datatype->getMpiType(), root, comm);
5490 } else {
5491
5492 // the type is an AD type so handle the buffers
5494 typename DATATYPE::ModifiedType* bufferSendMod = nullptr;
5495 int bufferSendElements = 0;
5496
5497 if(root == getCommRank(comm)) {
5498 // compute the total size of the buffer
5499 if(AMPI_IN_PLACE != bufferSend) {
5500 bufferSendElements = count;
5501 } else {
5502 bufferSendElements = count;
5503 }
5504
5505 if(datatype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == bufferSend)) {
5506 datatype->createModifiedTypeBuffer(bufferSendMod, bufferSendElements);
5507 } else {
5508 bufferSendMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(bufferSend));
5509 }
5510 }
5511 typename DATATYPE::ModifiedType* bufferRecvMod = nullptr;
5512 int bufferRecvElements = 0;
5513
5514 // compute the total size of the buffer
5515 bufferRecvElements = count;
5516
5517 if(datatype->isModifiedBufferRequired() ) {
5518 datatype->createModifiedTypeBuffer(bufferRecvMod, bufferRecvElements);
5519 } else {
5520 bufferRecvMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(bufferRecv));
5521 }
5522
5523 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
5524 if(datatype->getADTool().isHandleRequired()) {
5526 }
5527 datatype->getADTool().startAssembly(h);
5528 if(root == getCommRank(comm)) {
5529 if(datatype->isModifiedBufferRequired()) {
5530 if(AMPI_IN_PLACE != bufferSend) {
5531 datatype->copyIntoModifiedBuffer(bufferSend, 0, bufferSendMod, 0, count);
5532 } else {
5533 datatype->copyIntoModifiedBuffer(bufferRecv, 0, bufferRecvMod, 0, count);
5534 }
5535 }
5536 }
5537
5538 if(nullptr != h) {
5539 // gather the information for the reverse sweep
5540
5541 // create the index buffers
5542 if(root == getCommRank(comm)) {
5543 if(AMPI_IN_PLACE != bufferSend) {
5544 h->bufferSendCount = datatype->computeActiveElements(count);
5545 } else {
5546 h->bufferSendCount = datatype->computeActiveElements(count);
5547 }
5548 h->bufferSendTotalSize = datatype->computeActiveElements(bufferSendElements);
5549 datatype->getADTool().createIndexTypeBuffer(h->bufferSendIndices, h->bufferSendTotalSize);
5550 }
5551 h->bufferRecvCount = datatype->computeActiveElements(count);
5552 h->bufferRecvTotalSize = datatype->computeActiveElements(bufferRecvElements);
5553 datatype->getADTool().createIndexTypeBuffer(h->bufferRecvIndices, h->bufferRecvTotalSize);
5554
5555
5556 // extract the old primal values from the recv buffer if the AD tool
5557 // needs the primal values reset
5558 if(datatype->getADTool().isOldPrimalsRequired()) {
5559 datatype->getADTool().createPrimalTypeBuffer(h->bufferRecvOldPrimals, h->bufferRecvTotalSize);
5560 datatype->getValues(bufferRecv, 0, h->bufferRecvOldPrimals, 0, count);
5561 }
5562
5563
5564 if(root == getCommRank(comm)) {
5565 if(AMPI_IN_PLACE != bufferSend) {
5566 datatype->getIndices(bufferSend, 0, h->bufferSendIndices, 0, count);
5567 } else {
5568 datatype->getIndices(bufferRecv, 0, h->bufferSendIndices, 0, count);
5569 }
5570 }
5571
5572 datatype->createIndices(bufferRecv, 0, h->bufferRecvIndices, 0, count);
5573
5574 // pack all the variables in the handle
5575 h->funcReverse = AMPI_Bcast_wrap_b<DATATYPE>;
5576 h->funcForward = AMPI_Bcast_wrap_d<DATATYPE>;
5577 h->funcPrimal = AMPI_Bcast_wrap_p<DATATYPE>;
5578 h->count = count;
5579 h->datatype = datatype;
5580 h->root = root;
5581 h->comm = comm;
5582 }
5583
5584 if(!datatype->isModifiedBufferRequired()) {
5585 datatype->clearIndices(bufferRecv, 0, count);
5586 }
5587
5588 rStatus = MPI_Bcast_wrap(bufferSendMod, bufferRecvMod, count, datatype->getModifiedMpiType(), root, comm);
5589 datatype->getADTool().addToolAction(h);
5590
5591 if(datatype->isModifiedBufferRequired()) {
5592 datatype->copyFromModifiedBuffer(bufferRecv, 0, bufferRecvMod, 0, count);
5593 }
5594
5595 if(nullptr != h) {
5596 // handle the recv buffers
5597 datatype->registerValue(bufferRecv, 0, h->bufferRecvIndices, h->bufferRecvOldPrimals, 0, count);
5598 }
5599
5600 datatype->getADTool().stopAssembly(h);
5601
5602 if(root == getCommRank(comm)) {
5603 if(datatype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == bufferSend)) {
5604 datatype->deleteModifiedTypeBuffer(bufferSendMod);
5605 }
5606 }
5607 if(datatype->isModifiedBufferRequired() ) {
5608 datatype->deleteModifiedTypeBuffer(bufferRecvMod);
5609 }
5610
5611 // handle is deleted by the AD tool
5612 }
5613
5614 return rStatus;
5615 }
5616
5617#endif
5618#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
5619 template<typename SENDTYPE, typename RECVTYPE>
5622 typename SENDTYPE::IndexType* sendbufIndices;
5623 typename SENDTYPE::PrimalType* sendbufPrimals;
5624 /* required for async */ void* sendbufAdjoints;
5628 SENDTYPE* sendtype;
5630 typename RECVTYPE::IndexType* recvbufIndices;
5631 typename RECVTYPE::PrimalType* recvbufPrimals;
5632 typename RECVTYPE::PrimalType* recvbufOldPrimals;
5633 /* required for async */ void* recvbufAdjoints;
5637 RECVTYPE* recvtype;
5638 int root;
5640
5642 if(nullptr != sendbufIndices) {
5643 sendtype->getADTool().deleteIndexTypeBuffer(sendbufIndices);
5644 sendbufIndices = nullptr;
5645 }
5646 if(nullptr != sendbufPrimals) {
5647 sendtype->getADTool().deletePrimalTypeBuffer(sendbufPrimals);
5648 sendbufPrimals = nullptr;
5649 }
5650 if(nullptr != recvbufIndices) {
5651 recvtype->getADTool().deleteIndexTypeBuffer(recvbufIndices);
5652 recvbufIndices = nullptr;
5653 }
5654 if(nullptr != recvbufPrimals) {
5655 recvtype->getADTool().deletePrimalTypeBuffer(recvbufPrimals);
5656 recvbufPrimals = nullptr;
5657 }
5658 if(nullptr != recvbufOldPrimals) {
5659 recvtype->getADTool().deletePrimalTypeBuffer(recvbufOldPrimals);
5660 recvbufOldPrimals = nullptr;
5661 }
5662 }
5663 };
5664
5665
5666 template<typename SENDTYPE, typename RECVTYPE>
5667 void AMPI_Gather_p(HandleBase* handle, AdjointInterface* adjointInterface) {
5669
5670 h->recvbufAdjoints = nullptr;
5671 if(h->root == getCommRank(h->comm)) {
5672 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
5673 adjointInterface->createPrimalTypeBuffer((void*&)h->recvbufPrimals, h->recvbufTotalSize );
5674 }
5675 h->sendbufAdjoints = nullptr;
5676 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
5677 adjointInterface->createPrimalTypeBuffer((void*&)h->sendbufPrimals, h->sendbufTotalSize );
5678 // Primal buffers are always linear in space so we can accesses them in one sweep
5679 adjointInterface->getPrimals(h->sendbufIndices, h->sendbufPrimals, h->sendbufTotalSize);
5680
5681
5682 AMPI_Gather_pri<SENDTYPE, RECVTYPE>(h->sendbufPrimals, h->sendbufCountVec, h->sendcount, h->sendtype, h->recvbufPrimals,
5683 h->recvbufCountVec, h->recvcount, h->recvtype, h->root, h->comm);
5684
5685 adjointInterface->deletePrimalTypeBuffer((void*&)h->sendbufPrimals);
5686 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
5687 if(h->root == getCommRank(h->comm)) {
5688 adjointInterface->getPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
5689 }
5690 }
5691 if(h->root == getCommRank(h->comm)) {
5692 // Primal buffers are always linear in space so we can accesses them in one sweep
5693 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufPrimals, h->recvbufTotalSize);
5694 adjointInterface->deletePrimalTypeBuffer((void*&)h->recvbufPrimals);
5695 }
5696 }
5697
5698 template<typename SENDTYPE, typename RECVTYPE>
5699 void AMPI_Gather_d(HandleBase* handle, AdjointInterface* adjointInterface) {
5701
5702 h->recvbufAdjoints = nullptr;
5703 if(h->root == getCommRank(h->comm)) {
5704 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
5705 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
5706 }
5707 h->sendbufAdjoints = nullptr;
5708 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
5709 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
5710 // Adjoint buffers are always linear in space so we can accesses them in one sweep
5711 adjointInterface->getAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
5712
5713
5714 AMPI_Gather_fwd<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype,
5716
5717 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
5718 if(h->root == getCommRank(h->comm)) {
5719 // Adjoint buffers are always linear in space so we can accesses them in one sweep
5720 adjointInterface->updateAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
5721 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
5722 }
5723 }
5724
5725 template<typename SENDTYPE, typename RECVTYPE>
5726 void AMPI_Gather_b(HandleBase* handle, AdjointInterface* adjointInterface) {
5728
5729 h->recvbufAdjoints = nullptr;
5730 if(h->root == getCommRank(h->comm)) {
5731 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
5732 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
5733 // Adjoint buffers are always linear in space so we can accesses them in one sweep
5734 adjointInterface->getAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
5735
5736 }
5737 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
5738 if(h->root == getCommRank(h->comm)) {
5739 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
5740 }
5741 }
5742 h->sendbufAdjoints = nullptr;
5743 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
5744 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
5745
5746 AMPI_Gather_adj<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype,
5748
5749 // Adjoint buffers are always linear in space so we can accesses them in one sweep
5750 adjointInterface->updateAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
5751 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
5752 if(h->root == getCommRank(h->comm)) {
5753 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
5754 }
5755 }
5756
5757 template<typename SENDTYPE, typename RECVTYPE>
5758 int AMPI_Gather(MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf, int sendcount, SENDTYPE* sendtype,
5759 typename RECVTYPE::Type* recvbuf, int recvcount, RECVTYPE* recvtype, int root, AMPI_Comm comm) {
5760 int rStatus;
5761
5762 if(!recvtype->getADTool().isActiveType()) {
5763 // call the regular function if the type is not active
5764 rStatus = MPI_Gather(sendbuf, sendcount, sendtype->getMpiType(), recvbuf, recvcount, recvtype->getMpiType(), root,
5765 comm);
5766 } else {
5767
5768 // the type is an AD type so handle the buffers
5770 typename SENDTYPE::ModifiedType* sendbufMod = nullptr;
5771 int sendbufElements = 0;
5772
5773 // compute the total size of the buffer
5774 if(AMPI_IN_PLACE != sendbuf) {
5775 sendbufElements = sendcount;
5776 } else {
5777 sendbufElements = recvcount;
5778 }
5779
5780 if(sendtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
5781 sendtype->createModifiedTypeBuffer(sendbufMod, sendbufElements);
5782 } else {
5783 sendbufMod = reinterpret_cast<typename SENDTYPE::ModifiedType*>(const_cast<typename SENDTYPE::Type*>(sendbuf));
5784 }
5785 typename RECVTYPE::ModifiedType* recvbufMod = nullptr;
5786 int recvbufElements = 0;
5787
5788 if(root == getCommRank(comm)) {
5789 // compute the total size of the buffer
5790 recvbufElements = recvcount * getCommSize(comm);
5791
5792 if(recvtype->isModifiedBufferRequired() ) {
5793 recvtype->createModifiedTypeBuffer(recvbufMod, recvbufElements);
5794 } else {
5795 recvbufMod = reinterpret_cast<typename RECVTYPE::ModifiedType*>(const_cast<typename RECVTYPE::Type*>(recvbuf));
5796 }
5797 }
5798
5799 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
5800 if(recvtype->getADTool().isHandleRequired()) {
5802 }
5803 recvtype->getADTool().startAssembly(h);
5804 if(sendtype->isModifiedBufferRequired()) {
5805 if(AMPI_IN_PLACE != sendbuf) {
5806 sendtype->copyIntoModifiedBuffer(sendbuf, 0, sendbufMod, 0, sendcount);
5807 } else {
5808 recvtype->copyIntoModifiedBuffer(recvbuf, recvcount * getCommRank(comm), recvbufMod, recvcount * getCommRank(comm),
5809 recvcount);
5810 }
5811 }
5812
5813 if(nullptr != h) {
5814 // gather the information for the reverse sweep
5815
5816 // create the index buffers
5817 if(AMPI_IN_PLACE != sendbuf) {
5818 h->sendbufCount = sendtype->computeActiveElements(sendcount);
5819 } else {
5820 h->sendbufCount = recvtype->computeActiveElements(recvcount);
5821 }
5822 h->sendbufTotalSize = sendtype->computeActiveElements(sendbufElements);
5823 recvtype->getADTool().createIndexTypeBuffer(h->sendbufIndices, h->sendbufTotalSize);
5824 if(root == getCommRank(comm)) {
5825 h->recvbufCount = recvtype->computeActiveElements(recvcount);
5826 h->recvbufTotalSize = recvtype->computeActiveElements(recvbufElements);
5827 recvtype->getADTool().createIndexTypeBuffer(h->recvbufIndices, h->recvbufTotalSize);
5828 }
5829
5830
5831 // extract the old primal values from the recv buffer if the AD tool
5832 // needs the primal values reset
5833 if(recvtype->getADTool().isOldPrimalsRequired()) {
5834 if(root == getCommRank(comm)) {
5835 recvtype->getADTool().createPrimalTypeBuffer(h->recvbufOldPrimals, h->recvbufTotalSize);
5836 if(root == getCommRank(comm)) {
5837 recvtype->getValues(recvbuf, 0, h->recvbufOldPrimals, 0, recvcount * getCommSize(comm));
5838 }
5839 }
5840 }
5841
5842
5843 if(AMPI_IN_PLACE != sendbuf) {
5844 sendtype->getIndices(sendbuf, 0, h->sendbufIndices, 0, sendcount);
5845 } else {
5846 recvtype->getIndices(recvbuf, recvcount * getCommRank(comm), h->sendbufIndices, 0, recvcount);
5847 }
5848
5849 if(root == getCommRank(comm)) {
5850 recvtype->createIndices(recvbuf, 0, h->recvbufIndices, 0, recvcount * getCommSize(comm));
5851 }
5852
5853 // pack all the variables in the handle
5854 h->funcReverse = AMPI_Gather_b<SENDTYPE, RECVTYPE>;
5855 h->funcForward = AMPI_Gather_d<SENDTYPE, RECVTYPE>;
5856 h->funcPrimal = AMPI_Gather_p<SENDTYPE, RECVTYPE>;
5857 h->sendcount = sendcount;
5858 h->sendtype = sendtype;
5859 h->recvcount = recvcount;
5860 h->recvtype = recvtype;
5861 h->root = root;
5862 h->comm = comm;
5863 }
5864
5865 if(root == getCommRank(comm)) {
5866 if(!recvtype->isModifiedBufferRequired()) {
5867 recvtype->clearIndices(recvbuf, 0, recvcount * getCommSize(comm));
5868 }
5869 }
5870
5871 rStatus = MPI_Gather(sendbufMod, sendcount, sendtype->getModifiedMpiType(), recvbufMod, recvcount,
5872 recvtype->getModifiedMpiType(), root, comm);
5873 recvtype->getADTool().addToolAction(h);
5874
5875 if(root == getCommRank(comm)) {
5876 if(recvtype->isModifiedBufferRequired()) {
5877 recvtype->copyFromModifiedBuffer(recvbuf, 0, recvbufMod, 0, recvcount * getCommSize(comm));
5878 }
5879 }
5880
5881 if(nullptr != h) {
5882 // handle the recv buffers
5883 if(root == getCommRank(comm)) {
5884 recvtype->registerValue(recvbuf, 0, h->recvbufIndices, h->recvbufOldPrimals, 0, recvcount * getCommSize(comm));
5885 }
5886 }
5887
5888 recvtype->getADTool().stopAssembly(h);
5889
5890 if(sendtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
5891 sendtype->deleteModifiedTypeBuffer(sendbufMod);
5892 }
5893 if(root == getCommRank(comm)) {
5894 if(recvtype->isModifiedBufferRequired() ) {
5895 recvtype->deleteModifiedTypeBuffer(recvbufMod);
5896 }
5897 }
5898
5899 // handle is deleted by the AD tool
5900 }
5901
5902 return rStatus;
5903 }
5904
5905#endif
5906#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
5907 template<typename SENDTYPE, typename RECVTYPE>
5910 typename SENDTYPE::IndexType* sendbufIndices;
5911 typename SENDTYPE::PrimalType* sendbufPrimals;
5912 /* required for async */ void* sendbufAdjoints;
5916 SENDTYPE* sendtype;
5918 typename RECVTYPE::IndexType* recvbufIndices;
5919 typename RECVTYPE::PrimalType* recvbufPrimals;
5920 typename RECVTYPE::PrimalType* recvbufOldPrimals;
5921 /* required for async */ void* recvbufAdjoints;
5923 /* required for async */ int* recvbufCountVec;
5924 /* required for async */ int* recvbufDisplsVec;
5925 const int* recvcounts;
5926 const int* displs;
5927 RECVTYPE* recvtype;
5928 int root;
5930
5932 if(nullptr != sendbufIndices) {
5933 sendtype->getADTool().deleteIndexTypeBuffer(sendbufIndices);
5934 sendbufIndices = nullptr;
5935 }
5936 if(nullptr != sendbufPrimals) {
5937 sendtype->getADTool().deletePrimalTypeBuffer(sendbufPrimals);
5938 sendbufPrimals = nullptr;
5939 }
5940 if(nullptr != recvbufIndices) {
5941 recvtype->getADTool().deleteIndexTypeBuffer(recvbufIndices);
5942 recvbufIndices = nullptr;
5943 }
5944 if(nullptr != recvbufPrimals) {
5945 recvtype->getADTool().deletePrimalTypeBuffer(recvbufPrimals);
5946 recvbufPrimals = nullptr;
5947 }
5948 if(nullptr != recvbufOldPrimals) {
5949 recvtype->getADTool().deletePrimalTypeBuffer(recvbufOldPrimals);
5950 recvbufOldPrimals = nullptr;
5951 }
5952 if(nullptr != recvbufCount) {
5953 delete [] recvbufCount;
5954 recvbufCount = nullptr;
5955 }
5956 }
5957 };
5958
5959
5960 template<typename SENDTYPE, typename RECVTYPE>
5961 void AMPI_Gatherv_p(HandleBase* handle, AdjointInterface* adjointInterface) {
5963 (handle);
5964
5965 h->recvbufAdjoints = nullptr;
5966 if(h->root == getCommRank(h->comm)) {
5968 adjointInterface->getVectorSize());
5969 adjointInterface->createPrimalTypeBuffer((void*&)h->recvbufPrimals, h->recvbufTotalSize );
5970 }
5971 h->sendbufAdjoints = nullptr;
5972 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
5973 adjointInterface->createPrimalTypeBuffer((void*&)h->sendbufPrimals, h->sendbufTotalSize );
5974 // Primal buffers are always linear in space so we can accesses them in one sweep
5975 adjointInterface->getPrimals(h->sendbufIndices, h->sendbufPrimals, h->sendbufTotalSize);
5976
5977
5978 AMPI_Gatherv_pri<SENDTYPE, RECVTYPE>(h->sendbufPrimals, h->sendbufCountVec, h->sendcount, h->sendtype,
5980
5981 adjointInterface->deletePrimalTypeBuffer((void*&)h->sendbufPrimals);
5982 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
5983 if(h->root == getCommRank(h->comm)) {
5984 adjointInterface->getPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
5985 }
5986 }
5987 if(h->root == getCommRank(h->comm)) {
5988 // Primal buffers are always linear in space so we can accesses them in one sweep
5989 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufPrimals, h->recvbufTotalSize);
5990 adjointInterface->deletePrimalTypeBuffer((void*&)h->recvbufPrimals);
5991 delete [] h->recvbufCountVec;
5992 delete [] h->recvbufDisplsVec;
5993 }
5994 }
5995
5996 template<typename SENDTYPE, typename RECVTYPE>
5997 void AMPI_Gatherv_d(HandleBase* handle, AdjointInterface* adjointInterface) {
5999 (handle);
6000
6001 h->recvbufAdjoints = nullptr;
6002 if(h->root == getCommRank(h->comm)) {
6004 adjointInterface->getVectorSize());
6005 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
6006 }
6007 h->sendbufAdjoints = nullptr;
6008 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
6009 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
6010 // Adjoint buffers are always linear in space so we can accesses them in one sweep
6011 adjointInterface->getAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
6012
6013
6014 AMPI_Gatherv_fwd<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype,
6016
6017 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
6018 if(h->root == getCommRank(h->comm)) {
6019 // Adjoint buffers are always linear in space so we can accesses them in one sweep
6020 adjointInterface->updateAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
6021 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
6022 delete [] h->recvbufCountVec;
6023 delete [] h->recvbufDisplsVec;
6024 }
6025 }
6026
6027 template<typename SENDTYPE, typename RECVTYPE>
6028 void AMPI_Gatherv_b(HandleBase* handle, AdjointInterface* adjointInterface) {
6030 (handle);
6031
6032 h->recvbufAdjoints = nullptr;
6033 if(h->root == getCommRank(h->comm)) {
6035 adjointInterface->getVectorSize());
6036 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
6037 // Adjoint buffers are always linear in space so we can accesses them in one sweep
6038 adjointInterface->getAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
6039
6040 }
6041 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
6042 if(h->root == getCommRank(h->comm)) {
6043 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
6044 }
6045 }
6046 h->sendbufAdjoints = nullptr;
6047 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
6048 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
6049
6050 AMPI_Gatherv_adj<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype,
6052
6053 // Adjoint buffers are always linear in space so we can accesses them in one sweep
6054 adjointInterface->updateAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
6055 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
6056 if(h->root == getCommRank(h->comm)) {
6057 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
6058 delete [] h->recvbufCountVec;
6059 delete [] h->recvbufDisplsVec;
6060 }
6061 }
6062
6063 template<typename SENDTYPE, typename RECVTYPE>
6064 int AMPI_Gatherv(MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf, int sendcount, SENDTYPE* sendtype,
6065 typename RECVTYPE::Type* recvbuf, const int* recvcounts, const int* displs, RECVTYPE* recvtype, int root,
6066 AMPI_Comm comm) {
6067 int rStatus;
6068
6069 if(!recvtype->getADTool().isActiveType()) {
6070 // call the regular function if the type is not active
6071 rStatus = MPI_Gatherv(sendbuf, sendcount, sendtype->getMpiType(), recvbuf, recvcounts, displs, recvtype->getMpiType(),
6072 root, comm);
6073 } else {
6074
6075 // the type is an AD type so handle the buffers
6077 MEDI_OPTIONAL_CONST int* displsMod = displs;
6078 int displsTotalSize = 0;
6079 if(nullptr != displs) {
6080 displsTotalSize = computeDisplacementsTotalSize(recvcounts, getCommSize(comm));
6081 if(recvtype->isModifiedBufferRequired()) {
6082 displsMod = createLinearDisplacements(recvcounts, getCommSize(comm));
6083 }
6084 }
6085 typename SENDTYPE::ModifiedType* sendbufMod = nullptr;
6086 int sendbufElements = 0;
6087
6088 // compute the total size of the buffer
6089 if(AMPI_IN_PLACE != sendbuf) {
6090 sendbufElements = sendcount;
6091 } else {
6092 sendbufElements = recvcounts[getCommRank(comm)];
6093 }
6094
6095 if(sendtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
6096 sendtype->createModifiedTypeBuffer(sendbufMod, sendbufElements);
6097 } else {
6098 sendbufMod = reinterpret_cast<typename SENDTYPE::ModifiedType*>(const_cast<typename SENDTYPE::Type*>(sendbuf));
6099 }
6100 typename RECVTYPE::ModifiedType* recvbufMod = nullptr;
6101 int recvbufElements = 0;
6102
6103 if(root == getCommRank(comm)) {
6104 // compute the total size of the buffer
6105 recvbufElements = displsTotalSize;
6106
6107 if(recvtype->isModifiedBufferRequired() ) {
6108 recvtype->createModifiedTypeBuffer(recvbufMod, recvbufElements);
6109 } else {
6110 recvbufMod = reinterpret_cast<typename RECVTYPE::ModifiedType*>(const_cast<typename RECVTYPE::Type*>(recvbuf));
6111 }
6112 }
6113
6114 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
6115 if(recvtype->getADTool().isHandleRequired()) {
6117 }
6118 recvtype->getADTool().startAssembly(h);
6119 if(sendtype->isModifiedBufferRequired()) {
6120 if(AMPI_IN_PLACE != sendbuf) {
6121 sendtype->copyIntoModifiedBuffer(sendbuf, 0, sendbufMod, 0, sendcount);
6122 } else {
6123 {
6124 const int rank = getCommRank(comm);
6125 recvtype->copyIntoModifiedBuffer(recvbuf, displs[rank], recvbufMod, displsMod[rank], recvcounts[rank]);
6126 }
6127 }
6128 }
6129
6130 if(nullptr != h) {
6131 // gather the information for the reverse sweep
6132
6133 // create the index buffers
6134 if(AMPI_IN_PLACE != sendbuf) {
6135 h->sendbufCount = sendtype->computeActiveElements(sendcount);
6136 } else {
6137 h->sendbufCount = recvtype->computeActiveElements(displs[getCommRank(comm)] + recvcounts[getCommRank(
6138 comm)]) - recvtype->computeActiveElements(displs[getCommRank(comm)]);
6139 }
6140 h->sendbufTotalSize = sendtype->computeActiveElements(sendbufElements);
6141 recvtype->getADTool().createIndexTypeBuffer(h->sendbufIndices, h->sendbufTotalSize);
6142 if(root == getCommRank(comm)) {
6143 createLinearIndexCounts(h->recvbufCount, recvcounts, displs, getCommSize(comm), recvtype);
6144 h->recvbufTotalSize = recvtype->computeActiveElements(recvbufElements);
6145 recvtype->getADTool().createIndexTypeBuffer(h->recvbufIndices, h->recvbufTotalSize);
6146 }
6147
6148
6149 // extract the old primal values from the recv buffer if the AD tool
6150 // needs the primal values reset
6151 if(recvtype->getADTool().isOldPrimalsRequired()) {
6152 if(root == getCommRank(comm)) {
6153 recvtype->getADTool().createPrimalTypeBuffer(h->recvbufOldPrimals, h->recvbufTotalSize);
6154 if(root == getCommRank(comm)) {
6155 for(int i = 0; i < getCommSize(comm); ++i) {
6156 recvtype->getValues(recvbuf, displs[i], h->recvbufOldPrimals, displsMod[i], recvcounts[i]);
6157 }
6158 }
6159 }
6160 }
6161
6162
6163 if(AMPI_IN_PLACE != sendbuf) {
6164 sendtype->getIndices(sendbuf, 0, h->sendbufIndices, 0, sendcount);
6165 } else {
6166 {
6167 const int rank = getCommRank(comm);
6168 recvtype->getIndices(recvbuf, displs[rank], h->sendbufIndices, 0, recvcounts[rank]);
6169 }
6170 }
6171
6172 if(root == getCommRank(comm)) {
6173 for(int i = 0; i < getCommSize(comm); ++i) {
6174 recvtype->createIndices(recvbuf, displs[i], h->recvbufIndices, displsMod[i], recvcounts[i]);
6175 }
6176 }
6177
6178 // pack all the variables in the handle
6179 h->funcReverse = AMPI_Gatherv_b<SENDTYPE, RECVTYPE>;
6180 h->funcForward = AMPI_Gatherv_d<SENDTYPE, RECVTYPE>;
6181 h->funcPrimal = AMPI_Gatherv_p<SENDTYPE, RECVTYPE>;
6182 h->sendcount = sendcount;
6183 h->sendtype = sendtype;
6184 h->recvcounts = recvcounts;
6185 h->displs = displs;
6186 h->recvtype = recvtype;
6187 h->root = root;
6188 h->comm = comm;
6189 }
6190
6191 if(root == getCommRank(comm)) {
6192 if(!recvtype->isModifiedBufferRequired()) {
6193 for(int i = 0; i < getCommSize(comm); ++i) {
6194 recvtype->clearIndices(recvbuf, displs[i], recvcounts[i]);
6195 }
6196 }
6197 }
6198
6199 rStatus = MPI_Gatherv(sendbufMod, sendcount, sendtype->getModifiedMpiType(), recvbufMod, recvcounts, displsMod,
6200 recvtype->getModifiedMpiType(), root, comm);
6201 recvtype->getADTool().addToolAction(h);
6202
6203 if(root == getCommRank(comm)) {
6204 if(recvtype->isModifiedBufferRequired()) {
6205 for(int i = 0; i < getCommSize(comm); ++i) {
6206 recvtype->copyFromModifiedBuffer(recvbuf, displs[i], recvbufMod, displsMod[i], recvcounts[i]);
6207 }
6208 }
6209 }
6210
6211 if(nullptr != h) {
6212 // handle the recv buffers
6213 if(root == getCommRank(comm)) {
6214 for(int i = 0; i < getCommSize(comm); ++i) {
6215 recvtype->registerValue(recvbuf, displs[i], h->recvbufIndices, h->recvbufOldPrimals, displsMod[i], recvcounts[i]);
6216 }
6217 }
6218 }
6219
6220 recvtype->getADTool().stopAssembly(h);
6221 if(recvtype->isModifiedBufferRequired()) {
6222 delete [] displsMod;
6223 }
6224
6225 if(sendtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
6226 sendtype->deleteModifiedTypeBuffer(sendbufMod);
6227 }
6228 if(root == getCommRank(comm)) {
6229 if(recvtype->isModifiedBufferRequired() ) {
6230 recvtype->deleteModifiedTypeBuffer(recvbufMod);
6231 }
6232 }
6233
6234 // handle is deleted by the AD tool
6235 }
6236
6237 return rStatus;
6238 }
6239
6240#endif
6241#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
6242 template<typename SENDTYPE, typename RECVTYPE>
6245 typename SENDTYPE::IndexType* sendbufIndices;
6246 typename SENDTYPE::PrimalType* sendbufPrimals;
6247 /* required for async */ void* sendbufAdjoints;
6251 SENDTYPE* sendtype;
6253 typename RECVTYPE::IndexType* recvbufIndices;
6254 typename RECVTYPE::PrimalType* recvbufPrimals;
6255 typename RECVTYPE::PrimalType* recvbufOldPrimals;
6256 /* required for async */ void* recvbufAdjoints;
6260 RECVTYPE* recvtype;
6262
6264 if(nullptr != sendbufIndices) {
6265 sendtype->getADTool().deleteIndexTypeBuffer(sendbufIndices);
6266 sendbufIndices = nullptr;
6267 }
6268 if(nullptr != sendbufPrimals) {
6269 sendtype->getADTool().deletePrimalTypeBuffer(sendbufPrimals);
6270 sendbufPrimals = nullptr;
6271 }
6272 if(nullptr != recvbufIndices) {
6273 recvtype->getADTool().deleteIndexTypeBuffer(recvbufIndices);
6274 recvbufIndices = nullptr;
6275 }
6276 if(nullptr != recvbufPrimals) {
6277 recvtype->getADTool().deletePrimalTypeBuffer(recvbufPrimals);
6278 recvbufPrimals = nullptr;
6279 }
6280 if(nullptr != recvbufOldPrimals) {
6281 recvtype->getADTool().deletePrimalTypeBuffer(recvbufOldPrimals);
6282 recvbufOldPrimals = nullptr;
6283 }
6284 }
6285 };
6286
6287 template<typename SENDTYPE, typename RECVTYPE>
6289 MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf;
6290 typename SENDTYPE::ModifiedType* sendbufMod;
6292 SENDTYPE* sendtype;
6293 typename RECVTYPE::Type* recvbuf;
6294 typename RECVTYPE::ModifiedType* recvbufMod;
6296 RECVTYPE* recvtype;
6299 };
6300
6301 template<typename SENDTYPE, typename RECVTYPE>
6302 void AMPI_Iallgather_p(HandleBase* handle, AdjointInterface* adjointInterface) {
6304 (handle);
6305
6306 h->recvbufAdjoints = nullptr;
6307 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
6308 adjointInterface->createPrimalTypeBuffer((void*&)h->recvbufPrimals, h->recvbufTotalSize );
6309 h->sendbufAdjoints = nullptr;
6310 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
6311 adjointInterface->createPrimalTypeBuffer((void*&)h->sendbufPrimals, h->sendbufTotalSize );
6312 // Primal buffers are always linear in space so we can accesses them in one sweep
6313 adjointInterface->getPrimals(h->sendbufIndices, h->sendbufPrimals, h->sendbufTotalSize);
6314
6315
6316 AMPI_Iallgather_pri<SENDTYPE, RECVTYPE>(h->sendbufPrimals, h->sendbufCountVec, h->sendcount, h->sendtype,
6318
6319 }
6320
6321 template<typename SENDTYPE, typename RECVTYPE>
6322 void AMPI_Iallgather_p_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
6323
6325 (handle);
6326 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
6327
6328 adjointInterface->deletePrimalTypeBuffer((void*&)h->sendbufPrimals);
6329 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
6330 adjointInterface->getPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
6331 }
6332 // Primal buffers are always linear in space so we can accesses them in one sweep
6333 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufPrimals, h->recvbufTotalSize);
6334 adjointInterface->deletePrimalTypeBuffer((void*&)h->recvbufPrimals);
6335 }
6336
6337 template<typename SENDTYPE, typename RECVTYPE>
6338 void AMPI_Iallgather_d(HandleBase* handle, AdjointInterface* adjointInterface) {
6340 (handle);
6341
6342 h->recvbufAdjoints = nullptr;
6343 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
6344 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
6345 h->sendbufAdjoints = nullptr;
6346 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
6347 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
6348 // Adjoint buffers are always linear in space so we can accesses them in one sweep
6349 adjointInterface->getAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
6350
6351
6352 AMPI_Iallgather_fwd<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype,
6354
6355 }
6356
6357 template<typename SENDTYPE, typename RECVTYPE>
6358 void AMPI_Iallgather_d_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
6359
6361 (handle);
6362 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
6363
6364 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
6365 // Adjoint buffers are always linear in space so we can accesses them in one sweep
6366 adjointInterface->updateAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
6367 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
6368 }
6369
6370 template<typename SENDTYPE, typename RECVTYPE>
6371 void AMPI_Iallgather_b(HandleBase* handle, AdjointInterface* adjointInterface) {
6373 (handle);
6374
6375 h->recvbufAdjoints = nullptr;
6376 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
6377 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
6378 // Adjoint buffers are always linear in space so we can accesses them in one sweep
6379 adjointInterface->getAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
6380
6381 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
6382 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
6383 }
6384 h->sendbufAdjoints = nullptr;
6385 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
6387
6388 AMPI_Iallgather_adj<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype,
6390
6391 }
6392
6393 template<typename SENDTYPE, typename RECVTYPE>
6394 void AMPI_Iallgather_b_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
6395
6397 (handle);
6398 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
6399
6400 adjointInterface->combineAdjoints(h->sendbufAdjoints, h->sendbufTotalSize, getCommSize(h->comm));
6401 // Adjoint buffers are always linear in space so we can accesses them in one sweep
6402 adjointInterface->updateAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
6403 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
6404 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
6405 }
6406
6407 template<typename SENDTYPE, typename RECVTYPE>
6408 int AMPI_Iallgather_finish(HandleBase* handle);
6409 template<typename SENDTYPE, typename RECVTYPE>
6410 int AMPI_Iallgather(MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf, int sendcount, SENDTYPE* sendtype,
6411 typename RECVTYPE::Type* recvbuf, int recvcount, RECVTYPE* recvtype, AMPI_Comm comm, AMPI_Request* request) {
6412 int rStatus;
6413
6414 if(!recvtype->getADTool().isActiveType()) {
6415 // call the regular function if the type is not active
6416 rStatus = MPI_Iallgather(sendbuf, sendcount, sendtype->getMpiType(), recvbuf, recvcount, recvtype->getMpiType(), comm,
6417 &request->request);
6418 } else {
6419
6420 // the type is an AD type so handle the buffers
6422 typename SENDTYPE::ModifiedType* sendbufMod = nullptr;
6423 int sendbufElements = 0;
6424
6425 // compute the total size of the buffer
6426 if(AMPI_IN_PLACE != sendbuf) {
6427 sendbufElements = sendcount;
6428 } else {
6429 sendbufElements = recvcount;
6430 }
6431
6432 if(sendtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
6433 sendtype->createModifiedTypeBuffer(sendbufMod, sendbufElements);
6434 } else {
6435 sendbufMod = reinterpret_cast<typename SENDTYPE::ModifiedType*>(const_cast<typename SENDTYPE::Type*>(sendbuf));
6436 }
6437 typename RECVTYPE::ModifiedType* recvbufMod = nullptr;
6438 int recvbufElements = 0;
6439
6440 // compute the total size of the buffer
6441 recvbufElements = recvcount * getCommSize(comm);
6442
6443 if(recvtype->isModifiedBufferRequired() ) {
6444 recvtype->createModifiedTypeBuffer(recvbufMod, recvbufElements);
6445 } else {
6446 recvbufMod = reinterpret_cast<typename RECVTYPE::ModifiedType*>(const_cast<typename RECVTYPE::Type*>(recvbuf));
6447 }
6448
6449 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
6450 if(recvtype->getADTool().isHandleRequired()) {
6452 }
6453 recvtype->getADTool().startAssembly(h);
6454 if(sendtype->isModifiedBufferRequired()) {
6455 if(AMPI_IN_PLACE != sendbuf) {
6456 sendtype->copyIntoModifiedBuffer(sendbuf, 0, sendbufMod, 0, sendcount);
6457 } else {
6458 recvtype->copyIntoModifiedBuffer(recvbuf, recvcount * getCommRank(comm), recvbufMod, recvcount * getCommRank(comm),
6459 recvcount);
6460 }
6461 }
6462
6463 if(nullptr != h) {
6464 // gather the information for the reverse sweep
6465
6466 // create the index buffers
6467 if(AMPI_IN_PLACE != sendbuf) {
6468 h->sendbufCount = sendtype->computeActiveElements(sendcount);
6469 } else {
6470 h->sendbufCount = recvtype->computeActiveElements(recvcount);
6471 }
6472 h->sendbufTotalSize = sendtype->computeActiveElements(sendbufElements);
6473 recvtype->getADTool().createIndexTypeBuffer(h->sendbufIndices, h->sendbufTotalSize);
6474 h->recvbufCount = recvtype->computeActiveElements(recvcount);
6475 h->recvbufTotalSize = recvtype->computeActiveElements(recvbufElements);
6476 recvtype->getADTool().createIndexTypeBuffer(h->recvbufIndices, h->recvbufTotalSize);
6477
6478
6479 // extract the old primal values from the recv buffer if the AD tool
6480 // needs the primal values reset
6481 if(recvtype->getADTool().isOldPrimalsRequired()) {
6482 recvtype->getADTool().createPrimalTypeBuffer(h->recvbufOldPrimals, h->recvbufTotalSize);
6483 recvtype->getValues(recvbuf, 0, h->recvbufOldPrimals, 0, recvcount * getCommSize(comm));
6484 }
6485
6486
6487 if(AMPI_IN_PLACE != sendbuf) {
6488 sendtype->getIndices(sendbuf, 0, h->sendbufIndices, 0, sendcount);
6489 } else {
6490 recvtype->getIndices(recvbuf, recvcount * getCommRank(comm), h->sendbufIndices, 0, recvcount);
6491 }
6492
6493 recvtype->createIndices(recvbuf, 0, h->recvbufIndices, 0, recvcount * getCommSize(comm));
6494
6495 // pack all the variables in the handle
6496 h->funcReverse = AMPI_Iallgather_b<SENDTYPE, RECVTYPE>;
6497 h->funcForward = AMPI_Iallgather_d_finish<SENDTYPE, RECVTYPE>;
6498 h->funcPrimal = AMPI_Iallgather_p_finish<SENDTYPE, RECVTYPE>;
6499 h->sendcount = sendcount;
6500 h->sendtype = sendtype;
6501 h->recvcount = recvcount;
6502 h->recvtype = recvtype;
6503 h->comm = comm;
6504 }
6505
6506 if(!recvtype->isModifiedBufferRequired()) {
6507 recvtype->clearIndices(recvbuf, 0, recvcount * getCommSize(comm));
6508 }
6509
6510 rStatus = MPI_Iallgather(sendbufMod, sendcount, sendtype->getModifiedMpiType(), recvbufMod, recvcount,
6511 recvtype->getModifiedMpiType(), comm, &request->request);
6512
6514 asyncHandle->sendbuf = sendbuf;
6515 asyncHandle->sendbufMod = sendbufMod;
6516 asyncHandle->sendcount = sendcount;
6517 asyncHandle->sendtype = sendtype;
6518 asyncHandle->recvbuf = recvbuf;
6519 asyncHandle->recvbufMod = recvbufMod;
6520 asyncHandle->recvcount = recvcount;
6521 asyncHandle->recvtype = recvtype;
6522 asyncHandle->comm = comm;
6523 asyncHandle->toolHandle = h;
6524 request->handle = asyncHandle;
6525 request->func = (ContinueFunction)AMPI_Iallgather_finish<SENDTYPE, RECVTYPE>;
6526
6527 // create adjoint wait
6528 if(nullptr != h) {
6529 WaitHandle* waitH = new WaitHandle((ReverseFunction)AMPI_Iallgather_b_finish<SENDTYPE, RECVTYPE>,
6530 (ForwardFunction)AMPI_Iallgather_d<SENDTYPE, RECVTYPE>, h);
6531 recvtype->getADTool().addToolAction(waitH);
6532 }
6533 }
6534
6535 return rStatus;
6536 }
6537
6538 template<typename SENDTYPE, typename RECVTYPE>
6540 int rStatus = 0;
6541
6544 MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf = asyncHandle->sendbuf;
6545 typename SENDTYPE::ModifiedType* sendbufMod = asyncHandle->sendbufMod;
6546 int sendcount = asyncHandle->sendcount;
6547 SENDTYPE* sendtype = asyncHandle->sendtype;
6548 typename RECVTYPE::Type* recvbuf = asyncHandle->recvbuf;
6549 typename RECVTYPE::ModifiedType* recvbufMod = asyncHandle->recvbufMod;
6550 int recvcount = asyncHandle->recvcount;
6551 RECVTYPE* recvtype = asyncHandle->recvtype;
6552 AMPI_Comm comm = asyncHandle->comm;
6553 AMPI_Request* request = asyncHandle->request;
6555 (asyncHandle->toolHandle);
6556 MEDI_UNUSED(h); // Unused generated to ignore warnings
6557 MEDI_UNUSED(sendbuf); // Unused generated to ignore warnings
6558 MEDI_UNUSED(sendbufMod); // Unused generated to ignore warnings
6559 MEDI_UNUSED(sendcount); // Unused generated to ignore warnings
6560 MEDI_UNUSED(sendtype); // Unused generated to ignore warnings
6561 MEDI_UNUSED(recvbuf); // Unused generated to ignore warnings
6562 MEDI_UNUSED(recvbufMod); // Unused generated to ignore warnings
6563 MEDI_UNUSED(recvcount); // Unused generated to ignore warnings
6564 MEDI_UNUSED(recvtype); // Unused generated to ignore warnings
6565 MEDI_UNUSED(comm); // Unused generated to ignore warnings
6566 MEDI_UNUSED(request); // Unused generated to ignore warnings
6567
6568 delete asyncHandle;
6569
6570 if(recvtype->getADTool().isActiveType()) {
6571
6572 recvtype->getADTool().addToolAction(h);
6573
6574 if(recvtype->isModifiedBufferRequired()) {
6575 recvtype->copyFromModifiedBuffer(recvbuf, 0, recvbufMod, 0, recvcount * getCommSize(comm));
6576 }
6577
6578 if(nullptr != h) {
6579 // handle the recv buffers
6580 recvtype->registerValue(recvbuf, 0, h->recvbufIndices, h->recvbufOldPrimals, 0, recvcount * getCommSize(comm));
6581 }
6582
6583 recvtype->getADTool().stopAssembly(h);
6584
6585 if(sendtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
6586 sendtype->deleteModifiedTypeBuffer(sendbufMod);
6587 }
6588 if(recvtype->isModifiedBufferRequired() ) {
6589 recvtype->deleteModifiedTypeBuffer(recvbufMod);
6590 }
6591
6592 // handle is deleted by the AD tool
6593 }
6594
6595 return rStatus;
6596 }
6597
6598#endif
6599#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
6600 template<typename SENDTYPE, typename RECVTYPE>
6603 typename SENDTYPE::IndexType* sendbufIndices;
6604 typename SENDTYPE::PrimalType* sendbufPrimals;
6605 /* required for async */ void* sendbufAdjoints;
6609 SENDTYPE* sendtype;
6611 typename RECVTYPE::IndexType* recvbufIndices;
6612 typename RECVTYPE::PrimalType* recvbufPrimals;
6613 typename RECVTYPE::PrimalType* recvbufOldPrimals;
6614 /* required for async */ void* recvbufAdjoints;
6616 /* required for async */ int* recvbufCountVec;
6617 /* required for async */ int* recvbufDisplsVec;
6618 const int* recvcounts;
6619 const int* displs;
6620 RECVTYPE* recvtype;
6622
6624 if(nullptr != sendbufIndices) {
6625 sendtype->getADTool().deleteIndexTypeBuffer(sendbufIndices);
6626 sendbufIndices = nullptr;
6627 }
6628 if(nullptr != sendbufPrimals) {
6629 sendtype->getADTool().deletePrimalTypeBuffer(sendbufPrimals);
6630 sendbufPrimals = nullptr;
6631 }
6632 if(nullptr != recvbufIndices) {
6633 recvtype->getADTool().deleteIndexTypeBuffer(recvbufIndices);
6634 recvbufIndices = nullptr;
6635 }
6636 if(nullptr != recvbufPrimals) {
6637 recvtype->getADTool().deletePrimalTypeBuffer(recvbufPrimals);
6638 recvbufPrimals = nullptr;
6639 }
6640 if(nullptr != recvbufOldPrimals) {
6641 recvtype->getADTool().deletePrimalTypeBuffer(recvbufOldPrimals);
6642 recvbufOldPrimals = nullptr;
6643 }
6644 if(nullptr != recvbufCount) {
6645 delete [] recvbufCount;
6646 recvbufCount = nullptr;
6647 }
6648 }
6649 };
6650
6651 template<typename SENDTYPE, typename RECVTYPE>
6653 MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf;
6654 typename SENDTYPE::ModifiedType* sendbufMod;
6656 SENDTYPE* sendtype;
6657 typename RECVTYPE::Type* recvbuf;
6658 typename RECVTYPE::ModifiedType* recvbufMod;
6659 const int* displsMod;
6660 const int* recvcounts;
6661 const int* displs;
6662 RECVTYPE* recvtype;
6665 };
6666
6667 template<typename SENDTYPE, typename RECVTYPE>
6668 void AMPI_Iallgatherv_p(HandleBase* handle, AdjointInterface* adjointInterface) {
6671
6672 h->recvbufAdjoints = nullptr;
6674 adjointInterface->getVectorSize());
6675 adjointInterface->createPrimalTypeBuffer((void*&)h->recvbufPrimals, h->recvbufTotalSize );
6676 h->sendbufAdjoints = nullptr;
6677 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
6678 adjointInterface->createPrimalTypeBuffer((void*&)h->sendbufPrimals, h->sendbufTotalSize );
6679 // Primal buffers are always linear in space so we can accesses them in one sweep
6680 adjointInterface->getPrimals(h->sendbufIndices, h->sendbufPrimals, h->sendbufTotalSize);
6681
6682
6683 AMPI_Iallgatherv_pri<SENDTYPE, RECVTYPE>(h->sendbufPrimals, h->sendbufCountVec, h->sendcount, h->sendtype,
6685 &h->requestReverse);
6686
6687 }
6688
6689 template<typename SENDTYPE, typename RECVTYPE>
6690 void AMPI_Iallgatherv_p_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
6691
6694 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
6695
6696 adjointInterface->deletePrimalTypeBuffer((void*&)h->sendbufPrimals);
6697 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
6698 adjointInterface->getPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
6699 }
6700 // Primal buffers are always linear in space so we can accesses them in one sweep
6701 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufPrimals, h->recvbufTotalSize);
6702 adjointInterface->deletePrimalTypeBuffer((void*&)h->recvbufPrimals);
6703 delete [] h->recvbufCountVec;
6704 delete [] h->recvbufDisplsVec;
6705 }
6706
6707 template<typename SENDTYPE, typename RECVTYPE>
6708 void AMPI_Iallgatherv_d(HandleBase* handle, AdjointInterface* adjointInterface) {
6711
6712 h->recvbufAdjoints = nullptr;
6714 adjointInterface->getVectorSize());
6715 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
6716 h->sendbufAdjoints = nullptr;
6717 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
6718 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
6719 // Adjoint buffers are always linear in space so we can accesses them in one sweep
6720 adjointInterface->getAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
6721
6722
6723 AMPI_Iallgatherv_fwd<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype,
6725 &h->requestReverse);
6726
6727 }
6728
6729 template<typename SENDTYPE, typename RECVTYPE>
6730 void AMPI_Iallgatherv_d_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
6731
6734 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
6735
6736 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
6737 // Adjoint buffers are always linear in space so we can accesses them in one sweep
6738 adjointInterface->updateAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
6739 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
6740 delete [] h->recvbufCountVec;
6741 delete [] h->recvbufDisplsVec;
6742 }
6743
6744 template<typename SENDTYPE, typename RECVTYPE>
6745 void AMPI_Iallgatherv_b(HandleBase* handle, AdjointInterface* adjointInterface) {
6748
6749 h->recvbufAdjoints = nullptr;
6751 adjointInterface->getVectorSize());
6752 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
6753 // Adjoint buffers are always linear in space so we can accesses them in one sweep
6754 adjointInterface->getAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
6755
6756 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
6757 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
6758 }
6759 h->sendbufAdjoints = nullptr;
6760 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
6762
6763 AMPI_Iallgatherv_adj<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype,
6765 &h->requestReverse);
6766
6767 }
6768
6769 template<typename SENDTYPE, typename RECVTYPE>
6770 void AMPI_Iallgatherv_b_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
6771
6774 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
6775
6776 adjointInterface->combineAdjoints(h->sendbufAdjoints, h->sendbufTotalSize, getCommSize(h->comm));
6777 // Adjoint buffers are always linear in space so we can accesses them in one sweep
6778 adjointInterface->updateAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
6779 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
6780 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
6781 delete [] h->recvbufCountVec;
6782 delete [] h->recvbufDisplsVec;
6783 }
6784
6785 template<typename SENDTYPE, typename RECVTYPE>
6786 int AMPI_Iallgatherv_finish(HandleBase* handle);
6787 template<typename SENDTYPE, typename RECVTYPE>
6788 int AMPI_Iallgatherv(MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf, int sendcount, SENDTYPE* sendtype,
6789 typename RECVTYPE::Type* recvbuf, const int* recvcounts, const int* displs, RECVTYPE* recvtype, AMPI_Comm comm,
6790 AMPI_Request* request) {
6791 int rStatus;
6792
6793 if(!recvtype->getADTool().isActiveType()) {
6794 // call the regular function if the type is not active
6795 rStatus = MPI_Iallgatherv(sendbuf, sendcount, sendtype->getMpiType(), recvbuf, recvcounts, displs,
6796 recvtype->getMpiType(), comm, &request->request);
6797 } else {
6798
6799 // the type is an AD type so handle the buffers
6801 MEDI_OPTIONAL_CONST int* displsMod = displs;
6802 int displsTotalSize = 0;
6803 if(nullptr != displs) {
6804 displsTotalSize = computeDisplacementsTotalSize(recvcounts, getCommSize(comm));
6805 if(recvtype->isModifiedBufferRequired()) {
6806 displsMod = createLinearDisplacements(recvcounts, getCommSize(comm));
6807 }
6808 }
6809 typename SENDTYPE::ModifiedType* sendbufMod = nullptr;
6810 int sendbufElements = 0;
6811
6812 // compute the total size of the buffer
6813 if(AMPI_IN_PLACE != sendbuf) {
6814 sendbufElements = sendcount;
6815 } else {
6816 sendbufElements = recvcounts[getCommRank(comm)];
6817 }
6818
6819 if(sendtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
6820 sendtype->createModifiedTypeBuffer(sendbufMod, sendbufElements);
6821 } else {
6822 sendbufMod = reinterpret_cast<typename SENDTYPE::ModifiedType*>(const_cast<typename SENDTYPE::Type*>(sendbuf));
6823 }
6824 typename RECVTYPE::ModifiedType* recvbufMod = nullptr;
6825 int recvbufElements = 0;
6826
6827 // compute the total size of the buffer
6828 recvbufElements = displsTotalSize;
6829
6830 if(recvtype->isModifiedBufferRequired() ) {
6831 recvtype->createModifiedTypeBuffer(recvbufMod, recvbufElements);
6832 } else {
6833 recvbufMod = reinterpret_cast<typename RECVTYPE::ModifiedType*>(const_cast<typename RECVTYPE::Type*>(recvbuf));
6834 }
6835
6836 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
6837 if(recvtype->getADTool().isHandleRequired()) {
6839 }
6840 recvtype->getADTool().startAssembly(h);
6841 if(sendtype->isModifiedBufferRequired()) {
6842 if(AMPI_IN_PLACE != sendbuf) {
6843 sendtype->copyIntoModifiedBuffer(sendbuf, 0, sendbufMod, 0, sendcount);
6844 } else {
6845 {
6846 const int rank = getCommRank(comm);
6847 recvtype->copyIntoModifiedBuffer(recvbuf, displs[rank], recvbufMod, displsMod[rank], recvcounts[rank]);
6848 }
6849 }
6850 }
6851
6852 if(nullptr != h) {
6853 // gather the information for the reverse sweep
6854
6855 // create the index buffers
6856 if(AMPI_IN_PLACE != sendbuf) {
6857 h->sendbufCount = sendtype->computeActiveElements(sendcount);
6858 } else {
6859 h->sendbufCount = recvtype->computeActiveElements(displs[getCommRank(comm)] + recvcounts[getCommRank(
6860 comm)]) - recvtype->computeActiveElements(displs[getCommRank(comm)]);
6861 }
6862 h->sendbufTotalSize = sendtype->computeActiveElements(sendbufElements);
6863 recvtype->getADTool().createIndexTypeBuffer(h->sendbufIndices, h->sendbufTotalSize);
6864 createLinearIndexCounts(h->recvbufCount, recvcounts, displs, getCommSize(comm), recvtype);
6865 h->recvbufTotalSize = recvtype->computeActiveElements(recvbufElements);
6866 recvtype->getADTool().createIndexTypeBuffer(h->recvbufIndices, h->recvbufTotalSize);
6867
6868
6869 // extract the old primal values from the recv buffer if the AD tool
6870 // needs the primal values reset
6871 if(recvtype->getADTool().isOldPrimalsRequired()) {
6872 recvtype->getADTool().createPrimalTypeBuffer(h->recvbufOldPrimals, h->recvbufTotalSize);
6873 for(int i = 0; i < getCommSize(comm); ++i) {
6874 recvtype->getValues(recvbuf, displs[i], h->recvbufOldPrimals, displsMod[i], recvcounts[i]);
6875 }
6876 }
6877
6878
6879 if(AMPI_IN_PLACE != sendbuf) {
6880 sendtype->getIndices(sendbuf, 0, h->sendbufIndices, 0, sendcount);
6881 } else {
6882 {
6883 const int rank = getCommRank(comm);
6884 recvtype->getIndices(recvbuf, displs[rank], h->sendbufIndices, 0, recvcounts[rank]);
6885 }
6886 }
6887
6888 for(int i = 0; i < getCommSize(comm); ++i) {
6889 recvtype->createIndices(recvbuf, displs[i], h->recvbufIndices, displsMod[i], recvcounts[i]);
6890 }
6891
6892 // pack all the variables in the handle
6893 h->funcReverse = AMPI_Iallgatherv_b<SENDTYPE, RECVTYPE>;
6894 h->funcForward = AMPI_Iallgatherv_d_finish<SENDTYPE, RECVTYPE>;
6895 h->funcPrimal = AMPI_Iallgatherv_p_finish<SENDTYPE, RECVTYPE>;
6896 h->sendcount = sendcount;
6897 h->sendtype = sendtype;
6898 h->recvcounts = recvcounts;
6899 h->displs = displs;
6900 h->recvtype = recvtype;
6901 h->comm = comm;
6902 }
6903
6904 if(!recvtype->isModifiedBufferRequired()) {
6905 for(int i = 0; i < getCommSize(comm); ++i) {
6906 recvtype->clearIndices(recvbuf, displs[i], recvcounts[i]);
6907 }
6908 }
6909
6910 rStatus = MPI_Iallgatherv(sendbufMod, sendcount, sendtype->getModifiedMpiType(), recvbufMod, recvcounts, displsMod,
6911 recvtype->getModifiedMpiType(), comm, &request->request);
6912
6914 asyncHandle->sendbuf = sendbuf;
6915 asyncHandle->sendbufMod = sendbufMod;
6916 asyncHandle->sendcount = sendcount;
6917 asyncHandle->sendtype = sendtype;
6918 asyncHandle->recvbuf = recvbuf;
6919 asyncHandle->recvbufMod = recvbufMod;
6920 asyncHandle->displsMod = displsMod;
6921 asyncHandle->recvcounts = recvcounts;
6922 asyncHandle->displs = displs;
6923 asyncHandle->recvtype = recvtype;
6924 asyncHandle->comm = comm;
6925 asyncHandle->toolHandle = h;
6926 request->handle = asyncHandle;
6927 request->func = (ContinueFunction)AMPI_Iallgatherv_finish<SENDTYPE, RECVTYPE>;
6928
6929 // create adjoint wait
6930 if(nullptr != h) {
6931 WaitHandle* waitH = new WaitHandle((ReverseFunction)AMPI_Iallgatherv_b_finish<SENDTYPE, RECVTYPE>,
6932 (ForwardFunction)AMPI_Iallgatherv_d<SENDTYPE, RECVTYPE>, h);
6933 recvtype->getADTool().addToolAction(waitH);
6934 }
6935 }
6936
6937 return rStatus;
6938 }
6939
6940 template<typename SENDTYPE, typename RECVTYPE>
6942 int rStatus = 0;
6943
6946 MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf = asyncHandle->sendbuf;
6947 typename SENDTYPE::ModifiedType* sendbufMod = asyncHandle->sendbufMod;
6948 int sendcount = asyncHandle->sendcount;
6949 SENDTYPE* sendtype = asyncHandle->sendtype;
6950 typename RECVTYPE::Type* recvbuf = asyncHandle->recvbuf;
6951 typename RECVTYPE::ModifiedType* recvbufMod = asyncHandle->recvbufMod;
6952 const int* displsMod = asyncHandle->displsMod;
6953 const int* recvcounts = asyncHandle->recvcounts;
6954 const int* displs = asyncHandle->displs;
6955 RECVTYPE* recvtype = asyncHandle->recvtype;
6956 AMPI_Comm comm = asyncHandle->comm;
6957 AMPI_Request* request = asyncHandle->request;
6960 MEDI_UNUSED(h); // Unused generated to ignore warnings
6961 MEDI_UNUSED(sendbuf); // Unused generated to ignore warnings
6962 MEDI_UNUSED(sendbufMod); // Unused generated to ignore warnings
6963 MEDI_UNUSED(sendcount); // Unused generated to ignore warnings
6964 MEDI_UNUSED(sendtype); // Unused generated to ignore warnings
6965 MEDI_UNUSED(recvbuf); // Unused generated to ignore warnings
6966 MEDI_UNUSED(recvbufMod); // Unused generated to ignore warnings
6967 MEDI_UNUSED(displsMod); // Unused generated to ignore warnings
6968 MEDI_UNUSED(recvcounts); // Unused generated to ignore warnings
6969 MEDI_UNUSED(displs); // Unused generated to ignore warnings
6970 MEDI_UNUSED(recvtype); // Unused generated to ignore warnings
6971 MEDI_UNUSED(comm); // Unused generated to ignore warnings
6972 MEDI_UNUSED(request); // Unused generated to ignore warnings
6973
6974 delete asyncHandle;
6975
6976 if(recvtype->getADTool().isActiveType()) {
6977
6978 recvtype->getADTool().addToolAction(h);
6979
6980 if(recvtype->isModifiedBufferRequired()) {
6981 for(int i = 0; i < getCommSize(comm); ++i) {
6982 recvtype->copyFromModifiedBuffer(recvbuf, displs[i], recvbufMod, displsMod[i], recvcounts[i]);
6983 }
6984 }
6985
6986 if(nullptr != h) {
6987 // handle the recv buffers
6988 for(int i = 0; i < getCommSize(comm); ++i) {
6989 recvtype->registerValue(recvbuf, displs[i], h->recvbufIndices, h->recvbufOldPrimals, displsMod[i], recvcounts[i]);
6990 }
6991 }
6992
6993 recvtype->getADTool().stopAssembly(h);
6994 if(recvtype->isModifiedBufferRequired()) {
6995 delete [] displsMod;
6996 }
6997
6998 if(sendtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
6999 sendtype->deleteModifiedTypeBuffer(sendbufMod);
7000 }
7001 if(recvtype->isModifiedBufferRequired() ) {
7002 recvtype->deleteModifiedTypeBuffer(recvbufMod);
7003 }
7004
7005 // handle is deleted by the AD tool
7006 }
7007
7008 return rStatus;
7009 }
7010
7011#endif
7012#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
7013 template<typename DATATYPE>
7016 typename DATATYPE::IndexType* sendbufIndices;
7017 typename DATATYPE::PrimalType* sendbufPrimals;
7018 /* required for async */ void* sendbufAdjoints;
7022 typename DATATYPE::IndexType* recvbufIndices;
7023 typename DATATYPE::PrimalType* recvbufPrimals;
7024 typename DATATYPE::PrimalType* recvbufOldPrimals;
7025 /* required for async */ void* recvbufAdjoints;
7029 DATATYPE* datatype;
7032
7034 if(nullptr != sendbufIndices) {
7035 datatype->getADTool().deleteIndexTypeBuffer(sendbufIndices);
7036 sendbufIndices = nullptr;
7037 }
7038 if(nullptr != sendbufPrimals) {
7039 datatype->getADTool().deletePrimalTypeBuffer(sendbufPrimals);
7040 sendbufPrimals = nullptr;
7041 }
7042 if(nullptr != recvbufIndices) {
7043 datatype->getADTool().deleteIndexTypeBuffer(recvbufIndices);
7044 recvbufIndices = nullptr;
7045 }
7046 if(nullptr != recvbufPrimals) {
7047 datatype->getADTool().deletePrimalTypeBuffer(recvbufPrimals);
7048 recvbufPrimals = nullptr;
7049 }
7050 if(nullptr != recvbufOldPrimals) {
7051 datatype->getADTool().deletePrimalTypeBuffer(recvbufOldPrimals);
7052 recvbufOldPrimals = nullptr;
7053 }
7054 }
7055 };
7056
7057 template<typename DATATYPE>
7059 MEDI_OPTIONAL_CONST typename DATATYPE::Type* sendbuf;
7060 typename DATATYPE::ModifiedType* sendbufMod;
7061 typename DATATYPE::Type* recvbuf;
7062 typename DATATYPE::ModifiedType* recvbufMod;
7064 DATATYPE* datatype;
7068 };
7069
7070 template<typename DATATYPE>
7071 void AMPI_Iallreduce_global_p(HandleBase* handle, AdjointInterface* adjointInterface) {
7073 (handle);
7074
7075 AMPI_Op convOp = h->datatype->getADTool().convertOperator(h->op);
7076 (void)convOp;
7077 h->recvbufAdjoints = nullptr;
7078 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
7079 adjointInterface->createPrimalTypeBuffer((void*&)h->recvbufPrimals, h->recvbufTotalSize );
7080 h->sendbufAdjoints = nullptr;
7081 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
7082 adjointInterface->createPrimalTypeBuffer((void*&)h->sendbufPrimals, h->sendbufTotalSize );
7083 // Primal buffers are always linear in space so we can accesses them in one sweep
7084 adjointInterface->getPrimals(h->sendbufIndices, h->sendbufPrimals, h->sendbufTotalSize);
7085
7086
7087 AMPI_Iallreduce_global_pri<DATATYPE>(h->sendbufPrimals, h->sendbufCountVec, h->recvbufPrimals, h->recvbufCountVec,
7088 h->count, h->datatype, h->op, h->comm, &h->requestReverse);
7089
7090 }
7091
7092 template<typename DATATYPE>
7094
7096 (handle);
7097 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
7098
7099 AMPI_Op convOp = h->datatype->getADTool().convertOperator(h->op);
7100 (void)convOp;
7101 adjointInterface->deletePrimalTypeBuffer((void*&)h->sendbufPrimals);
7102 if(h->datatype->getADTool().isOldPrimalsRequired()) {
7103 adjointInterface->getPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
7104 }
7105 // Primal buffers are always linear in space so we can accesses them in one sweep
7106 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufPrimals, h->recvbufTotalSize);
7107 adjointInterface->deletePrimalTypeBuffer((void*&)h->recvbufPrimals);
7108 }
7109
7110 template<typename DATATYPE>
7111 void AMPI_Iallreduce_global_d(HandleBase* handle, AdjointInterface* adjointInterface) {
7113 (handle);
7114
7115 AMPI_Op convOp = h->datatype->getADTool().convertOperator(h->op);
7116 (void)convOp;
7117 h->recvbufAdjoints = nullptr;
7118 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
7119 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
7120 h->sendbufAdjoints = nullptr;
7121 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
7122 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
7123 // Adjoint buffers are always linear in space so we can accesses them in one sweep
7124 adjointInterface->getAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
7125
7126
7127 AMPI_Iallreduce_global_fwd<DATATYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->recvbufAdjoints, h->recvbufCountVec,
7128 h->count, h->datatype, h->op, h->comm, &h->requestReverse);
7129
7130 }
7131
7132 template<typename DATATYPE>
7134
7136 (handle);
7137 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
7138
7139 AMPI_Op convOp = h->datatype->getADTool().convertOperator(h->op);
7140 (void)convOp;
7141 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
7142 // Adjoint buffers are always linear in space so we can accesses them in one sweep
7143 adjointInterface->updateAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
7144 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
7145 }
7146
7147 template<typename DATATYPE>
7148 void AMPI_Iallreduce_global_b(HandleBase* handle, AdjointInterface* adjointInterface) {
7150 (handle);
7151
7152 AMPI_Op convOp = h->datatype->getADTool().convertOperator(h->op);
7153 (void)convOp;
7154 h->recvbufAdjoints = nullptr;
7155 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
7156 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
7157 // Adjoint buffers are always linear in space so we can accesses them in one sweep
7158 adjointInterface->getAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
7159
7160 convOp.preAdjointOperation(h->recvbufAdjoints, h->recvbufPrimals, h->recvbufCount, adjointInterface->getVectorSize());
7161 if(h->datatype->getADTool().isOldPrimalsRequired()) {
7162 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
7163 }
7164 h->sendbufAdjoints = nullptr;
7165 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
7167
7168 AMPI_Iallreduce_global_adj<DATATYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->recvbufAdjoints, h->recvbufCountVec,
7169 h->count, h->datatype, h->op, h->comm, &h->requestReverse);
7170
7171 }
7172
7173 template<typename DATATYPE>
7175
7177 (handle);
7178 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
7179
7180 AMPI_Op convOp = h->datatype->getADTool().convertOperator(h->op);
7181 (void)convOp;
7182 adjointInterface->combineAdjoints(h->sendbufAdjoints, h->sendbufTotalSize, getCommSize(h->comm));
7183 // the primals of the recive buffer are always given to the function. The operator should ignore them if not needed.
7184 // The wrapper functions make sure that for operators that need the primals an all* action is perfomed (e.g. Allreduce instead of Reduce)
7186 adjointInterface->getVectorSize());
7187 // Adjoint buffers are always linear in space so we can accesses them in one sweep
7188 adjointInterface->updateAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
7189 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
7190 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
7191 }
7192
7193 template<typename DATATYPE>
7194 int AMPI_Iallreduce_global_finish(HandleBase* handle);
7195 template<typename DATATYPE>
7196 int AMPI_Iallreduce_global(MEDI_OPTIONAL_CONST typename DATATYPE::Type* sendbuf, typename DATATYPE::Type* recvbuf,
7197 int count, DATATYPE* datatype, AMPI_Op op, AMPI_Comm comm, AMPI_Request* request) {
7198 int rStatus;
7199 AMPI_Op convOp = datatype->getADTool().convertOperator(op);
7200 (void)convOp;
7201
7202 if(!datatype->getADTool().isActiveType()) {
7203 // call the regular function if the type is not active
7204 rStatus = MPI_Iallreduce(sendbuf, recvbuf, count, datatype->getMpiType(), convOp.primalFunction, comm,
7205 &request->request);
7206 } else {
7207
7208 // the type is an AD type so handle the buffers
7210 typename DATATYPE::ModifiedType* sendbufMod = nullptr;
7211 int sendbufElements = 0;
7212
7213 // compute the total size of the buffer
7214 if(AMPI_IN_PLACE != sendbuf) {
7215 sendbufElements = count;
7216 } else {
7217 sendbufElements = count;
7218 }
7219
7220 if(datatype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
7221 datatype->createModifiedTypeBuffer(sendbufMod, sendbufElements);
7222 } else {
7223 sendbufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(sendbuf));
7224 }
7225 typename DATATYPE::ModifiedType* recvbufMod = nullptr;
7226 int recvbufElements = 0;
7227
7228 // compute the total size of the buffer
7229 recvbufElements = count;
7230
7231 if(datatype->isModifiedBufferRequired() ) {
7232 datatype->createModifiedTypeBuffer(recvbufMod, recvbufElements);
7233 } else {
7234 recvbufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(recvbuf));
7235 }
7236
7237 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
7238 if(datatype->getADTool().isHandleRequired()) {
7240 }
7241 datatype->getADTool().startAssembly(h);
7242 if(datatype->isModifiedBufferRequired()) {
7243 if(AMPI_IN_PLACE != sendbuf) {
7244 datatype->copyIntoModifiedBuffer(sendbuf, 0, sendbufMod, 0, count);
7245 } else {
7246 datatype->copyIntoModifiedBuffer(recvbuf, 0, recvbufMod, 0, count);
7247 }
7248 }
7249
7250 if(nullptr != h) {
7251 // gather the information for the reverse sweep
7252
7253 // create the index buffers
7254 if(AMPI_IN_PLACE != sendbuf) {
7255 h->sendbufCount = datatype->computeActiveElements(count);
7256 } else {
7257 h->sendbufCount = datatype->computeActiveElements(count);
7258 }
7259 h->sendbufTotalSize = datatype->computeActiveElements(sendbufElements);
7260 datatype->getADTool().createIndexTypeBuffer(h->sendbufIndices, h->sendbufTotalSize);
7261 h->recvbufCount = datatype->computeActiveElements(count);
7262 h->recvbufTotalSize = datatype->computeActiveElements(recvbufElements);
7263 datatype->getADTool().createIndexTypeBuffer(h->recvbufIndices, h->recvbufTotalSize);
7264
7265 // extract the primal values for the operator if required
7266 if(convOp.requiresPrimal) {
7267 datatype->getADTool().createPrimalTypeBuffer(h->sendbufPrimals, h->sendbufTotalSize);
7268 if(AMPI_IN_PLACE != sendbuf) {
7269 datatype->getValues(sendbuf, 0, h->sendbufPrimals, 0, count);
7270 } else {
7271 datatype->getValues(recvbuf, 0, h->sendbufPrimals, 0, count);
7272 }
7273 }
7274
7275 // extract the old primal values from the recv buffer if the AD tool
7276 // needs the primal values reset
7277 if(datatype->getADTool().isOldPrimalsRequired()) {
7278 datatype->getADTool().createPrimalTypeBuffer(h->recvbufOldPrimals, h->recvbufTotalSize);
7279 datatype->getValues(recvbuf, 0, h->recvbufOldPrimals, 0, count);
7280 }
7281
7282
7283 if(AMPI_IN_PLACE != sendbuf) {
7284 datatype->getIndices(sendbuf, 0, h->sendbufIndices, 0, count);
7285 } else {
7286 datatype->getIndices(recvbuf, 0, h->sendbufIndices, 0, count);
7287 }
7288
7289 datatype->createIndices(recvbuf, 0, h->recvbufIndices, 0, count);
7290
7291 // pack all the variables in the handle
7292 h->funcReverse = AMPI_Iallreduce_global_b<DATATYPE>;
7293 h->funcForward = AMPI_Iallreduce_global_d_finish<DATATYPE>;
7294 h->funcPrimal = AMPI_Iallreduce_global_p_finish<DATATYPE>;
7295 h->count = count;
7296 h->datatype = datatype;
7297 h->op = op;
7298 h->comm = comm;
7299 }
7300
7301 if(!datatype->isModifiedBufferRequired()) {
7302 datatype->clearIndices(recvbuf, 0, count);
7303 }
7304
7305 rStatus = MPI_Iallreduce(sendbufMod, recvbufMod, count, datatype->getModifiedMpiType(), convOp.modifiedPrimalFunction,
7306 comm, &request->request);
7307
7309 asyncHandle->sendbuf = sendbuf;
7310 asyncHandle->sendbufMod = sendbufMod;
7311 asyncHandle->recvbuf = recvbuf;
7312 asyncHandle->recvbufMod = recvbufMod;
7313 asyncHandle->count = count;
7314 asyncHandle->datatype = datatype;
7315 asyncHandle->op = op;
7316 asyncHandle->comm = comm;
7317 asyncHandle->toolHandle = h;
7318 request->handle = asyncHandle;
7319 request->func = (ContinueFunction)AMPI_Iallreduce_global_finish<DATATYPE>;
7320
7321 // create adjoint wait
7322 if(nullptr != h) {
7323 WaitHandle* waitH = new WaitHandle((ReverseFunction)AMPI_Iallreduce_global_b_finish<DATATYPE>,
7324 (ForwardFunction)AMPI_Iallreduce_global_d<DATATYPE>, h);
7325 datatype->getADTool().addToolAction(waitH);
7326 }
7327 }
7328
7329 return rStatus;
7330 }
7331
7332 template<typename DATATYPE>
7334 int rStatus = 0;
7335
7337 (handle);
7338 MEDI_OPTIONAL_CONST typename DATATYPE::Type* sendbuf = asyncHandle->sendbuf;
7339 typename DATATYPE::ModifiedType* sendbufMod = asyncHandle->sendbufMod;
7340 typename DATATYPE::Type* recvbuf = asyncHandle->recvbuf;
7341 typename DATATYPE::ModifiedType* recvbufMod = asyncHandle->recvbufMod;
7342 int count = asyncHandle->count;
7343 DATATYPE* datatype = asyncHandle->datatype;
7344 AMPI_Op op = asyncHandle->op;
7345 AMPI_Comm comm = asyncHandle->comm;
7346 AMPI_Request* request = asyncHandle->request;
7348 (asyncHandle->toolHandle);
7349 MEDI_UNUSED(h); // Unused generated to ignore warnings
7350 MEDI_UNUSED(sendbuf); // Unused generated to ignore warnings
7351 MEDI_UNUSED(sendbufMod); // Unused generated to ignore warnings
7352 MEDI_UNUSED(recvbuf); // Unused generated to ignore warnings
7353 MEDI_UNUSED(recvbufMod); // Unused generated to ignore warnings
7354 MEDI_UNUSED(count); // Unused generated to ignore warnings
7355 MEDI_UNUSED(datatype); // Unused generated to ignore warnings
7356 MEDI_UNUSED(op); // Unused generated to ignore warnings
7357 MEDI_UNUSED(comm); // Unused generated to ignore warnings
7358 MEDI_UNUSED(request); // Unused generated to ignore warnings
7359
7360 delete asyncHandle;
7361
7362 if(datatype->getADTool().isActiveType()) {
7363
7364 AMPI_Op convOp = datatype->getADTool().convertOperator(op);
7365 (void)convOp;
7366 datatype->getADTool().addToolAction(h);
7367
7368 if(datatype->isModifiedBufferRequired()) {
7369 datatype->copyFromModifiedBuffer(recvbuf, 0, recvbufMod, 0, count);
7370 }
7371
7372 if(nullptr != h) {
7373 // handle the recv buffers
7374 datatype->registerValue(recvbuf, 0, h->recvbufIndices, h->recvbufOldPrimals, 0, count);
7375 }
7376 // extract the primal values for the operator if required
7377 if(nullptr != h && convOp.requiresPrimal) {
7378 datatype->getADTool().createPrimalTypeBuffer(h->recvbufPrimals, h->recvbufTotalSize);
7379 datatype->getValues(recvbuf, 0, h->recvbufPrimals, 0, count);
7380 }
7381
7382 datatype->getADTool().stopAssembly(h);
7383
7384 if(datatype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
7385 datatype->deleteModifiedTypeBuffer(sendbufMod);
7386 }
7387 if(datatype->isModifiedBufferRequired() ) {
7388 datatype->deleteModifiedTypeBuffer(recvbufMod);
7389 }
7390
7391 // handle is deleted by the AD tool
7392 }
7393
7394 return rStatus;
7395 }
7396
7397#endif
7398#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
7399 template<typename SENDTYPE, typename RECVTYPE>
7402 typename SENDTYPE::IndexType* sendbufIndices;
7403 typename SENDTYPE::PrimalType* sendbufPrimals;
7404 /* required for async */ void* sendbufAdjoints;
7408 SENDTYPE* sendtype;
7410 typename RECVTYPE::IndexType* recvbufIndices;
7411 typename RECVTYPE::PrimalType* recvbufPrimals;
7412 typename RECVTYPE::PrimalType* recvbufOldPrimals;
7413 /* required for async */ void* recvbufAdjoints;
7417 RECVTYPE* recvtype;
7419
7421 if(nullptr != sendbufIndices) {
7422 sendtype->getADTool().deleteIndexTypeBuffer(sendbufIndices);
7423 sendbufIndices = nullptr;
7424 }
7425 if(nullptr != sendbufPrimals) {
7426 sendtype->getADTool().deletePrimalTypeBuffer(sendbufPrimals);
7427 sendbufPrimals = nullptr;
7428 }
7429 if(nullptr != recvbufIndices) {
7430 recvtype->getADTool().deleteIndexTypeBuffer(recvbufIndices);
7431 recvbufIndices = nullptr;
7432 }
7433 if(nullptr != recvbufPrimals) {
7434 recvtype->getADTool().deletePrimalTypeBuffer(recvbufPrimals);
7435 recvbufPrimals = nullptr;
7436 }
7437 if(nullptr != recvbufOldPrimals) {
7438 recvtype->getADTool().deletePrimalTypeBuffer(recvbufOldPrimals);
7439 recvbufOldPrimals = nullptr;
7440 }
7441 }
7442 };
7443
7444 template<typename SENDTYPE, typename RECVTYPE>
7446 MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf;
7447 typename SENDTYPE::ModifiedType* sendbufMod;
7449 SENDTYPE* sendtype;
7450 typename RECVTYPE::Type* recvbuf;
7451 typename RECVTYPE::ModifiedType* recvbufMod;
7453 RECVTYPE* recvtype;
7456 };
7457
7458 template<typename SENDTYPE, typename RECVTYPE>
7459 void AMPI_Ialltoall_p(HandleBase* handle, AdjointInterface* adjointInterface) {
7461 (handle);
7462
7463 h->recvbufAdjoints = nullptr;
7464 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
7465 adjointInterface->createPrimalTypeBuffer((void*&)h->recvbufPrimals, h->recvbufTotalSize );
7466 h->sendbufAdjoints = nullptr;
7467 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
7468 adjointInterface->createPrimalTypeBuffer((void*&)h->sendbufPrimals, h->sendbufTotalSize );
7469 // Primal buffers are always linear in space so we can accesses them in one sweep
7470 adjointInterface->getPrimals(h->sendbufIndices, h->sendbufPrimals, h->sendbufTotalSize);
7471
7472
7473 AMPI_Ialltoall_pri<SENDTYPE, RECVTYPE>(h->sendbufPrimals, h->sendbufCountVec, h->sendcount, h->sendtype,
7475
7476 }
7477
7478 template<typename SENDTYPE, typename RECVTYPE>
7479 void AMPI_Ialltoall_p_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
7480
7482 (handle);
7483 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
7484
7485 adjointInterface->deletePrimalTypeBuffer((void*&)h->sendbufPrimals);
7486 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
7487 adjointInterface->getPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
7488 }
7489 // Primal buffers are always linear in space so we can accesses them in one sweep
7490 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufPrimals, h->recvbufTotalSize);
7491 adjointInterface->deletePrimalTypeBuffer((void*&)h->recvbufPrimals);
7492 }
7493
7494 template<typename SENDTYPE, typename RECVTYPE>
7495 void AMPI_Ialltoall_d(HandleBase* handle, AdjointInterface* adjointInterface) {
7497 (handle);
7498
7499 h->recvbufAdjoints = nullptr;
7500 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
7501 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
7502 h->sendbufAdjoints = nullptr;
7503 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
7504 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
7505 // Adjoint buffers are always linear in space so we can accesses them in one sweep
7506 adjointInterface->getAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
7507
7508
7509 AMPI_Ialltoall_fwd<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype,
7511
7512 }
7513
7514 template<typename SENDTYPE, typename RECVTYPE>
7515 void AMPI_Ialltoall_d_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
7516
7518 (handle);
7519 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
7520
7521 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
7522 // Adjoint buffers are always linear in space so we can accesses them in one sweep
7523 adjointInterface->updateAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
7524 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
7525 }
7526
7527 template<typename SENDTYPE, typename RECVTYPE>
7528 void AMPI_Ialltoall_b(HandleBase* handle, AdjointInterface* adjointInterface) {
7530 (handle);
7531
7532 h->recvbufAdjoints = nullptr;
7533 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
7534 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
7535 // Adjoint buffers are always linear in space so we can accesses them in one sweep
7536 adjointInterface->getAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
7537
7538 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
7539 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
7540 }
7541 h->sendbufAdjoints = nullptr;
7542 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
7543 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
7544
7545 AMPI_Ialltoall_adj<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype,
7547
7548 }
7549
7550 template<typename SENDTYPE, typename RECVTYPE>
7551 void AMPI_Ialltoall_b_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
7552
7554 (handle);
7555 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
7556
7557 // Adjoint buffers are always linear in space so we can accesses them in one sweep
7558 adjointInterface->updateAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
7559 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
7560 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
7561 }
7562
7563 template<typename SENDTYPE, typename RECVTYPE>
7564 int AMPI_Ialltoall_finish(HandleBase* handle);
7565 template<typename SENDTYPE, typename RECVTYPE>
7566 int AMPI_Ialltoall(MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf, int sendcount, SENDTYPE* sendtype,
7567 typename RECVTYPE::Type* recvbuf, int recvcount, RECVTYPE* recvtype, AMPI_Comm comm, AMPI_Request* request) {
7568 int rStatus;
7569
7570 if(!recvtype->getADTool().isActiveType()) {
7571 // call the regular function if the type is not active
7572 rStatus = MPI_Ialltoall(sendbuf, sendcount, sendtype->getMpiType(), recvbuf, recvcount, recvtype->getMpiType(), comm,
7573 &request->request);
7574 } else {
7575
7576 // the type is an AD type so handle the buffers
7578 typename SENDTYPE::ModifiedType* sendbufMod = nullptr;
7579 int sendbufElements = 0;
7580
7581 // compute the total size of the buffer
7582 if(AMPI_IN_PLACE != sendbuf) {
7583 sendbufElements = sendcount * getCommSize(comm);
7584 } else {
7585 sendbufElements = recvcount * getCommSize(comm);
7586 }
7587
7588 if(sendtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
7589 sendtype->createModifiedTypeBuffer(sendbufMod, sendbufElements);
7590 } else {
7591 sendbufMod = reinterpret_cast<typename SENDTYPE::ModifiedType*>(const_cast<typename SENDTYPE::Type*>(sendbuf));
7592 }
7593 typename RECVTYPE::ModifiedType* recvbufMod = nullptr;
7594 int recvbufElements = 0;
7595
7596 // compute the total size of the buffer
7597 recvbufElements = recvcount * getCommSize(comm);
7598
7599 if(recvtype->isModifiedBufferRequired() ) {
7600 recvtype->createModifiedTypeBuffer(recvbufMod, recvbufElements);
7601 } else {
7602 recvbufMod = reinterpret_cast<typename RECVTYPE::ModifiedType*>(const_cast<typename RECVTYPE::Type*>(recvbuf));
7603 }
7604
7605 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
7606 if(recvtype->getADTool().isHandleRequired()) {
7608 }
7609 recvtype->getADTool().startAssembly(h);
7610 if(sendtype->isModifiedBufferRequired()) {
7611 if(AMPI_IN_PLACE != sendbuf) {
7612 sendtype->copyIntoModifiedBuffer(sendbuf, 0, sendbufMod, 0, sendcount * getCommSize(comm));
7613 } else {
7614 recvtype->copyIntoModifiedBuffer(recvbuf, 0, recvbufMod, 0, recvcount * getCommSize(comm));
7615 }
7616 }
7617
7618 if(nullptr != h) {
7619 // gather the information for the reverse sweep
7620
7621 // create the index buffers
7622 if(AMPI_IN_PLACE != sendbuf) {
7623 h->sendbufCount = sendtype->computeActiveElements(sendcount);
7624 } else {
7625 h->sendbufCount = recvtype->computeActiveElements(recvcount);
7626 }
7627 h->sendbufTotalSize = sendtype->computeActiveElements(sendbufElements);
7628 recvtype->getADTool().createIndexTypeBuffer(h->sendbufIndices, h->sendbufTotalSize);
7629 h->recvbufCount = recvtype->computeActiveElements(recvcount);
7630 h->recvbufTotalSize = recvtype->computeActiveElements(recvbufElements);
7631 recvtype->getADTool().createIndexTypeBuffer(h->recvbufIndices, h->recvbufTotalSize);
7632
7633
7634 // extract the old primal values from the recv buffer if the AD tool
7635 // needs the primal values reset
7636 if(recvtype->getADTool().isOldPrimalsRequired()) {
7637 recvtype->getADTool().createPrimalTypeBuffer(h->recvbufOldPrimals, h->recvbufTotalSize);
7638 recvtype->getValues(recvbuf, 0, h->recvbufOldPrimals, 0, recvcount * getCommSize(comm));
7639 }
7640
7641
7642 if(AMPI_IN_PLACE != sendbuf) {
7643 sendtype->getIndices(sendbuf, 0, h->sendbufIndices, 0, sendcount * getCommSize(comm));
7644 } else {
7645 recvtype->getIndices(recvbuf, 0, h->sendbufIndices, 0, recvcount * getCommSize(comm));
7646 }
7647
7648 recvtype->createIndices(recvbuf, 0, h->recvbufIndices, 0, recvcount * getCommSize(comm));
7649
7650 // pack all the variables in the handle
7651 h->funcReverse = AMPI_Ialltoall_b<SENDTYPE, RECVTYPE>;
7652 h->funcForward = AMPI_Ialltoall_d_finish<SENDTYPE, RECVTYPE>;
7653 h->funcPrimal = AMPI_Ialltoall_p_finish<SENDTYPE, RECVTYPE>;
7654 h->sendcount = sendcount;
7655 h->sendtype = sendtype;
7656 h->recvcount = recvcount;
7657 h->recvtype = recvtype;
7658 h->comm = comm;
7659 }
7660
7661 if(!recvtype->isModifiedBufferRequired()) {
7662 recvtype->clearIndices(recvbuf, 0, recvcount * getCommSize(comm));
7663 }
7664
7665 rStatus = MPI_Ialltoall(sendbufMod, sendcount, sendtype->getModifiedMpiType(), recvbufMod, recvcount,
7666 recvtype->getModifiedMpiType(), comm, &request->request);
7667
7669 asyncHandle->sendbuf = sendbuf;
7670 asyncHandle->sendbufMod = sendbufMod;
7671 asyncHandle->sendcount = sendcount;
7672 asyncHandle->sendtype = sendtype;
7673 asyncHandle->recvbuf = recvbuf;
7674 asyncHandle->recvbufMod = recvbufMod;
7675 asyncHandle->recvcount = recvcount;
7676 asyncHandle->recvtype = recvtype;
7677 asyncHandle->comm = comm;
7678 asyncHandle->toolHandle = h;
7679 request->handle = asyncHandle;
7680 request->func = (ContinueFunction)AMPI_Ialltoall_finish<SENDTYPE, RECVTYPE>;
7681
7682 // create adjoint wait
7683 if(nullptr != h) {
7684 WaitHandle* waitH = new WaitHandle((ReverseFunction)AMPI_Ialltoall_b_finish<SENDTYPE, RECVTYPE>,
7685 (ForwardFunction)AMPI_Ialltoall_d<SENDTYPE, RECVTYPE>, h);
7686 recvtype->getADTool().addToolAction(waitH);
7687 }
7688 }
7689
7690 return rStatus;
7691 }
7692
7693 template<typename SENDTYPE, typename RECVTYPE>
7695 int rStatus = 0;
7696
7699 MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf = asyncHandle->sendbuf;
7700 typename SENDTYPE::ModifiedType* sendbufMod = asyncHandle->sendbufMod;
7701 int sendcount = asyncHandle->sendcount;
7702 SENDTYPE* sendtype = asyncHandle->sendtype;
7703 typename RECVTYPE::Type* recvbuf = asyncHandle->recvbuf;
7704 typename RECVTYPE::ModifiedType* recvbufMod = asyncHandle->recvbufMod;
7705 int recvcount = asyncHandle->recvcount;
7706 RECVTYPE* recvtype = asyncHandle->recvtype;
7707 AMPI_Comm comm = asyncHandle->comm;
7708 AMPI_Request* request = asyncHandle->request;
7710 (asyncHandle->toolHandle);
7711 MEDI_UNUSED(h); // Unused generated to ignore warnings
7712 MEDI_UNUSED(sendbuf); // Unused generated to ignore warnings
7713 MEDI_UNUSED(sendbufMod); // Unused generated to ignore warnings
7714 MEDI_UNUSED(sendcount); // Unused generated to ignore warnings
7715 MEDI_UNUSED(sendtype); // Unused generated to ignore warnings
7716 MEDI_UNUSED(recvbuf); // Unused generated to ignore warnings
7717 MEDI_UNUSED(recvbufMod); // Unused generated to ignore warnings
7718 MEDI_UNUSED(recvcount); // Unused generated to ignore warnings
7719 MEDI_UNUSED(recvtype); // Unused generated to ignore warnings
7720 MEDI_UNUSED(comm); // Unused generated to ignore warnings
7721 MEDI_UNUSED(request); // Unused generated to ignore warnings
7722
7723 delete asyncHandle;
7724
7725 if(recvtype->getADTool().isActiveType()) {
7726
7727 recvtype->getADTool().addToolAction(h);
7728
7729 if(recvtype->isModifiedBufferRequired()) {
7730 recvtype->copyFromModifiedBuffer(recvbuf, 0, recvbufMod, 0, recvcount * getCommSize(comm));
7731 }
7732
7733 if(nullptr != h) {
7734 // handle the recv buffers
7735 recvtype->registerValue(recvbuf, 0, h->recvbufIndices, h->recvbufOldPrimals, 0, recvcount * getCommSize(comm));
7736 }
7737
7738 recvtype->getADTool().stopAssembly(h);
7739
7740 if(sendtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
7741 sendtype->deleteModifiedTypeBuffer(sendbufMod);
7742 }
7743 if(recvtype->isModifiedBufferRequired() ) {
7744 recvtype->deleteModifiedTypeBuffer(recvbufMod);
7745 }
7746
7747 // handle is deleted by the AD tool
7748 }
7749
7750 return rStatus;
7751 }
7752
7753#endif
7754#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
7755 template<typename SENDTYPE, typename RECVTYPE>
7758 typename SENDTYPE::IndexType* sendbufIndices;
7759 typename SENDTYPE::PrimalType* sendbufPrimals;
7760 /* required for async */ void* sendbufAdjoints;
7762 /* required for async */ int* sendbufCountVec;
7763 /* required for async */ int* sendbufDisplsVec;
7764 const int* sendcounts;
7765 const int* sdispls;
7766 SENDTYPE* sendtype;
7768 typename RECVTYPE::IndexType* recvbufIndices;
7769 typename RECVTYPE::PrimalType* recvbufPrimals;
7770 typename RECVTYPE::PrimalType* recvbufOldPrimals;
7771 /* required for async */ void* recvbufAdjoints;
7773 /* required for async */ int* recvbufCountVec;
7774 /* required for async */ int* recvbufDisplsVec;
7775 const int* recvcounts;
7776 const int* rdispls;
7777 RECVTYPE* recvtype;
7779
7781 if(nullptr != sendbufIndices) {
7782 sendtype->getADTool().deleteIndexTypeBuffer(sendbufIndices);
7783 sendbufIndices = nullptr;
7784 }
7785 if(nullptr != sendbufPrimals) {
7786 sendtype->getADTool().deletePrimalTypeBuffer(sendbufPrimals);
7787 sendbufPrimals = nullptr;
7788 }
7789 if(nullptr != sendbufCount) {
7790 delete [] sendbufCount;
7791 sendbufCount = nullptr;
7792 }
7793 if(nullptr != recvbufIndices) {
7794 recvtype->getADTool().deleteIndexTypeBuffer(recvbufIndices);
7795 recvbufIndices = nullptr;
7796 }
7797 if(nullptr != recvbufPrimals) {
7798 recvtype->getADTool().deletePrimalTypeBuffer(recvbufPrimals);
7799 recvbufPrimals = nullptr;
7800 }
7801 if(nullptr != recvbufOldPrimals) {
7802 recvtype->getADTool().deletePrimalTypeBuffer(recvbufOldPrimals);
7803 recvbufOldPrimals = nullptr;
7804 }
7805 if(nullptr != recvbufCount) {
7806 delete [] recvbufCount;
7807 recvbufCount = nullptr;
7808 }
7809 }
7810 };
7811
7812 template<typename SENDTYPE, typename RECVTYPE>
7814 MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf;
7815 typename SENDTYPE::ModifiedType* sendbufMod;
7816 const int* sdisplsMod;
7817 const int* sendcounts;
7818 const int* sdispls;
7819 SENDTYPE* sendtype;
7820 typename RECVTYPE::Type* recvbuf;
7821 typename RECVTYPE::ModifiedType* recvbufMod;
7822 const int* rdisplsMod;
7823 const int* recvcounts;
7824 const int* rdispls;
7825 RECVTYPE* recvtype;
7828 };
7829
7830 template<typename SENDTYPE, typename RECVTYPE>
7831 void AMPI_Ialltoallv_p(HandleBase* handle, AdjointInterface* adjointInterface) {
7833 (handle);
7834
7835 h->recvbufAdjoints = nullptr;
7837 adjointInterface->getVectorSize());
7838 adjointInterface->createPrimalTypeBuffer((void*&)h->recvbufPrimals, h->recvbufTotalSize );
7839 h->sendbufAdjoints = nullptr;
7841 adjointInterface->getVectorSize());
7842 adjointInterface->createPrimalTypeBuffer((void*&)h->sendbufPrimals, h->sendbufTotalSize );
7843 // Primal buffers are always linear in space so we can accesses them in one sweep
7844 adjointInterface->getPrimals(h->sendbufIndices, h->sendbufPrimals, h->sendbufTotalSize);
7845
7846
7847 AMPI_Ialltoallv_pri<SENDTYPE, RECVTYPE>(h->sendbufPrimals, h->sendbufCountVec, h->sendbufDisplsVec, h->sendcounts,
7849 h->recvtype, h->comm, &h->requestReverse);
7850
7851 }
7852
7853 template<typename SENDTYPE, typename RECVTYPE>
7854 void AMPI_Ialltoallv_p_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
7855
7857 (handle);
7858 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
7859
7860 adjointInterface->deletePrimalTypeBuffer((void*&)h->sendbufPrimals);
7861 delete [] h->sendbufCountVec;
7862 delete [] h->sendbufDisplsVec;
7863 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
7864 adjointInterface->getPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
7865 }
7866 // Primal buffers are always linear in space so we can accesses them in one sweep
7867 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufPrimals, h->recvbufTotalSize);
7868 adjointInterface->deletePrimalTypeBuffer((void*&)h->recvbufPrimals);
7869 delete [] h->recvbufCountVec;
7870 delete [] h->recvbufDisplsVec;
7871 }
7872
7873 template<typename SENDTYPE, typename RECVTYPE>
7874 void AMPI_Ialltoallv_d(HandleBase* handle, AdjointInterface* adjointInterface) {
7876 (handle);
7877
7878 h->recvbufAdjoints = nullptr;
7880 adjointInterface->getVectorSize());
7881 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
7882 h->sendbufAdjoints = nullptr;
7884 adjointInterface->getVectorSize());
7885 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
7886 // Adjoint buffers are always linear in space so we can accesses them in one sweep
7887 adjointInterface->getAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
7888
7889
7890 AMPI_Ialltoallv_fwd<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendbufDisplsVec, h->sendcounts,
7892 h->recvtype, h->comm, &h->requestReverse);
7893
7894 }
7895
7896 template<typename SENDTYPE, typename RECVTYPE>
7897 void AMPI_Ialltoallv_d_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
7898
7900 (handle);
7901 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
7902
7903 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
7904 delete [] h->sendbufCountVec;
7905 delete [] h->sendbufDisplsVec;
7906 // Adjoint buffers are always linear in space so we can accesses them in one sweep
7907 adjointInterface->updateAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
7908 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
7909 delete [] h->recvbufCountVec;
7910 delete [] h->recvbufDisplsVec;
7911 }
7912
7913 template<typename SENDTYPE, typename RECVTYPE>
7914 void AMPI_Ialltoallv_b(HandleBase* handle, AdjointInterface* adjointInterface) {
7916 (handle);
7917
7918 h->recvbufAdjoints = nullptr;
7920 adjointInterface->getVectorSize());
7921 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
7922 // Adjoint buffers are always linear in space so we can accesses them in one sweep
7923 adjointInterface->getAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
7924
7925 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
7926 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
7927 }
7928 h->sendbufAdjoints = nullptr;
7930 adjointInterface->getVectorSize());
7931 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
7932
7933 AMPI_Ialltoallv_adj<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendbufDisplsVec, h->sendcounts,
7935 h->recvtype, h->comm, &h->requestReverse);
7936
7937 }
7938
7939 template<typename SENDTYPE, typename RECVTYPE>
7940 void AMPI_Ialltoallv_b_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
7941
7943 (handle);
7944 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
7945
7946 // Adjoint buffers are always linear in space so we can accesses them in one sweep
7947 adjointInterface->updateAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
7948 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
7949 delete [] h->sendbufCountVec;
7950 delete [] h->sendbufDisplsVec;
7951 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
7952 delete [] h->recvbufCountVec;
7953 delete [] h->recvbufDisplsVec;
7954 }
7955
7956 template<typename SENDTYPE, typename RECVTYPE>
7957 int AMPI_Ialltoallv_finish(HandleBase* handle);
7958 template<typename SENDTYPE, typename RECVTYPE>
7959 int AMPI_Ialltoallv(MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf, const int* sendcounts, const int* sdispls,
7960 SENDTYPE* sendtype, typename RECVTYPE::Type* recvbuf, const int* recvcounts, const int* rdispls, RECVTYPE* recvtype,
7961 AMPI_Comm comm, AMPI_Request* request) {
7962 int rStatus;
7963
7964 if(!recvtype->getADTool().isActiveType()) {
7965 // call the regular function if the type is not active
7966 rStatus = MPI_Ialltoallv(sendbuf, sendcounts, sdispls, sendtype->getMpiType(), recvbuf, recvcounts, rdispls,
7967 recvtype->getMpiType(), comm, &request->request);
7968 } else {
7969
7970 // the type is an AD type so handle the buffers
7972 MEDI_OPTIONAL_CONST int* sdisplsMod = sdispls;
7973 int sdisplsTotalSize = 0;
7974 if(nullptr != sdispls) {
7975 sdisplsTotalSize = computeDisplacementsTotalSize(sendcounts, getCommSize(comm));
7976 if(recvtype->isModifiedBufferRequired()) {
7977 sdisplsMod = createLinearDisplacements(sendcounts, getCommSize(comm));
7978 }
7979 }
7980 MEDI_OPTIONAL_CONST int* rdisplsMod = rdispls;
7981 int rdisplsTotalSize = 0;
7982 if(nullptr != rdispls) {
7983 rdisplsTotalSize = computeDisplacementsTotalSize(recvcounts, getCommSize(comm));
7984 if(recvtype->isModifiedBufferRequired()) {
7985 rdisplsMod = createLinearDisplacements(recvcounts, getCommSize(comm));
7986 }
7987 }
7988 typename SENDTYPE::ModifiedType* sendbufMod = nullptr;
7989 int sendbufElements = 0;
7990
7991 // compute the total size of the buffer
7992 if(AMPI_IN_PLACE != sendbuf) {
7993 sendbufElements = sdisplsTotalSize;
7994 } else {
7995 sendbufElements = rdisplsTotalSize;
7996 }
7997
7998 if(sendtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
7999 sendtype->createModifiedTypeBuffer(sendbufMod, sendbufElements);
8000 } else {
8001 sendbufMod = reinterpret_cast<typename SENDTYPE::ModifiedType*>(const_cast<typename SENDTYPE::Type*>(sendbuf));
8002 }
8003 typename RECVTYPE::ModifiedType* recvbufMod = nullptr;
8004 int recvbufElements = 0;
8005
8006 // compute the total size of the buffer
8007 recvbufElements = rdisplsTotalSize;
8008
8009 if(recvtype->isModifiedBufferRequired() ) {
8010 recvtype->createModifiedTypeBuffer(recvbufMod, recvbufElements);
8011 } else {
8012 recvbufMod = reinterpret_cast<typename RECVTYPE::ModifiedType*>(const_cast<typename RECVTYPE::Type*>(recvbuf));
8013 }
8014
8015 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
8016 if(recvtype->getADTool().isHandleRequired()) {
8018 }
8019 recvtype->getADTool().startAssembly(h);
8020 if(sendtype->isModifiedBufferRequired()) {
8021 if(AMPI_IN_PLACE != sendbuf) {
8022 for(int i = 0; i < getCommSize(comm); ++i) {
8023 sendtype->copyIntoModifiedBuffer(sendbuf, sdispls[i], sendbufMod, sdisplsMod[i], sendcounts[i]);
8024 }
8025 } else {
8026 for(int i = 0; i < getCommSize(comm); ++i) {
8027 recvtype->copyIntoModifiedBuffer(recvbuf, rdispls[i], recvbufMod, rdisplsMod[i], recvcounts[i]);
8028 }
8029 }
8030 }
8031
8032 if(nullptr != h) {
8033 // gather the information for the reverse sweep
8034
8035 // create the index buffers
8036 if(AMPI_IN_PLACE != sendbuf) {
8037 createLinearIndexCounts(h->sendbufCount, sendcounts, sdispls, getCommSize(comm), sendtype);
8038 } else {
8039 createLinearIndexCounts(h->sendbufCount, recvcounts, rdispls, getCommSize(comm), recvtype);
8040 }
8041 h->sendbufTotalSize = sendtype->computeActiveElements(sendbufElements);
8042 recvtype->getADTool().createIndexTypeBuffer(h->sendbufIndices, h->sendbufTotalSize);
8043 createLinearIndexCounts(h->recvbufCount, recvcounts, rdispls, getCommSize(comm), recvtype);
8044 h->recvbufTotalSize = recvtype->computeActiveElements(recvbufElements);
8045 recvtype->getADTool().createIndexTypeBuffer(h->recvbufIndices, h->recvbufTotalSize);
8046
8047
8048 // extract the old primal values from the recv buffer if the AD tool
8049 // needs the primal values reset
8050 if(recvtype->getADTool().isOldPrimalsRequired()) {
8051 recvtype->getADTool().createPrimalTypeBuffer(h->recvbufOldPrimals, h->recvbufTotalSize);
8052 for(int i = 0; i < getCommSize(comm); ++i) {
8053 recvtype->getValues(recvbuf, rdispls[i], h->recvbufOldPrimals, rdisplsMod[i], recvcounts[i]);
8054 }
8055 }
8056
8057
8058 if(AMPI_IN_PLACE != sendbuf) {
8059 for(int i = 0; i < getCommSize(comm); ++i) {
8060 sendtype->getIndices(sendbuf, sdispls[i], h->sendbufIndices, sdisplsMod[i], sendcounts[i]);
8061 }
8062 } else {
8063 for(int i = 0; i < getCommSize(comm); ++i) {
8064 recvtype->getIndices(recvbuf, rdispls[i], h->sendbufIndices, rdisplsMod[i], recvcounts[i]);
8065 }
8066 }
8067
8068 for(int i = 0; i < getCommSize(comm); ++i) {
8069 recvtype->createIndices(recvbuf, rdispls[i], h->recvbufIndices, rdisplsMod[i], recvcounts[i]);
8070 }
8071
8072 // pack all the variables in the handle
8073 h->funcReverse = AMPI_Ialltoallv_b<SENDTYPE, RECVTYPE>;
8074 h->funcForward = AMPI_Ialltoallv_d_finish<SENDTYPE, RECVTYPE>;
8075 h->funcPrimal = AMPI_Ialltoallv_p_finish<SENDTYPE, RECVTYPE>;
8076 h->sendcounts = sendcounts;
8077 h->sdispls = sdispls;
8078 h->sendtype = sendtype;
8079 h->recvcounts = recvcounts;
8080 h->rdispls = rdispls;
8081 h->recvtype = recvtype;
8082 h->comm = comm;
8083 }
8084
8085 if(!recvtype->isModifiedBufferRequired()) {
8086 for(int i = 0; i < getCommSize(comm); ++i) {
8087 recvtype->clearIndices(recvbuf, rdispls[i], recvcounts[i]);
8088 }
8089 }
8090
8091 rStatus = MPI_Ialltoallv(sendbufMod, sendcounts, sdisplsMod, sendtype->getModifiedMpiType(), recvbufMod, recvcounts,
8092 rdisplsMod, recvtype->getModifiedMpiType(), comm, &request->request);
8093
8095 asyncHandle->sendbuf = sendbuf;
8096 asyncHandle->sendbufMod = sendbufMod;
8097 asyncHandle->sdisplsMod = sdisplsMod;
8098 asyncHandle->sendcounts = sendcounts;
8099 asyncHandle->sdispls = sdispls;
8100 asyncHandle->sendtype = sendtype;
8101 asyncHandle->recvbuf = recvbuf;
8102 asyncHandle->recvbufMod = recvbufMod;
8103 asyncHandle->rdisplsMod = rdisplsMod;
8104 asyncHandle->recvcounts = recvcounts;
8105 asyncHandle->rdispls = rdispls;
8106 asyncHandle->recvtype = recvtype;
8107 asyncHandle->comm = comm;
8108 asyncHandle->toolHandle = h;
8109 request->handle = asyncHandle;
8110 request->func = (ContinueFunction)AMPI_Ialltoallv_finish<SENDTYPE, RECVTYPE>;
8111
8112 // create adjoint wait
8113 if(nullptr != h) {
8114 WaitHandle* waitH = new WaitHandle((ReverseFunction)AMPI_Ialltoallv_b_finish<SENDTYPE, RECVTYPE>,
8115 (ForwardFunction)AMPI_Ialltoallv_d<SENDTYPE, RECVTYPE>, h);
8116 recvtype->getADTool().addToolAction(waitH);
8117 }
8118 }
8119
8120 return rStatus;
8121 }
8122
8123 template<typename SENDTYPE, typename RECVTYPE>
8125 int rStatus = 0;
8126
8129 MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf = asyncHandle->sendbuf;
8130 typename SENDTYPE::ModifiedType* sendbufMod = asyncHandle->sendbufMod;
8131 const int* sdisplsMod = asyncHandle->sdisplsMod;
8132 const int* sendcounts = asyncHandle->sendcounts;
8133 const int* sdispls = asyncHandle->sdispls;
8134 SENDTYPE* sendtype = asyncHandle->sendtype;
8135 typename RECVTYPE::Type* recvbuf = asyncHandle->recvbuf;
8136 typename RECVTYPE::ModifiedType* recvbufMod = asyncHandle->recvbufMod;
8137 const int* rdisplsMod = asyncHandle->rdisplsMod;
8138 const int* recvcounts = asyncHandle->recvcounts;
8139 const int* rdispls = asyncHandle->rdispls;
8140 RECVTYPE* recvtype = asyncHandle->recvtype;
8141 AMPI_Comm comm = asyncHandle->comm;
8142 AMPI_Request* request = asyncHandle->request;
8144 (asyncHandle->toolHandle);
8145 MEDI_UNUSED(h); // Unused generated to ignore warnings
8146 MEDI_UNUSED(sendbuf); // Unused generated to ignore warnings
8147 MEDI_UNUSED(sendbufMod); // Unused generated to ignore warnings
8148 MEDI_UNUSED(sdisplsMod); // Unused generated to ignore warnings
8149 MEDI_UNUSED(sendcounts); // Unused generated to ignore warnings
8150 MEDI_UNUSED(sdispls); // Unused generated to ignore warnings
8151 MEDI_UNUSED(sendtype); // Unused generated to ignore warnings
8152 MEDI_UNUSED(recvbuf); // Unused generated to ignore warnings
8153 MEDI_UNUSED(recvbufMod); // Unused generated to ignore warnings
8154 MEDI_UNUSED(rdisplsMod); // Unused generated to ignore warnings
8155 MEDI_UNUSED(recvcounts); // Unused generated to ignore warnings
8156 MEDI_UNUSED(rdispls); // Unused generated to ignore warnings
8157 MEDI_UNUSED(recvtype); // Unused generated to ignore warnings
8158 MEDI_UNUSED(comm); // Unused generated to ignore warnings
8159 MEDI_UNUSED(request); // Unused generated to ignore warnings
8160
8161 delete asyncHandle;
8162
8163 if(recvtype->getADTool().isActiveType()) {
8164
8165 recvtype->getADTool().addToolAction(h);
8166
8167 if(recvtype->isModifiedBufferRequired()) {
8168 for(int i = 0; i < getCommSize(comm); ++i) {
8169 recvtype->copyFromModifiedBuffer(recvbuf, rdispls[i], recvbufMod, rdisplsMod[i], recvcounts[i]);
8170 }
8171 }
8172
8173 if(nullptr != h) {
8174 // handle the recv buffers
8175 for(int i = 0; i < getCommSize(comm); ++i) {
8176 recvtype->registerValue(recvbuf, rdispls[i], h->recvbufIndices, h->recvbufOldPrimals, rdisplsMod[i], recvcounts[i]);
8177 }
8178 }
8179
8180 recvtype->getADTool().stopAssembly(h);
8181 if(recvtype->isModifiedBufferRequired()) {
8182 delete [] sdisplsMod;
8183 }
8184 if(recvtype->isModifiedBufferRequired()) {
8185 delete [] rdisplsMod;
8186 }
8187
8188 if(sendtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
8189 sendtype->deleteModifiedTypeBuffer(sendbufMod);
8190 }
8191 if(recvtype->isModifiedBufferRequired() ) {
8192 recvtype->deleteModifiedTypeBuffer(recvbufMod);
8193 }
8194
8195 // handle is deleted by the AD tool
8196 }
8197
8198 return rStatus;
8199 }
8200
8201#endif
8202#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
8203 template<typename DATATYPE>
8206 typename DATATYPE::IndexType* bufferSendIndices;
8207 typename DATATYPE::PrimalType* bufferSendPrimals;
8208 /* required for async */ void* bufferSendAdjoints;
8212 typename DATATYPE::IndexType* bufferRecvIndices;
8213 typename DATATYPE::PrimalType* bufferRecvPrimals;
8214 typename DATATYPE::PrimalType* bufferRecvOldPrimals;
8215 /* required for async */ void* bufferRecvAdjoints;
8219 DATATYPE* datatype;
8220 int root;
8222
8224 if(nullptr != bufferSendIndices) {
8225 datatype->getADTool().deleteIndexTypeBuffer(bufferSendIndices);
8226 bufferSendIndices = nullptr;
8227 }
8228 if(nullptr != bufferSendPrimals) {
8229 datatype->getADTool().deletePrimalTypeBuffer(bufferSendPrimals);
8230 bufferSendPrimals = nullptr;
8231 }
8232 if(nullptr != bufferRecvIndices) {
8233 datatype->getADTool().deleteIndexTypeBuffer(bufferRecvIndices);
8234 bufferRecvIndices = nullptr;
8235 }
8236 if(nullptr != bufferRecvPrimals) {
8237 datatype->getADTool().deletePrimalTypeBuffer(bufferRecvPrimals);
8238 bufferRecvPrimals = nullptr;
8239 }
8240 if(nullptr != bufferRecvOldPrimals) {
8241 datatype->getADTool().deletePrimalTypeBuffer(bufferRecvOldPrimals);
8242 bufferRecvOldPrimals = nullptr;
8243 }
8244 }
8245 };
8246
8247 template<typename DATATYPE>
8249 typename DATATYPE::Type* bufferSend;
8250 typename DATATYPE::ModifiedType* bufferSendMod;
8251 typename DATATYPE::Type* bufferRecv;
8252 typename DATATYPE::ModifiedType* bufferRecvMod;
8254 DATATYPE* datatype;
8255 int root;
8258 };
8259
8260 template<typename DATATYPE>
8261 void AMPI_Ibcast_wrap_p(HandleBase* handle, AdjointInterface* adjointInterface) {
8263
8264 h->bufferRecvAdjoints = nullptr;
8265 h->bufferRecvCountVec = adjointInterface->getVectorSize() * h->bufferRecvCount;
8266 adjointInterface->createPrimalTypeBuffer((void*&)h->bufferRecvPrimals, h->bufferRecvTotalSize );
8267 h->bufferSendAdjoints = nullptr;
8268 if(h->root == getCommRank(h->comm)) {
8269 h->bufferSendCountVec = adjointInterface->getVectorSize() * h->bufferSendCount;
8270 adjointInterface->createPrimalTypeBuffer((void*&)h->bufferSendPrimals, h->bufferSendTotalSize );
8271 // Primal buffers are always linear in space so we can accesses them in one sweep
8273
8274 }
8275
8276 AMPI_Ibcast_wrap_pri<DATATYPE>(h->bufferSendPrimals, h->bufferSendCountVec, h->bufferRecvPrimals, h->bufferRecvCountVec,
8277 h->count, h->datatype, h->root, h->comm, &h->requestReverse);
8278
8279 }
8280
8281 template<typename DATATYPE>
8282 void AMPI_Ibcast_wrap_p_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
8283
8285 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
8286
8287 if(h->root == getCommRank(h->comm)) {
8288 adjointInterface->deletePrimalTypeBuffer((void*&)h->bufferSendPrimals);
8289 }
8290 if(h->datatype->getADTool().isOldPrimalsRequired()) {
8292 }
8293 // Primal buffers are always linear in space so we can accesses them in one sweep
8295 adjointInterface->deletePrimalTypeBuffer((void*&)h->bufferRecvPrimals);
8296 }
8297
8298 template<typename DATATYPE>
8299 void AMPI_Ibcast_wrap_d(HandleBase* handle, AdjointInterface* adjointInterface) {
8301
8302 h->bufferRecvAdjoints = nullptr;
8303 h->bufferRecvCountVec = adjointInterface->getVectorSize() * h->bufferRecvCount;
8305 h->bufferSendAdjoints = nullptr;
8306 if(h->root == getCommRank(h->comm)) {
8307 h->bufferSendCountVec = adjointInterface->getVectorSize() * h->bufferSendCount;
8309 // Adjoint buffers are always linear in space so we can accesses them in one sweep
8311
8312 }
8313
8314 AMPI_Ibcast_wrap_fwd<DATATYPE>(h->bufferSendAdjoints, h->bufferSendCountVec, h->bufferRecvAdjoints,
8315 h->bufferRecvCountVec, h->count, h->datatype, h->root, h->comm, &h->requestReverse);
8316
8317 }
8318
8319 template<typename DATATYPE>
8320 void AMPI_Ibcast_wrap_d_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
8321
8323 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
8324
8325 if(h->root == getCommRank(h->comm)) {
8326 adjointInterface->deleteAdjointTypeBuffer(h->bufferSendAdjoints);
8327 }
8328 // Adjoint buffers are always linear in space so we can accesses them in one sweep
8330 adjointInterface->deleteAdjointTypeBuffer(h->bufferRecvAdjoints);
8331 }
8332
8333 template<typename DATATYPE>
8334 void AMPI_Ibcast_wrap_b(HandleBase* handle, AdjointInterface* adjointInterface) {
8336
8337 h->bufferRecvAdjoints = nullptr;
8338 h->bufferRecvCountVec = adjointInterface->getVectorSize() * h->bufferRecvCount;
8340 // Adjoint buffers are always linear in space so we can accesses them in one sweep
8342
8343 if(h->datatype->getADTool().isOldPrimalsRequired()) {
8345 }
8346 h->bufferSendAdjoints = nullptr;
8347 if(h->root == getCommRank(h->comm)) {
8348 h->bufferSendCountVec = adjointInterface->getVectorSize() * h->bufferSendCount;
8350 }
8351
8352 AMPI_Ibcast_wrap_adj<DATATYPE>(h->bufferSendAdjoints, h->bufferSendCountVec, h->bufferRecvAdjoints,
8353 h->bufferRecvCountVec, h->count, h->datatype, h->root, h->comm, &h->requestReverse);
8354
8355 }
8356
8357 template<typename DATATYPE>
8358 void AMPI_Ibcast_wrap_b_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
8359
8361 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
8362
8363 if(h->root == getCommRank(h->comm)) {
8365 // Adjoint buffers are always linear in space so we can accesses them in one sweep
8367 adjointInterface->deleteAdjointTypeBuffer(h->bufferSendAdjoints);
8368 }
8369 adjointInterface->deleteAdjointTypeBuffer(h->bufferRecvAdjoints);
8370 }
8371
8372 template<typename DATATYPE>
8373 int AMPI_Ibcast_wrap_finish(HandleBase* handle);
8374 template<typename DATATYPE>
8375 int AMPI_Ibcast_wrap(typename DATATYPE::Type* bufferSend, typename DATATYPE::Type* bufferRecv, int count,
8376 DATATYPE* datatype, int root, AMPI_Comm comm, AMPI_Request* request) {
8377 int rStatus;
8378
8379 if(!datatype->getADTool().isActiveType()) {
8380 // call the regular function if the type is not active
8381 rStatus = MPI_Ibcast_wrap(bufferSend, bufferRecv, count, datatype->getMpiType(), root, comm, &request->request);
8382 } else {
8383
8384 // the type is an AD type so handle the buffers
8386 typename DATATYPE::ModifiedType* bufferSendMod = nullptr;
8387 int bufferSendElements = 0;
8388
8389 if(root == getCommRank(comm)) {
8390 // compute the total size of the buffer
8391 if(AMPI_IN_PLACE != bufferSend) {
8392 bufferSendElements = count;
8393 } else {
8394 bufferSendElements = count;
8395 }
8396
8397 if(datatype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == bufferSend)) {
8398 datatype->createModifiedTypeBuffer(bufferSendMod, bufferSendElements);
8399 } else {
8400 bufferSendMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(bufferSend));
8401 }
8402 }
8403 typename DATATYPE::ModifiedType* bufferRecvMod = nullptr;
8404 int bufferRecvElements = 0;
8405
8406 // compute the total size of the buffer
8407 bufferRecvElements = count;
8408
8409 if(datatype->isModifiedBufferRequired() ) {
8410 datatype->createModifiedTypeBuffer(bufferRecvMod, bufferRecvElements);
8411 } else {
8412 bufferRecvMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(bufferRecv));
8413 }
8414
8415 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
8416 if(datatype->getADTool().isHandleRequired()) {
8418 }
8419 datatype->getADTool().startAssembly(h);
8420 if(root == getCommRank(comm)) {
8421 if(datatype->isModifiedBufferRequired()) {
8422 if(AMPI_IN_PLACE != bufferSend) {
8423 datatype->copyIntoModifiedBuffer(bufferSend, 0, bufferSendMod, 0, count);
8424 } else {
8425 datatype->copyIntoModifiedBuffer(bufferRecv, 0, bufferRecvMod, 0, count);
8426 }
8427 }
8428 }
8429
8430 if(nullptr != h) {
8431 // gather the information for the reverse sweep
8432
8433 // create the index buffers
8434 if(root == getCommRank(comm)) {
8435 if(AMPI_IN_PLACE != bufferSend) {
8436 h->bufferSendCount = datatype->computeActiveElements(count);
8437 } else {
8438 h->bufferSendCount = datatype->computeActiveElements(count);
8439 }
8440 h->bufferSendTotalSize = datatype->computeActiveElements(bufferSendElements);
8441 datatype->getADTool().createIndexTypeBuffer(h->bufferSendIndices, h->bufferSendTotalSize);
8442 }
8443 h->bufferRecvCount = datatype->computeActiveElements(count);
8444 h->bufferRecvTotalSize = datatype->computeActiveElements(bufferRecvElements);
8445 datatype->getADTool().createIndexTypeBuffer(h->bufferRecvIndices, h->bufferRecvTotalSize);
8446
8447
8448 // extract the old primal values from the recv buffer if the AD tool
8449 // needs the primal values reset
8450 if(datatype->getADTool().isOldPrimalsRequired()) {
8451 datatype->getADTool().createPrimalTypeBuffer(h->bufferRecvOldPrimals, h->bufferRecvTotalSize);
8452 datatype->getValues(bufferRecv, 0, h->bufferRecvOldPrimals, 0, count);
8453 }
8454
8455
8456 if(root == getCommRank(comm)) {
8457 if(AMPI_IN_PLACE != bufferSend) {
8458 datatype->getIndices(bufferSend, 0, h->bufferSendIndices, 0, count);
8459 } else {
8460 datatype->getIndices(bufferRecv, 0, h->bufferSendIndices, 0, count);
8461 }
8462 }
8463
8464 datatype->createIndices(bufferRecv, 0, h->bufferRecvIndices, 0, count);
8465
8466 // pack all the variables in the handle
8467 h->funcReverse = AMPI_Ibcast_wrap_b<DATATYPE>;
8468 h->funcForward = AMPI_Ibcast_wrap_d_finish<DATATYPE>;
8469 h->funcPrimal = AMPI_Ibcast_wrap_p_finish<DATATYPE>;
8470 h->count = count;
8471 h->datatype = datatype;
8472 h->root = root;
8473 h->comm = comm;
8474 }
8475
8476 if(!datatype->isModifiedBufferRequired()) {
8477 datatype->clearIndices(bufferRecv, 0, count);
8478 }
8479
8480 rStatus = MPI_Ibcast_wrap(bufferSendMod, bufferRecvMod, count, datatype->getModifiedMpiType(), root, comm,
8481 &request->request);
8482
8484 asyncHandle->bufferSend = bufferSend;
8485 asyncHandle->bufferSendMod = bufferSendMod;
8486 asyncHandle->bufferRecv = bufferRecv;
8487 asyncHandle->bufferRecvMod = bufferRecvMod;
8488 asyncHandle->count = count;
8489 asyncHandle->datatype = datatype;
8490 asyncHandle->root = root;
8491 asyncHandle->comm = comm;
8492 asyncHandle->toolHandle = h;
8493 request->handle = asyncHandle;
8494 request->func = (ContinueFunction)AMPI_Ibcast_wrap_finish<DATATYPE>;
8495
8496 // create adjoint wait
8497 if(nullptr != h) {
8498 WaitHandle* waitH = new WaitHandle((ReverseFunction)AMPI_Ibcast_wrap_b_finish<DATATYPE>,
8499 (ForwardFunction)AMPI_Ibcast_wrap_d<DATATYPE>, h);
8500 datatype->getADTool().addToolAction(waitH);
8501 }
8502 }
8503
8504 return rStatus;
8505 }
8506
8507 template<typename DATATYPE>
8509 int rStatus = 0;
8510
8512 typename DATATYPE::Type* bufferSend = asyncHandle->bufferSend;
8513 typename DATATYPE::ModifiedType* bufferSendMod = asyncHandle->bufferSendMod;
8514 typename DATATYPE::Type* bufferRecv = asyncHandle->bufferRecv;
8515 typename DATATYPE::ModifiedType* bufferRecvMod = asyncHandle->bufferRecvMod;
8516 int count = asyncHandle->count;
8517 DATATYPE* datatype = asyncHandle->datatype;
8518 int root = asyncHandle->root;
8519 AMPI_Comm comm = asyncHandle->comm;
8520 AMPI_Request* request = asyncHandle->request;
8522 (asyncHandle->toolHandle);
8523 MEDI_UNUSED(h); // Unused generated to ignore warnings
8524 MEDI_UNUSED(bufferSend); // Unused generated to ignore warnings
8525 MEDI_UNUSED(bufferSendMod); // Unused generated to ignore warnings
8526 MEDI_UNUSED(bufferRecv); // Unused generated to ignore warnings
8527 MEDI_UNUSED(bufferRecvMod); // Unused generated to ignore warnings
8528 MEDI_UNUSED(count); // Unused generated to ignore warnings
8529 MEDI_UNUSED(datatype); // Unused generated to ignore warnings
8530 MEDI_UNUSED(root); // Unused generated to ignore warnings
8531 MEDI_UNUSED(comm); // Unused generated to ignore warnings
8532 MEDI_UNUSED(request); // Unused generated to ignore warnings
8533
8534 delete asyncHandle;
8535
8536 if(datatype->getADTool().isActiveType()) {
8537
8538 datatype->getADTool().addToolAction(h);
8539
8540 if(datatype->isModifiedBufferRequired()) {
8541 datatype->copyFromModifiedBuffer(bufferRecv, 0, bufferRecvMod, 0, count);
8542 }
8543
8544 if(nullptr != h) {
8545 // handle the recv buffers
8546 datatype->registerValue(bufferRecv, 0, h->bufferRecvIndices, h->bufferRecvOldPrimals, 0, count);
8547 }
8548
8549 datatype->getADTool().stopAssembly(h);
8550
8551 if(root == getCommRank(comm)) {
8552 if(datatype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == bufferSend)) {
8553 datatype->deleteModifiedTypeBuffer(bufferSendMod);
8554 }
8555 }
8556 if(datatype->isModifiedBufferRequired() ) {
8557 datatype->deleteModifiedTypeBuffer(bufferRecvMod);
8558 }
8559
8560 // handle is deleted by the AD tool
8561 }
8562
8563 return rStatus;
8564 }
8565
8566#endif
8567#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
8568 template<typename SENDTYPE, typename RECVTYPE>
8571 typename SENDTYPE::IndexType* sendbufIndices;
8572 typename SENDTYPE::PrimalType* sendbufPrimals;
8573 /* required for async */ void* sendbufAdjoints;
8577 SENDTYPE* sendtype;
8579 typename RECVTYPE::IndexType* recvbufIndices;
8580 typename RECVTYPE::PrimalType* recvbufPrimals;
8581 typename RECVTYPE::PrimalType* recvbufOldPrimals;
8582 /* required for async */ void* recvbufAdjoints;
8586 RECVTYPE* recvtype;
8587 int root;
8589
8591 if(nullptr != sendbufIndices) {
8592 sendtype->getADTool().deleteIndexTypeBuffer(sendbufIndices);
8593 sendbufIndices = nullptr;
8594 }
8595 if(nullptr != sendbufPrimals) {
8596 sendtype->getADTool().deletePrimalTypeBuffer(sendbufPrimals);
8597 sendbufPrimals = nullptr;
8598 }
8599 if(nullptr != recvbufIndices) {
8600 recvtype->getADTool().deleteIndexTypeBuffer(recvbufIndices);
8601 recvbufIndices = nullptr;
8602 }
8603 if(nullptr != recvbufPrimals) {
8604 recvtype->getADTool().deletePrimalTypeBuffer(recvbufPrimals);
8605 recvbufPrimals = nullptr;
8606 }
8607 if(nullptr != recvbufOldPrimals) {
8608 recvtype->getADTool().deletePrimalTypeBuffer(recvbufOldPrimals);
8609 recvbufOldPrimals = nullptr;
8610 }
8611 }
8612 };
8613
8614 template<typename SENDTYPE, typename RECVTYPE>
8616 MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf;
8617 typename SENDTYPE::ModifiedType* sendbufMod;
8619 SENDTYPE* sendtype;
8620 typename RECVTYPE::Type* recvbuf;
8621 typename RECVTYPE::ModifiedType* recvbufMod;
8623 RECVTYPE* recvtype;
8624 int root;
8627 };
8628
8629 template<typename SENDTYPE, typename RECVTYPE>
8630 void AMPI_Igather_p(HandleBase* handle, AdjointInterface* adjointInterface) {
8632 (handle);
8633
8634 h->recvbufAdjoints = nullptr;
8635 if(h->root == getCommRank(h->comm)) {
8636 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
8637 adjointInterface->createPrimalTypeBuffer((void*&)h->recvbufPrimals, h->recvbufTotalSize );
8638 }
8639 h->sendbufAdjoints = nullptr;
8640 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
8641 adjointInterface->createPrimalTypeBuffer((void*&)h->sendbufPrimals, h->sendbufTotalSize );
8642 // Primal buffers are always linear in space so we can accesses them in one sweep
8643 adjointInterface->getPrimals(h->sendbufIndices, h->sendbufPrimals, h->sendbufTotalSize);
8644
8645
8646 AMPI_Igather_pri<SENDTYPE, RECVTYPE>(h->sendbufPrimals, h->sendbufCountVec, h->sendcount, h->sendtype,
8648
8649 }
8650
8651 template<typename SENDTYPE, typename RECVTYPE>
8652 void AMPI_Igather_p_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
8653
8655 (handle);
8656 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
8657
8658 adjointInterface->deletePrimalTypeBuffer((void*&)h->sendbufPrimals);
8659 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
8660 if(h->root == getCommRank(h->comm)) {
8661 adjointInterface->getPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
8662 }
8663 }
8664 if(h->root == getCommRank(h->comm)) {
8665 // Primal buffers are always linear in space so we can accesses them in one sweep
8666 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufPrimals, h->recvbufTotalSize);
8667 adjointInterface->deletePrimalTypeBuffer((void*&)h->recvbufPrimals);
8668 }
8669 }
8670
8671 template<typename SENDTYPE, typename RECVTYPE>
8672 void AMPI_Igather_d(HandleBase* handle, AdjointInterface* adjointInterface) {
8674 (handle);
8675
8676 h->recvbufAdjoints = nullptr;
8677 if(h->root == getCommRank(h->comm)) {
8678 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
8679 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
8680 }
8681 h->sendbufAdjoints = nullptr;
8682 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
8683 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
8684 // Adjoint buffers are always linear in space so we can accesses them in one sweep
8685 adjointInterface->getAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
8686
8687
8688 AMPI_Igather_fwd<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype,
8690
8691 }
8692
8693 template<typename SENDTYPE, typename RECVTYPE>
8694 void AMPI_Igather_d_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
8695
8697 (handle);
8698 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
8699
8700 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
8701 if(h->root == getCommRank(h->comm)) {
8702 // Adjoint buffers are always linear in space so we can accesses them in one sweep
8703 adjointInterface->updateAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
8704 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
8705 }
8706 }
8707
8708 template<typename SENDTYPE, typename RECVTYPE>
8709 void AMPI_Igather_b(HandleBase* handle, AdjointInterface* adjointInterface) {
8711 (handle);
8712
8713 h->recvbufAdjoints = nullptr;
8714 if(h->root == getCommRank(h->comm)) {
8715 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
8716 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
8717 // Adjoint buffers are always linear in space so we can accesses them in one sweep
8718 adjointInterface->getAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
8719
8720 }
8721 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
8722 if(h->root == getCommRank(h->comm)) {
8723 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
8724 }
8725 }
8726 h->sendbufAdjoints = nullptr;
8727 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
8728 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
8729
8730 AMPI_Igather_adj<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype,
8732
8733 }
8734
8735 template<typename SENDTYPE, typename RECVTYPE>
8736 void AMPI_Igather_b_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
8737
8739 (handle);
8740 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
8741
8742 // Adjoint buffers are always linear in space so we can accesses them in one sweep
8743 adjointInterface->updateAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
8744 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
8745 if(h->root == getCommRank(h->comm)) {
8746 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
8747 }
8748 }
8749
8750 template<typename SENDTYPE, typename RECVTYPE>
8751 int AMPI_Igather_finish(HandleBase* handle);
8752 template<typename SENDTYPE, typename RECVTYPE>
8753 int AMPI_Igather(MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf, int sendcount, SENDTYPE* sendtype,
8754 typename RECVTYPE::Type* recvbuf, int recvcount, RECVTYPE* recvtype, int root, AMPI_Comm comm, AMPI_Request* request) {
8755 int rStatus;
8756
8757 if(!recvtype->getADTool().isActiveType()) {
8758 // call the regular function if the type is not active
8759 rStatus = MPI_Igather(sendbuf, sendcount, sendtype->getMpiType(), recvbuf, recvcount, recvtype->getMpiType(), root,
8760 comm, &request->request);
8761 } else {
8762
8763 // the type is an AD type so handle the buffers
8765 typename SENDTYPE::ModifiedType* sendbufMod = nullptr;
8766 int sendbufElements = 0;
8767
8768 // compute the total size of the buffer
8769 if(AMPI_IN_PLACE != sendbuf) {
8770 sendbufElements = sendcount;
8771 } else {
8772 sendbufElements = recvcount;
8773 }
8774
8775 if(sendtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
8776 sendtype->createModifiedTypeBuffer(sendbufMod, sendbufElements);
8777 } else {
8778 sendbufMod = reinterpret_cast<typename SENDTYPE::ModifiedType*>(const_cast<typename SENDTYPE::Type*>(sendbuf));
8779 }
8780 typename RECVTYPE::ModifiedType* recvbufMod = nullptr;
8781 int recvbufElements = 0;
8782
8783 if(root == getCommRank(comm)) {
8784 // compute the total size of the buffer
8785 recvbufElements = recvcount * getCommSize(comm);
8786
8787 if(recvtype->isModifiedBufferRequired() ) {
8788 recvtype->createModifiedTypeBuffer(recvbufMod, recvbufElements);
8789 } else {
8790 recvbufMod = reinterpret_cast<typename RECVTYPE::ModifiedType*>(const_cast<typename RECVTYPE::Type*>(recvbuf));
8791 }
8792 }
8793
8794 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
8795 if(recvtype->getADTool().isHandleRequired()) {
8797 }
8798 recvtype->getADTool().startAssembly(h);
8799 if(sendtype->isModifiedBufferRequired()) {
8800 if(AMPI_IN_PLACE != sendbuf) {
8801 sendtype->copyIntoModifiedBuffer(sendbuf, 0, sendbufMod, 0, sendcount);
8802 } else {
8803 recvtype->copyIntoModifiedBuffer(recvbuf, recvcount * getCommRank(comm), recvbufMod, recvcount * getCommRank(comm),
8804 recvcount);
8805 }
8806 }
8807
8808 if(nullptr != h) {
8809 // gather the information for the reverse sweep
8810
8811 // create the index buffers
8812 if(AMPI_IN_PLACE != sendbuf) {
8813 h->sendbufCount = sendtype->computeActiveElements(sendcount);
8814 } else {
8815 h->sendbufCount = recvtype->computeActiveElements(recvcount);
8816 }
8817 h->sendbufTotalSize = sendtype->computeActiveElements(sendbufElements);
8818 recvtype->getADTool().createIndexTypeBuffer(h->sendbufIndices, h->sendbufTotalSize);
8819 if(root == getCommRank(comm)) {
8820 h->recvbufCount = recvtype->computeActiveElements(recvcount);
8821 h->recvbufTotalSize = recvtype->computeActiveElements(recvbufElements);
8822 recvtype->getADTool().createIndexTypeBuffer(h->recvbufIndices, h->recvbufTotalSize);
8823 }
8824
8825
8826 // extract the old primal values from the recv buffer if the AD tool
8827 // needs the primal values reset
8828 if(recvtype->getADTool().isOldPrimalsRequired()) {
8829 if(root == getCommRank(comm)) {
8830 recvtype->getADTool().createPrimalTypeBuffer(h->recvbufOldPrimals, h->recvbufTotalSize);
8831 if(root == getCommRank(comm)) {
8832 recvtype->getValues(recvbuf, 0, h->recvbufOldPrimals, 0, recvcount * getCommSize(comm));
8833 }
8834 }
8835 }
8836
8837
8838 if(AMPI_IN_PLACE != sendbuf) {
8839 sendtype->getIndices(sendbuf, 0, h->sendbufIndices, 0, sendcount);
8840 } else {
8841 recvtype->getIndices(recvbuf, recvcount * getCommRank(comm), h->sendbufIndices, 0, recvcount);
8842 }
8843
8844 if(root == getCommRank(comm)) {
8845 recvtype->createIndices(recvbuf, 0, h->recvbufIndices, 0, recvcount * getCommSize(comm));
8846 }
8847
8848 // pack all the variables in the handle
8849 h->funcReverse = AMPI_Igather_b<SENDTYPE, RECVTYPE>;
8850 h->funcForward = AMPI_Igather_d_finish<SENDTYPE, RECVTYPE>;
8851 h->funcPrimal = AMPI_Igather_p_finish<SENDTYPE, RECVTYPE>;
8852 h->sendcount = sendcount;
8853 h->sendtype = sendtype;
8854 h->recvcount = recvcount;
8855 h->recvtype = recvtype;
8856 h->root = root;
8857 h->comm = comm;
8858 }
8859
8860 if(root == getCommRank(comm)) {
8861 if(!recvtype->isModifiedBufferRequired()) {
8862 recvtype->clearIndices(recvbuf, 0, recvcount * getCommSize(comm));
8863 }
8864 }
8865
8866 rStatus = MPI_Igather(sendbufMod, sendcount, sendtype->getModifiedMpiType(), recvbufMod, recvcount,
8867 recvtype->getModifiedMpiType(), root, comm, &request->request);
8868
8870 asyncHandle->sendbuf = sendbuf;
8871 asyncHandle->sendbufMod = sendbufMod;
8872 asyncHandle->sendcount = sendcount;
8873 asyncHandle->sendtype = sendtype;
8874 asyncHandle->recvbuf = recvbuf;
8875 asyncHandle->recvbufMod = recvbufMod;
8876 asyncHandle->recvcount = recvcount;
8877 asyncHandle->recvtype = recvtype;
8878 asyncHandle->root = root;
8879 asyncHandle->comm = comm;
8880 asyncHandle->toolHandle = h;
8881 request->handle = asyncHandle;
8882 request->func = (ContinueFunction)AMPI_Igather_finish<SENDTYPE, RECVTYPE>;
8883
8884 // create adjoint wait
8885 if(nullptr != h) {
8886 WaitHandle* waitH = new WaitHandle((ReverseFunction)AMPI_Igather_b_finish<SENDTYPE, RECVTYPE>,
8887 (ForwardFunction)AMPI_Igather_d<SENDTYPE, RECVTYPE>, h);
8888 recvtype->getADTool().addToolAction(waitH);
8889 }
8890 }
8891
8892 return rStatus;
8893 }
8894
8895 template<typename SENDTYPE, typename RECVTYPE>
8897 int rStatus = 0;
8898
8900 (handle);
8901 MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf = asyncHandle->sendbuf;
8902 typename SENDTYPE::ModifiedType* sendbufMod = asyncHandle->sendbufMod;
8903 int sendcount = asyncHandle->sendcount;
8904 SENDTYPE* sendtype = asyncHandle->sendtype;
8905 typename RECVTYPE::Type* recvbuf = asyncHandle->recvbuf;
8906 typename RECVTYPE::ModifiedType* recvbufMod = asyncHandle->recvbufMod;
8907 int recvcount = asyncHandle->recvcount;
8908 RECVTYPE* recvtype = asyncHandle->recvtype;
8909 int root = asyncHandle->root;
8910 AMPI_Comm comm = asyncHandle->comm;
8911 AMPI_Request* request = asyncHandle->request;
8913 (asyncHandle->toolHandle);
8914 MEDI_UNUSED(h); // Unused generated to ignore warnings
8915 MEDI_UNUSED(sendbuf); // Unused generated to ignore warnings
8916 MEDI_UNUSED(sendbufMod); // Unused generated to ignore warnings
8917 MEDI_UNUSED(sendcount); // Unused generated to ignore warnings
8918 MEDI_UNUSED(sendtype); // Unused generated to ignore warnings
8919 MEDI_UNUSED(recvbuf); // Unused generated to ignore warnings
8920 MEDI_UNUSED(recvbufMod); // Unused generated to ignore warnings
8921 MEDI_UNUSED(recvcount); // Unused generated to ignore warnings
8922 MEDI_UNUSED(recvtype); // Unused generated to ignore warnings
8923 MEDI_UNUSED(root); // Unused generated to ignore warnings
8924 MEDI_UNUSED(comm); // Unused generated to ignore warnings
8925 MEDI_UNUSED(request); // Unused generated to ignore warnings
8926
8927 delete asyncHandle;
8928
8929 if(recvtype->getADTool().isActiveType()) {
8930
8931 recvtype->getADTool().addToolAction(h);
8932
8933 if(root == getCommRank(comm)) {
8934 if(recvtype->isModifiedBufferRequired()) {
8935 recvtype->copyFromModifiedBuffer(recvbuf, 0, recvbufMod, 0, recvcount * getCommSize(comm));
8936 }
8937 }
8938
8939 if(nullptr != h) {
8940 // handle the recv buffers
8941 if(root == getCommRank(comm)) {
8942 recvtype->registerValue(recvbuf, 0, h->recvbufIndices, h->recvbufOldPrimals, 0, recvcount * getCommSize(comm));
8943 }
8944 }
8945
8946 recvtype->getADTool().stopAssembly(h);
8947
8948 if(sendtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
8949 sendtype->deleteModifiedTypeBuffer(sendbufMod);
8950 }
8951 if(root == getCommRank(comm)) {
8952 if(recvtype->isModifiedBufferRequired() ) {
8953 recvtype->deleteModifiedTypeBuffer(recvbufMod);
8954 }
8955 }
8956
8957 // handle is deleted by the AD tool
8958 }
8959
8960 return rStatus;
8961 }
8962
8963#endif
8964#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
8965 template<typename SENDTYPE, typename RECVTYPE>
8968 typename SENDTYPE::IndexType* sendbufIndices;
8969 typename SENDTYPE::PrimalType* sendbufPrimals;
8970 /* required for async */ void* sendbufAdjoints;
8974 SENDTYPE* sendtype;
8976 typename RECVTYPE::IndexType* recvbufIndices;
8977 typename RECVTYPE::PrimalType* recvbufPrimals;
8978 typename RECVTYPE::PrimalType* recvbufOldPrimals;
8979 /* required for async */ void* recvbufAdjoints;
8981 /* required for async */ int* recvbufCountVec;
8982 /* required for async */ int* recvbufDisplsVec;
8983 const int* recvcounts;
8984 const int* displs;
8985 RECVTYPE* recvtype;
8986 int root;
8988
8990 if(nullptr != sendbufIndices) {
8991 sendtype->getADTool().deleteIndexTypeBuffer(sendbufIndices);
8992 sendbufIndices = nullptr;
8993 }
8994 if(nullptr != sendbufPrimals) {
8995 sendtype->getADTool().deletePrimalTypeBuffer(sendbufPrimals);
8996 sendbufPrimals = nullptr;
8997 }
8998 if(nullptr != recvbufIndices) {
8999 recvtype->getADTool().deleteIndexTypeBuffer(recvbufIndices);
9000 recvbufIndices = nullptr;
9001 }
9002 if(nullptr != recvbufPrimals) {
9003 recvtype->getADTool().deletePrimalTypeBuffer(recvbufPrimals);
9004 recvbufPrimals = nullptr;
9005 }
9006 if(nullptr != recvbufOldPrimals) {
9007 recvtype->getADTool().deletePrimalTypeBuffer(recvbufOldPrimals);
9008 recvbufOldPrimals = nullptr;
9009 }
9010 if(nullptr != recvbufCount) {
9011 delete [] recvbufCount;
9012 recvbufCount = nullptr;
9013 }
9014 }
9015 };
9016
9017 template<typename SENDTYPE, typename RECVTYPE>
9019 MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf;
9020 typename SENDTYPE::ModifiedType* sendbufMod;
9022 SENDTYPE* sendtype;
9023 typename RECVTYPE::Type* recvbuf;
9024 typename RECVTYPE::ModifiedType* recvbufMod;
9025 const int* displsMod;
9026 const int* recvcounts;
9027 const int* displs;
9028 RECVTYPE* recvtype;
9029 int root;
9032 };
9033
9034 template<typename SENDTYPE, typename RECVTYPE>
9035 void AMPI_Igatherv_p(HandleBase* handle, AdjointInterface* adjointInterface) {
9037 (handle);
9038
9039 h->recvbufAdjoints = nullptr;
9040 if(h->root == getCommRank(h->comm)) {
9042 adjointInterface->getVectorSize());
9043 adjointInterface->createPrimalTypeBuffer((void*&)h->recvbufPrimals, h->recvbufTotalSize );
9044 }
9045 h->sendbufAdjoints = nullptr;
9046 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
9047 adjointInterface->createPrimalTypeBuffer((void*&)h->sendbufPrimals, h->sendbufTotalSize );
9048 // Primal buffers are always linear in space so we can accesses them in one sweep
9049 adjointInterface->getPrimals(h->sendbufIndices, h->sendbufPrimals, h->sendbufTotalSize);
9050
9051
9052 AMPI_Igatherv_pri<SENDTYPE, RECVTYPE>(h->sendbufPrimals, h->sendbufCountVec, h->sendcount, h->sendtype,
9054 &h->requestReverse);
9055
9056 }
9057
9058 template<typename SENDTYPE, typename RECVTYPE>
9059 void AMPI_Igatherv_p_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
9060
9062 (handle);
9063 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
9064
9065 adjointInterface->deletePrimalTypeBuffer((void*&)h->sendbufPrimals);
9066 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
9067 if(h->root == getCommRank(h->comm)) {
9068 adjointInterface->getPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
9069 }
9070 }
9071 if(h->root == getCommRank(h->comm)) {
9072 // Primal buffers are always linear in space so we can accesses them in one sweep
9073 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufPrimals, h->recvbufTotalSize);
9074 adjointInterface->deletePrimalTypeBuffer((void*&)h->recvbufPrimals);
9075 delete [] h->recvbufCountVec;
9076 delete [] h->recvbufDisplsVec;
9077 }
9078 }
9079
9080 template<typename SENDTYPE, typename RECVTYPE>
9081 void AMPI_Igatherv_d(HandleBase* handle, AdjointInterface* adjointInterface) {
9083 (handle);
9084
9085 h->recvbufAdjoints = nullptr;
9086 if(h->root == getCommRank(h->comm)) {
9088 adjointInterface->getVectorSize());
9089 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
9090 }
9091 h->sendbufAdjoints = nullptr;
9092 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
9093 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
9094 // Adjoint buffers are always linear in space so we can accesses them in one sweep
9095 adjointInterface->getAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
9096
9097
9098 AMPI_Igatherv_fwd<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype,
9100 &h->requestReverse);
9101
9102 }
9103
9104 template<typename SENDTYPE, typename RECVTYPE>
9105 void AMPI_Igatherv_d_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
9106
9108 (handle);
9109 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
9110
9111 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
9112 if(h->root == getCommRank(h->comm)) {
9113 // Adjoint buffers are always linear in space so we can accesses them in one sweep
9114 adjointInterface->updateAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
9115 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
9116 delete [] h->recvbufCountVec;
9117 delete [] h->recvbufDisplsVec;
9118 }
9119 }
9120
9121 template<typename SENDTYPE, typename RECVTYPE>
9122 void AMPI_Igatherv_b(HandleBase* handle, AdjointInterface* adjointInterface) {
9124 (handle);
9125
9126 h->recvbufAdjoints = nullptr;
9127 if(h->root == getCommRank(h->comm)) {
9129 adjointInterface->getVectorSize());
9130 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
9131 // Adjoint buffers are always linear in space so we can accesses them in one sweep
9132 adjointInterface->getAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
9133
9134 }
9135 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
9136 if(h->root == getCommRank(h->comm)) {
9137 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
9138 }
9139 }
9140 h->sendbufAdjoints = nullptr;
9141 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
9142 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
9143
9144 AMPI_Igatherv_adj<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype,
9146 &h->requestReverse);
9147
9148 }
9149
9150 template<typename SENDTYPE, typename RECVTYPE>
9151 void AMPI_Igatherv_b_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
9152
9154 (handle);
9155 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
9156
9157 // Adjoint buffers are always linear in space so we can accesses them in one sweep
9158 adjointInterface->updateAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
9159 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
9160 if(h->root == getCommRank(h->comm)) {
9161 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
9162 delete [] h->recvbufCountVec;
9163 delete [] h->recvbufDisplsVec;
9164 }
9165 }
9166
9167 template<typename SENDTYPE, typename RECVTYPE>
9168 int AMPI_Igatherv_finish(HandleBase* handle);
9169 template<typename SENDTYPE, typename RECVTYPE>
9170 int AMPI_Igatherv(MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf, int sendcount, SENDTYPE* sendtype,
9171 typename RECVTYPE::Type* recvbuf, const int* recvcounts, const int* displs, RECVTYPE* recvtype, int root,
9172 AMPI_Comm comm, AMPI_Request* request) {
9173 int rStatus;
9174
9175 if(!recvtype->getADTool().isActiveType()) {
9176 // call the regular function if the type is not active
9177 rStatus = MPI_Igatherv(sendbuf, sendcount, sendtype->getMpiType(), recvbuf, recvcounts, displs, recvtype->getMpiType(),
9178 root, comm, &request->request);
9179 } else {
9180
9181 // the type is an AD type so handle the buffers
9183 MEDI_OPTIONAL_CONST int* displsMod = displs;
9184 int displsTotalSize = 0;
9185 if(nullptr != displs) {
9186 displsTotalSize = computeDisplacementsTotalSize(recvcounts, getCommSize(comm));
9187 if(recvtype->isModifiedBufferRequired()) {
9188 displsMod = createLinearDisplacements(recvcounts, getCommSize(comm));
9189 }
9190 }
9191 typename SENDTYPE::ModifiedType* sendbufMod = nullptr;
9192 int sendbufElements = 0;
9193
9194 // compute the total size of the buffer
9195 if(AMPI_IN_PLACE != sendbuf) {
9196 sendbufElements = sendcount;
9197 } else {
9198 sendbufElements = recvcounts[getCommRank(comm)];
9199 }
9200
9201 if(sendtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
9202 sendtype->createModifiedTypeBuffer(sendbufMod, sendbufElements);
9203 } else {
9204 sendbufMod = reinterpret_cast<typename SENDTYPE::ModifiedType*>(const_cast<typename SENDTYPE::Type*>(sendbuf));
9205 }
9206 typename RECVTYPE::ModifiedType* recvbufMod = nullptr;
9207 int recvbufElements = 0;
9208
9209 if(root == getCommRank(comm)) {
9210 // compute the total size of the buffer
9211 recvbufElements = displsTotalSize;
9212
9213 if(recvtype->isModifiedBufferRequired() ) {
9214 recvtype->createModifiedTypeBuffer(recvbufMod, recvbufElements);
9215 } else {
9216 recvbufMod = reinterpret_cast<typename RECVTYPE::ModifiedType*>(const_cast<typename RECVTYPE::Type*>(recvbuf));
9217 }
9218 }
9219
9220 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
9221 if(recvtype->getADTool().isHandleRequired()) {
9223 }
9224 recvtype->getADTool().startAssembly(h);
9225 if(sendtype->isModifiedBufferRequired()) {
9226 if(AMPI_IN_PLACE != sendbuf) {
9227 sendtype->copyIntoModifiedBuffer(sendbuf, 0, sendbufMod, 0, sendcount);
9228 } else {
9229 {
9230 const int rank = getCommRank(comm);
9231 recvtype->copyIntoModifiedBuffer(recvbuf, displs[rank], recvbufMod, displsMod[rank], recvcounts[rank]);
9232 }
9233 }
9234 }
9235
9236 if(nullptr != h) {
9237 // gather the information for the reverse sweep
9238
9239 // create the index buffers
9240 if(AMPI_IN_PLACE != sendbuf) {
9241 h->sendbufCount = sendtype->computeActiveElements(sendcount);
9242 } else {
9243 h->sendbufCount = recvtype->computeActiveElements(displs[getCommRank(comm)] + recvcounts[getCommRank(
9244 comm)]) - recvtype->computeActiveElements(displs[getCommRank(comm)]);
9245 }
9246 h->sendbufTotalSize = sendtype->computeActiveElements(sendbufElements);
9247 recvtype->getADTool().createIndexTypeBuffer(h->sendbufIndices, h->sendbufTotalSize);
9248 if(root == getCommRank(comm)) {
9249 createLinearIndexCounts(h->recvbufCount, recvcounts, displs, getCommSize(comm), recvtype);
9250 h->recvbufTotalSize = recvtype->computeActiveElements(recvbufElements);
9251 recvtype->getADTool().createIndexTypeBuffer(h->recvbufIndices, h->recvbufTotalSize);
9252 }
9253
9254
9255 // extract the old primal values from the recv buffer if the AD tool
9256 // needs the primal values reset
9257 if(recvtype->getADTool().isOldPrimalsRequired()) {
9258 if(root == getCommRank(comm)) {
9259 recvtype->getADTool().createPrimalTypeBuffer(h->recvbufOldPrimals, h->recvbufTotalSize);
9260 if(root == getCommRank(comm)) {
9261 for(int i = 0; i < getCommSize(comm); ++i) {
9262 recvtype->getValues(recvbuf, displs[i], h->recvbufOldPrimals, displsMod[i], recvcounts[i]);
9263 }
9264 }
9265 }
9266 }
9267
9268
9269 if(AMPI_IN_PLACE != sendbuf) {
9270 sendtype->getIndices(sendbuf, 0, h->sendbufIndices, 0, sendcount);
9271 } else {
9272 {
9273 const int rank = getCommRank(comm);
9274 recvtype->getIndices(recvbuf, displs[rank], h->sendbufIndices, 0, recvcounts[rank]);
9275 }
9276 }
9277
9278 if(root == getCommRank(comm)) {
9279 for(int i = 0; i < getCommSize(comm); ++i) {
9280 recvtype->createIndices(recvbuf, displs[i], h->recvbufIndices, displsMod[i], recvcounts[i]);
9281 }
9282 }
9283
9284 // pack all the variables in the handle
9285 h->funcReverse = AMPI_Igatherv_b<SENDTYPE, RECVTYPE>;
9286 h->funcForward = AMPI_Igatherv_d_finish<SENDTYPE, RECVTYPE>;
9287 h->funcPrimal = AMPI_Igatherv_p_finish<SENDTYPE, RECVTYPE>;
9288 h->sendcount = sendcount;
9289 h->sendtype = sendtype;
9290 h->recvcounts = recvcounts;
9291 h->displs = displs;
9292 h->recvtype = recvtype;
9293 h->root = root;
9294 h->comm = comm;
9295 }
9296
9297 if(root == getCommRank(comm)) {
9298 if(!recvtype->isModifiedBufferRequired()) {
9299 for(int i = 0; i < getCommSize(comm); ++i) {
9300 recvtype->clearIndices(recvbuf, displs[i], recvcounts[i]);
9301 }
9302 }
9303 }
9304
9305 rStatus = MPI_Igatherv(sendbufMod, sendcount, sendtype->getModifiedMpiType(), recvbufMod, recvcounts, displsMod,
9306 recvtype->getModifiedMpiType(), root, comm, &request->request);
9307
9309 asyncHandle->sendbuf = sendbuf;
9310 asyncHandle->sendbufMod = sendbufMod;
9311 asyncHandle->sendcount = sendcount;
9312 asyncHandle->sendtype = sendtype;
9313 asyncHandle->recvbuf = recvbuf;
9314 asyncHandle->recvbufMod = recvbufMod;
9315 asyncHandle->displsMod = displsMod;
9316 asyncHandle->recvcounts = recvcounts;
9317 asyncHandle->displs = displs;
9318 asyncHandle->recvtype = recvtype;
9319 asyncHandle->root = root;
9320 asyncHandle->comm = comm;
9321 asyncHandle->toolHandle = h;
9322 request->handle = asyncHandle;
9323 request->func = (ContinueFunction)AMPI_Igatherv_finish<SENDTYPE, RECVTYPE>;
9324
9325 // create adjoint wait
9326 if(nullptr != h) {
9327 WaitHandle* waitH = new WaitHandle((ReverseFunction)AMPI_Igatherv_b_finish<SENDTYPE, RECVTYPE>,
9328 (ForwardFunction)AMPI_Igatherv_d<SENDTYPE, RECVTYPE>, h);
9329 recvtype->getADTool().addToolAction(waitH);
9330 }
9331 }
9332
9333 return rStatus;
9334 }
9335
9336 template<typename SENDTYPE, typename RECVTYPE>
9338 int rStatus = 0;
9339
9342 MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf = asyncHandle->sendbuf;
9343 typename SENDTYPE::ModifiedType* sendbufMod = asyncHandle->sendbufMod;
9344 int sendcount = asyncHandle->sendcount;
9345 SENDTYPE* sendtype = asyncHandle->sendtype;
9346 typename RECVTYPE::Type* recvbuf = asyncHandle->recvbuf;
9347 typename RECVTYPE::ModifiedType* recvbufMod = asyncHandle->recvbufMod;
9348 const int* displsMod = asyncHandle->displsMod;
9349 const int* recvcounts = asyncHandle->recvcounts;
9350 const int* displs = asyncHandle->displs;
9351 RECVTYPE* recvtype = asyncHandle->recvtype;
9352 int root = asyncHandle->root;
9353 AMPI_Comm comm = asyncHandle->comm;
9354 AMPI_Request* request = asyncHandle->request;
9356 (asyncHandle->toolHandle);
9357 MEDI_UNUSED(h); // Unused generated to ignore warnings
9358 MEDI_UNUSED(sendbuf); // Unused generated to ignore warnings
9359 MEDI_UNUSED(sendbufMod); // Unused generated to ignore warnings
9360 MEDI_UNUSED(sendcount); // Unused generated to ignore warnings
9361 MEDI_UNUSED(sendtype); // Unused generated to ignore warnings
9362 MEDI_UNUSED(recvbuf); // Unused generated to ignore warnings
9363 MEDI_UNUSED(recvbufMod); // Unused generated to ignore warnings
9364 MEDI_UNUSED(displsMod); // Unused generated to ignore warnings
9365 MEDI_UNUSED(recvcounts); // Unused generated to ignore warnings
9366 MEDI_UNUSED(displs); // Unused generated to ignore warnings
9367 MEDI_UNUSED(recvtype); // Unused generated to ignore warnings
9368 MEDI_UNUSED(root); // Unused generated to ignore warnings
9369 MEDI_UNUSED(comm); // Unused generated to ignore warnings
9370 MEDI_UNUSED(request); // Unused generated to ignore warnings
9371
9372 delete asyncHandle;
9373
9374 if(recvtype->getADTool().isActiveType()) {
9375
9376 recvtype->getADTool().addToolAction(h);
9377
9378 if(root == getCommRank(comm)) {
9379 if(recvtype->isModifiedBufferRequired()) {
9380 for(int i = 0; i < getCommSize(comm); ++i) {
9381 recvtype->copyFromModifiedBuffer(recvbuf, displs[i], recvbufMod, displsMod[i], recvcounts[i]);
9382 }
9383 }
9384 }
9385
9386 if(nullptr != h) {
9387 // handle the recv buffers
9388 if(root == getCommRank(comm)) {
9389 for(int i = 0; i < getCommSize(comm); ++i) {
9390 recvtype->registerValue(recvbuf, displs[i], h->recvbufIndices, h->recvbufOldPrimals, displsMod[i], recvcounts[i]);
9391 }
9392 }
9393 }
9394
9395 recvtype->getADTool().stopAssembly(h);
9396 if(recvtype->isModifiedBufferRequired()) {
9397 delete [] displsMod;
9398 }
9399
9400 if(sendtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
9401 sendtype->deleteModifiedTypeBuffer(sendbufMod);
9402 }
9403 if(root == getCommRank(comm)) {
9404 if(recvtype->isModifiedBufferRequired() ) {
9405 recvtype->deleteModifiedTypeBuffer(recvbufMod);
9406 }
9407 }
9408
9409 // handle is deleted by the AD tool
9410 }
9411
9412 return rStatus;
9413 }
9414
9415#endif
9416#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
9417 template<typename DATATYPE>
9420 typename DATATYPE::IndexType* sendbufIndices;
9421 typename DATATYPE::PrimalType* sendbufPrimals;
9422 /* required for async */ void* sendbufAdjoints;
9426 typename DATATYPE::IndexType* recvbufIndices;
9427 typename DATATYPE::PrimalType* recvbufPrimals;
9428 typename DATATYPE::PrimalType* recvbufOldPrimals;
9429 /* required for async */ void* recvbufAdjoints;
9433 DATATYPE* datatype;
9435 int root;
9437
9439 if(nullptr != sendbufIndices) {
9440 datatype->getADTool().deleteIndexTypeBuffer(sendbufIndices);
9441 sendbufIndices = nullptr;
9442 }
9443 if(nullptr != sendbufPrimals) {
9444 datatype->getADTool().deletePrimalTypeBuffer(sendbufPrimals);
9445 sendbufPrimals = nullptr;
9446 }
9447 if(nullptr != recvbufIndices) {
9448 datatype->getADTool().deleteIndexTypeBuffer(recvbufIndices);
9449 recvbufIndices = nullptr;
9450 }
9451 if(nullptr != recvbufPrimals) {
9452 datatype->getADTool().deletePrimalTypeBuffer(recvbufPrimals);
9453 recvbufPrimals = nullptr;
9454 }
9455 if(nullptr != recvbufOldPrimals) {
9456 datatype->getADTool().deletePrimalTypeBuffer(recvbufOldPrimals);
9457 recvbufOldPrimals = nullptr;
9458 }
9459 }
9460 };
9461
9462 template<typename DATATYPE>
9464 MEDI_OPTIONAL_CONST typename DATATYPE::Type* sendbuf;
9465 typename DATATYPE::ModifiedType* sendbufMod;
9466 typename DATATYPE::Type* recvbuf;
9467 typename DATATYPE::ModifiedType* recvbufMod;
9469 DATATYPE* datatype;
9471 int root;
9474 };
9475
9476 template<typename DATATYPE>
9477 void AMPI_Ireduce_global_p(HandleBase* handle, AdjointInterface* adjointInterface) {
9479
9480 AMPI_Op convOp = h->datatype->getADTool().convertOperator(h->op);
9481 (void)convOp;
9482 h->recvbufAdjoints = nullptr;
9483 if(h->root == getCommRank(h->comm)) {
9484 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
9485 adjointInterface->createPrimalTypeBuffer((void*&)h->recvbufPrimals, h->recvbufTotalSize );
9486 }
9487 h->sendbufAdjoints = nullptr;
9488 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
9489 adjointInterface->createPrimalTypeBuffer((void*&)h->sendbufPrimals, h->sendbufTotalSize );
9490 // Primal buffers are always linear in space so we can accesses them in one sweep
9491 adjointInterface->getPrimals(h->sendbufIndices, h->sendbufPrimals, h->sendbufTotalSize);
9492
9493
9494 AMPI_Ireduce_global_pri<DATATYPE>(h->sendbufPrimals, h->sendbufCountVec, h->recvbufPrimals, h->recvbufCountVec,
9495 h->count, h->datatype, h->op, h->root, h->comm, &h->requestReverse);
9496
9497 }
9498
9499 template<typename DATATYPE>
9501
9503 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
9504
9505 AMPI_Op convOp = h->datatype->getADTool().convertOperator(h->op);
9506 (void)convOp;
9507 adjointInterface->deletePrimalTypeBuffer((void*&)h->sendbufPrimals);
9508 if(h->datatype->getADTool().isOldPrimalsRequired()) {
9509 if(h->root == getCommRank(h->comm)) {
9510 adjointInterface->getPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
9511 }
9512 }
9513 if(h->root == getCommRank(h->comm)) {
9514 // Primal buffers are always linear in space so we can accesses them in one sweep
9515 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufPrimals, h->recvbufTotalSize);
9516 adjointInterface->deletePrimalTypeBuffer((void*&)h->recvbufPrimals);
9517 }
9518 }
9519
9520 template<typename DATATYPE>
9521 void AMPI_Ireduce_global_d(HandleBase* handle, AdjointInterface* adjointInterface) {
9523
9524 AMPI_Op convOp = h->datatype->getADTool().convertOperator(h->op);
9525 (void)convOp;
9526 h->recvbufAdjoints = nullptr;
9527 if(h->root == getCommRank(h->comm)) {
9528 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
9529 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
9530 }
9531 h->sendbufAdjoints = nullptr;
9532 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
9533 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
9534 // Adjoint buffers are always linear in space so we can accesses them in one sweep
9535 adjointInterface->getAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
9536
9537
9538 AMPI_Ireduce_global_fwd<DATATYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->recvbufAdjoints, h->recvbufCountVec,
9539 h->count, h->datatype, h->op, h->root, h->comm, &h->requestReverse);
9540
9541 }
9542
9543 template<typename DATATYPE>
9545
9547 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
9548
9549 AMPI_Op convOp = h->datatype->getADTool().convertOperator(h->op);
9550 (void)convOp;
9551 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
9552 if(h->root == getCommRank(h->comm)) {
9553 // Adjoint buffers are always linear in space so we can accesses them in one sweep
9554 adjointInterface->updateAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
9555 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
9556 }
9557 }
9558
9559 template<typename DATATYPE>
9560 void AMPI_Ireduce_global_b(HandleBase* handle, AdjointInterface* adjointInterface) {
9562
9563 AMPI_Op convOp = h->datatype->getADTool().convertOperator(h->op);
9564 (void)convOp;
9565 h->recvbufAdjoints = nullptr;
9566 if(h->root == getCommRank(h->comm)) {
9567 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
9568 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
9569 // Adjoint buffers are always linear in space so we can accesses them in one sweep
9570 adjointInterface->getAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
9571
9572 convOp.preAdjointOperation(h->recvbufAdjoints, h->recvbufPrimals, h->recvbufCount, adjointInterface->getVectorSize());
9573 }
9574 if(h->datatype->getADTool().isOldPrimalsRequired()) {
9575 if(h->root == getCommRank(h->comm)) {
9576 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
9577 }
9578 }
9579 h->sendbufAdjoints = nullptr;
9580 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
9581 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
9582
9583 AMPI_Ireduce_global_adj<DATATYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->recvbufAdjoints, h->recvbufCountVec,
9584 h->count, h->datatype, h->op, h->root, h->comm, &h->requestReverse);
9585
9586 }
9587
9588 template<typename DATATYPE>
9590
9592 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
9593
9594 AMPI_Op convOp = h->datatype->getADTool().convertOperator(h->op);
9595 (void)convOp;
9596 // the primals of the recive buffer are always given to the function. The operator should ignore them if not needed.
9597 // The wrapper functions make sure that for operators that need the primals an all* action is perfomed (e.g. Allreduce instead of Reduce)
9599 adjointInterface->getVectorSize());
9600 // Adjoint buffers are always linear in space so we can accesses them in one sweep
9601 adjointInterface->updateAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
9602 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
9603 if(h->root == getCommRank(h->comm)) {
9604 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
9605 }
9606 }
9607
9608 template<typename DATATYPE>
9609 int AMPI_Ireduce_global_finish(HandleBase* handle);
9610 template<typename DATATYPE>
9611 int AMPI_Ireduce_global(MEDI_OPTIONAL_CONST typename DATATYPE::Type* sendbuf, typename DATATYPE::Type* recvbuf,
9612 int count, DATATYPE* datatype, AMPI_Op op, int root, AMPI_Comm comm, AMPI_Request* request) {
9613 int rStatus;
9614 AMPI_Op convOp = datatype->getADTool().convertOperator(op);
9615 (void)convOp;
9616
9617 if(!datatype->getADTool().isActiveType()) {
9618 // call the regular function if the type is not active
9619 rStatus = MPI_Ireduce(sendbuf, recvbuf, count, datatype->getMpiType(), convOp.primalFunction, root, comm,
9620 &request->request);
9621 } else {
9622
9623 // the type is an AD type so handle the buffers
9625 typename DATATYPE::ModifiedType* sendbufMod = nullptr;
9626 int sendbufElements = 0;
9627
9628 // compute the total size of the buffer
9629 if(AMPI_IN_PLACE != sendbuf) {
9630 sendbufElements = count;
9631 } else {
9632 sendbufElements = count;
9633 }
9634
9635 if(datatype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
9636 datatype->createModifiedTypeBuffer(sendbufMod, sendbufElements);
9637 } else {
9638 sendbufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(sendbuf));
9639 }
9640 typename DATATYPE::ModifiedType* recvbufMod = nullptr;
9641 int recvbufElements = 0;
9642
9643 if(root == getCommRank(comm)) {
9644 // compute the total size of the buffer
9645 recvbufElements = count;
9646
9647 if(datatype->isModifiedBufferRequired() ) {
9648 datatype->createModifiedTypeBuffer(recvbufMod, recvbufElements);
9649 } else {
9650 recvbufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(recvbuf));
9651 }
9652 }
9653
9654 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
9655 if(datatype->getADTool().isHandleRequired()) {
9657 }
9658 datatype->getADTool().startAssembly(h);
9659 if(datatype->isModifiedBufferRequired()) {
9660 if(AMPI_IN_PLACE != sendbuf) {
9661 datatype->copyIntoModifiedBuffer(sendbuf, 0, sendbufMod, 0, count);
9662 } else {
9663 datatype->copyIntoModifiedBuffer(recvbuf, 0, recvbufMod, 0, count);
9664 }
9665 }
9666
9667 if(nullptr != h) {
9668 // gather the information for the reverse sweep
9669
9670 // create the index buffers
9671 if(AMPI_IN_PLACE != sendbuf) {
9672 h->sendbufCount = datatype->computeActiveElements(count);
9673 } else {
9674 h->sendbufCount = datatype->computeActiveElements(count);
9675 }
9676 h->sendbufTotalSize = datatype->computeActiveElements(sendbufElements);
9677 datatype->getADTool().createIndexTypeBuffer(h->sendbufIndices, h->sendbufTotalSize);
9678 if(root == getCommRank(comm)) {
9679 h->recvbufCount = datatype->computeActiveElements(count);
9680 h->recvbufTotalSize = datatype->computeActiveElements(recvbufElements);
9681 datatype->getADTool().createIndexTypeBuffer(h->recvbufIndices, h->recvbufTotalSize);
9682 }
9683
9684 // extract the primal values for the operator if required
9685 if(convOp.requiresPrimal) {
9686 datatype->getADTool().createPrimalTypeBuffer(h->sendbufPrimals, h->sendbufTotalSize);
9687 if(AMPI_IN_PLACE != sendbuf) {
9688 datatype->getValues(sendbuf, 0, h->sendbufPrimals, 0, count);
9689 } else {
9690 datatype->getValues(recvbuf, 0, h->sendbufPrimals, 0, count);
9691 }
9692 }
9693
9694 // extract the old primal values from the recv buffer if the AD tool
9695 // needs the primal values reset
9696 if(datatype->getADTool().isOldPrimalsRequired()) {
9697 if(root == getCommRank(comm)) {
9698 datatype->getADTool().createPrimalTypeBuffer(h->recvbufOldPrimals, h->recvbufTotalSize);
9699 if(root == getCommRank(comm)) {
9700 datatype->getValues(recvbuf, 0, h->recvbufOldPrimals, 0, count);
9701 }
9702 }
9703 }
9704
9705
9706 if(AMPI_IN_PLACE != sendbuf) {
9707 datatype->getIndices(sendbuf, 0, h->sendbufIndices, 0, count);
9708 } else {
9709 datatype->getIndices(recvbuf, 0, h->sendbufIndices, 0, count);
9710 }
9711
9712 if(root == getCommRank(comm)) {
9713 datatype->createIndices(recvbuf, 0, h->recvbufIndices, 0, count);
9714 }
9715
9716 // pack all the variables in the handle
9717 h->funcReverse = AMPI_Ireduce_global_b<DATATYPE>;
9718 h->funcForward = AMPI_Ireduce_global_d_finish<DATATYPE>;
9719 h->funcPrimal = AMPI_Ireduce_global_p_finish<DATATYPE>;
9720 h->count = count;
9721 h->datatype = datatype;
9722 h->op = op;
9723 h->root = root;
9724 h->comm = comm;
9725 }
9726
9727 if(root == getCommRank(comm)) {
9728 if(!datatype->isModifiedBufferRequired()) {
9729 datatype->clearIndices(recvbuf, 0, count);
9730 }
9731 }
9732
9733 rStatus = MPI_Ireduce(sendbufMod, recvbufMod, count, datatype->getModifiedMpiType(), convOp.modifiedPrimalFunction,
9734 root, comm, &request->request);
9735
9737 asyncHandle->sendbuf = sendbuf;
9738 asyncHandle->sendbufMod = sendbufMod;
9739 asyncHandle->recvbuf = recvbuf;
9740 asyncHandle->recvbufMod = recvbufMod;
9741 asyncHandle->count = count;
9742 asyncHandle->datatype = datatype;
9743 asyncHandle->op = op;
9744 asyncHandle->root = root;
9745 asyncHandle->comm = comm;
9746 asyncHandle->toolHandle = h;
9747 request->handle = asyncHandle;
9748 request->func = (ContinueFunction)AMPI_Ireduce_global_finish<DATATYPE>;
9749
9750 // create adjoint wait
9751 if(nullptr != h) {
9752 WaitHandle* waitH = new WaitHandle((ReverseFunction)AMPI_Ireduce_global_b_finish<DATATYPE>,
9753 (ForwardFunction)AMPI_Ireduce_global_d<DATATYPE>, h);
9754 datatype->getADTool().addToolAction(waitH);
9755 }
9756 }
9757
9758 return rStatus;
9759 }
9760
9761 template<typename DATATYPE>
9763 int rStatus = 0;
9764
9766 (handle);
9767 MEDI_OPTIONAL_CONST typename DATATYPE::Type* sendbuf = asyncHandle->sendbuf;
9768 typename DATATYPE::ModifiedType* sendbufMod = asyncHandle->sendbufMod;
9769 typename DATATYPE::Type* recvbuf = asyncHandle->recvbuf;
9770 typename DATATYPE::ModifiedType* recvbufMod = asyncHandle->recvbufMod;
9771 int count = asyncHandle->count;
9772 DATATYPE* datatype = asyncHandle->datatype;
9773 AMPI_Op op = asyncHandle->op;
9774 int root = asyncHandle->root;
9775 AMPI_Comm comm = asyncHandle->comm;
9776 AMPI_Request* request = asyncHandle->request;
9778 (asyncHandle->toolHandle);
9779 MEDI_UNUSED(h); // Unused generated to ignore warnings
9780 MEDI_UNUSED(sendbuf); // Unused generated to ignore warnings
9781 MEDI_UNUSED(sendbufMod); // Unused generated to ignore warnings
9782 MEDI_UNUSED(recvbuf); // Unused generated to ignore warnings
9783 MEDI_UNUSED(recvbufMod); // Unused generated to ignore warnings
9784 MEDI_UNUSED(count); // Unused generated to ignore warnings
9785 MEDI_UNUSED(datatype); // Unused generated to ignore warnings
9786 MEDI_UNUSED(op); // Unused generated to ignore warnings
9787 MEDI_UNUSED(root); // Unused generated to ignore warnings
9788 MEDI_UNUSED(comm); // Unused generated to ignore warnings
9789 MEDI_UNUSED(request); // Unused generated to ignore warnings
9790
9791 delete asyncHandle;
9792
9793 if(datatype->getADTool().isActiveType()) {
9794
9795 AMPI_Op convOp = datatype->getADTool().convertOperator(op);
9796 (void)convOp;
9797 datatype->getADTool().addToolAction(h);
9798
9799 if(root == getCommRank(comm)) {
9800 if(datatype->isModifiedBufferRequired()) {
9801 datatype->copyFromModifiedBuffer(recvbuf, 0, recvbufMod, 0, count);
9802 }
9803 }
9804
9805 if(nullptr != h) {
9806 // handle the recv buffers
9807 if(root == getCommRank(comm)) {
9808 datatype->registerValue(recvbuf, 0, h->recvbufIndices, h->recvbufOldPrimals, 0, count);
9809 }
9810 }
9811 // extract the primal values for the operator if required
9812 if(nullptr != h && convOp.requiresPrimal) {
9813 if(root == getCommRank(comm)) {
9814 datatype->getADTool().createPrimalTypeBuffer(h->recvbufPrimals, h->recvbufTotalSize);
9815 if(root == getCommRank(comm)) {
9816 datatype->getValues(recvbuf, 0, h->recvbufPrimals, 0, count);
9817 }
9818 }
9819 }
9820
9821 datatype->getADTool().stopAssembly(h);
9822
9823 if(datatype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
9824 datatype->deleteModifiedTypeBuffer(sendbufMod);
9825 }
9826 if(root == getCommRank(comm)) {
9827 if(datatype->isModifiedBufferRequired() ) {
9828 datatype->deleteModifiedTypeBuffer(recvbufMod);
9829 }
9830 }
9831
9832 // handle is deleted by the AD tool
9833 }
9834
9835 return rStatus;
9836 }
9837
9838#endif
9839#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
9840 template<typename SENDTYPE, typename RECVTYPE>
9843 typename SENDTYPE::IndexType* sendbufIndices;
9844 typename SENDTYPE::PrimalType* sendbufPrimals;
9845 /* required for async */ void* sendbufAdjoints;
9849 SENDTYPE* sendtype;
9851 typename RECVTYPE::IndexType* recvbufIndices;
9852 typename RECVTYPE::PrimalType* recvbufPrimals;
9853 typename RECVTYPE::PrimalType* recvbufOldPrimals;
9854 /* required for async */ void* recvbufAdjoints;
9858 RECVTYPE* recvtype;
9859 int root;
9861
9863 if(nullptr != sendbufIndices) {
9864 sendtype->getADTool().deleteIndexTypeBuffer(sendbufIndices);
9865 sendbufIndices = nullptr;
9866 }
9867 if(nullptr != sendbufPrimals) {
9868 sendtype->getADTool().deletePrimalTypeBuffer(sendbufPrimals);
9869 sendbufPrimals = nullptr;
9870 }
9871 if(nullptr != recvbufIndices) {
9872 recvtype->getADTool().deleteIndexTypeBuffer(recvbufIndices);
9873 recvbufIndices = nullptr;
9874 }
9875 if(nullptr != recvbufPrimals) {
9876 recvtype->getADTool().deletePrimalTypeBuffer(recvbufPrimals);
9877 recvbufPrimals = nullptr;
9878 }
9879 if(nullptr != recvbufOldPrimals) {
9880 recvtype->getADTool().deletePrimalTypeBuffer(recvbufOldPrimals);
9881 recvbufOldPrimals = nullptr;
9882 }
9883 }
9884 };
9885
9886 template<typename SENDTYPE, typename RECVTYPE>
9888 const typename SENDTYPE::Type* sendbuf;
9889 typename SENDTYPE::ModifiedType* sendbufMod;
9891 SENDTYPE* sendtype;
9892 typename RECVTYPE::Type* recvbuf;
9893 typename RECVTYPE::ModifiedType* recvbufMod;
9895 RECVTYPE* recvtype;
9896 int root;
9899 };
9900
9901 template<typename SENDTYPE, typename RECVTYPE>
9902 void AMPI_Iscatter_p(HandleBase* handle, AdjointInterface* adjointInterface) {
9904 (handle);
9905
9906 h->recvbufAdjoints = nullptr;
9907 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
9908 adjointInterface->createPrimalTypeBuffer((void*&)h->recvbufPrimals, h->recvbufTotalSize );
9909 h->sendbufAdjoints = nullptr;
9910 if(h->root == getCommRank(h->comm)) {
9911 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
9912 adjointInterface->createPrimalTypeBuffer((void*&)h->sendbufPrimals, h->sendbufTotalSize );
9913 // Primal buffers are always linear in space so we can accesses them in one sweep
9914 adjointInterface->getPrimals(h->sendbufIndices, h->sendbufPrimals, h->sendbufTotalSize);
9915
9916 }
9917
9918 AMPI_Iscatter_pri<SENDTYPE, RECVTYPE>(h->sendbufPrimals, h->sendbufCountVec, h->sendcount, h->sendtype,
9920
9921 }
9922
9923 template<typename SENDTYPE, typename RECVTYPE>
9924 void AMPI_Iscatter_p_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
9925
9927 (handle);
9928 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
9929
9930 if(h->root == getCommRank(h->comm)) {
9931 adjointInterface->deletePrimalTypeBuffer((void*&)h->sendbufPrimals);
9932 }
9933 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
9934 adjointInterface->getPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
9935 }
9936 // Primal buffers are always linear in space so we can accesses them in one sweep
9937 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufPrimals, h->recvbufTotalSize);
9938 adjointInterface->deletePrimalTypeBuffer((void*&)h->recvbufPrimals);
9939 }
9940
9941 template<typename SENDTYPE, typename RECVTYPE>
9942 void AMPI_Iscatter_d(HandleBase* handle, AdjointInterface* adjointInterface) {
9944 (handle);
9945
9946 h->recvbufAdjoints = nullptr;
9947 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
9948 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
9949 h->sendbufAdjoints = nullptr;
9950 if(h->root == getCommRank(h->comm)) {
9951 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
9952 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
9953 // Adjoint buffers are always linear in space so we can accesses them in one sweep
9954 adjointInterface->getAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
9955
9956 }
9957
9958 AMPI_Iscatter_fwd<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype,
9960
9961 }
9962
9963 template<typename SENDTYPE, typename RECVTYPE>
9964 void AMPI_Iscatter_d_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
9965
9967 (handle);
9968 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
9969
9970 if(h->root == getCommRank(h->comm)) {
9971 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
9972 }
9973 // Adjoint buffers are always linear in space so we can accesses them in one sweep
9974 adjointInterface->updateAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
9975 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
9976 }
9977
9978 template<typename SENDTYPE, typename RECVTYPE>
9979 void AMPI_Iscatter_b(HandleBase* handle, AdjointInterface* adjointInterface) {
9981 (handle);
9982
9983 h->recvbufAdjoints = nullptr;
9984 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
9985 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
9986 // Adjoint buffers are always linear in space so we can accesses them in one sweep
9987 adjointInterface->getAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
9988
9989 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
9990 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
9991 }
9992 h->sendbufAdjoints = nullptr;
9993 if(h->root == getCommRank(h->comm)) {
9994 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
9995 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
9996 }
9997
9998 AMPI_Iscatter_adj<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype,
10000
10001 }
10002
10003 template<typename SENDTYPE, typename RECVTYPE>
10004 void AMPI_Iscatter_b_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
10005
10007 (handle);
10008 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
10009
10010 if(h->root == getCommRank(h->comm)) {
10011 // Adjoint buffers are always linear in space so we can accesses them in one sweep
10012 adjointInterface->updateAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
10013 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
10014 }
10015 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
10016 }
10017
10018 template<typename SENDTYPE, typename RECVTYPE>
10019 int AMPI_Iscatter_finish(HandleBase* handle);
10020 template<typename SENDTYPE, typename RECVTYPE>
10021 int AMPI_Iscatter(const typename SENDTYPE::Type* sendbuf, int sendcount, SENDTYPE* sendtype,
10022 typename RECVTYPE::Type* recvbuf, int recvcount, RECVTYPE* recvtype, int root, AMPI_Comm comm, AMPI_Request* request) {
10023 int rStatus;
10024
10025 if(!recvtype->getADTool().isActiveType()) {
10026 // call the regular function if the type is not active
10027 rStatus = MPI_Iscatter(sendbuf, sendcount, sendtype->getMpiType(), recvbuf, recvcount, recvtype->getMpiType(), root,
10028 comm, &request->request);
10029 } else {
10030
10031 // the type is an AD type so handle the buffers
10033 typename SENDTYPE::ModifiedType* sendbufMod = nullptr;
10034 int sendbufElements = 0;
10035
10036 if(root == getCommRank(comm)) {
10037 // compute the total size of the buffer
10038 sendbufElements = sendcount * getCommSize(comm);
10039
10040 if(sendtype->isModifiedBufferRequired() ) {
10041 sendtype->createModifiedTypeBuffer(sendbufMod, sendbufElements);
10042 } else {
10043 sendbufMod = reinterpret_cast<typename SENDTYPE::ModifiedType*>(const_cast<typename SENDTYPE::Type*>(sendbuf));
10044 }
10045 }
10046 typename RECVTYPE::ModifiedType* recvbufMod = nullptr;
10047 int recvbufElements = 0;
10048
10049 // compute the total size of the buffer
10050 if(AMPI_IN_PLACE != recvbuf) {
10051 recvbufElements = recvcount;
10052 } else {
10053 recvbufElements = sendcount;
10054 }
10055
10056 if(recvtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == recvbuf)) {
10057 recvtype->createModifiedTypeBuffer(recvbufMod, recvbufElements);
10058 } else {
10059 recvbufMod = reinterpret_cast<typename RECVTYPE::ModifiedType*>(const_cast<typename RECVTYPE::Type*>(recvbuf));
10060 }
10061
10062 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
10063 if(recvtype->getADTool().isHandleRequired()) {
10065 }
10066 recvtype->getADTool().startAssembly(h);
10067 if(root == getCommRank(comm)) {
10068 if(sendtype->isModifiedBufferRequired()) {
10069 sendtype->copyIntoModifiedBuffer(sendbuf, 0, sendbufMod, 0, sendcount * getCommSize(comm));
10070 }
10071 }
10072
10073 if(nullptr != h) {
10074 // gather the information for the reverse sweep
10075
10076 // create the index buffers
10077 if(root == getCommRank(comm)) {
10078 h->sendbufCount = sendtype->computeActiveElements(sendcount);
10079 h->sendbufTotalSize = sendtype->computeActiveElements(sendbufElements);
10080 recvtype->getADTool().createIndexTypeBuffer(h->sendbufIndices, h->sendbufTotalSize);
10081 }
10082 if(AMPI_IN_PLACE != recvbuf) {
10083 h->recvbufCount = recvtype->computeActiveElements(recvcount);
10084 } else {
10085 h->recvbufCount = sendtype->computeActiveElements(sendcount);
10086 }
10087 h->recvbufTotalSize = recvtype->computeActiveElements(recvbufElements);
10088 recvtype->getADTool().createIndexTypeBuffer(h->recvbufIndices, h->recvbufTotalSize);
10089
10090
10091 // extract the old primal values from the recv buffer if the AD tool
10092 // needs the primal values reset
10093 if(recvtype->getADTool().isOldPrimalsRequired()) {
10094 recvtype->getADTool().createPrimalTypeBuffer(h->recvbufOldPrimals, h->recvbufTotalSize);
10095 if(AMPI_IN_PLACE != recvbuf) {
10096 recvtype->getValues(recvbuf, 0, h->recvbufOldPrimals, 0, recvcount);
10097 } else {
10098 sendtype->getValues(sendbuf, sendcount * getCommRank(comm), h->recvbufOldPrimals, 0, sendcount);
10099 }
10100 }
10101
10102
10103 if(root == getCommRank(comm)) {
10104 sendtype->getIndices(sendbuf, 0, h->sendbufIndices, 0, sendcount * getCommSize(comm));
10105 }
10106
10107 if(AMPI_IN_PLACE != recvbuf) {
10108 recvtype->createIndices(recvbuf, 0, h->recvbufIndices, 0, recvcount);
10109 } else {
10110 sendtype->createIndices(const_cast<typename SENDTYPE::Type*>(sendbuf), sendcount * getCommRank(comm), h->recvbufIndices,
10111 0, sendcount);
10112 }
10113
10114 // pack all the variables in the handle
10115 h->funcReverse = AMPI_Iscatter_b<SENDTYPE, RECVTYPE>;
10116 h->funcForward = AMPI_Iscatter_d_finish<SENDTYPE, RECVTYPE>;
10117 h->funcPrimal = AMPI_Iscatter_p_finish<SENDTYPE, RECVTYPE>;
10118 h->sendcount = sendcount;
10119 h->sendtype = sendtype;
10120 h->recvcount = recvcount;
10121 h->recvtype = recvtype;
10122 h->root = root;
10123 h->comm = comm;
10124 }
10125
10126 if(!recvtype->isModifiedBufferRequired()) {
10127 if(AMPI_IN_PLACE != recvbuf) {
10128 recvtype->clearIndices(recvbuf, 0, recvcount);
10129 } else {
10130 sendtype->clearIndices(const_cast<typename SENDTYPE::Type*>(sendbuf), sendcount * getCommRank(comm), sendcount);
10131 }
10132 }
10133
10134 rStatus = MPI_Iscatter(sendbufMod, sendcount, sendtype->getModifiedMpiType(), recvbufMod, recvcount,
10135 recvtype->getModifiedMpiType(), root, comm, &request->request);
10136
10138 asyncHandle->sendbuf = sendbuf;
10139 asyncHandle->sendbufMod = sendbufMod;
10140 asyncHandle->sendcount = sendcount;
10141 asyncHandle->sendtype = sendtype;
10142 asyncHandle->recvbuf = recvbuf;
10143 asyncHandle->recvbufMod = recvbufMod;
10144 asyncHandle->recvcount = recvcount;
10145 asyncHandle->recvtype = recvtype;
10146 asyncHandle->root = root;
10147 asyncHandle->comm = comm;
10148 asyncHandle->toolHandle = h;
10149 request->handle = asyncHandle;
10150 request->func = (ContinueFunction)AMPI_Iscatter_finish<SENDTYPE, RECVTYPE>;
10151
10152 // create adjoint wait
10153 if(nullptr != h) {
10154 WaitHandle* waitH = new WaitHandle((ReverseFunction)AMPI_Iscatter_b_finish<SENDTYPE, RECVTYPE>,
10155 (ForwardFunction)AMPI_Iscatter_d<SENDTYPE, RECVTYPE>, h);
10156 recvtype->getADTool().addToolAction(waitH);
10157 }
10158 }
10159
10160 return rStatus;
10161 }
10162
10163 template<typename SENDTYPE, typename RECVTYPE>
10165 int rStatus = 0;
10166
10169 const typename SENDTYPE::Type* sendbuf = asyncHandle->sendbuf;
10170 typename SENDTYPE::ModifiedType* sendbufMod = asyncHandle->sendbufMod;
10171 int sendcount = asyncHandle->sendcount;
10172 SENDTYPE* sendtype = asyncHandle->sendtype;
10173 typename RECVTYPE::Type* recvbuf = asyncHandle->recvbuf;
10174 typename RECVTYPE::ModifiedType* recvbufMod = asyncHandle->recvbufMod;
10175 int recvcount = asyncHandle->recvcount;
10176 RECVTYPE* recvtype = asyncHandle->recvtype;
10177 int root = asyncHandle->root;
10178 AMPI_Comm comm = asyncHandle->comm;
10179 AMPI_Request* request = asyncHandle->request;
10181 (asyncHandle->toolHandle);
10182 MEDI_UNUSED(h); // Unused generated to ignore warnings
10183 MEDI_UNUSED(sendbuf); // Unused generated to ignore warnings
10184 MEDI_UNUSED(sendbufMod); // Unused generated to ignore warnings
10185 MEDI_UNUSED(sendcount); // Unused generated to ignore warnings
10186 MEDI_UNUSED(sendtype); // Unused generated to ignore warnings
10187 MEDI_UNUSED(recvbuf); // Unused generated to ignore warnings
10188 MEDI_UNUSED(recvbufMod); // Unused generated to ignore warnings
10189 MEDI_UNUSED(recvcount); // Unused generated to ignore warnings
10190 MEDI_UNUSED(recvtype); // Unused generated to ignore warnings
10191 MEDI_UNUSED(root); // Unused generated to ignore warnings
10192 MEDI_UNUSED(comm); // Unused generated to ignore warnings
10193 MEDI_UNUSED(request); // Unused generated to ignore warnings
10194
10195 delete asyncHandle;
10196
10197 if(recvtype->getADTool().isActiveType()) {
10198
10199 recvtype->getADTool().addToolAction(h);
10200
10201 if(recvtype->isModifiedBufferRequired()) {
10202 if(AMPI_IN_PLACE != recvbuf) {
10203 recvtype->copyFromModifiedBuffer(recvbuf, 0, recvbufMod, 0, recvcount);
10204 } else {
10205 sendtype->copyFromModifiedBuffer(const_cast<typename SENDTYPE::Type*>(sendbuf), sendcount * getCommRank(comm),
10206 sendbufMod, sendcount * getCommRank(comm), sendcount);
10207 }
10208 }
10209
10210 if(nullptr != h) {
10211 // handle the recv buffers
10212 if(AMPI_IN_PLACE != recvbuf) {
10213 recvtype->registerValue(recvbuf, 0, h->recvbufIndices, h->recvbufOldPrimals, 0, recvcount);
10214 } else {
10215 sendtype->registerValue(const_cast<typename SENDTYPE::Type*>(sendbuf), sendcount * getCommRank(comm), h->recvbufIndices,
10216 h->recvbufOldPrimals, 0, sendcount);
10217 }
10218 }
10219
10220 recvtype->getADTool().stopAssembly(h);
10221
10222 if(root == getCommRank(comm)) {
10223 if(sendtype->isModifiedBufferRequired() ) {
10224 sendtype->deleteModifiedTypeBuffer(sendbufMod);
10225 }
10226 }
10227 if(recvtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == recvbuf)) {
10228 recvtype->deleteModifiedTypeBuffer(recvbufMod);
10229 }
10230
10231 // handle is deleted by the AD tool
10232 }
10233
10234 return rStatus;
10235 }
10236
10237#endif
10238#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
10239 template<typename SENDTYPE, typename RECVTYPE>
10242 typename SENDTYPE::IndexType* sendbufIndices;
10243 typename SENDTYPE::PrimalType* sendbufPrimals;
10244 /* required for async */ void* sendbufAdjoints;
10246 /* required for async */ int* sendbufCountVec;
10247 /* required for async */ int* sendbufDisplsVec;
10248 const int* sendcounts;
10249 const int* displs;
10250 SENDTYPE* sendtype;
10252 typename RECVTYPE::IndexType* recvbufIndices;
10253 typename RECVTYPE::PrimalType* recvbufPrimals;
10254 typename RECVTYPE::PrimalType* recvbufOldPrimals;
10255 /* required for async */ void* recvbufAdjoints;
10259 RECVTYPE* recvtype;
10260 int root;
10262
10264 if(nullptr != sendbufIndices) {
10265 sendtype->getADTool().deleteIndexTypeBuffer(sendbufIndices);
10266 sendbufIndices = nullptr;
10267 }
10268 if(nullptr != sendbufPrimals) {
10269 sendtype->getADTool().deletePrimalTypeBuffer(sendbufPrimals);
10270 sendbufPrimals = nullptr;
10271 }
10272 if(nullptr != sendbufCount) {
10273 delete [] sendbufCount;
10274 sendbufCount = nullptr;
10275 }
10276 if(nullptr != recvbufIndices) {
10277 recvtype->getADTool().deleteIndexTypeBuffer(recvbufIndices);
10278 recvbufIndices = nullptr;
10279 }
10280 if(nullptr != recvbufPrimals) {
10281 recvtype->getADTool().deletePrimalTypeBuffer(recvbufPrimals);
10282 recvbufPrimals = nullptr;
10283 }
10284 if(nullptr != recvbufOldPrimals) {
10285 recvtype->getADTool().deletePrimalTypeBuffer(recvbufOldPrimals);
10286 recvbufOldPrimals = nullptr;
10287 }
10288 }
10289 };
10290
10291 template<typename SENDTYPE, typename RECVTYPE>
10293 const typename SENDTYPE::Type* sendbuf;
10294 typename SENDTYPE::ModifiedType* sendbufMod;
10295 const int* displsMod;
10296 const int* sendcounts;
10297 const int* displs;
10298 SENDTYPE* sendtype;
10299 typename RECVTYPE::Type* recvbuf;
10300 typename RECVTYPE::ModifiedType* recvbufMod;
10302 RECVTYPE* recvtype;
10303 int root;
10306 };
10307
10308 template<typename SENDTYPE, typename RECVTYPE>
10309 void AMPI_Iscatterv_p(HandleBase* handle, AdjointInterface* adjointInterface) {
10311 (handle);
10312
10313 h->recvbufAdjoints = nullptr;
10314 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
10315 adjointInterface->createPrimalTypeBuffer((void*&)h->recvbufPrimals, h->recvbufTotalSize );
10316 h->sendbufAdjoints = nullptr;
10317 if(h->root == getCommRank(h->comm)) {
10319 adjointInterface->getVectorSize());
10320 adjointInterface->createPrimalTypeBuffer((void*&)h->sendbufPrimals, h->sendbufTotalSize );
10321 // Primal buffers are always linear in space so we can accesses them in one sweep
10322 adjointInterface->getPrimals(h->sendbufIndices, h->sendbufPrimals, h->sendbufTotalSize);
10323
10324 }
10325
10326 AMPI_Iscatterv_pri<SENDTYPE, RECVTYPE>(h->sendbufPrimals, h->sendbufCountVec, h->sendbufDisplsVec, h->sendcounts,
10328 &h->requestReverse);
10329
10330 }
10331
10332 template<typename SENDTYPE, typename RECVTYPE>
10333 void AMPI_Iscatterv_p_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
10334
10336 (handle);
10337 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
10338
10339 if(h->root == getCommRank(h->comm)) {
10340 adjointInterface->deletePrimalTypeBuffer((void*&)h->sendbufPrimals);
10341 delete [] h->sendbufCountVec;
10342 delete [] h->sendbufDisplsVec;
10343 }
10344 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
10345 adjointInterface->getPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
10346 }
10347 // Primal buffers are always linear in space so we can accesses them in one sweep
10348 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufPrimals, h->recvbufTotalSize);
10349 adjointInterface->deletePrimalTypeBuffer((void*&)h->recvbufPrimals);
10350 }
10351
10352 template<typename SENDTYPE, typename RECVTYPE>
10353 void AMPI_Iscatterv_d(HandleBase* handle, AdjointInterface* adjointInterface) {
10355 (handle);
10356
10357 h->recvbufAdjoints = nullptr;
10358 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
10359 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
10360 h->sendbufAdjoints = nullptr;
10361 if(h->root == getCommRank(h->comm)) {
10363 adjointInterface->getVectorSize());
10364 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
10365 // Adjoint buffers are always linear in space so we can accesses them in one sweep
10366 adjointInterface->getAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
10367
10368 }
10369
10370 AMPI_Iscatterv_fwd<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendbufDisplsVec, h->sendcounts,
10372 &h->requestReverse);
10373
10374 }
10375
10376 template<typename SENDTYPE, typename RECVTYPE>
10377 void AMPI_Iscatterv_d_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
10378
10380 (handle);
10381 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
10382
10383 if(h->root == getCommRank(h->comm)) {
10384 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
10385 delete [] h->sendbufCountVec;
10386 delete [] h->sendbufDisplsVec;
10387 }
10388 // Adjoint buffers are always linear in space so we can accesses them in one sweep
10389 adjointInterface->updateAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
10390 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
10391 }
10392
10393 template<typename SENDTYPE, typename RECVTYPE>
10394 void AMPI_Iscatterv_b(HandleBase* handle, AdjointInterface* adjointInterface) {
10396 (handle);
10397
10398 h->recvbufAdjoints = nullptr;
10399 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
10400 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
10401 // Adjoint buffers are always linear in space so we can accesses them in one sweep
10402 adjointInterface->getAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
10403
10404 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
10405 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
10406 }
10407 h->sendbufAdjoints = nullptr;
10408 if(h->root == getCommRank(h->comm)) {
10410 adjointInterface->getVectorSize());
10411 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
10412 }
10413
10414 AMPI_Iscatterv_adj<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendbufDisplsVec, h->sendcounts,
10416 &h->requestReverse);
10417
10418 }
10419
10420 template<typename SENDTYPE, typename RECVTYPE>
10421 void AMPI_Iscatterv_b_finish(HandleBase* handle, AdjointInterface* adjointInterface) {
10422
10424 (handle);
10425 MPI_Wait(&h->requestReverse.request, MPI_STATUS_IGNORE);
10426
10427 if(h->root == getCommRank(h->comm)) {
10428 // Adjoint buffers are always linear in space so we can accesses them in one sweep
10429 adjointInterface->updateAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
10430 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
10431 delete [] h->sendbufCountVec;
10432 delete [] h->sendbufDisplsVec;
10433 }
10434 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
10435 }
10436
10437 template<typename SENDTYPE, typename RECVTYPE>
10438 int AMPI_Iscatterv_finish(HandleBase* handle);
10439 template<typename SENDTYPE, typename RECVTYPE>
10440 int AMPI_Iscatterv(const typename SENDTYPE::Type* sendbuf, const int* sendcounts, const int* displs, SENDTYPE* sendtype,
10441 typename RECVTYPE::Type* recvbuf, int recvcount, RECVTYPE* recvtype, int root, AMPI_Comm comm, AMPI_Request* request) {
10442 int rStatus;
10443
10444 if(!recvtype->getADTool().isActiveType()) {
10445 // call the regular function if the type is not active
10446 rStatus = MPI_Iscatterv(sendbuf, sendcounts, displs, sendtype->getMpiType(), recvbuf, recvcount, recvtype->getMpiType(),
10447 root, comm, &request->request);
10448 } else {
10449
10450 // the type is an AD type so handle the buffers
10452 MEDI_OPTIONAL_CONST int* displsMod = displs;
10453 int displsTotalSize = 0;
10454 if(nullptr != displs) {
10455 displsTotalSize = computeDisplacementsTotalSize(sendcounts, getCommSize(comm));
10456 if(recvtype->isModifiedBufferRequired()) {
10457 displsMod = createLinearDisplacements(sendcounts, getCommSize(comm));
10458 }
10459 }
10460 typename SENDTYPE::ModifiedType* sendbufMod = nullptr;
10461 int sendbufElements = 0;
10462
10463 if(root == getCommRank(comm)) {
10464 // compute the total size of the buffer
10465 sendbufElements = displsTotalSize;
10466
10467 if(sendtype->isModifiedBufferRequired() ) {
10468 sendtype->createModifiedTypeBuffer(sendbufMod, sendbufElements);
10469 } else {
10470 sendbufMod = reinterpret_cast<typename SENDTYPE::ModifiedType*>(const_cast<typename SENDTYPE::Type*>(sendbuf));
10471 }
10472 }
10473 typename RECVTYPE::ModifiedType* recvbufMod = nullptr;
10474 int recvbufElements = 0;
10475
10476 // compute the total size of the buffer
10477 if(AMPI_IN_PLACE != recvbuf) {
10478 recvbufElements = recvcount;
10479 } else {
10480 recvbufElements = sendcounts[getCommRank(comm)];
10481 }
10482
10483 if(recvtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == recvbuf)) {
10484 recvtype->createModifiedTypeBuffer(recvbufMod, recvbufElements);
10485 } else {
10486 recvbufMod = reinterpret_cast<typename RECVTYPE::ModifiedType*>(const_cast<typename RECVTYPE::Type*>(recvbuf));
10487 }
10488
10489 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
10490 if(recvtype->getADTool().isHandleRequired()) {
10492 }
10493 recvtype->getADTool().startAssembly(h);
10494 if(root == getCommRank(comm)) {
10495 if(sendtype->isModifiedBufferRequired()) {
10496 for(int i = 0; i < getCommSize(comm); ++i) {
10497 sendtype->copyIntoModifiedBuffer(sendbuf, displs[i], sendbufMod, displsMod[i], sendcounts[i]);
10498 }
10499 }
10500 }
10501
10502 if(nullptr != h) {
10503 // gather the information for the reverse sweep
10504
10505 // create the index buffers
10506 if(root == getCommRank(comm)) {
10507 createLinearIndexCounts(h->sendbufCount, sendcounts, displs, getCommSize(comm), sendtype);
10508 h->sendbufTotalSize = sendtype->computeActiveElements(sendbufElements);
10509 recvtype->getADTool().createIndexTypeBuffer(h->sendbufIndices, h->sendbufTotalSize);
10510 }
10511 if(AMPI_IN_PLACE != recvbuf) {
10512 h->recvbufCount = recvtype->computeActiveElements(recvcount);
10513 } else {
10514 h->recvbufCount = sendtype->computeActiveElements(displs[getCommRank(comm)] + sendcounts[getCommRank(
10515 comm)]) - sendtype->computeActiveElements(displs[getCommRank(comm)]);
10516 }
10517 h->recvbufTotalSize = recvtype->computeActiveElements(recvbufElements);
10518 recvtype->getADTool().createIndexTypeBuffer(h->recvbufIndices, h->recvbufTotalSize);
10519
10520
10521 // extract the old primal values from the recv buffer if the AD tool
10522 // needs the primal values reset
10523 if(recvtype->getADTool().isOldPrimalsRequired()) {
10524 recvtype->getADTool().createPrimalTypeBuffer(h->recvbufOldPrimals, h->recvbufTotalSize);
10525 if(AMPI_IN_PLACE != recvbuf) {
10526 recvtype->getValues(recvbuf, 0, h->recvbufOldPrimals, 0, recvcount);
10527 } else {
10528 {
10529 const int rank = getCommRank(comm);
10530 sendtype->getValues(sendbuf, displs[rank], h->recvbufOldPrimals, 0, sendcounts[rank]);
10531 }
10532 }
10533 }
10534
10535
10536 if(root == getCommRank(comm)) {
10537 for(int i = 0; i < getCommSize(comm); ++i) {
10538 sendtype->getIndices(sendbuf, displs[i], h->sendbufIndices, displsMod[i], sendcounts[i]);
10539 }
10540 }
10541
10542 if(AMPI_IN_PLACE != recvbuf) {
10543 recvtype->createIndices(recvbuf, 0, h->recvbufIndices, 0, recvcount);
10544 } else {
10545 {
10546 const int rank = getCommRank(comm);
10547 sendtype->createIndices(const_cast<typename SENDTYPE::Type*>(sendbuf), displs[rank], h->recvbufIndices, 0,
10548 sendcounts[rank]);
10549 }
10550 }
10551
10552 // pack all the variables in the handle
10553 h->funcReverse = AMPI_Iscatterv_b<SENDTYPE, RECVTYPE>;
10554 h->funcForward = AMPI_Iscatterv_d_finish<SENDTYPE, RECVTYPE>;
10555 h->funcPrimal = AMPI_Iscatterv_p_finish<SENDTYPE, RECVTYPE>;
10556 h->sendcounts = sendcounts;
10557 h->displs = displs;
10558 h->sendtype = sendtype;
10559 h->recvcount = recvcount;
10560 h->recvtype = recvtype;
10561 h->root = root;
10562 h->comm = comm;
10563 }
10564
10565 if(!recvtype->isModifiedBufferRequired()) {
10566 if(AMPI_IN_PLACE != recvbuf) {
10567 recvtype->clearIndices(recvbuf, 0, recvcount);
10568 } else {
10569 {
10570 const int rank = getCommRank(comm);
10571 sendtype->clearIndices(const_cast<typename SENDTYPE::Type*>(sendbuf), displs[rank], sendcounts[rank]);
10572 }
10573 }
10574 }
10575
10576 rStatus = MPI_Iscatterv(sendbufMod, sendcounts, displsMod, sendtype->getModifiedMpiType(), recvbufMod, recvcount,
10577 recvtype->getModifiedMpiType(), root, comm, &request->request);
10578
10580 asyncHandle->sendbuf = sendbuf;
10581 asyncHandle->sendbufMod = sendbufMod;
10582 asyncHandle->displsMod = displsMod;
10583 asyncHandle->sendcounts = sendcounts;
10584 asyncHandle->displs = displs;
10585 asyncHandle->sendtype = sendtype;
10586 asyncHandle->recvbuf = recvbuf;
10587 asyncHandle->recvbufMod = recvbufMod;
10588 asyncHandle->recvcount = recvcount;
10589 asyncHandle->recvtype = recvtype;
10590 asyncHandle->root = root;
10591 asyncHandle->comm = comm;
10592 asyncHandle->toolHandle = h;
10593 request->handle = asyncHandle;
10594 request->func = (ContinueFunction)AMPI_Iscatterv_finish<SENDTYPE, RECVTYPE>;
10595
10596 // create adjoint wait
10597 if(nullptr != h) {
10598 WaitHandle* waitH = new WaitHandle((ReverseFunction)AMPI_Iscatterv_b_finish<SENDTYPE, RECVTYPE>,
10599 (ForwardFunction)AMPI_Iscatterv_d<SENDTYPE, RECVTYPE>, h);
10600 recvtype->getADTool().addToolAction(waitH);
10601 }
10602 }
10603
10604 return rStatus;
10605 }
10606
10607 template<typename SENDTYPE, typename RECVTYPE>
10609 int rStatus = 0;
10610
10613 const typename SENDTYPE::Type* sendbuf = asyncHandle->sendbuf;
10614 typename SENDTYPE::ModifiedType* sendbufMod = asyncHandle->sendbufMod;
10615 const int* displsMod = asyncHandle->displsMod;
10616 const int* sendcounts = asyncHandle->sendcounts;
10617 const int* displs = asyncHandle->displs;
10618 SENDTYPE* sendtype = asyncHandle->sendtype;
10619 typename RECVTYPE::Type* recvbuf = asyncHandle->recvbuf;
10620 typename RECVTYPE::ModifiedType* recvbufMod = asyncHandle->recvbufMod;
10621 int recvcount = asyncHandle->recvcount;
10622 RECVTYPE* recvtype = asyncHandle->recvtype;
10623 int root = asyncHandle->root;
10624 AMPI_Comm comm = asyncHandle->comm;
10625 AMPI_Request* request = asyncHandle->request;
10627 (asyncHandle->toolHandle);
10628 MEDI_UNUSED(h); // Unused generated to ignore warnings
10629 MEDI_UNUSED(sendbuf); // Unused generated to ignore warnings
10630 MEDI_UNUSED(sendbufMod); // Unused generated to ignore warnings
10631 MEDI_UNUSED(displsMod); // Unused generated to ignore warnings
10632 MEDI_UNUSED(sendcounts); // Unused generated to ignore warnings
10633 MEDI_UNUSED(displs); // Unused generated to ignore warnings
10634 MEDI_UNUSED(sendtype); // Unused generated to ignore warnings
10635 MEDI_UNUSED(recvbuf); // Unused generated to ignore warnings
10636 MEDI_UNUSED(recvbufMod); // Unused generated to ignore warnings
10637 MEDI_UNUSED(recvcount); // Unused generated to ignore warnings
10638 MEDI_UNUSED(recvtype); // Unused generated to ignore warnings
10639 MEDI_UNUSED(root); // Unused generated to ignore warnings
10640 MEDI_UNUSED(comm); // Unused generated to ignore warnings
10641 MEDI_UNUSED(request); // Unused generated to ignore warnings
10642
10643 delete asyncHandle;
10644
10645 if(recvtype->getADTool().isActiveType()) {
10646
10647 recvtype->getADTool().addToolAction(h);
10648
10649 if(recvtype->isModifiedBufferRequired()) {
10650 if(AMPI_IN_PLACE != recvbuf) {
10651 recvtype->copyFromModifiedBuffer(recvbuf, 0, recvbufMod, 0, recvcount);
10652 } else {
10653 {
10654 const int rank = getCommRank(comm);
10655 sendtype->copyFromModifiedBuffer(const_cast<typename SENDTYPE::Type*>(sendbuf), displs[rank], sendbufMod,
10656 displsMod[rank], sendcounts[rank]);
10657 }
10658 }
10659 }
10660
10661 if(nullptr != h) {
10662 // handle the recv buffers
10663 if(AMPI_IN_PLACE != recvbuf) {
10664 recvtype->registerValue(recvbuf, 0, h->recvbufIndices, h->recvbufOldPrimals, 0, recvcount);
10665 } else {
10666 {
10667 const int rank = getCommRank(comm);
10668 sendtype->registerValue(const_cast<typename SENDTYPE::Type*>(sendbuf), displs[rank], h->recvbufIndices,
10669 h->recvbufOldPrimals, 0, sendcounts[rank]);
10670 }
10671 }
10672 }
10673
10674 recvtype->getADTool().stopAssembly(h);
10675 if(recvtype->isModifiedBufferRequired()) {
10676 delete [] displsMod;
10677 }
10678
10679 if(root == getCommRank(comm)) {
10680 if(sendtype->isModifiedBufferRequired() ) {
10681 sendtype->deleteModifiedTypeBuffer(sendbufMod);
10682 }
10683 }
10684 if(recvtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == recvbuf)) {
10685 recvtype->deleteModifiedTypeBuffer(recvbufMod);
10686 }
10687
10688 // handle is deleted by the AD tool
10689 }
10690
10691 return rStatus;
10692 }
10693
10694#endif
10695#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
10696 template<typename DATATYPE>
10699 typename DATATYPE::IndexType* sendbufIndices;
10700 typename DATATYPE::PrimalType* sendbufPrimals;
10701 /* required for async */ void* sendbufAdjoints;
10705 typename DATATYPE::IndexType* recvbufIndices;
10706 typename DATATYPE::PrimalType* recvbufPrimals;
10707 typename DATATYPE::PrimalType* recvbufOldPrimals;
10708 /* required for async */ void* recvbufAdjoints;
10712 DATATYPE* datatype;
10714 int root;
10716
10718 if(nullptr != sendbufIndices) {
10719 datatype->getADTool().deleteIndexTypeBuffer(sendbufIndices);
10720 sendbufIndices = nullptr;
10721 }
10722 if(nullptr != sendbufPrimals) {
10723 datatype->getADTool().deletePrimalTypeBuffer(sendbufPrimals);
10724 sendbufPrimals = nullptr;
10725 }
10726 if(nullptr != recvbufIndices) {
10727 datatype->getADTool().deleteIndexTypeBuffer(recvbufIndices);
10728 recvbufIndices = nullptr;
10729 }
10730 if(nullptr != recvbufPrimals) {
10731 datatype->getADTool().deletePrimalTypeBuffer(recvbufPrimals);
10732 recvbufPrimals = nullptr;
10733 }
10734 if(nullptr != recvbufOldPrimals) {
10735 datatype->getADTool().deletePrimalTypeBuffer(recvbufOldPrimals);
10736 recvbufOldPrimals = nullptr;
10737 }
10738 }
10739 };
10740
10741
10742 template<typename DATATYPE>
10743 void AMPI_Reduce_global_p(HandleBase* handle, AdjointInterface* adjointInterface) {
10745
10746 AMPI_Op convOp = h->datatype->getADTool().convertOperator(h->op);
10747 (void)convOp;
10748 h->recvbufAdjoints = nullptr;
10749 if(h->root == getCommRank(h->comm)) {
10750 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
10751 adjointInterface->createPrimalTypeBuffer((void*&)h->recvbufPrimals, h->recvbufTotalSize );
10752 }
10753 h->sendbufAdjoints = nullptr;
10754 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
10755 adjointInterface->createPrimalTypeBuffer((void*&)h->sendbufPrimals, h->sendbufTotalSize );
10756 // Primal buffers are always linear in space so we can accesses them in one sweep
10757 adjointInterface->getPrimals(h->sendbufIndices, h->sendbufPrimals, h->sendbufTotalSize);
10758
10759
10760 AMPI_Reduce_global_pri<DATATYPE>(h->sendbufPrimals, h->sendbufCountVec, h->recvbufPrimals, h->recvbufCountVec, h->count,
10761 h->datatype, h->op, h->root, h->comm);
10762
10763 adjointInterface->deletePrimalTypeBuffer((void*&)h->sendbufPrimals);
10764 if(h->datatype->getADTool().isOldPrimalsRequired()) {
10765 if(h->root == getCommRank(h->comm)) {
10766 adjointInterface->getPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
10767 }
10768 }
10769 if(h->root == getCommRank(h->comm)) {
10770 // Primal buffers are always linear in space so we can accesses them in one sweep
10771 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufPrimals, h->recvbufTotalSize);
10772 adjointInterface->deletePrimalTypeBuffer((void*&)h->recvbufPrimals);
10773 }
10774 }
10775
10776 template<typename DATATYPE>
10777 void AMPI_Reduce_global_d(HandleBase* handle, AdjointInterface* adjointInterface) {
10779
10780 AMPI_Op convOp = h->datatype->getADTool().convertOperator(h->op);
10781 (void)convOp;
10782 h->recvbufAdjoints = nullptr;
10783 if(h->root == getCommRank(h->comm)) {
10784 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
10785 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
10786 }
10787 h->sendbufAdjoints = nullptr;
10788 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
10789 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
10790 // Adjoint buffers are always linear in space so we can accesses them in one sweep
10791 adjointInterface->getAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
10792
10793
10794 AMPI_Reduce_global_fwd<DATATYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->recvbufAdjoints, h->recvbufCountVec,
10795 h->count, h->datatype, h->op, h->root, h->comm);
10796
10797 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
10798 if(h->root == getCommRank(h->comm)) {
10799 // Adjoint buffers are always linear in space so we can accesses them in one sweep
10800 adjointInterface->updateAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
10801 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
10802 }
10803 }
10804
10805 template<typename DATATYPE>
10806 void AMPI_Reduce_global_b(HandleBase* handle, AdjointInterface* adjointInterface) {
10808
10809 AMPI_Op convOp = h->datatype->getADTool().convertOperator(h->op);
10810 (void)convOp;
10811 h->recvbufAdjoints = nullptr;
10812 if(h->root == getCommRank(h->comm)) {
10813 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
10814 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
10815 // Adjoint buffers are always linear in space so we can accesses them in one sweep
10816 adjointInterface->getAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
10817
10818 convOp.preAdjointOperation(h->recvbufAdjoints, h->recvbufPrimals, h->recvbufCount, adjointInterface->getVectorSize());
10819 }
10820 if(h->datatype->getADTool().isOldPrimalsRequired()) {
10821 if(h->root == getCommRank(h->comm)) {
10822 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
10823 }
10824 }
10825 h->sendbufAdjoints = nullptr;
10826 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
10827 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
10828
10829 AMPI_Reduce_global_adj<DATATYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->recvbufAdjoints, h->recvbufCountVec,
10830 h->count, h->datatype, h->op, h->root, h->comm);
10831
10832 // the primals of the recive buffer are always given to the function. The operator should ignore them if not needed.
10833 // The wrapper functions make sure that for operators that need the primals an all* action is perfomed (e.g. Allreduce instead of Reduce)
10834 convOp.postAdjointOperation(h->sendbufAdjoints, h->sendbufPrimals, h->recvbufPrimals, h->sendbufTotalSize,
10835 adjointInterface->getVectorSize());
10836 // Adjoint buffers are always linear in space so we can accesses them in one sweep
10837 adjointInterface->updateAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
10838 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
10839 if(h->root == getCommRank(h->comm)) {
10840 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
10841 }
10842 }
10843
10844 template<typename DATATYPE>
10845 int AMPI_Reduce_global(MEDI_OPTIONAL_CONST typename DATATYPE::Type* sendbuf, typename DATATYPE::Type* recvbuf,
10846 int count, DATATYPE* datatype, AMPI_Op op, int root, AMPI_Comm comm) {
10847 int rStatus;
10848 AMPI_Op convOp = datatype->getADTool().convertOperator(op);
10849 (void)convOp;
10850
10851 if(!datatype->getADTool().isActiveType()) {
10852 // call the regular function if the type is not active
10853 rStatus = MPI_Reduce(sendbuf, recvbuf, count, datatype->getMpiType(), convOp.primalFunction, root, comm);
10854 } else {
10855
10856 // the type is an AD type so handle the buffers
10858 typename DATATYPE::ModifiedType* sendbufMod = nullptr;
10859 int sendbufElements = 0;
10860
10861 // compute the total size of the buffer
10862 if(AMPI_IN_PLACE != sendbuf) {
10863 sendbufElements = count;
10864 } else {
10865 sendbufElements = count;
10866 }
10867
10868 if(datatype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
10869 datatype->createModifiedTypeBuffer(sendbufMod, sendbufElements);
10870 } else {
10871 sendbufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(sendbuf));
10872 }
10873 typename DATATYPE::ModifiedType* recvbufMod = nullptr;
10874 int recvbufElements = 0;
10875
10876 if(root == getCommRank(comm)) {
10877 // compute the total size of the buffer
10878 recvbufElements = count;
10879
10880 if(datatype->isModifiedBufferRequired() ) {
10881 datatype->createModifiedTypeBuffer(recvbufMod, recvbufElements);
10882 } else {
10883 recvbufMod = reinterpret_cast<typename DATATYPE::ModifiedType*>(const_cast<typename DATATYPE::Type*>(recvbuf));
10884 }
10885 }
10886
10887 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
10888 if(datatype->getADTool().isHandleRequired()) {
10890 }
10891 datatype->getADTool().startAssembly(h);
10892 if(datatype->isModifiedBufferRequired()) {
10893 if(AMPI_IN_PLACE != sendbuf) {
10894 datatype->copyIntoModifiedBuffer(sendbuf, 0, sendbufMod, 0, count);
10895 } else {
10896 datatype->copyIntoModifiedBuffer(recvbuf, 0, recvbufMod, 0, count);
10897 }
10898 }
10899
10900 if(nullptr != h) {
10901 // gather the information for the reverse sweep
10902
10903 // create the index buffers
10904 if(AMPI_IN_PLACE != sendbuf) {
10905 h->sendbufCount = datatype->computeActiveElements(count);
10906 } else {
10907 h->sendbufCount = datatype->computeActiveElements(count);
10908 }
10909 h->sendbufTotalSize = datatype->computeActiveElements(sendbufElements);
10910 datatype->getADTool().createIndexTypeBuffer(h->sendbufIndices, h->sendbufTotalSize);
10911 if(root == getCommRank(comm)) {
10912 h->recvbufCount = datatype->computeActiveElements(count);
10913 h->recvbufTotalSize = datatype->computeActiveElements(recvbufElements);
10914 datatype->getADTool().createIndexTypeBuffer(h->recvbufIndices, h->recvbufTotalSize);
10915 }
10916
10917 // extract the primal values for the operator if required
10918 if(convOp.requiresPrimal) {
10919 datatype->getADTool().createPrimalTypeBuffer(h->sendbufPrimals, h->sendbufTotalSize);
10920 if(AMPI_IN_PLACE != sendbuf) {
10921 datatype->getValues(sendbuf, 0, h->sendbufPrimals, 0, count);
10922 } else {
10923 datatype->getValues(recvbuf, 0, h->sendbufPrimals, 0, count);
10924 }
10925 }
10926
10927 // extract the old primal values from the recv buffer if the AD tool
10928 // needs the primal values reset
10929 if(datatype->getADTool().isOldPrimalsRequired()) {
10930 if(root == getCommRank(comm)) {
10931 datatype->getADTool().createPrimalTypeBuffer(h->recvbufOldPrimals, h->recvbufTotalSize);
10932 if(root == getCommRank(comm)) {
10933 datatype->getValues(recvbuf, 0, h->recvbufOldPrimals, 0, count);
10934 }
10935 }
10936 }
10937
10938
10939 if(AMPI_IN_PLACE != sendbuf) {
10940 datatype->getIndices(sendbuf, 0, h->sendbufIndices, 0, count);
10941 } else {
10942 datatype->getIndices(recvbuf, 0, h->sendbufIndices, 0, count);
10943 }
10944
10945 if(root == getCommRank(comm)) {
10946 datatype->createIndices(recvbuf, 0, h->recvbufIndices, 0, count);
10947 }
10948
10949 // pack all the variables in the handle
10950 h->funcReverse = AMPI_Reduce_global_b<DATATYPE>;
10951 h->funcForward = AMPI_Reduce_global_d<DATATYPE>;
10952 h->funcPrimal = AMPI_Reduce_global_p<DATATYPE>;
10953 h->count = count;
10954 h->datatype = datatype;
10955 h->op = op;
10956 h->root = root;
10957 h->comm = comm;
10958 }
10959
10960 if(root == getCommRank(comm)) {
10961 if(!datatype->isModifiedBufferRequired()) {
10962 datatype->clearIndices(recvbuf, 0, count);
10963 }
10964 }
10965
10966 rStatus = MPI_Reduce(sendbufMod, recvbufMod, count, datatype->getModifiedMpiType(), convOp.modifiedPrimalFunction, root,
10967 comm);
10968 datatype->getADTool().addToolAction(h);
10969
10970 if(root == getCommRank(comm)) {
10971 if(datatype->isModifiedBufferRequired()) {
10972 datatype->copyFromModifiedBuffer(recvbuf, 0, recvbufMod, 0, count);
10973 }
10974 }
10975
10976 if(nullptr != h) {
10977 // handle the recv buffers
10978 if(root == getCommRank(comm)) {
10979 datatype->registerValue(recvbuf, 0, h->recvbufIndices, h->recvbufOldPrimals, 0, count);
10980 }
10981 }
10982 // extract the primal values for the operator if required
10983 if(nullptr != h && convOp.requiresPrimal) {
10984 if(root == getCommRank(comm)) {
10985 datatype->getADTool().createPrimalTypeBuffer(h->recvbufPrimals, h->recvbufTotalSize);
10986 if(root == getCommRank(comm)) {
10987 datatype->getValues(recvbuf, 0, h->recvbufPrimals, 0, count);
10988 }
10989 }
10990 }
10991
10992 datatype->getADTool().stopAssembly(h);
10993
10994 if(datatype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == sendbuf)) {
10995 datatype->deleteModifiedTypeBuffer(sendbufMod);
10996 }
10997 if(root == getCommRank(comm)) {
10998 if(datatype->isModifiedBufferRequired() ) {
10999 datatype->deleteModifiedTypeBuffer(recvbufMod);
11000 }
11001 }
11002
11003 // handle is deleted by the AD tool
11004 }
11005
11006 return rStatus;
11007 }
11008
11009#endif
11010#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11011 template<typename SENDTYPE, typename RECVTYPE>
11014 typename SENDTYPE::IndexType* sendbufIndices;
11015 typename SENDTYPE::PrimalType* sendbufPrimals;
11016 /* required for async */ void* sendbufAdjoints;
11020 SENDTYPE* sendtype;
11022 typename RECVTYPE::IndexType* recvbufIndices;
11023 typename RECVTYPE::PrimalType* recvbufPrimals;
11024 typename RECVTYPE::PrimalType* recvbufOldPrimals;
11025 /* required for async */ void* recvbufAdjoints;
11029 RECVTYPE* recvtype;
11030 int root;
11032
11034 if(nullptr != sendbufIndices) {
11035 sendtype->getADTool().deleteIndexTypeBuffer(sendbufIndices);
11036 sendbufIndices = nullptr;
11037 }
11038 if(nullptr != sendbufPrimals) {
11039 sendtype->getADTool().deletePrimalTypeBuffer(sendbufPrimals);
11040 sendbufPrimals = nullptr;
11041 }
11042 if(nullptr != recvbufIndices) {
11043 recvtype->getADTool().deleteIndexTypeBuffer(recvbufIndices);
11044 recvbufIndices = nullptr;
11045 }
11046 if(nullptr != recvbufPrimals) {
11047 recvtype->getADTool().deletePrimalTypeBuffer(recvbufPrimals);
11048 recvbufPrimals = nullptr;
11049 }
11050 if(nullptr != recvbufOldPrimals) {
11051 recvtype->getADTool().deletePrimalTypeBuffer(recvbufOldPrimals);
11052 recvbufOldPrimals = nullptr;
11053 }
11054 }
11055 };
11056
11057
11058 template<typename SENDTYPE, typename RECVTYPE>
11059 void AMPI_Scatter_p(HandleBase* handle, AdjointInterface* adjointInterface) {
11061 (handle);
11062
11063 h->recvbufAdjoints = nullptr;
11064 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
11065 adjointInterface->createPrimalTypeBuffer((void*&)h->recvbufPrimals, h->recvbufTotalSize );
11066 h->sendbufAdjoints = nullptr;
11067 if(h->root == getCommRank(h->comm)) {
11068 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
11069 adjointInterface->createPrimalTypeBuffer((void*&)h->sendbufPrimals, h->sendbufTotalSize );
11070 // Primal buffers are always linear in space so we can accesses them in one sweep
11071 adjointInterface->getPrimals(h->sendbufIndices, h->sendbufPrimals, h->sendbufTotalSize);
11072
11073 }
11074
11075 AMPI_Scatter_pri<SENDTYPE, RECVTYPE>(h->sendbufPrimals, h->sendbufCountVec, h->sendcount, h->sendtype,
11076 h->recvbufPrimals, h->recvbufCountVec, h->recvcount, h->recvtype, h->root, h->comm);
11077
11078 if(h->root == getCommRank(h->comm)) {
11079 adjointInterface->deletePrimalTypeBuffer((void*&)h->sendbufPrimals);
11080 }
11081 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
11082 adjointInterface->getPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
11083 }
11084 // Primal buffers are always linear in space so we can accesses them in one sweep
11085 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufPrimals, h->recvbufTotalSize);
11086 adjointInterface->deletePrimalTypeBuffer((void*&)h->recvbufPrimals);
11087 }
11088
11089 template<typename SENDTYPE, typename RECVTYPE>
11090 void AMPI_Scatter_d(HandleBase* handle, AdjointInterface* adjointInterface) {
11092 (handle);
11093
11094 h->recvbufAdjoints = nullptr;
11095 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
11096 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
11097 h->sendbufAdjoints = nullptr;
11098 if(h->root == getCommRank(h->comm)) {
11099 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
11100 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
11101 // Adjoint buffers are always linear in space so we can accesses them in one sweep
11102 adjointInterface->getAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
11103
11104 }
11105
11106 AMPI_Scatter_fwd<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype,
11108
11109 if(h->root == getCommRank(h->comm)) {
11110 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
11111 }
11112 // Adjoint buffers are always linear in space so we can accesses them in one sweep
11113 adjointInterface->updateAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
11114 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
11115 }
11116
11117 template<typename SENDTYPE, typename RECVTYPE>
11118 void AMPI_Scatter_b(HandleBase* handle, AdjointInterface* adjointInterface) {
11120 (handle);
11121
11122 h->recvbufAdjoints = nullptr;
11123 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
11124 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
11125 // Adjoint buffers are always linear in space so we can accesses them in one sweep
11126 adjointInterface->getAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
11127
11128 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
11129 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
11130 }
11131 h->sendbufAdjoints = nullptr;
11132 if(h->root == getCommRank(h->comm)) {
11133 h->sendbufCountVec = adjointInterface->getVectorSize() * h->sendbufCount;
11134 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
11135 }
11136
11137 AMPI_Scatter_adj<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendcount, h->sendtype,
11139
11140 if(h->root == getCommRank(h->comm)) {
11141 // Adjoint buffers are always linear in space so we can accesses them in one sweep
11142 adjointInterface->updateAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
11143 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
11144 }
11145 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
11146 }
11147
11148 template<typename SENDTYPE, typename RECVTYPE>
11149 int AMPI_Scatter(MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf, int sendcount, SENDTYPE* sendtype,
11150 typename RECVTYPE::Type* recvbuf, int recvcount, RECVTYPE* recvtype, int root, AMPI_Comm comm) {
11151 int rStatus;
11152
11153 if(!recvtype->getADTool().isActiveType()) {
11154 // call the regular function if the type is not active
11155 rStatus = MPI_Scatter(sendbuf, sendcount, sendtype->getMpiType(), recvbuf, recvcount, recvtype->getMpiType(), root,
11156 comm);
11157 } else {
11158
11159 // the type is an AD type so handle the buffers
11161 typename SENDTYPE::ModifiedType* sendbufMod = nullptr;
11162 int sendbufElements = 0;
11163
11164 if(root == getCommRank(comm)) {
11165 // compute the total size of the buffer
11166 sendbufElements = sendcount * getCommSize(comm);
11167
11168 if(sendtype->isModifiedBufferRequired() ) {
11169 sendtype->createModifiedTypeBuffer(sendbufMod, sendbufElements);
11170 } else {
11171 sendbufMod = reinterpret_cast<typename SENDTYPE::ModifiedType*>(const_cast<typename SENDTYPE::Type*>(sendbuf));
11172 }
11173 }
11174 typename RECVTYPE::ModifiedType* recvbufMod = nullptr;
11175 int recvbufElements = 0;
11176
11177 // compute the total size of the buffer
11178 if(AMPI_IN_PLACE != recvbuf) {
11179 recvbufElements = recvcount;
11180 } else {
11181 recvbufElements = sendcount;
11182 }
11183
11184 if(recvtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == recvbuf)) {
11185 recvtype->createModifiedTypeBuffer(recvbufMod, recvbufElements);
11186 } else {
11187 recvbufMod = reinterpret_cast<typename RECVTYPE::ModifiedType*>(const_cast<typename RECVTYPE::Type*>(recvbuf));
11188 }
11189
11190 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
11191 if(recvtype->getADTool().isHandleRequired()) {
11193 }
11194 recvtype->getADTool().startAssembly(h);
11195 if(root == getCommRank(comm)) {
11196 if(sendtype->isModifiedBufferRequired()) {
11197 sendtype->copyIntoModifiedBuffer(sendbuf, 0, sendbufMod, 0, sendcount * getCommSize(comm));
11198 }
11199 }
11200
11201 if(nullptr != h) {
11202 // gather the information for the reverse sweep
11203
11204 // create the index buffers
11205 if(root == getCommRank(comm)) {
11206 h->sendbufCount = sendtype->computeActiveElements(sendcount);
11207 h->sendbufTotalSize = sendtype->computeActiveElements(sendbufElements);
11208 recvtype->getADTool().createIndexTypeBuffer(h->sendbufIndices, h->sendbufTotalSize);
11209 }
11210 if(AMPI_IN_PLACE != recvbuf) {
11211 h->recvbufCount = recvtype->computeActiveElements(recvcount);
11212 } else {
11213 h->recvbufCount = sendtype->computeActiveElements(sendcount);
11214 }
11215 h->recvbufTotalSize = recvtype->computeActiveElements(recvbufElements);
11216 recvtype->getADTool().createIndexTypeBuffer(h->recvbufIndices, h->recvbufTotalSize);
11217
11218
11219 // extract the old primal values from the recv buffer if the AD tool
11220 // needs the primal values reset
11221 if(recvtype->getADTool().isOldPrimalsRequired()) {
11222 recvtype->getADTool().createPrimalTypeBuffer(h->recvbufOldPrimals, h->recvbufTotalSize);
11223 if(AMPI_IN_PLACE != recvbuf) {
11224 recvtype->getValues(recvbuf, 0, h->recvbufOldPrimals, 0, recvcount);
11225 } else {
11226 sendtype->getValues(sendbuf, sendcount * getCommRank(comm), h->recvbufOldPrimals, 0, sendcount);
11227 }
11228 }
11229
11230
11231 if(root == getCommRank(comm)) {
11232 sendtype->getIndices(sendbuf, 0, h->sendbufIndices, 0, sendcount * getCommSize(comm));
11233 }
11234
11235 if(AMPI_IN_PLACE != recvbuf) {
11236 recvtype->createIndices(recvbuf, 0, h->recvbufIndices, 0, recvcount);
11237 } else {
11238 sendtype->createIndices(const_cast<typename SENDTYPE::Type*>(sendbuf), sendcount * getCommRank(comm), h->recvbufIndices,
11239 0, sendcount);
11240 }
11241
11242 // pack all the variables in the handle
11243 h->funcReverse = AMPI_Scatter_b<SENDTYPE, RECVTYPE>;
11244 h->funcForward = AMPI_Scatter_d<SENDTYPE, RECVTYPE>;
11245 h->funcPrimal = AMPI_Scatter_p<SENDTYPE, RECVTYPE>;
11246 h->sendcount = sendcount;
11247 h->sendtype = sendtype;
11248 h->recvcount = recvcount;
11249 h->recvtype = recvtype;
11250 h->root = root;
11251 h->comm = comm;
11252 }
11253
11254 if(!recvtype->isModifiedBufferRequired()) {
11255 if(AMPI_IN_PLACE != recvbuf) {
11256 recvtype->clearIndices(recvbuf, 0, recvcount);
11257 } else {
11258 sendtype->clearIndices(const_cast<typename SENDTYPE::Type*>(sendbuf), sendcount * getCommRank(comm), sendcount);
11259 }
11260 }
11261
11262 rStatus = MPI_Scatter(sendbufMod, sendcount, sendtype->getModifiedMpiType(), recvbufMod, recvcount,
11263 recvtype->getModifiedMpiType(), root, comm);
11264 recvtype->getADTool().addToolAction(h);
11265
11266 if(recvtype->isModifiedBufferRequired()) {
11267 if(AMPI_IN_PLACE != recvbuf) {
11268 recvtype->copyFromModifiedBuffer(recvbuf, 0, recvbufMod, 0, recvcount);
11269 } else {
11270 sendtype->copyFromModifiedBuffer(const_cast<typename SENDTYPE::Type*>(sendbuf), sendcount * getCommRank(comm),
11271 sendbufMod, sendcount * getCommRank(comm), sendcount);
11272 }
11273 }
11274
11275 if(nullptr != h) {
11276 // handle the recv buffers
11277 if(AMPI_IN_PLACE != recvbuf) {
11278 recvtype->registerValue(recvbuf, 0, h->recvbufIndices, h->recvbufOldPrimals, 0, recvcount);
11279 } else {
11280 sendtype->registerValue(const_cast<typename SENDTYPE::Type*>(sendbuf), sendcount * getCommRank(comm), h->recvbufIndices,
11281 h->recvbufOldPrimals, 0, sendcount);
11282 }
11283 }
11284
11285 recvtype->getADTool().stopAssembly(h);
11286
11287 if(root == getCommRank(comm)) {
11288 if(sendtype->isModifiedBufferRequired() ) {
11289 sendtype->deleteModifiedTypeBuffer(sendbufMod);
11290 }
11291 }
11292 if(recvtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == recvbuf)) {
11293 recvtype->deleteModifiedTypeBuffer(recvbufMod);
11294 }
11295
11296 // handle is deleted by the AD tool
11297 }
11298
11299 return rStatus;
11300 }
11301
11302#endif
11303#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11304 template<typename SENDTYPE, typename RECVTYPE>
11307 typename SENDTYPE::IndexType* sendbufIndices;
11308 typename SENDTYPE::PrimalType* sendbufPrimals;
11309 /* required for async */ void* sendbufAdjoints;
11311 /* required for async */ int* sendbufCountVec;
11312 /* required for async */ int* sendbufDisplsVec;
11313 const int* sendcounts;
11314 const int* displs;
11315 SENDTYPE* sendtype;
11317 typename RECVTYPE::IndexType* recvbufIndices;
11318 typename RECVTYPE::PrimalType* recvbufPrimals;
11319 typename RECVTYPE::PrimalType* recvbufOldPrimals;
11320 /* required for async */ void* recvbufAdjoints;
11324 RECVTYPE* recvtype;
11325 int root;
11327
11329 if(nullptr != sendbufIndices) {
11330 sendtype->getADTool().deleteIndexTypeBuffer(sendbufIndices);
11331 sendbufIndices = nullptr;
11332 }
11333 if(nullptr != sendbufPrimals) {
11334 sendtype->getADTool().deletePrimalTypeBuffer(sendbufPrimals);
11335 sendbufPrimals = nullptr;
11336 }
11337 if(nullptr != sendbufCount) {
11338 delete [] sendbufCount;
11339 sendbufCount = nullptr;
11340 }
11341 if(nullptr != recvbufIndices) {
11342 recvtype->getADTool().deleteIndexTypeBuffer(recvbufIndices);
11343 recvbufIndices = nullptr;
11344 }
11345 if(nullptr != recvbufPrimals) {
11346 recvtype->getADTool().deletePrimalTypeBuffer(recvbufPrimals);
11347 recvbufPrimals = nullptr;
11348 }
11349 if(nullptr != recvbufOldPrimals) {
11350 recvtype->getADTool().deletePrimalTypeBuffer(recvbufOldPrimals);
11351 recvbufOldPrimals = nullptr;
11352 }
11353 }
11354 };
11355
11356
11357 template<typename SENDTYPE, typename RECVTYPE>
11358 void AMPI_Scatterv_p(HandleBase* handle, AdjointInterface* adjointInterface) {
11360 (handle);
11361
11362 h->recvbufAdjoints = nullptr;
11363 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
11364 adjointInterface->createPrimalTypeBuffer((void*&)h->recvbufPrimals, h->recvbufTotalSize );
11365 h->sendbufAdjoints = nullptr;
11366 if(h->root == getCommRank(h->comm)) {
11368 adjointInterface->getVectorSize());
11369 adjointInterface->createPrimalTypeBuffer((void*&)h->sendbufPrimals, h->sendbufTotalSize );
11370 // Primal buffers are always linear in space so we can accesses them in one sweep
11371 adjointInterface->getPrimals(h->sendbufIndices, h->sendbufPrimals, h->sendbufTotalSize);
11372
11373 }
11374
11375 AMPI_Scatterv_pri<SENDTYPE, RECVTYPE>(h->sendbufPrimals, h->sendbufCountVec, h->sendbufDisplsVec, h->sendcounts,
11376 h->displs, h->sendtype, h->recvbufPrimals, h->recvbufCountVec, h->recvcount, h->recvtype, h->root, h->comm);
11377
11378 if(h->root == getCommRank(h->comm)) {
11379 adjointInterface->deletePrimalTypeBuffer((void*&)h->sendbufPrimals);
11380 delete [] h->sendbufCountVec;
11381 delete [] h->sendbufDisplsVec;
11382 }
11383 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
11384 adjointInterface->getPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
11385 }
11386 // Primal buffers are always linear in space so we can accesses them in one sweep
11387 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufPrimals, h->recvbufTotalSize);
11388 adjointInterface->deletePrimalTypeBuffer((void*&)h->recvbufPrimals);
11389 }
11390
11391 template<typename SENDTYPE, typename RECVTYPE>
11392 void AMPI_Scatterv_d(HandleBase* handle, AdjointInterface* adjointInterface) {
11394 (handle);
11395
11396 h->recvbufAdjoints = nullptr;
11397 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
11398 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
11399 h->sendbufAdjoints = nullptr;
11400 if(h->root == getCommRank(h->comm)) {
11402 adjointInterface->getVectorSize());
11403 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
11404 // Adjoint buffers are always linear in space so we can accesses them in one sweep
11405 adjointInterface->getAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
11406
11407 }
11408
11409 AMPI_Scatterv_fwd<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendbufDisplsVec, h->sendcounts,
11410 h->displs, h->sendtype, h->recvbufAdjoints, h->recvbufCountVec, h->recvcount, h->recvtype, h->root, h->comm);
11411
11412 if(h->root == getCommRank(h->comm)) {
11413 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
11414 delete [] h->sendbufCountVec;
11415 delete [] h->sendbufDisplsVec;
11416 }
11417 // Adjoint buffers are always linear in space so we can accesses them in one sweep
11418 adjointInterface->updateAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
11419 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
11420 }
11421
11422 template<typename SENDTYPE, typename RECVTYPE>
11423 void AMPI_Scatterv_b(HandleBase* handle, AdjointInterface* adjointInterface) {
11425 (handle);
11426
11427 h->recvbufAdjoints = nullptr;
11428 h->recvbufCountVec = adjointInterface->getVectorSize() * h->recvbufCount;
11429 adjointInterface->createAdjointTypeBuffer(h->recvbufAdjoints, h->recvbufTotalSize );
11430 // Adjoint buffers are always linear in space so we can accesses them in one sweep
11431 adjointInterface->getAdjoints(h->recvbufIndices, h->recvbufAdjoints, h->recvbufTotalSize);
11432
11433 if(h->recvtype->getADTool().isOldPrimalsRequired()) {
11434 adjointInterface->setPrimals(h->recvbufIndices, h->recvbufOldPrimals, h->recvbufTotalSize);
11435 }
11436 h->sendbufAdjoints = nullptr;
11437 if(h->root == getCommRank(h->comm)) {
11439 adjointInterface->getVectorSize());
11440 adjointInterface->createAdjointTypeBuffer(h->sendbufAdjoints, h->sendbufTotalSize );
11441 }
11442
11443 AMPI_Scatterv_adj<SENDTYPE, RECVTYPE>(h->sendbufAdjoints, h->sendbufCountVec, h->sendbufDisplsVec, h->sendcounts,
11444 h->displs, h->sendtype, h->recvbufAdjoints, h->recvbufCountVec, h->recvcount, h->recvtype, h->root, h->comm);
11445
11446 if(h->root == getCommRank(h->comm)) {
11447 // Adjoint buffers are always linear in space so we can accesses them in one sweep
11448 adjointInterface->updateAdjoints(h->sendbufIndices, h->sendbufAdjoints, h->sendbufTotalSize);
11449 adjointInterface->deleteAdjointTypeBuffer(h->sendbufAdjoints);
11450 delete [] h->sendbufCountVec;
11451 delete [] h->sendbufDisplsVec;
11452 }
11453 adjointInterface->deleteAdjointTypeBuffer(h->recvbufAdjoints);
11454 }
11455
11456 template<typename SENDTYPE, typename RECVTYPE>
11457 int AMPI_Scatterv(MEDI_OPTIONAL_CONST typename SENDTYPE::Type* sendbuf, const int* sendcounts, const int* displs,
11458 SENDTYPE* sendtype, typename RECVTYPE::Type* recvbuf, int recvcount, RECVTYPE* recvtype, int root, AMPI_Comm comm) {
11459 int rStatus;
11460
11461 if(!recvtype->getADTool().isActiveType()) {
11462 // call the regular function if the type is not active
11463 rStatus = MPI_Scatterv(sendbuf, sendcounts, displs, sendtype->getMpiType(), recvbuf, recvcount, recvtype->getMpiType(),
11464 root, comm);
11465 } else {
11466
11467 // the type is an AD type so handle the buffers
11469 MEDI_OPTIONAL_CONST int* displsMod = displs;
11470 int displsTotalSize = 0;
11471 if(nullptr != displs) {
11472 displsTotalSize = computeDisplacementsTotalSize(sendcounts, getCommSize(comm));
11473 if(recvtype->isModifiedBufferRequired()) {
11474 displsMod = createLinearDisplacements(sendcounts, getCommSize(comm));
11475 }
11476 }
11477 typename SENDTYPE::ModifiedType* sendbufMod = nullptr;
11478 int sendbufElements = 0;
11479
11480 if(root == getCommRank(comm)) {
11481 // compute the total size of the buffer
11482 sendbufElements = displsTotalSize;
11483
11484 if(sendtype->isModifiedBufferRequired() ) {
11485 sendtype->createModifiedTypeBuffer(sendbufMod, sendbufElements);
11486 } else {
11487 sendbufMod = reinterpret_cast<typename SENDTYPE::ModifiedType*>(const_cast<typename SENDTYPE::Type*>(sendbuf));
11488 }
11489 }
11490 typename RECVTYPE::ModifiedType* recvbufMod = nullptr;
11491 int recvbufElements = 0;
11492
11493 // compute the total size of the buffer
11494 if(AMPI_IN_PLACE != recvbuf) {
11495 recvbufElements = recvcount;
11496 } else {
11497 recvbufElements = sendcounts[getCommRank(comm)];
11498 }
11499
11500 if(recvtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == recvbuf)) {
11501 recvtype->createModifiedTypeBuffer(recvbufMod, recvbufElements);
11502 } else {
11503 recvbufMod = reinterpret_cast<typename RECVTYPE::ModifiedType*>(const_cast<typename RECVTYPE::Type*>(recvbuf));
11504 }
11505
11506 // the handle is created if a reverse action should be recorded, h != nullptr => tape is active
11507 if(recvtype->getADTool().isHandleRequired()) {
11509 }
11510 recvtype->getADTool().startAssembly(h);
11511 if(root == getCommRank(comm)) {
11512 if(sendtype->isModifiedBufferRequired()) {
11513 for(int i = 0; i < getCommSize(comm); ++i) {
11514 sendtype->copyIntoModifiedBuffer(sendbuf, displs[i], sendbufMod, displsMod[i], sendcounts[i]);
11515 }
11516 }
11517 }
11518
11519 if(nullptr != h) {
11520 // gather the information for the reverse sweep
11521
11522 // create the index buffers
11523 if(root == getCommRank(comm)) {
11524 createLinearIndexCounts(h->sendbufCount, sendcounts, displs, getCommSize(comm), sendtype);
11525 h->sendbufTotalSize = sendtype->computeActiveElements(sendbufElements);
11526 recvtype->getADTool().createIndexTypeBuffer(h->sendbufIndices, h->sendbufTotalSize);
11527 }
11528 if(AMPI_IN_PLACE != recvbuf) {
11529 h->recvbufCount = recvtype->computeActiveElements(recvcount);
11530 } else {
11531 h->recvbufCount = sendtype->computeActiveElements(displs[getCommRank(comm)] + sendcounts[getCommRank(
11532 comm)]) - sendtype->computeActiveElements(displs[getCommRank(comm)]);
11533 }
11534 h->recvbufTotalSize = recvtype->computeActiveElements(recvbufElements);
11535 recvtype->getADTool().createIndexTypeBuffer(h->recvbufIndices, h->recvbufTotalSize);
11536
11537
11538 // extract the old primal values from the recv buffer if the AD tool
11539 // needs the primal values reset
11540 if(recvtype->getADTool().isOldPrimalsRequired()) {
11541 recvtype->getADTool().createPrimalTypeBuffer(h->recvbufOldPrimals, h->recvbufTotalSize);
11542 if(AMPI_IN_PLACE != recvbuf) {
11543 recvtype->getValues(recvbuf, 0, h->recvbufOldPrimals, 0, recvcount);
11544 } else {
11545 {
11546 const int rank = getCommRank(comm);
11547 sendtype->getValues(sendbuf, displs[rank], h->recvbufOldPrimals, 0, sendcounts[rank]);
11548 }
11549 }
11550 }
11551
11552
11553 if(root == getCommRank(comm)) {
11554 for(int i = 0; i < getCommSize(comm); ++i) {
11555 sendtype->getIndices(sendbuf, displs[i], h->sendbufIndices, displsMod[i], sendcounts[i]);
11556 }
11557 }
11558
11559 if(AMPI_IN_PLACE != recvbuf) {
11560 recvtype->createIndices(recvbuf, 0, h->recvbufIndices, 0, recvcount);
11561 } else {
11562 {
11563 const int rank = getCommRank(comm);
11564 sendtype->createIndices(const_cast<typename SENDTYPE::Type*>(sendbuf), displs[rank], h->recvbufIndices, 0,
11565 sendcounts[rank]);
11566 }
11567 }
11568
11569 // pack all the variables in the handle
11570 h->funcReverse = AMPI_Scatterv_b<SENDTYPE, RECVTYPE>;
11571 h->funcForward = AMPI_Scatterv_d<SENDTYPE, RECVTYPE>;
11572 h->funcPrimal = AMPI_Scatterv_p<SENDTYPE, RECVTYPE>;
11573 h->sendcounts = sendcounts;
11574 h->displs = displs;
11575 h->sendtype = sendtype;
11576 h->recvcount = recvcount;
11577 h->recvtype = recvtype;
11578 h->root = root;
11579 h->comm = comm;
11580 }
11581
11582 if(!recvtype->isModifiedBufferRequired()) {
11583 if(AMPI_IN_PLACE != recvbuf) {
11584 recvtype->clearIndices(recvbuf, 0, recvcount);
11585 } else {
11586 {
11587 const int rank = getCommRank(comm);
11588 sendtype->clearIndices(const_cast<typename SENDTYPE::Type*>(sendbuf), displs[rank], sendcounts[rank]);
11589 }
11590 }
11591 }
11592
11593 rStatus = MPI_Scatterv(sendbufMod, sendcounts, displsMod, sendtype->getModifiedMpiType(), recvbufMod, recvcount,
11594 recvtype->getModifiedMpiType(), root, comm);
11595 recvtype->getADTool().addToolAction(h);
11596
11597 if(recvtype->isModifiedBufferRequired()) {
11598 if(AMPI_IN_PLACE != recvbuf) {
11599 recvtype->copyFromModifiedBuffer(recvbuf, 0, recvbufMod, 0, recvcount);
11600 } else {
11601 {
11602 const int rank = getCommRank(comm);
11603 sendtype->copyFromModifiedBuffer(const_cast<typename SENDTYPE::Type*>(sendbuf), displs[rank], sendbufMod,
11604 displsMod[rank], sendcounts[rank]);
11605 }
11606 }
11607 }
11608
11609 if(nullptr != h) {
11610 // handle the recv buffers
11611 if(AMPI_IN_PLACE != recvbuf) {
11612 recvtype->registerValue(recvbuf, 0, h->recvbufIndices, h->recvbufOldPrimals, 0, recvcount);
11613 } else {
11614 {
11615 const int rank = getCommRank(comm);
11616 sendtype->registerValue(const_cast<typename SENDTYPE::Type*>(sendbuf), displs[rank], h->recvbufIndices,
11617 h->recvbufOldPrimals, 0, sendcounts[rank]);
11618 }
11619 }
11620 }
11621
11622 recvtype->getADTool().stopAssembly(h);
11623 if(recvtype->isModifiedBufferRequired()) {
11624 delete [] displsMod;
11625 }
11626
11627 if(root == getCommRank(comm)) {
11628 if(sendtype->isModifiedBufferRequired() ) {
11629 sendtype->deleteModifiedTypeBuffer(sendbufMod);
11630 }
11631 }
11632 if(recvtype->isModifiedBufferRequired() && !(AMPI_IN_PLACE == recvbuf)) {
11633 recvtype->deleteModifiedTypeBuffer(recvbufMod);
11634 }
11635
11636 // handle is deleted by the AD tool
11637 }
11638
11639 return rStatus;
11640 }
11641
11642#endif
11643
11644#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11645 inline int AMPI_Buffer_attach(void* buffer, int size) {
11646 return MPI_Buffer_attach(buffer, size);
11647 }
11648
11649#endif
11650#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11651 inline int AMPI_Buffer_detach(void* buffer_addr, int* size) {
11652 return MPI_Buffer_detach(buffer_addr, size);
11653 }
11654
11655#endif
11656#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11657 inline int AMPI_Cancel(AMPI_Request* request) {
11658 return MPI_Cancel(&request->request);
11659 }
11660
11661#endif
11662#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11663 template<typename DATATYPE>
11664 inline int AMPI_Get_count(MEDI_OPTIONAL_CONST AMPI_Status* status, DATATYPE* datatype, int* count) {
11665 return MPI_Get_count(status, datatype->getModifiedMpiType(), count);
11666 }
11667
11668#endif
11669#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11670 inline int AMPI_Iprobe(int source, int tag, AMPI_Comm comm, int* flag, AMPI_Status* status) {
11671 return MPI_Iprobe(source, tag, comm, flag, status);
11672 }
11673
11674#endif
11675#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11676 inline int AMPI_Probe(int source, int tag, AMPI_Comm comm, AMPI_Status* status) {
11677 return MPI_Probe(source, tag, comm, status);
11678 }
11679
11680#endif
11681#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
11682 inline int AMPI_Request_get_status(AMPI_Request request, int* flag, AMPI_Status* status) {
11683 return MPI_Request_get_status(request.request, flag, status);
11684 }
11685
11686#endif
11687#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11688 inline int AMPI_Test_cancelled(MEDI_OPTIONAL_CONST AMPI_Status* status, int* flag) {
11689 return MPI_Test_cancelled(status, flag);
11690 }
11691
11692#endif
11693#if MEDI_MPI_VERSION_3_1 <= MEDI_MPI_TARGET
11694 inline MPI_Aint AMPI_Aint_add(AMPI_Aint base, AMPI_Aint disp) {
11695 return MPI_Aint_add(base, disp);
11696 }
11697
11698#endif
11699#if MEDI_MPI_VERSION_3_1 <= MEDI_MPI_TARGET
11700 inline MPI_Aint AMPI_Aint_diff(AMPI_Aint addr1, AMPI_Aint addr2) {
11701 return MPI_Aint_diff(addr1, addr2);
11702 }
11703
11704#endif
11705#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
11706 inline int AMPI_Get_address(MEDI_OPTIONAL_CONST void* location, AMPI_Aint* address) {
11707 return MPI_Get_address(location, address);
11708 }
11709
11710#endif
11711#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11712 template<typename DATATYPE>
11713 inline int AMPI_Get_elements(const AMPI_Status* status, DATATYPE* datatype, int* count) {
11714 return MPI_Get_elements(status, datatype->getModifiedMpiType(), count);
11715 }
11716
11717#endif
11718#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
11719 template<typename DATATYPE>
11720 inline int AMPI_Get_elements_x(const AMPI_Status* status, DATATYPE* datatype, AMPI_Count* count) {
11721 return MPI_Get_elements_x(status, datatype->getModifiedMpiType(), count);
11722 }
11723
11724#endif
11725#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
11726 template<typename DATATYPE>
11727 inline int AMPI_Type_get_contents(DATATYPE* datatype, int max_integers, int max_addresses, int max_datatypes,
11728 int* array_of_integers, AMPI_Aint* array_of_addresses, AMPI_Datatype* array_of_datatypes) {
11729 return MPI_Type_get_contents(datatype->getModifiedMpiType(), max_integers, max_addresses, max_datatypes,
11730 array_of_integers, array_of_addresses, array_of_datatypes);
11731 }
11732
11733#endif
11734#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
11735 template<typename DATATYPE>
11736 inline int AMPI_Type_get_envelope(DATATYPE* datatype, int* num_integers, int* num_addresses, int* num_datatypes,
11737 int* combiner) {
11738 return MPI_Type_get_envelope(datatype->getModifiedMpiType(), num_integers, num_addresses, num_datatypes, combiner);
11739 }
11740
11741#endif
11742#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
11743 template<typename DATATYPE>
11744 inline int AMPI_Type_get_extent(DATATYPE* datatype, AMPI_Aint* lb, AMPI_Aint* extent) {
11745 return MPI_Type_get_extent(datatype->getModifiedMpiType(), lb, extent);
11746 }
11747
11748#endif
11749#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
11750 template<typename DATATYPE>
11751 inline int AMPI_Type_get_extent_x(DATATYPE* datatype, AMPI_Count* lb, AMPI_Count* extent) {
11752 return MPI_Type_get_extent_x(datatype->getModifiedMpiType(), lb, extent);
11753 }
11754
11755#endif
11756#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
11757 template<typename DATATYPE>
11758 inline int AMPI_Type_get_true_extent(DATATYPE* datatype, AMPI_Aint* true_lb, AMPI_Aint* true_extent) {
11759 return MPI_Type_get_true_extent(datatype->getModifiedMpiType(), true_lb, true_extent);
11760 }
11761
11762#endif
11763#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
11764 template<typename DATATYPE>
11765 inline int AMPI_Type_get_true_extent_x(DATATYPE* datatype, AMPI_Count* true_lb, AMPI_Count* true_extent) {
11766 return MPI_Type_get_true_extent_x(datatype->getModifiedMpiType(), true_lb, true_extent);
11767 }
11768
11769#endif
11770#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11771 template<typename DATATYPE>
11772 inline int AMPI_Type_size(DATATYPE* datatype, int* size) {
11773 return MPI_Type_size(datatype->getModifiedMpiType(), size);
11774 }
11775
11776#endif
11777#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
11778 template<typename DATATYPE>
11779 inline int AMPI_Type_size_x(DATATYPE* datatype, AMPI_Count* size) {
11780 return MPI_Type_size_x(datatype->getModifiedMpiType(), size);
11781 }
11782
11783#endif
11784#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11785 inline int AMPI_Barrier(AMPI_Comm comm) {
11786 return MPI_Barrier(comm);
11787 }
11788
11789#endif
11790#if MEDI_MPI_VERSION_2_2 <= MEDI_MPI_TARGET
11791 inline int AMPI_Op_commutative(AMPI_Op op, int* commute) {
11792 AMPI_Op convOp = op;
11793 (void)convOp;
11794 return MPI_Op_commutative(convOp.modifiedPrimalFunction, commute);
11795 }
11796
11797#endif
11798#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11799 inline int AMPI_Comm_compare(AMPI_Comm comm1, AMPI_Comm comm2, int* result) {
11800 return MPI_Comm_compare(comm1, comm2, result);
11801 }
11802
11803#endif
11804#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11805 inline int AMPI_Comm_create(AMPI_Comm comm, AMPI_Group group, AMPI_Comm* newcomm) {
11806 return MPI_Comm_create(comm, group, newcomm);
11807 }
11808
11809#endif
11810#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
11811 inline int AMPI_Comm_create_group(AMPI_Comm comm, AMPI_Group group, int tag, AMPI_Comm* newcomm) {
11812 return MPI_Comm_create_group(comm, group, tag, newcomm);
11813 }
11814
11815#endif
11816#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
11818 AMPI_Comm_delete_attr_function* comm_delete_attr_fn, int* comm_keyval, void* extra_state) {
11819 return MPI_Comm_create_keyval(comm_copy_attr_fn, comm_delete_attr_fn, comm_keyval, extra_state);
11820 }
11821
11822#endif
11823#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
11824 inline int AMPI_Comm_delete_attr(AMPI_Comm comm, int comm_keyval) {
11825 return MPI_Comm_delete_attr(comm, comm_keyval);
11826 }
11827
11828#endif
11829#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11830 inline int AMPI_Comm_dup(AMPI_Comm comm, AMPI_Comm* newcomm) {
11831 return MPI_Comm_dup(comm, newcomm);
11832 }
11833
11834#endif
11835#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
11836 inline int AMPI_Comm_dup_with_info(AMPI_Comm comm, AMPI_Info info, AMPI_Comm* newcomm) {
11837 return MPI_Comm_dup_with_info(comm, info, newcomm);
11838 }
11839
11840#endif
11841#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11842 inline int AMPI_Comm_free(AMPI_Comm* comm) {
11843 return MPI_Comm_free(comm);
11844 }
11845
11846#endif
11847#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
11848 inline int AMPI_Comm_free_keyval(int* comm_keyval) {
11849 return MPI_Comm_free_keyval(comm_keyval);
11850 }
11851
11852#endif
11853#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
11854 inline int AMPI_Comm_get_attr(AMPI_Comm comm, int comm_keyval, void* attribute_val, int* flag) {
11855 return MPI_Comm_get_attr(comm, comm_keyval, attribute_val, flag);
11856 }
11857
11858#endif
11859#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
11860 inline int AMPI_Comm_get_info(AMPI_Comm comm, AMPI_Info* info_used) {
11861 return MPI_Comm_get_info(comm, info_used);
11862 }
11863
11864#endif
11865#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
11866 inline int AMPI_Comm_get_name(AMPI_Comm comm, char* comm_name, int* resultlen) {
11867 return MPI_Comm_get_name(comm, comm_name, resultlen);
11868 }
11869
11870#endif
11871#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11872 inline int AMPI_Comm_group(AMPI_Comm comm, AMPI_Group* group) {
11873 return MPI_Comm_group(comm, group);
11874 }
11875
11876#endif
11877#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
11878 inline int AMPI_Comm_idup(AMPI_Comm comm, AMPI_Comm* newcomm, AMPI_Request* request) {
11879 return MPI_Comm_idup(comm, newcomm, &request->request);
11880 }
11881
11882#endif
11883#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11884 inline int AMPI_Comm_rank(AMPI_Comm comm, int* rank) {
11885 return MPI_Comm_rank(comm, rank);
11886 }
11887
11888#endif
11889#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11891 return MPI_Comm_remote_group(comm, group);
11892 }
11893
11894#endif
11895#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11896 inline int AMPI_Comm_remote_size(AMPI_Comm comm, int* size) {
11897 return MPI_Comm_remote_size(comm, size);
11898 }
11899
11900#endif
11901#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
11902 inline int AMPI_Comm_set_attr(AMPI_Comm comm, int comm_keyval, void* attribute_val) {
11903 return MPI_Comm_set_attr(comm, comm_keyval, attribute_val);
11904 }
11905
11906#endif
11907#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
11908 inline int AMPI_Comm_set_info(AMPI_Comm comm, AMPI_Info info) {
11909 return MPI_Comm_set_info(comm, info);
11910 }
11911
11912#endif
11913#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
11914 inline int AMPI_Comm_set_name(AMPI_Comm comm, MEDI_OPTIONAL_CONST char* comm_name) {
11915 return MPI_Comm_set_name(comm, comm_name);
11916 }
11917
11918#endif
11919#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11920 inline int AMPI_Comm_size(AMPI_Comm comm, int* size) {
11921 return MPI_Comm_size(comm, size);
11922 }
11923
11924#endif
11925#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11926 inline int AMPI_Comm_split(AMPI_Comm comm, int color, int key, AMPI_Comm* newcomm) {
11927 return MPI_Comm_split(comm, color, key, newcomm);
11928 }
11929
11930#endif
11931#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
11932 inline int AMPI_Comm_split_type(AMPI_Comm comm, int split_type, int key, AMPI_Info info, AMPI_Comm* newcomm) {
11933 return MPI_Comm_split_type(comm, split_type, key, info, newcomm);
11934 }
11935
11936#endif
11937#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11938 inline int AMPI_Comm_test_inter(AMPI_Comm comm, int* flag) {
11939 return MPI_Comm_test_inter(comm, flag);
11940 }
11941
11942#endif
11943#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11944 inline int AMPI_Group_compare(AMPI_Group group1, AMPI_Group group2, int* result) {
11945 return MPI_Group_compare(group1, group2, result);
11946 }
11947
11948#endif
11949#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11950 inline int AMPI_Group_difference(AMPI_Group group1, AMPI_Group group2, AMPI_Group* newgroup) {
11951 return MPI_Group_difference(group1, group2, newgroup);
11952 }
11953
11954#endif
11955#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11956 inline int AMPI_Group_excl(AMPI_Group group, int n, MEDI_OPTIONAL_CONST int* ranks, AMPI_Group* newgroup) {
11957 return MPI_Group_excl(group, n, ranks, newgroup);
11958 }
11959
11960#endif
11961#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11962 inline int AMPI_Group_free(AMPI_Group* group) {
11963 return MPI_Group_free(group);
11964 }
11965
11966#endif
11967#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11968 inline int AMPI_Group_incl(AMPI_Group group, int n, MEDI_OPTIONAL_CONST int* ranks, AMPI_Group* newgroup) {
11969 return MPI_Group_incl(group, n, ranks, newgroup);
11970 }
11971
11972#endif
11973#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11974 inline int AMPI_Group_intersection(AMPI_Group group1, AMPI_Group group2, AMPI_Group* newgroup) {
11975 return MPI_Group_intersection(group1, group2, newgroup);
11976 }
11977
11978#endif
11979#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11980 inline int AMPI_Group_range_excl(AMPI_Group group, int n, ::medi::common::Range* ranges, AMPI_Group* newgroup) {
11981 return MPI_Group_range_excl(group, n, ranges, newgroup);
11982 }
11983
11984#endif
11985#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11986 inline int AMPI_Group_range_incl(AMPI_Group group, int n, ::medi::common::Range* ranges, AMPI_Group* newgroup) {
11987 return MPI_Group_range_incl(group, n, ranges, newgroup);
11988 }
11989
11990#endif
11991#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11992 inline int AMPI_Group_rank(AMPI_Group group, int* rank) {
11993 return MPI_Group_rank(group, rank);
11994 }
11995
11996#endif
11997#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
11998 inline int AMPI_Group_size(AMPI_Group group, int* size) {
11999 return MPI_Group_size(group, size);
12000 }
12001
12002#endif
12003#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12004 inline int AMPI_Group_translate_ranks(AMPI_Group group1, int n, MEDI_OPTIONAL_CONST int* ranks1, AMPI_Group group2,
12005 int* ranks2) {
12006 return MPI_Group_translate_ranks(group1, n, ranks1, group2, ranks2);
12007 }
12008
12009#endif
12010#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12011 inline int AMPI_Group_union(AMPI_Group group1, AMPI_Group group2, AMPI_Group* newgroup) {
12012 return MPI_Group_union(group1, group2, newgroup);
12013 }
12014
12015#endif
12016#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12017 inline int AMPI_Intercomm_create(AMPI_Comm local_comm, int local_leader, AMPI_Comm peer_comm, int remote_leader,
12018 int tag, AMPI_Comm* newintercomm) {
12019 return MPI_Intercomm_create(local_comm, local_leader, peer_comm, remote_leader, tag, newintercomm);
12020 }
12021
12022#endif
12023#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12024 inline int AMPI_Intercomm_merge(AMPI_Comm intercomm, int high, AMPI_Comm* newintracomm) {
12025 return MPI_Intercomm_merge(intercomm, high, newintracomm);
12026 }
12027
12028#endif
12029#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12031 AMPI_Type_delete_attr_function* type_delete_attr_fn, int* type_keyval, void* extra_state) {
12032 return MPI_Type_create_keyval(type_copy_attr_fn, type_delete_attr_fn, type_keyval, extra_state);
12033 }
12034
12035#endif
12036#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12037 template<typename DATATYPE>
12038 inline int AMPI_Type_delete_attr(DATATYPE* datatype, int type_keyval) {
12039 return MPI_Type_delete_attr(datatype->getModifiedMpiType(), type_keyval);
12040 }
12041
12042#endif
12043#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12044 inline int AMPI_Type_free_keyval(int* type_keyval) {
12045 return MPI_Type_free_keyval(type_keyval);
12046 }
12047
12048#endif
12049#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12050 template<typename DATATYPE>
12051 inline int AMPI_Type_get_attr(DATATYPE* datatype, int type_keyval, void* attribute_val, int* flag) {
12052 return MPI_Type_get_attr(datatype->getModifiedMpiType(), type_keyval, attribute_val, flag);
12053 }
12054
12055#endif
12056#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12057 template<typename DATATYPE>
12058 inline int AMPI_Type_get_name(DATATYPE* datatype, char* type_name, int* resultlen) {
12059 return MPI_Type_get_name(datatype->getModifiedMpiType(), type_name, resultlen);
12060 }
12061
12062#endif
12063#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12064 template<typename DATATYPE>
12065 inline int AMPI_Type_set_attr(DATATYPE* datatype, int type_keyval, void* attribute_val) {
12066 return MPI_Type_set_attr(datatype->getModifiedMpiType(), type_keyval, attribute_val);
12067 }
12068
12069#endif
12070#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12071 template<typename DATATYPE>
12072 inline int AMPI_Type_set_name(DATATYPE* datatype, const char* type_name) {
12073 return MPI_Type_set_name(datatype->getModifiedMpiType(), type_name);
12074 }
12075
12076#endif
12077#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12079 AMPI_Win_delete_attr_function* win_delete_attr_fn, int* win_keyval, void* extra_state) {
12080 return MPI_Win_create_keyval(win_copy_attr_fn, win_delete_attr_fn, win_keyval, extra_state);
12081 }
12082
12083#endif
12084#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12085 inline int AMPI_Win_delete_attr(AMPI_Win win, int win_keyval) {
12086 return MPI_Win_delete_attr(win, win_keyval);
12087 }
12088
12089#endif
12090#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12091 inline int AMPI_Win_free_keyval(int* win_keyval) {
12092 return MPI_Win_free_keyval(win_keyval);
12093 }
12094
12095#endif
12096#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12097 inline int AMPI_Win_get_attr(AMPI_Win win, int win_keyval, void* attribute_val, int* flag) {
12098 return MPI_Win_get_attr(win, win_keyval, attribute_val, flag);
12099 }
12100
12101#endif
12102#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12103 inline int AMPI_Win_get_name(AMPI_Win win, char* win_name, int* resultlen) {
12104 return MPI_Win_get_name(win, win_name, resultlen);
12105 }
12106
12107#endif
12108#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12109 inline int AMPI_Win_set_attr(AMPI_Win win, int win_keyval, void* attribute_val) {
12110 return MPI_Win_set_attr(win, win_keyval, attribute_val);
12111 }
12112
12113#endif
12114#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12115 inline int AMPI_Win_set_name(AMPI_Win win, MEDI_OPTIONAL_CONST char* win_name) {
12116 return MPI_Win_set_name(win, win_name);
12117 }
12118
12119#endif
12120#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12121 inline int AMPI_Cart_coords(AMPI_Comm comm, int rank, int maxdims, int* coords) {
12122 return MPI_Cart_coords(comm, rank, maxdims, coords);
12123 }
12124
12125#endif
12126#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12127 inline int AMPI_Cart_create(AMPI_Comm comm_old, int ndims, MEDI_OPTIONAL_CONST int* dims,
12128 MEDI_OPTIONAL_CONST int* periods, int reorder, AMPI_Comm* comm_cart) {
12129 return MPI_Cart_create(comm_old, ndims, dims, periods, reorder, comm_cart);
12130 }
12131
12132#endif
12133#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12134 inline int AMPI_Cart_get(AMPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
12135 return MPI_Cart_get(comm, maxdims, dims, periods, coords);
12136 }
12137
12138#endif
12139#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12140 inline int AMPI_Cart_map(AMPI_Comm comm, int ndims, MEDI_OPTIONAL_CONST int* dims, MEDI_OPTIONAL_CONST int* periods,
12141 int* newrank) {
12142 return MPI_Cart_map(comm, ndims, dims, periods, newrank);
12143 }
12144
12145#endif
12146#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12147 inline int AMPI_Cart_rank(AMPI_Comm comm, MEDI_OPTIONAL_CONST int* coords, int* rank) {
12148 return MPI_Cart_rank(comm, coords, rank);
12149 }
12150
12151#endif
12152#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12153 inline int AMPI_Cart_shift(AMPI_Comm comm, int direction, int disp, int* rank_source, int* rank_dest) {
12154 return MPI_Cart_shift(comm, direction, disp, rank_source, rank_dest);
12155 }
12156
12157#endif
12158#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12159 inline int AMPI_Cart_sub(AMPI_Comm comm, MEDI_OPTIONAL_CONST int* remain_dims, AMPI_Comm* newcomm) {
12160 return MPI_Cart_sub(comm, remain_dims, newcomm);
12161 }
12162
12163#endif
12164#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12165 inline int AMPI_Cartdim_get(AMPI_Comm comm, int* ndims) {
12166 return MPI_Cartdim_get(comm, ndims);
12167 }
12168
12169#endif
12170#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12171 inline int AMPI_Dims_create(int nnodes, int ndims, int* dims) {
12172 return MPI_Dims_create(nnodes, ndims, dims);
12173 }
12174
12175#endif
12176#if MEDI_MPI_VERSION_2_2 <= MEDI_MPI_TARGET
12177 inline int AMPI_Dist_graph_create(AMPI_Comm comm_old, int n, MEDI_OPTIONAL_CONST int* sources,
12178 MEDI_OPTIONAL_CONST int* degrees, MEDI_OPTIONAL_CONST int* destinations, MEDI_OPTIONAL_CONST int* weights,
12179 AMPI_Info info, int reorder, AMPI_Comm* comm_dist_graph) {
12180 return MPI_Dist_graph_create(comm_old, n, sources, degrees, destinations, weights, info, reorder, comm_dist_graph);
12181 }
12182
12183#endif
12184#if MEDI_MPI_VERSION_2_2 <= MEDI_MPI_TARGET
12185 inline int AMPI_Dist_graph_create_adjacent(AMPI_Comm comm_old, int indegree, MEDI_OPTIONAL_CONST int* sources,
12186 MEDI_OPTIONAL_CONST int* sourceweights, int outdegree, MEDI_OPTIONAL_CONST int* destinations,
12187 MEDI_OPTIONAL_CONST int* destweights, AMPI_Info info, int reorder, AMPI_Comm* comm_dist_graph) {
12188 return MPI_Dist_graph_create_adjacent(comm_old, indegree, sources, sourceweights, outdegree, destinations, destweights,
12189 info, reorder, comm_dist_graph);
12190 }
12191
12192#endif
12193#if MEDI_MPI_VERSION_2_2 <= MEDI_MPI_TARGET
12194 inline int AMPI_Dist_graph_neighbors(AMPI_Comm comm, int maxindegree, int* sources, int* sourceweights,
12195 int maxoutdegree, int* destinations, int* destweights) {
12196 return MPI_Dist_graph_neighbors(comm, maxindegree, sources, sourceweights, maxoutdegree, destinations, destweights);
12197 }
12198
12199#endif
12200#if MEDI_MPI_VERSION_2_2 <= MEDI_MPI_TARGET
12201 inline int AMPI_Dist_graph_neighbors_count(AMPI_Comm comm, int* indegree, int* outdegree, int* weighted) {
12202 return MPI_Dist_graph_neighbors_count(comm, indegree, outdegree, weighted);
12203 }
12204
12205#endif
12206#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12207 inline int AMPI_Graph_create(AMPI_Comm comm_old, int nnodes, MEDI_OPTIONAL_CONST int* index,
12208 MEDI_OPTIONAL_CONST int* edges, int reorder, AMPI_Comm* comm_graph) {
12209 return MPI_Graph_create(comm_old, nnodes, index, edges, reorder, comm_graph);
12210 }
12211
12212#endif
12213#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12214 inline int AMPI_Graph_get(AMPI_Comm comm, int maxindex, int maxedges, int* index, int* edges) {
12215 return MPI_Graph_get(comm, maxindex, maxedges, index, edges);
12216 }
12217
12218#endif
12219#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12220 inline int AMPI_Graph_map(AMPI_Comm comm, int nnodes, MEDI_OPTIONAL_CONST int* index, MEDI_OPTIONAL_CONST int* edges,
12221 int* newrank) {
12222 return MPI_Graph_map(comm, nnodes, index, edges, newrank);
12223 }
12224
12225#endif
12226#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12227 inline int AMPI_Graph_neighbors(AMPI_Comm comm, int rank, int maxneighbors, int* neighbors) {
12228 return MPI_Graph_neighbors(comm, rank, maxneighbors, neighbors);
12229 }
12230
12231#endif
12232#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12233 inline int AMPI_Graph_neighbors_count(AMPI_Comm comm, int rank, int* nneighbors) {
12234 return MPI_Graph_neighbors_count(comm, rank, nneighbors);
12235 }
12236
12237#endif
12238#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12239 inline int AMPI_Graphdims_get(AMPI_Comm comm, int* nnodes, int* nedges) {
12240 return MPI_Graphdims_get(comm, nnodes, nedges);
12241 }
12242
12243#endif
12244#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12245 inline int AMPI_Topo_test(AMPI_Comm comm, int* status) {
12246 return MPI_Topo_test(comm, status);
12247 }
12248
12249#endif
12250#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12251 inline double AMPI_Wtick() {
12252 return MPI_Wtick();
12253 }
12254
12255#endif
12256#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12257 inline double AMPI_Wtime() {
12258 return MPI_Wtime();
12259 }
12260
12261#endif
12262#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12263 inline int AMPI_Abort(AMPI_Comm comm, int errorcode) {
12264 return MPI_Abort(comm, errorcode);
12265 }
12266
12267#endif
12268#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12269 inline int AMPI_Add_error_class(int* errorclass) {
12270 return MPI_Add_error_class(errorclass);
12271 }
12272
12273#endif
12274#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12275 inline int AMPI_Add_error_code(int errorclass, int* errorcode) {
12276 return MPI_Add_error_code(errorclass, errorcode);
12277 }
12278
12279#endif
12280#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12281 inline int AMPI_Add_error_string(int errorcode, MEDI_OPTIONAL_CONST char* string) {
12282 return MPI_Add_error_string(errorcode, string);
12283 }
12284
12285#endif
12286#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12287 inline int AMPI_Alloc_mem(AMPI_Aint size, AMPI_Info info, void* baseptr) {
12288 return MPI_Alloc_mem(size, info, baseptr);
12289 }
12290
12291#endif
12292#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12293 inline int AMPI_Comm_call_errhandler(AMPI_Comm comm, int errorcode) {
12294 return MPI_Comm_call_errhandler(comm, errorcode);
12295 }
12296
12297#endif
12298#if MEDI_MPI_VERSION_2_2 <= MEDI_MPI_TARGET
12300 return MPI_Comm_create_errhandler(comm_errhandler_fn, errhandler);
12301 }
12302
12303#endif
12304#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET && MEDI_MPI_TARGET < MEDI_MPI_VERSION_2_2
12305 inline int AMPI_Comm_create_errhandler(AMPI_Comm_errhandler_fn* comm_errhandler_fn, AMPI_Errhandler* errhandler) {
12306 return MPI_Comm_create_errhandler(comm_errhandler_fn, errhandler);
12307 }
12308
12309#endif
12310#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12312 return MPI_Comm_get_errhandler(comm, errhandler);
12313 }
12314
12315#endif
12316#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12318 return MPI_Comm_set_errhandler(comm, errhandler);
12319 }
12320
12321#endif
12322#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12323 inline int AMPI_Errhandler_free(AMPI_Errhandler* errhandler) {
12324 return MPI_Errhandler_free(errhandler);
12325 }
12326
12327#endif
12328#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12329 inline int AMPI_Error_class(int errorcode, int* errorclass) {
12330 return MPI_Error_class(errorcode, errorclass);
12331 }
12332
12333#endif
12334#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12335 inline int AMPI_Error_string(int errorcode, char* string, int* resultlen) {
12336 return MPI_Error_string(errorcode, string, resultlen);
12337 }
12338
12339#endif
12340#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12341 inline int AMPI_File_call_errhandler(AMPI_File fh, int errorcode) {
12342 return MPI_File_call_errhandler(fh, errorcode);
12343 }
12344
12345#endif
12346#if MEDI_MPI_VERSION_2_2 <= MEDI_MPI_TARGET
12348 return MPI_File_create_errhandler(file_errhandler_fn, errhandler);
12349 }
12350
12351#endif
12352#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET && MEDI_MPI_TARGET < MEDI_MPI_VERSION_2_2
12353 inline int AMPI_File_create_errhandler(AMPI_File_errhandler_fn* file_errhandler_fn, AMPI_Errhandler* errhandler) {
12354 return MPI_File_create_errhandler(file_errhandler_fn, errhandler);
12355 }
12356
12357#endif
12358#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12360 return MPI_File_get_errhandler(file, errhandler);
12361 }
12362
12363#endif
12364#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12366 return MPI_File_set_errhandler(file, errhandler);
12367 }
12368
12369#endif
12370#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12371 inline int AMPI_Finalize() {
12372 return MPI_Finalize();
12373 }
12374
12375#endif
12376#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12377 inline int AMPI_Finalized(int* flag) {
12378 return MPI_Finalized(flag);
12379 }
12380
12381#endif
12382#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12383 inline int AMPI_Free_mem(void* base) {
12384 return MPI_Free_mem(base);
12385 }
12386
12387#endif
12388#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
12389 inline int AMPI_Get_library_version(char* version, int* resultlen) {
12390 return MPI_Get_library_version(version, resultlen);
12391 }
12392
12393#endif
12394#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12395 inline int AMPI_Get_processor_name(char* name, int* resultlen) {
12396 return MPI_Get_processor_name(name, resultlen);
12397 }
12398
12399#endif
12400#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12401 inline int AMPI_Get_version(int* version, int* subversion) {
12402 return MPI_Get_version(version, subversion);
12403 }
12404
12405#endif
12406#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
12407 inline int AMPI_Initialized(int* flag) {
12408 return MPI_Initialized(flag);
12409 }
12410
12411#endif
12412#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12413 inline int AMPI_Win_call_errhandler(AMPI_Win win, int errorcode) {
12414 return MPI_Win_call_errhandler(win, errorcode);
12415 }
12416
12417#endif
12418#if MEDI_MPI_VERSION_2_2 <= MEDI_MPI_TARGET
12420 return MPI_Win_create_errhandler(win_errhandler_fn, errhandler);
12421 }
12422
12423#endif
12424#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET && MEDI_MPI_TARGET < MEDI_MPI_VERSION_2_2
12425 inline int AMPI_Win_create_errhandler(AMPI_Win_errhandler_fn* win_errhandler_fn, AMPI_Errhandler* errhandler) {
12426 return MPI_Win_create_errhandler(win_errhandler_fn, errhandler);
12427 }
12428
12429#endif
12430#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12431 inline int AMPI_Win_get_errhandler(AMPI_Win win, AMPI_Errhandler* errhandler) {
12432 return MPI_Win_get_errhandler(win, errhandler);
12433 }
12434
12435#endif
12436#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12438 return MPI_Win_set_errhandler(win, errhandler);
12439 }
12440
12441#endif
12442#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12443 inline int AMPI_Info_create(AMPI_Info* info) {
12444 return MPI_Info_create(info);
12445 }
12446
12447#endif
12448#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12449 inline int AMPI_Info_delete(AMPI_Info info, MEDI_OPTIONAL_CONST char* key) {
12450 return MPI_Info_delete(info, key);
12451 }
12452
12453#endif
12454#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12455 inline int AMPI_Info_dup(AMPI_Info info, AMPI_Info* newinfo) {
12456 return MPI_Info_dup(info, newinfo);
12457 }
12458
12459#endif
12460#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12461 inline int AMPI_Info_free(AMPI_Info* info) {
12462 return MPI_Info_free(info);
12463 }
12464
12465#endif
12466#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12467 inline int AMPI_Info_get(AMPI_Info info, MEDI_OPTIONAL_CONST char* key, int valuelen, char* value, int* flag) {
12468 return MPI_Info_get(info, key, valuelen, value, flag);
12469 }
12470
12471#endif
12472#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12473 inline int AMPI_Info_get_nkeys(AMPI_Info info, int* nkeys) {
12474 return MPI_Info_get_nkeys(info, nkeys);
12475 }
12476
12477#endif
12478#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12479 inline int AMPI_Info_get_nthkey(AMPI_Info info, int n, char* key) {
12480 return MPI_Info_get_nthkey(info, n, key);
12481 }
12482
12483#endif
12484#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12485 inline int AMPI_Info_get_valuelen(AMPI_Info info, MEDI_OPTIONAL_CONST char* key, int* valuelen, int* flag) {
12486 return MPI_Info_get_valuelen(info, key, valuelen, flag);
12487 }
12488
12489#endif
12490#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12491 inline int AMPI_Info_set(AMPI_Info info, MEDI_OPTIONAL_CONST char* key, MEDI_OPTIONAL_CONST char* value) {
12492 return MPI_Info_set(info, key, value);
12493 }
12494
12495#endif
12496#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12497 inline int AMPI_Close_port(MEDI_OPTIONAL_CONST char* port_name) {
12498 return MPI_Close_port(port_name);
12499 }
12500
12501#endif
12502#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12503 inline int AMPI_Comm_accept(MEDI_OPTIONAL_CONST char* port_name, AMPI_Info info, int root, AMPI_Comm comm,
12504 AMPI_Comm* newcomm) {
12505 return MPI_Comm_accept(port_name, info, root, comm, newcomm);
12506 }
12507
12508#endif
12509#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12510 inline int AMPI_Comm_connect(MEDI_OPTIONAL_CONST char* port_name, AMPI_Info info, int root, AMPI_Comm comm,
12511 AMPI_Comm* newcomm) {
12512 return MPI_Comm_connect(port_name, info, root, comm, newcomm);
12513 }
12514
12515#endif
12516#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12518 return MPI_Comm_disconnect(comm);
12519 }
12520
12521#endif
12522#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12523 inline int AMPI_Comm_get_parent(AMPI_Comm* parent) {
12524 return MPI_Comm_get_parent(parent);
12525 }
12526
12527#endif
12528#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12529 inline int AMPI_Comm_join(int fd, AMPI_Comm* intercomm) {
12530 return MPI_Comm_join(fd, intercomm);
12531 }
12532
12533#endif
12534#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12535 inline int AMPI_Comm_spawn(MEDI_OPTIONAL_CONST char* command, char** argv, int maxprocs, AMPI_Info info, int root,
12536 AMPI_Comm comm, AMPI_Comm* intercomm, int* array_of_errcodes) {
12537 return MPI_Comm_spawn(command, argv, maxprocs, info, root, comm, intercomm, array_of_errcodes);
12538 }
12539
12540#endif
12541#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12542 inline int AMPI_Comm_spawn_multiple(int count, char** array_of_commands, char*** array_of_argv,
12543 MEDI_OPTIONAL_CONST int* array_of_maxprocs, MEDI_OPTIONAL_CONST AMPI_Info* array_of_info, int root, AMPI_Comm comm,
12544 AMPI_Comm* intercomm, int* array_of_errcodes) {
12545 return MPI_Comm_spawn_multiple(count, array_of_commands, array_of_argv, array_of_maxprocs, array_of_info, root, comm,
12546 intercomm, array_of_errcodes);
12547 }
12548
12549#endif
12550#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12551 inline int AMPI_Lookup_name(MEDI_OPTIONAL_CONST char* service_name, AMPI_Info info, char* port_name) {
12552 return MPI_Lookup_name(service_name, info, port_name);
12553 }
12554
12555#endif
12556#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12557 inline int AMPI_Open_port(AMPI_Info info, char* port_name) {
12558 return MPI_Open_port(info, port_name);
12559 }
12560
12561#endif
12562#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12563 inline int AMPI_Publish_name(MEDI_OPTIONAL_CONST char* service_name, AMPI_Info info,
12564 MEDI_OPTIONAL_CONST char* port_name) {
12565 return MPI_Publish_name(service_name, info, port_name);
12566 }
12567
12568#endif
12569#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12570 inline int AMPI_Unpublish_name(MEDI_OPTIONAL_CONST char* service_name, AMPI_Info info,
12571 MEDI_OPTIONAL_CONST char* port_name) {
12572 return MPI_Unpublish_name(service_name, info, port_name);
12573 }
12574
12575#endif
12576#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12578 return MPI_Grequest_complete(request.request);
12579 }
12580
12581#endif
12582#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12584 AMPI_Grequest_cancel_function* cancel_fn, void* extra_state, AMPI_Request* request) {
12585 return MPI_Grequest_start(query_fn, free_fn, cancel_fn, extra_state, &request->request);
12586 }
12587
12588#endif
12589#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12590 inline int AMPI_Is_thread_main(int* flag) {
12591 return MPI_Is_thread_main(flag);
12592 }
12593
12594#endif
12595#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12596 inline int AMPI_Query_thread(int* provided) {
12597 return MPI_Query_thread(provided);
12598 }
12599
12600#endif
12601#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12602 inline int AMPI_Status_set_cancelled(AMPI_Status* status, int flag) {
12603 return MPI_Status_set_cancelled(status, flag);
12604 }
12605
12606#endif
12607#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12608 template<typename DATATYPE>
12609 inline int AMPI_Status_set_elements(AMPI_Status* status, DATATYPE* datatype, int count) {
12610 return MPI_Status_set_elements(status, datatype->getModifiedMpiType(), count);
12611 }
12612
12613#endif
12614#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
12615 template<typename DATATYPE>
12616 inline int AMPI_Status_set_elements_x(AMPI_Status* status, DATATYPE* datatype, AMPI_Count count) {
12617 return MPI_Status_set_elements_x(status, datatype->getModifiedMpiType(), count);
12618 }
12619
12620#endif
12621#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12622 inline int AMPI_File_close(AMPI_File* fh) {
12623 return MPI_File_close(fh);
12624 }
12625
12626#endif
12627#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12628 inline int AMPI_File_delete(MEDI_OPTIONAL_CONST char* filename, AMPI_Info info) {
12629 return MPI_File_delete(filename, info);
12630 }
12631
12632#endif
12633#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12634 inline int AMPI_File_get_amode(AMPI_File fh, int* amode) {
12635 return MPI_File_get_amode(fh, amode);
12636 }
12637
12638#endif
12639#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12640 inline int AMPI_File_get_atomicity(AMPI_File fh, int* flag) {
12641 return MPI_File_get_atomicity(fh, flag);
12642 }
12643
12644#endif
12645#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12647 return MPI_File_get_byte_offset(fh, offset, disp);
12648 }
12649
12650#endif
12651#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12653 return MPI_File_get_group(fh, group);
12654 }
12655
12656#endif
12657#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12658 inline int AMPI_File_get_info(AMPI_File fh, AMPI_Info* info_used) {
12659 return MPI_File_get_info(fh, info_used);
12660 }
12661
12662#endif
12663#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12665 return MPI_File_get_position(fh, offset);
12666 }
12667
12668#endif
12669#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12671 return MPI_File_get_position_shared(fh, offset);
12672 }
12673
12674#endif
12675#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12677 return MPI_File_get_size(fh, size);
12678 }
12679
12680#endif
12681#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12682 template<typename DATATYPE>
12683 inline int AMPI_File_get_type_extent(AMPI_File fh, DATATYPE* datatype, AMPI_Aint* extent) {
12684 return MPI_File_get_type_extent(fh, datatype->getModifiedMpiType(), extent);
12685 }
12686
12687#endif
12688#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12689 template<typename ETYPE, typename FILETYPE>
12690 inline int AMPI_File_get_view(AMPI_File fh, AMPI_Offset* disp, ETYPE* etype, FILETYPE* filetype, char* datarep) {
12691 return MPI_File_get_view(fh, disp, etype->getModifiedMpiType(), filetype->getModifiedMpiType(), datarep);
12692 }
12693
12694#endif
12695#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12696 template<typename DATATYPE>
12697 inline int AMPI_File_iread(AMPI_File fh, void* buf, int count, DATATYPE* datatype, AMPI_Request* request) {
12698 return MPI_File_iread(fh, buf, count, datatype->getModifiedMpiType(), request);
12699 }
12700
12701#endif
12702#if MEDI_MPI_VERSION_3_1 <= MEDI_MPI_TARGET
12703 template<typename DATATYPE>
12704 inline int AMPI_File_iread_all(AMPI_File fh, void* buf, int count, DATATYPE* datatype, AMPI_Request* request) {
12705 return MPI_File_iread_all(fh, buf, count, datatype->getModifiedMpiType(), &request->request);
12706 }
12707
12708#endif
12709#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12710 template<typename DATATYPE>
12711 inline int AMPI_File_iread_at(AMPI_File fh, AMPI_Offset offset, void* buf, int count, DATATYPE* datatype,
12712 AMPI_Request* request) {
12713 return MPI_File_iread_at(fh, offset, buf, count, datatype->getModifiedMpiType(), &request->request);
12714 }
12715
12716#endif
12717#if MEDI_MPI_VERSION_3_1 <= MEDI_MPI_TARGET
12718 template<typename DATATYPE>
12719 inline int AMPI_File_iread_at_all(AMPI_File fh, AMPI_Offset offset, void* buf, int count, DATATYPE* datatype,
12720 AMPI_Request* request) {
12721 return MPI_File_iread_at_all(fh, offset, buf, count, datatype->getModifiedMpiType(), &request->request);
12722 }
12723
12724#endif
12725#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12726 template<typename DATATYPE>
12727 inline int AMPI_File_iread_shared(AMPI_File fh, void* buf, int count, DATATYPE* datatype, AMPI_Request* request) {
12728 return MPI_File_iread_shared(fh, buf, count, datatype->getModifiedMpiType(), &request->request);
12729 }
12730
12731#endif
12732#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12733 template<typename DATATYPE>
12734 inline int AMPI_File_iwrite(AMPI_File fh, const void* buf, int count, DATATYPE* datatype, AMPI_Request* request) {
12735 return MPI_File_iwrite(fh, buf, count, datatype->getModifiedMpiType(), &request->request);
12736 }
12737
12738#endif
12739#if MEDI_MPI_VERSION_3_1 <= MEDI_MPI_TARGET
12740 template<typename DATATYPE>
12741 inline int AMPI_File_iwrite_all(AMPI_File fh, const void* buf, int count, DATATYPE* datatype, AMPI_Request* request) {
12742 return MPI_File_iwrite_all(fh, buf, count, datatype->getModifiedMpiType(), &request->request);
12743 }
12744
12745#endif
12746#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12747 template<typename DATATYPE>
12748 inline int AMPI_File_iwrite_at(AMPI_File fh, AMPI_Offset offset, const void* buf, int count, DATATYPE* datatype,
12749 AMPI_Request* request) {
12750 return MPI_File_iwrite_at(fh, offset, buf, count, datatype->getModifiedMpiType(), &request->request);
12751 }
12752
12753#endif
12754#if MEDI_MPI_VERSION_3_1 <= MEDI_MPI_TARGET
12755 template<typename DATATYPE>
12756 inline int AMPI_File_iwrite_at_all(AMPI_File fh, AMPI_Offset offset, const void* buf, int count, DATATYPE* datatype,
12757 AMPI_Request* request) {
12758 return MPI_File_iwrite_at_all(fh, offset, buf, count, datatype->getModifiedMpiType(), &request->request);
12759 }
12760
12761#endif
12762#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12763 template<typename DATATYPE>
12764 inline int AMPI_File_iwrite_shared(AMPI_File fh, const void* buf, int count, DATATYPE* datatype,
12765 AMPI_Request* request) {
12766 return MPI_File_iwrite_shared(fh, buf, count, datatype->getModifiedMpiType(), &request->request);
12767 }
12768
12769#endif
12770#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12771 inline int AMPI_File_open(AMPI_Comm comm, MEDI_OPTIONAL_CONST char* filename, int amode, AMPI_Info info,
12772 AMPI_File* fh) {
12773 return MPI_File_open(comm, filename, amode, info, fh);
12774 }
12775
12776#endif
12777#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12779 return MPI_File_preallocate(fh, size);
12780 }
12781
12782#endif
12783#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12784 template<typename DATATYPE>
12785 inline int AMPI_File_read(AMPI_File fh, void* buf, int count, DATATYPE* datatype, AMPI_Status* status) {
12786 return MPI_File_read(fh, buf, count, datatype->getModifiedMpiType(), status);
12787 }
12788
12789#endif
12790#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12791 template<typename DATATYPE>
12792 inline int AMPI_File_read_all(AMPI_File fh, void* buf, int count, DATATYPE* datatype, AMPI_Status* status) {
12793 return MPI_File_read_all(fh, buf, count, datatype->getModifiedMpiType(), status);
12794 }
12795
12796#endif
12797#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12798 template<typename DATATYPE>
12799 inline int AMPI_File_read_all_begin(AMPI_File fh, void* buf, int count, DATATYPE* datatype) {
12800 return MPI_File_read_all_begin(fh, buf, count, datatype->getModifiedMpiType());
12801 }
12802
12803#endif
12804#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12805 inline int AMPI_File_read_all_end(AMPI_File fh, void* buf, AMPI_Status* status) {
12806 return MPI_File_read_all_end(fh, buf, status);
12807 }
12808
12809#endif
12810#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12811 template<typename DATATYPE>
12812 inline int AMPI_File_read_at(AMPI_File fh, AMPI_Offset offset, void* buf, int count, DATATYPE* datatype,
12813 AMPI_Status* status) {
12814 return MPI_File_read_at(fh, offset, buf, count, datatype->getModifiedMpiType(), status);
12815 }
12816
12817#endif
12818#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12819 template<typename DATATYPE>
12820 inline int AMPI_File_read_at_all(AMPI_File fh, AMPI_Offset offset, void* buf, int count, DATATYPE* datatype,
12821 AMPI_Status* status) {
12822 return MPI_File_read_at_all(fh, offset, buf, count, datatype->getModifiedMpiType(), status);
12823 }
12824
12825#endif
12826#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12827 template<typename DATATYPE>
12828 inline int AMPI_File_read_at_all_begin(AMPI_File fh, AMPI_Offset offset, void* buf, int count, DATATYPE* datatype) {
12829 return MPI_File_read_at_all_begin(fh, offset, buf, count, datatype->getModifiedMpiType());
12830 }
12831
12832#endif
12833#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12834 inline int AMPI_File_read_at_all_end(AMPI_File fh, void* buf, AMPI_Status* status) {
12835 return MPI_File_read_at_all_end(fh, buf, status);
12836 }
12837
12838#endif
12839#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12840 template<typename DATATYPE>
12841 inline int AMPI_File_read_ordered(AMPI_File fh, void* buf, int count, DATATYPE* datatype, AMPI_Status* status) {
12842 return MPI_File_read_ordered(fh, buf, count, datatype->getModifiedMpiType(), status);
12843 }
12844
12845#endif
12846#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12847 template<typename DATATYPE>
12848 inline int AMPI_File_read_ordered_begin(AMPI_File fh, void* buf, int count, DATATYPE* datatype) {
12849 return MPI_File_read_ordered_begin(fh, buf, count, datatype->getModifiedMpiType());
12850 }
12851
12852#endif
12853#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12854 inline int AMPI_File_read_ordered_end(AMPI_File fh, void* buf, AMPI_Status* status) {
12855 return MPI_File_read_ordered_end(fh, buf, status);
12856 }
12857
12858#endif
12859#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12860 template<typename DATATYPE>
12861 inline int AMPI_File_read_shared(AMPI_File fh, void* buf, int count, DATATYPE* datatype, AMPI_Status* status) {
12862 return MPI_File_read_shared(fh, buf, count, datatype->getModifiedMpiType(), status);
12863 }
12864
12865#endif
12866#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12867 inline int AMPI_File_seek(AMPI_File fh, AMPI_Offset offset, int whence) {
12868 return MPI_File_seek(fh, offset, whence);
12869 }
12870
12871#endif
12872#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12873 inline int AMPI_File_seek_shared(AMPI_File fh, AMPI_Offset offset, int whence) {
12874 return MPI_File_seek_shared(fh, offset, whence);
12875 }
12876
12877#endif
12878#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12879 inline int AMPI_File_set_atomicity(AMPI_File fh, int flag) {
12880 return MPI_File_set_atomicity(fh, flag);
12881 }
12882
12883#endif
12884#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12886 return MPI_File_set_info(fh, info);
12887 }
12888
12889#endif
12890#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12892 return MPI_File_set_size(fh, size);
12893 }
12894
12895#endif
12896#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12897 template<typename ETYPE, typename FILETYPE>
12898 inline int AMPI_File_set_view(AMPI_File fh, AMPI_Offset disp, ETYPE* etype, FILETYPE* filetype, const char* datarep,
12899 AMPI_Info info) {
12900 return MPI_File_set_view(fh, disp, etype->getModifiedMpiType(), filetype->getModifiedMpiType(), datarep, info);
12901 }
12902
12903#endif
12904#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12905 inline int AMPI_File_sync(AMPI_File fh) {
12906 return MPI_File_sync(fh);
12907 }
12908
12909#endif
12910#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12911 template<typename DATATYPE>
12912 inline int AMPI_File_write(AMPI_File fh, const void* buf, int count, DATATYPE* datatype, AMPI_Status* status) {
12913 return MPI_File_write(fh, buf, count, datatype->getModifiedMpiType(), status);
12914 }
12915
12916#endif
12917#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12918 template<typename DATATYPE>
12919 inline int AMPI_File_write_all(AMPI_File fh, const void* buf, int count, DATATYPE* datatype, AMPI_Status* status) {
12920 return MPI_File_write_all(fh, buf, count, datatype->getModifiedMpiType(), status);
12921 }
12922
12923#endif
12924#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12925 template<typename DATATYPE>
12926 inline int AMPI_File_write_all_begin(AMPI_File fh, const void* buf, int count, DATATYPE* datatype) {
12927 return MPI_File_write_all_begin(fh, buf, count, datatype->getModifiedMpiType());
12928 }
12929
12930#endif
12931#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12933 return MPI_File_write_all_end(fh, buf, status);
12934 }
12935
12936#endif
12937#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12938 template<typename DATATYPE>
12939 inline int AMPI_File_write_at(AMPI_File fh, AMPI_Offset offset, const void* buf, int count, DATATYPE* datatype,
12940 AMPI_Status* status) {
12941 return MPI_File_write_at(fh, offset, buf, count, datatype->getModifiedMpiType(), status);
12942 }
12943
12944#endif
12945#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12946 template<typename DATATYPE>
12947 inline int AMPI_File_write_at_all(AMPI_File fh, AMPI_Offset offset, const void* buf, int count, DATATYPE* datatype,
12948 AMPI_Status* status) {
12949 return MPI_File_write_at_all(fh, offset, buf, count, datatype->getModifiedMpiType(), status);
12950 }
12951
12952#endif
12953#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12954 template<typename DATATYPE>
12955 inline int AMPI_File_write_at_all_begin(AMPI_File fh, AMPI_Offset offset, const void* buf, int count,
12956 DATATYPE* datatype) {
12957 return MPI_File_write_at_all_begin(fh, offset, buf, count, datatype->getModifiedMpiType());
12958 }
12959
12960#endif
12961#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12963 return MPI_File_write_at_all_end(fh, buf, status);
12964 }
12965
12966#endif
12967#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12968 template<typename DATATYPE>
12969 inline int AMPI_File_write_ordered(AMPI_File fh, const void* buf, int count, DATATYPE* datatype, AMPI_Status* status) {
12970 return MPI_File_write_ordered(fh, buf, count, datatype->getModifiedMpiType(), status);
12971 }
12972
12973#endif
12974#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12975 template<typename DATATYPE>
12976 inline int AMPI_File_write_ordered_begin(AMPI_File fh, const void* buf, int count, DATATYPE* datatype) {
12977 return MPI_File_write_ordered_begin(fh, buf, count, datatype->getModifiedMpiType());
12978 }
12979
12980#endif
12981#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12983 return MPI_File_write_ordered_end(fh, buf, status);
12984 }
12985
12986#endif
12987#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12988 template<typename DATATYPE>
12989 inline int AMPI_File_write_shared(AMPI_File fh, const void* buf, int count, DATATYPE* datatype, AMPI_Status* status) {
12990 return MPI_File_write_shared(fh, buf, count, datatype->getModifiedMpiType(), status);
12991 }
12992
12993#endif
12994#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
12996 AMPI_Datarep_conversion_function* read_conversion_fn, AMPI_Datarep_conversion_function* write_conversion_fn,
12997 AMPI_Datarep_extent_function* dtype_file_extent_fn, void* extra_state) {
12998 return MPI_Register_datarep(datarep, read_conversion_fn, write_conversion_fn, dtype_file_extent_fn, extra_state);
12999 }
13000
13001#endif
13002#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
13003 inline MPI_Fint AMPI_Comm_c2f(AMPI_Comm comm) {
13004 return MPI_Comm_c2f(comm);
13005 }
13006
13007#endif
13008#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
13009 inline MPI_Comm AMPI_Comm_f2c(AMPI_Fint comm) {
13010 return MPI_Comm_f2c(comm);
13011 }
13012
13013#endif
13014#if MEDI_MPI_VERSION_2_1 <= MEDI_MPI_TARGET
13015 inline MPI_Fint AMPI_Errhandler_c2f(AMPI_Errhandler errhandler) {
13016 return MPI_Errhandler_c2f(errhandler);
13017 }
13018
13019#endif
13020#if MEDI_MPI_VERSION_2_1 <= MEDI_MPI_TARGET
13021 inline MPI_Errhandler AMPI_Errhandler_f2c(AMPI_Fint errhandler) {
13022 return MPI_Errhandler_f2c(errhandler);
13023 }
13024
13025#endif
13026#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
13027 inline MPI_Fint AMPI_File_c2f(AMPI_File file) {
13028 return MPI_File_c2f(file);
13029 }
13030
13031#endif
13032#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
13033 inline MPI_File AMPI_File_f2c(AMPI_Fint file) {
13034 return MPI_File_f2c(file);
13035 }
13036
13037#endif
13038#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
13039 inline MPI_Fint AMPI_Group_c2f(AMPI_Group group) {
13040 return MPI_Group_c2f(group);
13041 }
13042
13043#endif
13044#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
13045 inline MPI_Group AMPI_Group_f2c(AMPI_Fint group) {
13046 return MPI_Group_f2c(group);
13047 }
13048
13049#endif
13050#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
13051 inline MPI_Fint AMPI_Info_c2f(AMPI_Info info) {
13052 return MPI_Info_c2f(info);
13053 }
13054
13055#endif
13056#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
13057 inline MPI_Info AMPI_Info_f2c(AMPI_Fint info) {
13058 return MPI_Info_f2c(info);
13059 }
13060
13061#endif
13062#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
13064 return MPI_Status_c2f(c_status, f_status);
13065 }
13066
13067#endif
13068#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
13070 return MPI_Status_f2c(f_status, c_status);
13071 }
13072
13073#endif
13074#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
13075 inline MPI_Fint AMPI_Win_c2f(AMPI_Win win) {
13076 return MPI_Win_c2f(win);
13077 }
13078
13079#endif
13080#if MEDI_MPI_VERSION_2_0 <= MEDI_MPI_TARGET
13081 inline MPI_Win AMPI_Win_f2c(AMPI_Fint win) {
13082 return MPI_Win_f2c(win);
13083 }
13084
13085#endif
13086#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13087 inline int AMPI_T_category_changed(int* stamp) {
13088 return MPI_T_category_changed(stamp);
13089 }
13090
13091#endif
13092#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13093 inline int AMPI_T_category_get_categories(int cat_index, int len, int* indices) {
13094 return MPI_T_category_get_categories(cat_index, len, indices);
13095 }
13096
13097#endif
13098#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13099 inline int AMPI_T_category_get_cvars(int cat_index, int len, int* indices) {
13100 return MPI_T_category_get_cvars(cat_index, len, indices);
13101 }
13102
13103#endif
13104#if MEDI_MPI_VERSION_3_1 <= MEDI_MPI_TARGET
13105 inline int AMPI_T_category_get_index(const char* name, int* cat_index) {
13106 return MPI_T_category_get_index(name, cat_index);
13107 }
13108
13109#endif
13110#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13111 inline int AMPI_T_category_get_info(int cat_index, char* name, int* name_len, char* desc, int* desc_len, int* num_cvars,
13112 int* num_pvars, int* num_categories) {
13113 return MPI_T_category_get_info(cat_index, name, name_len, desc, desc_len, num_cvars, num_pvars, num_categories);
13114 }
13115
13116#endif
13117#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13118 inline int AMPI_T_category_get_num(int* num_cat) {
13119 return MPI_T_category_get_num(num_cat);
13120 }
13121
13122#endif
13123#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13124 inline int AMPI_T_category_get_pvars(int cat_index, int len, int* indices) {
13125 return MPI_T_category_get_pvars(cat_index, len, indices);
13126 }
13127
13128#endif
13129#if MEDI_MPI_VERSION_3_1 <= MEDI_MPI_TARGET
13130 inline int AMPI_T_cvar_get_index(const char* name, int* cvar_index) {
13131 return MPI_T_cvar_get_index(name, cvar_index);
13132 }
13133
13134#endif
13135#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13136 inline int AMPI_T_cvar_get_num(int* num_cvar) {
13137 return MPI_T_cvar_get_num(num_cvar);
13138 }
13139
13140#endif
13141#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13142 inline int AMPI_T_cvar_handle_alloc(int cvar_index, void* obj_handle, AMPI_T_cvar_handle* handle, int* count) {
13143 return MPI_T_cvar_handle_alloc(cvar_index, obj_handle, handle, count);
13144 }
13145
13146#endif
13147#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13149 return MPI_T_cvar_handle_free(handle);
13150 }
13151
13152#endif
13153#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13154 inline int AMPI_T_cvar_read(AMPI_T_cvar_handle handle, void* buf) {
13155 return MPI_T_cvar_read(handle, buf);
13156 }
13157
13158#endif
13159#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13160 inline int AMPI_T_cvar_write(AMPI_T_cvar_handle handle, const void* buf) {
13161 return MPI_T_cvar_write(handle, buf);
13162 }
13163
13164#endif
13165#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13166 inline int AMPI_T_enum_get_info(AMPI_T_enum enumtype, int* num, char* name, int* name_len) {
13167 return MPI_T_enum_get_info(enumtype, num, name, name_len);
13168 }
13169
13170#endif
13171#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13172 inline int AMPI_T_enum_get_item(AMPI_T_enum enumtype, int index, int* value, char* name, int* name_len) {
13173 return MPI_T_enum_get_item(enumtype, index, value, name, name_len);
13174 }
13175
13176#endif
13177#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13178 inline int AMPI_T_finalize() {
13179 return MPI_T_finalize();
13180 }
13181
13182#endif
13183#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13184 inline int AMPI_T_init_thread(int required, int* provided) {
13185 return MPI_T_init_thread(required, provided);
13186 }
13187
13188#endif
13189#if MEDI_MPI_VERSION_3_1 <= MEDI_MPI_TARGET
13190 inline int AMPI_T_pvar_get_index(const char* name, int var_class, int* pvar_index) {
13191 return MPI_T_pvar_get_index(name, var_class, pvar_index);
13192 }
13193
13194#endif
13195#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13196 inline int AMPI_T_pvar_get_num(int* num_pvar) {
13197 return MPI_T_pvar_get_num(num_pvar);
13198 }
13199
13200#endif
13201#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13202 inline int AMPI_T_pvar_handle_alloc(AMPI_T_pvar_session session, int pvar_index, void* obj_handle,
13203 AMPI_T_pvar_handle* handle, int* count) {
13204 return MPI_T_pvar_handle_alloc(session, pvar_index, obj_handle, handle, count);
13205 }
13206
13207#endif
13208#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13210 return MPI_T_pvar_handle_free(session, handle);
13211 }
13212
13213#endif
13214#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13215 inline int AMPI_T_pvar_read(AMPI_T_pvar_session session, AMPI_T_pvar_handle handle, void* buf) {
13216 return MPI_T_pvar_read(session, handle, buf);
13217 }
13218
13219#endif
13220#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13221 inline int AMPI_T_pvar_readreset(AMPI_T_pvar_session session, AMPI_T_pvar_handle handle, void* buf) {
13222 return MPI_T_pvar_readreset(session, handle, buf);
13223 }
13224
13225#endif
13226#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13228 return MPI_T_pvar_reset(session, handle);
13229 }
13230
13231#endif
13232#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13234 return MPI_T_pvar_session_create(session);
13235 }
13236
13237#endif
13238#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13240 return MPI_T_pvar_session_free(session);
13241 }
13242
13243#endif
13244#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13246 return MPI_T_pvar_start(session, handle);
13247 }
13248
13249#endif
13250#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13252 return MPI_T_pvar_stop(session, handle);
13253 }
13254
13255#endif
13256#if MEDI_MPI_VERSION_3_0 <= MEDI_MPI_TARGET
13257 inline int AMPI_T_pvar_write(AMPI_T_pvar_session session, AMPI_T_pvar_handle handle, const void* buf) {
13258 return MPI_T_pvar_write(session, handle, buf);
13259 }
13260
13261#endif
13262#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET && MEDI_MPI_TARGET < MEDI_MPI_VERSION_3_0
13263 inline int AMPI_Address(void* location, AMPI_Aint* address) {
13264 return MPI_Address(location, address);
13265 }
13266
13267#endif
13268#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
13269 inline int AMPI_Attr_delete(AMPI_Comm comm, int keyval) {
13270 return MPI_Attr_delete(comm, keyval);
13271 }
13272
13273#endif
13274#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
13275 inline int AMPI_Attr_get(AMPI_Comm comm, int keyval, void* attribute_val, int* flag) {
13276 return MPI_Attr_get(comm, keyval, attribute_val, flag);
13277 }
13278
13279#endif
13280#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
13281 inline int AMPI_Attr_put(AMPI_Comm comm, int keyval, void* attribute_val) {
13282 return MPI_Attr_put(comm, keyval, attribute_val);
13283 }
13284
13285#endif
13286#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
13287 inline int AMPI_Keyval_create(AMPI_Copy_function* copy_fn, AMPI_Delete_function* delete_fn, int* keyval,
13288 void* extra_state) {
13289 return MPI_Keyval_create(copy_fn, delete_fn, keyval, extra_state);
13290 }
13291
13292#endif
13293#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
13294 inline int AMPI_Keyval_free(int* keyval) {
13295 return MPI_Keyval_free(keyval);
13296 }
13297
13298#endif
13299#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET && MEDI_MPI_TARGET < MEDI_MPI_VERSION_3_0
13300 inline int AMPI_Errhandler_create(AMPI_Handler_function* function, AMPI_Errhandler* errhandler) {
13301 return MPI_Errhandler_create(function, errhandler);
13302 }
13303
13304#endif
13305#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET && MEDI_MPI_TARGET < MEDI_MPI_VERSION_3_0
13306 inline int AMPI_Errhandler_get(AMPI_Comm comm, AMPI_Errhandler* errhandler) {
13307 return MPI_Errhandler_get(comm, errhandler);
13308 }
13309
13310#endif
13311#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET && MEDI_MPI_TARGET < MEDI_MPI_VERSION_3_0
13312 inline int AMPI_Errhandler_set(AMPI_Comm comm, AMPI_Errhandler errhandler) {
13313 return MPI_Errhandler_set(comm, errhandler);
13314 }
13315
13316#endif
13317#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET && MEDI_MPI_TARGET < MEDI_MPI_VERSION_3_0
13318 template<typename DATATYPE>
13319 inline int AMPI_Type_extent(DATATYPE* datatype, AMPI_Aint* extent) {
13320 return MPI_Type_extent(datatype->getModifiedMpiType(), extent);
13321 }
13322
13323#endif
13324#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET && MEDI_MPI_TARGET < MEDI_MPI_VERSION_3_0
13325 template<typename DATATYPE>
13326 inline int AMPI_Type_lb(DATATYPE* datatype, AMPI_Aint* displacement) {
13327 return MPI_Type_lb(datatype->getModifiedMpiType(), displacement);
13328 }
13329
13330#endif
13331#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET && MEDI_MPI_TARGET < MEDI_MPI_VERSION_3_0
13332 template<typename DATATYPE>
13333 inline int AMPI_Type_ub(DATATYPE* datatype, AMPI_Aint* displacement) {
13334 return MPI_Type_ub(datatype->getModifiedMpiType(), displacement);
13335 }
13336
13337#endif
13338
13339#if MEDI_MPI_VERSION_1_0 <= MEDI_MPI_TARGET
13340#define AMPI_Pcontrol MPI_Pcontrol
13341#endif
13342
13343
13344}
#define AMPI_T_pvar_session
Definition ampiDefinitions.h:805
#define AMPI_Status
Definition ampiDefinitions.h:772
#define AMPI_T_cvar_handle
Definition ampiDefinitions.h:799
#define AMPI_Errhandler
Definition ampiDefinitions.h:781
#define AMPI_T_pvar_handle
Definition ampiDefinitions.h:802
#define AMPI_Aint
Definition ampiDefinitions.h:760
#define AMPI_Info
Definition ampiDefinitions.h:790
#define AMPI_Win
Definition ampiDefinitions.h:793
#define AMPI_Group
Definition ampiDefinitions.h:787
#define AMPI_Comm
Definition ampiDefinitions.h:778
#define AMPI_Fint
Definition ampiDefinitions.h:766
#define AMPI_Count
Definition ampiDefinitions.h:763
#define AMPI_Offset
Definition ampiDefinitions.h:769
#define AMPI_File
Definition ampiDefinitions.h:784
#define AMPI_T_enum
Definition ampiDefinitions.h:796
Definition adjointInterface.hpp:40
virtual void updateAdjoints(const void *indices, const void *adjoints, int elements) const =0
Add the adjoint varaibles to the ones in the AD tool. That is the AD tool should perform the operatio...
virtual void createPrimalTypeBuffer(void *&buf, size_t size) const =0
Create an array for the primal variables.
virtual void deletePrimalTypeBuffer(void *&buf) const =0
Delete the array of the primal variables.
virtual void getPrimals(const void *indices, const void *primals, int elements) const =0
Get the primal values from the AD tool.
virtual void getAdjoints(const void *indices, void *adjoints, int elements) const =0
Get the adjoints for the indices from the AD tool.
virtual void createAdjointTypeBuffer(void *&buf, size_t size) const =0
Create an array for the adjoint variables.
virtual int getVectorSize() const =0
The vector size for the current evaluation.
virtual void combineAdjoints(void *buf, const int elements, const int ranks) const =0
Perform a reduction in the first element of the buffer.
virtual void deleteAdjointTypeBuffer(void *&buf) const =0
Delete the array of the adjoint variables.
virtual void setPrimals(const void *indices, const void *primals, int elements) const =0
Set the primal values on the AD tool.
Wrapper interface for MPI types in communications.
Definition typeInterface.hpp:63
#define MEDI_OPTIONAL_CONST
Definition macros.h:70
#define MEDI_UNUSED(name)
Definition macros.h:108
int Range[3]
Definition mpiTools.h:43
Global namespace for MeDiPack - Message Differentiation Package.
Definition adjointInterface.hpp:37
void AMPI_Igatherv_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:9035
int AMPI_Comm_free_keyval(int *comm_keyval)
Definition ampiFunctions.hpp:11848
int AMPI_T_enum_get_info(MPI_T_enum enumtype, int *num, char *name, int *name_len)
Definition ampiFunctions.hpp:13166
int AMPI_Info_dup(MPI_Info info, MPI_Info *newinfo)
Definition ampiFunctions.hpp:12455
MPI_Comm_errhandler_function AMPI_Comm_errhandler_function
Definition ampiDefinitions.h:848
int AMPI_Errhandler_free(MPI_Errhandler *errhandler)
Definition ampiFunctions.hpp:12323
int AMPI_Topo_test(MPI_Comm comm, int *status)
Definition ampiFunctions.hpp:12245
MPI_Win AMPI_Win_f2c(MPI_Fint win)
Definition ampiFunctions.hpp:13081
int AMPI_Reduce_global(const typename DATATYPE::Type *sendbuf, typename DATATYPE::Type *recvbuf, int count, DATATYPE *datatype, AMPI_Op op, int root, MPI_Comm comm)
Definition ampiFunctions.hpp:10845
void AMPI_Irsend_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:1268
void AMPI_Iscatter_p_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:9924
int AMPI_Allgather(const typename SENDTYPE::Type *sendbuf, int sendcount, SENDTYPE *sendtype, typename RECVTYPE::Type *recvbuf, int recvcount, RECVTYPE *recvtype, MPI_Comm comm)
Definition ampiFunctions.hpp:4061
void AMPI_Iscatter_d_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:9964
int AMPI_File_get_amode(MPI_File fh, int *amode)
Definition ampiFunctions.hpp:12634
int AMPI_Send_init_postEnd(HandleBase *handle)
Definition ampiFunctions.hpp:3266
void AMPI_Igatherv_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:9122
int AMPI_File_create_errhandler(AMPI_File_errhandler_function *file_errhandler_fn, MPI_Errhandler *errhandler)
Definition ampiFunctions.hpp:12347
int AMPI_T_pvar_stop(MPI_T_pvar_session session, MPI_T_pvar_handle handle)
Definition ampiFunctions.hpp:13251
int AMPI_Free_mem(void *base)
Definition ampiFunctions.hpp:12383
int AMPI_Grequest_start(AMPI_Grequest_query_function *query_fn, AMPI_Grequest_free_function *free_fn, AMPI_Grequest_cancel_function *cancel_fn, void *extra_state, AMPI_Request *request)
Definition ampiFunctions.hpp:12583
int AMPI_File_write_all_begin(MPI_File fh, const void *buf, int count, DATATYPE *datatype)
Definition ampiFunctions.hpp:12926
MPI_Datarep_conversion_function AMPI_Datarep_conversion_function
Definition ampiDefinitions.h:878
void AMPI_Irecv_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:1004
int AMPI_Group_intersection(MPI_Group group1, MPI_Group group2, MPI_Group *newgroup)
Definition ampiFunctions.hpp:11974
int AMPI_Info_delete(MPI_Info info, const char *key)
Definition ampiFunctions.hpp:12449
int AMPI_Get_elements(const MPI_Status *status, DATATYPE *datatype, int *count)
Definition ampiFunctions.hpp:11713
void AMPI_Igather_d_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:8694
void AMPI_Ibcast_wrap_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:8299
void AMPI_Isend_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:1490
MPI_Delete_function AMPI_Delete_function
Definition ampiDefinitions.h:884
void AMPI_Reduce_global_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:10806
void AMPI_Iallreduce_global_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:7071
int AMPI_Issend(const typename DATATYPE::Type *buf, int count, DATATYPE *datatype, int dest, int tag, MPI_Comm comm, AMPI_Request *request)
Definition ampiFunctions.hpp:1813
int AMPI_Bsend_init(const typename DATATYPE::Type *buf, int count, DATATYPE *datatype, int dest, int tag, MPI_Comm comm, AMPI_Request *request)
Definition ampiFunctions.hpp:467
int AMPI_File_write_all_end(MPI_File fh, const void *buf, MPI_Status *status)
Definition ampiFunctions.hpp:12932
void AMPI_Gatherv_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:6028
int AMPI_Comm_delete_attr(MPI_Comm comm, int comm_keyval)
Definition ampiFunctions.hpp:11824
int AMPI_Type_get_true_extent_x(DATATYPE *datatype, MPI_Count *true_lb, MPI_Count *true_extent)
Definition ampiFunctions.hpp:11765
void AMPI_Imrecv_p_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:725
int AMPI_Close_port(const char *port_name)
Definition ampiFunctions.hpp:12497
int AMPI_T_pvar_start(MPI_T_pvar_session session, MPI_T_pvar_handle handle)
Definition ampiFunctions.hpp:13245
int MPI_Ibcast_wrap(void *bufferSend, void *bufferRecv, int count, MPI_Datatype type, int root, MPI_Comm comm, MPI_Request *request)
Definition wrappers.hpp:68
int AMPI_Graph_map(MPI_Comm comm, int nnodes, const int *index, const int *edges, int *newrank)
Definition ampiFunctions.hpp:12220
int AMPI_Attr_delete(MPI_Comm comm, int keyval)
Definition ampiFunctions.hpp:13269
MPI_Aint AMPI_Aint_add(MPI_Aint base, MPI_Aint disp)
Definition ampiFunctions.hpp:11694
void AMPI_Iallgatherv_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:6745
int AMPI_Mrecv(typename DATATYPE::Type *buf, int count, DATATYPE *datatype, AMPI_Message *message, MPI_Status *status, RecvAdjCall reverse_send=RecvAdjCall::Send)
Definition ampiFunctions.hpp:2032
int AMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int *coords)
Definition ampiFunctions.hpp:12121
MPI_Aint AMPI_Aint_diff(MPI_Aint addr1, MPI_Aint addr2)
Definition ampiFunctions.hpp:11700
int AMPI_File_read_ordered(MPI_File fh, void *buf, int count, DATATYPE *datatype, MPI_Status *status)
Definition ampiFunctions.hpp:12841
void AMPI_Iscatterv_b_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:10421
int AMPI_Comm_join(int fd, MPI_Comm *intercomm)
Definition ampiFunctions.hpp:12529
int AMPI_T_finalize()
Definition ampiFunctions.hpp:13178
int AMPI_Comm_group(MPI_Comm comm, MPI_Group *group)
Definition ampiFunctions.hpp:11872
void AMPI_Issend_d_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:1778
void AMPI_Bsend_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:88
int AMPI_Status_set_cancelled(MPI_Status *status, int flag)
Definition ampiFunctions.hpp:12602
int AMPI_Iallreduce_global_finish(HandleBase *handle)
Definition ampiFunctions.hpp:7333
int AMPI_T_enum_get_item(MPI_T_enum enumtype, int index, int *value, char *name, int *name_len)
Definition ampiFunctions.hpp:13172
void AMPI_Igather_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:8672
int AMPI_Add_error_code(int errorclass, int *errorcode)
Definition ampiFunctions.hpp:12275
int AMPI_Open_port(MPI_Info info, char *port_name)
Definition ampiFunctions.hpp:12557
int AMPI_Barrier(MPI_Comm comm)
Definition ampiFunctions.hpp:11785
void AMPI_Send_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:2971
void AMPI_Iscatterv_p_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:10333
int AMPI_Info_get_nthkey(MPI_Info info, int n, char *key)
Definition ampiFunctions.hpp:12479
void AMPI_Alltoall_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:4813
void AMPI_Bsend_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:72
void AMPI_Imrecv_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:739
int AMPI_Info_free(MPI_Info *info)
Definition ampiFunctions.hpp:12461
void AMPI_Alltoallv_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:5078
int AMPI_Dist_graph_neighbors_count(MPI_Comm comm, int *indegree, int *outdegree, int *weighted)
Definition ampiFunctions.hpp:12201
void AMPI_Alltoallv_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:5143
int AMPI_File_iwrite_all(MPI_File fh, const void *buf, int count, DATATYPE *datatype, AMPI_Request *request)
Definition ampiFunctions.hpp:12741
int AMPI_File_iread(MPI_File fh, void *buf, int count, DATATYPE *datatype, AMPI_Request *request)
Definition ampiFunctions.hpp:12697
int AMPI_Type_set_name(DATATYPE *datatype, const char *type_name)
Definition ampiFunctions.hpp:12072
int AMPI_Win_get_errhandler(MPI_Win win, MPI_Errhandler *errhandler)
Definition ampiFunctions.hpp:12431
int AMPI_File_get_position_shared(MPI_File fh, MPI_Offset *offset)
Definition ampiFunctions.hpp:12670
int AMPI_T_pvar_readreset(MPI_T_pvar_session session, MPI_T_pvar_handle handle, void *buf)
Definition ampiFunctions.hpp:13221
void AMPI_Ireduce_global_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:9560
int AMPI_Ssend_init_postEnd(HandleBase *handle)
Definition ampiFunctions.hpp:3895
int AMPI_Rsend_init(const typename DATATYPE::Type *buf, int count, DATATYPE *datatype, int dest, int tag, MPI_Comm comm, AMPI_Request *request)
Definition ampiFunctions.hpp:2724
int AMPI_Bsend_init_finish(HandleBase *handle)
Definition ampiFunctions.hpp:590
int AMPI_Bsend(const typename DATATYPE::Type *buf, int count, DATATYPE *datatype, int dest, int tag, MPI_Comm comm)
Definition ampiFunctions.hpp:119
int AMPI_Iallgather_finish(HandleBase *handle)
Definition ampiFunctions.hpp:6539
int AMPI_File_get_position(MPI_File fh, MPI_Offset *offset)
Definition ampiFunctions.hpp:12664
int AMPI_Cart_create(MPI_Comm comm_old, int ndims, const int *dims, const int *periods, int reorder, MPI_Comm *comm_cart)
Definition ampiFunctions.hpp:12127
void AMPI_Ireduce_global_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:9521
void AMPI_Gather_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:5667
int AMPI_Alltoallv(const typename SENDTYPE::Type *sendbuf, const int *sendcounts, const int *sdispls, SENDTYPE *sendtype, typename RECVTYPE::Type *recvbuf, const int *recvcounts, const int *rdispls, RECVTYPE *recvtype, MPI_Comm comm)
Definition ampiFunctions.hpp:5177
int AMPI_Irsend_finish(HandleBase *handle)
Definition ampiFunctions.hpp:1403
int AMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status *status)
Definition ampiFunctions.hpp:11676
int AMPI_T_category_get_info(int cat_index, char *name, int *name_len, char *desc, int *desc_len, int *num_cvars, int *num_pvars, int *num_categories)
Definition ampiFunctions.hpp:13111
int AMPI_Allgatherv(const typename SENDTYPE::Type *sendbuf, int sendcount, SENDTYPE *sendtype, typename RECVTYPE::Type *recvbuf, const int *recvcounts, const int *displs, RECVTYPE *recvtype, MPI_Comm comm)
Definition ampiFunctions.hpp:4331
int AMPI_Ialltoallv_finish(HandleBase *handle)
Definition ampiFunctions.hpp:8124
int AMPI_File_get_size(MPI_File fh, MPI_Offset *size)
Definition ampiFunctions.hpp:12676
int AMPI_Add_error_class(int *errorclass)
Definition ampiFunctions.hpp:12269
int AMPI_Gather(const typename SENDTYPE::Type *sendbuf, int sendcount, SENDTYPE *sendtype, typename RECVTYPE::Type *recvbuf, int recvcount, RECVTYPE *recvtype, int root, MPI_Comm comm)
Definition ampiFunctions.hpp:5758
void AMPI_Issend_p_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:1753
void AMPI_Recv_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:2193
void AMPI_Iallgatherv_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:6668
int AMPI_Isend_finish(HandleBase *handle)
Definition ampiFunctions.hpp:1650
MPI_File_errhandler_function AMPI_File_errhandler_function
Definition ampiDefinitions.h:854
int AMPI_Keyval_free(int *keyval)
Definition ampiFunctions.hpp:13294
int AMPI_Is_thread_main(int *flag)
Definition ampiFunctions.hpp:12590
MPI_Win_copy_attr_function AMPI_Win_copy_attr_function
Definition ampiDefinitions.h:836
int AMPI_Type_size(DATATYPE *datatype, int *size)
Definition ampiFunctions.hpp:11772
void AMPI_Ialltoallv_d_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:7897
int AMPI_Comm_size(MPI_Comm comm, int *size)
Definition ampiFunctions.hpp:11920
int AMPI_Get_library_version(char *version, int *resultlen)
Definition ampiFunctions.hpp:12389
int AMPI_Iscatter_finish(HandleBase *handle)
Definition ampiFunctions.hpp:10164
int AMPI_Buffer_attach(void *buffer, int size)
Definition ampiFunctions.hpp:11645
int AMPI_T_pvar_read(MPI_T_pvar_session session, MPI_T_pvar_handle handle, void *buf)
Definition ampiFunctions.hpp:13215
int AMPI_File_set_size(MPI_File fh, MPI_Offset size)
Definition ampiFunctions.hpp:12891
void AMPI_Allgather_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:4033
int AMPI_Igather(const typename SENDTYPE::Type *sendbuf, int sendcount, SENDTYPE *sendtype, typename RECVTYPE::Type *recvbuf, int recvcount, RECVTYPE *recvtype, int root, MPI_Comm comm, AMPI_Request *request)
Definition ampiFunctions.hpp:8753
int AMPI_Send_init_finish(HandleBase *handle)
Definition ampiFunctions.hpp:3226
int AMPI_Rsend_init_preStart(HandleBase *handle)
Definition ampiFunctions.hpp:2768
int AMPI_Ssend_init(const typename DATATYPE::Type *buf, int count, DATATYPE *datatype, int dest, int tag, MPI_Comm comm, AMPI_Request *request)
Definition ampiFunctions.hpp:3732
int AMPI_Get_version(int *version, int *subversion)
Definition ampiFunctions.hpp:12401
void AMPI_Ibcast_wrap_b_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:8358
int AMPI_Cart_rank(MPI_Comm comm, const int *coords, int *rank)
Definition ampiFunctions.hpp:12147
int AMPI_Iscatter(const typename SENDTYPE::Type *sendbuf, int sendcount, SENDTYPE *sendtype, typename RECVTYPE::Type *recvbuf, int recvcount, RECVTYPE *recvtype, int root, MPI_Comm comm, AMPI_Request *request)
Definition ampiFunctions.hpp:10021
int AMPI_File_get_atomicity(MPI_File fh, int *flag)
Definition ampiFunctions.hpp:12640
int AMPI_T_category_get_cvars(int cat_index, int len, int *indices)
Definition ampiFunctions.hpp:13099
int AMPI_Dims_create(int nnodes, int ndims, int *dims)
Definition ampiFunctions.hpp:12171
void AMPI_Ialltoall_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:7495
int AMPI_File_seek_shared(MPI_File fh, MPI_Offset offset, int whence)
Definition ampiFunctions.hpp:12873
void AMPI_Gather_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:5726
void AMPI_Scatter_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:11090
int AMPI_Comm_remote_group(MPI_Comm comm, MPI_Group *group)
Definition ampiFunctions.hpp:11890
int AMPI_Info_set(MPI_Info info, const char *key, const char *value)
Definition ampiFunctions.hpp:12491
int AMPI_Graph_get(MPI_Comm comm, int maxindex, int maxedges, int *index, int *edges)
Definition ampiFunctions.hpp:12214
void AMPI_Bcast_wrap_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:5425
int AMPI_File_get_errhandler(MPI_File file, MPI_Errhandler *errhandler)
Definition ampiFunctions.hpp:12359
int AMPI_Attr_get(MPI_Comm comm, int keyval, void *attribute_val, int *flag)
Definition ampiFunctions.hpp:13275
int AMPI_Igather_finish(HandleBase *handle)
Definition ampiFunctions.hpp:8896
int AMPI_File_get_view(MPI_File fh, MPI_Offset *disp, ETYPE *etype, FILETYPE *filetype, char *datarep)
Definition ampiFunctions.hpp:12690
int AMPI_Scatterv(const typename SENDTYPE::Type *sendbuf, const int *sendcounts, const int *displs, SENDTYPE *sendtype, typename RECVTYPE::Type *recvbuf, int recvcount, RECVTYPE *recvtype, int root, MPI_Comm comm)
Definition ampiFunctions.hpp:11457
void AMPI_Sendrecv_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:3357
int AMPI_Cartdim_get(MPI_Comm comm, int *ndims)
Definition ampiFunctions.hpp:12165
void AMPI_Ibcast_wrap_p_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:8282
int AMPI_Ibcast_wrap(typename DATATYPE::Type *bufferSend, typename DATATYPE::Type *bufferRecv, int count, DATATYPE *datatype, int root, MPI_Comm comm, AMPI_Request *request)
Definition ampiFunctions.hpp:8375
MPI_Comm AMPI_Comm_f2c(MPI_Fint comm)
Definition ampiFunctions.hpp:13009
int AMPI_Graph_neighbors(MPI_Comm comm, int rank, int maxneighbors, int *neighbors)
Definition ampiFunctions.hpp:12227
void AMPI_Mrecv_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:1996
int AMPI_Isend(const typename DATATYPE::Type *buf, int count, DATATYPE *datatype, int dest, int tag, MPI_Comm comm, AMPI_Request *request)
Definition ampiFunctions.hpp:1566
void AMPI_Iscatterv_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:10309
int AMPI_File_iread_at(MPI_File fh, MPI_Offset offset, void *buf, int count, DATATYPE *datatype, AMPI_Request *request)
Definition ampiFunctions.hpp:12711
int AMPI_Win_create_errhandler(AMPI_Win_errhandler_function *win_errhandler_fn, MPI_Errhandler *errhandler)
Definition ampiFunctions.hpp:12419
void AMPI_Iscatterv_d_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:10377
int AMPI_File_read_at_all_begin(MPI_File fh, MPI_Offset offset, void *buf, int count, DATATYPE *datatype)
Definition ampiFunctions.hpp:12828
int AMPI_File_open(MPI_Comm comm, const char *filename, int amode, MPI_Info info, MPI_File *fh)
Definition ampiFunctions.hpp:12771
int AMPI_Type_size_x(DATATYPE *datatype, MPI_Count *size)
Definition ampiFunctions.hpp:11779
void AMPI_Ibsend_p_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:254
void AMPI_Mrecv_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:2012
IrecvAdjCall
Definition enums.hpp:40
int AMPI_File_read_at_all(MPI_File fh, MPI_Offset offset, void *buf, int count, DATATYPE *datatype, MPI_Status *status)
Definition ampiFunctions.hpp:12820
int AMPI_Comm_set_name(MPI_Comm comm, const char *comm_name)
Definition ampiFunctions.hpp:11914
int AMPI_Igatherv_finish(HandleBase *handle)
Definition ampiFunctions.hpp:9337
int AMPI_Comm_set_info(MPI_Comm comm, MPI_Info info)
Definition ampiFunctions.hpp:11908
int AMPI_Type_create_keyval(AMPI_Type_copy_attr_function *type_copy_attr_fn, AMPI_Type_delete_attr_function *type_delete_attr_fn, int *type_keyval, void *extra_state)
Definition ampiFunctions.hpp:12030
int AMPI_Comm_spawn_multiple(int count, char **array_of_commands, char ***array_of_argv, const int *array_of_maxprocs, const MPI_Info *array_of_info, int root, MPI_Comm comm, MPI_Comm *intercomm, int *array_of_errcodes)
Definition ampiFunctions.hpp:12542
MPI_Fint AMPI_Win_c2f(MPI_Win win)
Definition ampiFunctions.hpp:13075
int AMPI_Win_get_name(MPI_Win win, char *win_name, int *resultlen)
Definition ampiFunctions.hpp:12103
int AMPI_File_set_atomicity(MPI_File fh, int flag)
Definition ampiFunctions.hpp:12879
int AMPI_T_init_thread(int required, int *provided)
Definition ampiFunctions.hpp:13184
int AMPI_T_category_get_categories(int cat_index, int len, int *indices)
Definition ampiFunctions.hpp:13093
void AMPI_Iallgather_d_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:6358
int AMPI_Irecv_finish(HandleBase *handle)
Definition ampiFunctions.hpp:1150
int AMPI_Attr_put(MPI_Comm comm, int keyval, void *attribute_val)
Definition ampiFunctions.hpp:13281
void AMPI_Allreduce_global_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:4564
int AMPI_Ialltoall(const typename SENDTYPE::Type *sendbuf, int sendcount, SENDTYPE *sendtype, typename RECVTYPE::Type *recvbuf, int recvcount, RECVTYPE *recvtype, MPI_Comm comm, AMPI_Request *request)
Definition ampiFunctions.hpp:7566
int AMPI_Group_range_incl(MPI_Group group, int n, ::medi::common::Range *ranges, MPI_Group *newgroup)
Definition ampiFunctions.hpp:11986
int AMPI_File_delete(const char *filename, MPI_Info info)
Definition ampiFunctions.hpp:12628
int AMPI_Group_rank(MPI_Group group, int *rank)
Definition ampiFunctions.hpp:11992
int AMPI_Rsend_init_finish(HandleBase *handle)
Definition ampiFunctions.hpp:2847
void AMPI_Ialltoallv_p_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:7854
void AMPI_Ibcast_wrap_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:8334
void AMPI_Irsend_d_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:1284
int AMPI_File_iwrite(MPI_File fh, const void *buf, int count, DATATYPE *datatype, AMPI_Request *request)
Definition ampiFunctions.hpp:12734
void AMPI_Igatherv_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:9081
void AMPI_Ibcast_wrap_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:8261
void AMPI_Irecv_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:977
int AMPI_File_set_info(MPI_File fh, MPI_Info info)
Definition ampiFunctions.hpp:12885
int AMPI_Status_set_elements_x(MPI_Status *status, DATATYPE *datatype, MPI_Count count)
Definition ampiFunctions.hpp:12616
int AMPI_Win_create_keyval(AMPI_Win_copy_attr_function *win_copy_attr_fn, AMPI_Win_delete_attr_function *win_delete_attr_fn, int *win_keyval, void *extra_state)
Definition ampiFunctions.hpp:12078
int computeDisplacementsTotalSize(const int *counts, int ranks)
Compute the total size of a message that has a different size on each rank.
Definition displacementTools.hpp:105
int AMPI_Comm_test_inter(MPI_Comm comm, int *flag)
Definition ampiFunctions.hpp:11938
int AMPI_Ssend_init_finish(HandleBase *handle)
Definition ampiFunctions.hpp:3855
int AMPI_Cart_map(MPI_Comm comm, int ndims, const int *dims, const int *periods, int *newrank)
Definition ampiFunctions.hpp:12140
int AMPI_File_iwrite_shared(MPI_File fh, const void *buf, int count, DATATYPE *datatype, AMPI_Request *request)
Definition ampiFunctions.hpp:12764
int AMPI_Comm_idup(MPI_Comm comm, MPI_Comm *newcomm, AMPI_Request *request)
Definition ampiFunctions.hpp:11878
int AMPI_Comm_create_keyval(AMPI_Comm_copy_attr_function *comm_copy_attr_fn, AMPI_Comm_delete_attr_function *comm_delete_attr_fn, int *comm_keyval, void *extra_state)
Definition ampiFunctions.hpp:11817
int AMPI_Cart_shift(MPI_Comm comm, int direction, int disp, int *rank_source, int *rank_dest)
Definition ampiFunctions.hpp:12153
void AMPI_Isend_b_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:1553
double AMPI_Wtick()
Definition ampiFunctions.hpp:12251
int AMPI_Lookup_name(const char *service_name, MPI_Info info, char *port_name)
Definition ampiFunctions.hpp:12551
int AMPI_T_cvar_get_num(int *num_cvar)
Definition ampiFunctions.hpp:13136
int AMPI_Comm_get_attr(MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
Definition ampiFunctions.hpp:11854
int AMPI_Comm_free(MPI_Comm *comm)
Definition ampiFunctions.hpp:11842
int AMPI_Recv_init_finish(HandleBase *handle)
Definition ampiFunctions.hpp:2460
RecvAdjCall
Definition enums.hpp:44
const AMPI_IN_PLACE_IMPL AMPI_IN_PLACE
This structure is able to be cast to any type.
Definition ampi.cpp:40
void AMPI_Irsend_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:1293
void AMPI_Bcast_wrap_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:5452
int AMPI_Win_free_keyval(int *win_keyval)
Definition ampiFunctions.hpp:12091
int MPI_Bcast_wrap(void *bufferSend, void *bufferRecv, int count, MPI_Datatype type, int root, MPI_Comm comm)
Definition wrappers.hpp:52
int AMPI_Group_excl(MPI_Group group, int n, const int *ranks, MPI_Group *newgroup)
Definition ampiFunctions.hpp:11956
int AMPI_Request_get_status(AMPI_Request request, int *flag, MPI_Status *status)
Definition ampiFunctions.hpp:11682
void AMPI_Ialltoallv_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:7831
int AMPI_Iallgather(const typename SENDTYPE::Type *sendbuf, int sendcount, SENDTYPE *sendtype, typename RECVTYPE::Type *recvbuf, int recvcount, RECVTYPE *recvtype, MPI_Comm comm, AMPI_Request *request)
Definition ampiFunctions.hpp:6410
int AMPI_Get_count(const MPI_Status *status, DATATYPE *datatype, int *count)
Definition ampiFunctions.hpp:11664
void AMPI_Iallgatherv_d_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:6730
int AMPI_Status_f2c(const MPI_Fint *f_status, MPI_Status *c_status)
Definition ampiFunctions.hpp:13069
int AMPI_File_set_errhandler(MPI_File file, MPI_Errhandler errhandler)
Definition ampiFunctions.hpp:12365
void(* ForwardFunction)(HandleBase *h, AdjointInterface *a)
Definition typeDefinitions.h:46
int AMPI_Ibsend(const typename DATATYPE::Type *buf, int count, DATATYPE *datatype, int dest, int tag, MPI_Comm comm, AMPI_Request *request)
Definition ampiFunctions.hpp:314
MPI_Group AMPI_Group_f2c(MPI_Fint group)
Definition ampiFunctions.hpp:13045
int AMPI_File_read(MPI_File fh, void *buf, int count, DATATYPE *datatype, MPI_Status *status)
Definition ampiFunctions.hpp:12785
void AMPI_Irecv_b_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:1047
void AMPI_Scatter_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:11118
int AMPI_Intercomm_merge(MPI_Comm intercomm, int high, MPI_Comm *newintracomm)
Definition ampiFunctions.hpp:12024
int AMPI_File_preallocate(MPI_File fh, MPI_Offset size)
Definition ampiFunctions.hpp:12778
void AMPI_Ssend_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:3600
void AMPI_Iallgather_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:6338
int AMPI_Comm_remote_size(MPI_Comm comm, int *size)
Definition ampiFunctions.hpp:11896
int AMPI_Type_delete_attr(DATATYPE *datatype, int type_keyval)
Definition ampiFunctions.hpp:12038
int AMPI_Status_set_elements(MPI_Status *status, DATATYPE *datatype, int count)
Definition ampiFunctions.hpp:12609
void AMPI_Iallgather_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:6302
int AMPI_Group_size(MPI_Group group, int *size)
Definition ampiFunctions.hpp:11998
MPI_Info AMPI_Info_f2c(MPI_Fint info)
Definition ampiFunctions.hpp:13057
int AMPI_Info_create(MPI_Info *info)
Definition ampiFunctions.hpp:12443
int AMPI_T_category_get_pvars(int cat_index, int len, int *indices)
Definition ampiFunctions.hpp:13124
void AMPI_Ialltoallv_b_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:7940
MPI_Win_delete_attr_function AMPI_Win_delete_attr_function
Definition ampiDefinitions.h:839
int AMPI_Ialltoall_finish(HandleBase *handle)
Definition ampiFunctions.hpp:7694
int AMPI_Finalize()
Definition ampiFunctions.hpp:12371
int AMPI_Igatherv(const typename SENDTYPE::Type *sendbuf, int sendcount, SENDTYPE *sendtype, typename RECVTYPE::Type *recvbuf, const int *recvcounts, const int *displs, RECVTYPE *recvtype, int root, MPI_Comm comm, AMPI_Request *request)
Definition ampiFunctions.hpp:9170
void AMPI_Ibsend_b_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:301
int AMPI_Issend_finish(HandleBase *handle)
Definition ampiFunctions.hpp:1897
MPI_Grequest_query_function AMPI_Grequest_query_function
Definition ampiDefinitions.h:866
MPI_Type_delete_attr_function AMPI_Type_delete_attr_function
Definition ampiDefinitions.h:845
int * createLinearDisplacements(const int *counts, int ranks)
Creates the linearized displacements of a message with a different size on each rank.
Definition displacementTools.hpp:122
void AMPI_Sendrecv_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:3410
MPI_Win_errhandler_function AMPI_Win_errhandler_function
Definition ampiDefinitions.h:851
int AMPI_Graph_create(MPI_Comm comm_old, int nnodes, const int *index, const int *edges, int reorder, MPI_Comm *comm_graph)
Definition ampiFunctions.hpp:12207
void AMPI_Allgather_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:3982
int AMPI_Info_get(MPI_Info info, const char *key, int valuelen, char *value, int *flag)
Definition ampiFunctions.hpp:12467
MPI_Fint AMPI_Info_c2f(MPI_Info info)
Definition ampiFunctions.hpp:13051
int AMPI_Win_set_errhandler(MPI_Win win, MPI_Errhandler errhandler)
Definition ampiFunctions.hpp:12437
int AMPI_File_get_group(MPI_File fh, MPI_Group *group)
Definition ampiFunctions.hpp:12652
int AMPI_Comm_set_errhandler(MPI_Comm comm, MPI_Errhandler errhandler)
Definition ampiFunctions.hpp:12317
int AMPI_File_read_shared(MPI_File fh, void *buf, int count, DATATYPE *datatype, MPI_Status *status)
Definition ampiFunctions.hpp:12861
int AMPI_T_pvar_handle_alloc(MPI_T_pvar_session session, int pvar_index, void *obj_handle, MPI_T_pvar_handle *handle, int *count)
Definition ampiFunctions.hpp:13202
void AMPI_Irsend_p_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:1259
void AMPI_Igather_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:8630
int AMPI_Get_address(const void *location, MPI_Aint *address)
Definition ampiFunctions.hpp:11706
int AMPI_Win_set_attr(MPI_Win win, int win_keyval, void *attribute_val)
Definition ampiFunctions.hpp:12109
void AMPI_Imrecv_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:763
int AMPI_Query_thread(int *provided)
Definition ampiFunctions.hpp:12596
int AMPI_File_sync(MPI_File fh)
Definition ampiFunctions.hpp:12905
void AMPI_Alltoall_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:4840
int AMPI_Rsend(const typename DATATYPE::Type *buf, int count, DATATYPE *datatype, int dest, int tag, MPI_Comm comm)
Definition ampiFunctions.hpp:2623
void AMPI_Igather_p_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:8652
int AMPI_Send_init(const typename DATATYPE::Type *buf, int count, DATATYPE *datatype, int dest, int tag, MPI_Comm comm, AMPI_Request *request)
Definition ampiFunctions.hpp:3103
void AMPI_Igather_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:8709
int AMPI_Ssend(const typename DATATYPE::Type *buf, int count, DATATYPE *datatype, int dest, int tag, MPI_Comm comm)
Definition ampiFunctions.hpp:3631
int AMPI_T_pvar_reset(MPI_T_pvar_session session, MPI_T_pvar_handle handle)
Definition ampiFunctions.hpp:13227
int AMPI_Initialized(int *flag)
Definition ampiFunctions.hpp:12407
void AMPI_Iallreduce_global_b_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:7174
void AMPI_Igatherv_d_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:9105
int AMPI_Group_range_excl(MPI_Group group, int n, ::medi::common::Range *ranges, MPI_Group *newgroup)
Definition ampiFunctions.hpp:11980
int AMPI_Type_set_attr(DATATYPE *datatype, int type_keyval, void *attribute_val)
Definition ampiFunctions.hpp:12065
double AMPI_Wtime()
Definition ampiFunctions.hpp:12257
int AMPI_File_set_view(MPI_File fh, MPI_Offset disp, ETYPE *etype, FILETYPE *filetype, const char *datarep, MPI_Info info)
Definition ampiFunctions.hpp:12898
int AMPI_Iprobe(int source, int tag, MPI_Comm comm, int *flag, MPI_Status *status)
Definition ampiFunctions.hpp:11670
void AMPI_Send_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:2987
MPI_Grequest_cancel_function AMPI_Grequest_cancel_function
Definition ampiDefinitions.h:872
void AMPI_Iscatter_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:9979
int AMPI_T_pvar_get_num(int *num_pvar)
Definition ampiFunctions.hpp:13196
int AMPI_File_write(MPI_File fh, const void *buf, int count, DATATYPE *datatype, MPI_Status *status)
Definition ampiFunctions.hpp:12912
void AMPI_Iscatter_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:9942
int AMPI_Iscatterv_finish(HandleBase *handle)
Definition ampiFunctions.hpp:10608
int AMPI_Dist_graph_neighbors(MPI_Comm comm, int maxindegree, int *sources, int *sourceweights, int maxoutdegree, int *destinations, int *destweights)
Definition ampiFunctions.hpp:12194
void AMPI_Ssend_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:3584
int AMPI_Comm_get_name(MPI_Comm comm, char *comm_name, int *resultlen)
Definition ampiFunctions.hpp:11866
void AMPI_Scatterv_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:11423
int AMPI_T_category_get_index(const char *name, int *cat_index)
Definition ampiFunctions.hpp:13105
void AMPI_Ialltoall_b_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:7551
void AMPI_Gather_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:5699
int AMPI_Get_elements_x(const MPI_Status *status, DATATYPE *datatype, MPI_Count *count)
Definition ampiFunctions.hpp:11720
MPI_Errhandler AMPI_Errhandler_f2c(MPI_Fint errhandler)
Definition ampiFunctions.hpp:13021
int AMPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm)
Definition ampiFunctions.hpp:11830
int AMPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group *newgroup)
Definition ampiFunctions.hpp:11950
void AMPI_Iscatter_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:9902
void AMPI_Ssend_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:3616
int AMPI_Dist_graph_create(MPI_Comm comm_old, int n, const int *sources, const int *degrees, const int *destinations, const int *weights, MPI_Info info, int reorder, MPI_Comm *comm_dist_graph)
Definition ampiFunctions.hpp:12177
int AMPI_Grequest_complete(AMPI_Request request)
Definition ampiFunctions.hpp:12577
void AMPI_Iallgather_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:6371
void createLinearDisplacementsAndCount(int *&countsOut, int *&displsOut, const int *counts, int ranks, int scale)
Creates the linearized displacements of a message with a different size on each rank.
Definition displacementTools.hpp:144
int AMPI_Group_translate_ranks(MPI_Group group1, int n, const int *ranks1, MPI_Group group2, int *ranks2)
Definition ampiFunctions.hpp:12004
int AMPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
Definition ampiFunctions.hpp:11799
int AMPI_File_read_all(MPI_File fh, void *buf, int count, DATATYPE *datatype, MPI_Status *status)
Definition ampiFunctions.hpp:12792
int AMPI_Comm_call_errhandler(MPI_Comm comm, int errorcode)
Definition ampiFunctions.hpp:12293
int AMPI_Type_get_extent_x(DATATYPE *datatype, MPI_Count *lb, MPI_Count *extent)
Definition ampiFunctions.hpp:11751
int AMPI_Win_delete_attr(MPI_Win win, int win_keyval)
Definition ampiFunctions.hpp:12085
int AMPI_Imrecv(typename DATATYPE::Type *buf, int count, DATATYPE *datatype, AMPI_Message *message, AMPI_Request *request, IrecvAdjCall reverse_send=IrecvAdjCall::Isend)
Definition ampiFunctions.hpp:793
void createLinearIndexCounts(int *&linearCounts, const int *counts, const int *displs, int ranks, Datatype *type)
Creates the counts for a message with a different size on each rank.
Definition displacementTools.hpp:170
MPI_Fint AMPI_File_c2f(MPI_File file)
Definition ampiFunctions.hpp:13027
int AMPI_Allreduce_global(const typename DATATYPE::Type *sendbuf, typename DATATYPE::Type *recvbuf, int count, DATATYPE *datatype, AMPI_Op op, MPI_Comm comm)
Definition ampiFunctions.hpp:4623
void AMPI_Igather_b_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:8736
MPI_Fint AMPI_Group_c2f(MPI_Group group)
Definition ampiFunctions.hpp:13039
void AMPI_Iscatterv_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:10353
void AMPI_Imrecv_d_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:752
int AMPI_T_pvar_session_free(MPI_T_pvar_session *session)
Definition ampiFunctions.hpp:13239
int AMPI_Graph_neighbors_count(MPI_Comm comm, int rank, int *nneighbors)
Definition ampiFunctions.hpp:12233
int AMPI_Iscatterv(const typename SENDTYPE::Type *sendbuf, const int *sendcounts, const int *displs, SENDTYPE *sendtype, typename RECVTYPE::Type *recvbuf, int recvcount, RECVTYPE *recvtype, int root, MPI_Comm comm, AMPI_Request *request)
Definition ampiFunctions.hpp:10440
int AMPI_Ibsend_finish(HandleBase *handle)
Definition ampiFunctions.hpp:398
int AMPI_File_write_shared(MPI_File fh, const void *buf, int count, DATATYPE *datatype, MPI_Status *status)
Definition ampiFunctions.hpp:12989
int AMPI_Ialltoallv(const typename SENDTYPE::Type *sendbuf, const int *sendcounts, const int *sdispls, SENDTYPE *sendtype, typename RECVTYPE::Type *recvbuf, const int *recvcounts, const int *rdispls, RECVTYPE *recvtype, MPI_Comm comm, AMPI_Request *request)
Definition ampiFunctions.hpp:7959
int AMPI_Info_get_valuelen(MPI_Info info, const char *key, int *valuelen, int *flag)
Definition ampiFunctions.hpp:12485
int AMPI_Win_set_name(MPI_Win win, const char *win_name)
Definition ampiFunctions.hpp:12115
int AMPI_Dist_graph_create_adjacent(MPI_Comm comm_old, int indegree, const int *sources, const int *sourceweights, int outdegree, const int *destinations, const int *destweights, MPI_Info info, int reorder, MPI_Comm *comm_dist_graph)
Definition ampiFunctions.hpp:12185
void AMPI_Irsend_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:1243
void AMPI_Recv_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:2176
int AMPI_Recv_init(typename DATATYPE::Type *buf, int count, DATATYPE *datatype, int source, int tag, MPI_Comm comm, AMPI_Request *request, IrecvAdjCall reverse_send=IrecvAdjCall::Isend)
Definition ampiFunctions.hpp:2327
int AMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *newcomm)
Definition ampiFunctions.hpp:11926
int AMPI_Type_get_true_extent(DATATYPE *datatype, MPI_Aint *true_lb, MPI_Aint *true_extent)
Definition ampiFunctions.hpp:11758
int AMPI_File_get_byte_offset(MPI_File fh, MPI_Offset offset, MPI_Offset *disp)
Definition ampiFunctions.hpp:12646
int AMPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr)
Definition ampiFunctions.hpp:12287
MPI_Type_copy_attr_function AMPI_Type_copy_attr_function
Definition ampiDefinitions.h:842
int AMPI_Get_processor_name(char *name, int *resultlen)
Definition ampiFunctions.hpp:12395
void AMPI_Rsend_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:2576
int AMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm *newcomm)
Definition ampiFunctions.hpp:11805
MPI_Datarep_extent_function AMPI_Datarep_extent_function
Definition ampiDefinitions.h:875
int getCommSize(MPI_Comm comm)
Helper function that gets the number of ranks from the communicator.
Definition mpiTools.h:64
int AMPI_Comm_disconnect(MPI_Comm *comm)
Definition ampiFunctions.hpp:12517
int AMPI_Win_call_errhandler(MPI_Win win, int errorcode)
Definition ampiFunctions.hpp:12413
void AMPI_Igatherv_p_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:9059
int AMPI_T_pvar_handle_free(MPI_T_pvar_session session, MPI_T_pvar_handle *handle)
Definition ampiFunctions.hpp:13209
int AMPI_Comm_get_errhandler(MPI_Comm comm, MPI_Errhandler *errhandler)
Definition ampiFunctions.hpp:12311
int AMPI_Comm_split_type(MPI_Comm comm, int split_type, int key, MPI_Info info, MPI_Comm *newcomm)
Definition ampiFunctions.hpp:11932
int AMPI_Add_error_string(int errorcode, const char *string)
Definition ampiFunctions.hpp:12281
int AMPI_Irecv(typename DATATYPE::Type *buf, int count, DATATYPE *datatype, int source, int tag, MPI_Comm comm, AMPI_Request *request, IrecvAdjCall reverse_send=IrecvAdjCall::Isend)
Definition ampiFunctions.hpp:1058
int AMPI_Register_datarep(const char *datarep, AMPI_Datarep_conversion_function *read_conversion_fn, AMPI_Datarep_conversion_function *write_conversion_fn, AMPI_Datarep_extent_function *dtype_file_extent_fn, void *extra_state)
Definition ampiFunctions.hpp:12995
void AMPI_Issend_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:1787
int getCommRank(MPI_Comm comm)
Helper function that gets the own rank number from the communicator.
Definition mpiTools.h:52
void AMPI_Iallgather_p_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:6322
MPI_Fint AMPI_Errhandler_c2f(MPI_Errhandler errhandler)
Definition ampiFunctions.hpp:13015
int AMPI_Iallgatherv(const typename SENDTYPE::Type *sendbuf, int sendcount, SENDTYPE *sendtype, typename RECVTYPE::Type *recvbuf, const int *recvcounts, const int *displs, RECVTYPE *recvtype, MPI_Comm comm, AMPI_Request *request)
Definition ampiFunctions.hpp:6788
int AMPI_Comm_get_parent(MPI_Comm *parent)
Definition ampiFunctions.hpp:12523
int AMPI_Group_incl(MPI_Group group, int n, const int *ranks, MPI_Group *newgroup)
Definition ampiFunctions.hpp:11968
int AMPI_Comm_set_attr(MPI_Comm comm, int comm_keyval, void *attribute_val)
Definition ampiFunctions.hpp:11902
int AMPI_Ssend_init_preStart(HandleBase *handle)
Definition ampiFunctions.hpp:3776
void AMPI_Iallgatherv_p_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:6690
int AMPI_Comm_spawn(const char *command, char **argv, int maxprocs, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *intercomm, int *array_of_errcodes)
Definition ampiFunctions.hpp:12535
int AMPI_Op_commutative(AMPI_Op op, int *commute)
Definition ampiFunctions.hpp:11791
void AMPI_Iscatter_b_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:10004
void AMPI_Allgatherv_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:4300
int AMPI_Buffer_detach(void *buffer_addr, int *size)
Definition ampiFunctions.hpp:11651
int AMPI_File_iread_all(MPI_File fh, void *buf, int count, DATATYPE *datatype, AMPI_Request *request)
Definition ampiFunctions.hpp:12704
void AMPI_Rsend_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:2592
void AMPI_Issend_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:1737
void AMPI_Imrecv_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:712
int AMPI_Finalized(int *flag)
Definition ampiFunctions.hpp:12377
int AMPI_Alltoall(const typename SENDTYPE::Type *sendbuf, int sendcount, SENDTYPE *sendtype, typename RECVTYPE::Type *recvbuf, int recvcount, RECVTYPE *recvtype, MPI_Comm comm)
Definition ampiFunctions.hpp:4891
int AMPI_File_write_ordered(MPI_File fh, const void *buf, int count, DATATYPE *datatype, MPI_Status *status)
Definition ampiFunctions.hpp:12969
MPI_Copy_function AMPI_Copy_function
Definition ampiDefinitions.h:881
int AMPI_File_read_at(MPI_File fh, MPI_Offset offset, void *buf, int count, DATATYPE *datatype, MPI_Status *status)
Definition ampiFunctions.hpp:12812
int AMPI_T_cvar_get_index(const char *name, int *cvar_index)
Definition ampiFunctions.hpp:13130
int AMPI_File_read_all_begin(MPI_File fh, void *buf, int count, DATATYPE *datatype)
Definition ampiFunctions.hpp:12799
int AMPI_Bcast_wrap(typename DATATYPE::Type *bufferSend, typename DATATYPE::Type *bufferRecv, int count, DATATYPE *datatype, int root, MPI_Comm comm)
Definition ampiFunctions.hpp:5483
void AMPI_Allgatherv_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:4273
void AMPI_Iallreduce_global_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:7111
int AMPI_Publish_name(const char *service_name, MPI_Info info, const char *port_name)
Definition ampiFunctions.hpp:12563
void AMPI_Iscatterv_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:10394
int AMPI_Imrecv_finish(HandleBase *handle)
Definition ampiFunctions.hpp:881
void AMPI_Isend_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:1540
void AMPI_Allreduce_global_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:4536
int AMPI_File_get_type_extent(MPI_File fh, DATATYPE *datatype, MPI_Aint *extent)
Definition ampiFunctions.hpp:12683
int AMPI_Recv_init_preStart(HandleBase *handle)
Definition ampiFunctions.hpp:2372
void AMPI_Ialltoall_d_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:7515
void AMPI_Rsend_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:2608
void AMPI_Ibsend_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:263
int AMPI_Unpublish_name(const char *service_name, MPI_Info info, const char *port_name)
Definition ampiFunctions.hpp:12570
int AMPI_Bsend_init_postEnd(HandleBase *handle)
Definition ampiFunctions.hpp:630
void AMPI_Ibsend_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:238
void AMPI_Scatterv_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:11358
int AMPI_Rsend_init_postEnd(HandleBase *handle)
Definition ampiFunctions.hpp:2887
int AMPI_Iallreduce_global(const typename DATATYPE::Type *sendbuf, typename DATATYPE::Type *recvbuf, int count, DATATYPE *datatype, AMPI_Op op, MPI_Comm comm, AMPI_Request *request)
Definition ampiFunctions.hpp:7196
int AMPI_Gatherv(const typename SENDTYPE::Type *sendbuf, int sendcount, SENDTYPE *sendtype, typename RECVTYPE::Type *recvbuf, const int *recvcounts, const int *displs, RECVTYPE *recvtype, int root, MPI_Comm comm)
Definition ampiFunctions.hpp:6064
void AMPI_Scatterv_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:11392
void AMPI_Ireduce_global_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:9477
void AMPI_Gatherv_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:5997
int AMPI_File_close(MPI_File *fh)
Definition ampiFunctions.hpp:12622
MPI_Grequest_free_function AMPI_Grequest_free_function
Definition ampiDefinitions.h:869
void AMPI_Ibcast_wrap_d_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:8320
void AMPI_Bsend_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:104
int AMPI_Ibcast_wrap_finish(HandleBase *handle)
Definition ampiFunctions.hpp:8508
void AMPI_Sendrecv_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:3385
int AMPI_T_pvar_session_create(MPI_T_pvar_session *session)
Definition ampiFunctions.hpp:13233
int AMPI_Group_union(MPI_Group group1, MPI_Group group2, MPI_Group *newgroup)
Definition ampiFunctions.hpp:12011
void AMPI_Alltoallv_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:5112
void AMPI_Send_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:2955
void AMPI_Reduce_global_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:10777
int(* ContinueFunction)(HandleBase *h)
Definition typeDefinitions.h:48
void AMPI_Iallreduce_global_p_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:7093
int AMPI_File_write_at_all_end(MPI_File fh, const void *buf, MPI_Status *status)
Definition ampiFunctions.hpp:12962
int AMPI_Type_get_extent(DATATYPE *datatype, MPI_Aint *lb, MPI_Aint *extent)
Definition ampiFunctions.hpp:11744
void AMPI_Mrecv_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:1978
int AMPI_Test_cancelled(const MPI_Status *status, int *flag)
Definition ampiFunctions.hpp:11688
void AMPI_Iallreduce_global_d_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:7133
void AMPI_Ireduce_global_d_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:9544
void AMPI_Allgatherv_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:4243
void AMPI_Iallgather_b_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:6394
int AMPI_File_call_errhandler(MPI_File fh, int errorcode)
Definition ampiFunctions.hpp:12341
int AMPI_File_write_at_all_begin(MPI_File fh, MPI_Offset offset, const void *buf, int count, DATATYPE *datatype)
Definition ampiFunctions.hpp:12955
int AMPI_Type_get_envelope(DATATYPE *datatype, int *num_integers, int *num_addresses, int *num_datatypes, int *combiner)
Definition ampiFunctions.hpp:11736
int AMPI_Group_free(MPI_Group *group)
Definition ampiFunctions.hpp:11962
void AMPI_Ialltoall_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:7528
void AMPI_Gatherv_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:5961
void AMPI_Iallgatherv_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:6708
void AMPI_Imrecv_b_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:782
int AMPI_Cart_sub(MPI_Comm comm, const int *remain_dims, MPI_Comm *newcomm)
Definition ampiFunctions.hpp:12159
int AMPI_File_read_ordered_begin(MPI_File fh, void *buf, int count, DATATYPE *datatype)
Definition ampiFunctions.hpp:12848
void AMPI_Isend_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:1515
int AMPI_File_get_info(MPI_File fh, MPI_Info *info_used)
Definition ampiFunctions.hpp:12658
int AMPI_File_iread_shared(MPI_File fh, void *buf, int count, DATATYPE *datatype, AMPI_Request *request)
Definition ampiFunctions.hpp:12727
int AMPI_Comm_accept(const char *port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *newcomm)
Definition ampiFunctions.hpp:12503
int AMPI_T_category_get_num(int *num_cat)
Definition ampiFunctions.hpp:13118
void AMPI_Alltoall_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:4864
int AMPI_Recv_init_postEnd(HandleBase *handle)
Definition ampiFunctions.hpp:2506
MPI_Fint AMPI_Comm_c2f(MPI_Comm comm)
Definition ampiFunctions.hpp:13003
void AMPI_Issend_b_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:1800
int AMPI_File_iread_at_all(MPI_File fh, MPI_Offset offset, void *buf, int count, DATATYPE *datatype, AMPI_Request *request)
Definition ampiFunctions.hpp:12719
void AMPI_Recv_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:2156
int AMPI_Send_init_preStart(HandleBase *handle)
Definition ampiFunctions.hpp:3147
void AMPI_Isend_p_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:1506
int AMPI_File_write_at_all(MPI_File fh, MPI_Offset offset, const void *buf, int count, DATATYPE *datatype, MPI_Status *status)
Definition ampiFunctions.hpp:12947
int AMPI_File_write_ordered_begin(MPI_File fh, const void *buf, int count, DATATYPE *datatype)
Definition ampiFunctions.hpp:12976
int AMPI_Status_c2f(const MPI_Status *c_status, MPI_Fint *f_status)
Definition ampiFunctions.hpp:13063
int AMPI_Graphdims_get(MPI_Comm comm, int *nnodes, int *nedges)
Definition ampiFunctions.hpp:12239
void AMPI_Iallgatherv_b_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:6770
int AMPI_File_write_all(MPI_File fh, const void *buf, int count, DATATYPE *datatype, MPI_Status *status)
Definition ampiFunctions.hpp:12919
int AMPI_Comm_connect(const char *port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *newcomm)
Definition ampiFunctions.hpp:12510
void AMPI_Bcast_wrap_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:5395
int AMPI_Type_get_name(DATATYPE *datatype, char *type_name, int *resultlen)
Definition ampiFunctions.hpp:12058
void AMPI_Ibsend_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:288
int AMPI_T_cvar_read(MPI_T_cvar_handle handle, void *buf)
Definition ampiFunctions.hpp:13154
void AMPI_Irecv_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:1028
int AMPI_File_iwrite_at_all(MPI_File fh, MPI_Offset offset, const void *buf, int count, DATATYPE *datatype, AMPI_Request *request)
Definition ampiFunctions.hpp:12756
int AMPI_File_write_at(MPI_File fh, MPI_Offset offset, const void *buf, int count, DATATYPE *datatype, MPI_Status *status)
Definition ampiFunctions.hpp:12939
void AMPI_Igatherv_b_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:9151
void AMPI_Irecv_p_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:990
int AMPI_T_pvar_get_index(const char *name, int var_class, int *pvar_index)
Definition ampiFunctions.hpp:13190
int AMPI_Ireduce_global(const typename DATATYPE::Type *sendbuf, typename DATATYPE::Type *recvbuf, int count, DATATYPE *datatype, AMPI_Op op, int root, MPI_Comm comm, AMPI_Request *request)
Definition ampiFunctions.hpp:9611
int AMPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm)
Definition ampiFunctions.hpp:12017
int AMPI_Type_get_attr(DATATYPE *datatype, int type_keyval, void *attribute_val, int *flag)
Definition ampiFunctions.hpp:12051
void(* ReverseFunction)(HandleBase *h, AdjointInterface *a)
Definition typeDefinitions.h:45
int AMPI_Type_free_keyval(int *type_keyval)
Definition ampiFunctions.hpp:12044
int AMPI_Irsend(const typename DATATYPE::Type *buf, int count, DATATYPE *datatype, int dest, int tag, MPI_Comm comm, AMPI_Request *request)
Definition ampiFunctions.hpp:1319
int AMPI_Abort(MPI_Comm comm, int errorcode)
Definition ampiFunctions.hpp:12263
void AMPI_Scatter_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:11059
int AMPI_File_iwrite_at(MPI_File fh, MPI_Offset offset, const void *buf, int count, DATATYPE *datatype, AMPI_Request *request)
Definition ampiFunctions.hpp:12748
int AMPI_Ireduce_global_finish(HandleBase *handle)
Definition ampiFunctions.hpp:9762
int AMPI_T_cvar_handle_alloc(int cvar_index, void *obj_handle, MPI_T_cvar_handle *handle, int *count)
Definition ampiFunctions.hpp:13142
int AMPI_Win_get_attr(MPI_Win win, int win_keyval, void *attribute_val, int *flag)
Definition ampiFunctions.hpp:12097
void AMPI_Allreduce_global_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:4589
int AMPI_Recv(typename DATATYPE::Type *buf, int count, DATATYPE *datatype, int source, int tag, MPI_Comm comm, MPI_Status *status, RecvAdjCall reverse_send=RecvAdjCall::Send)
Definition ampiFunctions.hpp:2214
int AMPI_Comm_get_info(MPI_Comm comm, MPI_Info *info_used)
Definition ampiFunctions.hpp:11860
int AMPI_Bsend_init_preStart(HandleBase *handle)
Definition ampiFunctions.hpp:511
int AMPI_Scatter(const typename SENDTYPE::Type *sendbuf, int sendcount, SENDTYPE *sendtype, typename RECVTYPE::Type *recvbuf, int recvcount, RECVTYPE *recvtype, int root, MPI_Comm comm)
Definition ampiFunctions.hpp:11149
void AMPI_Ialltoall_p_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:7479
int AMPI_Comm_create_group(MPI_Comm comm, MPI_Group group, int tag, MPI_Comm *newcomm)
Definition ampiFunctions.hpp:11811
MPI_File AMPI_File_f2c(MPI_Fint file)
Definition ampiFunctions.hpp:13033
int AMPI_File_read_ordered_end(MPI_File fh, void *buf, MPI_Status *status)
Definition ampiFunctions.hpp:12854
void AMPI_Reduce_global_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:10743
void AMPI_Iallreduce_global_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:7148
void AMPI_Irsend_b_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:1306
int AMPI_Iallgatherv_finish(HandleBase *handle)
Definition ampiFunctions.hpp:6941
int AMPI_Error_string(int errorcode, char *string, int *resultlen)
Definition ampiFunctions.hpp:12335
int AMPI_Comm_dup_with_info(MPI_Comm comm, MPI_Info info, MPI_Comm *newcomm)
Definition ampiFunctions.hpp:11836
int AMPI_T_cvar_handle_free(MPI_T_cvar_handle *handle)
Definition ampiFunctions.hpp:13148
int AMPI_Comm_create_errhandler(AMPI_Comm_errhandler_function *comm_errhandler_fn, MPI_Errhandler *errhandler)
Definition ampiFunctions.hpp:12299
int AMPI_File_seek(MPI_File fh, MPI_Offset offset, int whence)
Definition ampiFunctions.hpp:12867
int AMPI_Type_get_contents(DATATYPE *datatype, int max_integers, int max_addresses, int max_datatypes, int *array_of_integers, MPI_Aint *array_of_addresses, AMPI_Datatype *array_of_datatypes)
Definition ampiFunctions.hpp:11727
int AMPI_Cart_get(MPI_Comm comm, int maxdims, int *dims, int *periods, int *coords)
Definition ampiFunctions.hpp:12134
void AMPI_Ialltoallv_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:7874
int AMPI_Send(const typename DATATYPE::Type *buf, int count, DATATYPE *datatype, int dest, int tag, MPI_Comm comm)
Definition ampiFunctions.hpp:3002
void AMPI_Issend_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:1762
void AMPI_Ireduce_global_p_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:9500
int AMPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result)
Definition ampiFunctions.hpp:11944
int AMPI_Sendrecv(const typename SENDTYPE::Type *sendbuf, int sendcount, SENDTYPE *sendtype, int dest, int sendtag, typename RECVTYPE::Type *recvbuf, int recvcount, RECVTYPE *recvtype, int source, int recvtag, MPI_Comm comm, MPI_Status *status)
Definition ampiFunctions.hpp:3438
void AMPI_Ialltoall_p(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:7459
int AMPI_T_category_changed(int *stamp)
Definition ampiFunctions.hpp:13087
void AMPI_Isend_d_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:1531
void AMPI_Allgather_d(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:4009
int AMPI_Comm_rank(MPI_Comm comm, int *rank)
Definition ampiFunctions.hpp:11884
int AMPI_Info_get_nkeys(MPI_Info info, int *nkeys)
Definition ampiFunctions.hpp:12473
int AMPI_Cancel(AMPI_Request *request)
Definition ampiFunctions.hpp:11657
void AMPI_Ialltoallv_b(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:7914
void AMPI_Irecv_d_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:1017
int AMPI_File_read_at_all_end(MPI_File fh, void *buf, MPI_Status *status)
Definition ampiFunctions.hpp:12834
int AMPI_T_cvar_write(MPI_T_cvar_handle handle, const void *buf)
Definition ampiFunctions.hpp:13160
MPI_Comm_delete_attr_function AMPI_Comm_delete_attr_function
Definition ampiDefinitions.h:833
void AMPI_Ireduce_global_b_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:9589
int AMPI_File_read_all_end(MPI_File fh, void *buf, MPI_Status *status)
Definition ampiFunctions.hpp:12805
MPI_Comm_copy_attr_function AMPI_Comm_copy_attr_function
Definition ampiDefinitions.h:830
int AMPI_T_pvar_write(MPI_T_pvar_session session, MPI_T_pvar_handle handle, const void *buf)
Definition ampiFunctions.hpp:13257
int AMPI_Error_class(int errorcode, int *errorclass)
Definition ampiFunctions.hpp:12329
void AMPI_Ibsend_d_finish(HandleBase *handle, AdjointInterface *adjointInterface)
Definition ampiFunctions.hpp:279
int AMPI_File_write_ordered_end(MPI_File fh, const void *buf, MPI_Status *status)
Definition ampiFunctions.hpp:12982
int AMPI_Keyval_create(AMPI_Copy_function *copy_fn, AMPI_Delete_function *delete_fn, int *keyval, void *extra_state)
Definition ampiFunctions.hpp:13287
Definition ampiFunctions.hpp:3936
int sendbufTotalSize
Definition ampiFunctions.hpp:3937
int recvbufCountVec
Definition ampiFunctions.hpp:3951
RECVTYPE::IndexType * recvbufIndices
Definition ampiFunctions.hpp:3946
RECVTYPE::PrimalType * recvbufPrimals
Definition ampiFunctions.hpp:3947
SENDTYPE::PrimalType * sendbufPrimals
Definition ampiFunctions.hpp:3939
SENDTYPE::IndexType * sendbufIndices
Definition ampiFunctions.hpp:3938
int sendcount
Definition ampiFunctions.hpp:3943
void * recvbufAdjoints
Definition ampiFunctions.hpp:3949
int recvbufTotalSize
Definition ampiFunctions.hpp:3945
void * sendbufAdjoints
Definition ampiFunctions.hpp:3940
int recvbufCount
Definition ampiFunctions.hpp:3950
int recvcount
Definition ampiFunctions.hpp:3952
RECVTYPE::PrimalType * recvbufOldPrimals
Definition ampiFunctions.hpp:3948
~AMPI_Allgather_AdjointHandle()
Definition ampiFunctions.hpp:3956
int sendbufCountVec
Definition ampiFunctions.hpp:3942
int sendbufCount
Definition ampiFunctions.hpp:3941
RECVTYPE * recvtype
Definition ampiFunctions.hpp:3953
MPI_Comm comm
Definition ampiFunctions.hpp:3954
SENDTYPE * sendtype
Definition ampiFunctions.hpp:3944
Definition ampiFunctions.hpp:4191
int * recvbufCount
Definition ampiFunctions.hpp:4205
SENDTYPE::PrimalType * sendbufPrimals
Definition ampiFunctions.hpp:4194
int sendbufTotalSize
Definition ampiFunctions.hpp:4192
void * sendbufAdjoints
Definition ampiFunctions.hpp:4195
SENDTYPE::IndexType * sendbufIndices
Definition ampiFunctions.hpp:4193
MPI_Comm comm
Definition ampiFunctions.hpp:4211
void * recvbufAdjoints
Definition ampiFunctions.hpp:4204
int * recvbufDisplsVec
Definition ampiFunctions.hpp:4207
int * recvbufCountVec
Definition ampiFunctions.hpp:4206
int sendbufCountVec
Definition ampiFunctions.hpp:4197
SENDTYPE * sendtype
Definition ampiFunctions.hpp:4199
int sendcount
Definition ampiFunctions.hpp:4198
int recvbufTotalSize
Definition ampiFunctions.hpp:4200
RECVTYPE::IndexType * recvbufIndices
Definition ampiFunctions.hpp:4201
RECVTYPE * recvtype
Definition ampiFunctions.hpp:4210
~AMPI_Allgatherv_AdjointHandle()
Definition ampiFunctions.hpp:4213
int sendbufCount
Definition ampiFunctions.hpp:4196
const int * recvcounts
Definition ampiFunctions.hpp:4208
RECVTYPE::PrimalType * recvbufOldPrimals
Definition ampiFunctions.hpp:4203
const int * displs
Definition ampiFunctions.hpp:4209
RECVTYPE::PrimalType * recvbufPrimals
Definition ampiFunctions.hpp:4202
Definition ampiFunctions.hpp:4491
~AMPI_Allreduce_global_AdjointHandle()
Definition ampiFunctions.hpp:4510
void * sendbufAdjoints
Definition ampiFunctions.hpp:4495
void * recvbufAdjoints
Definition ampiFunctions.hpp:4502
DATATYPE::PrimalType * recvbufPrimals
Definition ampiFunctions.hpp:4500
DATATYPE * datatype
Definition ampiFunctions.hpp:4506
DATATYPE::IndexType * recvbufIndices
Definition ampiFunctions.hpp:4499
DATATYPE::IndexType * sendbufIndices
Definition ampiFunctions.hpp:4493
int count
Definition ampiFunctions.hpp:4505
int sendbufCountVec
Definition ampiFunctions.hpp:4497
int recvbufCountVec
Definition ampiFunctions.hpp:4504
MPI_Comm comm
Definition ampiFunctions.hpp:4508
int sendbufTotalSize
Definition ampiFunctions.hpp:4492
int sendbufCount
Definition ampiFunctions.hpp:4496
int recvbufTotalSize
Definition ampiFunctions.hpp:4498
DATATYPE::PrimalType * sendbufPrimals
Definition ampiFunctions.hpp:4494
DATATYPE::PrimalType * recvbufOldPrimals
Definition ampiFunctions.hpp:4501
AMPI_Op op
Definition ampiFunctions.hpp:4507
int recvbufCount
Definition ampiFunctions.hpp:4503
Definition ampiFunctions.hpp:4767
void * sendbufAdjoints
Definition ampiFunctions.hpp:4771
RECVTYPE::IndexType * recvbufIndices
Definition ampiFunctions.hpp:4777
int sendbufCount
Definition ampiFunctions.hpp:4772
int sendbufTotalSize
Definition ampiFunctions.hpp:4768
int recvbufCountVec
Definition ampiFunctions.hpp:4782
int sendcount
Definition ampiFunctions.hpp:4774
SENDTYPE * sendtype
Definition ampiFunctions.hpp:4775
int recvcount
Definition ampiFunctions.hpp:4783
RECVTYPE::PrimalType * recvbufPrimals
Definition ampiFunctions.hpp:4778
int recvbufTotalSize
Definition ampiFunctions.hpp:4776
MPI_Comm comm
Definition ampiFunctions.hpp:4785
RECVTYPE * recvtype
Definition ampiFunctions.hpp:4784
int sendbufCountVec
Definition ampiFunctions.hpp:4773
RECVTYPE::PrimalType * recvbufOldPrimals
Definition ampiFunctions.hpp:4779
int recvbufCount
Definition ampiFunctions.hpp:4781
SENDTYPE::PrimalType * sendbufPrimals
Definition ampiFunctions.hpp:4770
~AMPI_Alltoall_AdjointHandle()
Definition ampiFunctions.hpp:4787
void * recvbufAdjoints
Definition ampiFunctions.hpp:4780
SENDTYPE::IndexType * sendbufIndices
Definition ampiFunctions.hpp:4769
Definition ampiFunctions.hpp:5020
const int * rdispls
Definition ampiFunctions.hpp:5040
int * recvbufCount
Definition ampiFunctions.hpp:5036
int * sendbufCount
Definition ampiFunctions.hpp:5025
MPI_Comm comm
Definition ampiFunctions.hpp:5042
~AMPI_Alltoallv_AdjointHandle()
Definition ampiFunctions.hpp:5044
void * recvbufAdjoints
Definition ampiFunctions.hpp:5035
RECVTYPE::IndexType * recvbufIndices
Definition ampiFunctions.hpp:5032
RECVTYPE::PrimalType * recvbufPrimals
Definition ampiFunctions.hpp:5033
SENDTYPE * sendtype
Definition ampiFunctions.hpp:5030
int * recvbufCountVec
Definition ampiFunctions.hpp:5037
const int * sdispls
Definition ampiFunctions.hpp:5029
int * sendbufDisplsVec
Definition ampiFunctions.hpp:5027
SENDTYPE::PrimalType * sendbufPrimals
Definition ampiFunctions.hpp:5023
RECVTYPE::PrimalType * recvbufOldPrimals
Definition ampiFunctions.hpp:5034
const int * sendcounts
Definition ampiFunctions.hpp:5028
void * sendbufAdjoints
Definition ampiFunctions.hpp:5024
int * recvbufDisplsVec
Definition ampiFunctions.hpp:5038
RECVTYPE * recvtype
Definition ampiFunctions.hpp:5041
SENDTYPE::IndexType * sendbufIndices
Definition ampiFunctions.hpp:5022
const int * recvcounts
Definition ampiFunctions.hpp:5039
int sendbufTotalSize
Definition ampiFunctions.hpp:5021
int * sendbufCountVec
Definition ampiFunctions.hpp:5026
int recvbufTotalSize
Definition ampiFunctions.hpp:5031
Definition ampiFunctions.hpp:5350
int bufferRecvCountVec
Definition ampiFunctions.hpp:5363
int bufferSendTotalSize
Definition ampiFunctions.hpp:5351
int bufferRecvCount
Definition ampiFunctions.hpp:5362
DATATYPE::PrimalType * bufferSendPrimals
Definition ampiFunctions.hpp:5353
void * bufferRecvAdjoints
Definition ampiFunctions.hpp:5361
int bufferSendCount
Definition ampiFunctions.hpp:5355
int bufferRecvTotalSize
Definition ampiFunctions.hpp:5357
int root
Definition ampiFunctions.hpp:5366
MPI_Comm comm
Definition ampiFunctions.hpp:5367
DATATYPE::PrimalType * bufferRecvPrimals
Definition ampiFunctions.hpp:5359
int count
Definition ampiFunctions.hpp:5364
void * bufferSendAdjoints
Definition ampiFunctions.hpp:5354
DATATYPE * datatype
Definition ampiFunctions.hpp:5365
int bufferSendCountVec
Definition ampiFunctions.hpp:5356
DATATYPE::PrimalType * bufferRecvOldPrimals
Definition ampiFunctions.hpp:5360
~AMPI_Bcast_wrap_AdjointHandle()
Definition ampiFunctions.hpp:5369
DATATYPE::IndexType * bufferRecvIndices
Definition ampiFunctions.hpp:5358
DATATYPE::IndexType * bufferSendIndices
Definition ampiFunctions.hpp:5352
Definition ampiFunctions.hpp:45
int bufCountVec
Definition ampiFunctions.hpp:51
DATATYPE::IndexType * bufIndices
Definition ampiFunctions.hpp:47
int bufCount
Definition ampiFunctions.hpp:50
int count
Definition ampiFunctions.hpp:52
int tag
Definition ampiFunctions.hpp:55
int bufTotalSize
Definition ampiFunctions.hpp:46
MPI_Comm comm
Definition ampiFunctions.hpp:56
DATATYPE::PrimalType * bufPrimals
Definition ampiFunctions.hpp:48
DATATYPE * datatype
Definition ampiFunctions.hpp:53
void * bufAdjoints
Definition ampiFunctions.hpp:49
int dest
Definition ampiFunctions.hpp:54
~AMPI_Bsend_AdjointHandle()
Definition ampiFunctions.hpp:58
Definition ampiFunctions.hpp:448
AMPI_Request * request
Definition ampiFunctions.hpp:456
DATATYPE::ModifiedType * bufMod
Definition ampiFunctions.hpp:450
int count
Definition ampiFunctions.hpp:451
const DATATYPE::Type * buf
Definition ampiFunctions.hpp:449
int tag
Definition ampiFunctions.hpp:454
DATATYPE * datatype
Definition ampiFunctions.hpp:452
int dest
Definition ampiFunctions.hpp:453
MPI_Comm comm
Definition ampiFunctions.hpp:455
Definition ampiFunctions.hpp:5620
int sendbufCount
Definition ampiFunctions.hpp:5625
SENDTYPE * sendtype
Definition ampiFunctions.hpp:5628
RECVTYPE * recvtype
Definition ampiFunctions.hpp:5637
SENDTYPE::IndexType * sendbufIndices
Definition ampiFunctions.hpp:5622
int sendcount
Definition ampiFunctions.hpp:5627
int sendbufTotalSize
Definition ampiFunctions.hpp:5621
int recvbufCountVec
Definition ampiFunctions.hpp:5635
RECVTYPE::PrimalType * recvbufPrimals
Definition ampiFunctions.hpp:5631
int recvcount
Definition ampiFunctions.hpp:5636
MPI_Comm comm
Definition ampiFunctions.hpp:5639
int sendbufCountVec
Definition ampiFunctions.hpp:5626
int root
Definition ampiFunctions.hpp:5638
int recvbufCount
Definition ampiFunctions.hpp:5634
RECVTYPE::IndexType * recvbufIndices
Definition ampiFunctions.hpp:5630
int recvbufTotalSize
Definition ampiFunctions.hpp:5629
~AMPI_Gather_AdjointHandle()
Definition ampiFunctions.hpp:5641
void * sendbufAdjoints
Definition ampiFunctions.hpp:5624
RECVTYPE::PrimalType * recvbufOldPrimals
Definition ampiFunctions.hpp:5632
SENDTYPE::PrimalType * sendbufPrimals
Definition ampiFunctions.hpp:5623
void * recvbufAdjoints
Definition ampiFunctions.hpp:5633
Definition ampiFunctions.hpp:5908
SENDTYPE * sendtype
Definition ampiFunctions.hpp:5916
int sendcount
Definition ampiFunctions.hpp:5915
RECVTYPE::IndexType * recvbufIndices
Definition ampiFunctions.hpp:5918
const int * recvcounts
Definition ampiFunctions.hpp:5925
RECVTYPE * recvtype
Definition ampiFunctions.hpp:5927
int sendbufCountVec
Definition ampiFunctions.hpp:5914
const int * displs
Definition ampiFunctions.hpp:5926
int root
Definition ampiFunctions.hpp:5928
int * recvbufCountVec
Definition ampiFunctions.hpp:5923
~AMPI_Gatherv_AdjointHandle()
Definition ampiFunctions.hpp:5931
void * recvbufAdjoints
Definition ampiFunctions.hpp:5921
void * sendbufAdjoints
Definition ampiFunctions.hpp:5912
int recvbufTotalSize
Definition ampiFunctions.hpp:5917
int * recvbufCount
Definition ampiFunctions.hpp:5922
RECVTYPE::PrimalType * recvbufOldPrimals
Definition ampiFunctions.hpp:5920
int sendbufCount
Definition ampiFunctions.hpp:5913
SENDTYPE::PrimalType * sendbufPrimals
Definition ampiFunctions.hpp:5911
SENDTYPE::IndexType * sendbufIndices
Definition ampiFunctions.hpp:5910
int * recvbufDisplsVec
Definition ampiFunctions.hpp:5924
int sendbufTotalSize
Definition ampiFunctions.hpp:5909
MPI_Comm comm
Definition ampiFunctions.hpp:5929
RECVTYPE::PrimalType * recvbufPrimals
Definition ampiFunctions.hpp:5919
Definition ampiFunctions.hpp:6243
int recvbufCount
Definition ampiFunctions.hpp:6257
RECVTYPE::IndexType * recvbufIndices
Definition ampiFunctions.hpp:6253
int sendcount
Definition ampiFunctions.hpp:6250
RECVTYPE::PrimalType * recvbufPrimals
Definition ampiFunctions.hpp:6254
int recvcount
Definition ampiFunctions.hpp:6259
int recvbufTotalSize
Definition ampiFunctions.hpp:6252
int recvbufCountVec
Definition ampiFunctions.hpp:6258
RECVTYPE * recvtype
Definition ampiFunctions.hpp:6260
void * sendbufAdjoints
Definition ampiFunctions.hpp:6247
SENDTYPE * sendtype
Definition ampiFunctions.hpp:6251
SENDTYPE::IndexType * sendbufIndices
Definition ampiFunctions.hpp:6245
int sendbufTotalSize
Definition ampiFunctions.hpp:6244
SENDTYPE::PrimalType * sendbufPrimals
Definition ampiFunctions.hpp:6246
int sendbufCount
Definition ampiFunctions.hpp:6248
~AMPI_Iallgather_AdjointHandle()
Definition ampiFunctions.hpp:6263
RECVTYPE::PrimalType * recvbufOldPrimals
Definition ampiFunctions.hpp:6255
int sendbufCountVec
Definition ampiFunctions.hpp:6249
void * recvbufAdjoints
Definition ampiFunctions.hpp:6256
MPI_Comm comm
Definition ampiFunctions.hpp:6261
Definition ampiFunctions.hpp:6288
SENDTYPE::ModifiedType * sendbufMod
Definition ampiFunctions.hpp:6290
SENDTYPE * sendtype
Definition ampiFunctions.hpp:6292
MPI_Comm comm
Definition ampiFunctions.hpp:6297
int sendcount
Definition ampiFunctions.hpp:6291
RECVTYPE * recvtype
Definition ampiFunctions.hpp:6296
int recvcount
Definition ampiFunctions.hpp:6295
const SENDTYPE::Type * sendbuf
Definition ampiFunctions.hpp:6289
RECVTYPE::ModifiedType * recvbufMod
Definition ampiFunctions.hpp:6294
RECVTYPE::Type * recvbuf
Definition ampiFunctions.hpp:6293
AMPI_Request * request
Definition ampiFunctions.hpp:6298
Definition ampiFunctions.hpp:6601
SENDTYPE::PrimalType * sendbufPrimals
Definition ampiFunctions.hpp:6604
int * recvbufCount
Definition ampiFunctions.hpp:6615
MPI_Comm comm
Definition ampiFunctions.hpp:6621
RECVTYPE::PrimalType * recvbufOldPrimals
Definition ampiFunctions.hpp:6613
int * recvbufDisplsVec
Definition ampiFunctions.hpp:6617
const int * displs
Definition ampiFunctions.hpp:6619
int sendcount
Definition ampiFunctions.hpp:6608
void * sendbufAdjoints
Definition ampiFunctions.hpp:6605
int sendbufCountVec
Definition ampiFunctions.hpp:6607
SENDTYPE::IndexType * sendbufIndices
Definition ampiFunctions.hpp:6603
~AMPI_Iallgatherv_AdjointHandle()
Definition ampiFunctions.hpp:6623
SENDTYPE * sendtype
Definition ampiFunctions.hpp:6609
int sendbufTotalSize
Definition ampiFunctions.hpp:6602
void * recvbufAdjoints
Definition ampiFunctions.hpp:6614
int * recvbufCountVec
Definition ampiFunctions.hpp:6616
RECVTYPE * recvtype
Definition ampiFunctions.hpp:6620
RECVTYPE::PrimalType * recvbufPrimals
Definition ampiFunctions.hpp:6612
int sendbufCount
Definition ampiFunctions.hpp:6606
int recvbufTotalSize
Definition ampiFunctions.hpp:6610
const int * recvcounts
Definition ampiFunctions.hpp:6618
RECVTYPE::IndexType * recvbufIndices
Definition ampiFunctions.hpp:6611
Definition ampiFunctions.hpp:6652
SENDTYPE::ModifiedType * sendbufMod
Definition ampiFunctions.hpp:6654
MPI_Comm comm
Definition ampiFunctions.hpp:6663
RECVTYPE * recvtype
Definition ampiFunctions.hpp:6662
SENDTYPE * sendtype
Definition ampiFunctions.hpp:6656
const SENDTYPE::Type * sendbuf
Definition ampiFunctions.hpp:6653
RECVTYPE::ModifiedType * recvbufMod
Definition ampiFunctions.hpp:6658
const int * recvcounts
Definition ampiFunctions.hpp:6660
int sendcount
Definition ampiFunctions.hpp:6655
AMPI_Request * request
Definition ampiFunctions.hpp:6664
RECVTYPE::Type * recvbuf
Definition ampiFunctions.hpp:6657
const int * displsMod
Definition ampiFunctions.hpp:6659
const int * displs
Definition ampiFunctions.hpp:6661
Definition ampiFunctions.hpp:7014
MPI_Comm comm
Definition ampiFunctions.hpp:7031
void * sendbufAdjoints
Definition ampiFunctions.hpp:7018
int recvbufCountVec
Definition ampiFunctions.hpp:7027
int count
Definition ampiFunctions.hpp:7028
~AMPI_Iallreduce_global_AdjointHandle()
Definition ampiFunctions.hpp:7033
DATATYPE::PrimalType * recvbufPrimals
Definition ampiFunctions.hpp:7023
int recvbufTotalSize
Definition ampiFunctions.hpp:7021
DATATYPE::PrimalType * sendbufPrimals
Definition ampiFunctions.hpp:7017
void * recvbufAdjoints
Definition ampiFunctions.hpp:7025
int recvbufCount
Definition ampiFunctions.hpp:7026
DATATYPE::IndexType * sendbufIndices
Definition ampiFunctions.hpp:7016
DATATYPE::PrimalType * recvbufOldPrimals
Definition ampiFunctions.hpp:7024
DATATYPE * datatype
Definition ampiFunctions.hpp:7029
int sendbufTotalSize
Definition ampiFunctions.hpp:7015
int sendbufCountVec
Definition ampiFunctions.hpp:7020
int sendbufCount
Definition ampiFunctions.hpp:7019
AMPI_Op op
Definition ampiFunctions.hpp:7030
DATATYPE::IndexType * recvbufIndices
Definition ampiFunctions.hpp:7022
Definition ampiFunctions.hpp:7058
AMPI_Op op
Definition ampiFunctions.hpp:7065
DATATYPE * datatype
Definition ampiFunctions.hpp:7064
int count
Definition ampiFunctions.hpp:7063
DATATYPE::Type * recvbuf
Definition ampiFunctions.hpp:7061
DATATYPE::ModifiedType * recvbufMod
Definition ampiFunctions.hpp:7062
AMPI_Request * request
Definition ampiFunctions.hpp:7067
const DATATYPE::Type * sendbuf
Definition ampiFunctions.hpp:7059
MPI_Comm comm
Definition ampiFunctions.hpp:7066
DATATYPE::ModifiedType * sendbufMod
Definition ampiFunctions.hpp:7060
Definition ampiFunctions.hpp:7400
RECVTYPE * recvtype
Definition ampiFunctions.hpp:7417
int sendcount
Definition ampiFunctions.hpp:7407
RECVTYPE::IndexType * recvbufIndices
Definition ampiFunctions.hpp:7410
int recvcount
Definition ampiFunctions.hpp:7416
RECVTYPE::PrimalType * recvbufOldPrimals
Definition ampiFunctions.hpp:7412
int recvbufTotalSize
Definition ampiFunctions.hpp:7409
int sendbufTotalSize
Definition ampiFunctions.hpp:7401
RECVTYPE::PrimalType * recvbufPrimals
Definition ampiFunctions.hpp:7411
MPI_Comm comm
Definition ampiFunctions.hpp:7418
SENDTYPE::PrimalType * sendbufPrimals
Definition ampiFunctions.hpp:7403
~AMPI_Ialltoall_AdjointHandle()
Definition ampiFunctions.hpp:7420
int sendbufCountVec
Definition ampiFunctions.hpp:7406
void * sendbufAdjoints
Definition ampiFunctions.hpp:7404
SENDTYPE * sendtype
Definition ampiFunctions.hpp:7408
void * recvbufAdjoints
Definition ampiFunctions.hpp:7413
int sendbufCount
Definition ampiFunctions.hpp:7405
int recvbufCount
Definition ampiFunctions.hpp:7414
int recvbufCountVec
Definition ampiFunctions.hpp:7415
SENDTYPE::IndexType * sendbufIndices
Definition ampiFunctions.hpp:7402
Definition ampiFunctions.hpp:7445
MPI_Comm comm
Definition ampiFunctions.hpp:7454
RECVTYPE::ModifiedType * recvbufMod
Definition ampiFunctions.hpp:7451
const SENDTYPE::Type * sendbuf
Definition ampiFunctions.hpp:7446
RECVTYPE::Type * recvbuf
Definition ampiFunctions.hpp:7450
int sendcount
Definition ampiFunctions.hpp:7448
SENDTYPE::ModifiedType * sendbufMod
Definition ampiFunctions.hpp:7447
AMPI_Request * request
Definition ampiFunctions.hpp:7455
RECVTYPE * recvtype
Definition ampiFunctions.hpp:7453
int recvcount
Definition ampiFunctions.hpp:7452
SENDTYPE * sendtype
Definition ampiFunctions.hpp:7449
Definition ampiFunctions.hpp:7756
int * sendbufCountVec
Definition ampiFunctions.hpp:7762
SENDTYPE * sendtype
Definition ampiFunctions.hpp:7766
SENDTYPE::IndexType * sendbufIndices
Definition ampiFunctions.hpp:7758
const int * sdispls
Definition ampiFunctions.hpp:7765
RECVTYPE::PrimalType * recvbufPrimals
Definition ampiFunctions.hpp:7769
int * recvbufCountVec
Definition ampiFunctions.hpp:7773
~AMPI_Ialltoallv_AdjointHandle()
Definition ampiFunctions.hpp:7780
const int * recvcounts
Definition ampiFunctions.hpp:7775
MPI_Comm comm
Definition ampiFunctions.hpp:7778
int * recvbufDisplsVec
Definition ampiFunctions.hpp:7774
void * recvbufAdjoints
Definition ampiFunctions.hpp:7771
int sendbufTotalSize
Definition ampiFunctions.hpp:7757
RECVTYPE * recvtype
Definition ampiFunctions.hpp:7777
const int * sendcounts
Definition ampiFunctions.hpp:7764
int * sendbufDisplsVec
Definition ampiFunctions.hpp:7763
SENDTYPE::PrimalType * sendbufPrimals
Definition ampiFunctions.hpp:7759
RECVTYPE::PrimalType * recvbufOldPrimals
Definition ampiFunctions.hpp:7770
int recvbufTotalSize
Definition ampiFunctions.hpp:7767
int * sendbufCount
Definition ampiFunctions.hpp:7761
int * recvbufCount
Definition ampiFunctions.hpp:7772
RECVTYPE::IndexType * recvbufIndices
Definition ampiFunctions.hpp:7768
void * sendbufAdjoints
Definition ampiFunctions.hpp:7760
const int * rdispls
Definition ampiFunctions.hpp:7776
Definition ampiFunctions.hpp:7813
RECVTYPE::ModifiedType * recvbufMod
Definition ampiFunctions.hpp:7821
const int * rdisplsMod
Definition ampiFunctions.hpp:7822
const int * rdispls
Definition ampiFunctions.hpp:7824
RECVTYPE::Type * recvbuf
Definition ampiFunctions.hpp:7820
AMPI_Request * request
Definition ampiFunctions.hpp:7827
RECVTYPE * recvtype
Definition ampiFunctions.hpp:7825
SENDTYPE * sendtype
Definition ampiFunctions.hpp:7819
const int * sendcounts
Definition ampiFunctions.hpp:7817
const int * sdisplsMod
Definition ampiFunctions.hpp:7816
SENDTYPE::ModifiedType * sendbufMod
Definition ampiFunctions.hpp:7815
const int * sdispls
Definition ampiFunctions.hpp:7818
const SENDTYPE::Type * sendbuf
Definition ampiFunctions.hpp:7814
const int * recvcounts
Definition ampiFunctions.hpp:7823
MPI_Comm comm
Definition ampiFunctions.hpp:7826
Definition ampiFunctions.hpp:8204
int bufferSendTotalSize
Definition ampiFunctions.hpp:8205
DATATYPE::PrimalType * bufferRecvPrimals
Definition ampiFunctions.hpp:8213
~AMPI_Ibcast_wrap_AdjointHandle()
Definition ampiFunctions.hpp:8223
DATATYPE::PrimalType * bufferSendPrimals
Definition ampiFunctions.hpp:8207
MPI_Comm comm
Definition ampiFunctions.hpp:8221
int bufferSendCountVec
Definition ampiFunctions.hpp:8210
int bufferSendCount
Definition ampiFunctions.hpp:8209
int count
Definition ampiFunctions.hpp:8218
int bufferRecvTotalSize
Definition ampiFunctions.hpp:8211
DATATYPE::IndexType * bufferSendIndices
Definition ampiFunctions.hpp:8206
int root
Definition ampiFunctions.hpp:8220
void * bufferRecvAdjoints
Definition ampiFunctions.hpp:8215
DATATYPE::PrimalType * bufferRecvOldPrimals
Definition ampiFunctions.hpp:8214
DATATYPE * datatype
Definition ampiFunctions.hpp:8219
int bufferRecvCountVec
Definition ampiFunctions.hpp:8217
void * bufferSendAdjoints
Definition ampiFunctions.hpp:8208
DATATYPE::IndexType * bufferRecvIndices
Definition ampiFunctions.hpp:8212
int bufferRecvCount
Definition ampiFunctions.hpp:8216
Definition ampiFunctions.hpp:8248
DATATYPE::Type * bufferRecv
Definition ampiFunctions.hpp:8251
AMPI_Request * request
Definition ampiFunctions.hpp:8257
DATATYPE * datatype
Definition ampiFunctions.hpp:8254
int root
Definition ampiFunctions.hpp:8255
DATATYPE::ModifiedType * bufferSendMod
Definition ampiFunctions.hpp:8250
MPI_Comm comm
Definition ampiFunctions.hpp:8256
DATATYPE::ModifiedType * bufferRecvMod
Definition ampiFunctions.hpp:8252
DATATYPE::Type * bufferSend
Definition ampiFunctions.hpp:8249
int count
Definition ampiFunctions.hpp:8253
Definition ampiFunctions.hpp:200
int dest
Definition ampiFunctions.hpp:209
int bufCount
Definition ampiFunctions.hpp:205
int count
Definition ampiFunctions.hpp:207
DATATYPE::PrimalType * bufPrimals
Definition ampiFunctions.hpp:203
DATATYPE::IndexType * bufIndices
Definition ampiFunctions.hpp:202
int tag
Definition ampiFunctions.hpp:210
~AMPI_Ibsend_AdjointHandle()
Definition ampiFunctions.hpp:213
DATATYPE * datatype
Definition ampiFunctions.hpp:208
void * bufAdjoints
Definition ampiFunctions.hpp:204
MPI_Comm comm
Definition ampiFunctions.hpp:211
int bufTotalSize
Definition ampiFunctions.hpp:201
int bufCountVec
Definition ampiFunctions.hpp:206
Definition ampiFunctions.hpp:226
const DATATYPE::Type * buf
Definition ampiFunctions.hpp:227
int count
Definition ampiFunctions.hpp:229
DATATYPE::ModifiedType * bufMod
Definition ampiFunctions.hpp:228
MPI_Comm comm
Definition ampiFunctions.hpp:233
AMPI_Request * request
Definition ampiFunctions.hpp:234
int dest
Definition ampiFunctions.hpp:231
int tag
Definition ampiFunctions.hpp:232
DATATYPE * datatype
Definition ampiFunctions.hpp:230
Definition ampiFunctions.hpp:8569
SENDTYPE * sendtype
Definition ampiFunctions.hpp:8577
int sendbufTotalSize
Definition ampiFunctions.hpp:8570
int sendbufCount
Definition ampiFunctions.hpp:8574
RECVTYPE::PrimalType * recvbufOldPrimals
Definition ampiFunctions.hpp:8581
SENDTYPE::IndexType * sendbufIndices
Definition ampiFunctions.hpp:8571
int sendbufCountVec
Definition ampiFunctions.hpp:8575
int root
Definition ampiFunctions.hpp:8587
RECVTYPE::PrimalType * recvbufPrimals
Definition ampiFunctions.hpp:8580
int recvbufCount
Definition ampiFunctions.hpp:8583
int recvbufCountVec
Definition ampiFunctions.hpp:8584
void * recvbufAdjoints
Definition ampiFunctions.hpp:8582
RECVTYPE * recvtype
Definition ampiFunctions.hpp:8586
SENDTYPE::PrimalType * sendbufPrimals
Definition ampiFunctions.hpp:8572
~AMPI_Igather_AdjointHandle()
Definition ampiFunctions.hpp:8590
void * sendbufAdjoints
Definition ampiFunctions.hpp:8573
RECVTYPE::IndexType * recvbufIndices
Definition ampiFunctions.hpp:8579
int sendcount
Definition ampiFunctions.hpp:8576
int recvcount
Definition ampiFunctions.hpp:8585
int recvbufTotalSize
Definition ampiFunctions.hpp:8578
MPI_Comm comm
Definition ampiFunctions.hpp:8588
Definition ampiFunctions.hpp:8615
AMPI_Request * request
Definition ampiFunctions.hpp:8626
RECVTYPE::ModifiedType * recvbufMod
Definition ampiFunctions.hpp:8621
SENDTYPE::ModifiedType * sendbufMod
Definition ampiFunctions.hpp:8617
MPI_Comm comm
Definition ampiFunctions.hpp:8625
int sendcount
Definition ampiFunctions.hpp:8618
RECVTYPE * recvtype
Definition ampiFunctions.hpp:8623
int recvcount
Definition ampiFunctions.hpp:8622
int root
Definition ampiFunctions.hpp:8624
const SENDTYPE::Type * sendbuf
Definition ampiFunctions.hpp:8616
RECVTYPE::Type * recvbuf
Definition ampiFunctions.hpp:8620
SENDTYPE * sendtype
Definition ampiFunctions.hpp:8619
Definition ampiFunctions.hpp:8966
RECVTYPE::PrimalType * recvbufOldPrimals
Definition ampiFunctions.hpp:8978
int sendcount
Definition ampiFunctions.hpp:8973
~AMPI_Igatherv_AdjointHandle()
Definition ampiFunctions.hpp:8989
int * recvbufCount
Definition ampiFunctions.hpp:8980
const int * recvcounts
Definition ampiFunctions.hpp:8983
int root
Definition ampiFunctions.hpp:8986
void * sendbufAdjoints
Definition ampiFunctions.hpp:8970
int sendbufCountVec
Definition ampiFunctions.hpp:8972
RECVTYPE::PrimalType * recvbufPrimals
Definition ampiFunctions.hpp:8977
int * recvbufDisplsVec
Definition ampiFunctions.hpp:8982
void * recvbufAdjoints
Definition ampiFunctions.hpp:8979
SENDTYPE::IndexType * sendbufIndices
Definition ampiFunctions.hpp:8968
int sendbufCount
Definition ampiFunctions.hpp:8971
MPI_Comm comm
Definition ampiFunctions.hpp:8987
const int * displs
Definition ampiFunctions.hpp:8984
int recvbufTotalSize
Definition ampiFunctions.hpp:8975
SENDTYPE * sendtype
Definition ampiFunctions.hpp:8974
int sendbufTotalSize
Definition ampiFunctions.hpp:8967
RECVTYPE * recvtype
Definition ampiFunctions.hpp:8985
RECVTYPE::IndexType * recvbufIndices
Definition ampiFunctions.hpp:8976
SENDTYPE::PrimalType * sendbufPrimals
Definition ampiFunctions.hpp:8969
int * recvbufCountVec
Definition ampiFunctions.hpp:8981
Definition ampiFunctions.hpp:9018
MPI_Comm comm
Definition ampiFunctions.hpp:9030
int root
Definition ampiFunctions.hpp:9029
const int * displsMod
Definition ampiFunctions.hpp:9025
RECVTYPE::Type * recvbuf
Definition ampiFunctions.hpp:9023
AMPI_Request * request
Definition ampiFunctions.hpp:9031
int sendcount
Definition ampiFunctions.hpp:9021
RECVTYPE * recvtype
Definition ampiFunctions.hpp:9028
SENDTYPE * sendtype
Definition ampiFunctions.hpp:9022
const int * displs
Definition ampiFunctions.hpp:9027
const int * recvcounts
Definition ampiFunctions.hpp:9026
RECVTYPE::ModifiedType * recvbufMod
Definition ampiFunctions.hpp:9024
const SENDTYPE::Type * sendbuf
Definition ampiFunctions.hpp:9019
SENDTYPE::ModifiedType * sendbufMod
Definition ampiFunctions.hpp:9020
Definition ampiFunctions.hpp:671
void * bufAdjoints
Definition ampiFunctions.hpp:676
DATATYPE::PrimalType * bufOldPrimals
Definition ampiFunctions.hpp:675
int bufCountVec
Definition ampiFunctions.hpp:678
DATATYPE * datatype
Definition ampiFunctions.hpp:680
IrecvAdjCall reverse_send
Definition ampiFunctions.hpp:682
int bufCount
Definition ampiFunctions.hpp:677
int bufTotalSize
Definition ampiFunctions.hpp:672
~AMPI_Imrecv_AdjointHandle()
Definition ampiFunctions.hpp:684
int count
Definition ampiFunctions.hpp:679
DATATYPE::PrimalType * bufPrimals
Definition ampiFunctions.hpp:674
AMPI_Message message
Definition ampiFunctions.hpp:681
DATATYPE::IndexType * bufIndices
Definition ampiFunctions.hpp:673
Definition ampiFunctions.hpp:701
int count
Definition ampiFunctions.hpp:704
DATATYPE::Type * buf
Definition ampiFunctions.hpp:702
DATATYPE::ModifiedType * bufMod
Definition ampiFunctions.hpp:703
DATATYPE * datatype
Definition ampiFunctions.hpp:705
IrecvAdjCall reverse_send
Definition ampiFunctions.hpp:708
AMPI_Request * request
Definition ampiFunctions.hpp:707
AMPI_Message * message
Definition ampiFunctions.hpp:706
Definition ampiFunctions.hpp:932
int bufCount
Definition ampiFunctions.hpp:938
DATATYPE::IndexType * bufIndices
Definition ampiFunctions.hpp:934
int source
Definition ampiFunctions.hpp:942
IrecvAdjCall reverse_send
Definition ampiFunctions.hpp:945
int bufTotalSize
Definition ampiFunctions.hpp:933
DATATYPE::PrimalType * bufOldPrimals
Definition ampiFunctions.hpp:936
DATATYPE::PrimalType * bufPrimals
Definition ampiFunctions.hpp:935
int tag
Definition ampiFunctions.hpp:943
void * bufAdjoints
Definition ampiFunctions.hpp:937
int bufCountVec
Definition ampiFunctions.hpp:939
DATATYPE * datatype
Definition ampiFunctions.hpp:941
MPI_Comm comm
Definition ampiFunctions.hpp:944
int count
Definition ampiFunctions.hpp:940
~AMPI_Irecv_AdjointHandle()
Definition ampiFunctions.hpp:947
Definition ampiFunctions.hpp:964
int count
Definition ampiFunctions.hpp:967
int source
Definition ampiFunctions.hpp:969
DATATYPE::Type * buf
Definition ampiFunctions.hpp:965
int tag
Definition ampiFunctions.hpp:970
DATATYPE * datatype
Definition ampiFunctions.hpp:968
MPI_Comm comm
Definition ampiFunctions.hpp:971
DATATYPE::ModifiedType * bufMod
Definition ampiFunctions.hpp:966
IrecvAdjCall reverse_send
Definition ampiFunctions.hpp:973
AMPI_Request * request
Definition ampiFunctions.hpp:972
Definition ampiFunctions.hpp:9418
int sendbufCount
Definition ampiFunctions.hpp:9423
~AMPI_Ireduce_global_AdjointHandle()
Definition ampiFunctions.hpp:9438
AMPI_Op op
Definition ampiFunctions.hpp:9434
DATATYPE * datatype
Definition ampiFunctions.hpp:9433
void * recvbufAdjoints
Definition ampiFunctions.hpp:9429
int root
Definition ampiFunctions.hpp:9435
DATATYPE::PrimalType * sendbufPrimals
Definition ampiFunctions.hpp:9421
MPI_Comm comm
Definition ampiFunctions.hpp:9436
int sendbufTotalSize
Definition ampiFunctions.hpp:9419
int count
Definition ampiFunctions.hpp:9432
DATATYPE::PrimalType * recvbufOldPrimals
Definition ampiFunctions.hpp:9428
void * sendbufAdjoints
Definition ampiFunctions.hpp:9422
DATATYPE::IndexType * sendbufIndices
Definition ampiFunctions.hpp:9420
int sendbufCountVec
Definition ampiFunctions.hpp:9424
DATATYPE::PrimalType * recvbufPrimals
Definition ampiFunctions.hpp:9427
int recvbufCountVec
Definition ampiFunctions.hpp:9431
DATATYPE::IndexType * recvbufIndices
Definition ampiFunctions.hpp:9426
int recvbufTotalSize
Definition ampiFunctions.hpp:9425
int recvbufCount
Definition ampiFunctions.hpp:9430
Definition ampiFunctions.hpp:9463
const DATATYPE::Type * sendbuf
Definition ampiFunctions.hpp:9464
DATATYPE * datatype
Definition ampiFunctions.hpp:9469
DATATYPE::ModifiedType * sendbufMod
Definition ampiFunctions.hpp:9465
MPI_Comm comm
Definition ampiFunctions.hpp:9472
AMPI_Request * request
Definition ampiFunctions.hpp:9473
DATATYPE::Type * recvbuf
Definition ampiFunctions.hpp:9466
DATATYPE::ModifiedType * recvbufMod
Definition ampiFunctions.hpp:9467
int root
Definition ampiFunctions.hpp:9471
int count
Definition ampiFunctions.hpp:9468
AMPI_Op op
Definition ampiFunctions.hpp:9470
Definition ampiFunctions.hpp:1205
int bufCountVec
Definition ampiFunctions.hpp:1211
DATATYPE * datatype
Definition ampiFunctions.hpp:1213
int bufCount
Definition ampiFunctions.hpp:1210
MPI_Comm comm
Definition ampiFunctions.hpp:1216
int bufTotalSize
Definition ampiFunctions.hpp:1206
void * bufAdjoints
Definition ampiFunctions.hpp:1209
~AMPI_Irsend_AdjointHandle()
Definition ampiFunctions.hpp:1218
DATATYPE::IndexType * bufIndices
Definition ampiFunctions.hpp:1207
int dest
Definition ampiFunctions.hpp:1214
DATATYPE::PrimalType * bufPrimals
Definition ampiFunctions.hpp:1208
int tag
Definition ampiFunctions.hpp:1215
int count
Definition ampiFunctions.hpp:1212
Definition ampiFunctions.hpp:1231
int dest
Definition ampiFunctions.hpp:1236
AMPI_Request * request
Definition ampiFunctions.hpp:1239
DATATYPE::ModifiedType * bufMod
Definition ampiFunctions.hpp:1233
DATATYPE * datatype
Definition ampiFunctions.hpp:1235
int count
Definition ampiFunctions.hpp:1234
MPI_Comm comm
Definition ampiFunctions.hpp:1238
const DATATYPE::Type * buf
Definition ampiFunctions.hpp:1232
int tag
Definition ampiFunctions.hpp:1237
Definition ampiFunctions.hpp:9841
MPI_Comm comm
Definition ampiFunctions.hpp:9860
void * sendbufAdjoints
Definition ampiFunctions.hpp:9845
RECVTYPE::PrimalType * recvbufOldPrimals
Definition ampiFunctions.hpp:9853
SENDTYPE * sendtype
Definition ampiFunctions.hpp:9849
SENDTYPE::IndexType * sendbufIndices
Definition ampiFunctions.hpp:9843
int sendbufTotalSize
Definition ampiFunctions.hpp:9842
int sendbufCount
Definition ampiFunctions.hpp:9846
RECVTYPE * recvtype
Definition ampiFunctions.hpp:9858
int recvbufCountVec
Definition ampiFunctions.hpp:9856
~AMPI_Iscatter_AdjointHandle()
Definition ampiFunctions.hpp:9862
RECVTYPE::IndexType * recvbufIndices
Definition ampiFunctions.hpp:9851
int recvcount
Definition ampiFunctions.hpp:9857
RECVTYPE::PrimalType * recvbufPrimals
Definition ampiFunctions.hpp:9852
SENDTYPE::PrimalType * sendbufPrimals
Definition ampiFunctions.hpp:9844
int recvbufTotalSize
Definition ampiFunctions.hpp:9850
int root
Definition ampiFunctions.hpp:9859
void * recvbufAdjoints
Definition ampiFunctions.hpp:9854
int sendcount
Definition ampiFunctions.hpp:9848
int recvbufCount
Definition ampiFunctions.hpp:9855
int sendbufCountVec
Definition ampiFunctions.hpp:9847
Definition ampiFunctions.hpp:9887
RECVTYPE::ModifiedType * recvbufMod
Definition ampiFunctions.hpp:9893
int root
Definition ampiFunctions.hpp:9896
RECVTYPE::Type * recvbuf
Definition ampiFunctions.hpp:9892
SENDTYPE::ModifiedType * sendbufMod
Definition ampiFunctions.hpp:9889
const SENDTYPE::Type * sendbuf
Definition ampiFunctions.hpp:9888
SENDTYPE * sendtype
Definition ampiFunctions.hpp:9891
RECVTYPE * recvtype
Definition ampiFunctions.hpp:9895
int sendcount
Definition ampiFunctions.hpp:9890
AMPI_Request * request
Definition ampiFunctions.hpp:9898
int recvcount
Definition ampiFunctions.hpp:9894
MPI_Comm comm
Definition ampiFunctions.hpp:9897
Definition ampiFunctions.hpp:10240
int recvcount
Definition ampiFunctions.hpp:10258
RECVTYPE::IndexType * recvbufIndices
Definition ampiFunctions.hpp:10252
const int * sendcounts
Definition ampiFunctions.hpp:10248
int sendbufTotalSize
Definition ampiFunctions.hpp:10241
int * sendbufCount
Definition ampiFunctions.hpp:10245
SENDTYPE::IndexType * sendbufIndices
Definition ampiFunctions.hpp:10242
int recvbufCountVec
Definition ampiFunctions.hpp:10257
RECVTYPE * recvtype
Definition ampiFunctions.hpp:10259
RECVTYPE::PrimalType * recvbufOldPrimals
Definition ampiFunctions.hpp:10254
int * sendbufCountVec
Definition ampiFunctions.hpp:10246
void * sendbufAdjoints
Definition ampiFunctions.hpp:10244
int * sendbufDisplsVec
Definition ampiFunctions.hpp:10247
SENDTYPE * sendtype
Definition ampiFunctions.hpp:10250
MPI_Comm comm
Definition ampiFunctions.hpp:10261
int root
Definition ampiFunctions.hpp:10260
int recvbufCount
Definition ampiFunctions.hpp:10256
void * recvbufAdjoints
Definition ampiFunctions.hpp:10255
SENDTYPE::PrimalType * sendbufPrimals
Definition ampiFunctions.hpp:10243
int recvbufTotalSize
Definition ampiFunctions.hpp:10251
RECVTYPE::PrimalType * recvbufPrimals
Definition ampiFunctions.hpp:10253
~AMPI_Iscatterv_AdjointHandle()
Definition ampiFunctions.hpp:10263
const int * displs
Definition ampiFunctions.hpp:10249
Definition ampiFunctions.hpp:10292
MPI_Comm comm
Definition ampiFunctions.hpp:10304
int root
Definition ampiFunctions.hpp:10303
RECVTYPE::ModifiedType * recvbufMod
Definition ampiFunctions.hpp:10300
RECVTYPE * recvtype
Definition ampiFunctions.hpp:10302
int recvcount
Definition ampiFunctions.hpp:10301
const int * displsMod
Definition ampiFunctions.hpp:10295
const SENDTYPE::Type * sendbuf
Definition ampiFunctions.hpp:10293
const int * displs
Definition ampiFunctions.hpp:10297
const int * sendcounts
Definition ampiFunctions.hpp:10296
AMPI_Request * request
Definition ampiFunctions.hpp:10305
SENDTYPE::ModifiedType * sendbufMod
Definition ampiFunctions.hpp:10294
RECVTYPE::Type * recvbuf
Definition ampiFunctions.hpp:10299
SENDTYPE * sendtype
Definition ampiFunctions.hpp:10298
Definition ampiFunctions.hpp:1452
int bufCountVec
Definition ampiFunctions.hpp:1458
DATATYPE::PrimalType * bufPrimals
Definition ampiFunctions.hpp:1455
int tag
Definition ampiFunctions.hpp:1462
void * bufAdjoints
Definition ampiFunctions.hpp:1456
int count
Definition ampiFunctions.hpp:1459
~AMPI_Isend_AdjointHandle()
Definition ampiFunctions.hpp:1465
DATATYPE * datatype
Definition ampiFunctions.hpp:1460
int dest
Definition ampiFunctions.hpp:1461
MPI_Comm comm
Definition ampiFunctions.hpp:1463
DATATYPE::IndexType * bufIndices
Definition ampiFunctions.hpp:1454
int bufCount
Definition ampiFunctions.hpp:1457
int bufTotalSize
Definition ampiFunctions.hpp:1453
Definition ampiFunctions.hpp:1478
int count
Definition ampiFunctions.hpp:1481
const DATATYPE::Type * buf
Definition ampiFunctions.hpp:1479
int dest
Definition ampiFunctions.hpp:1483
DATATYPE * datatype
Definition ampiFunctions.hpp:1482
AMPI_Request * request
Definition ampiFunctions.hpp:1486
int tag
Definition ampiFunctions.hpp:1484
MPI_Comm comm
Definition ampiFunctions.hpp:1485
DATATYPE::ModifiedType * bufMod
Definition ampiFunctions.hpp:1480
Definition ampiFunctions.hpp:1699
~AMPI_Issend_AdjointHandle()
Definition ampiFunctions.hpp:1712
int bufCountVec
Definition ampiFunctions.hpp:1705
DATATYPE::PrimalType * bufPrimals
Definition ampiFunctions.hpp:1702
DATATYPE::IndexType * bufIndices
Definition ampiFunctions.hpp:1701
int bufCount
Definition ampiFunctions.hpp:1704
MPI_Comm comm
Definition ampiFunctions.hpp:1710
int tag
Definition ampiFunctions.hpp:1709
int dest
Definition ampiFunctions.hpp:1708
void * bufAdjoints
Definition ampiFunctions.hpp:1703
int bufTotalSize
Definition ampiFunctions.hpp:1700
int count
Definition ampiFunctions.hpp:1706
DATATYPE * datatype
Definition ampiFunctions.hpp:1707
Definition ampiFunctions.hpp:1725
int count
Definition ampiFunctions.hpp:1728
AMPI_Request * request
Definition ampiFunctions.hpp:1733
int tag
Definition ampiFunctions.hpp:1731
int dest
Definition ampiFunctions.hpp:1730
DATATYPE::ModifiedType * bufMod
Definition ampiFunctions.hpp:1727
const DATATYPE::Type * buf
Definition ampiFunctions.hpp:1726
DATATYPE * datatype
Definition ampiFunctions.hpp:1729
MPI_Comm comm
Definition ampiFunctions.hpp:1732
Stores additional information for a MPI_Message.
Definition message.hpp:44
MPI_Message message
Definition message.hpp:45
Definition ampiFunctions.hpp:1946
DATATYPE::PrimalType * bufPrimals
Definition ampiFunctions.hpp:1949
~AMPI_Mrecv_AdjointHandle()
Definition ampiFunctions.hpp:1960
int bufTotalSize
Definition ampiFunctions.hpp:1947
int count
Definition ampiFunctions.hpp:1954
RecvAdjCall reverse_send
Definition ampiFunctions.hpp:1958
int bufCountVec
Definition ampiFunctions.hpp:1953
AMPI_Message message
Definition ampiFunctions.hpp:1956
DATATYPE::PrimalType * bufOldPrimals
Definition ampiFunctions.hpp:1950
DATATYPE * datatype
Definition ampiFunctions.hpp:1955
DATATYPE::IndexType * bufIndices
Definition ampiFunctions.hpp:1948
int bufCount
Definition ampiFunctions.hpp:1952
void * bufAdjoints
Definition ampiFunctions.hpp:1951
MPI_Status * status
Definition ampiFunctions.hpp:1957
Structure for the special handling of the MPI_Op structure.
Definition op.hpp:50
PostAdjointOperation postAdjointOperation
The operation that is evaluated on each adjoint after the values have been received in a message.
Definition op.hpp:87
MPI_Op primalFunction
The mpi operator for the unmodified AD types. The AD tool needs to record all operations that are eva...
Definition op.hpp:69
bool requiresPrimal
Indicates if the primal on the sending and receiving side are required by this operator.
Definition op.hpp:55
MPI_Op modifiedPrimalFunction
The mpi operator for the modified AD types. This are the operations that are evaluated during the mpi...
Definition op.hpp:77
Definition ampiFunctions.hpp:2123
~AMPI_Recv_AdjointHandle()
Definition ampiFunctions.hpp:2138
DATATYPE::PrimalType * bufPrimals
Definition ampiFunctions.hpp:2126
int count
Definition ampiFunctions.hpp:2131
RecvAdjCall reverse_send
Definition ampiFunctions.hpp:2136
MPI_Comm comm
Definition ampiFunctions.hpp:2135
int source
Definition ampiFunctions.hpp:2133
DATATYPE::PrimalType * bufOldPrimals
Definition ampiFunctions.hpp:2127
int bufCountVec
Definition ampiFunctions.hpp:2130
void * bufAdjoints
Definition ampiFunctions.hpp:2128
int bufTotalSize
Definition ampiFunctions.hpp:2124
int bufCount
Definition ampiFunctions.hpp:2129
DATATYPE * datatype
Definition ampiFunctions.hpp:2132
DATATYPE::IndexType * bufIndices
Definition ampiFunctions.hpp:2125
int tag
Definition ampiFunctions.hpp:2134
Definition ampiFunctions.hpp:2307
MPI_Comm comm
Definition ampiFunctions.hpp:2314
DATATYPE::Type * buf
Definition ampiFunctions.hpp:2308
int count
Definition ampiFunctions.hpp:2310
int tag
Definition ampiFunctions.hpp:2313
AMPI_Request * request
Definition ampiFunctions.hpp:2315
int source
Definition ampiFunctions.hpp:2312
IrecvAdjCall reverse_send
Definition ampiFunctions.hpp:2316
DATATYPE::ModifiedType * bufMod
Definition ampiFunctions.hpp:2309
DATATYPE * datatype
Definition ampiFunctions.hpp:2311
Definition ampiFunctions.hpp:10697
DATATYPE::PrimalType * recvbufOldPrimals
Definition ampiFunctions.hpp:10707
int sendbufTotalSize
Definition ampiFunctions.hpp:10698
int recvbufCountVec
Definition ampiFunctions.hpp:10710
DATATYPE * datatype
Definition ampiFunctions.hpp:10712
int recvbufTotalSize
Definition ampiFunctions.hpp:10704
DATATYPE::PrimalType * sendbufPrimals
Definition ampiFunctions.hpp:10700
int count
Definition ampiFunctions.hpp:10711
DATATYPE::PrimalType * recvbufPrimals
Definition ampiFunctions.hpp:10706
void * sendbufAdjoints
Definition ampiFunctions.hpp:10701
int sendbufCountVec
Definition ampiFunctions.hpp:10703
~AMPI_Reduce_global_AdjointHandle()
Definition ampiFunctions.hpp:10717
DATATYPE::IndexType * sendbufIndices
Definition ampiFunctions.hpp:10699
AMPI_Op op
Definition ampiFunctions.hpp:10713
void * recvbufAdjoints
Definition ampiFunctions.hpp:10708
MPI_Comm comm
Definition ampiFunctions.hpp:10715
int root
Definition ampiFunctions.hpp:10714
int recvbufCount
Definition ampiFunctions.hpp:10709
int sendbufCount
Definition ampiFunctions.hpp:10702
DATATYPE::IndexType * recvbufIndices
Definition ampiFunctions.hpp:10705
Definition async.hpp:45
AsyncHandle * handle
Definition async.hpp:47
ContinueFunction start
Definition async.hpp:52
ContinueFunction end
Definition async.hpp:53
MPI_Request request
Definition async.hpp:46
ContinueFunction func
Definition async.hpp:48
Definition ampiFunctions.hpp:2549
MPI_Comm comm
Definition ampiFunctions.hpp:2560
int count
Definition ampiFunctions.hpp:2556
int bufCountVec
Definition ampiFunctions.hpp:2555
DATATYPE * datatype
Definition ampiFunctions.hpp:2557
DATATYPE::IndexType * bufIndices
Definition ampiFunctions.hpp:2551
DATATYPE::PrimalType * bufPrimals
Definition ampiFunctions.hpp:2552
~AMPI_Rsend_AdjointHandle()
Definition ampiFunctions.hpp:2562
int tag
Definition ampiFunctions.hpp:2559
int bufTotalSize
Definition ampiFunctions.hpp:2550
int bufCount
Definition ampiFunctions.hpp:2554
void * bufAdjoints
Definition ampiFunctions.hpp:2553
int dest
Definition ampiFunctions.hpp:2558
Definition ampiFunctions.hpp:2705
DATATYPE * datatype
Definition ampiFunctions.hpp:2709
DATATYPE::ModifiedType * bufMod
Definition ampiFunctions.hpp:2707
int tag
Definition ampiFunctions.hpp:2711
const DATATYPE::Type * buf
Definition ampiFunctions.hpp:2706
MPI_Comm comm
Definition ampiFunctions.hpp:2712
AMPI_Request * request
Definition ampiFunctions.hpp:2713
int count
Definition ampiFunctions.hpp:2708
int dest
Definition ampiFunctions.hpp:2710
Definition ampiFunctions.hpp:11012
SENDTYPE::IndexType * sendbufIndices
Definition ampiFunctions.hpp:11014
void * sendbufAdjoints
Definition ampiFunctions.hpp:11016
int recvbufTotalSize
Definition ampiFunctions.hpp:11021
RECVTYPE * recvtype
Definition ampiFunctions.hpp:11029
int sendbufCountVec
Definition ampiFunctions.hpp:11018
RECVTYPE::IndexType * recvbufIndices
Definition ampiFunctions.hpp:11022
RECVTYPE::PrimalType * recvbufOldPrimals
Definition ampiFunctions.hpp:11024
void * recvbufAdjoints
Definition ampiFunctions.hpp:11025
SENDTYPE::PrimalType * sendbufPrimals
Definition ampiFunctions.hpp:11015
int recvbufCountVec
Definition ampiFunctions.hpp:11027
int sendbufTotalSize
Definition ampiFunctions.hpp:11013
SENDTYPE * sendtype
Definition ampiFunctions.hpp:11020
int recvcount
Definition ampiFunctions.hpp:11028
int root
Definition ampiFunctions.hpp:11030
~AMPI_Scatter_AdjointHandle()
Definition ampiFunctions.hpp:11033
int recvbufCount
Definition ampiFunctions.hpp:11026
int sendcount
Definition ampiFunctions.hpp:11019
int sendbufCount
Definition ampiFunctions.hpp:11017
RECVTYPE::PrimalType * recvbufPrimals
Definition ampiFunctions.hpp:11023
MPI_Comm comm
Definition ampiFunctions.hpp:11031
Definition ampiFunctions.hpp:11305
RECVTYPE::PrimalType * recvbufOldPrimals
Definition ampiFunctions.hpp:11319
int root
Definition ampiFunctions.hpp:11325
SENDTYPE::IndexType * sendbufIndices
Definition ampiFunctions.hpp:11307
int recvcount
Definition ampiFunctions.hpp:11323
void * recvbufAdjoints
Definition ampiFunctions.hpp:11320
RECVTYPE::IndexType * recvbufIndices
Definition ampiFunctions.hpp:11317
RECVTYPE * recvtype
Definition ampiFunctions.hpp:11324
~AMPI_Scatterv_AdjointHandle()
Definition ampiFunctions.hpp:11328
const int * sendcounts
Definition ampiFunctions.hpp:11313
SENDTYPE::PrimalType * sendbufPrimals
Definition ampiFunctions.hpp:11308
SENDTYPE * sendtype
Definition ampiFunctions.hpp:11315
int recvbufTotalSize
Definition ampiFunctions.hpp:11316
int recvbufCountVec
Definition ampiFunctions.hpp:11322
int * sendbufCountVec
Definition ampiFunctions.hpp:11311
MPI_Comm comm
Definition ampiFunctions.hpp:11326
int * sendbufDisplsVec
Definition ampiFunctions.hpp:11312
int * sendbufCount
Definition ampiFunctions.hpp:11310
int recvbufCount
Definition ampiFunctions.hpp:11321
int sendbufTotalSize
Definition ampiFunctions.hpp:11306
void * sendbufAdjoints
Definition ampiFunctions.hpp:11309
const int * displs
Definition ampiFunctions.hpp:11314
RECVTYPE::PrimalType * recvbufPrimals
Definition ampiFunctions.hpp:11318
Definition ampiFunctions.hpp:2928
~AMPI_Send_AdjointHandle()
Definition ampiFunctions.hpp:2941
DATATYPE::PrimalType * bufPrimals
Definition ampiFunctions.hpp:2931
void * bufAdjoints
Definition ampiFunctions.hpp:2932
MPI_Comm comm
Definition ampiFunctions.hpp:2939
DATATYPE * datatype
Definition ampiFunctions.hpp:2936
DATATYPE::IndexType * bufIndices
Definition ampiFunctions.hpp:2930
int dest
Definition ampiFunctions.hpp:2937
int bufTotalSize
Definition ampiFunctions.hpp:2929
int count
Definition ampiFunctions.hpp:2935
int bufCount
Definition ampiFunctions.hpp:2933
int bufCountVec
Definition ampiFunctions.hpp:2934
int tag
Definition ampiFunctions.hpp:2938
Definition ampiFunctions.hpp:3084
DATATYPE * datatype
Definition ampiFunctions.hpp:3088
MPI_Comm comm
Definition ampiFunctions.hpp:3091
const DATATYPE::Type * buf
Definition ampiFunctions.hpp:3085
DATATYPE::ModifiedType * bufMod
Definition ampiFunctions.hpp:3086
AMPI_Request * request
Definition ampiFunctions.hpp:3092
int tag
Definition ampiFunctions.hpp:3090
int count
Definition ampiFunctions.hpp:3087
int dest
Definition ampiFunctions.hpp:3089
Definition ampiFunctions.hpp:3307
SENDTYPE::IndexType * sendbufIndices
Definition ampiFunctions.hpp:3309
void * sendbufAdjoints
Definition ampiFunctions.hpp:3311
int sendcount
Definition ampiFunctions.hpp:3314
int recvbufCountVec
Definition ampiFunctions.hpp:3324
SENDTYPE::PrimalType * sendbufPrimals
Definition ampiFunctions.hpp:3310
int source
Definition ampiFunctions.hpp:3327
int recvcount
Definition ampiFunctions.hpp:3325
MPI_Comm comm
Definition ampiFunctions.hpp:3329
RECVTYPE * recvtype
Definition ampiFunctions.hpp:3326
int recvbufTotalSize
Definition ampiFunctions.hpp:3318
~AMPI_Sendrecv_AdjointHandle()
Definition ampiFunctions.hpp:3331
RECVTYPE::IndexType * recvbufIndices
Definition ampiFunctions.hpp:3319
int recvbufCount
Definition ampiFunctions.hpp:3323
int recvtag
Definition ampiFunctions.hpp:3328
SENDTYPE * sendtype
Definition ampiFunctions.hpp:3315
RECVTYPE::PrimalType * recvbufOldPrimals
Definition ampiFunctions.hpp:3321
int sendbufCountVec
Definition ampiFunctions.hpp:3313
int sendbufTotalSize
Definition ampiFunctions.hpp:3308
int sendtag
Definition ampiFunctions.hpp:3317
void * recvbufAdjoints
Definition ampiFunctions.hpp:3322
RECVTYPE::PrimalType * recvbufPrimals
Definition ampiFunctions.hpp:3320
int dest
Definition ampiFunctions.hpp:3316
int sendbufCount
Definition ampiFunctions.hpp:3312
Definition ampiFunctions.hpp:3557
MPI_Comm comm
Definition ampiFunctions.hpp:3568
int count
Definition ampiFunctions.hpp:3564
DATATYPE * datatype
Definition ampiFunctions.hpp:3565
void * bufAdjoints
Definition ampiFunctions.hpp:3561
int tag
Definition ampiFunctions.hpp:3567
int bufCount
Definition ampiFunctions.hpp:3562
DATATYPE::PrimalType * bufPrimals
Definition ampiFunctions.hpp:3560
DATATYPE::IndexType * bufIndices
Definition ampiFunctions.hpp:3559
int bufCountVec
Definition ampiFunctions.hpp:3563
int bufTotalSize
Definition ampiFunctions.hpp:3558
~AMPI_Ssend_AdjointHandle()
Definition ampiFunctions.hpp:3570
int dest
Definition ampiFunctions.hpp:3566
Definition ampiFunctions.hpp:3713
int dest
Definition ampiFunctions.hpp:3718
AMPI_Request * request
Definition ampiFunctions.hpp:3721
int tag
Definition ampiFunctions.hpp:3719
MPI_Comm comm
Definition ampiFunctions.hpp:3720
DATATYPE::ModifiedType * bufMod
Definition ampiFunctions.hpp:3715
DATATYPE * datatype
Definition ampiFunctions.hpp:3717
int count
Definition ampiFunctions.hpp:3716
const DATATYPE::Type * buf
Definition ampiFunctions.hpp:3714
Definition async.hpp:92
AMPI_Request requestReverse
Definition async.hpp:95
Definition async.hpp:101
AsyncAdjointHandle * toolHandle
Definition async.hpp:103
Definition typeDefinitions.h:53
PrimalFunction funcPrimal
Definition typeDefinitions.h:56
ReverseFunction funcReverse
Definition typeDefinitions.h:54
ForwardFunction funcForward
Definition typeDefinitions.h:55
Definition async.hpp:111