1936c5a86SJed Brown /* 2936c5a86SJed Brown A star forest (SF) describes a communication pattern 3936c5a86SJed Brown */ 4936c5a86SJed Brown #if !defined(__PETSCSF_H) 5936c5a86SJed Brown #define __PETSCSF_H 62c8e378dSBarry Smith #include <petscsys.h> 7936c5a86SJed Brown 8014dd563SJed Brown PETSC_EXTERN PetscClassId PETSCSF_CLASSID; 9936c5a86SJed Brown 10936c5a86SJed Brown /*S 11378b0e49SJed Brown PetscSF - PETSc object for communication using star forests 12936c5a86SJed Brown 13936c5a86SJed Brown Level: intermediate 14936c5a86SJed Brown 15936c5a86SJed Brown Concepts: star forest 16936c5a86SJed Brown 17936c5a86SJed Brown .seealso: PetscSFCreate() 18936c5a86SJed Brown S*/ 19936c5a86SJed Brown typedef struct _p_PetscSF* PetscSF; 20936c5a86SJed Brown 215af141bcSJed Brown 225af141bcSJed Brown /*J 235af141bcSJed Brown PetscSFType - String with the name of a PetscSF method or the creation function 245af141bcSJed Brown with an optional dynamic library name, for example 255af141bcSJed Brown http://www.mcs.anl.gov/petsc/lib.so:mysfcreate() 265af141bcSJed Brown 275af141bcSJed Brown Level: beginner 285af141bcSJed Brown 295af141bcSJed Brown .seealso: PetscSFSetType(), PetscSF 305af141bcSJed Brown J*/ 315af141bcSJed Brown typedef const char *PetscSFType; 325af141bcSJed Brown #define PETSCSFWINDOW "window" 33ac762476SJed Brown #define PETSCSFBASIC "basic" 345af141bcSJed Brown 35936c5a86SJed Brown /*S 36936c5a86SJed Brown PetscSFNode - specifier of owner and index 37936c5a86SJed Brown 38936c5a86SJed Brown Level: beginner 39936c5a86SJed Brown 40936c5a86SJed Brown Concepts: indexing, stride, distribution 41936c5a86SJed Brown 42936c5a86SJed Brown .seealso: PetscSFSetGraph() 43936c5a86SJed Brown S*/ 44936c5a86SJed Brown typedef struct { 45936c5a86SJed Brown PetscInt rank; /* Rank of owner */ 46936c5a86SJed Brown PetscInt index; /* Index of node on rank */ 47936c5a86SJed Brown } PetscSFNode; 48936c5a86SJed Brown 49936c5a86SJed Brown /*E 505af141bcSJed Brown PetscSFWindowSyncType - Type of synchronization for PETSCSFWINDOW 51936c5a86SJed Brown 525af141bcSJed Brown $ PETSCSF_WINDOW_SYNC_FENCE - simplest model, synchronizing across communicator 535af141bcSJed Brown $ PETSCSF_WINDOW_SYNC_LOCK - passive model, less synchronous, requires less setup than PETSCSF_WINDOW_SYNC_ACTIVE, but may require more handshakes 545af141bcSJed Brown $ 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) 55936c5a86SJed Brown 56e84a5f06SJed Brown Level: advanced 57936c5a86SJed Brown 58e84a5f06SJed Brown .seealso: PetscSFWindowSetSyncType(), PetscSFWindowGetSyncType() 59936c5a86SJed Brown E*/ 605af141bcSJed Brown typedef enum {PETSCSF_WINDOW_SYNC_FENCE,PETSCSF_WINDOW_SYNC_LOCK,PETSCSF_WINDOW_SYNC_ACTIVE} PetscSFWindowSyncType; 615af141bcSJed Brown PETSC_EXTERN const char *const PetscSFWindowSyncTypes[]; 62936c5a86SJed Brown 63e84a5f06SJed Brown /*E 64e84a5f06SJed Brown PetscSFDuplicateOption - Aspects to preserve when duplicating a PetscSF 65e84a5f06SJed Brown 66e84a5f06SJed Brown $ PETSCSF_DUPLICATE_CONFONLY - configuration only, user must call PetscSFSetGraph() 67e84a5f06SJed Brown $ PETSCSF_DUPLICATE_RANKS - communication ranks preserved, but different graph (allows simpler setup after calling PetscSFSetGraph()) 68e84a5f06SJed Brown $ PETSCSF_DUPLICATE_GRAPH - entire graph duplicated 69e84a5f06SJed Brown 70e84a5f06SJed Brown Level: beginner 71e84a5f06SJed Brown 72e84a5f06SJed Brown .seealso: PetscSFDuplicate() 73e84a5f06SJed Brown E*/ 74e84a5f06SJed Brown typedef enum {PETSCSF_DUPLICATE_CONFONLY,PETSCSF_DUPLICATE_RANKS,PETSCSF_DUPLICATE_GRAPH} PetscSFDuplicateOption; 75e84a5f06SJed Brown PETSC_EXTERN const char *const PetscSFDuplicateOptions[]; 76090c6444SJed Brown 775af141bcSJed Brown PETSC_EXTERN PetscFList PetscSFList; 785af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFRegisterDestroy(void); 795af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFRegisterAll(const char[]); 805af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFRegister(const char[],const char[],const char[],PetscErrorCode (*)(PetscSF)); 815af141bcSJed Brown 825af141bcSJed Brown /*MC 835af141bcSJed Brown PetscSFRegisterDynamic - Adds an implementation of the PetscSF communication protocol. 845af141bcSJed Brown 855af141bcSJed Brown Synopsis: 865af141bcSJed Brown PetscErrorCode PetscSFRegisterDynamic(const char *name_method,const char *path,const char *name_create,PetscErrorCode (*routine_create)(PetscSF)) 875af141bcSJed Brown 885af141bcSJed Brown Not collective 895af141bcSJed Brown 905af141bcSJed Brown Input Parameters: 915af141bcSJed Brown + name_impl - name of a new user-defined implementation 925af141bcSJed Brown . path - path (either absolute or relative) the library containing this solver 935af141bcSJed Brown . name_create - name of routine to create method context 945af141bcSJed Brown - routine_create - routine to create method context 955af141bcSJed Brown 965af141bcSJed Brown Notes: 975af141bcSJed Brown PetscSFRegisterDynamic() may be called multiple times to add several user-defined implementations. 985af141bcSJed Brown 995af141bcSJed Brown If dynamic libraries are used, then the fourth input argument (routine_create) 1005af141bcSJed Brown is ignored. 1015af141bcSJed Brown 1025af141bcSJed Brown Environmental variables such as ${PETSC_ARCH}, ${PETSC_DIR}, ${PETSC_LIB_DIR}, 1035af141bcSJed Brown and others of the form ${any_environmental_variable} occuring in pathname will be 1045af141bcSJed Brown replaced with appropriate values. 1055af141bcSJed Brown 1065af141bcSJed Brown Sample usage: 1075af141bcSJed Brown .vb 1085af141bcSJed Brown PetscSFRegisterDynamic("my_impl",/home/username/my_lib/lib/libg/solaris/mylib.a, 1095af141bcSJed Brown "MyImplCreate",MyImplCreate); 1105af141bcSJed Brown .ve 1115af141bcSJed Brown 1125af141bcSJed Brown Then, this implementation can be chosen with the procedural interface via 1135af141bcSJed Brown $ PetscSFSetType(sf,"my_impl") 1145af141bcSJed Brown or at runtime via the option 1155af141bcSJed Brown $ -snes_type my_solver 1165af141bcSJed Brown 1175af141bcSJed Brown Level: advanced 1185af141bcSJed Brown 1195af141bcSJed Brown Note: If your function is not being put into a shared library then use PetscSFRegister() instead 1205af141bcSJed Brown 1215af141bcSJed Brown .keywords: PetscSF, register 1225af141bcSJed Brown 1235af141bcSJed Brown .seealso: PetscSFRegisterAll(), PetscSFRegisterDestroy() 1245af141bcSJed Brown M*/ 1255af141bcSJed Brown #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 1265af141bcSJed Brown #define PetscSFRegisterDynamic(a,b,c,d) PetscSFRegister(a,b,c,0) 1275af141bcSJed Brown #else 1285af141bcSJed Brown #define PetscSFRegisterDynamic(a,b,c,d) PetscSFRegister(a,b,c,d) 1295af141bcSJed Brown #endif 1305af141bcSJed Brown 131014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFInitializePackage(const char*); 132014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFFinalizePackage(void); 133014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFCreate(MPI_Comm comm,PetscSF*); 134014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFDestroy(PetscSF*); 1355af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFSetType(PetscSF,PetscSFType); 136014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFView(PetscSF,PetscViewer); 1375af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFSetUp(PetscSF); 138014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFSetFromOptions(PetscSF); 139e84a5f06SJed Brown PETSC_EXTERN PetscErrorCode PetscSFDuplicate(PetscSF,PetscSFDuplicateOption,PetscSF*); 1405af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFWindowSetSyncType(PetscSF,PetscSFWindowSyncType); 1415af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFWindowGetSyncType(PetscSF,PetscSFWindowSyncType*); 142014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFSetRankOrder(PetscSF,PetscBool); 14363f4a732SJed Brown PETSC_EXTERN PetscErrorCode PetscSFSetGraph(PetscSF,PetscInt,PetscInt,const PetscInt*,PetscCopyMode,const PetscSFNode*,PetscCopyMode); 144014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFGetGraph(PetscSF,PetscInt *nroots,PetscInt *nleaves,const PetscInt **ilocal,const PetscSFNode **iremote); 145f723732fSJed Brown PETSC_EXTERN PetscErrorCode PetscSFGetLeafRange(PetscSF,PetscInt*,PetscInt*); 146014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFCreateEmbeddedSF(PetscSF,PetscInt nroots,const PetscInt *selected,PetscSF *newsf); 147014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFCreateArray(PetscSF,MPI_Datatype,void*,void*); 148014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFDestroyArray(PetscSF,MPI_Datatype,void*,void*); 149014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFReset(PetscSF); 150*5b6cb184SJed Brown PETSC_EXTERN PetscErrorCode PetscSFGetRanks(PetscSF,PetscInt*,const PetscMPIInt**,const PetscInt**,const PetscInt**,const PetscInt**); 151014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFGetGroups(PetscSF,MPI_Group*,MPI_Group*); 152014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFGetMultiSF(PetscSF,PetscSF*); 153014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFCreateInverseSF(PetscSF,PetscSF*); 154936c5a86SJed Brown 155936c5a86SJed Brown /* broadcasts rootdata to leafdata */ 156014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFBcastBegin(PetscSF,MPI_Datatype,const void *rootdata,void *leafdata); 157014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFBcastEnd(PetscSF,MPI_Datatype,const void *rootdata,void *leafdata); 158936c5a86SJed Brown /* Reduce leafdata into rootdata using provided operation */ 159014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFReduceBegin(PetscSF,MPI_Datatype,const void *leafdata,void *rootdata,MPI_Op); 160014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFReduceEnd(PetscSF,MPI_Datatype,const void *leafdata,void *rootdata,MPI_Op); 161936c5a86SJed Brown /* Atomically modifies (using provided operation) rootdata using leafdata from each leaf, value at root at time of modification is returned in leafupdate. */ 162014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFFetchAndOpBegin(PetscSF,MPI_Datatype,void *rootdata,const void *leafdata,void *leafupdate,MPI_Op); 163014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFFetchAndOpEnd(PetscSF,MPI_Datatype,void *rootdata,const void *leafdata,void *leafupdate,MPI_Op); 164936c5a86SJed Brown /* Compute the degree of every root vertex (number of leaves in its star) */ 165014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFComputeDegreeBegin(PetscSF,const PetscInt **degree); 166014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFComputeDegreeEnd(PetscSF,const PetscInt **degree); 167936c5a86SJed Brown /* Concatenate data from all leaves into roots */ 168014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFGatherBegin(PetscSF,MPI_Datatype,const void *leafdata,void *multirootdata); 169014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFGatherEnd(PetscSF,MPI_Datatype,const void *leafdata,void *multirootdata); 170936c5a86SJed Brown /* Distribute distinct values to each leaf from roots */ 171014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFScatterBegin(PetscSF,MPI_Datatype,const void *multirootdata,void *leafdata); 172014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFScatterEnd(PetscSF,MPI_Datatype,const void *multirootdata,void *leafdata); 173936c5a86SJed Brown 174936c5a86SJed Brown 175936c5a86SJed Brown #endif 176