PetscSF (Star Forest) - Low-level Interface
The PetscSF (Star Forest) component provides efficient parallel communication patterns for distributed data structures. A star forest is a specialized graph structure optimized for scatter/gather operations in parallel computing.
Overview
PetscSF enables:
- Point-to-point communication: Efficient MPI communication patterns
- Scatter/gather operations: Move data between processors
- Halo exchange: Update ghost/boundary values
- Reduction operations: Parallel sums, max, min across shared data
- Irregular communication: Handle non-uniform data distributions
A star forest consists of:
- Roots: Data owned locally
- Leaves: Data needed from remote processes (or local)
- Communication pattern: Which leaves come from which roots
PetscSF is the underlying communication layer for DM ghost point updates and other parallel operations.
Basic Usage
using PETSc, MPI
# Initialize MPI and PETSc
MPI.Init()
petsclib = PETSc.getlib()
PETSc.initialize(petsclib)
PetscInt = petsclib.PetscInt
# Create a star forest
sf = LibPETSc.PetscSFCreate(petsclib, MPI.COMM_WORLD)
# Define communication pattern
# nleaves: number of leaves (data items we need)
# ilocal: local indices for leaves (can be C_NULL if identity)
# iremote: (rank, index) pairs specifying which process/index to get from
nleaves = 5
# number of roots owned locally (for this simple example set equal to nleaves)
nroots = 5
ilocal = [0, 1, 2, 3, 4] # Local indices where data will be stored
iremote = [
LibPETSc.PetscSFNode(0, 0),
LibPETSc.PetscSFNode(0, 1),
LibPETSc.PetscSFNode(0, 2),
LibPETSc.PetscSFNode(0, 3),
LibPETSc.PetscSFNode(0, 4),
]
LibPETSc.PetscSFSetGraph(petsclib, sf, nroots, nleaves, ilocal, LibPETSc.PETSC_COPY_VALUES,
iremote, LibPETSc.PETSC_COPY_VALUES)
# Setup
LibPETSc.PetscSFSetUp(petsclib, sf)
# Cleanup
LibPETSc.PetscSFDestroy(petsclib, sf)
# Finalize PETSc and MPI
PETSc.finalize(petsclib)
MPI.Finalize()Communication Operations
Broadcast (Scatter)
Send data from roots to leaves:
# Root data: data we own
root_data = Float64[1.0, 2.0, 3.0, 4.0, 5.0]
# Leaf data: buffer to receive data
leaf_data = zeros(Float64, nleaves)
# Broadcast: send root data to leaves (the datatype and op are MPI.jl objects)
LibPETSc.PetscSFBcastBegin(petsclib, sf, MPI.Datatype(Float64), root_data, leaf_data, MPI.REPLACE)
LibPETSc.PetscSFBcastEnd(petsclib, sf, MPI.Datatype(Float64), root_data, leaf_data, MPI.REPLACE)Reduce
Accumulate data from leaves back to roots:
# Leaf contributions
leaf_data = Float64[0.1, 0.2, 0.3, 0.4, 0.5]
# Root accumulator
root_data = zeros(Float64, nroots)
# Reduce: accumulate leaf data to roots
LibPETSc.PetscSFReduceBegin(petsclib, sf, MPI.Datatype(Float64), leaf_data, root_data, MPI.SUM)
LibPETSc.PetscSFReduceEnd(petsclib, sf, MPI.Datatype(Float64), leaf_data, root_data, MPI.SUM)Fetch and Operations
Atomic operations for concurrent updates:
# Fetch the old root value into leaf_updates, then apply op(root, leaf) at the root
leaf_updates = zeros(Float64, nleaves)
LibPETSc.PetscSFFetchAndOpBegin(petsclib, sf, MPI.Datatype(Float64), root_data, leaf_data, leaf_updates, MPI.SUM)
LibPETSc.PetscSFFetchAndOpEnd(petsclib, sf, MPI.Datatype(Float64), root_data, leaf_data, leaf_updates, MPI.SUM)MPI Operations
Supported MPI operations for reduce (MPI.jl objects):
MPI.SUM: Sum valuesMPI.MAX: Maximum valueMPI.MIN: Minimum valueMPI.REPLACE: Replace (last write wins)MPI.PROD: Product
The communication routines (PetscSFBcastBegin/End, PetscSFReduceBegin/End, PetscSFFetchAndOpBegin/End) are hand-written wrappers: PETSc's API extractor skips functions taking an MPI_Datatype. They accept Arrays or raw pointers and keep the arrays alive for the duration of the call; the arrays must not be freed between Begin and End.
Star Forest Types
Available through PetscSFSetType:
- PETSCSFBASIC: Basic implementation
- PETSCSFNEIGHBOR: MPI neighborhood collectives (efficient for structured patterns)
- PETSCSFALLGATHERV: All-gather based
- PETSCSFALLGATHER: All-gather for small data
- PETSCSFGATHERV: Gather-based
- PETSCSFGATHER: Simple gather
- PETSCSFALLTOALL: All-to-all based
Graph Queries
# Get the graph: root count, leaf count, leaf locations and remote (rank, index) pairs.
# `ilocal` is `nothing` when the leaves are contiguous [0, nleaves); the arrays are
# owned by the SF and valid until it changes.
nroots, nleaves, ilocal, iremote = LibPETSc.PetscSFGetGraph(petsclib, sf)
for leaf in 1:nleaves
node = iremote[leaf] # node.rank, node.index
endMulti-Root Support
Handle communication with multiple root data per point:
# Create multi-SF for multiple DOFs per point
nroots_mult = nroots * num_components
multi_sf = LibPETSc.PetscSFCreateEmbeddedRootSF(petsclib, sf, nroots_mult, iroot_indices)Common Use Cases
1. Ghost Point Updates (Halo Exchange)
# After modifying owned data, update ghost points: broadcast roots to leaves
LibPETSc.PetscSFBcastBegin(petsclib, sf, MPI.Datatype(Float64), local_data, ghost_data, MPI.REPLACE)
LibPETSc.PetscSFBcastEnd(petsclib, sf, MPI.Datatype(Float64), local_data, ghost_data, MPI.REPLACE)2. Parallel Assembly
# After local assembly, accumulate contributions from other processes at the owners
LibPETSc.PetscSFReduceBegin(petsclib, sf, MPI.Datatype(Float64), local_contrib, global_data, MPI.SUM)
LibPETSc.PetscSFReduceEnd(petsclib, sf, MPI.Datatype(Float64), local_contrib, global_data, MPI.SUM)3. DM Point Communication
# Get the point SF of a DM (describes the point distribution); the DM owns it
dm_sf = LibPETSc.DMGetPointSF(petsclib, dm)
# Use to communicate point-based dataPerformance Considerations
- Choose appropriate type:
PETSCSFNEIGHBORis often best for structured grids - Reuse SF objects: Creating the communication pattern is expensive
- Batch communications: Combine multiple small messages when possible
- Alignment: Use properly aligned data types for better performance
Function Reference
PETSc.LibPETSc.PetscSFCompose — Method
sfBA::PetscSF = PetscSFCompose(petsclib::PetscLibType, sfA::PetscSF, sfB::PetscSF)Compose a new PetscSF by putting the second PetscSF under the first one in a top (roots) down (leaves) view
Input Parameters:
sfA- The firstPetscSFsfB- The secondPetscSF
Output Parameter:
sfBA- The compositePetscSF
Level: developer
See also: PetscSF, PetscSFComposeInverse(), PetscSFGetGraph(), PetscSFSetGraph()
External Links
- PETSc Manual:
PetscSF/PetscSFCompose
PETSc.LibPETSc.PetscSFComposeInverse — Method
sfBA::PetscSF = PetscSFComposeInverse(petsclib::PetscLibType, sfA::PetscSF, sfB::PetscSF)Compose a new PetscSF by putting the inverse of the second PetscSF under the first one
Input Parameters:
sfA- The firstPetscSFsfB- The secondPetscSF
Output Parameter:
sfBA- The compositePetscSF.
Level: developer
See also: PetscSF, PetscSFCompose(), PetscSFGetGraph(), PetscSFSetGraph(), PetscSFCreateInverseSF()
External Links
- PETSc Manual:
PetscSF/PetscSFComposeInverse
PETSc.LibPETSc.PetscSFComputeDegreeBegin — Method
degree::Ptr{PetscInt} = PetscSFComputeDegreeBegin(petsclib::PetscLibType, sf::PetscSF)begin computation of the degree of each root vertex, to be completed with PetscSFComputeDegreeEnd()
Collective
Input Parameter:
sf- star forest
Output Parameter:
degree- degree (the number of leaves) of each root vertex
Level: advanced
See also: PetscSF, PetscSFGatherBegin(), PetscSFComputeDegreeEnd()
External Links
- PETSc Manual:
PetscSF/PetscSFComputeDegreeBegin
PETSc.LibPETSc.PetscSFComputeDegreeEnd — Method
degree::Ptr{PetscInt} = PetscSFComputeDegreeEnd(petsclib::PetscLibType, sf::PetscSF)complete computation of degree for each root vertex, started with PetscSFComputeDegreeBegin()
Collective
Input Parameter:
sf- star forest
Output Parameter:
degree- degree of each root vertex
Level: developer
See also: PetscSF, PetscSFGatherBegin(), PetscSFComputeDegreeBegin()
External Links
- PETSc Manual:
PetscSF/PetscSFComputeDegreeEnd
PETSc.LibPETSc.PetscSFComputeMultiRootOriginalNumbering — Method
nMultiRoots::PetscInt,multiRootsOrigNumbering::Vector{PetscInt} = PetscSFComputeMultiRootOriginalNumbering(petsclib::PetscLibType, sf::PetscSF, degree::Vector{PetscInt})Returns original numbering of multi-roots (roots of multi-PetscSF returned by PetscSFGetMultiSF()). Each multi-root is assigned index of the corresponding original root.
Collective
Input Parameters:
sf- star forestdegree- degree of each root vertex, computed withPetscSFComputeDegreeBegin()andPetscSFComputeDegreeEnd()
Output Parameters:
nMultiRoots- (optional) number of multi-roots (roots of multi-PetscSF)multiRootsOrigNumbering- original indices of multi-roots; length of this array isnMultiRoots
Level: developer
See also: PetscSF, PetscSFComputeDegreeBegin(), PetscSFComputeDegreeEnd(), PetscSFGetMultiSF()
External Links
- PETSc Manual:
PetscSF/PetscSFComputeMultiRootOriginalNumbering
PETSc.LibPETSc.PetscSFConcatenate — Method
newsf::PetscSF = PetscSFConcatenate(petsclib::PetscLibType, comm::MPI_Comm, nsfs::PetscInt, sfs::Vector{PetscSF}, rootMode::PetscSFConcatenateRootMode, leafOffsets::Vector{PetscInt})concatenate multiple PetscSF into a new PetscSF
Input Parameters:
comm- the communicatornsfs- the number of inputPetscSFsfs- the array of inputPetscSFrootMode- the root mode specifying how roots are handledleafOffsets- the array of local leaf offsets, one for each inputPetscSF, orNULLfor contiguous storage
Output Parameter:
newsf- The resultingPetscSF
Level: advanced
See also: PetscSF, PetscSFCompose(), PetscSFGetGraph(), PetscSFSetGraph(), PetscSFConcatenateRootMode
External Links
- PETSc Manual:
PetscSF/PetscSFConcatenate
PETSc.LibPETSc.PetscSFCreate — Method
sf::PetscSF = PetscSFCreate(petsclib::PetscLibType, comm::MPI_Comm)create a star forest communication context
Collective
Input Parameter:
comm- communicator on which the star forest will operate
Output Parameter:
sf- new star forest context
Options Database Key:
-sf_type (basic|window|neighbor)- Use MPI persistent Isend/Irecv, or MPI-3 one-sided window, or MPI-3 neighborhood collectives for communication-sf_neighbor_persistent (true|false)- Use MPI-4 persistent neighborhood collectives for communication (used along with-sf_type neighbor)
Level: intermediate
See also: PetscSF, PetscSFSetType, PetscSFSetGraph(), PetscSFSetGraphWithPattern(), PetscSFDestroy()
External Links
- PETSc Manual:
PetscSF/PetscSFCreate
PETSc.LibPETSc.PetscSFCreateByMatchingIndices — Method
sfA::PetscSF,sf::PetscSF = PetscSFCreateByMatchingIndices(petsclib::PetscLibType, layout::PetscLayout, numRootIndices::PetscInt, rootIndices::Vector{PetscInt}, rootLocalIndices::Vector{PetscInt}, rootLocalOffset::PetscInt, numLeafIndices::PetscInt, leafIndices::Vector{PetscInt}, leafLocalIndices::Vector{PetscInt}, leafLocalOffset::PetscInt)Create PetscSF by matching root and leaf indices
Collective
Input Parameters:
layout-PetscLayoutdefining the global index space and the MPI rank that brokers each indexnumRootIndices- size ofrootIndicesrootIndices- array of global indices of which this process requests ownershiprootLocalIndices- root local index permutation (NULLif no permutation)rootLocalOffset- offset to be added torootLocalIndicesnumLeafIndices- size ofleafIndicesleafIndices- array of global indices with which this process requires data associatedleafLocalIndices- leaf local index permutation (NULLif no permutation)leafLocalOffset- offset to be added toleafLocalIndices
Output Parameters:
sfA- star forest representing the communication pattern from the layout space to the leaf space (NULLif not needed)sf- star forest representing the communication pattern from the root space to the leaf space
Level: advanced
Example 1: `` rank : 0 1 2 rootIndices : [1 0 2] [3] [3] rootLocalOffset : 100 200 300 layout : [0 1] [2] [3] leafIndices : [0] [2] [0 3] leafLocalOffset : 400 500 600
would build the following PetscSF
[0] 400 <- (0,101) [1] 500 <- (0,102) [2] 600 <- (0,101) [2] 601 <- (2,300) ``
Example 2: `` rank : 0 1 2 rootIndices : [1 0 2] [3] [3] rootLocalOffset : 100 200 300 layout : [0 1] [2] [3] leafIndices : rootIndices rootIndices rootIndices leafLocalOffset : rootLocalOffset rootLocalOffset rootLocalOffset
would build the following PetscSF
[1] 200 <- (2,300) ``
Example 3: `` No process requests ownership of global index 1, but no process needs it.
rank : 0 1 2 numRootIndices : 2 1 1 rootIndices : [0 2] [3] [3] rootLocalOffset : 100 200 300 layout : [0 1] [2] [3] numLeafIndices : 1 1 2 leafIndices : [0] [2] [0 3] leafLocalOffset : 400 500 600
would build the following PetscSF
[0] 400 <- (0,100) [1] 500 <- (0,101) [2] 600 <- (0,100) [2] 601 <- (2,300) ``
See also: PetscSF, PetscSFCreate()
External Links
- PETSc Manual:
PetscSF/PetscSFCreateByMatchingIndices
PETSc.LibPETSc.PetscSFCreateEmbeddedLeafSF — Method
newsf::PetscSF = PetscSFCreateEmbeddedLeafSF(petsclib::PetscLibType, sf::PetscSF, nselected::PetscInt, selected::Vector{PetscInt})removes edges from all but the selected leaves of a PetscSF, does not remap indices
Collective
Input Parameters:
sf- original star forestnselected- number of selected leaves on this MPI processselected- indices of the selected leaves on this MPI process
Output Parameter:
newsf- new star forest
Level: advanced
See also: PetscSF, PetscSFCreateEmbeddedRootSF(), PetscSFSetGraph(), PetscSFGetGraph()
External Links
- PETSc Manual:
PetscSF/PetscSFCreateEmbeddedLeafSF
PETSc.LibPETSc.PetscSFCreateEmbeddedRootSF — Method
esf::PetscSF = PetscSFCreateEmbeddedRootSF(petsclib::PetscLibType, sf::PetscSF, nselected::PetscInt, selected::Vector{PetscInt})removes edges from all but the selected roots of a PetscSF, does not remap indices
Collective
Input Parameters:
sf- original star forestnselected- number of selected roots on this MPI processselected- indices of the selected roots on this MPI process
Output Parameter:
esf- new star forest
Level: advanced
See also: PetscSF, PetscSFSetGraph(), PetscSFGetGraph()
External Links
- PETSc Manual:
PetscSF/PetscSFCreateEmbeddedRootSF
PETSc.LibPETSc.PetscSFCreateFromLayouts — Method
sf::PetscSF = PetscSFCreateFromLayouts(petsclib::PetscLibType, rmap::PetscLayout, lmap::PetscLayout)Creates a parallel star forest mapping between two PetscLayout objects
Collective
Input Parameters:
rmap-PetscLayoutdefining the global root spacelmap-PetscLayoutdefining the global leaf space
Output Parameter:
sf- The parallel star forest
Level: intermediate
See also: PetscSF, PetscLayout, PetscSFCreate(), PetscSFSetGraph(), PetscLayoutCreate(), PetscSFSetGraphLayout()
External Links
- PETSc Manual:
PetscSF/PetscSFCreateFromLayouts
PETSc.LibPETSc.PetscSFCreateInverseSF — Method
isf::PetscSF = PetscSFCreateInverseSF(petsclib::PetscLibType, sf::PetscSF)given a PetscSF in which all roots have degree 1 (exactly one leaf), creates the inverse map
Collective
Input Parameter:
sf- star forest to invert
Output Parameter:
isf- inverse ofsf
Level: advanced
See also: PetscSF, PetscSFType, PetscSFSetGraph()
External Links
- PETSc Manual:
PetscSF/PetscSFCreateInverseSF
PETSc.LibPETSc.PetscSFCreateRemoteOffsets — Method
remoteOffsets::Ptr{PetscInt} = PetscSFCreateRemoteOffsets(petsclib::PetscLibType, sf::PetscSF, rootSection::PetscSection, leafSection::PetscSection)Create offsets for point data on remote processes
Collective
Input Parameters:
sf- ThePetscSFrootSection- Data layout of remote points for outgoing data (this is layout for roots)leafSection- Data layout of local points for incoming data (this is layout for leaves)
Output Parameter:
remoteOffsets- Offsets for point data on remote processes (these are offsets from the root section), orNULL
Level: developer
See also: PetscSF, PetscSFCreate()
External Links
- PETSc Manual:
PetscSF/PetscSFCreateRemoteOffsets
PETSc.LibPETSc.PetscSFCreateSectionSF — Method
sectionSF::PetscSF = PetscSFCreateSectionSF(petsclib::PetscLibType, sf::PetscSF, rootSection::PetscSection, remoteOffsets::Vector{PetscInt}, leafSection::PetscSection)Create an expanded PetscSF of dofs, assuming the input PetscSF relates points
Collective
Input Parameters:
sf- ThePetscSFrootSection- Data layout of remote points for outgoing data (this is usually the serial section)remoteOffsets- Offsets for point data on remote processes (these are offsets from the root section), orNULLleafSection- Data layout of local points for incoming data (this is the distributed section)
Output Parameter:
sectionSF- The newPetscSF
Level: advanced
See also: PetscSF, PetscSFCreate(), PetscSFDistributeSection()
External Links
- PETSc Manual:
PetscSF/PetscSFCreateSectionSF
PETSc.LibPETSc.PetscSFCreateStridedSF — Method
vsf::PetscSF = PetscSFCreateStridedSF(petsclib::PetscLibType, sf::PetscSF, bs::PetscInt, ldr::PetscInt, ldl::PetscInt)Create an PetscSF to communicate interleaved blocks of data
Collective
Input Parameters:
sf- star forestbs- strideldr- leading dimension of root spaceldl- leading dimension of leaf space
Output Parameter:
vsf- the newPetscSF
Level: intermediate
See also: PetscSF, PetscSFCreate(), PetscSFSetGraph()
External Links
- PETSc Manual:
PetscSF/PetscSFCreateStridedSF
PETSc.LibPETSc.PetscSFDestroy — Method
PetscSFDestroy(petsclib::PetscLibType, sf::Union{PetscSF, Ref{PetscSF}})destroy a star forest
Collective
Input Parameter:
sf- address of star forest
Level: intermediate
See also: PetscSF, PetscSFType, PetscSFCreate(), PetscSFReset()
External Links
- PETSc Manual:
PetscSF/PetscSFDestroy
PETSc.LibPETSc.PetscSFDistributeSection — Method
remoteOffsets::Ptr{PetscInt} = PetscSFDistributeSection(petsclib::PetscLibType, sf::PetscSF, rootSection::PetscSection, leafSection::PetscSection)Create a new PetscSection reorganized, moving from the root to the leaves of the PetscSF
Collective
Input Parameters:
sf- ThePetscSFrootSection- Section defined on root space
Output Parameters:
remoteOffsets- root offsets in leaf storage, orNULL, its length will be the size of the chart ofleafSectionleafSection- Section defined on the leaf space
Level: advanced
See also: PetscSF, PetscSFCreate(), PetscSFCreateSectionSF()
External Links
- PETSc Manual:
PetscSF/PetscSFDistributeSection
PETSc.LibPETSc.PetscSFDuplicate — Method
newsf::PetscSF = PetscSFDuplicate(petsclib::PetscLibType, sf::PetscSF, opt::PetscSFDuplicateOption)duplicate a PetscSF, optionally preserving rank connectivity and graph
Collective
Input Parameters:
sf- communication object to duplicateopt-PETSCSF_DUPLICATE_CONFONLY,PETSCSF_DUPLICATE_RANKS, orPETSCSF_DUPLICATE_GRAPH(seePetscSFDuplicateOption)
Output Parameter:
newsf- new communication object
Level: beginner
See also: PetscSF, PetscSFType, PetscSFCreate(), PetscSFSetType(), PetscSFSetGraph()
External Links
- PETSc Manual:
PetscSF/PetscSFDuplicate
PETSc.LibPETSc.PetscSFFinalizePackage — Method
PetscSFFinalizePackage(petsclib::PetscLibType)Finalize PetscSF package, it is called from PetscFinalize()
Logically Collective
Level: developer
See also: PetscSF, PetscSFInitializePackage()
External Links
- PETSc Manual:
PetscSF/PetscSFFinalizePackage
PETSc.LibPETSc.PetscSFGetGraph — Method
nroots::PetscInt,nleaves::PetscInt,iloc::Vector{PetscInt} = PetscSFGetGraph(petsclib::PetscLibType, sf::PetscSF, iremote::Vector{PetscSFNode})Get the graph specifying a parallel star forest
Not Collective
Input Parameter:
sf- star forest
Output Parameters:
nroots- number of root vertices on the current process (these are possible targets for other process to attach leaves)nleaves- number of leaf vertices on the current process, each of these references a root on any processilocal- locations of leaves in leafdata buffers (if returned value isNULL, it means leaves are in contiguous storage)iremote- remote locations of root vertices for each leaf on the current process
Level: intermediate
See also: PetscSF, PetscSFType, PetscSFCreate(), PetscSFView(), PetscSFSetGraph()
External Links
- PETSc Manual:
Vec/PetscSFGetGraph
PETSc.LibPETSc.PetscSFGetGraphLayout — Method
nleaves::PetscInt,iloc::Vector{PetscInt},gremote::Vector{PetscInt} = PetscSFGetGraphLayout(petsclib::PetscLibType, sf::PetscSF, layout::PetscLayout)Get the global indices and PetscLayout that describe this star forest
Collective
Input Parameter:
sf- star forest
Output Parameters:
layout-PetscLayoutdefining the global space for rootsnleaves- number of leaf vertices on the current process, each of these references a root on any processilocal- locations of leaves in leafdata buffers, orNULLfor contiguous storagegremote- root vertices in global numbering corresponding to leaves in ilocal
Level: intermediate
See also: PetscSF, PetscSFSetGraphLayout(), PetscSFCreate(), PetscSFView(), PetscSFSetGraph(), PetscSFGetGraph()
External Links
- PETSc Manual:
Vec/PetscSFGetGraphLayout
PETSc.LibPETSc.PetscSFGetGroups — Method
incoming::MPI_Group,outgoing::MPI_Group = PetscSFGetGroups(petsclib::PetscLibType, sf::PetscSF)gets incoming and outgoing process groups
Collective
Input Parameter:
sf- star forest
Output Parameters:
incoming- group of origin processes for incoming edges (leaves that reference my roots)outgoing- group of destination processes for outgoing edges (roots that I reference)
Level: developer
See also: PetscSF, PetscSFGetWindow(), PetscSFRestoreWindow()
External Links
- PETSc Manual:
PetscSF/PetscSFGetGroups
PETSc.LibPETSc.PetscSFGetLeafRange — Method
minleaf::PetscInt,maxleaf::PetscInt = PetscSFGetLeafRange(petsclib::PetscLibType, sf::PetscSF)Get the active leaf ranges
Not Collective
Input Parameter:
sf- star forest
Output Parameters:
minleaf- minimum active leaf on this MPI process. Returns 0 if there are no leaves.maxleaf- maximum active leaf on this MPI process. Returns -1 if there are no leaves.
Level: developer
See also: PetscSF, PetscSFType, PetscSFCreate(), PetscSFView(), PetscSFSetGraph(), PetscSFGetGraph()
External Links
- PETSc Manual:
PetscSF/PetscSFGetLeafRange
PETSc.LibPETSc.PetscSFGetLeafRanks — Method
niranks::PetscMPIInt,iranks::Vector{PetscMPIInt},ioffset::Vector{PetscInt},irootloc::Vector{PetscInt} = PetscSFGetLeafRanks(petsclib::PetscLibType, sf::PetscSF)Get leaf MPI ranks referencing roots on this process
Not Collective
Input Parameter:
sf- star forest
Output Parameters:
niranks- number of leaf MPI processes referencing roots on this processiranks- [niranks] array of MPI ranksioffset- [niranks+1] offset inirootlocfor each MPI processirootloc- [ioffset[niranks]] concatenated array holding local indices of roots referenced by each leaf MPI process
Level: developer
See also: PetscSF, PetscSFGetRootRanks()
External Links
- PETSc Manual:
PetscSF/PetscSFGetLeafRanks
PETSc.LibPETSc.PetscSFGetMultiSF — Method
multi::PetscSF = PetscSFGetMultiSF(petsclib::PetscLibType, sf::PetscSF)gets the inner PetscSF implementing gathers and scatters
Collective
Input Parameter:
sf- star forest that may contain roots with 0 or with more than 1 vertex
Output Parameter:
multi- star forest with split roots, such that each root has degree exactly 1 (has one leaf)
Level: developer
See also: PetscSF, PetscSFSetGraph(), PetscSFGatherBegin(), PetscSFScatterBegin(), PetscSFComputeMultiRootOriginalNumbering()
External Links
- PETSc Manual:
PetscSF/PetscSFGetMultiSF
PETSc.LibPETSc.PetscSFGetRanksSF — Method
rsf::PetscSF = PetscSFGetRanksSF(petsclib::PetscLibType, sf::PetscSF)gets the PetscSF to perform communications with root ranks
Collective
Input Parameter:
sf- star forest
Output Parameter:
rsf- the star forest with a single root per MPI process to perform communications
Level: developer
See also: PetscSF, PetscSFSetGraph(), PetscSFGetRootRanks()
External Links
- PETSc Manual:
PetscSF/PetscSFGetRanksSF
PETSc.LibPETSc.PetscSFGetRootRanks — Method
nranks::PetscMPIInt,ranks::Vector{PetscMPIInt},roffset::Vector{PetscInt},rmine::Vector{PetscInt},rremote::Vector{PetscInt} = PetscSFGetRootRanks(petsclib::PetscLibType, sf::PetscSF)Get the root MPI ranks and number of vertices referenced by leaves on this process
Not Collective
Input Parameter:
sf- star forest
Output Parameters:
nranks- number of MPI processes referenced by local partranks- [nranks] array of MPI ranksroffset- [nranks+1] offset inrmineandrremotefor each MPI processrmine- [roffset[nranks]] concatenated array holding local indices referencing each remote MPI process, orNULLrremote- [roffset[nranks]] concatenated array holding remote indices referenced for each remote MPI process, orNULL
Level: developer
See also: PetscSF, PetscSFGetLeafRanks()
External Links
- PETSc Manual:
PetscSF/PetscSFGetRootRanks
PETSc.LibPETSc.PetscSFGetSubSF — Method
subSF::PetscSF = PetscSFGetSubSF(petsclib::PetscLibType, mainsf::PetscSF, map::ISLocalToGlobalMapping)Returns an PetscSF for a specific subset of points. Leaves are re-numbered to reflect the new ordering
Collective
Input Parameters:
mainsf-PetscSFstructuremap- aISLocalToGlobalMappingthat contains the subset of points
Output Parameter:
subSF- a subset of themainSFfor the desired subset.
Level: intermediate
See also: PetscSF
External Links
- PETSc Manual:
DMNetwork/PetscSFGetSubSF
PETSc.LibPETSc.PetscSFGetType — Method
type::String = PetscSFGetType(petsclib::PetscLibType, sf::PetscSF)Get the PetscSF communication implementation
Not Collective
Input Parameter:
sf- thePetscSFcontext
Output Parameter:
type- thePetscSFtype name
Level: intermediate
See also: PetscSF, PetscSFType, PetscSFSetType(), PetscSFCreate()
External Links
- PETSc Manual:
PetscSF/PetscSFGetType
PETSc.LibPETSc.PetscSFInitializePackage — Method
PetscSFInitializePackage(petsclib::PetscLibType)Initialize PetscSF package
Logically Collective
Level: developer
See also: PetscSF, PetscSFFinalizePackage()
External Links
- PETSc Manual:
Sys/PetscSFInitializePackage
PETSc.LibPETSc.PetscSFMerge — Method
merged::PetscSF = PetscSFMerge(petsclib::PetscLibType, sfa::PetscSF, sfb::PetscSF)append/merge indices of sfb into sfa, with preference for sfb
Collective
Input Parameters:
sfa- defaultPetscSFsfb- additional edges to add/replace edges insfa
Output Parameter:
merged- newPetscSFwith combined edges
Level: intermediate
See also: PetscSF, PetscSFCompose()
External Links
- PETSc Manual:
PetscSF/PetscSFMerge
PETSc.LibPETSc.PetscSFRegister — Method
PetscSFRegister(petsclib::PetscLibType, name::String, create::external)Adds an implementation of the PetscSF communication protocol.
Not Collective, No Fortran Support
Input Parameters:
name- name of a new user-defined implementationcreate- routine to create method context
See also: PetscSF, PetscSFType, PetscSFRegisterAll(), PetscSFInitializePackage()
External Links
- PETSc Manual:
PetscSF/PetscSFRegister
PETSc.LibPETSc.PetscSFReset — Method
PetscSFReset(petsclib::PetscLibType, sf::PetscSF)Reset a star forest so that different sizes or neighbors can be used
Collective
Input Parameter:
sf- star forest
Level: advanced
See also: PetscSF, PetscSFCreate(), PetscSFSetGraph(), PetscSFDestroy()
External Links
- PETSc Manual:
PetscSF/PetscSFReset
PETSc.LibPETSc.PetscSFSetFromOptions — Method
PetscSFSetFromOptions(petsclib::PetscLibType, sf::PetscSF)set PetscSF options using the options database
Logically Collective
Input Parameter:
sf- star forest
Options Database Keys:
-sf_type (basic|window|neighbor)- implementation type, seePetscSFSetType()-sf_rank_order (true|false)- sort composite points for gathers and scatters in MPI rank order, gathers are non-deterministic otherwise-sf_use_default_stream- Assume callers ofPetscSFcomputed the input root/leafdata with the default CUDA stream.PetscSFwill also
use the default stream to process data. Therefore, no stream synchronization is needed between PetscSF and its caller (default: true). If true, this option only works with -use_gpu_aware_mpi 1.
-sf_use_stream_aware_mpi- Assume the underlying MPI is CUDA-stream aware andPetscSFwon't sync streams for send/recv buffers passed to MPI (default: false).
If true, this option only works with -use_gpu_aware_mpi 1.
-sf_backend (cuda|hip|kokkos)- Select the device backendPetscSFuses. On CUDA (HIP) devices, one can choosecuda(hip) orkokkoswith the default beingkokkos.
On other devices, the only available is kokkos.
Level: intermediate
See also: PetscSF, PetscSFCreate(), PetscSFSetType()
External Links
- PETSc Manual:
PetscSF/PetscSFSetFromOptions
PETSc.LibPETSc.PetscSFSetGraph — Method
PetscSFSetGraph(petsclib::PetscLibType, sf::PetscSF, nroots::PetscInt, nleaves::PetscInt, ilocal::Vector{PetscInt}, localmode::PetscCopyMode, iremote::Vector{PetscSFNode}, remotemode::PetscCopyMode)Set a parallel star forest
Collective
Input Parameters:
sf- star forestnroots- number of root vertices on the current MPI process (these are possible targets for other process to attach leaves)nleaves- number of leaf vertices on the current MPI process, each of these references a root on any processilocal- locations of leaves in leafdata buffers (locations must be >= 0, enforced during setup in debug mode), passNULLfor contiguous storage (same as passing (0, 1, 2, ..., nleaves-1))localmode- copy mode forilocaliremote- remote locations of root vertices for each leaf on the current process, length is `nleaves' (locations must be >= 0, enforced during setup in debug mode)remotemode- copy mode foriremote
Level: intermediate
See also: PetscSF, PetscSFType, PetscSFCreate(), PetscSFView(), PetscSFGetGraph(), PetscSFSetGraphWithPattern()
External Links
- PETSc Manual:
PetscSF/PetscSFSetGraph
PETSc.LibPETSc.PetscSFSetGraphFromCoordinates — Method
PetscSFSetGraphFromCoordinates(petsclib::PetscLibType, sf::PetscSF, nroots::PetscInt, nleaves::PetscInt, dim::PetscInt, tol::PetscReal, rootcoords::Vector{PetscReal}, leafcoords::Vector{PetscReal})Create SF by fuzzy matching leaf coordinates to root coordinates
Collective
Input Parameters:
sf- PetscSF to set graph onnroots- number of root coordinatesnleaves- number of leaf coordinatesdim- spatial dimension of coordinatestol- positive tolerance for matchingrootcoords- array of root coordinates in which root i component d is [i*dim+d]leafcoords- array of root coordinates in which leaf i component d is [i*dim+d]
See also: PetscSFCreate(), PetscSFSetGraph(), PetscSFCreateByMatchingIndices()
External Links
- PETSc Manual:
PetscSF/PetscSFSetGraphFromCoordinates
PETSc.LibPETSc.PetscSFSetGraphLayout — Method
PetscSFSetGraphLayout(petsclib::PetscLibType, sf::PetscSF, layout::PetscLayout, nleaves::PetscInt, ilocal::Vector{PetscInt}, localmode::PetscCopyMode, gremote::Vector{PetscInt})Set a PetscSF communication pattern using global indices and a PetscLayout
Collective
Input Parameters:
sf- star forestlayout-PetscLayoutdefining the global space for roots, i.e. which roots are owned by each MPI processnleaves- number of leaf vertices on the current process, each of these references a root on any MPI processilocal- locations of leaves in leafdata buffers, passNULLfor contiguous storage, that is the locations are in [0,nleaves)localmode- copy mode forilocalgremote- root vertices in global numbering corresponding to the leaves
Level: intermediate
See also: PetscSF, PetscSFGetGraphLayout(), PetscSFCreate(), PetscSFView(), PetscSFSetGraph(), PetscSFGetGraph()
External Links
- PETSc Manual:
PetscSF/PetscSFSetGraphLayout
PETSc.LibPETSc.PetscSFSetGraphSection — Method
PetscSFSetGraphSection(petsclib::PetscLibType, sf::PetscSF, localSection::PetscSection, globalSection::PetscSection)Sets the PetscSF graph (communication pattern) encoding the parallel dof overlap based upon the PetscSection describing the data layout.
Input Parameters:
sf- ThePetscSFlocalSection-PetscSectiondescribing the local data layoutglobalSection-PetscSectiondescribing the global data layout
Level: developer
See also: PetscSF, PetscSFSetGraph(), PetscSFSetGraphLayout()
External Links
- PETSc Manual:
PetscSF/PetscSFSetGraphSection
PETSc.LibPETSc.PetscSFSetGraphWithPattern — Method
PetscSFSetGraphWithPattern(petsclib::PetscLibType, sf::PetscSF, map::PetscLayout, pattern::PetscSFPattern)Sets the graph of a PetscSF with a specific pattern
Collective
Input Parameters:
sf- ThePetscSFmap- Layout of roots over all processes (not used when pattern isPETSCSF_PATTERN_ALLTOALL)pattern- One ofPETSCSF_PATTERN_ALLGATHER,PETSCSF_PATTERN_GATHER,PETSCSF_PATTERN_ALLTOALL
Level: intermediate
See also: PetscSF, PetscSFCreate(), PetscSFView(), PetscSFGetGraph()
External Links
- PETSc Manual:
PetscSF/PetscSFSetGraphWithPattern
PETSc.LibPETSc.PetscSFSetRankOrder — Method
PetscSFSetRankOrder(petsclib::PetscLibType, sf::PetscSF, flg::PetscBool)sort multi-points for gathers and scatters by MPI rank order
Logically Collective
Input Parameters:
sf- star forestflg-PETSC_TRUEto sort,PETSC_FALSEto skip sorting (false has a lower setup cost, but is non-deterministic)
Level: advanced
See also: PetscSF, PetscSFType, PetscSFGatherBegin(), PetscSFScatterBegin()
External Links
- PETSc Manual:
PetscSF/PetscSFSetRankOrder
PETSc.LibPETSc.PetscSFSetType — Method
PetscSFSetType(petsclib::PetscLibType, sf::PetscSF, type::String)Set the PetscSF communication implementation
Collective
Input Parameters:
sf- thePetscSFcontexttype- a known method
$PETSCSFWINDOW - MPI-2/3 one-sided PETSCSFBASIC - basic implementation using MPI-1 two-sided$
Options Database Key:
-sf_type (basic|window|neighbor)- Sets the method; seePetscSFType
Level: intermediate
See also: PetscSF, PetscSFType, PetscSFCreate()
External Links
- PETSc Manual:
PetscSF/PetscSFSetType
PETSc.LibPETSc.PetscSFSetUp — Method
PetscSFSetUp(petsclib::PetscLibType, sf::PetscSF)set up communication structures for a PetscSF, after this is done it may be used to perform communication
Collective
Input Parameter:
sf- star forest communication object
Level: beginner
See also: PetscSF, PetscSFType, PetscSFSetFromOptions(), PetscSFSetType()
External Links
- PETSc Manual:
PetscSF/PetscSFSetUp
PETSc.LibPETSc.PetscSFSetUpRanks — Method
PetscSFSetUpRanks(petsclib::PetscLibType, sf::PetscSF, dgroup::MPI_Group)Set up data structures associated with MPI ranks; this is for internal use by PetscSF implementations.
Collective
Input Parameters:
sf-PetscSFto set up;PetscSFSetGraph()must have been calleddgroup-MPI_Groupof ranks to be distinguished (e.g., for self or shared memory exchange)
Level: developer
See also: PetscSF, PetscSFGetRootRanks()
External Links
- PETSc Manual:
PetscSF/PetscSFSetUpRanks
PETSc.LibPETSc.PetscSFView — Method
PetscSFView(petsclib::PetscLibType, sf::PetscSF, viewer::PetscViewer)view a star forest
Collective
Input Parameters:
sf- star forestviewer- viewer to display graph, for examplePETSC_VIEWER_STDOUT_WORLD
Level: beginner
See also: PetscSF, PetscViewer, PetscSFCreate(), PetscSFSetGraph()
External Links
- PETSc Manual:
PetscSF/PetscSFView
PETSc.LibPETSc.PetscSFViewFromOptions — Method
PetscSFViewFromOptions(petsclib::PetscLibType, A::PetscSF, obj, name::String)View a PetscSF based on arguments in the options database
Collective
Input Parameters:
A- the star forestobj- Optional object that provides the prefix for the option namesname- command line option
Options Database Key:
-name [viewertype][:...]- option name and values. SeePetscObjectViewFromOptions()for the possible arguments
Level: intermediate
See also: PetscSF, PetscSFView, PetscObjectViewFromOptions(), PetscSFCreate()
External Links
- PETSc Manual:
PetscSF/PetscSFViewFromOptions
PETSc.LibPETSc.PetscSFWindowGetFlavorType — Method
flavor::PetscSFWindowFlavorType = PetscSFWindowGetFlavorType(petsclib::PetscLibType, sf::PetscSF)Get PETSCSFWINDOW flavor type for PetscSF communication
Logically Collective
Input Parameter:
sf- star forest for communication of typePETSCSFWINDOW
Output Parameter:
flavor- flavor type
Level: advanced
See also: PetscSF, PETSCSFWINDOW, PetscSFSetFromOptions(), PetscSFWindowSetFlavorType()
External Links
- PETSc Manual:
PetscSF/PetscSFWindowGetFlavorType
PETSc.LibPETSc.PetscSFWindowGetInfo — Method
info::MPI_Info = PetscSFWindowGetInfo(petsclib::PetscLibType, sf::PetscSF)Get the MPI_Info handle used for windows allocation
Logically Collective
Input Parameter:
sf- star forest for communication
Output Parameter:
info-MPI_Infohandle
Level: advanced
See also: PetscSF, PETSCSFWINDOW, PetscSFSetFromOptions(), PetscSFWindowSetInfo()
External Links
- PETSc Manual:
PetscSF/PetscSFWindowGetInfo
PETSc.LibPETSc.PetscSFWindowGetSyncType — Method
sync::PetscSFWindowSyncType = PetscSFWindowGetSyncType(petsclib::PetscLibType, sf::PetscSF)Get synchronization type for PetscSF communication of type PETSCSFWINDOW
Logically Collective
Input Parameter:
sf- star forest for communication
Output Parameter:
sync- synchronization type
Level: advanced
See also: PetscSF, PETSCSFWINDOW, PetscSFSetFromOptions(), PetscSFWindowSetSyncType(), PetscSFWindowSyncType
External Links
- PETSc Manual:
PetscSF/PetscSFWindowGetSyncType
PETSc.LibPETSc.PetscSFWindowSetFlavorType — Method
PetscSFWindowSetFlavorType(petsclib::PetscLibType, sf::PetscSF, flavor::PetscSFWindowFlavorType)Set flavor type for MPI_Win creation
Logically Collective
Input Parameters:
sf- star forest for communication of typePETSCSFWINDOWflavor- flavor type
Options Database Key:
-sf_window_flavor flavor- sets the flavor type CREATE, DYNAMIC, ALLOCATE or SHARED (seePetscSFWindowFlavorType)
Level: advanced
See also: PetscSF, PETSCSFWINDOW, PetscSFSetFromOptions(), PetscSFWindowGetFlavorType()
External Links
- PETSc Manual:
PetscSF/PetscSFWindowSetFlavorType
PETSc.LibPETSc.PetscSFWindowSetInfo — Method
PetscSFWindowSetInfo(petsclib::PetscLibType, sf::PetscSF, info::MPI_Info)Set the MPI_Info handle that will be used for subsequent windows allocation
Logically Collective
Input Parameters:
sf- star forest for communicationinfo-MPI_Infohandle
Level: advanced
See also: PetscSF, PETSCSFWINDOW, PetscSFSetFromOptions(), PetscSFWindowGetInfo()
External Links
- PETSc Manual:
PetscSF/PetscSFWindowSetInfo
PETSc.LibPETSc.PetscSFWindowSetSyncType — Method
PetscSFWindowSetSyncType(petsclib::PetscLibType, sf::PetscSF, sync::PetscSFWindowSyncType)Set synchronization type for PetscSF communication of type PETSCSFWINDOW
Logically Collective
Input Parameters:
sf- star forest for communicationsync- synchronization type
Options Database Key:
-sf_window_sync sync- sets the synchronization type FENCE, LOCK, or ACTIVE (seePetscSFWindowSyncType)
Level: advanced
See also: PetscSF, PETSCSFWINDOW, PetscSFSetFromOptions(), PetscSFWindowGetSyncType(), PetscSFWindowSyncType
External Links
- PETSc Manual:
PetscSF/PetscSFWindowSetSyncType
Communication (hand-written wrappers)
PETSc.LibPETSc.PetscSFBcastBegin — Method
PetscSFBcastBegin(petsclib::PetscLibType, sf::PetscSF, unit::MPI.Datatype, rootdata, leafdata, op::MPI.Op)Begin broadcasting root values to leaves: for each leaf, leafdata[leaf] = op(leafdata[leaf], rootdata[root]).
unit is the MPI datatype of one entry (e.g. MPI.Datatype(Float64) or MPI.Datatype(petsclib.PetscInt)), rootdata and leafdata are Arrays (or raw pointers) of that type with the SF's root and leaf counts. op is usually MPI.REPLACE; use MPI.SUM etc. to combine with the existing leaf values. Both arrays must stay alive until PetscSFBcastEnd returns.
See also: PetscSF, PetscSFBcastEnd(), PetscSFSetGraph()
External Links
- PETSc Manual:
Vec/PetscSFBcastBegin
PETSc.LibPETSc.PetscSFBcastEnd — Method
PetscSFBcastEnd(petsclib::PetscLibType, sf::PetscSF, unit::MPI.Datatype, rootdata, leafdata, op::MPI.Op)End a broadcast started with PetscSFBcastBegin; must be called with the same arguments.
unit is the MPI datatype of one entry (e.g. MPI.Datatype(Float64) or MPI.Datatype(petsclib.PetscInt)), rootdata and leafdata are Arrays (or raw pointers) of that type with the SF's root and leaf counts.
See also: PetscSF, PetscSFBcastBegin(), PetscSFSetGraph()
External Links
- PETSc Manual:
Vec/PetscSFBcastEnd
PETSc.LibPETSc.PetscSFFetchAndOpBegin — Method
PetscSFFetchAndOpBegin(petsclib::PetscLibType, sf::PetscSF, unit::MPI.Datatype, rootdata, leafdata, leafupdate, op::MPI.Op)Begin a fetch-and-op: every leaf fetches the current root value into leafupdate and then applies rootdata[root] = op(rootdata[root], leafdata[leaf]), atomically per root.
unit is the MPI datatype of one entry (e.g. MPI.Datatype(Float64)); rootdata has the SF's root count, leafdata and leafupdate its leaf count. The arrays must stay alive until PetscSFFetchAndOpEnd returns.
See also: PetscSF, PetscSFFetchAndOpEnd(), PetscSFReduceBegin()
External Links
- PETSc Manual:
Vec/PetscSFFetchAndOpBegin
PETSc.LibPETSc.PetscSFFetchAndOpEnd — Method
PetscSFFetchAndOpEnd(petsclib::PetscLibType, sf::PetscSF, unit::MPI.Datatype, rootdata, leafdata, leafupdate, op::MPI.Op)End a fetch-and-op started with PetscSFFetchAndOpBegin; must be called with the same arguments.
unit is the MPI datatype of one entry (e.g. MPI.Datatype(Float64)); rootdata has the SF's root count, leafdata and leafupdate its leaf count. The arrays must stay alive until PetscSFFetchAndOpEnd returns.
See also: PetscSF, PetscSFFetchAndOpBegin(), PetscSFReduceBegin()
External Links
- PETSc Manual:
Vec/PetscSFFetchAndOpEnd
PETSc.LibPETSc.PetscSFReduceBegin — Method
PetscSFReduceBegin(petsclib::PetscLibType, sf::PetscSF, unit::MPI.Datatype, leafdata, rootdata, op::MPI.Op)Begin reducing leaf values into their roots: rootdata[root] = op(rootdata[root], leafdata[leaf]) over all leaves of a root.
unit is the MPI datatype of one entry (e.g. MPI.Datatype(Float64) or MPI.Datatype(petsclib.PetscInt)), leafdata and rootdata are Arrays (or raw pointers) of that type with the SF's root and leaf counts. Typical ops are MPI.SUM, MPI.MAX, MPI.MIN and MPI.REPLACE. Both arrays must stay alive until PetscSFReduceEnd returns.
See also: PetscSF, PetscSFReduceEnd(), PetscSFSetGraph()
External Links
- PETSc Manual:
Vec/PetscSFReduceBegin
PETSc.LibPETSc.PetscSFReduceEnd — Method
PetscSFReduceEnd(petsclib::PetscLibType, sf::PetscSF, unit::MPI.Datatype, leafdata, rootdata, op::MPI.Op)End a reduction started with PetscSFReduceBegin; must be called with the same arguments.
unit is the MPI datatype of one entry (e.g. MPI.Datatype(Float64) or MPI.Datatype(petsclib.PetscInt)), leafdata and rootdata are Arrays (or raw pointers) of that type with the SF's root and leaf counts.
See also: PetscSF, PetscSFReduceBegin(), PetscSFSetGraph()
External Links
- PETSc Manual:
Vec/PetscSFReduceEnd