[Omp] Does omp really work?
Mircea Tonceanu
tonceanum at yahoo.com
Wed Jan 25 05:27:49 PST 2006
Hello everybody,
I am dealing with simulations for n-body systems and I was very happy learning about omp. Anyway, after trying to implement it in my programs I was forced to test it in the simpliest program possible. Then I found out that something went wrong. I mean timing. Here you can see an extra simplified program I am concerned about:
#include <conio.h>
#include <stdio.h>
#include <windows.h>
#include <omp.h>
const long n = 5000000; // 5 million particles
long arr[n];
long arrb[n];
DWORD time_init;
DWORD time_final;
DWORD time_elapsed;
int main()
{
time_init = GetTickCount();
#pragma omp parallel for
for ( long k=1; k<n-1; k++)
{
arrb[k] = arr[k-1] + arr[k+1];
}
time_final = GetTickCount();
time_elapsed = time_final - time_init;
printf("Intial time:\t %u \n", time_init);
printf("Final time:\t %u \n", time_final);
printf("Elapsed time:\t %u \n", time_elapsed);
_getch();
return 0;
}
Conditions:
- AMD x64 dual core 3800+;
- 1 GB RAM;
- Win XP Pro X64;
- the program was compiled for 32 bits;
- with pragma enabled, task manager shows 2 threads and without, 1 thread;
- Visual Studio 2005 's compiler
The results are:
1. With pragma directive enabled:
- n = 5 million -> time_elapsed = 47 (meaning 47* 15 milisec which is the resolution of my timer);
- n = 50 million -> time_elapsed = 344;
- n< 5 million -> time_elapsed = 16;
2. With pragma directive disabled:
- n = 5 million -> time_elapsed = 31 ;
- n = 50 million -> time_elapsed = 344;
- n< 5 million -> time_elapsed = 0 (less then 15 ms).
In all other cases, time_elapsed is allways greater in case of #pragma omp enabled, which is not good.
Questions:
1. Why?
2. Why task manager shows 2 threads continously after the for loop has finished ?
3. Am I doing wrong something, or I have a misunderstanding of the omp ?
4. Am I stupid ?
Please help .
---------------------------------
Do you Yahoo!?
With a free 1 GB, there's more in store with Yahoo! Mail.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.openmp.org/pipermail/omp/attachments/20060125/620e67b4/attachment.html
More information about the Omp
mailing list