xref: /petsc/include/petscsf.h (revision adc40e5b25f0fa6b1e5761662f92c58850a98222)
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
11ed658588SBarry Smith    PetscSF - PETSc object for setting up and managing the communication of certain entries of arrays and Vecs between MPI processes.
12936c5a86SJed Brown 
13936c5a86SJed Brown    Level: intermediate
14936c5a86SJed Brown 
15936c5a86SJed Brown   Concepts: star forest
16936c5a86SJed Brown 
17b86e365eSBarry Smith        PetscSF uses the concept of star forests to indicate and determine the communication patterns concisely and efficiently.
18b86e365eSBarry Smith   A star  http://en.wikipedia.org/wiki/Star_(graph_theory) forest is simply a collection of trees of height 1. The leave nodes represent
19b86e365eSBarry Smith   "ghost locations" for the root nodes.
20b86e365eSBarry Smith 
21ed658588SBarry Smith .seealso: PetscSFCreate(), VecScatter, VecScatterCreate()
22936c5a86SJed Brown S*/
23936c5a86SJed Brown typedef struct _p_PetscSF* PetscSF;
24936c5a86SJed Brown 
255af141bcSJed Brown 
265af141bcSJed Brown /*J
275af141bcSJed Brown     PetscSFType - String with the name of a PetscSF method or the creation function
285af141bcSJed Brown        with an optional dynamic library name, for example
295af141bcSJed Brown        http://www.mcs.anl.gov/petsc/lib.so:mysfcreate()
305af141bcSJed Brown 
315af141bcSJed Brown    Level: beginner
325af141bcSJed Brown 
33ed658588SBarry Smith    Notes: The two approaches provided are
34ed658588SBarry Smith $     PETSCSFBASIC which uses MPI 1 message passing to perform the communication and
35ed658588SBarry Smith $     PETSCSFWINDOW which uses MPI 2 one-sided operations to perform the communication, this may be more efficient,
36ed658588SBarry Smith $                   but may not be available for all MPI distributions. In particular OpenMPI has bugs in its one-sided
37ed658588SBarry Smith $                   operations that prevent its use.
38ed658588SBarry Smith 
395af141bcSJed Brown .seealso: PetscSFSetType(), PetscSF
405af141bcSJed Brown J*/
415af141bcSJed Brown typedef const char *PetscSFType;
42ac762476SJed Brown #define PETSCSFBASIC  "basic"
43ed658588SBarry Smith #define PETSCSFWINDOW "window"
445af141bcSJed Brown 
45936c5a86SJed Brown /*S
46936c5a86SJed Brown    PetscSFNode - specifier of owner and index
47936c5a86SJed Brown 
48936c5a86SJed Brown    Level: beginner
49936c5a86SJed Brown 
50936c5a86SJed Brown   Concepts: indexing, stride, distribution
51936c5a86SJed Brown 
52936c5a86SJed Brown .seealso: PetscSFSetGraph()
53936c5a86SJed Brown S*/
54936c5a86SJed Brown typedef struct {
55936c5a86SJed Brown   PetscInt rank;                /* Rank of owner */
56936c5a86SJed Brown   PetscInt index;               /* Index of node on rank */
57936c5a86SJed Brown } PetscSFNode;
58936c5a86SJed Brown 
59936c5a86SJed Brown /*E
605af141bcSJed Brown     PetscSFWindowSyncType - Type of synchronization for PETSCSFWINDOW
61936c5a86SJed Brown 
625af141bcSJed Brown $  PETSCSF_WINDOW_SYNC_FENCE - simplest model, synchronizing across communicator
635af141bcSJed Brown $  PETSCSF_WINDOW_SYNC_LOCK - passive model, less synchronous, requires less setup than PETSCSF_WINDOW_SYNC_ACTIVE, but may require more handshakes
645af141bcSJed 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)
65936c5a86SJed Brown 
66e84a5f06SJed Brown    Level: advanced
67936c5a86SJed Brown 
68e84a5f06SJed Brown .seealso: PetscSFWindowSetSyncType(), PetscSFWindowGetSyncType()
69936c5a86SJed Brown E*/
705af141bcSJed Brown typedef enum {PETSCSF_WINDOW_SYNC_FENCE,PETSCSF_WINDOW_SYNC_LOCK,PETSCSF_WINDOW_SYNC_ACTIVE} PetscSFWindowSyncType;
715af141bcSJed Brown PETSC_EXTERN const char *const PetscSFWindowSyncTypes[];
72936c5a86SJed Brown 
73e84a5f06SJed Brown /*E
74e84a5f06SJed Brown     PetscSFDuplicateOption - Aspects to preserve when duplicating a PetscSF
75e84a5f06SJed Brown 
76e84a5f06SJed Brown $  PETSCSF_DUPLICATE_CONFONLY - configuration only, user must call PetscSFSetGraph()
77e84a5f06SJed Brown $  PETSCSF_DUPLICATE_RANKS - communication ranks preserved, but different graph (allows simpler setup after calling PetscSFSetGraph())
78e84a5f06SJed Brown $  PETSCSF_DUPLICATE_GRAPH - entire graph duplicated
79e84a5f06SJed Brown 
80e84a5f06SJed Brown    Level: beginner
81e84a5f06SJed Brown 
82e84a5f06SJed Brown .seealso: PetscSFDuplicate()
83e84a5f06SJed Brown E*/
84e84a5f06SJed Brown typedef enum {PETSCSF_DUPLICATE_CONFONLY,PETSCSF_DUPLICATE_RANKS,PETSCSF_DUPLICATE_GRAPH} PetscSFDuplicateOption;
85e84a5f06SJed Brown PETSC_EXTERN const char *const PetscSFDuplicateOptions[];
86090c6444SJed Brown 
87*adc40e5bSBarry Smith PETSC_EXTERN PetscFunctionList PetscSFList;
885af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFRegisterDestroy(void);
89607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscSFRegisterAll(void);
90bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscSFRegister(const char[],PetscErrorCode (*)(PetscSF));
915af141bcSJed Brown 
92607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscSFInitializePackage(void);
93014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFFinalizePackage(void);
94014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFCreate(MPI_Comm comm,PetscSF*);
95014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFDestroy(PetscSF*);
965af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFSetType(PetscSF,PetscSFType);
97014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFView(PetscSF,PetscViewer);
985af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFSetUp(PetscSF);
99014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFSetFromOptions(PetscSF);
100e84a5f06SJed Brown PETSC_EXTERN PetscErrorCode PetscSFDuplicate(PetscSF,PetscSFDuplicateOption,PetscSF*);
1015af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFWindowSetSyncType(PetscSF,PetscSFWindowSyncType);
1025af141bcSJed Brown PETSC_EXTERN PetscErrorCode PetscSFWindowGetSyncType(PetscSF,PetscSFWindowSyncType*);
103014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFSetRankOrder(PetscSF,PetscBool);
10463f4a732SJed Brown PETSC_EXTERN PetscErrorCode PetscSFSetGraph(PetscSF,PetscInt,PetscInt,const PetscInt*,PetscCopyMode,const PetscSFNode*,PetscCopyMode);
105014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFGetGraph(PetscSF,PetscInt *nroots,PetscInt *nleaves,const PetscInt **ilocal,const PetscSFNode **iremote);
106f723732fSJed Brown PETSC_EXTERN PetscErrorCode PetscSFGetLeafRange(PetscSF,PetscInt*,PetscInt*);
107014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFCreateEmbeddedSF(PetscSF,PetscInt nroots,const PetscInt *selected,PetscSF *newsf);
108014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFReset(PetscSF);
1095b6cb184SJed Brown PETSC_EXTERN PetscErrorCode PetscSFGetRanks(PetscSF,PetscInt*,const PetscMPIInt**,const PetscInt**,const PetscInt**,const PetscInt**);
110014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFGetGroups(PetscSF,MPI_Group*,MPI_Group*);
111014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFGetMultiSF(PetscSF,PetscSF*);
112014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFCreateInverseSF(PetscSF,PetscSF*);
113936c5a86SJed Brown 
114936c5a86SJed Brown /* broadcasts rootdata to leafdata */
115894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFBcastBegin(PetscSF,MPI_Datatype,const void *rootdata,void *leafdata)
116894dd566SJed Brown   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
117894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFBcastEnd(PetscSF,MPI_Datatype,const void *rootdata,void *leafdata)
118894dd566SJed Brown   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
119936c5a86SJed Brown /* Reduce leafdata into rootdata using provided operation */
120894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFReduceBegin(PetscSF,MPI_Datatype,const void *leafdata,void *rootdata,MPI_Op)
12119436ca2SJed Brown   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
122894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFReduceEnd(PetscSF,MPI_Datatype,const void *leafdata,void *rootdata,MPI_Op)
12319436ca2SJed Brown   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
124936c5a86SJed Brown /* Atomically modifies (using provided operation) rootdata using leafdata from each leaf, value at root at time of modification is returned in leafupdate. */
125894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFFetchAndOpBegin(PetscSF,MPI_Datatype,void *rootdata,const void *leafdata,void *leafupdate,MPI_Op)
126894dd566SJed Brown   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2) PetscAttrMPIPointerWithType(5,2);
127894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFFetchAndOpEnd(PetscSF,MPI_Datatype,void *rootdata,const void *leafdata,void *leafupdate,MPI_Op)
128894dd566SJed Brown   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2) PetscAttrMPIPointerWithType(5,2);
129936c5a86SJed Brown /* Compute the degree of every root vertex (number of leaves in its star) */
130014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFComputeDegreeBegin(PetscSF,const PetscInt **degree);
131014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSFComputeDegreeEnd(PetscSF,const PetscInt **degree);
132936c5a86SJed Brown /* Concatenate data from all leaves into roots */
133894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFGatherBegin(PetscSF,MPI_Datatype,const void *leafdata,void *multirootdata)
134894dd566SJed Brown   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
135894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFGatherEnd(PetscSF,MPI_Datatype,const void *leafdata,void *multirootdata)
136894dd566SJed Brown   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
137936c5a86SJed Brown /* Distribute distinct values to each leaf from roots */
138894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFScatterBegin(PetscSF,MPI_Datatype,const void *multirootdata,void *leafdata)
139894dd566SJed Brown   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
140894dd566SJed Brown PETSC_EXTERN PetscErrorCode PetscSFScatterEnd(PetscSF,MPI_Datatype,const void *multirootdata,void *leafdata)
141894dd566SJed Brown   PetscAttrMPIPointerWithType(3,2) PetscAttrMPIPointerWithType(4,2);
142936c5a86SJed Brown 
143936c5a86SJed Brown #endif
144