Reputation: 588
I am having a hard time understanding the relationship between omp parallel and vector slicing within each thread.
I was trying with std::vector
but switched to std:valarray
to try and minimize the slice copying, although I assume it is not relevant here.
For example, there is a vector:
std::valarray<custType> myvec(dataset.size());
I have some efficient functions that take a vector as input and do some computation, so I want to maximize the chunk size and pass the sliced valarray.
The general idea is:
std::valarray<custType> myvec(dataset.size());
#pragma omp parallel for schedule(static)
for (int i = 0; i < dataset.size(); i++) {
// Get the start and end index of this chunk
std::slice indexSlice(thread_start to thread_end);
// Assign the orginal datasets values to the newly calculated ones
dataset[indexSlice] = vectorizedFunction(myvec[indexSlice]);
}
When using omp parallel for
, I don't understand how to get all indices at once so that I can slice the vector to send to a function (as shown in the indexSlice being thread_start to thread_end
).
The other approach/idea was to make my own chunk definitions of (start,end)
indices, then parallelize the for loop over those chunks, but this seems like a weird solution when there is a parallelization library already. Is there an easier/cleaner/better way to do it (like how I am trying above), or is making a set of chunk indices the right way?
Upvotes: 1
Views: 156