免责声明:这篇文章的作者对C++和Python的了解有限,并且对Java和Ruby拥有足够的知识。
"OpenCL编程指南“中的一个示例使用以下OpenCL定制的图形数据结构在OpenCL设备上运行Dijkstra的算法:
void generateRandomGraph(GraphData *graph, int numVertices, int neighborsPerVertex)
{
graph->vertexCount = numVertices;
graph->vertexArray = (int*) malloc(graph->vertexCount * sizeof(int));
graph->edgeCount = numVertices * neighborsPerVertex;
graph->edgeArray = (int*)malloc(graph->edgeCount * sizeof(int));
graph->weightArray = (float*)malloc(graph->edgeCount * sizeof(float));
for(int i = 0; i < graph->vertexCount; i++)
{
graph->vertexArray[i] = i * neighborsPerVertex;
}
for(int i = 0; i < graph->edgeCount; i++)
{
graph->edgeArray[i] = (rand() % graph->vertexCount);
graph->weightArray[i] = (float)(rand() % 1000) / 1000.0f;
}
}
该数据结构是以Pawan Harish和P.J. Narayanan的论文“GPU上加速大图算法使用CUDA”为基础的。
基本上,它有三个数组:一个顶点数组V
,每个顶点指向边缘数组E
中的相邻顶点(顶点i+1
的邻居紧跟在数组E
中的顶点i
的邻居)。第三个数组用于边缘权重(还有两个更特定的OpenCL相关数组)。
如何用Python/Numpy来表示这个数据结构?,我想在PyOpenCL中使用它。
发布于 2011-10-17 03:56:18
http://wiki.python.org/moin/PythonGraphApi
。
发布于 2011-10-17 03:30:44
没有关于这一主题的专家,但这是某种附加矩阵(http://en.wikipedia.org/wiki/Adjacency_matrix)。Numpy核心数据类型是n维数组,所以这应该是非常直接的。
https://stackoverflow.com/questions/7791937
复制相似问题