Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 0.96 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Race conditions with OpenMP
  2. testfunc(const double* var, const double* par)
  3.     {
  4.        .......
  5.     }
  6.  
  7.     #define Nx 10000
  8.     #define Ny 10000
  9.     static double tmp[Ny][Nx];
  10.     double parGlob[2]; //<- Here are they!!!
  11.     #pragma omp threadprivate(parGlob)  // <-Magic directive!!!!
  12.  
  13.     int main()
  14.     {    
  15.  // Not here !!!! ->       double par[2]; // parameters
  16.         double xmin[]={0,0} // limits of 2D integration
  17.         double xmax[]={1,1};// limits of 2D integration
  18.  
  19.         double val,Tol=1e-7,AbsTol=1e-7;
  20.         int j,NDim=2,NEval=1e5;
  21.  
  22.     #pragma omp parallel for private(j,val)  // no `i` inside `private` clause
  23.         for (int i=0;i<Nx;i++)
  24.         {
  25.             for (j=0;j<Ny;j++)
  26.             {
  27.                 parGlob[0]=i;
  28.                 parGlob[1]=j*j;
  29.                 adapt_integrate(testfunc,par, NDim, xmin, xmax,
  30.                                 NEval, Tol, AbsTol, &val, &err);
  31.                 tmp[i][j] = val;
  32.             }
  33.         }
  34.     }