Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LAPACKE_*tgsen iwork not allocated for ijob = 0 #772

Closed
2 tasks done
mgates3 opened this issue Dec 1, 2022 · 0 comments
Closed
2 tasks done

LAPACKE_*tgsen iwork not allocated for ijob = 0 #772

mgates3 opened this issue Dec 1, 2022 · 0 comments

Comments

@mgates3
Copy link
Contributor

mgates3 commented Dec 1, 2022

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant