Thread safety while looping with OpenMP

前端 未结 3 1980
再見小時候
再見小時候 2021-01-27 10:41

I\'m working on a small Collatz conjecture calculator using C++ and GMP, and I\'m trying to implement parallelism on it using OpenMP, but I\'m coming across issues regarding thr

3条回答
  •  北海茫月
    2021-01-27 11:27

    You might want to touch x only with atomic instructions.

    #pragma omp atomic
    x++;
    

    This ensures that all threads see the same value of x without requires mutexes or other synchronization techniques.

提交回复
热议问题