CUDA:实现使用NVGRAPH库计算单源最短路径
以下是使用 NVGRAPH 库计算单源最短路径的示例代码:
#include <iostream>
#include <cuda_runtime.h>
#include <nvgraph.h>
int main() {
// Create graph handle
nvgraphHandle_t handle;
nvgraphCreate(&handle);
// Create graph descriptor
nvgraphGraphDescr_t graph;
nvgraphCreateGraphDescr(handle, &graph);
// Define the graph data
const size_t numNodes = 5;
const size_t numEdges = 6;
float weights[] = {1.0, 2.0, 1.0, 3.0, 2.0, 1.0};
int destinationOffsets[] = {0, 1, 2, 4, 5, 6};
int sourceIndices[] = {1, 2, 0, 3, 0, 4};
nvgraphTopologyType_t topology = NVGRAPH_CSR_32;
nvgraphCSRTopology32I_t csrGraph;
nvgraphCreateTopology32I(&csrGraph, topology, numNodes, numEdges, destinationOffsets, sourceI