Actual source code: petscsf.h
petsc-3.5.4 2015-05-23
1: /*
2: A star forest (SF) describes a communication pattern
3: */
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: The two approaches provided are
19: $ PETSCSFBASIC which uses MPI 1 message passing to perform the communication and
20: $ PETSCSFWINDOW which uses MPI 2 one-sided operations to perform the communication, this may be more efficient,
21: $ but may not be available for all MPI distributions. In particular OpenMPI has bugs in its one-sided
22: $ operations that prevent its use.
24: .seealso: PetscSFSetType(), PetscSF
25: J*/
26: typedef const char *PetscSFType;
27: #define PETSCSFBASIC "basic"
28: #define PETSCSFWINDOW "window"
30: /*S
31: PetscSFNode - specifier of owner and index
33: Level: beginner
35: Concepts: indexing, stride, distribution
37: .seealso: PetscSFSetGraph()
38: S*/
39: typedef struct {
40: PetscInt rank; /* Rank of owner */
41: PetscInt index; /* Index of node on rank */
42: } PetscSFNode;
44: /*E
45: PetscSFWindowSyncType - Type of synchronization for PETSCSFWINDOW
47: $ PETSCSF_WINDOW_SYNC_FENCE - simplest model, synchronizing across communicator
48: $ PETSCSF_WINDOW_SYNC_LOCK - passive model, less synchronous, requires less setup than PETSCSF_WINDOW_SYNC_ACTIVE, but may require more handshakes
49: $ 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)
51: Level: advanced
53: .seealso: PetscSFWindowSetSyncType(), PetscSFWindowGetSyncType()
54: E*/
55: typedef enum {PETSCSF_WINDOW_SYNC_FENCE,PETSCSF_WINDOW_SYNC_LOCK,PETSCSF_WINDOW_SYNC_ACTIVE} PetscSFWindowSyncType;
56: PETSC_EXTERN const char *const PetscSFWindowSyncTypes[];
58: /*E
59: PetscSFDuplicateOption - Aspects to preserve when duplicating a PetscSF
61: $ PETSCSF_DUPLICATE_CONFONLY - configuration only, user must call PetscSFSetGraph()
62: $ PETSCSF_DUPLICATE_RANKS - communication ranks preserved, but different graph (allows simpler setup after calling PetscSFSetGraph())
63: $ PETSCSF_DUPLICATE_GRAPH - entire graph duplicated
65: Level: beginner
67: .seealso: PetscSFDuplicate()
68: E*/
69: typedef enum {PETSCSF_DUPLICATE_CONFONLY,PETSCSF_DUPLICATE_RANKS,PETSCSF_DUPLICATE_GRAPH} PetscSFDuplicateOption;
70: PETSC_EXTERN const char *const PetscSFDuplicateOptions[];
72: PETSC_EXTERN PetscFunctionList PetscSFList;
73: PETSC_EXTERN PetscErrorCode PetscSFRegisterAll(void);
74: PETSC_EXTERN PetscErrorCode PetscSFRegister(const char[],PetscErrorCode (*)(PetscSF));
76: PETSC_EXTERN PetscErrorCode PetscSFInitializePackage(void);
77: PETSC_EXTERN PetscErrorCode PetscSFFinalizePackage(void);
78: PETSC_EXTERN PetscErrorCode PetscSFCreate(MPI_Comm comm,PetscSF*);
79: PETSC_EXTERN PetscErrorCode PetscSFDestroy(PetscSF*);
80: PETSC_EXTERN PetscErrorCode PetscSFSetType(PetscSF,PetscSFType);
81: PETSC_EXTERN PetscErrorCode PetscSFView(PetscSF,PetscViewer);
82: PETSC_EXTERN PetscErrorCode PetscSFSetUp(PetscSF);
83: PETSC_EXTERN PetscErrorCode PetscSFSetFromOptions(PetscSF);
84: PETSC_EXTERN PetscErrorCode PetscSFDuplicate(PetscSF,PetscSFDuplicateOption,PetscSF*);
85: PETSC_EXTERN PetscErrorCode PetscSFWindowSetSyncType(PetscSF,PetscSFWindowSyncType);
86: PETSC_EXTERN PetscErrorCode PetscSFWindowGetSyncType(PetscSF,PetscSFWindowSyncType*);
87: PETSC_EXTERN PetscErrorCode PetscSFSetRankOrder(PetscSF,PetscBool);
88: PETSC_EXTERN PetscErrorCode PetscSFSetGraph(PetscSF,PetscInt,PetscInt,const PetscInt*,PetscCopyMode,const PetscSFNode*,PetscCopyMode);
89: PETSC_EXTERN PetscErrorCode PetscSFGetGraph(PetscSF,PetscInt *nroots,PetscInt *nleaves,const PetscInt **ilocal,const PetscSFNode **iremote);
90: PETSC_EXTERN PetscErrorCode PetscSFGetLeafRange(PetscSF,PetscInt*,PetscInt*);
91: PETSC_EXTERN PetscErrorCode PetscSFCreateEmbeddedSF(PetscSF,PetscInt nroots,const PetscInt *selected,PetscSF *newsf);
92: PETSC_EXTERN PetscErrorCode PetscSFReset(PetscSF);
93: PETSC_EXTERN PetscErrorCode PetscSFGetRanks(PetscSF,PetscInt*,const PetscMPIInt**,const PetscInt**,const PetscInt**,const PetscInt**);
94: PETSC_EXTERN PetscErrorCode PetscSFGetGroups(PetscSF,MPI_Group*,MPI_Group*);
95: PETSC_EXTERN PetscErrorCode PetscSFGetMultiSF(PetscSF,PetscSF*);
96: PETSC_EXTERN PetscErrorCode PetscSFCreateInverseSF(PetscSF,PetscSF*);
98: /* broadcasts rootdata to leafdata */
99: PETSC_EXTERN PetscErrorCode PetscSFBcastBegin(PetscSF,MPI_Datatype,const void *rootdata,void *leafdata)
100: PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
101: PETSC_EXTERN PetscErrorCode PetscSFBcastEnd(PetscSF,MPI_Datatype,const void *rootdata,void *leafdata)
102: PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
103: /* Reduce leafdata into rootdata using provided operation */
104: PETSC_EXTERN PetscErrorCode PetscSFReduceBegin(PetscSF,MPI_Datatype,const void *leafdata,void *rootdata,MPI_Op)
105: PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
106: PETSC_EXTERN PetscErrorCode PetscSFReduceEnd(PetscSF,MPI_Datatype,const void *leafdata,void *rootdata,MPI_Op)
107: PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
108: /* Atomically modifies (using provided operation) rootdata using leafdata from each leaf, value at root at time of modification is returned in leafupdate. */
109: PETSC_EXTERN PetscErrorCode PetscSFFetchAndOpBegin(PetscSF,MPI_Datatype,void *rootdata,const void *leafdata,void *leafupdate,MPI_Op)
110: PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2) PetscAttrMPIPointerWithType(5,2);
111: PETSC_EXTERN PetscErrorCode PetscSFFetchAndOpEnd(PetscSF,MPI_Datatype,void *rootdata,const void *leafdata,void *leafupdate,MPI_Op)
112: PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2) PetscAttrMPIPointerWithType(5,2);
113: /* Compute the degree of every root vertex (number of leaves in its star) */
114: PETSC_EXTERN PetscErrorCode PetscSFComputeDegreeBegin(PetscSF,const PetscInt **degree);
115: PETSC_EXTERN PetscErrorCode PetscSFComputeDegreeEnd(PetscSF,const PetscInt **degree);
116: /* Concatenate data from all leaves into roots */
117: PETSC_EXTERN PetscErrorCode PetscSFGatherBegin(PetscSF,MPI_Datatype,const void *leafdata,void *multirootdata)
118: PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
119: PETSC_EXTERN PetscErrorCode PetscSFGatherEnd(PetscSF,MPI_Datatype,const void *leafdata,void *multirootdata)
120: PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
121: /* Distribute distinct values to each leaf from roots */
122: PETSC_EXTERN PetscErrorCode PetscSFScatterBegin(PetscSF,MPI_Datatype,const void *multirootdata,void *leafdata)
123: PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
124: PETSC_EXTERN PetscErrorCode PetscSFScatterEnd(PetscSF,MPI_Datatype,const void *multirootdata,void *leafdata)
125: PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
127: #if defined(MPI_REPLACE)
128: # define MPIU_REPLACE MPI_REPLACE
129: #else
130: /* When using an old MPI such that MPI_REPLACE is not defined, we do not pass MPI_REPLACE to MPI at all. Instead, we
131: * use it as a flag for our own reducer in the PETSCSFBASIC implementation. This could be any unique value unlikely to
132: * collide with another MPI_Op so we'll just use the value that has been used by every version of MPICH since
133: * MPICH2-1.0.6. */
134: # define MPIU_REPLACE (MPI_Op)(0x5800000d)
135: #endif
137: #endif