xref: /petsc/include/petscsf.h (revision ed658588eb05d09994f6f527a4f3ebdd29d7f3ac)
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
11*ed658588SBarry Smith    PetscSF - PETSc object for setting up and managing the communication of certain entries of arrays and Vecs between MPI processes.
12*ed658588SBarry Smith              It uses the concept of star forests to indicate and determine the communication patterns concisely and efficiently.
13936c5a86SJed Brown 
14936c5a86SJed Brown    Level: intermediate
15936c5a86SJed Brown 
16936c5a86SJed Brown   Concepts: star forest
17936c5a86SJed Brown 
18*ed658588SBarry Smith .seealso: PetscSFCreate(), VecScatter, VecScatterCreate()
19936c5a86SJed Brown S*/
20936c5a86SJed Brown typedef struct _p_PetscSF* PetscSF;
21936c5a86SJed Brown 
225af141bcSJed Brown 
235af141bcSJed Brown /*J
245af141bcSJed Brown     PetscSFType - String with the name of a PetscSF method or the creation function
255af141bcSJed Brown        with an optional dynamic library name, for example
265af141bcSJed Brown        http://www.mcs.anl.gov/petsc/lib.so:mysfcreate()
275af141bcSJed Brown 
285af141bcSJed Brown    Level: beginner
295af141bcSJed Brown 
30*ed658588SBarry Smith    Notes: The two approaches provided are
31*ed658588SBarry Smith $     PETSCSFBASIC which uses MPI 1 message passing to perform the communication and
32*ed658588SBarry Smith $     PETSCSFWINDOW which uses MPI 2 one-sided operations to perform the communication, this may be more efficient,
33*ed658588SBarry Smith $                   but may not be available for all MPI distributions. In particular OpenMPI has bugs in its one-sided
34*ed658588SBarry Smith $                   operations that prevent its use.
35*ed658588SBarry Smith 
365af141bcSJed Brown .seealso: PetscSFSetType(), PetscSF
375af141bcSJed Brown J*/
385af141bcSJed Brown typedef const char *PetscSFType;
39ac762476SJed Brown #define PETSCSFBASIC  "basic"
40*ed658588SBarry Smith #define PETSCSFWINDOW "window"
415af141bcSJed Brown 
42936c5a86SJed Brown /*S
43936c5a86SJed Brown    PetscSFNode - specifier of owner and index
44936c5a86SJed Brown 
45936c5a86SJed Brown    Level: beginner
46936c5a86SJed Brown 
47936c5a86SJed Brown   Concepts: indexing, stride, distribution
48936c5a86SJed Brown 
49936c5a86SJed Brown .seealso: PetscSFSetGraph()
50936c5a86SJed Brown S*/
51936c5a86SJed Brown typedef struct {
52936c5a86SJed Brown   PetscInt rank;                /* Rank of owner */
53936c5a86SJed Brown   PetscInt index;               /* Index of node on rank */
54936c5a86SJed Brown } PetscSFNode;
55936c5a86SJed Brown 
56936c5a86SJed Brown /*E
575af141bcSJed Brown     PetscSFWindowSyncType - Type of synchronization for PETSCSFWINDOW
58936c5a86SJed Brown 
595af141bcSJed Brown $  PETSCSF_WINDOW_SYNC_FENCE - simplest model, synchronizing across communicator
605af141bcSJed Brown $  PETSCSF_WINDOW_SYNC_LOCK - passive model, less synchronous, requires less setup than PETSCSF_WINDOW_SYNC_ACTIVE, but may require more handshakes
615af141bcSJed 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)
62936c5a86SJed Brown 
63e84a5f06SJed Brown    Level: advanced
64936c5a86SJed Brown 
65e84a5f06SJed Brown .seealso: PetscSFWindowSetSyncType(), PetscSFWindowGetSyncType()
66936c5a86SJed Brown E*/
675af141bcSJed Brown typedef enum {PETSCSF_WINDOW_SYNC_FENCE,PETSCSF_WINDOW_SYNC_LOCK,PETSCSF_WINDOW_SYNC_ACTIVE} PetscSFWindowSyncType;
685af141bcSJed Brown PETSC_EXTERN const char *const PetscSFWindowSyncTypes[];
69936c5a86SJed Brown 
70e84a5f06SJed Brown /*E
71e84a5f06SJed Brown     PetscSFDuplicateOption - Aspects to preserve when duplicating a PetscSF
72e84a5f06SJed Brown 
73e84a5f06SJed Brown $  PETSCSF_DUPLICATE_CONFONLY - configuration only, user must call PetscSFSetGraph()
74e84a5f06SJed Brown $  PETSCSF_DUPLICATE_RANKS - communication ranks preserved, but different graph (allows simpler setup after calling PetscSFSetGraph())
75e84a5f06SJed Brown $  PETSCSF_DUPLICATE_GRAPH - entire graph duplicated
76e84a5f06SJed Brown 
77e84a5f06SJed Brown    Level: beginner
78e84a5f06SJed Brown 
79e84a5f06SJed Brown .seealso: PetscSFDuplicate()
80e84a5f06SJed Brown E*/
81e84a5f06SJed Brown typedef enum {PETSCSF_DUPLICATE_CONFONLY,PETSCSF_DUPLICATE_RANKS,PETSCSF_DUPLICATE_GRAPH} PetscSFDuplicateOption;
82e84a5f06SJed Brown PETSC_EXTERN const char *const PetscSFDuplicateOptions[];
83090c6444SJed Brown 
84140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList PetscSFunctionList;
855af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFRegisterDestroy(void);
865af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFRegisterAll(const char[]);
875af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFRegister(const char[],const char[],const char[],PetscErrorCode (*)(PetscSF));
885af141bcSJed Brown 
895af141bcSJed Brown /*MC
905af141bcSJed Brown    PetscSFRegisterDynamic - Adds an implementation of the PetscSF communication protocol.
915af141bcSJed Brown 
925af141bcSJed Brown    Synopsis:
93f2ba6396SBarry Smith     #include "petscsf.h"
945af141bcSJed Brown    PetscErrorCode PetscSFRegisterDynamic(const char *name_method,const char *path,const char *name_create,PetscErrorCode (*routine_create)(PetscSF))
955af141bcSJed Brown 
965af141bcSJed Brown    Not collective
975af141bcSJed Brown 
985af141bcSJed Brown    Input Parameters:
995af141bcSJed Brown +  name_impl - name of a new user-defined implementation
1005af141bcSJed Brown .  path - path (either absolute or relative) the library containing this solver
1015af141bcSJed Brown .  name_create - name of routine to create method context
1025af141bcSJed Brown -  routine_create - routine to create method context
1035af141bcSJed Brown 
1045af141bcSJed Brown    Notes:
1055af141bcSJed Brown    PetscSFRegisterDynamic() may be called multiple times to add several user-defined implementations.
1065af141bcSJed Brown 
1075af141bcSJed Brown    If dynamic libraries are used, then the fourth input argument (routine_create)
1085af141bcSJed Brown    is ignored.
1095af141bcSJed Brown 
1105af141bcSJed Brown    Environmental variables such as ${PETSC_ARCH}, ${PETSC_DIR}, ${PETSC_LIB_DIR},
1115af141bcSJed Brown    and others of the form ${any_environmental_variable} occuring in pathname will be
1125af141bcSJed Brown    replaced with appropriate values.
1135af141bcSJed Brown 
1145af141bcSJed Brown    Sample usage:
1155af141bcSJed Brown .vb
1165af141bcSJed Brown    PetscSFRegisterDynamic("my_impl",/home/username/my_lib/lib/libg/solaris/mylib.a,
1175af141bcSJed Brown                 "MyImplCreate",MyImplCreate);
1185af141bcSJed Brown .ve
1195af141bcSJed Brown 
1205af141bcSJed Brown    Then, this implementation can be chosen with the procedural interface via
1215af141bcSJed Brown $     PetscSFSetType(sf,"my_impl")
1225af141bcSJed Brown    or at runtime via the option
1235af141bcSJed Brown $     -snes_type my_solver
1245af141bcSJed Brown 
1255af141bcSJed Brown    Level: advanced
1265af141bcSJed Brown 
1275af141bcSJed Brown     Note: If your function is not being put into a shared library then use PetscSFRegister() instead
1285af141bcSJed Brown 
1295af141bcSJed Brown .keywords: PetscSF, register
1305af141bcSJed Brown 
1315af141bcSJed Brown .seealso: PetscSFRegisterAll(), PetscSFRegisterDestroy()
1325af141bcSJed Brown M*/
1335af141bcSJed Brown #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
1345af141bcSJed Brown #define PetscSFRegisterDynamic(a,b,c,d) PetscSFRegister(a,b,c,0)
1355af141bcSJed Brown #else
1365af141bcSJed Brown #define PetscSFRegisterDynamic(a,b,c,d) PetscSFRegister(a,b,c,d)
1375af141bcSJed Brown #endif
1385af141bcSJed Brown 
139014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFInitializePackage(const char*);
140014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFFinalizePackage(void);
141014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFCreate(MPI_Comm comm,PetscSF*);
142014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFDestroy(PetscSF*);
1435af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFSetType(PetscSF,PetscSFType);
144014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFView(PetscSF,PetscViewer);
1455af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFSetUp(PetscSF);
146014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFSetFromOptions(PetscSF);
147e84a5f06SJed Brown PETSC_EXTERN PetscErrorCode PetscSFDuplicate(PetscSF,PetscSFDuplicateOption,PetscSF*);
1485af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFWindowSetSyncType(PetscSF,PetscSFWindowSyncType);
1495af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFWindowGetSyncType(PetscSF,PetscSFWindowSyncType*);
150014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFSetRankOrder(PetscSF,PetscBool);
15163f4a732SJed Brown PETSC_EXTERN PetscErrorCode PetscSFSetGraph(PetscSF,PetscInt,PetscInt,const PetscInt*,PetscCopyMode,const PetscSFNode*,PetscCopyMode);
152014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFGetGraph(PetscSF,PetscInt *nroots,PetscInt *nleaves,const PetscInt **ilocal,const PetscSFNode **iremote);
153f723732fSJed Brown PETSC_EXTERN PetscErrorCode PetscSFGetLeafRange(PetscSF,PetscInt*,PetscInt*);
154014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFCreateEmbeddedSF(PetscSF,PetscInt nroots,const PetscInt *selected,PetscSF *newsf);
155014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFReset(PetscSF);
1565b6cb184SJed Brown PETSC_EXTERN PetscErrorCode PetscSFGetRanks(PetscSF,PetscInt*,const PetscMPIInt**,const PetscInt**,const PetscInt**,const PetscInt**);
157014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFGetGroups(PetscSF,MPI_Group*,MPI_Group*);
158014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFGetMultiSF(PetscSF,PetscSF*);
159014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFCreateInverseSF(PetscSF,PetscSF*);
160936c5a86SJed Brown 
161936c5a86SJed Brown /* broadcasts rootdata to leafdata */
162894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFBcastBegin(PetscSF,MPI_Datatype,const void *rootdata,void *leafdata)
163894dd566SJed Brown   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
164894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFBcastEnd(PetscSF,MPI_Datatype,const void *rootdata,void *leafdata)
165894dd566SJed Brown   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
166936c5a86SJed Brown /* Reduce leafdata into rootdata using provided operation */
167894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFReduceBegin(PetscSF,MPI_Datatype,const void *leafdata,void *rootdata,MPI_Op)
16819436ca2SJed Brown   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
169894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFReduceEnd(PetscSF,MPI_Datatype,const void *leafdata,void *rootdata,MPI_Op)
17019436ca2SJed Brown   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
171936c5a86SJed Brown /* Atomically modifies (using provided operation) rootdata using leafdata from each leaf, value at root at time of modification is returned in leafupdate. */
172894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFFetchAndOpBegin(PetscSF,MPI_Datatype,void *rootdata,const void *leafdata,void *leafupdate,MPI_Op)
173894dd566SJed Brown   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2) PetscAttrMPIPointerWithType(5,2);
174894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFFetchAndOpEnd(PetscSF,MPI_Datatype,void *rootdata,const void *leafdata,void *leafupdate,MPI_Op)
175894dd566SJed Brown   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2) PetscAttrMPIPointerWithType(5,2);
176936c5a86SJed Brown /* Compute the degree of every root vertex (number of leaves in its star) */
177014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFComputeDegreeBegin(PetscSF,const PetscInt **degree);
178014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFComputeDegreeEnd(PetscSF,const PetscInt **degree);
179936c5a86SJed Brown /* Concatenate data from all leaves into roots */
180894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFGatherBegin(PetscSF,MPI_Datatype,const void *leafdata,void *multirootdata)
181894dd566SJed Brown   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
182894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFGatherEnd(PetscSF,MPI_Datatype,const void *leafdata,void *multirootdata)
183894dd566SJed Brown   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
184936c5a86SJed Brown /* Distribute distinct values to each leaf from roots */
185894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFScatterBegin(PetscSF,MPI_Datatype,const void *multirootdata,void *leafdata)
186894dd566SJed Brown   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
187894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFScatterEnd(PetscSF,MPI_Datatype,const void *multirootdata,void *leafdata)
188894dd566SJed Brown   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
189936c5a86SJed Brown 
190936c5a86SJed Brown #endif
191