I am doing a parallel for loop in OpenMP.
Here is my problem: I have a 4D array, where the 4th dimension's depth is a maximum value--I might not use all of the elements of the 4th dimension. In this array, I store indices of another array (I calculate the indices in a parallel loop).
So,
int my_index_array[dim_x][dim_y][dim_z][max_count];
At the same time, in the parallel loop, I am recording the number of elements stored in each 4th dimension vector (i.e., my_index_array[0][0][0][:]) in another integer array:
int my_index_counts[dim_x][dim_y][dim_z] = {(int) 0}
Such that I can create parallel for loops later using the values from my_index_counts.
So here is my problem:
I need an optimal, super fast way to "re-initialize" the index counts when I come back around to the top of the outer loop. Ideally, I would not loop through the index counts array and reset the values. But, in C++, I can't reinitialize the array. I found "memcpy," and have the space to create another "zeroed" array to copy from, but is that the optimal way to do this?
For array initialization you may use memset, it is suitable for continuous memory blocks. Your code should be something like this:
memset(&my_index_counts[x][y][z], 0, max_count*sizeof(int));
where x,y,z are indices to all but the last dimension
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With