遍历#

cuGraph 遍历算法包含在此目录中

SSSP#

单元测试代码是查找调用 SSSP 示例的最佳位置。

简单 SSSP#

此示例假设您以某种方式创建了 SG 或 MG 图。调用者必须在设备内存中创建距离和前驱节点向量,并将这些向量的原始指针传递给 SSSP 函数。

#include <cugraph/algorithms.hpp>
...
using vertex_t = int32_t;       // or int64_t, whichever is appropriate
using weight_t = float;         // or double, whichever is appropriate
using result_t = weight_t;      // could specify float or double also
raft::handle_t handle;          // Must be configured if MG
auto graph_view = graph.view(); // assumes you have created a graph somehow
vertex_t source;                // Initialized by user

rmm::device_uvector<weight_t> distances_v(graph_view.number_of_vertices(), handle.get_stream());
rmm::device_uvector<vertex_t> predecessors_v(graph_view.number_of_vertices(), handle.get_stream());

cugraph::sssp(handle, graph_view, distances_v.begin(), predecessors_v.begin(), source, std::numeric_limits<weight_t>::max(), false);

BFS#

单元测试代码是查找调用 BFS 示例的最佳位置。

简单 BFS#

此示例假设您以某种方式创建了 SG 或 MG 图。调用者必须在设备内存中创建距离和前驱节点向量,并将这些向量的原始指针传递给 BFS 函数。

#include <cugraph/algorithms.hpp>
...
using vertex_t = int32_t;       // or int64_t, whichever is appropriate
using weight_t = float;         // or double, whichever is appropriate
using result_t = weight_t;      // could specify float or double also
raft::handle_t handle;          // Must be configured if MG
auto graph_view = graph.view(); // assumes you have created a graph somehow
vertex_t source;                // Initialized by user

rmm::device_uvector<weight_t> distances_v(graph_view.number_of_vertices(), handle.get_stream());
rmm::device_uvector<vertex_t> predecessors_v(graph_view.number_of_vertices(), handle.get_stream());

cugraph::bfs(handle, graph_view, d_distances.begin(), d_predecessors.begin(), source, false, std::numeric_limits<vertex_t>::max(), false);