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 values
  • MPI.MAX: Maximum value
  • MPI.MIN: Minimum value
  • MPI.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
end

Multi-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 data

Performance Considerations

  • Choose appropriate type: PETSCSFNEIGHBOR is 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 first PetscSF
  • sfB - The second PetscSF

Output Parameter:

  • sfBA - The composite PetscSF

Level: developer

See also: PetscSF, PetscSFComposeInverse(), PetscSFGetGraph(), PetscSFSetGraph()

External Links

source
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 first PetscSF
  • sfB - The second PetscSF

Output Parameter:

  • sfBA - The composite PetscSF.

Level: developer

See also: PetscSF, PetscSFCompose(), PetscSFGetGraph(), PetscSFSetGraph(), PetscSFCreateInverseSF()

External Links

source
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

source
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

source
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 forest
  • degree - degree of each root vertex, computed with PetscSFComputeDegreeBegin() and PetscSFComputeDegreeEnd()

Output Parameters:

  • nMultiRoots - (optional) number of multi-roots (roots of multi-PetscSF)
  • multiRootsOrigNumbering - original indices of multi-roots; length of this array is nMultiRoots

Level: developer

See also: PetscSF, PetscSFComputeDegreeBegin(), PetscSFComputeDegreeEnd(), PetscSFGetMultiSF()

External Links

source
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 communicator
  • nsfs - the number of input PetscSF
  • sfs - the array of input PetscSF
  • rootMode - the root mode specifying how roots are handled
  • leafOffsets - the array of local leaf offsets, one for each input PetscSF, or NULL for contiguous storage

Output Parameter:

  • newsf - The resulting PetscSF

Level: advanced

See also: PetscSF, PetscSFCompose(), PetscSFGetGraph(), PetscSFSetGraph(), PetscSFConcatenateRootMode

External Links

source
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

source
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 - PetscLayout defining the global index space and the MPI rank that brokers each index
  • numRootIndices - size of rootIndices
  • rootIndices - array of global indices of which this process requests ownership
  • rootLocalIndices - root local index permutation (NULL if no permutation)
  • rootLocalOffset - offset to be added to rootLocalIndices
  • numLeafIndices - size of leafIndices
  • leafIndices - array of global indices with which this process requires data associated
  • leafLocalIndices - leaf local index permutation (NULL if no permutation)
  • leafLocalOffset - offset to be added to leafLocalIndices

Output Parameters:

  • sfA - star forest representing the communication pattern from the layout space to the leaf space (NULL if 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

source
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 forest
  • nselected - number of selected leaves on this MPI process
  • selected - 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

source
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 forest
  • nselected - number of selected roots on this MPI process
  • selected - indices of the selected roots on this MPI process

Output Parameter:

  • esf - new star forest

Level: advanced

See also: PetscSF, PetscSFSetGraph(), PetscSFGetGraph()

External Links

source
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 - PetscLayout defining the global root space
  • lmap - PetscLayout defining the global leaf space

Output Parameter:

  • sf - The parallel star forest

Level: intermediate

See also: PetscSF, PetscLayout, PetscSFCreate(), PetscSFSetGraph(), PetscLayoutCreate(), PetscSFSetGraphLayout()

External Links

source
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 of sf

Level: advanced

See also: PetscSF, PetscSFType, PetscSFSetGraph()

External Links

source
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 - The PetscSF
  • rootSection - 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), or NULL

Level: developer

See also: PetscSF, PetscSFCreate()

External Links

source
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 - The PetscSF
  • rootSection - 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), or NULL
  • leafSection - Data layout of local points for incoming data (this is the distributed section)

Output Parameter:

  • sectionSF - The new PetscSF

Level: advanced

See also: PetscSF, PetscSFCreate(), PetscSFDistributeSection()

External Links

source
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 forest
  • bs - stride
  • ldr - leading dimension of root space
  • ldl - leading dimension of leaf space

Output Parameter:

  • vsf - the new PetscSF

Level: intermediate

See also: PetscSF, PetscSFCreate(), PetscSFSetGraph()

External Links

source
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

source
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 - The PetscSF
  • rootSection - Section defined on root space

Output Parameters:

  • remoteOffsets - root offsets in leaf storage, or NULL, its length will be the size of the chart of leafSection
  • leafSection - Section defined on the leaf space

Level: advanced

