Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

Questions about sgels example

H__Bin
Beginner
329 Views

I have two questions about sgels example:

(1) why need to call sgels twice?

/* Query and allocate the optimal workspace */
    lwork = -1;
    sgels( "No transpose", &m, &n, &nrhs, a, &lda, b, &ldb, &wkopt, &lwork, &info );
    lwork = (MKL_INT)wkopt;
    work = (float*)malloc( lwork*sizeof(float) );
    /* Solve the equations A*X = B */
    sgels( "No transpose", &m, &n, &nrhs, a, &lda, b, &ldb, work, &lwork,  &info );

(2) where to decide row-major matrix or column -major matrix?

Thank you very much!

0 Kudos
1 Reply
mecej4
Honored Contributor III
329 Views

The first call, with lwork already equal to -1, is a "workspace query". The absurd value of -1 (absurd for a matrix size) tells SGEMM, "Don't do any calculations, just tell me how much workspace is going to be needed. I'll allocate the space and then call you again."

The routine you are calling is a Fortran 77 routine. All matrices must be column major. If you want to use other formats, there are other MKL routines for that, as you can see in the MKL reference manual.

0 Kudos
Reply