Fix corruption due to lock sharding issues by centralizing locking

This commit is contained in:
Nathan Goldbaum
2026-06-14 15:32:51 -06:00
parent 7aa79fbdff
commit 9363452742
17 changed files with 604 additions and 192 deletions
+9 -4
View File
@@ -2,8 +2,11 @@
#include <vector>
#include <random>
#include <future>
#include <omp.h>
#ifdef OPENBLAS_USE_GENERATED_CBLAS_H
#include "generated/cblas.h"
#else
#include "../cblas.h"
#endif
#include "cpp_thread_safety_common.h"
void launch_cblas_dgemv(double* A, double* x, double* y, const blasint randomMatSize)
@@ -17,7 +20,7 @@ int main(int argc, char* argv[])
blasint randomMatSize = 1024; //dimension of the random square matrices and vectors being used
uint32_t numConcurrentThreads = 52; //number of concurrent calls of the functions being tested
uint32_t numTestRounds = 16; //number of testing rounds before success exit
uint32_t maxHwThreads = omp_get_max_threads();
uint32_t maxHwThreads = GetMaxHwThreads();
if (maxHwThreads < 52)
numConcurrentThreads = maxHwThreads;
@@ -84,12 +87,14 @@ int main(int argc, char* argv[])
std::cout<<"done\n";
std::cout<<"Testing CBLAS DGEMV thread safety"<<std::endl;
omp_set_num_threads(numConcurrentThreads);
SetLauncherThreads(numConcurrentThreads);
for(uint32_t R=0; R<numTestRounds; R++)
{
std::cout<<"DGEMV round #"<<R<<std::endl;
std::cout<<"Launching "<<numConcurrentThreads<<" threads simultaneously using OpenMP..."<<std::flush;
std::cout<<"Launching "<<numConcurrentThreads<<" threads simultaneously"<<LauncherName()<<"..."<<std::flush;
#ifdef CPP_THREAD_SAFETY_USE_OPENMP
#pragma omp parallel for default(none) shared(futureBlock, matBlock, vecBlock, randomMatSize, numConcurrentThreads)
#endif
for(uint32_t i=0; i<numConcurrentThreads; i++)
{
futureBlock[i] = std::async(std::launch::async, launch_cblas_dgemv, &matBlock[i][0], &vecBlock[i*2][0], &vecBlock[i*2+1][0], randomMatSize);