See also: PetscSF, PetscSFCreate(), PetscSFCreateSectionSF()

External Links

source
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 duplicate
  • opt - PETSCSF_DUPLICATE_CONFONLY, PETSCSF_DUPLICATE_RANKS, or PETSCSF_DUPLICATE_GRAPH (see PetscSFDuplicateOption)

Output Parameter:

  • newsf - new communication object

Level: beginner

See also: PetscSF, PetscSFType, PetscSFCreate(), PetscSFSetType(), PetscSFSetGraph()

External Links

source
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 process
  • ilocal - locations of leaves in leafdata buffers (if returned value is NULL, 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

source
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 - PetscLayout defining the global space for roots
  • nleaves - number of leaf vertices on the current process, each of these references a root on any process
  • ilocal - locations of leaves in leafdata buffers, or NULL for contiguous storage
  • gremote - root vertices in global numbering corresponding to leaves in ilocal

Level: intermediate

See also: PetscSF, PetscSFSetGraphLayout(), PetscSFCreate(), PetscSFView(), PetscSFSetGraph(), PetscSFGetGraph()

External Links

source
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

source
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

source
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 process
  • iranks - [niranks] array of MPI ranks
  • ioffset - [niranks+1] offset in irootloc for each MPI process
  • irootloc - [ioffset[niranks]] concatenated array holding local indices of roots referenced by each leaf MPI process

Level: developer

See also: PetscSF, PetscSFGetRootRanks()

External Links

source
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

source
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

source
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 part
  • ranks - [nranks] array of MPI ranks
  • roffset - [nranks+1] offset in rmine and rremote for each MPI process
  • rmine - [roffset[nranks]] concatenated array holding local indices referencing each remote MPI process, or NULL
  • rremote - [roffset[nranks]] concatenated array holding remote indices referenced for each remote MPI process, or NULL

Level: developer

See also: PetscSF, PetscSFGetLeafRanks()

External Links

source
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 - PetscSF structure
  • map - a ISLocalToGlobalMapping that contains the subset of points

Output Parameter:

  • subSF - a subset of the mainSF for the desired subset.

Level: intermediate

See also: PetscSF

External Links

source
PETSc.LibPETSc.PetscSFGetType — Method
type::String = PetscSFGetType(petsclib::PetscLibType, sf::PetscSF)

Get the PetscSF communication implementation

Not Collective

Input Parameter:

  • sf - the PetscSF context

Output Parameter:

  • type - the PetscSF type name

Level: intermediate

See also: PetscSF, PetscSFType, PetscSFSetType(), PetscSFCreate()

External Links

source
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 - default PetscSF
  • sfb - additional edges to add/replace edges in sfa

Output Parameter:

  • merged - new PetscSF with combined edges

Level: intermediate

See also: PetscSF, PetscSFCompose()

External Links

source
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 implementation
  • create - routine to create method context

See also: PetscSF, PetscSFType, PetscSFRegisterAll(), PetscSFInitializePackage()

External Links

source
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

source
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, see PetscSFSetType()
  • -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 of PetscSF computed the input root/leafdata with the default CUDA stream. PetscSF will 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 and PetscSF won'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 backend PetscSF uses. On CUDA (HIP) devices, one can choose cuda (hip) or kokkos with the default being kokkos.

On other devices, the only available is kokkos.

Level: intermediate

See also: PetscSF, PetscSFCreate(), PetscSFSetType()

External Links

source
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 forest
  • nroots - 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 process
  • ilocal - locations of leaves in leafdata buffers (locations must be >= 0, enforced during setup in debug mode), pass NULL for contiguous storage (same as passing (0, 1, 2, ..., nleaves-1))
  • localmode - copy mode for ilocal
  • iremote - 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 for iremote

Level: intermediate

See also: PetscSF, PetscSFType, PetscSFCreate(), PetscSFView(), PetscSFGetGraph(), PetscSFSetGraphWithPattern()

External Links

source
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 on
  • nroots - number of root coordinates
  • nleaves - number of leaf coordinates
  • dim - spatial dimension of coordinates
  • tol - positive tolerance for matching
  • rootcoords - 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

source
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 forest
  • layout - PetscLayout defining the global space for roots, i.e. which roots are owned by each MPI process
  • nleaves - number of leaf vertices on the current process, each of these references a root on any MPI process
  • ilocal - locations of leaves in leafdata buffers, pass NULL for contiguous storage, that is the locations are in [0,nleaves)
  • localmode - copy mode for ilocal
  • gremote - root vertices in global numbering corresponding to the leaves

Level: intermediate

See also: PetscSF, PetscSFGetGraphLayout(), PetscSFCreate(), PetscSFView(), PetscSFSetGraph(), PetscSFGetGraph()

External Links

source
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 - The PetscSF
  • localSection - PetscSection describing the local data layout
  • globalSection - PetscSection describing the global data layout

Level: developer

See also: PetscSF, PetscSFSetGraph(), PetscSFSetGraphLayout()

External Links

source
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 - The PetscSF
  • map - Layout of roots over all processes (not used when pattern is PETSCSF_PATTERN_ALLTOALL)
  • pattern - One of PETSCSF_PATTERN_ALLGATHER, PETSCSF_PATTERN_GATHER, PETSCSF_PATTERN_ALLTOALL

Level: intermediate

See also: PetscSF, PetscSFCreate(), PetscSFView(), PetscSFGetGraph()

External Links

source
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 forest
  • flg - PETSC_TRUE to sort, PETSC_FALSE to skip sorting (false has a lower setup cost, but is non-deterministic)

Level: advanced

See also: PetscSF, PetscSFType, PetscSFGatherBegin(), PetscSFScatterBegin()

External Links

source
PETSc.LibPETSc.PetscSFSetType — Method
PetscSFSetType(petsclib::PetscLibType, sf::PetscSF, type::String)

Set the PetscSF communication implementation

Collective

Input Parameters:

  • sf - the PetscSF context
  • type - 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; see PetscSFType

Level: intermediate

See also: PetscSF, PetscSFType, PetscSFCreate()

External Links

source
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

source
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 - PetscSF to set up; PetscSFSetGraph() must have been called
  • dgroup - MPI_Group of ranks to be distinguished (e.g., for self or shared memory exchange)

Level: developer

See also: PetscSF, PetscSFGetRootRanks()

External Links

source
PETSc.LibPETSc.PetscSFView — Method
PetscSFView(petsclib::PetscLibType, sf::PetscSF, viewer::PetscViewer)

view a star forest

Collective

Input Parameters:

  • sf - star forest
  • viewer - viewer to display graph, for example PETSC_VIEWER_STDOUT_WORLD

Level: beginner

See also: PetscSF, PetscViewer, PetscSFCreate(), PetscSFSetGraph()

External Links

source
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 forest
  • obj - Optional object that provides the prefix for the option names
  • name - command line option

Options Database Key:

  • -name [viewertype][:...] - option name and values. See PetscObjectViewFromOptions() for the possible arguments

Level: intermediate

See also: PetscSF, PetscSFView, PetscObjectViewFromOptions(), PetscSFCreate()

External Links

source
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 type PETSCSFWINDOW

Output Parameter:

  • flavor - flavor type

Level: advanced

See also: PetscSF, PETSCSFWINDOW, PetscSFSetFromOptions(), PetscSFWindowSetFlavorType()

External Links

source
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_Info handle

Level: advanced

See also: PetscSF, PETSCSFWINDOW, PetscSFSetFromOptions(), PetscSFWindowSetInfo()

External Links

source
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

source
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 type PETSCSFWINDOW
  • flavor - flavor type

Options Database Key:

  • -sf_window_flavor flavor - sets the flavor type CREATE, DYNAMIC, ALLOCATE or SHARED (see PetscSFWindowFlavorType)

Level: advanced

See also: PetscSF, PETSCSFWINDOW, PetscSFSetFromOptions(), PetscSFWindowGetFlavorType()

External Links

source
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 communication
  • info - MPI_Info handle

Level: advanced

See also: PetscSF, PETSCSFWINDOW, PetscSFSetFromOptions(), PetscSFWindowGetInfo()

External Links

source
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 communication
  • sync - synchronization type

Options Database Key:

  • -sf_window_sync sync - sets the synchronization type FENCE, LOCK, or ACTIVE (see PetscSFWindowSyncType)

Level: advanced

See also: PetscSF, PETSCSFWINDOW, PetscSFSetFromOptions(), PetscSFWindowGetSyncType(), PetscSFWindowSyncType

External Links

source

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

source
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

source
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

source
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

source
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

source
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

source