Actual source code: petscsf.h

      1: /*
      2:    A star forest (SF) describes a communication pattern
      3: */
      4: #pragma once

      6: #include <petscsys.h>
      7: #include <petscsftypes.h>
      8: #include <petscvec.h>

     10: /* MANSEC = Vec */
     11: /* SUBMANSEC = PetscSF */

     13: PETSC_EXTERN PetscClassId PETSCSF_CLASSID;

     15: /*E
     16:    PetscSFPattern - Pattern of the `PetscSF` graph

     18:    Values:
     19: +  `PETSCSF_PATTERN_GENERAL`   - A general graph. One sets the graph with `PetscSFSetGraph()` and usually does not use this enum directly.
     20: .  `PETSCSF_PATTERN_ALLGATHER` - A graph that every MPI process gathers all roots from all MPI processes (like `MPI_Allgather()`). One sets the graph with `PetscSFSetGraphWithPattern()`.
     21: .  `PETSCSF_PATTERN_GATHER`    - A graph that MPI rank 0 gathers all roots from all MPI processes (like `MPI_Gatherv()` with root=0). One sets the graph with `PetscSFSetGraphWithPattern()`.
     22: -  `PETSCSF_PATTERN_ALLTOALL`  - A graph that every MPI process gathers different roots from all MPI processes (like `MPI_Alltoall()`). One sets the graph with `PetscSFSetGraphWithPattern()`.
     23:                                  We assume each process has <size> leaves and <size> roots, with each leaf connecting to a remote root. Here <size> is
     24:                                  the size of the communicator. This does not mean one can not communicate multiple data items between a pair of processes. One just needs to
     25:                                  create a new MPI datatype for the multiple data items, e.g., by `MPI_Type_contiguous`.
     26:    Level: beginner

     28: .seealso: `PetscSF`, `PetscSFSetGraph()`, `PetscSFSetGraphWithPattern()`
     29: E*/
     30: typedef enum {
     31:   PETSCSF_PATTERN_GENERAL,
     32:   PETSCSF_PATTERN_ALLGATHER,
     33:   PETSCSF_PATTERN_GATHER,
     34:   PETSCSF_PATTERN_ALLTOALL
     35: } PetscSFPattern;

     37: /*E
     38:     PetscSFWindowSyncType - Type of synchronization for `PETSCSFWINDOW`

     40:    Values:
     41: +  `PETSCSF_WINDOW_SYNC_FENCE`  - simplest model, synchronizing across communicator
     42: .  `PETSCSF_WINDOW_SYNC_LOCK`   - passive model, less synchronous, requires less setup than `PETSCSF_WINDOW_SYNC_ACTIVE`, but may require more handshakes
     43: -  `PETSCSF_WINDOW_SYNC_ACTIVE` - active model, provides most information to MPI implementation, needs to construct 2-way process groups (more setup than `PETSCSF_WINDOW_SYNC_LOCK`)

     45:    Level: advanced

     47: .seealso: `PetscSF`, `PetscSFWindowFlavorType`, `PetscSFWindowSetSyncType()`, `PetscSFWindowGetSyncType()`
     48: E*/
     49: typedef enum {
     50:   PETSCSF_WINDOW_SYNC_FENCE,
     51:   PETSCSF_WINDOW_SYNC_LOCK,
     52:   PETSCSF_WINDOW_SYNC_ACTIVE
     53: } PetscSFWindowSyncType;
     54: PETSC_EXTERN const char *const PetscSFWindowSyncTypes[];

     56: /*E
     57:     PetscSFWindowFlavorType - Flavor for the creation of MPI windows for `PETSCSFWINDOW`

     59:     Values:
     60: +  `PETSCSF_WINDOW_FLAVOR_CREATE`   - Use `MPI_Win_create()`, no reuse
     61: .  `PETSCSF_WINDOW_FLAVOR_DYNAMIC`  - Use `MPI_Win_create_dynamic()` and dynamically attach pointers
     62: .  `PETSCSF_WINDOW_FLAVOR_ALLOCATE` - Use `MPI_Win_allocate()`
     63: -  `PETSCSF_WINDOW_FLAVOR_SHARED`   - Use `MPI_Win_allocate_shared()`

     65:    Level: advanced

     67: .seealso: `PetscSF`, `PetscSFWindowSyncType`, `PetscSFWindowSetFlavorType()`, `PetscSFWindowGetFlavorType()`
     68: E*/
     69: typedef enum {
     70:   PETSCSF_WINDOW_FLAVOR_CREATE,
     71:   PETSCSF_WINDOW_FLAVOR_DYNAMIC,
     72:   PETSCSF_WINDOW_FLAVOR_ALLOCATE,
     73:   PETSCSF_WINDOW_FLAVOR_SHARED
     74: } PetscSFWindowFlavorType;
     75: PETSC_EXTERN const char *const PetscSFWindowFlavorTypes[];

     77: /*E
     78:     PetscSFDuplicateOption - Aspects to preserve when duplicating a `PetscSF`

     80:    Values:
     81: +  `PETSCSF_DUPLICATE_CONFONLY` - configuration only, user must call `PetscSFSetGraph()`
     82: .  `PETSCSF_DUPLICATE_RANKS`    - communication ranks preserved, but different graph (allows simpler setup after calling `PetscSFSetGraph()`)
     83: -  `PETSCSF_DUPLICATE_GRAPH`    - entire graph duplicated

     85:    Level: beginner

     87: .seealso: `PetscSF`, `PetscSFDuplicate()`
     88: E*/
     89: typedef enum {
     90:   PETSCSF_DUPLICATE_CONFONLY,
     91:   PETSCSF_DUPLICATE_RANKS,
     92:   PETSCSF_DUPLICATE_GRAPH
     93: } PetscSFDuplicateOption;
     94: PETSC_EXTERN const char *const PetscSFDuplicateOptions[];

     96: /*E
     97:     PetscSFConcatenateRootMode - Modes of root concatenation when concatenating `PetscSF`s

     99:    Values:
    100: +  `PETSCSF_CONCATENATE_ROOTMODE_LOCAL`  - concatenate root spaces locally (separately on each rank)
    101: .  `PETSCSF_CONCATENATE_ROOTMODE_SHARED` - do not concatenate roots; root space is considered the same for each input `PetscSF` (checked in debug mode)
    102: -  `PETSCSF_CONCATENATE_ROOTMODE_GLOBAL` - concatenate root spaces globally

    104:    Level: advanced

    106: .seealso: `PetscSF`, `PetscSFConcatenate()`
    107: E*/
    108: typedef enum {
    109:   PETSCSF_CONCATENATE_ROOTMODE_LOCAL,
    110:   PETSCSF_CONCATENATE_ROOTMODE_SHARED,
    111:   PETSCSF_CONCATENATE_ROOTMODE_GLOBAL,
    112: } PetscSFConcatenateRootMode;
    113: PETSC_EXTERN const char *const PetscSFConcatenateRootModes[];

    115: PETSC_EXTERN PetscFunctionList PetscSFList;
    116: PETSC_EXTERN PetscErrorCode    PetscSFRegister(const char[], PetscErrorCode (*)(PetscSF));

    118: PETSC_EXTERN PetscErrorCode PetscSFInitializePackage(void);
    119: PETSC_EXTERN PetscErrorCode PetscSFFinalizePackage(void);
    120: PETSC_EXTERN PetscErrorCode PetscSFCreate(MPI_Comm, PetscSF *);
    121: PETSC_EXTERN PetscErrorCode PetscSFDestroy(PetscSF *);
    122: PETSC_EXTERN PetscErrorCode PetscSFSetType(PetscSF, PetscSFType);
    123: PETSC_EXTERN PetscErrorCode PetscSFGetType(PetscSF, PetscSFType *);
    124: PETSC_EXTERN PetscErrorCode PetscSFView(PetscSF, PetscViewer);
    125: PETSC_EXTERN PetscErrorCode PetscSFViewFromOptions(PetscSF, PetscObject, const char[]);
    126: PETSC_EXTERN PetscErrorCode PetscSFSetUp(PetscSF);
    127: PETSC_EXTERN PetscErrorCode PetscSFSetFromOptions(PetscSF);
    128: PETSC_EXTERN PetscErrorCode PetscSFDuplicate(PetscSF, PetscSFDuplicateOption, PetscSF *);
    129: PETSC_EXTERN PetscErrorCode PetscSFWindowSetSyncType(PetscSF, PetscSFWindowSyncType);
    130: PETSC_EXTERN PetscErrorCode PetscSFWindowGetSyncType(PetscSF, PetscSFWindowSyncType *);
    131: PETSC_EXTERN PetscErrorCode PetscSFWindowSetFlavorType(PetscSF, PetscSFWindowFlavorType);
    132: PETSC_EXTERN PetscErrorCode PetscSFWindowGetFlavorType(PetscSF, PetscSFWindowFlavorType *);
    133: PETSC_EXTERN PetscErrorCode PetscSFWindowSetInfo(PetscSF, MPI_Info);
    134: PETSC_EXTERN PetscErrorCode PetscSFWindowGetInfo(PetscSF, MPI_Info *);
    135: PETSC_EXTERN PetscErrorCode PetscSFSetRankOrder(PetscSF, PetscBool);
    136: PETSC_EXTERN PetscErrorCode PetscSFSetGraph(PetscSF, PetscInt, PetscInt, PetscInt[], PetscCopyMode, PetscSFNode[], PetscCopyMode);
    137: PETSC_EXTERN PetscErrorCode PetscSFSetGraphWithPattern(PetscSF, PetscLayout, PetscSFPattern);
    138: PETSC_EXTERN PetscErrorCode PetscSFGetGraph(PetscSF, PetscInt *, PetscInt *, const PetscInt *[], const PetscSFNode *[]);
    139: PETSC_EXTERN PetscErrorCode PetscSFGetLeafRange(PetscSF, PetscInt *, PetscInt *);
    140: PETSC_EXTERN PetscErrorCode PetscSFCreateEmbeddedRootSF(PetscSF, PetscInt, const PetscInt[], PetscSF *);
    141: PETSC_EXTERN PetscErrorCode PetscSFCreateEmbeddedLeafSF(PetscSF, PetscInt, const PetscInt[], PetscSF *);
    142: PETSC_EXTERN PetscErrorCode PetscSFReset(PetscSF);
    143: PETSC_EXTERN PetscErrorCode PetscSFSetUpRanks(PetscSF, MPI_Group);
    144: PETSC_EXTERN PetscErrorCode PetscSFGetRootRanks(PetscSF, PetscMPIInt *, const PetscMPIInt *[], const PetscInt *[], const PetscInt *[], const PetscInt *[]);
    145: PETSC_EXTERN PetscErrorCode PetscSFGetLeafRanks(PetscSF, PetscMPIInt *, const PetscMPIInt *[], const PetscInt *[], const PetscInt *[]);
    146: PETSC_EXTERN PetscErrorCode PetscSFGetGroups(PetscSF, MPI_Group *, MPI_Group *);
    147: PETSC_EXTERN PetscErrorCode PetscSFGetMultiSF(PetscSF, PetscSF *);
    148: PETSC_EXTERN PetscErrorCode PetscSFGetRanksSF(PetscSF, PetscSF *);
    149: PETSC_EXTERN PetscErrorCode PetscSFCreateInverseSF(PetscSF, PetscSF *);
    150: PETSC_EXTERN PetscErrorCode PetscSFConcatenate(MPI_Comm, PetscInt, PetscSF[], PetscSFConcatenateRootMode, PetscInt[], PetscSF *);
    151: PETSC_EXTERN PetscErrorCode PetscSFCreateStridedSF(PetscSF, PetscInt, PetscInt, PetscInt, PetscSF *);

    153: /* Build PetscSF from PetscLayout */
    154: PETSC_EXTERN PetscErrorCode PetscSFSetGraphLayout(PetscSF, PetscLayout, PetscInt, PetscInt[], PetscCopyMode, const PetscInt[]);
    155: PETSC_EXTERN PetscErrorCode PetscSFGetGraphLayout(PetscSF, PetscLayout *, PetscInt *, const PetscInt *[], PetscInt *[]);
    156: PETSC_EXTERN PetscErrorCode PetscSFCreateFromLayouts(PetscLayout, PetscLayout, PetscSF *);
    157: PETSC_EXTERN PetscErrorCode PetscSFCreateByMatchingIndices(PetscLayout, PetscInt, const PetscInt[], const PetscInt[], PetscInt, PetscInt, const PetscInt[], const PetscInt[], PetscInt, PetscSF *, PetscSF *);
    158: PETSC_EXTERN PetscErrorCode PetscSFMerge(PetscSF, PetscSF, PetscSF *);
    159: PETSC_EXTERN PetscErrorCode PetscSFSetGraphFromCoordinates(PetscSF, PetscInt, PetscInt, PetscInt, PetscReal, const PetscReal[], const PetscReal[]);

    161: /* PetscSection interoperability */
    162: PETSC_EXTERN PetscErrorCode PetscSFSetGraphSection(PetscSF, PetscSection, PetscSection);
    163: PETSC_EXTERN PetscErrorCode PetscSFCreateRemoteOffsets(PetscSF, PetscSection, PetscSection, PetscInt *[]);
    164: PETSC_EXTERN PetscErrorCode PetscSFDistributeSection(PetscSF, PetscSection, PetscInt *[], PetscSection);
    165: PETSC_EXTERN PetscErrorCode PetscSFCreateSectionSF(PetscSF, PetscSection, PetscInt[], PetscSection, PetscSF *);

    167: /* Reduce rootdata to leafdata using provided operation */
    168: PETSC_EXTERN PetscErrorCode PetscSFBcastBegin(PetscSF, MPI_Datatype, const void *, void *, MPI_Op) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(3, 2) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(4, 2);
    169: PETSC_EXTERN PetscErrorCode PetscSFBcastEnd(PetscSF, MPI_Datatype, const void *, void *, MPI_Op) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(3, 2) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(4, 2);
    170: PETSC_EXTERN PetscErrorCode PetscSFBcastWithMemTypeBegin(PetscSF, MPI_Datatype, PetscMemType, const void *, PetscMemType, void *, MPI_Op) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(4, 2) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(6, 2);

    172: /* Reduce leafdata into rootdata using provided operation */
    173: PETSC_EXTERN PetscErrorCode PetscSFReduceBegin(PetscSF, MPI_Datatype, const void *, void *, MPI_Op) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(3, 2) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(4, 2);
    174: PETSC_EXTERN PetscErrorCode PetscSFReduceEnd(PetscSF, MPI_Datatype, const void *, void *, MPI_Op) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(3, 2) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(4, 2);
    175: PETSC_EXTERN PetscErrorCode PetscSFReduceWithMemTypeBegin(PetscSF, MPI_Datatype, PetscMemType, const void *, PetscMemType, void *, MPI_Op) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(4, 2) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(6, 2);

    177: /* Atomically modifies (using provided operation) rootdata using leafdata from each leaf, value at root at time of modification is returned in leafupdate. */
    178: PETSC_EXTERN PetscErrorCode PetscSFFetchAndOpBegin(PetscSF, MPI_Datatype, void *, const void *, void *, MPI_Op) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(3, 2) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(4, 2) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(5, 2);
    179: PETSC_EXTERN PetscErrorCode PetscSFFetchAndOpEnd(PetscSF, MPI_Datatype, void *, const void *, void *, MPI_Op) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(3, 2) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(4, 2) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(5, 2);

    181: PETSC_EXTERN PetscErrorCode PetscSFFetchAndOpWithMemTypeBegin(PetscSF, MPI_Datatype, PetscMemType, void *, PetscMemType, const void *, PetscMemType, void *, MPI_Op) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(4, 2) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(6, 2) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(8, 2);

    183: /* Compute the degree of every root vertex (number of leaves in its star) */
    184: PETSC_EXTERN PetscErrorCode PetscSFComputeDegreeBegin(PetscSF, const PetscInt *[]);
    185: PETSC_EXTERN PetscErrorCode PetscSFComputeDegreeEnd(PetscSF, const PetscInt *[]);
    186: PETSC_EXTERN PetscErrorCode PetscSFComputeMultiRootOriginalNumbering(PetscSF, const PetscInt[], PetscInt *, PetscInt *[]);
    187: /* Concatenate data from all leaves into roots */
    188: PETSC_EXTERN PetscErrorCode PetscSFGatherBegin(PetscSF, MPI_Datatype, const void *, void *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(3, 2) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(4, 2);
    189: PETSC_EXTERN PetscErrorCode PetscSFGatherEnd(PetscSF, MPI_Datatype, const void *, void *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(3, 2) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(4, 2);
    190: /* Distribute distinct values to each leaf from roots */
    191: PETSC_EXTERN PetscErrorCode PetscSFScatterBegin(PetscSF, MPI_Datatype, const void *, void *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(3, 2) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(4, 2);
    192: PETSC_EXTERN PetscErrorCode PetscSFScatterEnd(PetscSF, MPI_Datatype, const void *, void *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(3, 2) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(4, 2);

    194: PETSC_EXTERN PetscErrorCode PetscSFCompose(PetscSF, PetscSF, PetscSF *);
    195: PETSC_EXTERN PetscErrorCode PetscSFComposeInverse(PetscSF, PetscSF, PetscSF *);

    197: PETSC_EXTERN PetscErrorCode PetscSFRegisterPersistent(PetscSF, MPI_Datatype, const void *, const void *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(3, 2) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(4, 2);
    198: PETSC_EXTERN PetscErrorCode PetscSFDeregisterPersistent(PetscSF, MPI_Datatype, const void *, const void *) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(3, 2) PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(4, 2);

    200: #define MPIU_REPLACE MPI_REPLACE PETSC_DEPRECATED_MACRO(3, 15, 0, "MPI_REPLACE", )

    202: PETSC_DEPRECATED_FUNCTION(3, 12, 0, "PetscSFGetRootRanks()", )
    203: static inline PetscErrorCode PetscSFGetRanks(PetscSF sf, PetscMPIInt *nranks, const PetscMPIInt *ranks[], const PetscInt *roffset[], const PetscInt *rmine[], const PetscInt *rremote[])
    204: {
    205:   return PetscSFGetRootRanks(sf, nranks, ranks, roffset, rmine, rremote);
    206: }

    208: PETSC_DEPRECATED_FUNCTION(3, 15, 0, "PetscSFCreateEmbeddedRootSF()", )
    209: static inline PetscErrorCode PetscSFCreateEmbeddedSF(PetscSF sf, PetscInt nselected, const PetscInt selected[], PetscSF *esf)
    210: {
    211:   return PetscSFCreateEmbeddedRootSF(sf, nselected, selected, esf);
    212: }

    214: PETSC_DEPRECATED_FUNCTION(3, 15, 0, "PetscSFBcastBegin()", )
    215: static inline PetscErrorCode PetscSFBcastAndOpBegin(PetscSF sf, MPI_Datatype unit, const void *rootdata, void *leafdata, MPI_Op op)
    216: {
    217:   return PetscSFBcastBegin(sf, unit, rootdata, leafdata, op);
    218: }

    220: PETSC_DEPRECATED_FUNCTION(3, 15, 0, "PetscSFBcastEnd()", )
    221: static inline PetscErrorCode PetscSFBcastAndOpEnd(PetscSF sf, MPI_Datatype unit, const void *rootdata, void *leafdata, MPI_Op op)
    222: {
    223:   return PetscSFBcastEnd(sf, unit, rootdata, leafdata, op);
    224: }

    226: PETSC_DEPRECATED_FUNCTION(3, 15, 0, "PetscSFBcastWithMemTypeBegin()", )
    227: static inline PetscErrorCode PetscSFBcastAndOpWithMemtypeBegin(PetscSF sf, MPI_Datatype unit, PetscMemType rootmtype, const void *rootdata, PetscMemType leafmtype, void *leafdata, MPI_Op op)
    228: {
    229:   return PetscSFBcastWithMemTypeBegin(sf, unit, rootmtype, rootdata, leafmtype, leafdata, op);
    230: }