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 8 PETSC_EXTERN PetscClassId PETSCSF_CLASSID; 9 10 /*S 11 PetscSF - PETSc object for setting up and managing the communication of certain entries of arrays and Vecs between MPI processes. 12 13 Level: intermediate 14 15 Concepts: star forest 16 17 PetscSF uses the concept of star forests to indicate and determine the communication patterns concisely and efficiently. 18 A star http://en.wikipedia.org/wiki/Star_(graph_theory) forest is simply a collection of trees of height 1. The leave nodes represent 19 "ghost locations" for the root nodes. 20 21 .seealso: PetscSFCreate(), VecScatter, VecScatterCreate() 22 S*/ 23 typedef struct _p_PetscSF* PetscSF; 24 25 26 /*J 27 PetscSFType - String with the name of a PetscSF method or the creation function 28 with an optional dynamic library name, for example 29 http://www.mcs.anl.gov/petsc/lib.so:mysfcreate() 30 31 Level: beginner 32 33 Notes: The two approaches provided are 34 $ PETSCSFBASIC which uses MPI 1 message passing to perform the communication and 35 $ PETSCSFWINDOW which uses MPI 2 one-sided operations to perform the communication, this may be more efficient, 36 $ but may not be available for all MPI distributions. In particular OpenMPI has bugs in its one-sided 37 $ operations that prevent its use. 38 39 .seealso: PetscSFSetType(), PetscSF 40 J*/ 41 typedef const char *PetscSFType; 42 #define PETSCSFBASIC "basic" 43 #define PETSCSFWINDOW "window" 44 45 /*S 46 PetscSFNode - specifier of owner and index 47 48 Level: beginner 49 50 Concepts: indexing, stride, distribution 51 52 .seealso: PetscSFSetGraph() 53 S*/ 54 typedef struct { 55 PetscInt rank; /* Rank of owner */ 56 PetscInt index; /* Index of node on rank */ 57 } PetscSFNode; 58 59 /*E 60 PetscSFWindowSyncType - Type of synchronization for PETSCSFWINDOW 61 62 $ PETSCSF_WINDOW_SYNC_FENCE - simplest model, synchronizing across communicator 63 $ PETSCSF_WINDOW_SYNC_LOCK - passive model, less synchronous, requires less setup than PETSCSF_WINDOW_SYNC_ACTIVE, but may require more handshakes 64 $ 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) 65 66 Level: advanced 67 68 .seealso: PetscSFWindowSetSyncType(), PetscSFWindowGetSyncType() 69 E*/ 70 typedef enum {PETSCSF_WINDOW_SYNC_FENCE,PETSCSF_WINDOW_SYNC_LOCK,PETSCSF_WINDOW_SYNC_ACTIVE} PetscSFWindowSyncType; 71 PETSC_EXTERN const char *const PetscSFWindowSyncTypes[]; 72 73 /*E 74 PetscSFDuplicateOption - Aspects to preserve when duplicating a PetscSF 75 76 $ PETSCSF_DUPLICATE_CONFONLY - configuration only, user must call PetscSFSetGraph() 77 $ PETSCSF_DUPLICATE_RANKS - communication ranks preserved, but different graph (allows simpler setup after calling PetscSFSetGraph()) 78 $ PETSCSF_DUPLICATE_GRAPH - entire graph duplicated 79 80 Level: beginner 81 82 .seealso: PetscSFDuplicate() 83 E*/ 84 typedef enum {PETSCSF_DUPLICATE_CONFONLY,PETSCSF_DUPLICATE_RANKS,PETSCSF_DUPLICATE_GRAPH} PetscSFDuplicateOption; 85 PETSC_EXTERN const char *const PetscSFDuplicateOptions[]; 86 87 PETSC_EXTERN PetscFunctionList PetscSFunctionList; 88 PETSC_EXTERN PetscErrorCode PetscSFRegisterDestroy(void); 89 PETSC_EXTERN PetscErrorCode PetscSFRegisterAll(void); 90 PETSC_EXTERN PetscErrorCode PetscSFRegister(const char[],PetscErrorCode (*)(PetscSF)); 91 92 PETSC_EXTERN PetscErrorCode PetscSFInitializePackage(void); 93 PETSC_EXTERN PetscErrorCode PetscSFFinalizePackage(void); 94 PETSC_EXTERN PetscErrorCode PetscSFCreate(MPI_Comm comm,PetscSF*); 95 PETSC_EXTERN PetscErrorCode PetscSFDestroy(PetscSF*); 96 PETSC_EXTERN PetscErrorCode PetscSFSetType(PetscSF,PetscSFType); 97 PETSC_EXTERN PetscErrorCode PetscSFView(PetscSF,PetscViewer); 98 PETSC_EXTERN PetscErrorCode PetscSFSetUp(PetscSF); 99 PETSC_EXTERN PetscErrorCode PetscSFSetFromOptions(PetscSF); 100 PETSC_EXTERN PetscErrorCode PetscSFDuplicate(PetscSF,PetscSFDuplicateOption,PetscSF*); 101 PETSC_EXTERN PetscErrorCode PetscSFWindowSetSyncType(PetscSF,PetscSFWindowSyncType); 102 PETSC_EXTERN PetscErrorCode PetscSFWindowGetSyncType(PetscSF,PetscSFWindowSyncType*); 103 PETSC_EXTERN PetscErrorCode PetscSFSetRankOrder(PetscSF,PetscBool); 104 PETSC_EXTERN PetscErrorCode PetscSFSetGraph(PetscSF,PetscInt,PetscInt,const PetscInt*,PetscCopyMode,const PetscSFNode*,PetscCopyMode); 105 PETSC_EXTERN PetscErrorCode PetscSFGetGraph(PetscSF,PetscInt *nroots,PetscInt *nleaves,const PetscInt **ilocal,const PetscSFNode **iremote); 106 PETSC_EXTERN PetscErrorCode PetscSFGetLeafRange(PetscSF,PetscInt*,PetscInt*); 107 PETSC_EXTERN PetscErrorCode PetscSFCreateEmbeddedSF(PetscSF,PetscInt nroots,const PetscInt *selected,PetscSF *newsf); 108 PETSC_EXTERN PetscErrorCode PetscSFReset(PetscSF); 109 PETSC_EXTERN PetscErrorCode PetscSFGetRanks(PetscSF,PetscInt*,const PetscMPIInt**,const PetscInt**,const PetscInt**,const PetscInt**); 110 PETSC_EXTERN PetscErrorCode PetscSFGetGroups(PetscSF,MPI_Group*,MPI_Group*); 111 PETSC_EXTERN PetscErrorCode PetscSFGetMultiSF(PetscSF,PetscSF*); 112 PETSC_EXTERN PetscErrorCode PetscSFCreateInverseSF(PetscSF,PetscSF*); 113 114 /* broadcasts rootdata to leafdata */ 115 PETSC_EXTERN PetscErrorCode PetscSFBcastBegin(PetscSF,MPI_Datatype,const void *rootdata,void *leafdata) 116 PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2); 117 PETSC_EXTERN PetscErrorCode PetscSFBcastEnd(PetscSF,MPI_Datatype,const void *rootdata,void *leafdata) 118 PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2); 119 /* Reduce leafdata into rootdata using provided operation */ 120 PETSC_EXTERN PetscErrorCode PetscSFReduceBegin(PetscSF,MPI_Datatype,const void *leafdata,void *rootdata,MPI_Op) 121 PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2); 122 PETSC_EXTERN PetscErrorCode PetscSFReduceEnd(PetscSF,MPI_Datatype,const void *leafdata,void *rootdata,MPI_Op) 123 PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2); 124 /* Atomically modifies (using provided operation) rootdata using leafdata from each leaf, value at root at time of modification is returned in leafupdate. */ 125 PETSC_EXTERN PetscErrorCode PetscSFFetchAndOpBegin(PetscSF,MPI_Datatype,void *rootdata,const void *leafdata,void *leafupdate,MPI_Op) 126 PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2) PetscAttrMPIPointerWithType(5,2); 127 PETSC_EXTERN PetscErrorCode PetscSFFetchAndOpEnd(PetscSF,MPI_Datatype,void *rootdata,const void *leafdata,void *leafupdate,MPI_Op) 128 PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2) PetscAttrMPIPointerWithType(5,2); 129 /* Compute the degree of every root vertex (number of leaves in its star) */ 130 PETSC_EXTERN PetscErrorCode PetscSFComputeDegreeBegin(PetscSF,const PetscInt **degree); 131 PETSC_EXTERN PetscErrorCode PetscSFComputeDegreeEnd(PetscSF,const PetscInt **degree); 132 /* Concatenate data from all leaves into roots */ 133 PETSC_EXTERN PetscErrorCode PetscSFGatherBegin(PetscSF,MPI_Datatype,const void *leafdata,void *multirootdata) 134 PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2); 135 PETSC_EXTERN PetscErrorCode PetscSFGatherEnd(PetscSF,MPI_Datatype,const void *leafdata,void *multirootdata) 136 PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2); 137 /* Distribute distinct values to each leaf from roots */ 138 PETSC_EXTERN PetscErrorCode PetscSFScatterBegin(PetscSF,MPI_Datatype,const void *multirootdata,void *leafdata) 139 PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2); 140 PETSC_EXTERN PetscErrorCode PetscSFScatterEnd(PetscSF,MPI_Datatype,const void *multirootdata,void *leafdata) 141 PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2); 142 143 #endif 144