Parallel Bellman-Ford implementation

ⅰ亾dé卋堺 提交于 2019-12-08 13:11:29

问题


Can anyone point me to a good pseudocode of a simple parallel shortest path algorithm? Or any language, it doesn't matter. I'm having trouble finding good examples =[


回答1:


I eventually implemented it myself for a bitcoin bot using OpenMP:

/*defines the chunk size as 1 contiguous iteration*/
#define CHUNKSIZE 1 
/*forks off the threads*/
#pragma omp parallel private(i) {
/*Starts the work sharing construct*/
#pragma omp for schedule(dynamic, CHUNKSIZE)
        list<list_node>::iterator i;
        for (int u = 0; u < V - 1; u++) {
            if (dist[u] != INT_MAX) {
                for (i = adj[u].begin(); i != adj[u].end(); ++i) {
                    if (dist[i->get_vertex()] > dist[u] + i->get_weight()) {
                        dist[i->get_vertex()] = dist[u] + i->get_weight();
                        pre[i->get_vertex()] = u;
                    }
                }
            }
        }
    }

If you want to look at my full implementation, you can view it as a Gist on my GitHub



来源:https://stackoverflow.com/questions/20033028/parallel-bellman-ford-implementation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!