I'm learning c++ and trying to make my own calculator with charting. In this part, when I try to fill an array with coordinates. I want to make it faster using multithreading. But when I did so, the code began to work much worse, slower. How can I solve the problem what am I doing wrong? By the way, it doesn't work at all without "#pragma omp critical"
omp_set_num_threads(2);
#pragma omp parallel for
for (current = start; current < finish; current ++) {
Calc b(a.get_string());
double y_value = b.parsing((double)current/1000);
#pragma omp critical
{
if (y_value > yL || y_value < yR) {
x->push_back((double)current/1000);
y->push_back(y_value);
}
}
x and y this is QVector. Please try to express yourself as simply as possible because I'm just learning. Thank you all very much!