Unable to use LAPACK - potrs functions

Hi, 

We have a successful build of Pytorch on Windows with APL. The zpotrs, cpotrs, dpotrs, spotrs and zunqmr, cunmqr, dormqr, sormqr functions are unfortunately unreachable, therefore unusable. They require some major code changes.

So this type of declarations did not work for these.

extern "C" void zpotrs_(char *uplo, int *n, int *nrhs, std::complex<double> *a, int *lda, std::complex<double> *b, int *ldb, int *info);

We had to change the above code to below. 

extern "C" int LAPACKE_zpotrs(int matrix_layout, char uplo, int n, int nrhs, const float *a, int lda, float *b, int ldb);

static inline void zpotrs_(char *uplo, int *n, int *nrhs, std::complex<double> *a, int *lda, std::complex<double> *b, int *ldb, int *info) {
  *info = LAPACKE_zpotrs(LAPACK_COL_MAJOR, *uplo, *n, *nrhs, a, *lda, b, *ldb);

We also had these types of runtime outputs with the before code : 

   ** On entry to DPOTRS parameter number  1 had an illegal value

Could you assist us in making these functions usable like any others?

Parents Reply Children
  • Hi,

       I have found an example using zpotrs from NAG here

    support.nag.com/.../f07fsf.html

    which is in Fortran. I have tested this with our library and it seems to work correctly. I have converted this to c++ (and modified it slightly) and have compiled this directly with our library using the Microsoft cl.exe compiler with no issues. My code is below

    #include <armpl.h>
    #include <vector>
    #include <iostream>
    #include <iomanip>
    
    int main () {
    
      const char uplo = 'L';
      const armpl_int_t n = 4;
      const armpl_int_t nrhs = 2;
      const armpl_int_t lda = n;
      std::vector<armpl_doublecomplex_t> a(lda*n);
      const armpl_int_t ldb = n;
      std::vector<armpl_doublecomplex_t> b(ldb*nrhs);
      armpl_int_t info = -1;
    
      // Initialize matrix A to zero
      for (int i = 0; i < n*lda; ++i) {
        a[i] = _Cbuild((double)(0.0), (double)(0.0));
      }
    
      // Set initial values
      a[0] = _Cbuild((double)(3.23), (double)(0.0));
      a[1] = _Cbuild((double)(1.51), (double)(1.92)); a[5] = _Cbuild((double)(3.58), (double)(0.0));
      a[2] = _Cbuild((double)(1.90), (double)(-0.84)); a[6] = _Cbuild((double)(-0.23), (double)(-1.11)); a[10] = _Cbuild((double)( 4.09), (double)( 0.00));
      a[3] = _Cbuild((double)(0.42), (double)(-2.50)); a[7] = _Cbuild((double)(-1.18), (double)(-1.37));
      a[11] = _Cbuild((double)( 2.33), (double)( 0.14)); a[15] = _Cbuild((double)( 4.29), (double)( 0.00));
    
      b[0] = _Cbuild((double)( 3.93), (double)( -6.14));  b[4] = _Cbuild((double)( 1.48), (double)(  6.58));
      b[1] = _Cbuild((double)( 6.17), (double)(  9.42));  b[5] = _Cbuild((double)( 4.65), (double)( -4.75));
      b[2] = _Cbuild((double)(-7.17), (double)(-21.83));  b[6] = _Cbuild((double)(-4.91), (double)(  2.29));
      b[3] = _Cbuild((double)( 1.99), (double)(-14.38));  b[7] = _Cbuild((double)( 7.64), (double)(-10.79));
    
      zpotrf_(&uplo,&n,a.data(),&lda,&info);
    
      if (info == 0) {
        zpotrs_(&uplo,&n,&nrhs,a.data(),&lda,b.data(),&ldb,&info);
    
        if (info == 0) {
          std::cout << std::fixed << std::setw(8) << std::setprecision(2) << "\n";
          std::cout << "Solution:\n";
          for (int i = 0 ; i < n; i++) {
            std::cout << i ;
            std::cout << " (" << creal(b[i]) << ", " <<  cimag(b[i]) << "), (" <<  creal(b[i+n]) << "," <<  cimag(b[i+n]) << ")\n";
          }
          std::cout << "\n";
          std::cout << "Expected:\n";
          std::cout << "0 (1.00, -1.00), (-1.00,2.00)\n";
          std::cout << "1 (-0.00, 3.00), (3.00,-4.00)\n";
          std::cout << "2 (-4.00, -5.00), (-2.00,3.00)\n";
          std::cout << "3 (2.00, 1.00), (4.00,-5.00)\n";
        }
        else {
          std::cout << "Error: zpotrs returned an error.\n";
        }
      }
      else {
        std::cout << "Error: zpotrf returned an error.\n";
      }
    
    return 1;
    }
    

    I have compiled this code, called zpotrs_example.cpp,  in a windows command shell using the following commands

    cl.exe -c /MT /nologo /EHsc /I"%ARMPL_DIR%\include"  zpotrs_example.cpp /Fozpotrs_example.obj
    cl.exe /MT /Fezpotrs.exe zpotrs_example.obj libarmpl_lp64.dll.lib /link /libpath:"%ARMPL_DIR%"\lib
    

    and then run it using

    zpotrs.exe
    
    Solution:
    0 (1.00, -1.00), (-1.00,2.00)
    1 (-0.00, 3.00), (3.00,-4.00)
    2 (-4.00, -5.00), (-2.00,3.00)
    3 (2.00, 1.00), (4.00,-5.00)
    
    Expected:
    0 (1.00, -1.00), (-1.00,2.00)
    1 (-0.00, 3.00), (3.00,-4.00)
    2 (-4.00, -5.00), (-2.00,3.00)
    3 (2.00, 1.00), (4.00,-5.00)
    

    If this fails for you or if it doesn't help you resolve the issue you are having please reach out to us at 

    support-hpc-sw@arm.com