GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
graphlab::context< Engine > Class Template Reference

The context object mediates the interaction between the vertex program and the graphlab execution environment and implements the icontext interface. More...

#include <graphlab/vertex_program/context.hpp>

List of all members.

Public Types

typedef Engine engine_type
typedef icontext< typename
Engine::graph_type, typename
Engine::gather_type, typename
Engine::message_type > 
icontext_type
typedef icontext_type::graph_type graph_type
 the user graph type (typically distributed_graph)
typedef
icontext_type::vertex_id_type 
vertex_id_type
 the global vertex identifier (see graphlab::vertex_id_type).
typedef icontext_type::vertex_type vertex_type
 the opaque vertex_type defined in the ivertex_program::graph_type (typically distributed_graph::vertex_type)
typedef icontext_type::message_type message_type
typedef icontext_type::gather_type gather_type

Public Member Functions

 context (engine_type &engine, graph_type &graph)
 Construct a context for a particular engine and graph pair.
size_t num_vertices () const
 Get the total number of vertices in the graph.
size_t num_edges () const
size_t procid () const
size_t num_procs () const
 Get the number of processes in the current execution.
std::ostream & cout () const
 Returns a standard output object (like cout) which only prints once even when running distributed.
std::ostream & cerr () const
 Returns a standard error object (like cerr) which only prints once even when running distributed.
float elapsed_seconds () const
int iteration () const
void stop ()
void signal (const vertex_type &vertex, const message_type &message=message_type())
void signal_vid (vertex_id_type vid, const message_type &message=message_type())
void post_delta (const vertex_type &vertex, const gather_type &delta)
virtual void clear_gather_cache (const vertex_type &vertex)
virtual void signal (const vertex_type &vertex, const message_type &message=message_type())
 Signal a vertex with a particular message.
virtual void signal_vid (vertex_id_type gvid, const message_type &message=message_type())
 Send a message to a vertex ID.
virtual void post_delta (const vertex_type &vertex, const gather_type &delta)
 Post a change to the cached sum for the vertex.

Detailed Description

template<typename Engine>
class graphlab::context< Engine >

The context object mediates the interaction between the vertex program and the graphlab execution environment and implements the icontext interface.

Template Parameters:
Enginethe engine that is using this context.

Definition at line 44 of file context.hpp.


Member Typedef Documentation

template<typename Engine >
typedef Engine graphlab::context< Engine >::engine_type

The engine that created this context object

Definition at line 51 of file context.hpp.

template<typename Engine >
typedef icontext_type::gather_type graphlab::context< Engine >::gather_type

The type returned by the gather operation. (see ivertex_program::gather_type)

Reimplemented from graphlab::icontext< Engine::graph_type, Engine::gather_type, Engine::message_type >.

Definition at line 61 of file context.hpp.

template<typename Engine >
typedef icontext<typename Engine::graph_type, typename Engine::gather_type, typename Engine::message_type> graphlab::context< Engine >::icontext_type

The parent type

Definition at line 56 of file context.hpp.

template<typename Engine >
typedef icontext_type::message_type graphlab::context< Engine >::message_type

The message type specified by the user-defined vertex-program. (see ivertex_program::message_type)

Reimplemented from graphlab::icontext< Engine::graph_type, Engine::gather_type, Engine::message_type >.

Definition at line 60 of file context.hpp.


Member Function Documentation

template<typename Engine >
std::ostream& graphlab::context< Engine >::cerr ( ) const
inlinevirtual

Returns a standard error object (like cerr) which only prints once even when running distributed.

This returns a C++ standard output stream object which maps directly to std::cerr on machine with process ID 0, and to empty output streamss on all other processes. Calling,

context.cerr() << "Hello World!";

will therefore only print if the code is run on machine 0. This is useful in the finalize operation in aggregators.

Reimplemented from graphlab::icontext< Engine::graph_type, Engine::gather_type, Engine::message_type >.

Definition at line 99 of file context.hpp.

template<typename Engine >
virtual void graphlab::context< Engine >::clear_gather_cache ( const vertex_type vertex)
inlinevirtual

Invalidate the cached gather on the vertex.

Reimplemented from graphlab::icontext< Engine::graph_type, Engine::gather_type, Engine::message_type >.

Definition at line 150 of file context.hpp.

template<typename Engine >
std::ostream& graphlab::context< Engine >::cout ( ) const
inlinevirtual

Returns a standard output object (like cout) which only prints once even when running distributed.

This returns a C++ standard output stream object which maps directly to std::cout on machine with process ID 0, and to empty output streamss on all other processes. Calling,

context.cout() << "Hello World!";

will therefore only print if the code is run on machine 0. This is useful in the finalize operation in aggregators.

Reimplemented from graphlab::icontext< Engine::graph_type, Engine::gather_type, Engine::message_type >.

Definition at line 95 of file context.hpp.

template<typename Engine >
float graphlab::context< Engine >::elapsed_seconds ( ) const
inlinevirtual

Get the elapsed time in seconds

Reimplemented from graphlab::icontext< Engine::graph_type, Engine::gather_type, Engine::message_type >.

Definition at line 106 of file context.hpp.

