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 11ed658588SBarry Smith PetscSF - PETSc object for setting up and managing the communication of certain entries of arrays and Vecs between MPI processes. 12936c5a86SJed Brown 13936c5a86SJed Brown Level: intermediate 14936c5a86SJed Brown 15936c5a86SJed Brown Concepts: star forest 16936c5a86SJed Brown 17*b86e365eSBarry Smith PetscSF uses the concept of star forests to indicate and determine the communication patterns concisely and efficiently. 18*b86e365eSBarry Smith 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*b86e365eSBarry Smith "ghost locations" for the root nodes. 20*b86e365eSBarry Smith 21ed658588SBarry Smith .seealso: PetscSFCreate(), VecScatter, VecScatterCreate() 22936c5a86SJed Brown S*/ 23936c5a86SJed Brown typedef struct _p_PetscSF* PetscSF; 24936c5a86SJed Brown 255af141bcSJed Brown 265af141bcSJed Brown /*J 275af141bcSJed Brown PetscSFType - String with the name of a PetscSF method or the creation function 285af141bcSJed Brown with an optional dynamic library name, for example 295af141bcSJed Brown http://www.mcs.anl.gov/petsc/lib.so:mysfcreate() 305af141bcSJed Brown 315af141bcSJed Brown Level: beginner 325af141bcSJed Brown 33ed658588SBarry Smith Notes: The two approaches provided are 34ed658588SBarry Smith $ PETSCSFBASIC which uses MPI 1 message passing to perform the communication and 35ed658588SBarry Smith $ PETSCSFWINDOW which uses MPI 2 one-sided operations to perform the communication, this may be more efficient, 36ed658588SBarry Smith $ but may not be available for all MPI distributions. In particular OpenMPI has bugs in its one-sided 37ed658588SBarry Smith $ operations that prevent its use. 38ed658588SBarry Smith 395af141bcSJed Brown .seealso: PetscSFSetType(), PetscSF 405af141bcSJed Brown J*/ 415af141bcSJed Brown typedef const char *PetscSFType; 42ac762476SJed Brown #define PETSCSFBASIC "basic" 43ed658588SBarry Smith #define PETSCSFWINDOW "window" 445af141bcSJed Brown 45936c5a86SJed Brown /*S 46936c5a86SJed Brown PetscSFNode - specifier of owner and index 47936c5a86SJed Brown 48936c5a86SJed Brown Level: beginner 49936c5a86SJed Brown 50936c5a86SJed Brown Concepts: indexing, stride, distribution 51936c5a86SJed Brown 52936c5a86SJed Brown .seealso: PetscSFSetGraph() 53936c5a86SJed Brown S*/ 54936c5a86SJed Brown typedef struct { 55936c5a86SJed Brown PetscInt rank; /* Rank of owner */ 56936c5a86SJed Brown PetscInt index; /* Index of node on rank */ 57936c5a86SJed Brown } PetscSFNode; 58936c5a86SJed Brown 59936c5a86SJed Brown /*E 605af141bcSJed Brown PetscSFWindowSyncType - Type of synchronization for PETSCSFWINDOW 61936c5a86SJed Brown 625af141bcSJed Brown $ PETSCSF_WINDOW_SYNC_FENCE - simplest model, synchronizing across communicator 635af141bcSJed Brown $ PETSCSF_WINDOW_SYNC_LOCK - passive model, less synchronous, requires less setup than PETSCSF_WINDOW_SYNC_ACTIVE, but may require more handshakes 645af141bcSJed 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) 65936c5a86SJed Brown 66e84a5f06SJed Brown Level: advanced 67936c5a86SJed Brown 68e84a5f06SJed Brown .seealso: PetscSFWindowSetSyncType(), PetscSFWindowGetSyncType() 69936c5a86SJed Brown E*/ 705af141bcSJed Brown typedef enum {PETSCSF_WINDOW_SYNC_FENCE,PETSCSF_WINDOW_SYNC_LOCK,PETSCSF_WINDOW_SYNC_ACTIVE} PetscSFWindowSyncType; 715af141bcSJed Brown PETSC_EXTERN const char *const PetscSFWindowSyncTypes[]; 72936c5a86SJed Brown 73e84a5f06SJed Brown /*E 74e84a5f06SJed Brown PetscSFDuplicateOption - Aspects to preserve when duplicating a PetscSF 75e84a5f06SJed Brown 76e84a5f06SJed Brown $ PETSCSF_DUPLICATE_CONFONLY - configuration only, user must call PetscSFSetGraph() 77e84a5f06SJed Brown $ PETSCSF_DUPLICATE_RANKS - communication ranks preserved, but different graph (allows simpler setup after calling PetscSFSetGraph()) 78e84a5f06SJed Brown $ PETSCSF_DUPLICATE_GRAPH - entire graph duplicated 79e84a5f06SJed Brown 80e84a5f06SJed Brown Level: beginner 81e84a5f06SJed Brown 82e84a5f06SJed Brown .seealso: PetscSFDuplicate() 83e84a5f06SJed Brown E*/ 84e84a5f06SJed Brown typedef enum {PETSCSF_DUPLICATE_CONFONLY,PETSCSF_DUPLICATE_RANKS,PETSCSF_DUPLICATE_GRAPH} PetscSFDuplicateOption; 85e84a5f06SJed Brown PETSC_EXTERN const char *const PetscSFDuplicateOptions[]; 86090c6444SJed Brown 87140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList PetscSFunctionList; 885af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFRegisterDestroy(void); 895af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFRegisterAll(const char[]); 905af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFRegister(const char[],const char[],const char[],PetscErrorCode (*)(PetscSF)); 915af141bcSJed Brown 925af141bcSJed Brown /*MC 935af141bcSJed Brown PetscSFRegisterDynamic - Adds an implementation of the PetscSF communication protocol. 945af141bcSJed Brown 955af141bcSJed Brown Synopsis: 96f2ba6396SBarry Smith #include "petscsf.h" 975af141bcSJed Brown PetscErrorCode PetscSFRegisterDynamic(const char *name_method,const char *path,const char *name_create,PetscErrorCode (*routine_create)(PetscSF)) 985af141bcSJed Brown 995af141bcSJed Brown Not collective 1005af141bcSJed Brown 1015af141bcSJed Brown Input Parameters: 1025af141bcSJed Brown + name_impl - name of a new user-defined implementation 1035af141bcSJed Brown . path - path (either absolute or relative) the library containing this solver 1045af141bcSJed Brown . name_create - name of routine to create method context 1055af141bcSJed Brown - routine_create - routine to create method context 1065af141bcSJed Brown 1075af141bcSJed Brown Notes: 1085af141bcSJed Brown PetscSFRegisterDynamic() may be called multiple times to add several user-defined implementations. 1095af141bcSJed Brown 1105af141bcSJed Brown If dynamic libraries are used, then the fourth input argument (routine_create) 1115af141bcSJed Brown is ignored. 1125af141bcSJed Brown 1135af141bcSJed Brown Environmental variables such as ${PETSC_ARCH}, ${PETSC_DIR}, ${PETSC_LIB_DIR}, 1145af141bcSJed Brown and others of the form ${any_environmental_variable} occuring in pathname will be 1155af141bcSJed Brown replaced with appropriate values. 1165af141bcSJed Brown 1175af141bcSJed Brown Sample usage: 1185af141bcSJed Brown .vb 1195af141bcSJed Brown PetscSFRegisterDynamic("my_impl",/home/username/my_lib/lib/libg/solaris/mylib.a, 1205af141bcSJed Brown "MyImplCreate",MyImplCreate); 1215af141bcSJed Brown .ve 1225af141bcSJed Brown 1235af141bcSJed Brown Then, this implementation can be chosen with the procedural interface via 1245af141bcSJed Brown $ PetscSFSetType(sf,"my_impl") 1255af141bcSJed Brown or at runtime via the option 1265af141bcSJed Brown $ -snes_type my_solver 1275af141bcSJed Brown 1285af141bcSJed Brown Level: advanced 1295af141bcSJed Brown 1305af141bcSJed Brown Note: If your function is not being put into a shared library then use PetscSFRegister() instead 1315af141bcSJed Brown 1325af141bcSJed Brown .keywords: PetscSF, register 1335af141bcSJed Brown 1345af141bcSJed Brown .seealso: PetscSFRegisterAll(), PetscSFRegisterDestroy() 1355af141bcSJed Brown M*/ 1365af141bcSJed Brown #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 1375af141bcSJed Brown #define PetscSFRegisterDynamic(a,b,c,d) PetscSFRegister(a,b,c,0) 1385af141bcSJed Brown #else 1395af141bcSJed Brown #define PetscSFRegisterDynamic(a,b,c,d) PetscSFRegister(a,b,c,d) 1405af141bcSJed Brown #endif 1415af141bcSJed Brown 142014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFInitializePackage(const char*); 143014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFFinalizePackage(void); 144014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFCreate(MPI_Comm comm,PetscSF*); 145014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFDestroy(PetscSF*); 1465af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFSetType(PetscSF,PetscSFType); 147014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFView(PetscSF,PetscViewer); 1485af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFSetUp(PetscSF); 149014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFSetFromOptions(PetscSF); 150e84a5f06SJed Brown PETSC_EXTERN PetscErrorCode PetscSFDuplicate(PetscSF,PetscSFDuplicateOption,PetscSF*); 1515af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFWindowSetSyncType(PetscSF,PetscSFWindowSyncType); 1525af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFWindowGetSyncType(PetscSF,PetscSFWindowSyncType*); 153014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFSetRankOrder(PetscSF,PetscBool); 15463f4a732SJed Brown PETSC_EXTERN PetscErrorCode PetscSFSetGraph(PetscSF,PetscInt,PetscInt,const PetscInt*,PetscCopyMode,const PetscSFNode*,PetscCopyMode); 155014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFGetGraph(PetscSF,PetscInt *nroots,PetscInt *nleaves,const PetscInt **ilocal,const PetscSFNode **iremote); 156f723732fSJed Brown PETSC_EXTERN PetscErrorCode PetscSFGetLeafRange(PetscSF,PetscInt*,PetscInt*); 157014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFCreateEmbeddedSF(PetscSF,PetscInt nroots,const PetscInt *selected,PetscSF *newsf); 158014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFReset(PetscSF); 1595b6cb184SJed Brown PETSC_EXTERN PetscErrorCode PetscSFGetRanks(PetscSF,PetscInt*,const PetscMPIInt**,const PetscInt**,const PetscInt**,const PetscInt**); 160014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFGetGroups(PetscSF,MPI_Group*,MPI_Group*); 161014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFGetMultiSF(PetscSF,PetscSF*); 162014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFCreateInverseSF(PetscSF,PetscSF*); 163936c5a86SJed Brown 164936c5a86SJed Brown /* broadcasts rootdata to leafdata */ 165894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFBcastBegin(PetscSF,MPI_Datatype,const void *rootdata,void *leafdata) 166894dd566SJed Brown PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2); 167894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFBcastEnd(PetscSF,MPI_Datatype,const void *rootdata,void *leafdata) 168894dd566SJed Brown PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2); 169936c5a86SJed Brown /* Reduce leafdata into rootdata using provided operation */ 170894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFReduceBegin(PetscSF,MPI_Datatype,const void *leafdata,void *rootdata,MPI_Op) 17119436ca2SJed Brown PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2); 172894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFReduceEnd(PetscSF,MPI_Datatype,const void *leafdata,void *rootdata,MPI_Op) 17319436ca2SJed Brown PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2); 174936c5a86SJed Brown /* Atomically modifies (using provided operation) rootdata using leafdata from each leaf, value at root at time of modification is returned in leafupdate. */ 175894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFFetchAndOpBegin(PetscSF,MPI_Datatype,void *rootdata,const void *leafdata,void *leafupdate,MPI_Op) 176894dd566SJed Brown PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2) PetscAttrMPIPointerWithType(5,2); 177894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFFetchAndOpEnd(PetscSF,MPI_Datatype,void *rootdata,const void *leafdata,void *leafupdate,MPI_Op) 178894dd566SJed Brown PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2) PetscAttrMPIPointerWithType(5,2); 179936c5a86SJed Brown /* Compute the degree of every root vertex (number of leaves in its star) */ 180014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFComputeDegreeBegin(PetscSF,const PetscInt **degree); 181014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFComputeDegreeEnd(PetscSF,const PetscInt **degree); 182936c5a86SJed Brown /* Concatenate data from all leaves into roots */ 183894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFGatherBegin(PetscSF,MPI_Datatype,const void *leafdata,void *multirootdata) 184894dd566SJed Brown PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2); 185894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFGatherEnd(PetscSF,MPI_Datatype,const void *leafdata,void *multirootdata) 186894dd566SJed Brown PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2); 187936c5a86SJed Brown /* Distribute distinct values to each leaf from roots */ 188894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFScatterBegin(PetscSF,MPI_Datatype,const void *multirootdata,void *leafdata) 189894dd566SJed Brown PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2); 190894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFScatterEnd(PetscSF,MPI_Datatype,const void *multirootdata,void *leafdata) 191894dd566SJed Brown PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2); 192936c5a86SJed Brown 193936c5a86SJed Brown #endif 194