Открыть MP pragma omp параллельно, поскольку это приводит к разным выходным результатам [закрыто]C++

Программы на C++. Форум разработчиков
Ответить Пред. темаСлед. тема
Anonymous
 Открыть MP pragma omp параллельно, поскольку это приводит к разным выходным результатам [закрыто]

Сообщение Anonymous »


I am trying to introduce openMP to a code to speed up the loop. The loop processes some json inputs and generates json outputs. The json output contains almost exclusively doubles or vector or doubles. and We have some established expected results and test cases.

The problem : When running against the test case, It usually outputs the right result, but sometimes the results are off by a few hundred. This is clearly not good. The speed up is also very small (for example, a test case that used to take 4 sec now takes about 2-3 second but uses 8 threads).

The expected result: Better speed up while maintaining the same outputs.

Some details about the code:

1)DataObj is a class thats just holding json inputs

2)I tried to avoid concurrent write to the vector, so I set up critical regions.

3)the code standard is C++17, using visual studio to compile.

4)I have tried turning off optimization using #pragma optimize ("",off). It didn't seem to help.

#pragma optimize ("",off) int calc( DataObj *resultsP, // resultsP is just a container for outputs const DataObj &calcParams, const vector &inputs, const DataObj &Settings) { omp_set_dynamic(0); omp_set_nested(0); int rc = SUCCESS; // rc stands for return code int maxThreads = omp_get_max_threads() ; // outputs stored here vector* projectResultsVecP = resultsP->getObjVecPtr(PROJECT_RESULTS); const int n = static_cast(inputs.size()); #pragma omp parallel for schedule(guided) \ shared(projectResultsVecP,inputs)\ private (calcParams)reduction(&:rc) \ num_threads(n< maxThreads ? n: maxThreads) default (none) for (int i= 0; i< n; ++i) { DataObj* projectResults = new DataObj(); const char* fieldName = "ASSUMPTION_SETS"; Calculator* calculator = nullptr; vector assumptionSetsVec; #pragma omp critical (start) { //LOG("We have spawned this many threads : " + to_string(omp_get_num_threads())); LOG("We have spawned this threadnum : " + to_string(omp_get_thread_num()) + " for task " + to_string(i)); calculator = new Calculator(inputs); assumptionSetsVec = inputs.getObjVec(fieldName); } rc &= calculator->calc( projectResults, calcParams, // calc params is passed as const, and never modified assumptionSetsVec); #pragma omp critical (end) { (projectResultsVecP->at(i)) = move(*projectResults); LOG("We have finish this threadnum : " + to_string(omp_get_thread_num()) + " for task " + to_string(i)); } delete calculator; } LOG("We have finished openMP"); return rc; } #pragma optimize ("",on) I expected the output to be determinate as I specified the shared variables are only to be accessed in critical region.

Any idea what could have went wrong here?


Источник: https://stackoverflow.com/questions/780 ... put-result
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Возможен ли цикл Omp for, вызываемый в конечном итоге из одного региона OMP?
    Anonymous » » в форуме C++
    0 Ответы
    33 Просмотры
    Последнее сообщение Anonymous
  • #pragma omp для/параллельных задач
    Гость » » в форуме C++
    0 Ответы
    42 Просмотры
    Последнее сообщение Гость
  • #pragma omp для/параллельных задач [дубликат]
    Гость » » в форуме C++
    0 Ответы
    36 Просмотры
    Последнее сообщение Гость
  • Почему Visual Studio 2022 17.9.6 игнорирует параллель #pragma omp?
    Anonymous » » в форуме C++
    0 Ответы
    32 Просмотры
    Последнее сообщение Anonymous
  • Ошибка шины или ошибка сегментации (сброс ядра) с использованием #pragma omp Parallel для
    Anonymous » » в форуме C++
    0 Ответы
    23 Просмотры
    Последнее сообщение Anonymous

Вернуться в «C++»