I am trying to parallelize a for loop in my code base that should be embarrassingly parallel. However, Openmp is not doing so and rather is executing everything in sequential order. program complied using g++, std=c++11, I have executed a small program to ensure if openmp works or not, and it worked just fine.
The code block I am trying to parallelize is given below
void class_tmv::activate(class_tmv &result, const &a, const &b, const &c, const &d, const &e, f) const
{
result.clear();
#pragma omp parallel for
for (unsigned int i = 0; i < tms.size(); ++i)
{
class_TM tmTemp;
tms[i].activate(tmTemp, a, b, c, d, e, f);
result.tms[i] = tmTemp;
}
}
Class_tmv has class variable tms, that is essentially a vector of Class_TM objects. Class_TM has a method also named activate that gets called above, it is defined as
inline void Class_TM::activate(Class_TM &result, const &a, const &b, const &c, const &d, const &e, f) const
{
result.clear();
Class_TM tmTemp;
if (condition_1)
{
this->S_T(tmTemp, a, b, c, d, e, f);
}
else if (condition_2)
{
this->T_T(tmTemp, a, b, c, d, e, f);
}
else
{
cout << "The activation fundtion can be parsed." << endl;
}
result = tmTemp;
}
S_T and T_T are other methods in class_TM.
The issue I'm having is the overall execution of the system is completely sequential, and the loop I'm trying to parallelize isn't working.
Any suggestions on what may be going wrong are extremely helpful. Any other solutions not related to openmp are also welcomed.
(This is my first time working on parallel applications)
Did you use the -fopenmp flag when compiling your code?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With