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 communication using star forests 12 13 Level: intermediate 14 15 Concepts: star forest 16 17 .seealso: PetscSFCreate() 18 S*/ 19 typedef struct _p_PetscSF* PetscSF; 20 21 22 /*J 23 PetscSFType - String with the name of a PetscSF method or the creation function 24 with an optional dynamic library name, for example 25 http://www.mcs.anl.gov/petsc/lib.so:mysfcreate() 26 27 Level: beginner 28 29 .seealso: PetscSFSetType(), PetscSF 30 J*/ 31 typedef const char *PetscSFType; 32 #define PETSCSFWINDOW "window" 33 #define PETSCSFBASIC "basic" 34 35 /*S 36 PetscSFNode - specifier of owner and index 37 38 Level: beginner 39 40 Concepts: indexing, stride, distribution 41 42 .seealso: PetscSFSetGraph() 43 S*/ 44 typedef struct { 45 PetscInt rank; /* Rank of owner */ 46 PetscInt index; /* Index of node on rank */ 47 } PetscSFNode; 48 49 /*E 50 PetscSFWindowSyncType - Type of synchronization for PETSCSFWINDOW 51 52 $ PETSCSF_WINDOW_SYNC_FENCE - simplest model, synchronizing across communicator 53 $ PETSCSF_WINDOW_SYNC_LOCK - passive model, less synchronous, requires less setup than PETSCSF_WINDOW_SYNC_ACTIVE, but may require more handshakes 54 $ 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) 55 56 Level: beginner 57 58 .seealso: PetscSFWindowSetSyncType() 59 E*/ 60 typedef enum {PETSCSF_WINDOW_SYNC_FENCE,PETSCSF_WINDOW_SYNC_LOCK,PETSCSF_WINDOW_SYNC_ACTIVE} PetscSFWindowSyncType; 61 PETSC_EXTERN const char *const PetscSFWindowSyncTypes[]; 62 63 #if !defined(PETSC_HAVE_MPI_WIN_CREATE) /* The intent here is to be able to compile even without a complete MPI. */ 64 typedef struct MPI_Win_MISSING *MPI_Win; 65 #endif 66 67 PETSC_EXTERN PetscFList PetscSFList; 68 PETSC_EXTERN PetscErrorCode PetscSFRegisterDestroy(void); 69 PETSC_EXTERN PetscErrorCode PetscSFRegisterAll(const char[]); 70 PETSC_EXTERN PetscErrorCode PetscSFRegister(const char[],const char[],const char[],PetscErrorCode (*)(PetscSF)); 71 72 /*MC 73 PetscSFRegisterDynamic - Adds an implementation of the PetscSF communication protocol. 74 75 Synopsis: 76 PetscErrorCode PetscSFRegisterDynamic(const char *name_method,const char *path,const char *name_create,PetscErrorCode (*routine_create)(PetscSF)) 77 78 Not collective 79 80 Input Parameters: 81 + name_impl - name of a new user-defined implementation 82 . path - path (either absolute or relative) the library containing this solver 83 . name_create - name of routine to create method context 84 - routine_create - routine to create method context 85 86 Notes: 87 PetscSFRegisterDynamic() may be called multiple times to add several user-defined implementations. 88 89 If dynamic libraries are used, then the fourth input argument (routine_create) 90 is ignored. 91 92 Environmental variables such as ${PETSC_ARCH}, ${PETSC_DIR}, ${PETSC_LIB_DIR}, 93 and others of the form ${any_environmental_variable} occuring in pathname will be 94 replaced with appropriate values. 95 96 Sample usage: 97 .vb 98 PetscSFRegisterDynamic("my_impl",/home/username/my_lib/lib/libg/solaris/mylib.a, 99 "MyImplCreate",MyImplCreate); 100 .ve 101 102 Then, this implementation can be chosen with the procedural interface via 103 $ PetscSFSetType(sf,"my_impl") 104 or at runtime via the option 105 $ -snes_type my_solver 106 107 Level: advanced 108 109 Note: If your function is not being put into a shared library then use PetscSFRegister() instead 110 111 .keywords: PetscSF, register 112 113 .seealso: PetscSFRegisterAll(), PetscSFRegisterDestroy() 114 M*/ 115 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 116 #define PetscSFRegisterDynamic(a,b,c,d) PetscSFRegister(a,b,c,0) 117 #else 118 #define PetscSFRegisterDynamic(a,b,c,d) PetscSFRegister(a,b,c,d) 119 #endif 120 121 122 PETSC_EXTERN PetscErrorCode PetscSFInitializePackage(const char*); 123 PETSC_EXTERN PetscErrorCode PetscSFFinalizePackage(void); 124 PETSC_EXTERN PetscErrorCode PetscSFCreate(MPI_Comm comm,PetscSF*); 125 PETSC_EXTERN PetscErrorCode PetscSFDestroy(PetscSF*); 126 PETSC_EXTERN PetscErrorCode PetscSFSetType(PetscSF,PetscSFType); 127 PETSC_EXTERN PetscErrorCode PetscSFView(PetscSF,PetscViewer); 128 PETSC_EXTERN PetscErrorCode PetscSFSetUp(PetscSF); 129 PETSC_EXTERN PetscErrorCode PetscSFSetFromOptions(PetscSF); 130 PETSC_EXTERN PetscErrorCode PetscSFWindowSetSyncType(PetscSF,PetscSFWindowSyncType); 131 PETSC_EXTERN PetscErrorCode PetscSFWindowGetSyncType(PetscSF,PetscSFWindowSyncType*); 132 PETSC_EXTERN PetscErrorCode PetscSFSetRankOrder(PetscSF,PetscBool); 133 PETSC_EXTERN PetscErrorCode PetscSFSetGraph(PetscSF,PetscInt,PetscInt,const PetscInt*,PetscCopyMode,const PetscSFNode*,PetscCopyMode); 134 PETSC_EXTERN PetscErrorCode PetscSFGetGraph(PetscSF,PetscInt *nroots,PetscInt *nleaves,const PetscInt **ilocal,const PetscSFNode **iremote); 135 PETSC_EXTERN PetscErrorCode PetscSFGetLeafRange(PetscSF,PetscInt*,PetscInt*); 136 PETSC_EXTERN PetscErrorCode PetscSFCreateEmbeddedSF(PetscSF,PetscInt nroots,const PetscInt *selected,PetscSF *newsf); 137 PETSC_EXTERN PetscErrorCode PetscSFCreateArray(PetscSF,MPI_Datatype,void*,void*); 138 PETSC_EXTERN PetscErrorCode PetscSFDestroyArray(PetscSF,MPI_Datatype,void*,void*); 139 PETSC_EXTERN PetscErrorCode PetscSFReset(PetscSF); 140 PETSC_EXTERN PetscErrorCode PetscSFGetRanks(PetscSF,PetscInt*,const PetscMPIInt**,const PetscInt**,const PetscMPIInt**,const PetscMPIInt**); 141 PETSC_EXTERN PetscErrorCode PetscSFGetGroups(PetscSF,MPI_Group*,MPI_Group*); 142 PETSC_EXTERN PetscErrorCode PetscSFGetMultiSF(PetscSF,PetscSF*); 143 PETSC_EXTERN PetscErrorCode PetscSFCreateInverseSF(PetscSF,PetscSF*); 144 145 /* broadcasts rootdata to leafdata */ 146 PETSC_EXTERN PetscErrorCode PetscSFBcastBegin(PetscSF,MPI_Datatype,const void *rootdata,void *leafdata); 147 PETSC_EXTERN PetscErrorCode PetscSFBcastEnd(PetscSF,MPI_Datatype,const void *rootdata,void *leafdata); 148 /* Reduce leafdata into rootdata using provided operation */ 149 PETSC_EXTERN PetscErrorCode PetscSFReduceBegin(PetscSF,MPI_Datatype,const void *leafdata,void *rootdata,MPI_Op); 150 PETSC_EXTERN PetscErrorCode PetscSFReduceEnd(PetscSF,MPI_Datatype,const void *leafdata,void *rootdata,MPI_Op); 151 /* Atomically modifies (using provided operation) rootdata using leafdata from each leaf, value at root at time of modification is returned in leafupdate. */ 152 PETSC_EXTERN PetscErrorCode PetscSFFetchAndOpBegin(PetscSF,MPI_Datatype,void *rootdata,const void *leafdata,void *leafupdate,MPI_Op); 153 PETSC_EXTERN PetscErrorCode PetscSFFetchAndOpEnd(PetscSF,MPI_Datatype,void *rootdata,const void *leafdata,void *leafupdate,MPI_Op); 154 /* Compute the degree of every root vertex (number of leaves in its star) */ 155 PETSC_EXTERN PetscErrorCode PetscSFComputeDegreeBegin(PetscSF,const PetscInt **degree); 156 PETSC_EXTERN PetscErrorCode PetscSFComputeDegreeEnd(PetscSF,const PetscInt **degree); 157 /* Concatenate data from all leaves into roots */ 158 PETSC_EXTERN PetscErrorCode PetscSFGatherBegin(PetscSF,MPI_Datatype,const void *leafdata,void *multirootdata); 159 PETSC_EXTERN PetscErrorCode PetscSFGatherEnd(PetscSF,MPI_Datatype,const void *leafdata,void *multirootdata); 160 /* Distribute distinct values to each leaf from roots */ 161 PETSC_EXTERN PetscErrorCode PetscSFScatterBegin(PetscSF,MPI_Datatype,const void *multirootdata,void *leafdata); 162 PETSC_EXTERN PetscErrorCode PetscSFScatterEnd(PetscSF,MPI_Datatype,const void *multirootdata,void *leafdata); 163 164 165 #endif 166