Skip to content

Commit d277c6d

Browse files
authored
Merge pull request #4585 from martin-frbg/issue1881
Cap the number of parallel threads for GEMM;GETRF and POTRF to ensure sensible workloads on big systems
2 parents e1b618c + 68ab518 commit d277c6d

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

interface/gemm.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,12 @@ void CNAME(enum CBLAS_ORDER order, enum CBLAS_TRANSPOSE TransA, enum CBLAS_TRANS
533533
MNK = (double) args.m * (double) args.n * (double) args.k;
534534
if ( MNK <= (SMP_THRESHOLD_MIN * (double) GEMM_MULTITHREAD_THRESHOLD) )
535535
args.nthreads = 1;
536-
else
536+
else {
537537
args.nthreads = num_cpu_avail(3);
538+
if (MNK/args.nthreads < SMP_THRESHOLD_MIN*(double)GEMM_MULTITHREAD_THRESHOLD)
539+
args.nthreads = MNK/(SMP_THRESHOLD_MIN*(double)GEMM_MULTITHREAD_THRESHOLD);
540+
}
541+
538542
args.common = NULL;
539543

540544
if (args.nthreads == 1) {

interface/lapack/getrf.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,19 @@ int NAME(blasint *M, blasint *N, FLOAT *a, blasint *ldA, blasint *ipiv, blasint
9595

9696
#ifdef SMP
9797
args.common = NULL;
98+
9899
#ifndef DOUBLE
99-
if (args.m*args.n < 40000)
100-
#else
101-
if (args.m*args.n < 10000)
100+
int nmax = 40000;
101+
#else
102+
int nmax = 10000;
102103
#endif
103-
args.nthreads=1;
104-
else
105-
args.nthreads = num_cpu_avail(4);
104+
if (args.m*args.n <nmax) {
105+
args.nthreads = 1;
106+
} else {
107+
args.nthreads = num_cpu_avail(4);
108+
if ((args.m*args.n)/args.nthreads <nmax)
109+
args.nthreads = (args.m*args.n)/nmax;
110+
}
106111

107112
if (args.nthreads == 1) {
108113
#endif

interface/lapack/potrf.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,17 @@ int NAME(char *UPLO, blasint *N, FLOAT *a, blasint *ldA, blasint *Info){
113113
#ifdef SMP
114114
args.common = NULL;
115115
#ifndef DOUBLE
116-
if (args.n <128)
117-
#else
118-
if (args.n <64)
116+
int nmax = 128;
117+
#else
118+
int nmax = 64;
119119
#endif
120+
if (args.n <nmax) {
120121
args.nthreads = 1;
121-
else
122-
args.nthreads = num_cpu_avail(4);
122+
} else {
123+
args.nthreads = num_cpu_avail(4);
124+
if (args.n/args.nthreads <nmax)
125+
args.nthreads = args.n/nmax;
126+
}
123127

124128
if (args.nthreads == 1) {
125129
#endif

0 commit comments

Comments
 (0)