gomp-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gomp-discuss] Work in progress ....


From: Biagio Lucini
Subject: Re: [Gomp-discuss] Work in progress ....
Date: Fri, 16 May 2003 23:51:00 +0100 (BST)

On Fri, 16 May 2003, Lars Segerlund wrote:

>
>   Ok, so a lot of people is down :-( ...
>
>    Does anybody have some 'trivial' cases for OpenMP ? ( examples ) and
> I will try to get some time to patch together a set of 'hardcoded
> backend drivers' which generates some code for these ?
>

Below what I promised before. It takes ~ 32 sec. on a PIII 800Mhz, ~19sec
in the dual processor case. Tested with the Portland group compiler.
Uncomment the lines with NUM_THREADS if the compiler defaults the num of
threads to 1 instead of the num of CPUS.

Biagio

==========================================================================
#include <stdlib.h>
#include <stdio.h>
#include <omp.h>
/* #define NUM_THREADS 2 */
#define intervals 1000000000


int main()
{
  double width, sum;
  int i;
  double x;

  /* omp_set_num_threads(NUM_THREADS); */

  width = 1.0 / intervals;

  /* do the computation */
  sum = 0.0;
#pragma omp parallel for default(shared) private(i,x) reduction(+: sum)
  for (i=0; i<intervals; ++i) {
    x = (i + 0.5) * width;
    sum += 4.0 / (1.0 + x * x);
  }
  sum *= width;

  printf("Estimation of pi is %f\n", sum);

  return 0;
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]