Atomic_min - return Index


    I have an array "C" and I want to find the minimum between "C[i]+C[j]" for all "i" and "j", but I also want to find the value of the indices that give me the minimum value. I already have a global function that finds the minimum value, but I want to know if it is possible also to find the indices that return the minimum of the atomicMin operation. A pseudocode of the situation:

global kernel ( C , minimum_cost ){

        int j = blockIdx.y * blockDim.y + threadIdx.y;
    int i = blockIdx.x * blockDim.x + threadIdx.x;
        cost= C[i]+C[j];
        // here I need to find "i" an "j" that give me the minimum_cost


Two possible approaches:

  1. Use a custom atomic function, if cost can fit into a 32-bit quantity and your indices i,j can also be packed into a 32-bit quantity:

  1. Use a parallel reduction. A parallel reduction may be more efficient than atomics (will likely be more efficient than a custom atomic) and can easily “carry along” arbitrary additional data, such as indices.