最近更換新的並行計算框架,導師推薦了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!