gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 04:14:16 24 4
gpt4 key购买 nike

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

最佳答案

对此有点生疏。迪克斯特拉怎么样?

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
子任务:找到从节点去的地方
结合:你有共享内存,对吧?

关于graph-theory - 基于 GPU 搜索图上两个节点之间的所有可能路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4601364/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com