[Omp] slow performance

Dieter an Mey anmey at rz.rwth-aachen.de
Thu Dec 16 08:10:28 PST 2004


Good point!
Sorry that I didn't see it.

Dieter

Herbert Fruechtl wrote:

> You are not doing anything in parallel, but only replicating your work.
> You need either an "omp parallel for" pragma, or "parallel" AND "for"
> pragmas. Also be careful with accumulating your result. The statement
> 
> 	pi += sum;
> 
> needds an "atomic" pragma. Or better still, specify pi as "accumulate"
> in your omp pragma.
> 
> Hope this helps,
> 
>   Herbert
> 
> 
> 
>>-----Original Message-----
>>From: Omp-bounces at openmp.org [mailto:Omp-bounces at openmp.org] 
>>On Behalf Of andrew wang
>>Sent: 15 December 2004 14:53
>>To: omp at openmp.org
>>Subject: [Omp] slow performance
>>
>>
>>Hello,
>>
>>I am pretty new to OpenMP, before do some real thing, I write 
>>a simple code 
>>to test my understanding. But to my
>>big suprise, I see that the result is quite different from what I can 
>>imagine. The more threads I have, the more
>>slow the calculation is.
>>
>>Can you help me to take a look at the source code and the 
>>result I got? Is 
>>it too much fork/join, but little time on calculation in each thread?
>>
>>Thanks
>>Andrew
>>
>>
>>
>>
>>
>>source:
>>
>>#include <omp.h>
>>#include <time.h>
>>#include <stdio.h>
>>
>>static long num_steps = 1000000000L;
>>double step;
>>
>>int omp_threads = 1;
>>
>>void main (int argc,char **argv) {
>>
>>   double  x, sum, pi=0.0;
>>   int id;
>>   time_t t1,t2,t11,t22;
>>   int ii, jj, kk, i;
>>   int total_time=0;
>>
>>   (void) time(&t1);
>>
>>
>>   omp_threads=atoi(argv[1]);
>>
>>
>>   printf("omp_get_num_procs=%d\n",omp_get_num_procs());
>>
>>   step = 1.0/(double) num_steps;
>>   omp_set_num_threads(omp_threads);
>>
>>
>>   for (i=0;i<16200;i++) {
>>
>>	   for (ii=0; ii<50; ii++)
>>	   {
>>
>>	   	(void) time(&t11);
>>		#pragma omp parallel private (jj,kk,x, sum)
>>		{
>>
>>	   		id = omp_get_thread_num();
>>
>>	   		for (jj=id;jj<3; jj=jj+omp_threads )
>>	   		 {
>>
>>			   	for (kk=0; kk< 50; kk ++){
>>
>>
>>			   		x = (kk+0.5)*step;
>>			   		sum += 4.0/(1.0+x*x);   
>>// more complicated calculation here.
>>			   	}
>>
>>			   	pi += sum;
>>			 }
>>		}
>>
>>		(void) time(&t22);
>>                total_time += (long)(t22-t11);
>>
>>	   }
>>   }
>>
>>
>>   id = omp_get_thread_num();
>>
>>
>>   printf("Parallel region time=%d seconds\n", (int) total_time);
>>
>>   (void) time(&t2);
>>   printf("Total time = %d seconds\n", (int) (t2-t1));
>>
>>}
>>
>>result:
>>
>>
>>atlas1> a.out 1
>>omp_get_num_procs=4
>>Parallel region time=2 seconds
>>Total time = 3 seconds
>>atlas1> a.out 2
>>omp_get_num_procs=4
>>Parallel region time=41 seconds
>>Total time = 41 seconds
>>atlas1> a.out 3
>>omp_get_num_procs=4
>>Parallel region time=71 seconds
>>Total time = 72 seconds
>>
>>
>>
>>_______________________________________________
>>Omp mailing list
>>Omp at openmp.org http://openmp.org/mailman/listinfo/omp_openmp.org
>>
> 
> 
> _______________________________________________
> Omp mailing list
> Omp at openmp.org
> http://openmp.org/mailman/listinfo/omp_openmp.org
> 


-- 
--------------------------------------------------------------------
Dieter an Mey
High Performance Computing               Hochleistungsrechnen
RWTH Aachen University                   Rechen- und Kommunikations-
Center for Computing and Communication   zentrum der RWTH Aachen
phone: ++49-(0)241-80-24377              Seffenter Weg 23
fax:   ++49-(0)241-80-22134              52074 Aachen, Germany
email: anmey at rz.rwth-aachen.de
--------------------------------------------------------------------





More information about the Omp mailing list