Actual source code: petscsf.h

petsc-3.11.4 2019-09-28
Report Typos and Errors
  1: /*
  2:    A star forest (SF) describes a communication pattern
  3: */
  4: #if !defined(PETSCSF_H)
  5: #define PETSCSF_H
  6:  #include <petscsys.h>
  7:  #include <petscsftypes.h>

  9: PETSC_EXTERN PetscClassId PETSCSF_CLASSID;

 11: /*J
 12:     PetscSFType - String with the name of a PetscSF method or the creation function
 13:        with an optional dynamic library name, for example
 14:        http://www.mcs.anl.gov/petsc/lib.so:mysfcreate()

 16:    Level: beginner

 18:    Notes:
 19:     The two approaches provided are
 20: $     PETSCSFBASIC which uses MPI 1 message passing to perform the communication and
 21: $     PETSCSFWINDOW which uses MPI 2 one-sided operations to perform the communication, this may be more efficient,
 22: $                   but may not be available for all MPI distributions. In particular OpenMPI has bugs in its one-sided
 23: $                   operations that prevent its use.

 25: .seealso: PetscSFSetType(), PetscSF
 26: J*/
 27: typedef const char *PetscSFType;
 28: #define PETSCSFBASIC  "basic"
 29: #define PETSCSFWINDOW "window"

 31: /*E
 32:     PetscSFWindowSyncType - Type of synchronization for PETSCSFWINDOW

 34: $  PETSCSF_WINDOW_SYNC_FENCE - simplest model, synchronizing across communicator
 35: $  PETSCSF_WINDOW_SYNC_LOCK - passive model, less synchronous, requires less setup than PETSCSF_WINDOW_SYNC_ACTIVE, but may require more handshakes
 36: $  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)

 38:    Level: advanced

 40: .seealso: PetscSFWindowSetSyncType(), PetscSFWindowGetSyncType()
 41: E*/
 42: typedef enum {PETSCSF_WINDOW_SYNC_FENCE,PETSCSF_WINDOW_SYNC_LOCK,PETSCSF_WINDOW_SYNC_ACTIVE} PetscSFWindowSyncType;
 43: PETSC_EXTERN const char *const PetscSFWindowSyncTypes[];

 45: /*E
 46:     PetscSFDuplicateOption - Aspects to preserve when duplicating a PetscSF

 48: $  PETSCSF_DUPLICATE_CONFONLY - configuration only, user must call PetscSFSetGraph()
 49: $  PETSCSF_DUPLICATE_RANKS - communication ranks preserved, but different graph (allows simpler setup after calling PetscSFSetGraph())
 50: $  PETSCSF_DUPLICATE_GRAPH - entire graph duplicated

 52:    Level: beginner

 54: .seealso: PetscSFDuplicate()
 55: E*/
 56: typedef enum {PETSCSF_DUPLICATE_CONFONLY,PETSCSF_DUPLICATE_RANKS,PETSCSF_DUPLICATE_GRAPH} PetscSFDuplicateOption;
 57: PETSC_EXTERN const char *const PetscSFDuplicateOptions[];

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

 62: PETSC_EXTERN PetscErrorCode PetscSFInitializePackage(void);
 63: PETSC_EXTERN PetscErrorCode PetscSFFinalizePackage(void);
 64: PETSC_EXTERN PetscErrorCode PetscSFCreate(MPI_Comm,PetscSF*);
 65: PETSC_EXTERN PetscErrorCode PetscSFDestroy(PetscSF*);
 66: PETSC_EXTERN PetscErrorCode PetscSFSetType(PetscSF,PetscSFType);
 67: PETSC_EXTERN PetscErrorCode PetscSFGetType(PetscSF,PetscSFType*);
 68: PETSC_EXTERN PetscErrorCode PetscSFView(PetscSF,PetscViewer);
 69: PETSC_STATIC_INLINE PetscErrorCode PetscSFViewFromOptions(PetscSF A,PetscObject obj,const char name[]) {return PetscObjectViewFromOptions((PetscObject)A,obj,name);}
 70: PETSC_EXTERN PetscErrorCode PetscSFSetUp(PetscSF);
 71: PETSC_EXTERN PetscErrorCode PetscSFSetFromOptions(PetscSF);
 72: PETSC_EXTERN PetscErrorCode PetscSFDuplicate(PetscSF,PetscSFDuplicateOption,PetscSF*);
 73: PETSC_EXTERN PetscErrorCode PetscSFWindowSetSyncType(PetscSF,PetscSFWindowSyncType);
 74: PETSC_EXTERN PetscErrorCode PetscSFWindowGetSyncType(PetscSF,PetscSFWindowSyncType*);
 75: PETSC_EXTERN PetscErrorCode PetscSFSetRankOrder(PetscSF,PetscBool);
 76: PETSC_EXTERN PetscErrorCode PetscSFSetGraph(PetscSF,PetscInt,PetscInt,const PetscInt*,PetscCopyMode,const PetscSFNode*,PetscCopyMode);
 77: PETSC_EXTERN PetscErrorCode PetscSFGetGraph(PetscSF,PetscInt*,PetscInt*,const PetscInt**,const PetscSFNode**);
 78: PETSC_EXTERN PetscErrorCode PetscSFGetLeafRange(PetscSF,PetscInt*,PetscInt*);
 79: PETSC_EXTERN PetscErrorCode PetscSFCreateEmbeddedSF(PetscSF,PetscInt,const PetscInt*,PetscSF*);
 80: PETSC_EXTERN PetscErrorCode PetscSFCreateEmbeddedLeafSF(PetscSF,PetscInt,const PetscInt *, PetscSF *);
 81: PETSC_EXTERN PetscErrorCode PetscSFReset(PetscSF);
 82: PETSC_EXTERN PetscErrorCode PetscSFSetUpRanks(PetscSF,MPI_Group);
 83: PETSC_EXTERN PetscErrorCode PetscSFGetRanks(PetscSF,PetscInt*,const PetscMPIInt**,const PetscInt**,const PetscInt**,const PetscInt**);
 84: PETSC_EXTERN PetscErrorCode PetscSFGetLeafRanks(PetscSF,PetscInt*,const PetscMPIInt**,const PetscInt**,const PetscInt**);
 85: PETSC_EXTERN PetscErrorCode PetscSFGetGroups(PetscSF,MPI_Group*,MPI_Group*);
 86: PETSC_EXTERN PetscErrorCode PetscSFGetMultiSF(PetscSF,PetscSF*);
 87: PETSC_EXTERN PetscErrorCode PetscSFCreateInverseSF(PetscSF,PetscSF*);

 89: /* broadcasts rootdata to leafdata */
 90: PETSC_EXTERN PetscErrorCode PetscSFBcastBegin(PetscSF,MPI_Datatype,const void*,void*)
 91:   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
 92: PETSC_EXTERN PetscErrorCode PetscSFBcastEnd(PetscSF,MPI_Datatype,const void*,void*)
 93:   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
 94: /* Reduce rootdata to leafdata using provided operation */
 95: PETSC_EXTERN PetscErrorCode PetscSFBcastAndOpBegin(PetscSF,MPI_Datatype,const void*,void*,MPI_Op)
 96:   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
 97: PETSC_EXTERN PetscErrorCode PetscSFBcastAndOpEnd(PetscSF,MPI_Datatype,const void*,void*,MPI_Op)
 98:   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
 99: /* Reduce leafdata into rootdata using provided operation */
