Suppose I have 3 double precision arrays a1[], a2[], a3[] each of length L1, L2, L3
Suppose I want to concatenate these arrays “virtually” That is I want to create a virtual
array a_virtual[] such that a_virtual = {a1[L1], a2[L2], a3[L3]} logically, though physically these arrays may not be contiguous to each other.
So if I want to access a_virtual[5] and L1=2, L2=3, L3=1 then a3[0] will be fetched. For accessing a_virtual[0], a1[0] will be fetched
How would I do this
- in C
- in C++ (how to do this with std::vectors in place of arrays would
also be useful) - in CUDA
I suspect if there is a way to do it, it would be the same for all the three environments, but there might be more efficient ways to do this within each environment depending on the
capabilities provided.
Here’s a possible solution in C, using linked-list and (tail) recursion:
You can “see the code running” at http://ideone.com/mY0ix.