xref: /petsc/include/petscsf.h (revision 2205254efee3a00a594e5e2a3a70f74dcb40bc03)
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: advanced
57 
58 .seealso: PetscSFWindowSetSyncType(), PetscSFWindowGetSyncType()
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 /*E
64     PetscSFDuplicateOption - Aspects to preserve when duplicating a PetscSF
65 
66 $  PETSCSF_DUPLICATE_CONFONLY - configuration only, user must call PetscSFSetGraph()
67 $  PETSCSF_DUPLICATE_RANKS - communication ranks preserved, but different graph (allows simpler setup after calling PetscSFSetGraph())
68 $  PETSCSF_DUPLICATE_GRAPH - entire graph duplicated
69 
70    Level: beginner
71 
72 .seealso: PetscSFDuplicate()
73 E*/
74 typedef enum {PETSCSF_DUPLICATE_CONFONLY,PETSCSF_DUPLICATE_RANKS,PETSCSF_DUPLICATE_GRAPH} PetscSFDuplicateOption;
75 PETSC_EXTERN const char *const PetscSFDuplicateOptions[];
76 
77 PETSC_EXTERN PetscFunctionList PetscSFunctionList;
78 PETSC_EXTERN PetscErrorCode PetscSFRegisterDestroy(void);
79 PETSC_EXTERN PetscErrorCode PetscSFRegisterAll(const char[]);
80 PETSC_EXTERN PetscErrorCode PetscSFRegister(const char[],const char[],const char[],PetscErrorCode (*)(PetscSF));
81 
82 /*MC
83    PetscSFRegisterDynamic - Adds an implementation of the PetscSF communication protocol.
84 
85    Synopsis:
86     #include "petscsf.h"
87    PetscErrorCode PetscSFRegisterDynamic(const char *name_method,const char *path,const char *name_create,PetscErrorCode (*routine_create)(PetscSF))
88 
89    Not collective
90 
91    Input Parameters:
92 +  name_impl - name of a new user-defined implementation
93 .  path - path (either absolute or relative) the library containing this solver
94 .  name_create - name of routine to create method context
95 -  routine_create - routine to create method context
96 
97    Notes:
98    PetscSFRegisterDynamic() may be called multiple times to add several user-defined implementations.
99 
100    If dynamic libraries are used, then the fourth input argument (routine_create)
101    is ignored.
102 
103    Environmental variables such as ${PETSC_ARCH}, ${PETSC_DIR}, ${PETSC_LIB_DIR},
104    and others of the form ${any_environmental_variable} occuring in pathname will be
105    replaced with appropriate values.
106 
107    Sample usage:
108 .vb
109    PetscSFRegisterDynamic("my_impl",/home/username/my_lib/lib/libg/solaris/mylib.a,
110                 "MyImplCreate",MyImplCreate);
111 .ve
112 
113    Then, this implementation can be chosen with the procedural interface via
114 $     PetscSFSetType(sf,"my_impl")
115    or at runtime via the option
116 $     -snes_type my_solver
117 
118    Level: advanced
119 
120     Note: If your function is not being put into a shared library then use PetscSFRegister() instead
121 
122 .keywords: PetscSF, register
123 
124 .seealso: PetscSFRegisterAll(), PetscSFRegisterDestroy()
125 M*/
126 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
127 #define PetscSFRegisterDynamic(a,b,c,d) PetscSFRegister(a,b,c,0)
128 #else
129 #define PetscSFRegisterDynamic(a,b,c,d) PetscSFRegister(a,b,c,d)
130 #endif
131 
132 PETSC_EXTERN PetscErrorCode PetscSFInitializePackage(const char*);
133 PETSC_EXTERN PetscErrorCode PetscSFFinalizePackage(void);
134 PETSC_EXTERN PetscErrorCode PetscSFCreate(MPI_Comm comm,PetscSF*);
135 PETSC_EXTERN PetscErrorCode PetscSFDestroy(PetscSF*);
136 PETSC_EXTERN PetscErrorCode PetscSFSetType(PetscSF,PetscSFType);
137 PETSC_EXTERN PetscErrorCode PetscSFView(PetscSF,PetscViewer);
138 PETSC_EXTERN PetscErrorCode PetscSFSetUp(PetscSF);
139 PETSC_EXTERN PetscErrorCode PetscSFSetFromOptions(PetscSF);
140 PETSC_EXTERN PetscErrorCode PetscSFDuplicate(PetscSF,PetscSFDuplicateOption,PetscSF*);
141 PETSC_EXTERN PetscErrorCode PetscSFWindowSetSyncType(PetscSF,PetscSFWindowSyncType);
142 PETSC_EXTERN PetscErrorCode PetscSFWindowGetSyncType(PetscSF,PetscSFWindowSyncType*);
143 PETSC_EXTERN PetscErrorCode PetscSFSetRankOrder(PetscSF,PetscBool);
144 PETSC_EXTERN PetscErrorCode PetscSFSetGraph(PetscSF,PetscInt,PetscInt,const PetscInt*,PetscCopyMode,const PetscSFNode*,PetscCopyMode);
145 PETSC_EXTERN PetscErrorCode PetscSFGetGraph(PetscSF,PetscInt *nroots,PetscInt *nleaves,const PetscInt **ilocal,const PetscSFNode **iremote);
146 PETSC_EXTERN PetscErrorCode PetscSFGetLeafRange(PetscSF,PetscInt*,PetscInt*);
147 PETSC_EXTERN PetscErrorCode PetscSFCreateEmbeddedSF(PetscSF,PetscInt nroots,const PetscInt *selected,PetscSF *newsf);
148 PETSC_EXTERN PetscErrorCode PetscSFReset(PetscSF);
149 PETSC_EXTERN PetscErrorCode PetscSFGetRanks(PetscSF,PetscInt*,const PetscMPIInt**,const PetscInt**,const PetscInt**,const PetscInt**);
150 PETSC_EXTERN PetscErrorCode PetscSFGetGroups(PetscSF,MPI_Group*,MPI_Group*);
151 PETSC_EXTERN PetscErrorCode PetscSFGetMultiSF(PetscSF,PetscSF*);
152 PETSC_EXTERN PetscErrorCode PetscSFCreateInverseSF(PetscSF,PetscSF*);
153 
154 /* broadcasts rootdata to leafdata */
155 PETSC_EXTERN PetscErrorCode PetscSFBcastBegin(PetscSF,MPI_Datatype,const void *rootdata,void *leafdata)
156   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
157 PETSC_EXTERN PetscErrorCode PetscSFBcastEnd(PetscSF,MPI_Datatype,const void *rootdata,void *leafdata)
158   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
159 /* Reduce leafdata into rootdata using provided operation */
160 PETSC_EXTERN PetscErrorCode PetscSFReduceBegin(PetscSF,MPI_Datatype,const void *leafdata,void *rootdata,MPI_Op)
161   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
162 PETSC_EXTERN PetscErrorCode PetscSFReduceEnd(PetscSF,MPI_Datatype,const void *leafdata,void *rootdata,MPI_Op)
163   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
164 /* Atomically modifies (using provided operation) rootdata using leafdata from each leaf, value at root at time of modification is returned in leafupdate. */
165 PETSC_EXTERN PetscErrorCode PetscSFFetchAndOpBegin(PetscSF,MPI_Datatype,void *rootdata,const void *leafdata,void *leafupdate,MPI_Op)
166   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2) PetscAttrMPIPointerWithType(5,2);
167 PETSC_EXTERN PetscErrorCode PetscSFFetchAndOpEnd(PetscSF,MPI_Datatype,void *rootdata,const void *leafdata,void *leafupdate,MPI_Op)
168   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2) PetscAttrMPIPointerWithType(5,2);
169 /* Compute the degree of every root vertex (number of leaves in its star) */
170 PETSC_EXTERN PetscErrorCode PetscSFComputeDegreeBegin(PetscSF,const PetscInt **degree);
171 PETSC_EXTERN PetscErrorCode PetscSFComputeDegreeEnd(PetscSF,const PetscInt **degree);
172 /* Concatenate data from all leaves into roots */
173 PETSC_EXTERN PetscErrorCode PetscSFGatherBegin(PetscSF,MPI_Datatype,const void *leafdata,void *multirootdata)
174   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
175 PETSC_EXTERN PetscErrorCode PetscSFGatherEnd(PetscSF,MPI_Datatype,const void *leafdata,void *multirootdata)
176   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
177 /* Distribute distinct values to each leaf from roots */
178 PETSC_EXTERN PetscErrorCode PetscSFScatterBegin(PetscSF,MPI_Datatype,const void *multirootdata,void *leafdata)
179   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
180 PETSC_EXTERN PetscErrorCode PetscSFScatterEnd(PetscSF,MPI_Datatype,const void *multirootdata,void *leafdata)
181   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
182 
183 #endif
184