Block nested parallel

General OpenMP discussion

Block nested parallel

Postby chameleon » Mon Jun 18, 2012 11:01 am

In the following code, there is parallelization in vector addition and in matrix addition.
Matrix addition uses vector addition. But when use matrix addition I want to disable parallelization in vector addition.
Is possible to disable with a pragma directive, nested parallelization?

Code: Select all
struct Vector : public std::vector<double>
struct Matrix : public std::vector<Vector>

Vector Vector::operator+(const Vector &v) const
{
   Vector r(v.size());
   @pragma omp parallel for if (v.size() > 1000000)  // This directive must be ignored if Matrix::operator+ called.
   for (size_t z = 0; z < v.size(); z++)
      r[z] = (*this)[z] + v[z];
   return r;
}

Matrix Matrix::operator+(const Matrix &m) const
{
   Matrix r(m.size());
   @pragma omp parallel for // always
   for (size_t z = 0; z < m.size(); z++)
      r[z] = (*this)[z] + m[z];   // This is vector addition and I don't want to create threads.
   return r;
}
chameleon
 
Posts: 8
Joined: Mon Jan 23, 2012 6:37 pm

Re: Block nested parallel

Postby ftinetti » Mon Jun 18, 2012 11:05 am

Hi,

Is possible to disable with a pragma directive, nested parallelization?


Take a look at omp_set_nested()

HTH,

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

Re: Block nested parallel

Postby MarkB » Tue Jun 19, 2012 1:49 am

..or you could use
#pragma omp parallel for if(!omp_in_parallel())
MarkB
 
Posts: 428
Joined: Thu Jan 08, 2009 10:12 am


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 6 guests