1

I am currently implementing Dijkstra's algorithm in cuda and I want to know the previous of a node currently updating distance code looks like this

   int dstwt = dist[dst];
   int altdist = dist[src] + wt;  
  if(altdist < dstwt)
  {
     atomicMin(&dist[dst], altdist);
  }

Here if dist[dst] gets updated prev[dst] must be updated to src but this has to be atomic operation I am not able to find such a atomic operation?

hitish
  • 355
  • 1
  • 7
  • 1
    If you are dealing with two 32-bit quantities (`dist[]` and `prev[]`), you can use a [custom atomic method](http://stackoverflow.com/questions/17411493/custom-atomic-functions) to do an atomic update on two independent 32-bit quantities (you will need to reorganize them for adjacency). Otherwise a more general approach might be to use some kind of critical section (search in the upper right hand corner on "cuda critical section") or else re-think your overall algorithm to fit into a [classical parallel reduction](http://developer.download.nvidia.com/assets/cuda/files/reduction.pdf) form. – Robert Crovella Mar 13 '15 at 22:02

0 Answers0