BFS_CUDA

Algorithm 1 CUDA_BFS(Graph G(V, E), Source Vertex S)

{

1. Create vertex array Va from all vertices in G(V, E);

2. Create edge array Ea from all edges in G(V, E);

3. Create Frontier array Fa, visited array Xa and cost array Ca of size V;

4. Initialize Fa, Xa to false and Ca to INFINITE;

5. Fa[s]=true;

6. Ca[s]=0;

7. While Fa not Empty do

8.      for each vertex V in parallel do

9.            Invoke CUDA_BFS_KERNEL(Va, Ea, Fa, Xa, Ca) on the grid.

10.    end for

11. end while

}

 

Algorithm 2 CUDA_BFS_KERNEL(Va, Ea, Fa, Xa, Ca)

{

1. tid=getThreadID;

2. if Fa[tid] then

3.    Fa[tid]=false;Xa[tid]=true;

4.    for all neighbors nid of tid do

5.          if NOT Xa[nid] then

6.             Ca[nid]=Ca[nid]+1

7.             Fa[nid]=true;

8.          end if

9.    end for

10.end if

}

 

 

这个算法

Algorithm 1 CUDA_BFS(Graph G(V, E), Source Vertex S)

{

1. Create vertex array Va from all vertices in G(V, E);

2. Create edge array Ea from all edges in G(V, E);

3. Create Frontier array Fa, visited array Xa and cost array Ca of size V;

4. Initialize Fa, Xa to false and Ca to INFINITE;

5. Fa[s]=true;

6. Ca[s]=0;

7. While Fa not Empty do

8.      for each vertex V in parallel do

9.            Invoke CUDA_BFS_KERNEL(Va, Ea, Fa, Xa, Ca) on the grid.

10.    end for

11. end while

}

 

Algorithm 2 CUDA_BFS_KERNEL(Va, Ea, Fa, Xa, Ca)

{

1. tid=getThreadID;

2. if Fa[tid] then

3.    Fa[tid]=false;Xa[tid]=true;

4.    for all neighbors nid of tid do

5.          if NOT Xa[nid] then

6.             Ca[nid]=Ca[nid]+1

7.             Fa[nid]=true;

8.          end if

9.    end for

10.end if

}

 

 

这个算法实现了level synchronization, 一个顶点一个线程,算法复杂度是图的直径(就是从源到叶子的最长距离)即O(diameter).

 

其中数据结构的设计和存储上可以做很多优化。。。这图要是动态地根据一定规则自动生成,那么数据结构的动态性会影响到性能么?多大程度上?问问自己,动动手动动脑子~

 

学习自:Accelerating large graph algorithms on the GPU using CUDA

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值