File indexing completed on 2023-05-28 05:10:53 UTC
view on githubraw file Latest commit b4daa243 on 2023-05-28 03:53:22 UTC
b4daa24319 Shre*0001 /*
0002 ##########################################################
0003 # This file is part of the AdjoinableMPI library #
0004 # released under the MIT License. #
0005 # The full COPYRIGHT notice can be found in the top #
0006 # level directory of the AdjoinableMPI distribution. #
0007 ##########################################################
0008
0009 #ifndef _AMPI_ADTOOL_SUPPORT_H_
0010 #define _AMPI_ADTOOL_SUPPORT_H_
0011
0012 #include <mpi.h>
0013 #if defined(__cplusplus)
0014 extern "C" {
0015 #endif
0016
0017 #include "ampi/userIF/request.h"
0018 #include "ampi/userIF/activity.h"
0019 #include "ampi/userIF/modified.h"
0020
0021 /**
0022 * \file
0023 * \brief methods that an AD tool needs to implement in order to use the implementation in Common
0024 */
0025
0026 /**
0027 * The implementation of pushing the required elements for Bcast calls.
0028 * Might rework for conciseness. Wrote this to avoid pushing too much stuff with _pushSRinfo.
0029 */
0030 void ADTOOL_AMPI_pushBcastInfo(void* buf,
0031 int count,
0032 MPI_Datatype datatype,
0033 int root,
0034 MPI_Comm comm);
0035 typedef void (ADTOOL_AMPI_pushBcastInfoF) (void*,int, MPI_Datatype, int, MPI_Comm);
0036
0037
0038 /**
0039 * Popping the required elements for Bcast calls.
0040 */
0041 void ADTOOL_AMPI_popBcastInfo(void** buf,
0042 int* count,
0043 MPI_Datatype* datatype,
0044 int* root,
0045 MPI_Comm* comm,
0046 void **idx);
0047 typedef void (ADTOOL_AMPI_popBcastInfoF) (void**, int*, MPI_Datatype*, int*, MPI_Comm*, void**);
0048
0049
0050 /**
0051 * Pushing and popping a block of double values, specifically for reduction results.
0052 */
0053 void ADTOOL_AMPI_pushDoubleArray(void* buf,
0054 int count);
0055 typedef void (ADTOOL_AMPI_pushDoubleArrayF) (void*, int);
0056
0057 void ADTOOL_AMPI_popDoubleArray(double* buf,
0058 int* count);
0059 typedef void (ADTOOL_AMPI_popDoubleArrayF) (double*, int*);
0060
0061 /**
0062 * The implementation of pushing the required elements for Reduce calls.
0063 * Might rework for conciseness. Note that we require a separate TAPE_AMPI_push_MPI_Op
0064 * function to push the reduce operation. I defined _push_MPI_Op in
0065 * AdjoinableMPI/Tape/support.c w/ header AdjoinableMPI/ampi/tape/support.h.
0066 */
0067 void ADTOOL_AMPI_pushReduceInfo(void* sbuf,
0068 void* rbuf,
0069 void* resultData,
0070 int pushResultData,
0071 int count,
0072 MPI_Datatype datatype,
0073 MPI_Op op,
0074 int root,
0075 MPI_Comm comm);
0076 typedef void (ADTOOL_AMPI_pushReduceInfoF) (void*, void*, void*, int, int, MPI_Datatype, MPI_Op, int, MPI_Comm);
0077
0078 /**
0079 * Popping the required elements for Reduce calls.
0080 */
0081 void ADTOOL_AMPI_popReduceCountAndType(int* count,
0082 MPI_Datatype* datatype);
0083 typedef void (ADTOOL_AMPI_popReduceCountAndTypeF) (int*, MPI_Datatype*);
0084
0085 void ADTOOL_AMPI_popReduceInfo(void** sbuf,
0086 void** rbuf,
0087 void** prevData,
0088 void** resultData,
0089 int* count,
0090 MPI_Op* op,
0091 int* root,
0092 MPI_Comm* comm,
0093 void **idx);
0094 typedef void (ADTOOL_AMPI_popReduceInfoF) (void**, void**, void**, void**, int*, MPI_Op*, int*, MPI_Comm*, void **);
0095
0096
0097 /**
0098 * the implementation of pushing the required elements for send/recv
0099 * to the AD-tool-internal stack;
0100 * For source transformation this may remain unimplemented provided all the parameters
0101 * are recovered by TBR and <tt>buf</tt> is mapped explicitly.
0102 * the operator overloading implementation maps <tt>buf</tt> to the adjoint address space.
0103 * The source transformation implementation ignores <tt>buf</tt>
0104 */
0105 void ADTOOL_AMPI_pushSRinfo(void* buf,
0106 int count,
0107 MPI_Datatype datatype,
0108 int src,
0109 int tag,
0110 AMPI_PairedWith pairedWith,
0111 MPI_Comm comm);
0112 typedef void (ADTOOL_AMPI_pushSRinfoF) (void*, int, MPI_Datatype, int, int, AMPI_PairedWith, MPI_Comm);
0113
0114 /**
0115 * the implementation of popping the required elements for send/recv
0116 * from the AD-tool-internal stack;
0117 * See comments of \ref ADTOOL_AMPI_pushSRinfo.
0118 */
0119 void ADTOOL_AMPI_popSRinfo(void** buf,
0120 int* count,
0121 MPI_Datatype* datatype,
0122 int* src,
0123 int* tag,
0124 AMPI_PairedWith* pairedWith,
0125 MPI_Comm* comm,
0126 void **idx);
0127 typedef void (ADTOOL_AMPI_popSRinfoF) (void**, int*, MPI_Datatype*, int*, int*, AMPI_PairedWith*, MPI_Comm*, void**);
0128
0129 /**
0130 * the implementation of pushing the required elements for one-sided
0131 * communication
0132 * to the AD-tool-internal stack;
0133 * For source transformation this may remain unimplemented provided all the parameters
0134 * are recovered by TBR and <tt>buf</tt> is mapped explicitly.
0135 * the operator overloading implementation maps <tt>buf</tt> to the adjoint address space.
0136 * The source transformation implementation ignores <tt>buf</tt>
0137 */
0138 void ADTOOL_AMPI_pushOSinfo(void* buf,
0139 int count,
0140 MPI_Datatype datatype,
0141 int src,
0142 int tag,
0143 AMPI_PairedWith pairedWith,
0144 MPI_Comm comm);
0145 typedef void (ADTOOL_AMPI_pushOSinfoF) (void*, int, MPI_Datatype, int, int, AMPI_PairedWith, MPI_Comm);
0146
0147 /**
0148 * the implementation of popping the required elements for one-sided
0149 * communication
0150 * from the AD-tool-internal stack;
0151 * See comments of \ref ADTOOL_AMPI_pushOSinfo.
0152 */
0153 void ADTOOL_AMPI_popOSinfo(void** buf,
0154 int* count,
0155 MPI_Datatype* datatype,
0156 int* src,
0157 int* tag,
0158 AMPI_PairedWith* pairedWith,
0159 MPI_Comm* comm,
0160 void **idx);
0161 typedef void (ADTOOL_AMPI_popOSinfoF) (void**, int*, MPI_Datatype*, int*, int*, AMPI_PairedWith*, MPI_Comm*, void**);
0162
0163 /**
0164 * the implementation of pushing the required elements for gather/scatter
0165 * to the AD-tool-internal stack;
0166 * the implementation rationale follows \ref ADTOOL_AMPI_pushSRinfo
0167 * NOTE: for non-root ranks the root specific parameters are ignored
0168 * which implies in particular that the pointers passed may not be valid
0169 * therefore we use commSizeForRootOrNull to discriminate
0170 * \param commSizeForRootOrNull is the communicator size for rank root or 0
0171 * \param rbuf the buffer on rank root
0172 * \param rcnt the count on rank root
0173 * \param rtype the data type on rank root
0174 * \param buf the buffer on non-root ranks
0175 * \param count the counter for buf on non-root ranks
0176 * \param type the data type on non-root ranks
0177 * \param root the root rank
0178 * \param comm the communicator
0179 */
0180 void ADTOOL_AMPI_pushGSinfo(int commSizeForRootOrNull,
0181 void *rbuf,
0182 int rcnt,
0183 MPI_Datatype rtype,
0184 void *buf,
0185 int count,
0186 MPI_Datatype type,
0187 int root,
0188 MPI_Comm comm);
0189 typedef void (ADTOOL_AMPI_pushGSinfoF) (int, void*, int, MPI_Datatype, void*, int, MPI_Datatype, int, MPI_Comm);
0190
0191 /**
0192 * this must be called before \ref ADTOOL_AMPI_popGSinfo and \ref ADTOOL_AMPI_popGSVinfo
0193 * \param commSizeForRootOrNull this is popped so that we may allocate buffers for
0194 * rcnts and displs in the subsequent call to \ref ADTOOL_AMPI_popGSVinfo
0195 */
0196 void ADTOOL_AMPI_popGScommSizeForRootOrNull(int *commSizeForRootOrNull);
0197 typedef void (ADTOOL_AMPI_popGScommSizeForRootOrNullF) (int*);
0198
0199 /**
0200 * the implementation of popping the required elements for gather/scatter
0201 * from the AD-tool-internal stack;
0202 * see comments of \ref ADTOOL_AMPI_pushGSinfo;
0203 * following the note there we will not be setting the values for root specific
0204 * arguments on non-root ranks
0205 * \param commSizeForRootOrNull retrieved via \ref ADTOOL_AMPI_popGScommSizeForRootOrNull
0206 * \param rbuf the buffer on rank rook, set if commSizeForRootOrNull>0
0207 * \param rcnt the size for rank root, set if commSizeForRootOrNull>0
0208 * \param rtype the data type for rank root, set if commSizeForRootOrNull>0
0209 * \param buf the buffer for all ranks
0210 * \param count the count for all ranks
0211 * \param type the type for all ranks
0212 * \param root the root rank
0213 * \param comm the communicator for all ranks
0214 */
0215 void ADTOOL_AMPI_popGSinfo(int commSizeForRootOrNull,
0216 void **rbuf,
0217 int *rcnt,
0218 MPI_Datatype *rtype,
0219 void **buf,
0220 int *count,
0221 MPI_Datatype *type,
0222 int *root,
0223 MPI_Comm *comm);
0224 typedef void (ADTOOL_AMPI_popGSinfoF) (int, void**, int*, MPI_Datatype*, void**, int*, MPI_Datatype*, int*, MPI_Comm*);
0225
0226 /**
0227 * the implementation of pushing the required elements for gatherv/scatterv
0228 * to the AD-tool-internal stack;
0229 * the implementation rationale follows \ref ADTOOL_AMPI_pushSRinfo
0230 * NOTE: for non-root ranks the root specific parameters are ignored
0231 * which implies in particular that the pointers passed may not be valid
0232 * therefore we use commSizeForRootOrNull to discriminate
0233 * \param commSizeForRootOrNull is the communicator size for rank root or 0
0234 * \param rbuf the buffer on rank root
0235 * \param rcnts the counters per rank on rank root
0236 * \param displs the displacements for rbuf on rank root
0237 * \param rtype the data type on rank root
0238 * \param buf the buffer on non-root ranks
0239 * \param count the counter for buf on non-root ranks
0240 * \param type the data type on non-root ranks
0241 * \param root the root rank
0242 * \param comm the communicator
0243 */
0244 void ADTOOL_AMPI_pushGSVinfo(int commSizeForRootOrNull,
0245 void *rbuf,
0246 int *rcnts,
0247 int *displs,
0248 MPI_Datatype rtype,
0249 void *buf,
0250 int count,
0251 MPI_Datatype type,
0252 int root,
0253 MPI_Comm comm);
0254 typedef void (ADTOOL_AMPI_pushGSVinfoF) (int, void*, int*, int*, MPI_Datatype, void*, int, MPI_Datatype, int, MPI_Comm);
0255
0256 /**
0257 * the implementation of popping the required elements for gatherv/scatterv
0258 * from the AD-tool-internal stack;
0259 * see comments of \ref ADTOOL_AMPI_pushGSVinfo;
0260 * following the note there we will not be setting the values for root specific
0261 * arguments on non-root ranks
0262 * \param commSizeForRootOrNull retrieved via \ref ADTOOL_AMPI_popGScommSizeForRootOrNull
0263 * \param rbuf the buffer on rank rook, set if commSizeForRootOrNull>0
0264 * \param rcnts the array of size commSizeForRootOrNull for rank root, set if commSizeForRootOrNull>0
0265 * \param displs the array of size commSizeForRootOrNull for rank root, set if commSizeForRootOrNull>0
0266 * \param rtype the data type for rank root, set if commSizeForRootOrNull>0
0267 * \param buf the buffer for all ranks
0268 * \param count the count for all ranks
0269 * \param type the type for all ranks
0270 * \param root the root rank
0271 * \param comm the communicator for all ranks
0272 */
0273 void ADTOOL_AMPI_popGSVinfo(int commSizeForRootOrNull,
0274 void **rbuf,
0275 int *rcnts,
0276 int *displs,
0277 MPI_Datatype *rtype,
0278 void **buf,
0279 int *count,
0280 MPI_Datatype *type,
0281 int *root,
0282 MPI_Comm *comm);
0283 typedef void (ADTOOL_AMPI_popGSVinfoF) (int, void**, int*, int*, MPI_Datatype*, void**, int*, MPI_Datatype*, int*, MPI_Comm*);
0284
0285 /**
0286 * the implementation of pushing an operation code to the
0287 * to the AD-tool-internal stack for an operator overloading tool;
0288 * the source transformation implementation will leave this empty;
0289 * this method is called in the respective <tt>FW_</tt> variant
0290 * implemented in <tt>Common</tt>
0291 */
0292 void ADTOOL_AMPI_push_CallCode(enum AMPI_CallCode_E thisCall);
0293 typedef void (ADTOOL_AMPI_push_CallCodeF) (enum AMPI_CallCode_E);
0294
0295 /**
0296 * the implementation of pushing an operation code to the
0297 * to the AD-tool-internal stack for an operator overloading tool where a number
0298 * of locations have to be reserved on the trace, currently only called in
0299 * Scatterv and Gatherv;
0300 * the source transformation implementation will leave this empty;
0301 * this method is called in the respective <tt>FW_</tt> variant
0302 * implemented in <tt>Common</tt>
0303 */
0304 void ADTOOL_AMPI_push_CallCodeReserve(enum AMPI_CallCode_E thisCall, unsigned int);
0305 typedef void (ADTOOL_AMPI_push_CallCodeReserveF) (enum AMPI_CallCode_E, unsigned int);
0306
0307 /**
0308 * the implementation of popping an operation code from the
0309 * to the AD-tool-internal stack for an operator overloading tool;
0310 * See comments of \ref ADTOOL_AMPI_push_CallCode.
0311 * the operator overloading tool needs to pop the code from its operation
0312 * stack first and then call (with dummy parameters) the respect <tt>BW_</tt>
0313 * variant of the operatiorn represented by <tt>thisCall</tt>
0314 */
0315 void ADTOOL_AMPI_pop_CallCode(enum AMPI_CallCode_E *thisCall);
0316 typedef void (ADTOOL_AMPI_pop_CallCodeF) (enum AMPI_CallCode_E*);
0317
0318
0319
0320 /**
0321 * the implementation of pushing the required elements of an \ref AMPI_Request_S
0322 * to the AD-tool-internal stack
0323 */
0324 void ADTOOL_AMPI_push_AMPI_Request(struct AMPI_Request_S *ampiRequest);
0325 typedef void (ADTOOL_AMPI_push_AMPI_RequestF) (struct AMPI_Request_S*);
0326
0327 /**
0328 * the implementation of popping the required elements of an \ref AMPI_Request_S
0329 * from the AD-tool-internal stack
0330 */
0331 void ADTOOL_AMPI_pop_AMPI_Request(struct AMPI_Request_S *ampiRequest);
0332 typedef void (ADTOOL_AMPI_pop_AMPI_RequestF) (struct AMPI_Request_S*);
0333
0334
0335 /**
0336 * Push the MPI_Request on the AD tool internal stack.
0337 * This is used as a key to the request bookkeeping
0338 * to keep correspondence between the request Id of the FW sweep
0339 * to the request Id in BW sweep.
0340 * if we need to trace requests for a pure (operator overloading) trace evaluation
0341 * the Common implementation uses this to push the request
0342 * See \ref bookkeeping.
0343 */
0344 void ADTOOL_AMPI_push_request(MPI_Request request);
0345 typedef void (ADTOOL_AMPI_push_requestF) (MPI_Request);
0346
0347
0348 /**
0349 * Push a window request for one-sided communication using a specific window
0350 */
0351 void ADTOOL_AMPI_push_AMPI_WinRequest(AMPI_WinRequest *winRequest);
0352 typedef void (ADTOOL_AMPI_push_WinRequestF) (AMPI_WinRequest*);
0353
0354 /**
0355 * Pop a window request for one-sided communication using a specific window
0356 */
0357 void ADTOOL_AMPI_pop_AMPI_WinRequest(AMPI_WinRequest *winRequest);
0358 typedef void (ADTOOL_AMPI_pop_WinRequestF) (AMPI_WinRequest*);
0359
0360 /**
0361 * Push a window for one-sided communication using a specific window
0362 */
0363 void ADTOOL_AMPI_push_AMPI_Win(AMPI_Win *win);
0364 typedef void (ADTOOL_AMPI_push_AMPI_WinF) (AMPI_Win*);
0365
0366 /**
0367 * Pop a window for one-sided communication using a specific window
0368 */
0369 void ADTOOL_AMPI_pop_AMPI_Win(AMPI_Win *win);
0370 typedef void (ADTOOL_AMPI_pop_AMPI_WinF) (AMPI_Win*);
0371
0372 /**
0373 * the companion to \ref ADTOOL_AMPI_push_request.
0374 * See \ref bookkeeping.
0375 */
0376 MPI_Request ADTOOL_AMPI_pop_request();
0377 typedef MPI_Request (ADTOOL_AMPI_pop_requestF) ();
0378
0379 void ADTOOL_AMPI_push_comm(MPI_Comm comm);
0380 typedef void (ADTOOL_AMPI_push_commF) (MPI_Comm);
0381
0382 /**
0383 * the companion to \ref ADTOOL_AMPI_push_request
0384 */
0385 MPI_Comm ADTOOL_AMPI_pop_comm();
0386 typedef MPI_Comm (ADTOOL_AMPI_pop_commF) ();
0387
0388 /**
0389 * map active data to raw data; this is to be implemented for the forward
0390 * execution by tools using association-by-address;
0391 * for tools using association-by-name the same address should be returned;
0392 */
0393 void * ADTOOL_AMPI_rawData(void* activeData, int *size);
0394 typedef void* (ADTOOL_AMPI_rawDataF) (void*, int*);
0395
0396 /**
0397 * map active data to raw data; functionality similar to \ref ADTOOL_AMPI_rawData
0398 * except it is handling vector buffers with arrays of counts and displacements as
0399 * used in MPI_Gatherv or MPI_Scatterv
0400 */
0401 void * ADTOOL_AMPI_rawDataV(void* activeData, int commSize, int *counts, int* displs);
0402 typedef void * (ADTOOL_AMPI_rawDataVF) (void*, int, int*, int*);
0403
0404 /**
0405 * serialize user-defined struct for sending in forward execution in
0406 * association-by-address tools
0407 */
0408 void * ADTOOL_AMPI_packDType(void* indata, void* outdata, int count, int idx);
0409 typedef void * (ADTOOL_AMPI_packDTypeF) (void*, void*, int, int);
0410
0411 /**
0412 * unpack serialized user-defined struct data into its original form
0413 */
0414 void * ADTOOL_AMPI_unpackDType(void* indata, void* outdata, int count, int idx);
0415 typedef void * (ADTOOL_AMPI_unpackDTypeF) (void*, void*, int, int);
0416
0417 /**
0418 * \todo add description
0419 */
0420 void ADTOOL_AMPI_writeData(void* activeData, int *size);
0421 typedef void (ADTOOL_AMPI_writeDataF) (void*, int*);
0422
0423 /**
0424 * \todo add description
0425 */
0426 void ADTOOL_AMPI_writeDataV(void* activeData, int *counts, int* displs);
0427 typedef void (ADTOOL_AMPI_writeDataVF) (void*, int*, int*);
0428
0429 /**
0430 * map active data to adjoint data; this is to be implemented for the backward
0431 * execution by tools using association-by-address;
0432 * for tools using association-by-name the same address should be returned;
0433 */
0434 void * ADTOOL_AMPI_rawAdjointData(void* activeData);
0435 typedef void * (ADTOOL_AMPI_rawAdjointDataF) (void*);
0436
0437 /**
0438 * Declares correspondence between a buffer and its counterpart adjoint buffer
0439 * Adds correspondence into the request-to-buffer association list
0440 * This is necessary for association-by-name transfo tools.
0441 * should be done upon turn from FW sweep to BW sweep.
0442 * \param buf the original, non-differentiated buffer.
0443 * \param adjointBuf the corresponding adjoint buffer.
0444 */
0445 void ADTOOL_AMPI_Turn(void* buf, void* adjointBuf) ;
0446 typedef void (ADTOOL_AMPI_TurnF) (void*, void*) ;
0447
0448 /**
0449 * set it on the request;
0450 * \param buf is forward sweep buffer (for source transformation tools)
0451 * \param ampiRequest is the request to be pushed and popped for the adjoint communication
0452 */
0453 void ADTOOL_AMPI_mapBufForAdjoint(struct AMPI_Request_S *ampiRequest,
0454 void* buf);
0455 typedef void (ADTOOL_AMPI_mapBufForAdjointF) (struct AMPI_Request_S*, void*);
0456
0457 /**
0458 * Map buffer in a one-sided communication
0459 */
0460
0461 void ADTOOL_AMPI_mapWinBufForAdjoint(AMPI_WinRequest *winRequest,
0462 void* buf);
0463 typedef void (ADTOOL_AMPI_mapWinBufForAdjointF) (AMPI_WinRequest*, void*);
0464
0465 /**
0466 * an operator overloading tool should not do anything in the implementation but see \ref ADTOOL_AMPI_mapBufForAdjoint;
0467 * a source transformation tool would receive the adjoint buffer as an argument
0468 * and set it on the request;
0469 * \param buf is the adjoint buffer (for source transformation tools)
0470 * \param ampiRequest is the request to be used during the adjoint communication
0471 */
0472 void ADTOOL_AMPI_setBufForAdjoint(struct AMPI_Request_S *ampiRequest,
0473 void* buf);
0474 typedef void (ADTOOL_AMPI_setBufForAdjointF) (struct AMPI_Request_S *, void*);
0475
0476 /**
0477 * this method resets \param count member to represent the buffer in terms of
0478 * elements of the original MPI \param datatype; this is of particular interest for vector mode;
0479 * \todo needs to be expanded for the case where the adjoint data is not represented by the same MPI data type as the
0480 * original program data
0481 */
0482 void ADTOOL_AMPI_getAdjointCount(int *count,
0483 MPI_Datatype datatype);
0484 typedef void (ADTOOL_AMPI_getAdjointCountF) (int*, MPI_Datatype);
0485
0486 /**
0487 * \param ampiRequest in this instance this method resets the <tt>adjointCount</tt> member;
0488 */
0489 void ADTOOL_AMPI_setAdjointCount(struct AMPI_Request_S *ampiRequest);
0490 typedef void (ADTOOL_AMPI_setAdjointCountF) (struct AMPI_Request_S *);
0491
0492 /**
0493 * calls \ref ADTOOL_AMPI_setAdjointCount and sets up a temporary buffer into which the adjoint data is received, see e.g. \ref BW_AMPI_Wait
0494 * \param ampiRequest is the request instance that is modified
0495 */
0496 void ADTOOL_AMPI_setAdjointCountAndTempBuf(struct AMPI_Request_S *ampiRequest);
0497 typedef void (ADTOOL_AMPI_setAdjointCountAndTempBufF) (struct AMPI_Request_S*);
0498
0499 /**
0500 * \param winRequest in this instance this method resets the <tt>adjointCount</tt> member;
0501 */
0502 void ADTOOL_AMPI_setWinAdjointCount(AMPI_WinRequest *winRequest);
0503 typedef void (ADTOOL_AMPI_setWinAdjointCountF) (AMPI_WinRequest *);
0504
0505 /**
0506 * calls \ref ADTOOL_AMPI_setAdjointCount and sets up a temporary buffer into which the adjoint data is received, see e.g. \ref BW_AMPI_Win_fence
0507 * \param winRequest is the request instance that is modified
0508 */
0509 void ADTOOL_AMPI_setWinAdjointCountAndTempBuf(AMPI_WinRequest *winRequest);
0510 typedef void (ADTOOL_AMPI_setWinAdjointCountAndTempBufF) (AMPI_WinRequest *);
0511
0512 /**
0513 * synchronizes the window with incoming adjoints, applies the corresponding
0514 * increments and nullifies the adjoints in the window.
0515 * \param win is the AMPI_Win instance providing the window for the incoming
0516 * adjoints
0517 */
0518 void ADTOOL_AMPI_syncAdjointWin(AMPI_Win *win);
0519 typedef void (ADTOOL_AMPI_syncAdjointWinF) (AMPI_Win *);
0520
0521 /**
0522 * Allocates a temporary buffer needed to receive adjoint
0523 * data before adding it to the adjoint variable
0524 */
0525 void* ADTOOL_AMPI_allocateTempBuf(int adjointCount, MPI_Datatype dataType, MPI_Comm comm) ;
0526 typedef void* (ADTOOL_AMPI_allocateTempBufF) (int, MPI_Datatype, MPI_Comm) ;
0527
0528 /**
0529 * releases the temporary buffer (allocated by \ref ADTOOL_AMPI_setAdjointCountAndTempBuf) into which the adjoint data was received
0530 */
0531 void ADTOOL_AMPI_releaseAdjointTempBuf(void *tempBuf);
0532 typedef void (ADTOOL_AMPI_releaseAdjointTempBufF) (void *);
0533
0534 /**
0535 * allocates buffer with active variables (needed as a temporary in Reduce)
0536 */
0537 void* ADTOOL_AMPI_allocateTempActiveBuf(int count, MPI_Datatype datatype, MPI_Comm comm);
0538 typedef void* (ADTOOL_AMPI_allocateTempActiveBufF) (int, MPI_Datatype, MPI_Comm);
0539
0540 /**
0541 * releases buffer with active variables (used as a temporary in Reduce)
0542 */
0543 void ADTOOL_AMPI_releaseTempActiveBuf(void *buf, int count, MPI_Datatype datatype);
0544 typedef void (ADTOOL_AMPI_releaseTempActiveBufF) (void *, int, MPI_Datatype);
0545
0546 /**
0547 * copies contents of buffer including real values of active variables
0548 */
0549 void * ADTOOL_AMPI_copyActiveBuf(void* source, void* target, int count, MPI_Datatype datatype, MPI_Comm comm);
0550 typedef void* (ADTOOL_AMPI_copyActiveBufF) (void*, void*, int, MPI_Datatype, MPI_Comm);
0551
0552 /**
0553 * Adjoint of assignment target=source*target
0554 */
0555 void ADTOOL_AMPI_adjointMultiply(int count, MPI_Datatype datatype, MPI_Comm comm,
0556 void *source, void *adjointSource,
0557 void* target, void* adjointTarget) ;
0558 typedef void (ADTOOL_AMPI_adjointMultiplyF) (int, MPI_Datatype, MPI_Comm, void*, void*, void*, void*);
0559
0560 /**
0561 * Adjoint of assignment target=MIN(source,target)
0562 */
0563 void ADTOOL_AMPI_adjointMin(int count, MPI_Datatype datatype, MPI_Comm comm,
0564 void *source, void *adjointSource,
0565 void* target, void* adjointTarget) ;
0566 typedef void (ADTOOL_AMPI_adjointMinF) (int, MPI_Datatype, MPI_Comm, void*, void*, void*, void*);
0567
0568 /**
0569 * Adjoint of assignment target=MAX(source,target)
0570 */
0571 void ADTOOL_AMPI_adjointMax(int count, MPI_Datatype datatype, MPI_Comm comm,
0572 void *source, void *adjointSource,
0573 void* target, void* adjointTarget) ;
0574 typedef void (ADTOOL_AMPI_adjointMaxF) (int, MPI_Datatype, MPI_Comm, void*, void*, void*, void*);
0575
0576 /**
0577 * Multiply the given buffer target, which holds an adjoint, with the given source value
0578 * \param adjointCount is the number of items in the buffer we will increment
0579 * \param datatype the data type of the buffer to be incremented
0580 * \param comm the communicator to be passed to MPI_Abort for failures
0581 * \param target the adjoint buffer to be multiplied
0582 * \param source the value to multiply by.
0583 * \param idx tape index for each element of the non contiguous buffer
0584 */
0585 void ADTOOL_AMPI_multiplyAdjoint(int adjointCount, MPI_Datatype datatype, MPI_Comm comm, void* target, void *source, void* idx);
0586 typedef void (ADTOOL_AMPI_multiplyAdjointF)(int, MPI_Datatype, MPI_Comm, void*, void*, void*);
0587
0588 /**
0589 * Divide the given buffer target, which holds an adjoint, with the given source value
0590 * \param adjointCount is the number of items in the buffer we will increment
0591 * \param datatype the data type of the buffer to be incremented
0592 * \param comm the communicator to be passed to MPI_Abort for failures
0593 * \param target the adjoint buffer to be divided
0594 * \param source the value to divide by.
0595 * \param idx tape index for each element of the non contiguous buffer
0596 */
0597 void ADTOOL_AMPI_divideAdjoint(int adjointCount, MPI_Datatype datatype, MPI_Comm comm, void* target, void *source, void* idx);
0598 typedef void (ADTOOL_AMPI_divideAdjointF) (int, MPI_Datatype, MPI_Comm, void*, void*, void*);
0599
0600 /**
0601 * Check equality of the given buffers source1 and source2, which hold adjoints,
0602 * and return the result in the given target buffer.
0603 * \param adjointCount is the number of items in the buffer we will increment
0604 * \param datatype the data type of the buffer to be incremented
0605 * \param comm the communicator to be passed to MPI_Abort for failures
0606 * \param target the buffer that will hold the result (0==difference)
0607 * \param source1 the one buffer to compare
0608 * \param source2 the other buffer to compare
0609 * \param idx tape index for each element of the non contiguous buffer
0610 */
0611 void ADTOOL_AMPI_equalAdjoints(int adjointCount, MPI_Datatype datatype, MPI_Comm comm, void* target, void *source1, void *source2, void* idx);
0612 typedef void (ADTOOL_AMPI_equalAdjointsF) (int, MPI_Datatype, MPI_Comm, void*, void*, void*, void*);
0613
0614 /**
0615 * Increment the given buffer "target", which holds an adjoint variable,
0616 * with the given additional adjoint value found in "source".
0617 * \param adjointCount is the number of items in the buffer we will increment
0618 * \param datatype the data type of the buffer to be incremented
0619 * \param comm the communicator to be passed to MPI_Abort for failures
0620 * \param target the adjoint buffer to be incremented
0621 * \param source the adjoint value that must be added into the adjoint buffer.
0622 * \param idx tape index for each element of the non contiguous buffer
0623 */
0624 void ADTOOL_AMPI_incrementAdjoint(int adjointCount, MPI_Datatype datatype, MPI_Comm comm, void* target, void *source, void* idx);
0625 typedef void (ADTOOL_AMPI_incrementAdjointF) (int, MPI_Datatype, MPI_Comm, void*, void*, void*);
0626
0627 /**
0628 * Reset to zero the given buffer "target", which holds an adjoint variable.
0629 * \param adjointCount is the number of items in the buffer we will nullify
0630 * \param datatype the data type of the buffer to be nullified
0631 * \param comm the communicator to be passed to MPI_Abort for failures
0632 * \param target the adjoint buffer to be nullified
0633 */
0634 void ADTOOL_AMPI_nullifyAdjoint(int adjointCount, MPI_Datatype datatype, MPI_Comm comm, void* target);
0635 typedef void (ADTOOL_AMPI_nullifyAdjointF) (int, MPI_Datatype, MPI_Comm, void*);
0636
0637 /**
0638 * create predefined active types; to be cleaned up with \ref ADTOOL_AMPI_cleanupTypes
0639 */
0640 void ADTOOL_AMPI_setupTypes();
0641 typedef void (ADTOOL_AMPI_setupTypesF)();
0642
0643 /**
0644 * cleanup types created with \ref ADTOOL_AMPI_setupTypes
0645 */
0646 void ADTOOL_AMPI_cleanupTypes();
0647 typedef void (ADTOOL_AMPI_cleanupTypesF)();
0648
0649 #ifdef AMPI_FORTRANCOMPATIBLE
0650 /**
0651 * Fortran routine to figure out what the proper types are on the Fortran side
0652 * \param adouble returns the integer representation for the Fortran version of AMPI_ADOUBLE_PRECISION
0653 * \param real returns the integer representation for the Fortran version of AMPI_AREAL
0654 */
0655 void adtool_ampi_fortransetuptypes_(MPI_Fint* adouble, MPI_Fint* areal);
0656 typedef void (adtool_ampi_fortransetuptypes_F) (MPI_Fint*, MPI_Fint*);
0657
0658 void adtool_ampi_fortrancleanuptypes_(MPI_Fint* adouble, MPI_Fint* areal);
0659 typedef void (adtool_ampi_fortrancleanuptypes_F) (MPI_Fint*, MPI_Fint*);
0660
0661 /**
0662 * Fortran routine to ask Fortran to tell the C side about the Fortran-side values of the
0663 * "binding" variables i.e. MPI_IN_PLACE, MPI_BOTTOM, etc.
0664 */
0665 void adtool_ampi_fortransetupbindings_() ;
0666
0667 #endif
0668
0669 /**
0670 * Take datatype for forward mode, return datatype for transfer.
0671 */
0672 MPI_Datatype ADTOOL_AMPI_FW_rawType(MPI_Datatype datatype);
0673 typedef MPI_Datatype (ADTOOL_AMPI_FW_rawTypeF) (MPI_Datatype);
0674
0675 /**
0676 * Take datatype for reverse mode, return datatype for transfer.
0677 */
0678 MPI_Datatype ADTOOL_AMPI_BW_rawType(MPI_Datatype datatype);
0679 typedef MPI_Datatype (ADTOOL_AMPI_BW_rawTypeF) (MPI_Datatype);
0680
0681
0682 /**
0683 * test types for activity
0684 * \param datatype any data type but particularly also the active data type(s) created by the tool (see \ref AMPI_ADOUBLE etc.)
0685 * \returns the respective enum value based on the type's activity
0686 */
0687 AMPI_Activity ADTOOL_AMPI_isActiveType(MPI_Datatype datatype);
0688 typedef AMPI_Activity (ADTOOL_AMPI_isActiveTypeF) (MPI_Datatype);
0689
0690 /** The global MPI_COMM_WORLD_D */
0691 extern MPI_Comm ADTOOL_AMPI_COMM_WORLD_SHADOW;
0692
0693 /**
0694 * Maps the active buffer on a mapped buffer for a MPI_Win
0695 */
0696
0697 void *ADTOOL_AMPI_createWinMap(void *active_buf, MPI_Aint size);
0698 typedef void *(ADTOOL_AMPI_createWinMapF) (void *active_buf, MPI_Aint size);
0699
0700 /**
0701 * Maps the active buffer on a mapped buffer for a MPI_Win
0702 */
0703
0704 void ADTOOL_AMPI_writeWinData(void *map, void *buf, MPI_Aint size);
0705 typedef void (ADTOOL_AMPI_writeWinDataF) (void *map, void *buf, MPI_Aint size);
0706
0707 /**
0708 * Gets the size of the mapped buffer for a window at its creation. It returns
0709 * the size of the mapped window (may be equal to the active window).
0710 * \param size of the active window.
0711 */
0712
0713 MPI_Aint ADTOOL_AMPI_getWinSize(MPI_Aint size);
0714 typedef MPI_Aint (ADTOOL_AMPI_getWinSizeF) (MPI_Aint size);
0715 /** The functions that perform the tangent of standard reduction operations: */
0716 void ADTOOL_AMPI_tangentMultiply(int count, MPI_Datatype datatype, MPI_Comm comm,
0717 void* target, void* tangentTarget,
0718 void *source, void *tangentSource) ;
0719 typedef void (ADTOOL_AMPI_tangentMultiplyF) (int, MPI_Datatype, MPI_Comm, void*, void*, void*, void*) ;
0720 void ADTOOL_AMPI_tangentMin(int count, MPI_Datatype datatype, MPI_Comm comm,
0721 void* target, void* tangentTarget,
0722 void *source, void *tangentSource) ;
0723 typedef void (ADTOOL_AMPI_tangentMinF) (int, MPI_Datatype, MPI_Comm, void*, void*, void*, void*) ;
0724 void ADTOOL_AMPI_tangentMax(int count, MPI_Datatype datatype, MPI_Comm comm,
0725 void* target, void* tangentTarget,
0726 void *source, void *tangentSource) ;
0727 typedef void (ADTOOL_AMPI_tangentMaxF) (int, MPI_Datatype, MPI_Comm, void*, void*, void*, void*) ;
0728
0729 /**
0730 * Push/Pop the contents of buffer somewhere
0731 */
0732 void ADTOOL_AMPI_pushBuffer(int count, MPI_Datatype datatype, MPI_Comm comm, void* buffer) ;
0733 typedef void (ADTOOL_AMPI_pushBufferF) (int, MPI_Datatype, MPI_Comm, void*) ;
0734 void ADTOOL_AMPI_popBuffer(int count, MPI_Datatype datatype, MPI_Comm comm, void* buffer) ;
0735 typedef void (ADTOOL_AMPI_popBufferF) (int, MPI_Datatype, MPI_Comm, void*) ;
0736
0737 /** Memo mechanism for the shadow communicators used in tangent ST-AD association-by-name (e.g. Tapenade) */
0738 void ADTOOL_AMPI_addShadowComm(MPI_Comm comm, MPI_Comm dupComm) ;
0739 typedef void (ADTOOL_AMPI_addShadowCommF) (MPI_Comm, MPI_Comm) ;
0740 MPI_Comm ADTOOL_AMPI_getShadowComm(MPI_Comm comm) ;
0741 typedef MPI_Comm (ADTOOL_AMPI_getShadowCommF) (MPI_Comm) ;
0742 void ADTOOL_AMPI_delShadowComm(MPI_Comm comm);
0743 typedef void (ADTOOL_AMPI_delShadowCommF) (MPI_Comm) ;
0744
0745 struct ADTOOL_AMPI_FPCollection{
0746 ADTOOL_AMPI_pushBcastInfoF *pushBcastInfo_fp;
0747 ADTOOL_AMPI_popBcastInfoF *popBcastInfo_fp;
0748 ADTOOL_AMPI_pushDoubleArrayF *pushDoubleArray_fp;
0749 ADTOOL_AMPI_popDoubleArrayF *popDoubleArray_fp;
0750 ADTOOL_AMPI_pushReduceInfoF *pushReduceInfo_fp;
0751 ADTOOL_AMPI_popReduceCountAndTypeF *popReduceCountAndType_fp;
0752 ADTOOL_AMPI_popReduceInfoF *popReduceInfo_fp;
0753 ADTOOL_AMPI_pushSRinfoF *pushSRinfo_fp;
0754 ADTOOL_AMPI_popSRinfoF *popSRinfo_fp;
0755 ADTOOL_AMPI_pushOSinfoF *pushOSinfo_fp;
0756 ADTOOL_AMPI_popOSinfoF *popOSinfo_fp;
0757 ADTOOL_AMPI_pushGSinfoF *pushGSinfo_fp;
0758 ADTOOL_AMPI_popGScommSizeForRootOrNullF *popGScommSizeForRootOrNull_fp;
0759 ADTOOL_AMPI_popGSinfoF *popGSinfo_fp;
0760 ADTOOL_AMPI_pushGSVinfoF *pushGSVinfo_fp;
0761 ADTOOL_AMPI_popGSVinfoF *popGSVinfo_fp;
0762 ADTOOL_AMPI_push_CallCodeF *push_CallCode_fp;
0763 ADTOOL_AMPI_push_CallCodeReserveF *push_CallCodeReserve_fp;
0764 ADTOOL_AMPI_pop_CallCodeF *pop_CallCode_fp;
0765 ADTOOL_AMPI_push_AMPI_RequestF *push_AMPI_Request_fp;
0766 ADTOOL_AMPI_pop_AMPI_RequestF *pop_AMPI_Request_fp;
0767 ADTOOL_AMPI_push_AMPI_WinF *push_AMPI_Win_fp;
0768 ADTOOL_AMPI_pop_AMPI_WinF *pop_AMPI_Win_fp;
0769 ADTOOL_AMPI_push_WinRequestF *push_AMPI_WinRequest_fp;
0770 ADTOOL_AMPI_pop_WinRequestF *pop_AMPI_WinRequest_fp;
0771 ADTOOL_AMPI_push_requestF *push_request_fp;
0772 ADTOOL_AMPI_pop_requestF *pop_request_fp;
0773 ADTOOL_AMPI_push_commF *push_comm_fp;
0774 ADTOOL_AMPI_pop_commF *pop_comm_fp;
0775 ADTOOL_AMPI_rawDataF *rawData_fp;
0776 ADTOOL_AMPI_rawDataVF *rawDataV_fp;
0777 ADTOOL_AMPI_packDTypeF *packDType_fp;
0778 ADTOOL_AMPI_unpackDTypeF *unpackDType_fp;
0779 ADTOOL_AMPI_writeDataF *writeData_fp;
0780 ADTOOL_AMPI_writeDataVF *writeDataV_fp;
0781 ADTOOL_AMPI_rawAdjointDataF *rawAdjointData_fp;
0782 ADTOOL_AMPI_TurnF *Turn_fp;
0783 ADTOOL_AMPI_mapBufForAdjointF *mapBufForAdjoint_fp;
0784 ADTOOL_AMPI_mapWinBufForAdjointF *mapWinBufForAdjoint_fp;
0785 ADTOOL_AMPI_setBufForAdjointF *setBufForAdjoint_fp;
0786 ADTOOL_AMPI_getAdjointCountF *getAdjointCount_fp;
0787 ADTOOL_AMPI_setAdjointCountF *setAdjointCount_fp;
0788 ADTOOL_AMPI_setAdjointCountAndTempBufF *setAdjointCountAndTempBuf_fp;
0789 ADTOOL_AMPI_setWinAdjointCountF *setWinAdjointCount_fp;
0790 ADTOOL_AMPI_setWinAdjointCountAndTempBufF *setWinAdjointCountAndTempBuf_fp;
0791 ADTOOL_AMPI_allocateTempBufF *allocateTempBuf_fp;
0792 ADTOOL_AMPI_releaseAdjointTempBufF *releaseAdjointTempBuf_fp;
0793 ADTOOL_AMPI_allocateTempActiveBufF *allocateTempActiveBuf_fp;
0794 ADTOOL_AMPI_releaseTempActiveBufF *releaseTempActiveBuf_fp;
0795 ADTOOL_AMPI_copyActiveBufF *copyActiveBuf_fp;
0796 ADTOOL_AMPI_adjointMultiplyF *adjointMultiply_fp ;
0797 ADTOOL_AMPI_adjointMinF *adjointMin_fp ;
0798 ADTOOL_AMPI_adjointMaxF *adjointMax_fp ;
0799 ADTOOL_AMPI_multiplyAdjointF *multiplyAdjoint_fp;
0800 ADTOOL_AMPI_divideAdjointF *divideAdjoint_fp;
0801 ADTOOL_AMPI_equalAdjointsF *equalAdjoints_fp;
0802 ADTOOL_AMPI_incrementAdjointF *incrementAdjoint_fp;
0803 ADTOOL_AMPI_nullifyAdjointF *nullifyAdjoint_fp;
0804 ADTOOL_AMPI_setupTypesF *setupTypes_fp;
0805 ADTOOL_AMPI_cleanupTypesF *cleanupTypes_fp;
0806 ADTOOL_AMPI_FW_rawTypeF *FW_rawType_fp;
0807 ADTOOL_AMPI_BW_rawTypeF *BW_rawType_fp;
0808 ADTOOL_AMPI_createWinMapF *createWinMap_fp;
0809 ADTOOL_AMPI_writeWinDataF *writeWinData_fp;
0810 ADTOOL_AMPI_getWinSizeF *getWinSize_fp;
0811 ADTOOL_AMPI_syncAdjointWinF *syncAdjointWin_fp;
0812 ADTOOL_AMPI_isActiveTypeF *isActiveType_fp ;
0813 ADTOOL_AMPI_tangentMultiplyF *tangentMultiply_fp ;
0814 ADTOOL_AMPI_tangentMinF *tangentMin_fp ;
0815 ADTOOL_AMPI_tangentMaxF *tangentMax_fp ;
0816 ADTOOL_AMPI_pushBufferF *pushBuffer_fp ;
0817 ADTOOL_AMPI_popBufferF *popBuffer_fp ;
0818 ADTOOL_AMPI_addShadowCommF *addShadowComm_fp ;
0819 ADTOOL_AMPI_getShadowCommF *getShadowComm_fp ;
0820 ADTOOL_AMPI_delShadowCommF *delShadowComm_fp ;
0821 #ifdef AMPI_FORTRANCOMPATIBLE
0822 adtool_ampi_fortransetuptypes_F *fortransetuptypes__fp;
0823 adtool_ampi_fortrancleanuptypes_F *fortrancleanuptypes__fp;
0824 #endif
0825 };
0826
0827 /**
0828 * the single instance of ADTOOL_AMPI_FPCollection
0829 */
0830 extern struct ADTOOL_AMPI_FPCollection ourADTOOL_AMPI_FPCollection;
0831
0832 /** The type required for TANGENT user-given reduction functions,
0833 * that are passed e.g. to TLM_AMPI_Reduce in Tapenade-style diff AMPI code. */
0834 typedef void (TLM_userFunctionF) (void*, void*, void*, void*, int*, MPI_Datatype*, MPI_Datatype*) ;
0835
0836 /** The type required for ADJOINT user-given reduction functions,
0837 * that are passed e.g. to BW_AMPI_Reduce in Tapenade-style diff AMPI code. */
0838 typedef void (ADJ_userFunctionF) (void*, void*, void*, void*, int*, MPI_Datatype*, MPI_Datatype*) ;
0839
0840
0841 #if defined(__cplusplus)
0842 }
0843 #endif
0844
0845 #endif
0846