GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
2: Hello World in GraphLab

To use GraphLab,

#include <graphlab.hpp>

All of GraphLab lives in the graphlab namespace. You may use

using namespace graphlab;

if you wish, but we recommend against it.

Your main function should begin and end with:

int main(int argc, char** argv) {
graphlab::mpi_tools::init(argc, argv);
... main body ...
graphlab::mpi_tools::finalize();
}

dc is the distributed communication layer which is needed by a number of the core GraphLab objects, whether you are running distributed or not.

Placing the following code in my_first_app.cpp running "make" in the debug/ release/ build folders will create a program which when executed, will print "Hello World!".

#include <graphlab.hpp>
int main(int argc, char** argv) {
graphlab::mpi_tools::init(argc, argv);
dc.cout() << "Hello World!\n";
graphlab::mpi_tools::finalize();
}

dc.cout() provides a wrapper around standard std::cout, but wraps it in a way that when used in a distributed environment, only one copy will print, even though all machines execute it. To try that run the following:

  mpiexec -n 4 ./my_first_app

This should run 4 instances of "my_first_app" all on the local machine. However, only one "Hello World!" will be printed.

Note:
The distributed_control object is the core RPC implementation and has many other capabilities. See GraphLab RPC for details.

In the next section, we will see how to define a distributed graph.