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
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.