Skip to content

Commit 20033f9

Browse files
authored
Merge pull request #1929 from martin-frbg/issue1924
Avoid taking the root of a negative number in simple threaded syrk
2 parents e23366e + f343ed6 commit 20033f9

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

driver/level3/syrk_thread.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ int CNAME(int mode, blas_arg_t *arg, BLASLONG *range_m, BLASLONG *range_n, int (
4848

4949
BLASLONG width, i;
5050
BLASLONG n_from, n_to;
51-
double dnum, nf, nt, di;
51+
double dnum, nf, nt, di, dinum;
5252

5353
int num_cpu;
5454
int mask = 0;
@@ -109,7 +109,11 @@ int CNAME(int mode, blas_arg_t *arg, BLASLONG *range_m, BLASLONG *range_n, int (
109109
if (nthreads - num_cpu > 1) {
110110

111111
di = (double)i;
112-
width = (BLASLONG)(( sqrt(di * di + dnum) - di + mask)/(mask+1)) * (mask+1);
112+
dinum = di * di +dnum;
113+
if (dinum <0)
114+
width = (BLASLONG)(( - di + mask)/(mask+1)) * (mask+1);
115+
else
116+
width = (BLASLONG)(( sqrt(dinum) - di + mask)/(mask+1)) * (mask+1);
113117

114118
if ((width <= 0) || (width > n_to - i)) width = n_to - i;
115119

@@ -136,9 +140,7 @@ int CNAME(int mode, blas_arg_t *arg, BLASLONG *range_m, BLASLONG *range_n, int (
136140

137141
nf = (double)(arg -> n - n_from);
138142
nt = (double)(arg -> n - n_to);
139-
140143
dnum = (nt * nt - nf * nf) / (double)nthreads;
141-
142144
num_cpu = 0;
143145

144146
range[0] = n_from;
@@ -149,8 +151,11 @@ int CNAME(int mode, blas_arg_t *arg, BLASLONG *range_m, BLASLONG *range_n, int (
149151
if (nthreads - num_cpu > 1) {
150152

151153
di = (double)(arg -> n - i);
152-
width = ((BLASLONG)((-sqrt(di * di + dnum) + di) + mask)/(mask+1)) * (mask+1);
153-
154+
dinum = di * di + dnum;
155+
if (dinum<0)
156+
width = ((BLASLONG)(di + mask)/(mask+1)) * (mask+1);
157+
else
158+
width = ((BLASLONG)((-sqrt(dinum) + di) + mask)/(mask+1)) * (mask+1);
154159
if ((width <= 0) || (width > n_to - i)) width = n_to - i;
155160

156161
} else {

0 commit comments

Comments
 (0)