On processors without built-in atom support (and even with them) using #pragma omp atomic , as other answers show here, you can slow down your program.
The idea of a progress indicator is to give the user an idea of when something will end. If you hit the target plus / minus a small fraction of the total execution time, the user will not be too worried. That is, the user would prefer that everything ends earlier, due to the fact that you learned more precisely when it will all end.
For this reason, I usually track progress in only one thread and use it to measure overall progress. This is normal for situations where each thread has a similar workload. Since you are using #pragma omp parallel for , you are probably working on a number of similar elements without interdependencies, so my guess is probably true for your use case.
I wrapped this logic in the ProgressBar class, which I usually include in the header file along with my helper class Timer . The class uses ANSI control signals to make everything look good.
The result is as follows:
[====== ] (12% - 22.0s - 4 threads)
It is also easy to get the compiler to clear all the overhead in the progress panel by declaring the -DNOPROGRESS flag -DNOPROGRESS compilation.
Code and usage example:
source share