OpenMP on Dual Core machine

General OpenMP discussion

OpenMP on Dual Core machine

Postby Danesh_D » Thu May 01, 2008 11:06 am

Hi all,

I have tested this code on a machine with an Intel Dual Core processor:

omp_set_num_threads(1);
start=omp_get_wtime();

#pragma omp parallel for
for (i=1; i<1000000; ++i)
for (j=0; j<500; ++j)
b[i]=(a[j]+b[j])/2.0;

end=omp_get_wtime();

printf ("Elapsed time is: %f seconds\n", end-start);

and it will be run in ~7.5 seconds. Now when I change first line of
code to:

omp_set_num_threads(2);

elapsed time will be ~15 seconds which is almost twice. I except exactly reverse
behavior since my system is Dual Core and expect that elapsed time to be half and not
twice! Is there something that I am doing wrong? I use g++ 4.2 to compile my code.

Thanks!

Danesh
Danesh_D
 
Posts: 2
Joined: Thu May 01, 2008 11:05 am

Re: OpenMP on Dual Core machine

Postby ejd » Thu May 01, 2008 5:59 pm

One problem with your code is that the index for the second loop is not automatically privatized. Try putting "private(j)" on the "parallel for" directive and see if that makes a difference.
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Re: OpenMP on Dual Core machine

Postby Danesh_D » Fri May 02, 2008 8:10 am

Thanks for your help. It worked great when I use g++ but when I compile same code with Intel C++ I get this error:

error: invalid entity for this variable list in omp clause
#pragma omp parallel for private(j)
^

what is the problem? When I remove "private(j)" Intel C++ compiles code without any error.

Thanks!

D.
Danesh_D
 
Posts: 2
Joined: Thu May 01, 2008 11:05 am

Re: OpenMP on Dual Core machine

Postby ejd » Fri May 02, 2008 1:28 pm

I am afraid that I do not know why the Intel compiler is complaining. I assume that you have declared variables "i" and "j" as int in the program. You can try changing it to "private(i,j) and see if that makes any difference. It shouldn't. The only other thing to do is try and post this question on the Intel web site forum and see if you get a response. An Intel person might respond here, but I can't guarantee that. You can also post your entire program here and I can try looking at it and running the Intel compiler I have to see what happens. If you do that, please also note the Version of the Intel compiler you are using.
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot] and 6 guests