Fix corruption due to lock sharding issues by centralizing locking
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
#ifdef CPP_THREAD_SAFETY_USE_OPENMP
|
||||
#include <omp.h>
|
||||
#else
|
||||
#include <thread>
|
||||
#endif
|
||||
|
||||
inline void pauser(){
|
||||
/// a portable way to pause a program
|
||||
std::string dummy;
|
||||
@@ -13,6 +19,29 @@ void FailIfThreadsAreZero(uint32_t numConcurrentThreads) {
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t GetMaxHwThreads() {
|
||||
#ifdef CPP_THREAD_SAFETY_USE_OPENMP
|
||||
return omp_get_max_threads();
|
||||
#else
|
||||
const uint32_t maxHwThreads = std::thread::hardware_concurrency();
|
||||
return maxHwThreads == 0 ? 1 : maxHwThreads;
|
||||
#endif
|
||||
}
|
||||
|
||||
void SetLauncherThreads(uint32_t numConcurrentThreads) {
|
||||
#ifdef CPP_THREAD_SAFETY_USE_OPENMP
|
||||
omp_set_num_threads(numConcurrentThreads);
|
||||
#endif
|
||||
}
|
||||
|
||||
const char *LauncherName() {
|
||||
#ifdef CPP_THREAD_SAFETY_USE_OPENMP
|
||||
return " using OpenMP";
|
||||
#else
|
||||
return "";
|
||||
#endif
|
||||
}
|
||||
|
||||
void FillMatrices(std::vector<std::vector<double>>& matBlock, std::mt19937_64& PRNG, std::uniform_real_distribution<double>& rngdist, const blasint randomMatSize, const uint32_t numConcurrentThreads, const uint32_t numMat){
|
||||
for(uint32_t i=0; i<numMat; i++){
|
||||
for(uint32_t j = 0; j < static_cast<uint32_t>(randomMatSize*randomMatSize); j++){
|
||||
|
||||
Reference in New Issue
Block a user