How to generate random numbers in parallel?

I’ll post here what I posted to Concurrent random number generation : I think you’re looking for rand_r(), which explicitly takes the current RNG state as a parameter. Then each thread should have its own copy of seed data (whether you want each thread to start off with the same seed or different ones depends … Read more

How to set linker flags for OpenMP in CMake’s try_compile function

CMake has a standard module for testing if the compiler supports OpenMP: find_package(OpenMP) if (OPENMP_FOUND) set (CMAKE_C_FLAGS “${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}”) set (CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}”) set (CMAKE_EXE_LINKER_FLAGS “${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}”) endif() Note: This answer is not recommended to be used anymore for including OpenMP in the project for current CMake versions. Refer to the other answers.

Mixing C++11 atomics and OpenMP

Update: OpenMP 5.0 defines the interactions to C++11 and further. Among others, it says that using the following features may result in unspecified behavior: Data-dependency ordering: atomics and memory model Additions to the standard library C++11 library So clearly, mixing C++11 atomics and OpenMP 5.0 will result in unspecified behavior. At least the standard itself … Read more