OpenMP elapsed time is not a constant

General OpenMP discussion

OpenMP elapsed time is not a constant

Postby smartyyf » Sat Nov 29, 2008 8:57 am

several weeks ago, i asked one question and the board hoster "ejd" had given me an exact answer(thanks a lot :D ).
for some details please see:http://openmp.org/forum/viewtopic.php?f=3&t=307

But now i am encountering another problem with the same test code. it is as following
when the code run in serial model on my machine, the elapsed time is always about 16s.
but in OpenMP model,the elapsed time is not a stable. some time it's 8~9s(a good results), but some time it's 24s or more.
would anyone please do me a favor? thank you very much.

BTW: My PC is Inter(R) Core(TM)2 Duo CPU, the OS is Fedora core 9. OpenMP 2.5 & GCC 4.3.
I found that in OpenMP model, both cores are in 100% work.

the code:
#include <iostream>
#include "omp.h"
using namespace std;
int main(int argc,char **argv)
{
double start, finish;
static long num_steps = 1000000000;
double step;
int i;
double x, pi, sum = 0.0;

step = 1.0/(double) num_steps;
start = omp_get_wtime();
#pragma omp parallel for reduction(+:sum) private(x)
for (i=0;i< num_steps; i++)
{
x = (i+0.5)*step;
sum = sum + 4.0/(1.0+x*x);
}
pi = step * sum;
finish = omp_get_wtime();
cout<< pi<<"\t" <<num_steps<<"\t"<<finish-start<<endl;
return (0);
}
smartyyf
 

Re: OpenMP elapsed time is not a constant

Postby ejd » Sun Nov 30, 2008 9:58 pm

smartyyf wrote:several weeks ago, i asked one question and the board hoster "ejd" ...

Just to clarify my position, I am not the board "hoster", the OpenMP ARB is. In the past, the ARB took email queries in regards to the specification and gave "official" responses. The forums were started to try and get more of a community going so that more general questions could be asked and answered. The first questions didn't really get responses and so the ARB CEO started answering the posts. I thought that he had more than enough work to do and started responding to the posts. So far the ARB has been happy with my work and so I am now a moderator. Anyone is free to respond to the posts made and I hope that more people start doing just that.

As for your query, I am not sure what is causing the variation. I unfortunately do not have your setup, which makes it very hard to determine what is going on. I have tried a couple of different "flavors" of linux on several Intel chipsets using the Sun Studio compiler and have not seen the variation that you have.

Can you give me a little more information about the Intel chipset you are using (so I can look at the cache info) and how many threads you are running.
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Re: OpenMP elapsed time is not a constant

Postby smartyyf » Sun Nov 30, 2008 11:44 pm

thank you for your reply.and sorry for my mistake :) . My PC is a kind of Dell Latitude D830, it has only one CPU with double cores, so in my OpenMP, i employed two threads.

today,I tried many times and found that if i declare"static long num_steps = 1000000000;double step;" as global variables. the elapsed time will be stable. In serial run, it take 17s, while in OpenMP with 2 threads, it always 9s. But i don't know why these happen, can anybody know?

so the code will be:
#include <iostream>
#include "omp.h"
using namespace std;
static long num_steps = 1000000000;
double step;

int main(int argc,char **argv)
{
double start, finish;

int i;
double x, pi, sum = 0.0;

step = 1.0/(double) num_steps;
start = omp_get_wtime();
#pragma omp parallel for reduction(+:sum) private(x)
for (i=0;i< num_steps; i++)
{
x = (i+0.5)*step;
sum = sum + 4.0/(1.0+x*x);
}
pi = step * sum;
finish = omp_get_wtime();
cout<< pi<<"\t" <<num_steps<<"\t"<<finish-start<<endl;
return (0);
}
smartyyf
 

Re: OpenMP elapsed time is not a constant

Postby Ernst0 » Mon Dec 01, 2008 4:36 pm

I'm just starting out but I see that the way the threads are allocated isn't constant. If I understand the results from the code posts in New member thread.. How many threads are used and when, changes but, they will be used.

Does this sound correct?

Ernst0

I think we are doing the same thing.

Hey should we combine threads?
Ernst0
 

Re: OpenMP elapsed time is not a constant

Postby smartyyf » Mon Dec 01, 2008 7:05 pm

I have monitered the PC, In OpenMP,It's always 2 threads. and both cores are 100% used
smartyyf
 

Re: OpenMP elapsed time is not a constant

Postby Ernst0 » Mon Dec 01, 2008 8:58 pm

Alright..

I believe ya... I'm just starting out.

Ernst0
Ernst0
 

Re: OpenMP elapsed time is not a constant

Postby smartyyf » Mon Dec 01, 2008 9:27 pm

So am i, and i am not confident at all.
smartyyf
 

Re: OpenMP elapsed time is not a constant

Postby Ernst0 » Wed Dec 03, 2008 3:32 pm

Well I see you use C++. I'm old school that never made the jump. Still in C.

The first example I posted in hello thread shows when and how the threads are working on that code section. Atleast it did in my mind.

You may look at the output to see what I mean. I'm not promoting my OpenMP skills there but the output was a clue to me on how the system RH Enterprise works it.

I think the system can work it as it see fit.

I also see that my cpus can speed up the frequency they are driven at. So the speed, I figure, is relative to the system load.

Since I damaged my system messing with the diskdrives it will be a day or so till I'm back working the code. I see you used "private" and something else to scope some data. I need to study that.

The nice things is we can write for two cores or two million it's all the same LOL

Mind if I ask questions about C++? I may want to try out some of your code. I need to understand how to compile it.
Ernst0
 

Re: OpenMP elapsed time is not a constant

Postby ejd » Thu Dec 04, 2008 7:05 am

I don't have a version of gcc that I can play with right this minute to look at the code being produced and try and figure out why the two programs operate differently. Could you please tell me what the following program outputs for you:
Code: Select all
#include <stdio.h>

int main(void)
{
  int a;
  double b;
  long c;

  printf("sizeof(a): %i  sizeof(b): %i  sizeof(c): %i\n", sizeof(a), sizeof(b), sizeof(c));
  return 0;
}

Basically I am wondering what your limits.h gives for the size of the variables you are using in the program. Thanks.
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Re: OpenMP elapsed time is not a constant

Postby smartyyf » Thu Dec 04, 2008 7:32 pm

thank you all very much for some very useful suggestions and skills in code.

As for the example proposed 'ejd', my pc gave the following results:

sizeof(a):4 sizeof(b):8 sizeof(c): 4

BTW: i have parallelized my CFD program for flow and heat transfer simulation in enginnering application during these two days. but On a PC with 8 cores, i can only get a parallel efficiency about 70%. and i'm trying to improve its performance now. i'll share the my probelms and experience with all of you. thank you :D
smartyyf
 

Next

Return to Using OpenMP

Who is online

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