100: PETSC_EXTERN PetscErrorCode PetscSFReduceBegin(PetscSF,MPI_Datatype,const void*,void *,MPI_Op)
101:   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
102: PETSC_EXTERN PetscErrorCode PetscSFReduceEnd(PetscSF,MPI_Datatype,const void*,void*,MPI_Op)
103:   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
104: /* Atomically modifies (using provided operation) rootdata using leafdata from each leaf, value at root at time of modification is returned in leafupdate. */
105: PETSC_EXTERN PetscErrorCode PetscSFFetchAndOpBegin(PetscSF,MPI_Datatype,void*,const void*,void*,MPI_Op)
106:   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2) PetscAttrMPIPointerWithType(5,2);
107: PETSC_EXTERN PetscErrorCode PetscSFFetchAndOpEnd(PetscSF,MPI_Datatype,void*,const void*,void*,MPI_Op)
108:   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2) PetscAttrMPIPointerWithType(5,2);
109: /* Compute the degree of every root vertex (number of leaves in its star) */
110: PETSC_EXTERN PetscErrorCode PetscSFComputeDegreeBegin(PetscSF,const PetscInt**);
111: PETSC_EXTERN PetscErrorCode PetscSFComputeDegreeEnd(PetscSF,const PetscInt**);
112: PETSC_EXTERN PetscErrorCode PetscSFComputeMultiRootOriginalNumbering(PetscSF,const PetscInt[],PetscInt*[]);
113: /* Concatenate data from all leaves into roots */
114: PETSC_EXTERN PetscErrorCode PetscSFGatherBegin(PetscSF,MPI_Datatype,const void*,void*)
115:   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
116: PETSC_EXTERN PetscErrorCode PetscSFGatherEnd(PetscSF,MPI_Datatype,const void*,void*)
117:   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
118: /* Distribute distinct values to each leaf from roots */
119: PETSC_EXTERN PetscErrorCode PetscSFScatterBegin(PetscSF,MPI_Datatype,const void*,void*)
120:   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
121: PETSC_EXTERN PetscErrorCode PetscSFScatterEnd(PetscSF,MPI_Datatype,const void*,void*)
122:   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);

124: PETSC_EXTERN PetscErrorCode PetscSFCompose(PetscSF,PetscSF,PetscSF*);

126: #if defined(MPI_REPLACE)
127: #  define MPIU_REPLACE MPI_REPLACE
128: #else
129: /* When using an old MPI such that MPI_REPLACE is not defined, we do not pass MPI_REPLACE to MPI at all.  Instead, we
130:  * use it as a flag for our own reducer in the PETSCSFBASIC implementation.  This could be any unique value unlikely to
131:  * collide with another MPI_Op so we'll just use the value that has been used by every version of MPICH since
132:  * MPICH2-1.0.6. */
133: #  define MPIU_REPLACE (MPI_Op)(0x5800000d)
134: #endif

136: #endif