Bellman-Ford并行实施 [英] Parallel Bellman-Ford implementation

查看:168
本文介绍了Bellman-Ford并行实施的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能给我指出一个简单的并行最短路径算法的良好伪代码吗?或任何语言都没关系.我很难找到好的例子= [

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 =[

推荐答案

我最终使用OpenMP自己为比特币机器人实现了它:

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;
                    }
                }
            }
        }
    }

如果要查看我的完整实现,可以在我的GitHub中将其视为Gist a>

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

这篇关于Bellman-Ford并行实施的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