1
votes

Disclaimer: The author of this post has a limited knowledge of C++ and Python, and has sufficient knowledge of Java and Ruby.

An example from the "OpenCL Programming Guide" book uses the following OpenCL-customized graph data structure for Dijkstra's algorithm to run on an OpenCL device:

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;
    }
}

This data structure is based on the example from the "Accelerating large graph algorithms on the GPU using CUDA" paper by Pawan Harish and P. J. Narayanan.

Basically, it has three arrays: a vertex array V each vertex of which points to its neighbour vertices in the edge array E (the neighbours of a vertex i+1 follow the neighbours of the vertex i immediately in the array E). The third array is for edge weights (there are two more specific OpenCL related arrays).

How can I represent this data structure in Python/Numpy? I would like to use it in PyOpenCL.

2

2 Answers

1
votes
-1
votes

No expert on the topic, but this is some kind of adjency matrix (http://en.wikipedia.org/wiki/Adjacency_matrix). Numpy core data type is the n-dimension array so this should be quite straighforward.