142#ifndef _H_GRB_INTERFACES_PREGEL 
  143#define _H_GRB_INTERFACES_PREGEL 
  146#include <graphblas/utils/parser.hpp> 
  153    namespace interfaces {
 
  338            typename MatrixEntryType
 
  389                        throw std::runtime_error( 
"Could not set vector ones" );
 
  392                        throw std::runtime_error( 
"Could not initialise outdegrees" );
 
  394                    if( grb::mxv< grb::descriptors::dense >(
 
  395                            outdegrees, graph, ones, ring
 
  398                        throw std::runtime_error( 
"Could not compute outdegrees" );
 
  401                        throw std::runtime_error( 
"Could not initialise indegrees" );
 
  406                        indegrees, graph, ones, ring
 
  408                        throw std::runtime_error( 
"Could not compute indegrees" );
 
  410                    if( grb::set< grb::descriptors::use_index >(
 
  414                        throw std::runtime_error( 
"Could not compute vertex IDs" );
 
  427                template< 
typename IType >
 
  430                    IType _start, 
const IType _end,
 
  435                    activeVertices( _n ),
 
  443                        throw std::runtime_error( 
"Input graph is bipartite" );
 
  446                        graph, _start, _end, _mode
 
  448                        throw std::runtime_error( 
"Could not build graph" );
 
  500                template< 
typename IType >
 
  502                    const size_t _m, 
const size_t _n,
 
  503                    IType _start, 
const IType _end,
 
  505                ) : 
Pregel( std::max( _m, _n ), _start, _end, _mode ) {}
 
  643                    template< 
typename > 
class Id,
 
  646                    typename GlobalProgramData,
 
  647                    typename IncomingMessageType,
 
  648                    typename OutgoingMessageType
 
  651                    const Program program,
 
  653                    const GlobalProgramData &data,
 
  659                    const size_t max_rounds = 0
 
  663                        "The combiner must be an associate operator" 
  665                    static_assert( std::is_same< typename Op::D1, IncomingMessageType >::value,
 
  666                        "The combiner left-hand input domain should match the incoming message " 
  668                    static_assert( std::is_same< typename Op::D1, IncomingMessageType >::value,
 
  669                        "The combiner right-hand input domain should match the incoming message " 
  671                    static_assert( std::is_same< typename Op::D1, IncomingMessageType >::value,
 
  672                        "The combiner output domain should match the incoming message type." );
 
  717                            IncomingMessageType, bool, IncomingMessageType
 
  738                            std::cerr << 
"Overwriting initial incoming messages since it was not a " 
  742                        ret = 
grb::set( in, Id< IncomingMessageType >::value() );
 
  748                        ret = 
grb::set( out, Id< OutgoingMessageType >::value() );
 
  754                        std::cerr << 
"Error: initialisation failed, but if workspace holds full " 
  755                            << 
"capacity, initialisation should never fail. Please submit a bug " 
  763                        assert( max_rounds == 0 || step < max_rounds );
 
  774                            ]( 
const size_t i ) {
 
  787                                assert( activeVertices[ i ] );
 
  789                                std::cout << 
"Vertex " << i << 
" remains active in step " << step
 
  800                                std::cout << 
"Vertex " << i << 
" sends out message " << out[ i ]
 
  803                            }, activeVertices, vertex_state, in, out, outdegrees, haltVotes, indegrees, IDs
 
  812                            ret = grb::foldl< grb::descriptors::structural >(
 
  813                                halt, haltVotes, activeVertices, andMonoid
 
  818                                std::cout << 
"\t All active vertices voted to halt; " 
  819                                    << 
"terminating Pregel program.\n";
 
  828                            std::cout << 
"\t Number of active vertices was " 
  829                                << 
grb::nnz( activeVertices ) << 
", and ";
 
  832                            ret = ret ? ret : 
grb::set( buffer, activeVertices, 
true );
 
  833                            std::swap( buffer, activeVertices );
 
  835                            std::cout << 
" has now become " << 
grb::nnz( activeVertices ) << 
"\n";
 
  840                        const size_t curActive = 
grb::nnz( activeVertices );
 
  841                        if( ret == 
SUCCESS && curActive == 0 ) {
 
  843                            std::cout << 
"\t All vertices are inactive; " 
  844                                << 
"terminating Pregel program.\n";
 
  850                        if( max_rounds > 0 && step > max_rounds ) {
 
  852                            std::cout << 
"\t Maximum number of Pregel rounds met " 
  853                                << 
"without the program returning a valid termination condition. " 
  854                                << 
"Exiting prematurely with a FAILED error code.\n";
 
  861                        std::cout << 
"\t Starting message exchange\n";
 
  867                            ret = ret ? ret : grb::set< grb::descriptors::structural >(
 
  868                                haltVotes, activeVertices, 
false 
  875                            ret = ret ? ret : grb::set< grb::descriptors::structural >(
 
  876                                in, activeVertices, Id< IncomingMessageType >::value()
 
  882                            ret = grb::vxm< grb::descriptors::structural >(
 
  883                                in, activeVertices, out, graph, ring
 
  894                                ret = ret ? ret : grb::set< grb::descriptors::structural >(
 
  895                                        out_buffer, activeVertices, Id< OutgoingMessageType >::value()
 
  897                                std::swap( out, out_buffer );
 
  903                        std::cout << 
"\t Resetting outgoing message fields and " 
  904                            << 
"starting next compute round\n";
 
  911                        std::cout << 
"Info: Pregel exits after " << step
 
  912                            << 
" rounds with error code " << ret
 
A generalised monoid.
Definition: monoid.hpp:54
 
A generalised semiring.
Definition: semiring.hpp:186
 
Standard identitity for the logical or operator.
Definition: identities.hpp:151
 
Standard identity for the logical AND operator.
Definition: identities.hpp:178
 
Standard identity for numerical addition.
Definition: identities.hpp:57
 
A Pregel run-time instance.
Definition: pregel.hpp:340
 
const grb::Matrix< MatrixEntryType > & get_matrix() const noexcept
Returns the ALP/GraphBLAS matrix representation of the underlying graph.
Definition: pregel.hpp:949
 
size_t num_edges() const noexcept
Queries the number of edges of the graph this Pregel instance has been constructed over.
Definition: pregel.hpp:936
 
size_t num_vertices() const noexcept
Queries the maximum vertex ID for programs running on this Pregel instance.
Definition: pregel.hpp:928
 
Pregel(const size_t _m, const size_t _n, IType _start, const IType _end, const grb::IOMode _mode)
Constructs a Pregel instance from input iterators over some graph.
Definition: pregel.hpp:501
 
grb::RC execute(const Program program, grb::Vector< IOType > &vertex_state, const GlobalProgramData &data, grb::Vector< IncomingMessageType > &in, grb::Vector< OutgoingMessageType > &out, size_t &rounds, grb::Vector< OutgoingMessageType > &out_buffer=grb::Vector< OutgoingMessageType >(0), const size_t max_rounds=0)
Executes a given vertex-centric program on this graph.
Definition: pregel.hpp:650
 
This operator takes the sum of the two input parameters and writes it to the output variable.
Definition: ops.hpp:177
 
This operator assigns the left-hand input if the right-hand input evaluates true.
Definition: ops.hpp:88
 
The logical and.
Definition: ops.hpp:492
 
The logical or.
Definition: ops.hpp:464
 
This operator assigns the right-hand input if the left-hand input evaluates true.
Definition: ops.hpp:143
 
For backends that support multiple user processes this class defines some basic primitives to support...
Definition: spmd.hpp:51
 
The main header to include in order to use the ALP/GraphBLAS API.
 
RC eWiseLambda(const Func f, const Vector< DataType, backend, Coords > &x, Args...)
Executes an arbitrary element-wise user-defined function f on any number of vectors of equal length.
Definition: blas1.hpp:3746
 
RC mxv(Vector< IOType, backend, Coords > &u, const Vector< InputType3, backend, Coords > &u_mask, const Matrix< InputType2, backend, RIT, CIT, NIT > &A, const Vector< InputType1, backend, Coords > &v, const Vector< InputType4, backend, Coords > &v_mask, const Semiring &semiring=Semiring(), const Phase &phase=EXECUTE, const typename std::enable_if< grb::is_semiring< Semiring >::value &&!grb::is_object< IOType >::value &&!grb::is_object< InputType1 >::value &&!grb::is_object< InputType2 >::value &&!grb::is_object< InputType3 >::value &&!grb::is_object< InputType4 >::value, void >::type *const =nullptr)
Right-handed in-place doubly-masked sparse matrix times vector multiplication, .
Definition: blas2.hpp:243
 
RC set(Vector< DataType, backend, Coords > &x, const T val, const Phase &phase=EXECUTE, const typename std::enable_if< !grb::is_object< DataType >::value &&!grb::is_object< T >::value, void >::type *const =nullptr) noexcept
Sets all elements of a vector to the given value.
Definition: io.hpp:857
 
RC buildMatrixUnique(Matrix< InputType, implementation > &A, fwd_iterator1 I, const fwd_iterator1 I_end, fwd_iterator2 J, const fwd_iterator2 J_end, fwd_iterator3 V, const fwd_iterator3 V_end, const IOMode mode)
Assigns nonzeroes to the matrix from a coordinate format.
Definition: io.hpp:1336
 
size_t nnz(const Vector< DataType, backend, Coords > &x) noexcept
Request the number of nonzeroes in a given vector.
Definition: io.hpp:479
 
size_t size(const Vector< DataType, backend, Coords > &x) noexcept
Request the size of a given vector.
Definition: io.hpp:235
 
size_t ncols(const Matrix< InputType, backend, RIT, CIT, NIT > &A) noexcept
Requests the column size of a given matrix.
Definition: io.hpp:339
 
size_t capacity(const Vector< InputType, backend, Coords > &x) noexcept
Queries the capacity of the given ALP/GraphBLAS container.
Definition: io.hpp:388
 
size_t nrows(const Matrix< InputType, backend, RIT, CIT, NIT > &A) noexcept
Requests the row size of a given matrix.
Definition: io.hpp:286
 
RC clear(Vector< DataType, backend, Coords > &x) noexcept
Clears a given vector of all nonzeroes.
Definition: io.hpp:574
 
SparsificationStrategy
The set of sparsification strategies supported by the ALP/Pregel interface.
Definition: pregel.hpp:167
 
constexpr const SparsificationStrategy out_sparsify
What sparsification strategy should be applied to the outgoing messages.
Definition: pregel.hpp:242
 
@ ALWAYS
Always applies the sparsification procedure on both internal and user- defined vertex states.
Definition: pregel.hpp:189
 
@ WHEN_HALVED
Sparsify only when the resulting vector would have half (or less) its current number of nonzeroes.
Definition: pregel.hpp:227
 
@ NONE
No sparsification of internal and user-defined vertex states, beyond that which is necessary to bound...
Definition: pregel.hpp:174
 
@ WHEN_REDUCED
Sparsify only when the resulting vector would indeed be sparser.
Definition: pregel.hpp:209
 
static constexpr Descriptor transpose_matrix
Transposes the input matrix prior to applying it.
Definition: descriptors.hpp:71
 
static constexpr Descriptor dense
Indicates that all input and output vectors to an ALP/GraphBLAS primitive are structurally dense.
Definition: descriptors.hpp:151
 
The ALP/GraphBLAS namespace.
Definition: graphblas.hpp:452
 
IOMode
The GraphBLAS input and output functionalities can either be used in a sequential or parallel fashion...
Definition: iomode.hpp:67
 
RC
Return codes of ALP primitives.
Definition: rc.hpp:47
 
@ ILLEGAL
A call to a primitive has determined that one of its arguments was illegal as per the specification o...
Definition: rc.hpp:143
 
@ PANIC
Generic fatal error code.
Definition: rc.hpp:68
 
@ MISMATCH
One or more of the ALP/GraphBLAS objects passed to the primitive that returned this error have mismat...
Definition: rc.hpp:90
 
@ SUCCESS
Indicates the primitive has executed successfully.
Definition: rc.hpp:54
 
@ FAILED
Indicates when one of the grb::algorithms has failed to achieve its intended result,...
Definition: rc.hpp:154
 
std::string toString(const RC code)
 
The state of the vertex-center Pregel program that the user may interface with.
Definition: pregel.hpp:266
 
const size_t & num_vertices
The number of vertices in the global graph.
Definition: pregel.hpp:296
 
bool & voteToHalt
Represents whether this (active) vertex votes to terminate the program.
Definition: pregel.hpp:291
 
const size_t & num_edges
The number of edges in the global graph.
Definition: pregel.hpp:301
 
const size_t & indegree
The in-degree of this vertex.
Definition: pregel.hpp:311
 
bool & active
Represents whether the current vertex is active.
Definition: pregel.hpp:282
 
const size_t & round
The current round the vertex-centric program is currently executing.
Definition: pregel.hpp:316
 
const size_t & vertexID
A unique ID of this vertex.
Definition: pregel.hpp:324
 
const size_t & outdegree
The out-degree of this vertex.
Definition: pregel.hpp:306
 
Used to inspect whether a given operator or monoid is associative.
Definition: type_traits.hpp:202
 
Used to inspect whether a given type is an ALP operator.
Definition: type_traits.hpp:104