Skip to content

Commit

Permalink
Merge pull request OpenMathLib#4585 from martin-frbg/issue1881
Browse files Browse the repository at this point in the history
Cap the number of parallel threads for GEMM;GETRF and POTRF to ensure sensible workloads on big systems
  • Loading branch information
martin-frbg authored Apr 3, 2024
2 parents e1b618c + 68ab518 commit d277c6d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
6 changes: 5 additions & 1 deletion interface/gemm.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,12 @@ void CNAME(enum CBLAS_ORDER order, enum CBLAS_TRANSPOSE TransA, enum CBLAS_TRANS
MNK = (double) args.m * (double) args.n * (double) args.k;
if ( MNK <= (SMP_THRESHOLD_MIN * (double) GEMM_MULTITHREAD_THRESHOLD) )
args.nthreads = 1;
else
else {
args.nthreads = num_cpu_avail(3);
if (MNK/args.nthreads < SMP_THRESHOLD_MIN*(double)GEMM_MULTITHREAD_THRESHOLD)
args.nthreads = MNK/(SMP_THRESHOLD_MIN*(double)GEMM_MULTITHREAD_THRESHOLD);
}

args.common = NULL;

if (args.nthreads == 1) {
Expand Down
17 changes: 11 additions & 6 deletions interface/lapack/getrf.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,19 @@ int NAME(blasint *M, blasint *N, FLOAT *a, blasint *ldA, blasint *ipiv, blasint

#ifdef SMP
args.common = NULL;

#ifndef DOUBLE
if (args.m*args.n < 40000)
#else
if (args.m*args.n < 10000)
int nmax = 40000;
#else
int nmax = 10000;
#endif
args.nthreads=1;
else
args.nthreads = num_cpu_avail(4);
if (args.m*args.n <nmax) {
args.nthreads = 1;
} else {
args.nthreads = num_cpu_avail(4);
if ((args.m*args.n)/args.nthreads <nmax)
args.nthreads = (args.m*args.n)/nmax;
}

if (args.nthreads == 1) {
#endif
Expand Down
14 changes: 9 additions & 5 deletions interface/lapack/potrf.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,17 @@ int NAME(char *UPLO, blasint *N, FLOAT *a, blasint *ldA, blasint *Info){
#ifdef SMP
args.common = NULL;
#ifndef DOUBLE
if (args.n <128)
#else
if (args.n <64)
int nmax = 128;
#else
int nmax = 64;
#endif
if (args.n <nmax) {
args.nthreads = 1;
else
args.nthreads = num_cpu_avail(4);
} else {
args.nthreads = num_cpu_avail(4);
if (args.n/args.nthreads <nmax)
args.nthreads = args.n/nmax;
}

if (args.nthreads == 1) {
#endif
Expand Down

0 comments on commit d277c6d

Please sign in to comment.