最近更换新的并行计算框架,导师推荐了GraphLab。html
不多写C代码,大体看了一下工做量,挑战有些艰巨。这里先记录一下安装过程和helloworld的编译运行过程。node
安装基本按照官网上的指导,没遇到什么困难。惟一的小插曲就是make -j 4 中进程数量参数,因为电脑年迈,内存吃紧,第一次make时不出意外地崩了。改为-j 2,完成。可能会出现某个so库文件确实,在指定的位置作一个软连接就能够了。app
helloworld:框架
安装完成后,能够本身写一个示例测试一下,在测试以前能够先使用系统中的example,好比pagerank:oop
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:ui
#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目录,执行spa
make
完成编译。(注意,可能没有build结果,须要touch一下/apps目录下面的CMakeLists.txt,而后再执行make。)code
运行编译获得的可执行文件:orm
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!