Skip to content

Commit 5da4c93

Browse files
authored
Cap the number of parallel threads
1 parent 4961066 commit 5da4c93

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

interface/lapack/getrf.c

Lines changed: 12 additions & 7 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)
102-
#endif
103-
args.nthreads=1;
104-
else
105-
args.nthreads = num_cpu_avail(4);
100+
int nmax = 40000;
101+
#else
102+
int nmax = 10000;
103+
endif
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

0 commit comments

Comments
 (0)