openmp and vector

General OpenMP discussion

openmp and vector

Postby rkata » Mon Oct 17, 2011 3:57 am

Hi anyone.
I'm beginner in using of the OpenMP. I'd like to know it is possible to make parallelization for the following circle:

vector<int> v;
int t;

#pragma omp parallel for shared(v) private(t)
for(t = 0; t < 1000; t++)
{
v.push_back(t);// or other variant - v.insert(v.begin(), t);

}
It is task for investigations only. My current result - I have crash during program execution....
rkata
 
Posts: 1
Joined: Mon Oct 17, 2011 3:46 am

Re: openmp and vector

Postby ftinetti » Mon Oct 17, 2011 3:42 pm

Hi,

I'm not an expert, but it seems to be that vector is not thread safe. I've found some comments on this at

http://stackoverflow.com/questions/3447 ... turn-index
http://stackoverflow.com/questions/4410 ... d-crashing

So it seems to be that there is not other way than synchronizing access via critical, for example... thus serializing the whole for if no other work is done...

HTH
ftinetti
 
Posts: 582
Joined: Wed Feb 10, 2010 2:44 pm


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 8 guests