GraphLab的安装和使用

最近更换新的并行计算框架,导师推荐了GraphLab。

很少写C代码,大致看了一下工作量,挑战有些艰巨。这里先记录一下安装过程和helloworld的编译运行过程。

安装基本按照官网上的指导,没遇到什么困难。唯一的小插曲就是make -j 4 中进程数量参数,由于电脑年迈,内存吃紧,第一次make时不出意外地崩了。改成-j 2,完成。可能会出现某个so库文件确实,在指定的位置做一个软链接就可以了。

helloworld:

安装完成后,可以自己写一个示例测试一下,在测试之前可以先使用系统中的example,比如pagerank:

mpiexec -n 2 -hostfile ~/machines $GraphLabpath/release/toolkits/graph_analytics/pagerank --powerlaw=100000

建立新的app,首先进入$GraphLabpath/apps,在该目录下新建一个/helloworld。在/helloworld下新建CMakeLists.txt,内容如下:

project(GraphLab) 
add_graphlab_executable(helloworld [List of cpp files space seperated])

新建helloword.cpp:

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

进入$GraphLabpath/release/apps目录,执行

make

完成编译。(注意,可能没有build结果,需要touch一下/apps目录下面的CMakeLists.txt,然后再执行make。)

运行编译得到的可执行文件:

 mpiexec -n 2 ./helloworld

得到输出:

GRAPHLAB_SUBNET_ID/GRAPHLAB_SUBNET_MASK environment variables not defined.
Using default values
Subnet ID: 0.0.0.0
Subnet Mask: 0.0.0.0
Will find first IPv4 non-loopback address matching the subnet
INFO:     dc.cpp(init:573): Cluster of 2 instances created.
WARNING:  dc.cpp(init:587): Duplicate IP address: 192.168.1.102
WARNING:  dc.cpp(init:592): For maximum performance, GraphLab strongly prefers running just one process per machine.
Say hello from node 0!
Hello World!
Say hello from node 1!

 

 

posted on 2014-04-02 22:11  甲马  阅读(2217)  评论(0编辑  收藏  举报

导航