Template Numerical Library: Graph Reduction Lambda Function Reference

Template Numerical Library version\ main:16b9213d5

Loading...
Searching...
No Matches
Graph Reduction Lambda Function Reference

This page provides a comprehensive reference for all lambda function signatures used in graph reduction operations.

# Fetch Lambda Functions

The fetch lambda is used to extract and transform weights from graph edges during reduction.

## For Non-Const Graphs

For non-const graphs (TNL::Graphs::Graph and TNL::Graphs::GraphView) having a sparse adjacency matrix (TNL::Matrices::SparseMatrix, TNL::Matrices::SparseMatrixView), the signature of the fetch lambda is:

auto fetch = [] __cuda_callable__ ( IndexType sourceIdx, IndexType& targetIdx, RealType& weight ) -> FetchValue { ... }
__cuda_callable__
#define __cuda_callable__
Definition Macros.h:49

Parameters:

- sourceIdx - The index of the source graph vertex
- targetIdx - The index of the target graph vertex (can be modified)
- weight - The weight of the graph edge (can be modified)
- Returns: A value of type FetchValue to be used in the reduction

For graphs having other type of the adjacency matrix like dense matrix (TNL::Matrices::DenseMatrix, TNL::Matrices::DenseMatrixView), tridiagonal graphs (TNL::Matrices::TridiagonalMatrix, TNL::Matrices::TridiagonalMatrixView) or multidiagonal (TNL::Matrices::MultidiagonalMatrix, TNL::Matrices::MultidiagonalMatrixView), the column index (representing the target vertex index) is defined implicitly and cannot be changed even for non-constant graphs. The signature then reads as:

auto fetch = [] __cuda_callable__ ( IndexType sourceIdx, IndexType targetIdx, RealType& weight ) -> FetchValue { ... }

Parameters:

- sourceIdx - The index of the source graph vertex
- targetIdx - The index of the target graph vertex (passed by value)
- weight - The weight of the graph edge (can be modified)
- Returns: A value of type FetchValue to be used in the reduction

## For Const Graphs

auto fetch = [] __cuda_callable__ ( IndexType sourceIdx, IndexType targetIdx, const RealType& weight ) -> FetchValue { ... }

Parameters:

- sourceIdx - The index of the source graph vertex
- targetIdx - The index of the target graph vertex (passed by value)
- weight - The weight of the graph edge (const reference)
- Returns: A value of type FetchValue to be used in the reduction

# Reduction Lambda Functions

The reduction lambda defines how weights are combined during the reduction operation.

## Basic Reduction (Without Arguments)

auto reduction = [=] __cuda_callable__ ( const FetchValue& a, const FetchValue& b ) -> FetchValue { ... }

Parameters:

- a - First weight to be reduced
- b - Second weight to be reduced
- Returns: The result of reducing a and b

## Reduction With Argument (Position Tracking)

auto reduction = [] __cuda_callable__ ( Result& a, const Result& b, Index& aIdx, const Index& bIdx ) -> Result { ... }

Parameters:

- a - First weight to be reduced (mutable reference)
- b - Second weight to be reduced (const reference)
- aIdx - Index/position associated with weight a (mutable reference for tracking)
- bIdx - Index/position associated with weight b (const reference)

Note: This variant is used when you need to track which edge produced the final result (e.g., finding the maximum weight and its position).

# Store Lambda Functions

The store lambda is used to store the final reduction result for each vertex.

## Basic Store (Vertex Index Only)

auto store = [=] __cuda_callable__ ( IndexType sourceIdx, const FetchValue& weight ) { ... }

Parameters:

- sourceIdx - The index of the source graph vertex
- weight - The result of the reduction for this vertex

## Store With Argument (Position Tracking)

auto store = [=] __cuda_callable__ ( IndexType sourceIdx, IndexType localIdx, IndexType targetIdx, const Value& weight, bool
isolatedVertex ) {
... }

Parameters:

- sourceIdx - The index of the source graph vertex
- localIdx - The local index of the edge within the vertex (when tracking positions)
- targetIdx - The index of the target vertex of given edge (when tracking positions)
- weight - The result of the reduction for this vertex
- isolatedVertex - Boolean flag indicating whether the vertex has no edges (true if empty). When true, localIdx and targetIdx values are meaningless and should not be used.

## Store With Vertex Index Array Or Condition

auto store = [=] __cuda_callable__ ( IndexType indexOfVertexIdx, IndexType sourceIdx, const FetchValue& weight ) { ... }

Parameters:

- indexOfVertexIdx - The position within the vertexIndexes array or the rank in the set of vertices for which the condition was true.
- sourceIdx - The actual index of the vertex
- weight - The result of the reduction for this vertex

## Store With Vertex Index Array and With Argument

auto store = [=] __cuda_callable__ ( IndexType indexOfVertexIdx, IndexType sourceIdx, IndexType localIdx, IndexType
targetIdx, const FetchValue& weight, bool isolatedVertex ) { ...
}

Parameters:

- indexOfVertexIdx - The position within the vertexIndexes array or the rank in the set of vertices for which the condition was true.
- sourceIdx - The index of the source graph vertex
- localIdx - The position of the edge within the vertex
- targetIdx - The index of the target vertex of given edge
- weight - The result of the reduction for this vertex
- isolatedVertex - Boolean flag indicating whether the vertex has no edges (true if empty). When true, localIdx and targetIdx values are meaningless and should not be used.

# Condition Lambda Functions

The condition lambda determines which vertices should be processed (used in "If" variants).

## Condition Check

auto condition = [=] __cuda_callable__ ( IndexType sourceIdx ) -> bool { ... }

Parameters:

- sourceIdx - The index of the graph vertex
- Returns: true if the vertex should be processed, false otherwise

# Reduction Function Objects

Instead of lambda functions, reduction operations can also be specified using function objects from Function objects for reduction operations or Function objects for reduction operations with argument.

When using function objects:

- They must provide a static template method getIdentity to automatically deduce the identity value
- For WithArgument variants, they must be instances of Function objects for reduction operations with argument
- Common examples: Min, Max, Sum, Product, MinWithArg, MaxWithArg

# Related Pages

- Overview of Graph Reduction Functions - Overview of graph reduction functions