I am trying to parallelize the computation of a metric on the nodes of a graph.

As an approach I have made each thread calculate the metric on a node (since the calculation on a node is independent).

Each thread must calculate some values based on the clusters that are created with the neighbors of the considered node and store them in an array of initially unknown size (and different for each node).

I can’t use extern `__shared__`

array because each thread has to compute its own array and can’t be shared.

I can’t declare a (max) fixed array size because it would be very inefficient for my task.

The solution adopted (thanks to the proposed solution for this question) is to create an array in the kernel with the `new`

function (e.g. `int *array=new int[]`

); so each thread initializes and calculates its array.

Once I’m done writing the array I need to read the values for the next steps in the calculation of the metric. I have checked that up to this point the values written in the array are correct.

The problem arises when the thread try to read the elements previously written, it seems that it reads values written by others threads.

Aren’t the arrays created with `new`

private for each thread?

Could it be a heap size problem? (I already tried to set the heap size>8MB, i.e. 256MB)

How can I solve this problem?