1*936c5a86SJed Brown /* 2*936c5a86SJed Brown A star forest (SF) describes a communication pattern 3*936c5a86SJed Brown */ 4*936c5a86SJed Brown #if !defined(__PETSCSF_H) 5*936c5a86SJed Brown #define __PETSCSF_H 6*936c5a86SJed Brown #include "petscsys.h" 7*936c5a86SJed Brown PETSC_EXTERN_CXX_BEGIN 8*936c5a86SJed Brown 9*936c5a86SJed Brown extern PetscClassId PETSCSF_CLASSID; 10*936c5a86SJed Brown 11*936c5a86SJed Brown /*S 12*936c5a86SJed Brown PetscSF - PETSc object for communication using a bipartite graph 13*936c5a86SJed Brown 14*936c5a86SJed Brown Level: intermediate 15*936c5a86SJed Brown 16*936c5a86SJed Brown Concepts: star forest 17*936c5a86SJed Brown 18*936c5a86SJed Brown .seealso: PetscSFCreate() 19*936c5a86SJed Brown S*/ 20*936c5a86SJed Brown typedef struct _p_PetscSF* PetscSF; 21*936c5a86SJed Brown 22*936c5a86SJed Brown /*S 23*936c5a86SJed Brown PetscSFNode - specifier of owner and index 24*936c5a86SJed Brown 25*936c5a86SJed Brown Level: beginner 26*936c5a86SJed Brown 27*936c5a86SJed Brown Concepts: indexing, stride, distribution 28*936c5a86SJed Brown 29*936c5a86SJed Brown .seealso: PetscSFSetGraph() 30*936c5a86SJed Brown S*/ 31*936c5a86SJed Brown typedef struct { 32*936c5a86SJed Brown PetscInt rank; /* Rank of owner */ 33*936c5a86SJed Brown PetscInt index; /* Index of node on rank */ 34*936c5a86SJed Brown } PetscSFNode; 35*936c5a86SJed Brown 36*936c5a86SJed Brown /*E 37*936c5a86SJed Brown PetscSFSynchronizationType - Type of synchronization for PetscSF 38*936c5a86SJed Brown 39*936c5a86SJed Brown $ PETSCSF_SYNCHRONIZATION_FENCE - simplest model, synchronizing across communicator 40*936c5a86SJed Brown $ PETSCSF_SYNCHRONIZATION_LOCK - passive model, less synchronous, requires less setup than PETSCSF_SYNCHRONIZATION_ACTIVE, but may require more handshakes 41*936c5a86SJed Brown $ PETSCSF_SYNCHRONIZATION_ACTIVE - active model, provides most information to MPI implementation, needs to construct 2-way process groups (more setup than PETSCSF_SYNCHRONIZATION_LOCK) 42*936c5a86SJed Brown 43*936c5a86SJed Brown Level: beginner 44*936c5a86SJed Brown 45*936c5a86SJed Brown .seealso: PetscSFSetSynchronizationType() 46*936c5a86SJed Brown E*/ 47*936c5a86SJed Brown typedef enum {PETSCSF_SYNCHRONIZATION_FENCE,PETSCSF_SYNCHRONIZATION_LOCK,PETSCSF_SYNCHRONIZATION_ACTIVE} PetscSFSynchronizationType; 48*936c5a86SJed Brown extern const char *const PetscSFSynchronizationTypes[]; 49*936c5a86SJed Brown 50*936c5a86SJed Brown extern PetscErrorCode PetscSFInitializePackage(const char*); 51*936c5a86SJed Brown extern PetscErrorCode PetscSFFinalizePackage(void); 52*936c5a86SJed Brown extern PetscErrorCode PetscSFCreate(MPI_Comm comm,PetscSF*); 53*936c5a86SJed Brown extern PetscErrorCode PetscSFDestroy(PetscSF*); 54*936c5a86SJed Brown extern PetscErrorCode PetscSFView(PetscSF,PetscViewer); 55*936c5a86SJed Brown extern PetscErrorCode PetscSFSetFromOptions(PetscSF); 56*936c5a86SJed Brown extern PetscErrorCode PetscSFSetSynchronizationType(PetscSF,PetscSFSynchronizationType); 57*936c5a86SJed Brown extern PetscErrorCode PetscSFSetRankOrder(PetscSF,PetscBool); 58*936c5a86SJed Brown extern PetscErrorCode PetscSFSetGraph(PetscSF,PetscInt nroots,PetscInt nleaves,const PetscInt *ilocal,PetscCopyMode modelocal,const PetscSFNode *remote,PetscCopyMode moderemote); 59*936c5a86SJed Brown extern PetscErrorCode PetscSFCreateArray(PetscSF,MPI_Datatype,void*,void*); 60*936c5a86SJed Brown extern PetscErrorCode PetscSFDestroyArray(PetscSF,MPI_Datatype,void*,void*); 61*936c5a86SJed Brown extern PetscErrorCode PetscSFReset(PetscSF); 62*936c5a86SJed Brown extern PetscErrorCode PetscSFGetRanks(PetscSF,PetscInt*,const PetscInt**,const PetscInt**,const PetscMPIInt**,const PetscMPIInt**); 63*936c5a86SJed Brown extern PetscErrorCode PetscSFGetDataTypes(PetscSF,MPI_Datatype,const MPI_Datatype**,const MPI_Datatype**); 64*936c5a86SJed Brown extern PetscErrorCode PetscSFGetWindow(PetscSF,MPI_Datatype,void*,PetscBool,PetscMPIInt,PetscMPIInt,PetscMPIInt,MPI_Win*); 65*936c5a86SJed Brown extern PetscErrorCode PetscSFFindWindow(PetscSF,MPI_Datatype,const void*,MPI_Win*); 66*936c5a86SJed Brown extern PetscErrorCode PetscSFRestoreWindow(PetscSF,MPI_Datatype,const void*,PetscBool,PetscMPIInt,MPI_Win*); 67*936c5a86SJed Brown extern PetscErrorCode PetscSFGetGroups(PetscSF,MPI_Group*,MPI_Group*); 68*936c5a86SJed Brown extern PetscErrorCode PetscSFGetMultiSF(PetscSF,PetscSF*); 69*936c5a86SJed Brown 70*936c5a86SJed Brown /* broadcasts rootdata to leafdata */ 71*936c5a86SJed Brown extern PetscErrorCode PetscSFBcastBegin(PetscSF,MPI_Datatype,const void *rootdata,void *leafdata); 72*936c5a86SJed Brown extern PetscErrorCode PetscSFBcastEnd(PetscSF,MPI_Datatype,const void *rootdata,void *leafdata); 73*936c5a86SJed Brown /* Reduce leafdata into rootdata using provided operation */ 74*936c5a86SJed Brown extern PetscErrorCode PetscSFReduceBegin(PetscSF,MPI_Datatype,const void *leafdata,void *rootdata,MPI_Op); 75*936c5a86SJed Brown extern PetscErrorCode PetscSFReduceEnd(PetscSF,MPI_Datatype,const void *leafdata,void *rootdata,MPI_Op); 76*936c5a86SJed Brown /* Atomically modifies (using provided operation) rootdata using leafdata from each leaf, value at root at time of modification is returned in leafupdate. */ 77*936c5a86SJed Brown extern PetscErrorCode PetscSFFetchAndOpBegin(PetscSF,MPI_Datatype,void *rootdata,const void *leafdata,void *leafupdate,MPI_Op); 78*936c5a86SJed Brown extern PetscErrorCode PetscSFFetchAndOpEnd(PetscSF,MPI_Datatype,void *rootdata,const void *leafdata,void *leafupdate,MPI_Op); 79*936c5a86SJed Brown /* Compute the degree of every root vertex (number of leaves in its star) */ 80*936c5a86SJed Brown extern PetscErrorCode PetscSFComputeDegreeBegin(PetscSF,const PetscInt **degree); 81*936c5a86SJed Brown extern PetscErrorCode PetscSFComputeDegreeEnd(PetscSF,const PetscInt **degree); 82*936c5a86SJed Brown /* Concatenate data from all leaves into roots */ 83*936c5a86SJed Brown extern PetscErrorCode PetscSFGatherBegin(PetscSF,MPI_Datatype,const void *leafdata,void *multirootdata); 84*936c5a86SJed Brown extern PetscErrorCode PetscSFGatherEnd(PetscSF,MPI_Datatype,const void *leafdata,void *multirootdata); 85*936c5a86SJed Brown /* Distribute distinct values to each leaf from roots */ 86*936c5a86SJed Brown extern PetscErrorCode PetscSFScatterBegin(PetscSF,MPI_Datatype,const void *multirootdata,void *leafdata); 87*936c5a86SJed Brown extern PetscErrorCode PetscSFScatterEnd(PetscSF,MPI_Datatype,const void *multirootdata,void *leafdata); 88*936c5a86SJed Brown 89*936c5a86SJed Brown PETSC_EXTERN_CXX_END 90*936c5a86SJed Brown 91*936c5a86SJed Brown #endif 92