Using one (dedicated) vector per thread (OpenMP)
Apr 11, 2013 at 9:41am UTC
Hello everyone
I recently picked up multithreading with OpenMP, so it is still new to me. While processing data, I would like to store it in a vector, as shown here:
1 2 3 4 5 6 7
vector<int > vect;
#pragma omp parallel for
for (int c=0; c<500; ++c)
{
vect.push_back(c)
}
However, since it is multithreaded, I would like (and need!) to have one dedicated vector per thread. I haven't been able to find an example of how to do this online. Is it even possible? I'd be happy to get some hints...
Cheers,
B.
Apr 11, 2013 at 11:35am UTC
http://en.cppreference.com/w/c/thread/thread_local
Maybe that's what you're looking for?
From using the SFML library, I remember the "sf::ThreadLocalPtr<>" template. For every thread, there is a single instance.
Personally I'd just have every thread create its own vector on the stack and let it work with that.
Topic archived. No new replies allowed.