-
Notifications
You must be signed in to change notification settings - Fork 474
Closed
Labels
Description
Description
When LAPACKE_sgeqrt is executed with row major, the following code is executed to convert the result obtained with column major to row major.
lapack/LAPACKE/src/lapacke_sgeqrt_work.c
Lines 82 to 83 in 77fac7e
LAPACKE_sge_trans( LAPACK_COL_MAJOR, ldt, MIN(m,n), t_t, ldt_t, t, | |
ldt ); |
Here, ldt * MIN(m,n)
should be the number of elements in t_t
(= the number of elements in t
), but this expression takes more values when ldt > nb
nb > n
.
This causes a segmentation fault when LAPACKE_sgeqrt
is executed with row major and ldt > n
.
Here is an example that causes the problem:
#include <stdio.h>
#include <time.h>
#include <lapacke.h>
int main(int argc, char *argv[])
{
srandom(42);
const int N = 16;
const int NB = 4;
const int LDA = N;
const int LDT = 100 * N; // set the value so that LDT > N holds.
// allocate A and T
float *A = (float *)malloc(N * LDA * sizeof(float));
float *T = (float *)malloc(N * LDT * sizeof(float));
// initialize A
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
A[i * LDA + j] = (float)random() / (float)RAND_MAX;
}
}
// call sgeqrt
LAPACKE_sgeqrt(LAPACK_ROW_MAJOR, N, N, NB, A, LDA, T, LDT);
// print results
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
printf("% 8f ", A[i * LDA + j]);
}
printf("\n");
}
printf("\n");
for (int i = 0; i < NB; i++)
{
for (int j = 0; j < N; j++)
{
printf("% 8f ", T[i * LDT + j]);
}
printf("\n");
}
// free memory
free(A);
free(T);
return 0;
}
Shouldn't this line look like this?
LAPACKE_sge_trans(LAPACK_COL_MAJOR, nb, MIN(m,n), t_t, ldt_t, t, ldt );
I'm thinking that other LAPACKE_*geqrt
functions may contain similar problems.
Checklist
- I've included a minimal example to reproduce the issue
- I'd be willing to make a PR to solve this issue