2022-03-20

Calling SuperLU via Intel Visual fortran Windows

I have created static Library SuperLU 5.3 via Intel Visual Fortran (Intel Parallel Studio Windows) --> SuperLU.lib. Source = https://github.com/xiaoyeli/superlu/archive/refs/tags/v5.3.0.zip

It is c based.

I want to test it to call it with Fortran subroutine, f77_main.f with hbcode1.f Since it needs one of BLAS functions dtrsv.c, I use MKL instead. And it need also c_fortran_dgssv.c to be compiled first. I compiled with icx/c c_fortran_dgssv.c, and I got c_fortran_dgssv.obj when I compiled that f77_main.f hbcode1.f and superlu.lib and c_fortran_dgssv.obj with MKL /Qmkl using cmd console mode or Visual Studio IDE, it still have error linking.

example i try compiled without creating static lib:

cd c:\Superlu\SRC
icl/c *.c 
copy *.obj *.h c:\SuperLu\Fortran
cd c:\SuperLU\Fortran
icl/c c_fortran_dgssv.c 
ifort f77_main.f hbcode1.f *.obj /Qmkl

error LNK2019: unresolved external symbol C_FORTRAN_DGSSV referenced in function MAIN__     f77_main.obj        

f77_main.f

program f77_main
      call c_fortran_dgssv( iopt, n, nnz, nrhs, values, rowind, colptr, 
     $                      b, ldb, factors, info )

while c_fortran_dgssv.c had

void
c_fortran_dgssv_(int *iopt, int *n, int *nnz, int *nrhs, 
                 double *values, int *rowind, int *colptr,
                 double *b, int *ldb,
         fptr *f_factors, /* a handle containing the address
                     pointing to the factored matrices */
         int *info)

Looks like i got linker problem to call C from fortran. i tried ifort /names:lowercase or /names:UPPERCASE same problem

PROBLEM SOLVED! i see slu_cnames.h on superlu c header source code. i need to removed if symbol calling unnecessary method. use the appropriate only, if method not worked. Here is the approriate slu_cnames.h for intel compiler windows.

go to src, edit slu_cnames.h accordingly.

icl /c *.c /O3
lib *.obj /OUT:superlu53.lib /NODEFAULTLIB /INCLUDE:colamd.h /INCLUDE:f2c.h /INCLUDE:slu_cdefs.h /INCLUDE:slu_Cnames.h /INCLUDE:slu_dcomplex.h /INCLUDE:slu_ddefs.h /INCLUDE:slu_scomplex.h /INCLUDE:slu_util.h /INCLUDE:slu_sdefs.h /INCLUDE:slu_zdefs.h /INCLUDE:superlu_enum_consts.h /INCLUDE:supermatrix.h /VERBOSE /NODEFAULTLIB /MACHINE:x64

/* slu_cnames.h */
#define __SUPERLU_CNAMES

/* BLAS */
#define sswap_    SSWAP
#define saxpy_    SAXPY
#define sasum_    SASUM
#define isamax_   ISAMAX
#define scopy_    SCOPY
#define sscal_    SSCAL
#define sger_     SGER
#define snrm2_    SNRM2
#define ssymv_    SSYMV
#define sdot_     SDOT
#define saxpy_    SAXPY
#define ssyr2_    SSYR2
#define srot_     SROT
#define sgemv_    SGEMV
#define strsv_    STRSV
#define sgemm_    SGEMM
#define strsm_    STRSM

#define dswap_    DSWAP
#define daxpy_    DAXPY
#define dasum_    DASUM
#define idamax_   IDAMAX
#define dcopy_    DCOPY
#define dscal_    DSCAL
#define dger_     DGER
#define dnrm2_    DNRM2
#define dsymv_    DSYMV
#define ddot_     DDOT
#define dsyr2_    DSYR2
#define drot_     DROT
#define dgemv_    DGEMV
#define dtrsv_    DTRSV
#define dgemm_    DGEMM
#define dtrsm_    DTRSM

#define cswap_    CSWAP
#define caxpy_    CAXPY
#define scasum_   SCASUM
#define icamax_   ICAMAX
#define ccopy_    CCOPY
#define cscal_    CSCAL
#define scnrm2_   SCNRM2
#define cgemv_    CGEMV
#define ctrsv_    CTRSV
#define cgemm_    CGEMM
#define ctrsm_    CTRSM
#define cgerc_    CGERC
#define chemv_    CHEMV
#define cher2_    CHER2

#define zswap_    ZSWAP
#define zaxpy_    ZAXPY
#define dzasum_   DZASUM
#define izamax_   IZAMAX
#define zcopy_    ZCOPY
#define zscal_    ZSCAL
#define dznrm2_   DZNRM2
#define zgemv_    ZGEMV
#define ztrsv_    ZTRSV
#define zgemm_    ZGEMM
#define ztrsm_    ZTRSM
#define zgerc_    ZGERC
#define zhemv_    ZHEMV
#define zher2_    ZHER2

/* LAPACK */
#define dlacon_   DLACON
#define slacon_   SLACON
#define icmax1_   ICMAX1
#define scsum1_   SCSUM1
#define clacon_   CLACON
#define dzsum1_   DZSUM1
#define izmax1_   IZMAX1
#define zlacon_   ZLACON

/* Fortran interface */
#define c_bridge_dgssv_ C_BRIDGE_DGSSV
#define c_fortran_sgssv_ C_FORTRAN_SGSSV
#define c_fortran_dgssv_ C_FORTRAN_DGSSV
#define c_fortran_cgssv_ C_FORTRAN_CGSSV
#define c_fortran_zgssv_ C_FORTRAN_ZGSSV


No comments:

Post a Comment