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