ALP User Documentation 0.7.alpha
Algebraic Programming User Documentation
|
A Pregel run-time instance. More...
#include <pregel.hpp>
Public Member Functions | |
template<typename IType > | |
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. | |
template<class Op , template< typename > class Id, class Program , typename IOType , typename GlobalProgramData , typename IncomingMessageType , typename OutgoingMessageType > | |
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. | |
const grb::Matrix< MatrixEntryType > & | get_matrix () const noexcept |
Returns the ALP/GraphBLAS matrix representation of the underlying graph. | |
size_t | num_edges () const noexcept |
Queries the number of edges of the graph this Pregel instance has been constructed over. | |
size_t | num_vertices () const noexcept |
Queries the maximum vertex ID for programs running on this Pregel instance. | |
A Pregel run-time instance.
Pregel wraps around graph data and executes computations on said graph. A runtime thus is constructed from graph, and enables running any Pregel algorithm on said graph.
|
inline |
Constructs a Pregel instance from input iterators over some graph.
IType | The type of the input iterator. |
[in] | _m | The maximum vertex ID for excident edges. |
[in] | _n | The maximum vertex ID for incident edges. |
[in] | _start | An iterator pointing to the start element of an a collection of edges. |
[in] | _end | An iterator matching _start in end position. |
All edges to be ingested thus are contained within _start and end.
[in] | _mode | Whether sequential or parallel I/O is to be used. |
The value of _mode only takes effect when there are multiple user processes, such as for example when executing over a distributed-memory cluster. The choice between sequential and parallel I/O should be thus:
On errors during ingestion, this constructor throws exceptions.
|
inline |
Executes a given vertex-centric program on this graph.
The program must be a static function that returns void and takes five input arguments:
The program will be called during each round of a Pregel computation. The program is expected to compute something based on the incoming message and vertex-local state, and (optionally) generate an outgoing message. After each round, the outgoing message at all vertices are broadcast to all its neighbours. The Pregel runtime, again for each vertex, reduces all incoming messages into a single message, after which the next round of computation starts, after which the procedure is repeated.
The program terminates in one of two ways:
On program start, i.e., during the first round, all vertices are active. During the computation phase, any vertex can set itself inactive for subsequent rounds by setting grb::interfaces::PregelState::active to false
. Similarly, any active vertex can vote to halt by setting grb::interfaces::PregelState::voteToHalt to true
.
Reduction of incoming messages to a vertex will occur through an user- defined monoid given by:
Op | The binary operation of the monoid. This includes its domain. |
Id | The identity element of the monoid. |
The following template arguments will be automatically inferred:
Program | The type of the program to-be executed. |
IOType | The type of the state of a single vertex. |
GlobalProgramData | The type of globally accessible read-only program data. |
IncomingMessageType | The type of an incoming message. |
OutgoingMessageType | The type of an outgoing message. |
The arguments to this function are as follows:
[in] | program | The vertex-centric program to execute. |
The same Pregel runtime instance hence can be re-used to execute multiple algorithms on the same graph.
Vertex-centric programs have both vertex-local and global state:
[in] | vertex_state | A vector that contains the state of each vertex. |
[in] | data | Global read-only state for the given program. |
The capacity, size, and number of nonzeroes of vertex_state must equal the maximum vertex ID.
Finally, in the ALP spirit which aims to control all relevant performance aspects, the workspace required by the Pregel runtime must be pre- allocated and passed in:
[in] | in | Where incoming messages are stored. Any initial values may or may not be ignored, depending on the program behaviour during the first round of computation. |
[in] | out | Where outgoing messages are stored. Any initial values will be ignored. |
The capacities and sizes of in and out must equal the maximum vertex ID. For sparse vectors in with more than zero nonzeroes, all initial contents will be overwritten by the identity of the reduction monoid. Any initial contents for out will always be ignored as every round of computation starts with the outgoing message set to the monoid identity.
The contents of in and out after termination of a vertex-centric function are undefined, including when this function returns grb::SUCCESS. Output of the program should be part of the vertex-centric state recorded in vertex_state.
Some statistics are returned after a vertex-centric program terminates:
[out] | rounds | The number of rounds the Pregel program has executed. The initial value to rounds will be ignored. |
The contents of this field shall be undefined when this function does not return grb::SUCCESS.
Vertex-programs execute in rounds and could, if the given program does not infer proper termination conditions, run forever. To curb the number of rounds, the following optional parameter may be given:
[in] | out_buffer | An optional buffer area that should only be set whenever the config::out_sparsify configuration parameter is not set to config::NONE. If that is the case, then out_buffer should have size and capacity equal to the maximum vertex ID. |
[in] | max_rounds | The maximum number of rounds the program may execute. Once reached and not terminated, the program will forcibly terminate. |
To turn off termination after a maximum number of rounds, max_rounds may be set to zero. This is also the default.
Executing a Pregel function returns one of the following error codes:
|
inlinenoexcept |
Returns the ALP/GraphBLAS matrix representation of the underlying graph.
This is useful when an application prefers to sometimes use vertex- centric algorithms and other times prefers direct ALP/GraphBLAS algorithms.
|
inlinenoexcept |
Queries the number of edges of the graph this Pregel instance has been constructed over.
|
inlinenoexcept |
Queries the maximum vertex ID for programs running on this Pregel instance.