help openmp

General OpenMP discussion

help openmp

Postby student » Tue Jun 11, 2013 11:01 am

hi
i have this code, i want to find parallel time but time is always zero
Code: Select all
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
int main ()
{ int nthreads, tid;
double start,end;
start=omp_get_wtime();
#pragma omp parallel private(nthreads, tid)
{
tid = omp_get_thread_num();
printf("Hello World from thread = %d\n", tid);
if (tid == 0)
{ nthreads = omp_get_num_threads();
printf("Number of threads = %d\n", nthreads);
}
}
end=omp_get_wtime();
printf("pg est complete a %.3f seconds",(end-start));
return 0;
}

the execution is like that
Hello World from thread = 3
Hello World from thread = 0
Number of threads = 4
Hello World from thread = 1
Hello World from thread = 2
pg est complete a 0.000 seconds

Can anyone help me ? what is the problem with that ? i don't know why time (end-start) is always zero
thanks in advance
student
 
Posts: 2
Joined: Mon Jun 03, 2013 4:59 am

Re: help openmp

Postby ftinetti » Tue Jun 11, 2013 11:11 am

Hi,

Try with
Code: Select all
printf("pg est complete a %f seconds",(end-start));


instead of the current one printf("pg est complete a %.3f seconds",(end-start));

HTH,

Fernando.
ftinetti
 
Posts: 575
Joined: Wed Feb 10, 2010 2:44 pm

Re: help openmp

Postby student » Tue Jun 11, 2013 2:36 pm

thanks for replying :) it seems that it works

but i have another problem,i have made some changes in the program and tested it with varying the number of threads num_threads ( integer start from 1 to 4 ) like this line
Code: Select all
#pragma omp parallel num_threads(4) private(nthreads, tid)

the problem is that when i tested with 4 threads he gives
pg est complete a 0.000445 seconds
then when i close then i run another time he gives me another measure of time
pg est complete a 0.000301 seconds

is this normal? or there is something wrong with that ?
also when i run with 1 threads he gives me a time smaller than when i run with 4 threads
Code: Select all
#pragma omp parallel num_threads(1) private(nthreads, tid)

pg est complete a 0.000249 seconds (this is the message with 1 threads)
Is this correct or not ? as i'm beginner in openmp i need some help
please
this is the hole code
Code: Select all
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
int main ()
{ int nthreads, tid;
double debut,fin;
debut=omp_get_wtime();
#pragma omp parallel num_threads(4) private(nthreads, tid)
{
tid = omp_get_thread_num();
printf("Hello World from thread = %d\n", tid);
if (tid == 0)
{ nthreads = omp_get_num_threads();
printf("Number of threads = %d\n", nthreads);
}
}
fin=omp_get_wtime();
printf("pg est complete a %f seconds\n",(fin-debut));
return 0;
}

student
 
Posts: 2
Joined: Mon Jun 03, 2013 4:59 am

Re: help openmp

Postby ftinetti » Tue Jun 11, 2013 2:58 pm

Hi,

thanks for replying it seems that it works

Hmmm... and do you understand why?

he problem is that when i tested with 4 threads he gives
pg est complete a 0.000445 seconds
then when i close then i run another time he gives me another measure of time
pg est complete a 0.000301 seconds

is this normal? or there is something wrong with that ?
also when i run with 1 threads he gives me a time smaller than when i run with 4 threads

Maybe you should read a little bit more on parallel processing, overheads, etc. before trying anything else. There are very useful and specific comments on OpenMP overheads in posts such as
viewtopic.php?f=3&t=1583&p=6328&hilit=overhead#p6328
viewtopic.php?f=3&t=1533&p=6097&hilit=overhead#p6097

HTH,

Fernando.
ftinetti
 
Posts: 575
Joined: Wed Feb 10, 2010 2:44 pm


Return to Using OpenMP

Who is online

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