Thread safety while looping with OpenMP

前端 未结 3 1985
再見小時候
再見小時候 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:24

    You could well be right about collisions with x. You can mark x as private by:

    #pragma omp parallel private(x)
    

    This way each thread gets their own "version" of the variable x, which should make this thread-safe. By default, variables declared before a #pragma omp parallel are public, so there is one shared instance between all of the threads.

提交回复
热议问题