xref: /petsc/include/petscsf.h (revision 090c6444eff50dff7fb71fbf64165689aa88680f)
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
6936c5a86SJed Brown #include "petscsys.h"
7936c5a86SJed Brown PETSC_EXTERN_CXX_BEGIN
8936c5a86SJed Brown 
9936c5a86SJed Brown extern PetscClassId PETSCSF_CLASSID;
10936c5a86SJed Brown 
11936c5a86SJed Brown /*S
12378b0e49SJed Brown    PetscSF - PETSc object for communication using star forests
13936c5a86SJed Brown 
14936c5a86SJed Brown    Level: intermediate
15936c5a86SJed Brown 
16936c5a86SJed Brown   Concepts: star forest
17936c5a86SJed Brown 
18936c5a86SJed Brown .seealso: PetscSFCreate()
19936c5a86SJed Brown S*/
20936c5a86SJed Brown typedef struct _p_PetscSF* PetscSF;
21936c5a86SJed Brown 
22936c5a86SJed Brown /*S
23936c5a86SJed Brown    PetscSFNode - specifier of owner and index
24936c5a86SJed Brown 
25936c5a86SJed Brown    Level: beginner
26936c5a86SJed Brown 
27936c5a86SJed Brown   Concepts: indexing, stride, distribution
28936c5a86SJed Brown 
29936c5a86SJed Brown .seealso: PetscSFSetGraph()
30936c5a86SJed Brown S*/
31936c5a86SJed Brown typedef struct {
32936c5a86SJed Brown   PetscInt rank;                /* Rank of owner */
33936c5a86SJed Brown   PetscInt index;               /* Index of node on rank */
34936c5a86SJed Brown } PetscSFNode;
35936c5a86SJed Brown 
36936c5a86SJed Brown /*E
37936c5a86SJed Brown     PetscSFSynchronizationType - Type of synchronization for PetscSF
38936c5a86SJed Brown 
39936c5a86SJed Brown $  PETSCSF_SYNCHRONIZATION_FENCE - simplest model, synchronizing across communicator
40936c5a86SJed Brown $  PETSCSF_SYNCHRONIZATION_LOCK - passive model, less synchronous, requires less setup than PETSCSF_SYNCHRONIZATION_ACTIVE, but may require more handshakes
41936c5a86SJed Brown $  PETSCSF_SYNCHRONIZATION_ACTIVE - active model, provides most information to MPI implementation, needs to construct 2-way process groups (more setup than PETSCSF_SYNCHRONIZATION_LOCK)
42936c5a86SJed Brown 
43936c5a86SJed Brown    Level: beginner
44936c5a86SJed Brown 
45936c5a86SJed Brown .seealso: PetscSFSetSynchronizationType()
46936c5a86SJed Brown E*/
47936c5a86SJed Brown typedef enum {PETSCSF_SYNCHRONIZATION_FENCE,PETSCSF_SYNCHRONIZATION_LOCK,PETSCSF_SYNCHRONIZATION_ACTIVE} PetscSFSynchronizationType;
48936c5a86SJed Brown extern const char *const PetscSFSynchronizationTypes[];
49936c5a86SJed Brown 
50*090c6444SJed Brown #if !defined(PETSC_HAVE_MPI_WIN_CREATE) /* The intent here is to be able to compile even without a complete MPI. */
51*090c6444SJed Brown typedef struct MPI_Win_MISSING *MPI_Win;
52*090c6444SJed Brown #endif
53*090c6444SJed Brown 
54936c5a86SJed Brown extern PetscErrorCode PetscSFInitializePackage(const char*);
55936c5a86SJed Brown extern PetscErrorCode PetscSFFinalizePackage(void);
56936c5a86SJed Brown extern PetscErrorCode PetscSFCreate(MPI_Comm comm,PetscSF*);
57936c5a86SJed Brown extern PetscErrorCode PetscSFDestroy(PetscSF*);
58936c5a86SJed Brown extern PetscErrorCode PetscSFView(PetscSF,PetscViewer);
59936c5a86SJed Brown extern PetscErrorCode PetscSFSetFromOptions(PetscSF);
60936c5a86SJed Brown extern PetscErrorCode PetscSFSetSynchronizationType(PetscSF,PetscSFSynchronizationType);
61936c5a86SJed Brown extern PetscErrorCode PetscSFSetRankOrder(PetscSF,PetscBool);
62936c5a86SJed Brown extern PetscErrorCode PetscSFSetGraph(PetscSF,PetscInt nroots,PetscInt nleaves,const PetscInt *ilocal,PetscCopyMode modelocal,const PetscSFNode *remote,PetscCopyMode moderemote);
636b683e12SJed Brown extern PetscErrorCode PetscSFGetGraph(PetscSF,PetscInt *nroots,PetscInt *nleaves,const PetscInt **ilocal,const PetscSFNode **iremote);
64b8df6733SJed Brown extern PetscErrorCode PetscSFCreateEmbeddedSF(PetscSF,PetscInt nroots,const PetscInt *selected,PetscSF *newsf);
65936c5a86SJed Brown extern PetscErrorCode PetscSFCreateArray(PetscSF,MPI_Datatype,void*,void*);
66936c5a86SJed Brown extern PetscErrorCode PetscSFDestroyArray(PetscSF,MPI_Datatype,void*,void*);
67936c5a86SJed Brown extern PetscErrorCode PetscSFReset(PetscSF);
68936c5a86SJed Brown extern PetscErrorCode PetscSFGetRanks(PetscSF,PetscInt*,const PetscInt**,const PetscInt**,const PetscMPIInt**,const PetscMPIInt**);
69936c5a86SJed Brown extern PetscErrorCode PetscSFGetDataTypes(PetscSF,MPI_Datatype,const MPI_Datatype**,const MPI_Datatype**);
70936c5a86SJed Brown extern PetscErrorCode PetscSFGetWindow(PetscSF,MPI_Datatype,void*,PetscBool,PetscMPIInt,PetscMPIInt,PetscMPIInt,MPI_Win*);
71936c5a86SJed Brown extern PetscErrorCode PetscSFFindWindow(PetscSF,MPI_Datatype,const void*,MPI_Win*);
72936c5a86SJed Brown extern PetscErrorCode PetscSFRestoreWindow(PetscSF,MPI_Datatype,const void*,PetscBool,PetscMPIInt,MPI_Win*);
73936c5a86SJed Brown extern PetscErrorCode PetscSFGetGroups(PetscSF,MPI_Group*,MPI_Group*);
74936c5a86SJed Brown extern PetscErrorCode PetscSFGetMultiSF(PetscSF,PetscSF*);
75d974a681SJed Brown extern PetscErrorCode PetscSFCreateInverseSF(PetscSF,PetscSF*);
76936c5a86SJed Brown 
77936c5a86SJed Brown /* broadcasts rootdata to leafdata */
78936c5a86SJed Brown extern PetscErrorCode PetscSFBcastBegin(PetscSF,MPI_Datatype,const void *rootdata,void *leafdata);
79936c5a86SJed Brown extern PetscErrorCode PetscSFBcastEnd(PetscSF,MPI_Datatype,const void *rootdata,void *leafdata);
80936c5a86SJed Brown /* Reduce leafdata into rootdata using provided operation */
81936c5a86SJed Brown extern PetscErrorCode PetscSFReduceBegin(PetscSF,MPI_Datatype,const void *leafdata,void *rootdata,MPI_Op);
82936c5a86SJed Brown extern PetscErrorCode PetscSFReduceEnd(PetscSF,MPI_Datatype,const void *leafdata,void *rootdata,MPI_Op);
83936c5a86SJed Brown /* Atomically modifies (using provided operation) rootdata using leafdata from each leaf, value at root at time of modification is returned in leafupdate. */
84936c5a86SJed Brown extern PetscErrorCode PetscSFFetchAndOpBegin(PetscSF,MPI_Datatype,void *rootdata,const void *leafdata,void *leafupdate,MPI_Op);
85936c5a86SJed Brown extern PetscErrorCode PetscSFFetchAndOpEnd(PetscSF,MPI_Datatype,void *rootdata,const void *leafdata,void *leafupdate,MPI_Op);
86936c5a86SJed Brown /* Compute the degree of every root vertex (number of leaves in its star) */
87936c5a86SJed Brown extern PetscErrorCode PetscSFComputeDegreeBegin(PetscSF,const PetscInt **degree);
88936c5a86SJed Brown extern PetscErrorCode PetscSFComputeDegreeEnd(PetscSF,const PetscInt **degree);
89936c5a86SJed Brown /* Concatenate data from all leaves into roots */
90936c5a86SJed Brown extern PetscErrorCode PetscSFGatherBegin(PetscSF,MPI_Datatype,const void *leafdata,void *multirootdata);
91936c5a86SJed Brown extern PetscErrorCode PetscSFGatherEnd(PetscSF,MPI_Datatype,const void *leafdata,void *multirootdata);
92936c5a86SJed Brown /* Distribute distinct values to each leaf from roots */
93936c5a86SJed Brown extern PetscErrorCode PetscSFScatterBegin(PetscSF,MPI_Datatype,const void *multirootdata,void *leafdata);
94936c5a86SJed Brown extern PetscErrorCode PetscSFScatterEnd(PetscSF,MPI_Datatype,const void *multirootdata,void *leafdata);
95936c5a86SJed Brown 
96936c5a86SJed Brown PETSC_EXTERN_CXX_END
97936c5a86SJed Brown 
98936c5a86SJed Brown #endif
99