-
Notifications
You must be signed in to change notification settings - Fork 474
Description
Description
In LAPACKE_*tgsen, if ijob = 0
, no iwork
is allocated:
https://github.com/Reference-LAPACK/lapack/blob/master/LAPACKE/src/lapacke_dtgsen.c#L86-L92
However, liwork = 1 and iwork( 1 ) is written to:
https://github.com/Reference-LAPACK/lapack/blob/master/SRC/dtgsen.f#L571-L575
One simple solution is to set
lapack_int* iwork = &iwork_query;
For ijob == 0, only that one entry is needed; for ijob != 0, iwork will get allocated. Though I would also change the two if (ijob != 0)
conditions to if (liwork > 1)
for safety & clarity.
Alternatively, delete the two if (ijob != 0)
conditions:
https://github.com/Reference-LAPACK/lapack/blob/master/LAPACKE/src/lapacke_dtgsen.c#L86
https://github.com/Reference-LAPACK/lapack/blob/master/LAPACKE/src/lapacke_dtgsen.c#L106
and always malloc iwork, even when liwork = 1.
This was discovered in writing the LAPACK++ wrapper (tgsen not yet pushed). The routine works for ijob = 1, 2, 3, 4, 5 but segfaults for ijob = 0:
thyme lapackpp/test> ./tester --ijob 1,2,3,4,5,0 --dim 10 tgsen
LAPACK++ version 2022.07.00, id c878e31
input: ./tester --ijob '1,2,3,4,5,0' --dim 10 tgsen
type ijob jobvl jobvr n error time (s) ref time (s) status
d 1 novec novec 10 0.00e+00 0.000764 0.000653 pass
d 2 novec novec 10 0.00e+00 0.00156 0.00158 pass
d 3 novec novec 10 0.00e+00 0.00287 0.00285 pass
d 4 novec novec 10 0.00e+00 0.00123 0.00111 pass
d 5 novec novec 10 0.00e+00 0.00324 0.00294 pass
Segmentation fault
Checklist
- I've included a minimal example to reproduce the issue
- I'd be willing to make a PR to solve this issue