xref: /petsc/include/petscsf.h (revision b8df673394a7a2894237dec214e7184d5d4a1026)
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 
50936c5a86SJed Brown extern PetscErrorCode PetscSFInitializePackage(const char*);
51936c5a86SJed Brown extern PetscErrorCode PetscSFFinalizePackage(void);
52936c5a86SJed Brown extern PetscErrorCode PetscSFCreate(MPI_Comm comm,PetscSF*);
53936c5a86SJed Brown extern PetscErrorCode PetscSFDestroy(PetscSF*);
54936c5a86SJed Brown extern PetscErrorCode PetscSFView(PetscSF,PetscViewer);
55936c5a86SJed Brown extern PetscErrorCode PetscSFSetFromOptions(PetscSF);
56936c5a86SJed Brown extern PetscErrorCode PetscSFSetSynchronizationType(PetscSF,PetscSFSynchronizationType);
57936c5a86SJed Brown extern PetscErrorCode PetscSFSetRankOrder(PetscSF,PetscBool);
58936c5a86SJed Brown extern PetscErrorCode PetscSFSetGraph(PetscSF,PetscInt nroots,PetscInt nleaves,const PetscInt *ilocal,PetscCopyMode modelocal,const PetscSFNode *remote,PetscCopyMode moderemote);
596b683e12SJed Brown extern PetscErrorCode PetscSFGetGraph(PetscSF,PetscInt *nroots,PetscInt *nleaves,const PetscInt **ilocal,const PetscSFNode **iremote);
60*b8df6733SJed Brown extern PetscErrorCode PetscSFCreateEmbeddedSF(PetscSF,PetscInt nroots,const PetscInt *selected,PetscSF *newsf);
61936c5a86SJed Brown extern PetscErrorCode PetscSFCreateArray(PetscSF,MPI_Datatype,void*,void*);
62936c5a86SJed Brown extern PetscErrorCode PetscSFDestroyArray(PetscSF,MPI_Datatype,void*,void*);
63936c5a86SJed Brown extern PetscErrorCode PetscSFReset(PetscSF);
64936c5a86SJed Brown extern PetscErrorCode PetscSFGetRanks(PetscSF,PetscInt*,const PetscInt**,const PetscInt**,const PetscMPIInt**,const PetscMPIInt**);
65936c5a86SJed Brown extern PetscErrorCode PetscSFGetDataTypes(PetscSF,MPI_Datatype,const MPI_Datatype**,const MPI_Datatype**);
66936c5a86SJed Brown extern PetscErrorCode PetscSFGetWindow(PetscSF,MPI_Datatype,void*,PetscBool,PetscMPIInt,PetscMPIInt,PetscMPIInt,MPI_Win*);
67936c5a86SJed Brown extern PetscErrorCode PetscSFFindWindow(PetscSF,MPI_Datatype,const void*,MPI_Win*);
68936c5a86SJed Brown extern PetscErrorCode PetscSFRestoreWindow(PetscSF,MPI_Datatype,const void*,PetscBool,PetscMPIInt,MPI_Win*);
69936c5a86SJed Brown extern PetscErrorCode PetscSFGetGroups(PetscSF,MPI_Group*,MPI_Group*);
70936c5a86SJed Brown extern PetscErrorCode PetscSFGetMultiSF(PetscSF,PetscSF*);
71936c5a86SJed Brown 
72936c5a86SJed Brown /* broadcasts rootdata to leafdata */
73936c5a86SJed Brown extern PetscErrorCode PetscSFBcastBegin(PetscSF,MPI_Datatype,const void *rootdata,void *leafdata);
74936c5a86SJed Brown extern PetscErrorCode PetscSFBcastEnd(PetscSF,MPI_Datatype,const void *rootdata,void *leafdata);
75936c5a86SJed Brown /* Reduce leafdata into rootdata using provided operation */
76936c5a86SJed Brown extern PetscErrorCode PetscSFReduceBegin(PetscSF,MPI_Datatype,const void *leafdata,void *rootdata,MPI_Op);
77936c5a86SJed Brown extern PetscErrorCode PetscSFReduceEnd(PetscSF,MPI_Datatype,const void *leafdata,void *rootdata,MPI_Op);
78936c5a86SJed Brown /* Atomically modifies (using provided operation) rootdata using leafdata from each leaf, value at root at time of modification is returned in leafupdate. */
79936c5a86SJed Brown extern PetscErrorCode PetscSFFetchAndOpBegin(PetscSF,MPI_Datatype,void *rootdata,const void *leafdata,void *leafupdate,MPI_Op);
80936c5a86SJed Brown extern PetscErrorCode PetscSFFetchAndOpEnd(PetscSF,MPI_Datatype,void *rootdata,const void *leafdata,void *leafupdate,MPI_Op);
81936c5a86SJed Brown /* Compute the degree of every root vertex (number of leaves in its star) */
82936c5a86SJed Brown extern PetscErrorCode PetscSFComputeDegreeBegin(PetscSF,const PetscInt **degree);
83936c5a86SJed Brown extern PetscErrorCode PetscSFComputeDegreeEnd(PetscSF,const PetscInt **degree);
84936c5a86SJed Brown /* Concatenate data from all leaves into roots */
85936c5a86SJed Brown extern PetscErrorCode PetscSFGatherBegin(PetscSF,MPI_Datatype,const void *leafdata,void *multirootdata);
86936c5a86SJed Brown extern PetscErrorCode PetscSFGatherEnd(PetscSF,MPI_Datatype,const void *leafdata,void *multirootdata);
87936c5a86SJed Brown /* Distribute distinct values to each leaf from roots */
88936c5a86SJed Brown extern PetscErrorCode PetscSFScatterBegin(PetscSF,MPI_Datatype,const void *multirootdata,void *leafdata);
89936c5a86SJed Brown extern PetscErrorCode PetscSFScatterEnd(PetscSF,MPI_Datatype,const void *multirootdata,void *leafdata);
90936c5a86SJed Brown 
91936c5a86SJed Brown PETSC_EXTERN_CXX_END
92936c5a86SJed Brown 
93936c5a86SJed Brown #endif
94