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