I\'ve read some other questions on this topic. However, they didn\'t solve my problem anyway.
I wrote the code as following and I got pthread version an
WARNING: tho answer is controversial. The trick described below is implementation dependent and can lead to a decrease of performance. Still, it might increase it as well. I strongly recommend to take a look at comments to this answer.
This doesn't really answer the question, but if you alter the way you parallelize your code, you might get a performance boost. Now you do it like this:
#pragma omp parallel for
for(int n = 0; n < sizen; ++n)
sinTable[n] = std::sin(2 * M_PI * n / sizen);
In this case each thread will compute one item. Since you have 2 cores, OpenMP will create two threads by default. To calculate each value a thread would have to:
The first step is rather expensive. And both your threads would have to do it sizen/2 times.
Try to do the following:
int workloadPerThread = sizen / NUM_THREADS;
#pragma omp parallel for
for (int thread = 0; thread < NUM_THREADS; ++thread)
{
int start = thread * workloadPerThread;
int stop = start + workloadPerThread;
if (thread == NUM_THREADS - 1)
stop += sizen % NUM_THREADS;
for (int n = start; n < stop; ++n)
sinTable[n] = std::sin(2 * M_PI * n / sizen);
}
This way your threads will initialize only once.