graphlab试用笔记

1.编译问题

mpi1.6会有hang up 的情况。

使用 1.4.5

https://bbs.archlinux.org/viewtopic.php?id=145518

gcc 必须大于 4.2 

2.sample运行问题

bool line_parser

#include <graphlab.hpp>
#include <iostream>

using namespace std;

struct web_page {
        std::string pagename;
        double pagerank;

        web_page():pagerank(0.0) { }
        explicit web_page(std::string name):pagename(name),pagerank(0.0){ }

        void save(graphlab::oarchive& oarc) const {
                oarc << pagename << pagerank;
        }

        void load(graphlab::iarchive& iarc) {
                iarc >> pagename >> pagerank;
        }
};

typedef graphlab::distributed_graph<web_page, graphlab::empty> graph_type;

bool line_parser(graph_type& graph, const std::string& filename, const std::string& textline) {

        std::cout << "fname : '" << filename << "' and textline : '" << textline << "'\n";

        std::stringstream strm(textline);
        graphlab::vertex_id_type vid;
        std::string pagename;

        // first entry in the line is a vertex ID
        strm >> vid;
        strm >> pagename;
        // insert this web page
        graph.add_vertex(vid, web_page(pagename));

        // while there are elements in the line, continue to read until we fail
        while(1){
                graphlab::vertex_id_type other_vid;
                strm >> other_vid;
                if (strm.fail()){
                        break;
                }
                graph.add_edge(vid, other_vid);
        }

        return 1;
}

int main(int argc, char** argv) {
        graphlab::mpi_tools::init(argc, argv);

        graphlab::distributed_control dc;

        graph_type graph(dc);

        graph.load("/workshop/graphlab/graphlabapi/debug/apps/mytest/graph.txt", line_parser);

        graphlab::mpi_tools::finalize();
}


需要注意:官方示例里面是没有返回值的,这样会在执行时刻报错,

因为:

        const bool success = line_parser(*this, filename, line);
        if (!success) {
          logstream(LOG_WARNING) 
            << "Error parsing line " << linecount << " in "
            << filename << ": " << std::endl
            << "\t\"" << line << "\"" << std::endl;  
          return false;
        }




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值