ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
GraphBLAS.h File Reference

The graphs and the sparse matrices of ADS as matrices of SuiteSparse:GraphBLAS (https://github.com/DrTimothyAldenDavis/GraphBLAS), so that the operations of GraphBLAS, and the algorithms of LAGraph written on them, run on the structures of ADS, beyond the book: More...

#include "ADS/Contract.h"
#include "ADS/graph/StaticGraph.h"
#include "ADS/numeric/CsrMatrix.h"
#include <algorithm>
#include <concepts>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

Go to the source code of this file.

Classes

class  ADS::graphblas::Matrix
 the owner of a GrB_Matrix, freed at its end More...

Namespaces

namespace  ADS
namespace  ADS::graphblas

Macros

#define ADS_GRB_TYPED(F, T, ...)
 the call of the typed function of GraphBLAS F##_< T >, for the type T of the values of the arguments

Functions

void ADS::graphblas::check (GrB_Info r, const char *what)
 throws if \( r \) is not a success of GraphBLAS, naming what
template<class T>
GrB_Type ADS::graphblas::type (void)
 the type of GraphBLAS of the numbers T: GrB_BOOL, the integers of 8 to 64 bits with or without sign, GrB_FP32 and GrB_FP64
template<std::integral I>
GrB_Type ADS::graphblas::indexType (void)
 the type of GraphBLAS of the indices I, not negative, read by their size
template<class G>
requires ( detail::ArcRows< G > )
Matrix ADS::graphblas::copy (const G &g)
 the \( n \times n \) matrix of the arcs of \( g \), copied by GrB_Matrix_build() (for the layouts that view() does not take), of the weights of \( g \), or true if it is unweighted
template<CsrArrays G>
Matrix ADS::graphblas::view (const G &g)
 the \( n \times n \) matrix of the arcs of \( g \) by rows, its offsets, heads and weights read in place, iso-valued true if \( g \) is unweighted; a graph whose rows are not known to be sorted (an ArrayGraph, in the order of its edges) is checked in \( O( n + a ) \) time, and copied by copy() if the heads of some row do not increase, since GraphBLAS reads the columns of a row of a matrix that is not jumbled in increasing order
template<class T, class I, class P>
Matrix ADS::graphblas::view (const BasicCsrMatrix< T, I, P > &A)
 the \( m \times n \) matrix \( A \) by rows, its offsets, columns and values read in place
template<class T, class I = std::uint32_t, class P = ADS::detail::CsrOffset< I >>
BasicCsrMatrix< T, I, P > ADS::graphblas::toCsr (GrB_Matrix A)
 the matrix \( A \) of GraphBLAS copied into a BasicCsrMatrix of the values T, the columns I and the offsets P, by its triplets

Detailed description

The graphs and the sparse matrices of ADS as matrices of SuiteSparse:GraphBLAS (https://github.com/DrTimothyAldenDavis/GraphBLAS), so that the operations of GraphBLAS, and the algorithms of LAGraph written on them, run on the structures of ADS, beyond the book:

  • view( g ) of a graph whose rows are plain arrays (the concept CsrArrays: a StaticGraph of the separate layout, an ArrayGraph) is an \( n \times n \) GrB_Matrix by rows whose offsets and columns are offsets() and heads(), and whose values are weightData(), or one value true of a matrix iso-valued (all its entries equal) if the graph is unweighted; the rows of an ArrayGraph, whose heads are in the order of its edges, are checked first, and the graph is copied by copy( g ) if the heads of a row do not increase;
  • view( A ) of a BasicCsrMatrix< T , I , P > is the \( m \times n \) GrB_Matrix by rows of its three arrays.

Both make no copy: the arrays enter a GxB_Container of GraphBLAS 10 as vectors loaded by GxB_Vector_load() with GxB_IS_READONLY, i.e., left to their owner, which GraphBLAS reads and never writes nor frees, and the container becomes the matrix by GxB_load_Matrix_from_Container(). The integers of the offsets and of the columns are read as GrB_UINT32 or GrB_UINT64, by their size, which the integers of ADS, not negative, allow; the values may be booleans, integers of 8 to 64 bits or floating numbers. A graph of the interleaved layout, whose heads and weights alternate in one array, has no such view, and copy( g ) builds a matrix of its arcs by GrB_Matrix_build() instead, in the layout that GraphBLAS chooses, as for any graph of ADS with out(). Conversely, toCsr( A ) copies a GrB_Matrix into a BasicCsrMatrix by its triplets.

A view is Matrix, the owner of the handle, which GrB_Matrix_free() frees at its end, leaving the arrays to ADS. GraphBLAS has the semirings, the masks and the algebraic algorithms (triangles, k-truss, centralities in LAGraph), which ADS does not have and does not replace; the parallel visits and the products of ADS stay its own.

This header is of the set interop: no entry point of ADS includes it, and it needs SuiteSparse:GraphBLAS 10 or later, found by CMake when ADS_WITH_GRAPHBLAS is AUTO or ON (the target ADS::GraphBLAS). The contracts [see Contract.h]: GrB_init() was called; the structure viewed outlives its view and is not changed while it lives; a view is an input of the operations of GraphBLAS, never their output nor changed by GrB_Matrix_setElement() and the like; a failure of GraphBLAS throws std::runtime_error.

See also
T. A. Davis, Algorithm 1000: SuiteSparse:GraphBLAS: graph algorithms in the language of sparse linear algebra, ACM Transactions on Mathematical Software 45(4), 1-25, 2019, doi:10.1145/3322125
T. A. Davis, Algorithm 1037: SuiteSparse:GraphBLAS: parallel graph algorithms in the language of sparse linear algebra, ACM Transactions on Mathematical Software 49(3), 1-30, 2023, doi:10.1145/3577195
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa