The program uses the array list_indexes for this. As the number of lists is likely to be small, you can use the stack and thus declare the array as a local variable. Note this would be a bad idea with a GPU kernel, as the stack allocation may get placed into slow global memory, ...