Section example and multi-core

General OpenMP discussion

Section example and multi-core

Postby vcecala » Wed May 14, 2008 12:31 pm

The example manipulates arrays C and D. Each section is allocated to a thread. If I modify the code for each section to printf the value of array c[i] and d[i] using { } as part of the for loops. I would have expected "if the threads are ran in parallel and on separate cores" that the print out would have been c, d, c, d, c, d etc. but instead I get all values of c array then all values of d array. Which tells me yes they are in separate thread (I checked this out by printing out the thread id) but the system is still running things in serial (not concurrently). I am using a dual core with Linux 2.6.9-1 and Intel's 10.1.015 compiler. Newbee to parallel processing but using your examples to understand the effects of OpenMP. Is this a problem with Linux that the threads are not on separate cores and ran concurrently? Or is there a OpenMP directive I should be using to force this behavior??

The code:
#include <omp.h>
#define N 20

main()
{
int i;
float a[N], b[N], c[N], d[N];

/* Some initialization */
for (i=0; i<N; i++)
{
a[i] = i + 1.5;
b[i] = i + 22.35;
}

#pragma omp parallel shared(a,b,c,d) private(i)
{
#pragma omp sections nowait
{
#pragma omp section
for (i=0; i<N; i++)
{
c[i] = a[i] + b[i];
printf("C equals %d\n", c[i]);
}

#pragma omp section
for (i=0; i<N; i++)
{
d[i] = a[i] * b[i];
printf("D equals %d\n", d[i]);
}
} /* end of sections */
} /*end of parallel section */

}
Last edited by vcecala on Mon May 19, 2008 7:06 am, edited 1 time in total.
vcecala
 
Posts: 1
Joined: Wed May 14, 2008 12:17 pm

Re: Section example and multi-core

Postby ejd » Thu May 15, 2008 2:37 pm

Unfortunately I am not sure what example you are referring too. There are a couple of things that might cause this, but I need more information.
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am


Return to Using OpenMP

Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests