xref: /petsc/src/vec/is/sf/impls/basic/sfbasic.h (revision 3ca0882ebe6e6bc3c96f853b3244799ed8a662a6)
1 #if !defined(__SFBASIC_H)
2 #define __SFBASIC_H
3 
4 #include <../src/vec/is/sf/impls/basic/sfpack.h>
5 
6 typedef enum {PETSCSF_LEAF2ROOT_REDUCE=0, PETSCSF_ROOT2LEAF_BCAST=1} PetscSFDirection;
7 
8 typedef struct _n_PetscSFPack_Basic *PetscSFPack_Basic;
9 
10 #define SPPACKBASICHEADER \
11   SFPACKHEADER;                                                                                                                    \
12   char          **root;         /* Packed root data, indexed by leaf rank */                                                       \
13   char          **leaf;         /* Packed leaf data, indexed by root rank */                                                       \
14   PetscMPIInt   half;           /* Number of MPI_Requests used for either leaf2root or root2leaf communication */                  \
15   MPI_Request   *requests       /* [2*half] requests arranged in this order: leaf2root root/leaf reqs, root2leaf root/leaf reqs */
16 
17 struct _n_PetscSFPack_Basic {
18   SPPACKBASICHEADER;
19   PetscBool     initialized[2]; /* Is the communcation pattern in each direction initialized? [0] for leaf2root, [1] for root2leaf */
20 };
21 
22 #define SFBASICHEADER \
23   PetscMPIInt      niranks;     /* Number of incoming ranks (ranks accessing my roots) */                                      \
24   PetscMPIInt      ndiranks;    /* Number of incoming ranks (ranks accessing my roots) in distinguished set */                 \
25   PetscMPIInt      *iranks;     /* Array of ranks that reference my roots */                                                   \
26   PetscInt         itotal;      /* Total number of graph edges referencing my roots */                                         \
27   PetscInt         *ioffset;    /* Array of length niranks+1 holding offset in irootloc[] for each rank */                     \
28   PetscInt         *irootloc;   /* Incoming roots referenced by ranks starting at ioffset[rank] */                             \
29   PetscSFPackOpt   rootpackopt; /* Optimization plans to (un)pack roots based on patterns in irootloc[]. NULL for no plans */  \
30   PetscSFPack      avail;       /* One or more entries per MPI Datatype, lazily constructed */                                 \
31   PetscSFPack      inuse        /* Buffers being used for transactions that have not yet completed */
32 
33 typedef struct {
34   SFBASICHEADER;
35 } PetscSF_Basic;
36 
37 PETSC_STATIC_INLINE PetscErrorCode PetscSFGetRootInfo_Basic(PetscSF sf,PetscInt *nrootranks,PetscInt *ndrootranks,const PetscMPIInt **rootranks,const PetscInt **rootoffset,const PetscInt **rootloc)
38 {
39   PetscSF_Basic *bas = (PetscSF_Basic*)sf->data;
40 
41   PetscFunctionBegin;
42   if (nrootranks)  *nrootranks  = bas->niranks;
43   if (ndrootranks) *ndrootranks = bas->ndiranks;
44   if (rootranks)   *rootranks   = bas->iranks;
45   if (rootoffset)  *rootoffset  = bas->ioffset;
46   if (rootloc)     *rootloc     = bas->irootloc;
47   PetscFunctionReturn(0);
48 }
49 
50 PETSC_STATIC_INLINE PetscErrorCode PetscSFGetLeafInfo_Basic(PetscSF sf,PetscInt *nleafranks,PetscInt *ndleafranks,const PetscMPIInt **leafranks,const PetscInt **leafoffset,const PetscInt **leafloc,const PetscInt **leafrremote)
51 {
52   PetscFunctionBegin;
53   if (nleafranks)  *nleafranks  = sf->nranks;
54   if (ndleafranks) *ndleafranks = sf->ndranks;
55   if (leafranks)   *leafranks   = sf->ranks;
56   if (leafoffset)  *leafoffset  = sf->roffset;
57   if (leafloc)     *leafloc     = sf->rmine;
58   if (leafrremote) *leafrremote = sf->rremote;
59   PetscFunctionReturn(0);
60 }
61 
62 PETSC_STATIC_INLINE PetscErrorCode PetscSFPackWaitall_Basic(PetscSFPack_Basic link,PetscSFDirection direction)
63 {
64   PetscErrorCode ierr;
65   MPI_Request    *requests = (direction == PETSCSF_LEAF2ROOT_REDUCE) ? link->requests : link->requests  + link->half;
66 
67   PetscFunctionBegin;
68   ierr = MPI_Waitall(link->half,requests,MPI_STATUSES_IGNORE);CHKERRQ(ierr);
69   PetscFunctionReturn(0);
70 }
71 
72 PETSC_INTERN PetscErrorCode PetscSFSetUp_Basic(PetscSF);
73 PETSC_INTERN PetscErrorCode PetscSFView_Basic(PetscSF,PetscViewer);
74 PETSC_INTERN PetscErrorCode PetscSFReset_Basic(PetscSF);
75 PETSC_INTERN PetscErrorCode PetscSFDestroy_Basic(PetscSF);
76 PETSC_INTERN PetscErrorCode PetscSFBcastAndOpEnd_Basic(PetscSF,MPI_Datatype,const void*,void*,MPI_Op);
77 PETSC_INTERN PetscErrorCode PetscSFReduceEnd_Basic(PetscSF,MPI_Datatype,const void*,void*,MPI_Op);
78 PETSC_INTERN PetscErrorCode PetscSFFetchAndOpBegin_Basic(PetscSF,MPI_Datatype,void*,const void*,void*,MPI_Op);
79 PETSC_INTERN PetscErrorCode PetscSFCreateEmbeddedSF_Basic(PetscSF,PetscInt,const PetscInt*,PetscSF*);
80 PETSC_INTERN PetscErrorCode PetscSFCreateEmbeddedLeafSF_Basic(PetscSF,PetscInt,const PetscInt*,PetscSF*);
81 PETSC_INTERN PetscErrorCode PetscSFGetLeafRanks_Basic(PetscSF,PetscInt*,const PetscMPIInt**,const PetscInt**,const PetscInt**);
82 #endif
83