My C++ program takes about 300 s to run. Inside my program I need to cwis divide my vectors. VS analyzer tells this takes about 15% of running time. here is the code:
template <class T> myVector<T> cWisDivide(myVector<T> &vec1,
myVector<T> &vec2)
{
try
{
if (vec1._rows == vec2._rows)
{
myVector<T> result(vec1._rows);
//#pragma omp parallel for
for (int r = 1; r <= vec1._rows; r++)
{
if (vec2(r) != 0)
{
result(r) = vec1(r) / vec2(r);
}
else
{
throw std::runtime_error("");
}
}
return result;
}
}
catch (const exception &e)
{
....
}
}
this function is called many time. If I use #pragma ... before the loop, the cpu usage sticks 100% for about 350 s. which is more than the time taken to run program sequentially.
I would appreciate if any one could help me on the issue.
vec1._rows? - Oliver Charlesworthrinforloop should be defined beforeforitself. Like this:int r; #pragma.... for(r = 1...)- Michał Walenciak