基于 GPU 搜索图上两个节点之间的所有可能路径

发布于 2024-10-10 13:14:26 字数 404 浏览 0 评论 0原文

我的工作广泛使用 Migliore、Martorana 和 Sciortino 的算法来查找所有可能的简单路径,即在图中没有多次遇到节点的路径,如下所示: 一种查找图中两个节点之间的所有路径的算法。 (虽然这个算法本质上是深度优先搜索并且本质上是直观的递归,但作者还提出了一种非递归的、基于堆栈的实现。)我想知道这样的算法是否可以在 GPU 上实现。目前我正在努力寻找这个问题中任何真正的并行性。例如,监视和分派线程的成本可能会使协作图搜索(通过硬件线程)变得令人望而却步。或者,如果对图进行分区并分配给各个硬件线程进行搜索,则分而治之的策略也可以发挥作用。然而,人们必须弄清楚如何(1)对图进行分区(2)制定子任务以及(3)合并分区上的搜索结果。

My work makes extensive use of the algorithm by Migliore, Martorana and Sciortino for finding all possible simple paths, i.e. ones in which no node is encountered more than once, in a graph as described in: An Algorithm to find All Paths between Two Nodes in a Graph. (Although this algorithm is essentially a depth-first search and intuitively recursive in nature, the authors also present a non-recursive, stack-based implementation.) I'd like to know if such an algorithm can be implemented on the GPU. At the moment I'm struggling to see any real parallelism in this problem. For example, the cost of monitoring and dispatching threads might make the a cooperative graph search (by hardware threads) prohibitive. Alternatively, a divide and conquer strategy could work if the graph is partitioned and assigned to individual hardware threads for searching. However, one would have to figure out how to (1) partition the graph (2) formulate the subtasks and (3) combine the results of the searches on the partitions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暗喜 2024-10-17 13:14:26

这一点有点生疏了。迪克斯特拉怎么样?

Boolean[] visited;              // [node] = true;
Boolean[][] connected;          // [node][i] = node
Vector<Vector<Integer>>[] path; // this should suck
Integer startNode;
Integer endNode;
Queue queue0; //for thread 0
Queue queue1; //for thread 1

while (queue0.hasNext()) {
   Integer node = queue.getNext();
   if visited[node] { 
      continue;
   } else {
      visited[node] = true;
   }

   for (nextNode: connected[node]) {
      for (i) {
         path[nextNode].append(path[node][i].clone().append(node));
      }
      if (nextNode%2 == 0) { queue0.add(nextNode); }
      if (nextNode%2 == 1) { queue1.add(nextNode); }
   }
}

path[endNode][i] // 从 startNode

分区到 endNode 的第 i 条路径:来自节点 % 2
子任务:找到从节点去的地方
结合:你们有共享内存,对吧?

Bit rusty on this. How about Dijkstra?

Boolean[] visited;              // [node] = true;
Boolean[][] connected;          // [node][i] = node
Vector<Vector<Integer>>[] path; // this should suck
Integer startNode;
Integer endNode;
Queue queue0; //for thread 0
Queue queue1; //for thread 1

while (queue0.hasNext()) {
   Integer node = queue.getNext();
   if visited[node] { 
      continue;
   } else {
      visited[node] = true;
   }

   for (nextNode: connected[node]) {
      for (i) {
         path[nextNode].append(path[node][i].clone().append(node));
      }
      if (nextNode%2 == 0) { queue0.add(nextNode); }
      if (nextNode%2 == 1) { queue1.add(nextNode); }
   }
}

path[endNode][i] // ith path to endNode from startNode

partitioning: came from node % 2
subtasks: find place to go from node
combining: you have shared memory, right?

扶醉桌前 2024-10-17 13:14:26

我不认为你的问题可以轻松地移植到 GPU 上以使其执行速度更快。利用最多 GPU 能力的 GPU 程序:

  • 由数千个线程组成,但线程数量是恒定的。不会产生新线程或杀死以前的线程。
  • 更喜欢合并内存访问。如果相邻线程访问完全不同的内存区域(通常是图算法),速度将会很慢。
  • 不喜欢递归堆栈。最新的 NVIDIA Fermi 卡确实支持函数调用,并且线程可以拥有堆栈,但由于线程数量较多,堆栈非常短(或消耗大量内存)。

我并不是说不存在高效的 GPU 算法,但我相信没有直接的方法可以将现有算法转换为高效的代码。

I don't think that your problem can be easily ported on a GPU in a way that it would perform faster. GPU programs that utilise most GPU power:

  • Consist of thousants of threads, but the number of them is constant. No spawning of new threads or killing previous ones.
  • Prefer coalesced memory access. If neighbouring threads access completely different regions of memory (and usually graph algorithms do) it will be slow.
  • Don't like recurssion and stacks. Newest NVIDIA Fermi cards do support function calls and threads can have a stack, but because of high thread count, the stacks are very short (or consume a lot of memory).

I don't say that there is no efficient GPU algorithm, but I believe that there is no straightforward way to transform existing algorithms into an efficient code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文