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;

}