template<typename Engine >
int graphlab::context< Engine >::iteration ( ) const
inlinevirtual

Return the current interation number (if supported).

Reimplemented from graphlab::icontext< Engine::graph_type, Engine::gather_type, Engine::message_type >.

Definition at line 111 of file context.hpp.

template<typename Engine >
size_t graphlab::context< Engine >::num_edges ( ) const
inlinevirtual

Get the number of edges in the graph

Reimplemented from graphlab::icontext< Engine::graph_type, Engine::gather_type, Engine::message_type >.

Definition at line 83 of file context.hpp.

template<typename Engine >
size_t graphlab::context< Engine >::num_procs ( ) const
inlinevirtual

Get the number of processes in the current execution.

This is typically the number of mpi jobs created:

%> mpiexec -n 16 ./pagerank

would imply that num_procs() returns 16.

Returns:
the number of processes in the current execution

Reimplemented from graphlab::icontext< Engine::graph_type, Engine::gather_type, Engine::message_type >.

Definition at line 93 of file context.hpp.

template<typename Engine >
size_t graphlab::context< Engine >::num_vertices ( ) const
inlinevirtual

Get the total number of vertices in the graph.

Returns:
the total number of vertices in the entire graph.

Reimplemented from graphlab::icontext< Engine::graph_type, Engine::gather_type, Engine::message_type >.

Definition at line 78 of file context.hpp.

template<typename Engine >
void graphlab::context< Engine >::post_delta ( const vertex_type vertex,
const gather_type delta 
)
inline

Post a change to the cached sum for the vertex

Definition at line 142 of file context.hpp.

virtual void graphlab::icontext< Engine::graph_type , Engine::gather_type , Engine::message_type >::post_delta ( const vertex_type vertex,
const gather_type delta 
)
inlinevirtualinherited

Post a change to the cached sum for the vertex.

Often a vertex program will be signaled due to a change in one or a few of its neighbors. However the gather operation will be rerun on all neighbors potentially producing the same value as previous invocations and wasting computation time. To address this some engines support caching (see gather_caching for details) of the gather phase.

When caching is enabled the engines save a copy of the previous gather for each vertex. On subsequent calls to gather if their is a cached gather then the gather phase is skipped and the cached value is passed to the ivertex_program::apply function. Therefore it is the responsibility of the vertex program to update the cache values for neighboring vertices. This is accomplished by using the icontext::post_delta function. Posted deltas are atomically added to the cache.

Parameters:
vertex[in] the vertex whose cache we want to update
delta[in] the change that we want to add to the current cache.

Definition at line 254 of file icontext.hpp.

template<typename Engine >
size_t graphlab::context< Engine >::procid ( ) const
inlinevirtual

Get an estimate of the number of update functions executed up to this point.

Reimplemented from graphlab::icontext< Engine::graph_type, Engine::gather_type, Engine::message_type >.

Definition at line 91 of file context.hpp.

template<typename Engine >
void graphlab::context< Engine >::signal ( const vertex_type vertex,
const message_type message = message_type() 
)
inline

Send a message to a vertex.

Definition at line 121 of file context.hpp.

virtual void graphlab::icontext< Engine::graph_type , Engine::gather_type , Engine::message_type >::signal ( const vertex_type vertex,
const message_type message = message_type() 
)
inlinevirtualinherited

Signal a vertex with a particular message.

This function is an essential part of the GraphLab abstraction and is used to encode iterative computation. Typically a vertex program will signal neighboring vertices during the scatter phase. A vertex program may choose to signal neighbors on when changes made during the previos phases break invariants or warrant future computation on neighboring vertices.

The signal function takes two arguments. The first is mandatory and specifies which vertex to signal. The second argument is optional and is used to send a message. If no message is provided then the default message is used.

Parameters:
vertex[in] The vertex to send the message to
message[in] The message to send, defaults to message_type().

Definition at line 213 of file icontext.hpp.

template<typename Engine >
void graphlab::context< Engine >::signal_vid ( vertex_id_type  vid,
const message_type message = message_type() 
)
inline

Send a message to a vertex ID.

Warning:
This function will be slow since the current machine do not know the location of the vertex ID.
This may be unreliable. signals issued near to engine termination may be lost.

Definition at line 133 of file context.hpp.

virtual void graphlab::icontext< Engine::graph_type , Engine::gather_type , Engine::message_type >::signal_vid ( vertex_id_type  gvid,
const message_type message = message_type() 
)
inlinevirtualinherited

Send a message to a vertex ID.

Warning:
This function will be slow since the current machine do not know the location of the vertex ID. If possible use the the icontext::signal call instead.
Parameters:
gvid[in] the vertex id of the vertex to signal
message[in] the message to send to that vertex, defaults to message_type().

Definition at line 227 of file icontext.hpp.

template<typename Engine >
void graphlab::context< Engine >::stop ( )
inlinevirtual

Force the engine to stop executing additional update functions.

Reimplemented from graphlab::icontext< Engine::graph_type, Engine::gather_type, Engine::message_type >.

Definition at line 116 of file context.hpp.


The documentation for this class was generated from the following file: