Problem in trying to use LAPACK routines

Problem in trying to use LAPACK routines

I am trying to use a couple of routines in the Intel Math Kernel library, specifically

dpotrf anddpotri, in order to get the inverse of a matrix.

However, when I reach the line CALL dpotrf(TRUELAMBDAINV) in the following subroutine, I get an unhandled exceptionerror. I have also included the main program that calls this subroutine at the end of this message.

I think I may not have the proper include and use statements, but can't figure out from the documentation where I am going wrong.

Any help would be greatly appreciated

Siddarth

SUBROUTINE TRUE_PARAMS

USE SETTINGS

USE PARS

USE MKL_VSL_TYPE

USE MKL_VSL

use MKL95_LAPACK

use MKL95_PRECISION

IMPLICIT NONE

REAL*8 :: LBD12(NP,NP),RDRAW(NP),R(NP,1),TEMP(NP,1)

INTEGER :: I, J

INTEGER :: mstorage

TYPE (VSL_STREAM_STATE) :: stream

integer(kind=4) errcode

integer brng,method,seed,n

brng=VSL_BRNG_MT19937

method=VSL_METHOD_DGAUSSIAN_ICDF

seed=777

mstorage=VSL_MATRIX_STORAGE_FULL

DATA ((LBD12(I, J), J = 1,4), I = 1,4) / 5, 5, -1, 1, 0, 4, -2, 0, 0, 0, 3, 2, 0, 0,0, 1 /

LBD12=LBD12/2.0D0

TRUELAMBDA=MATMUL(TRANSPOSE(LBD12),LBD12)

TRUELAMBDAINV=TRUELAMBDA

CALL dpotrf(TRUELAMBDAINV)

CALL dpotri(TRUELAMBDAINV)

! ***** Initializing *****

errcode=vslnewstream( stream, brng, seed )

DO I=1,NSUB

errcode = vdrnggaussianmv( method, stream, 1, rdraw, np, mstorage, truemub, lbd12 )

TRUEB_S(I,:)=RDRAW

ENDDO

TRUESIGMA=5.0D0

END SUBROUTINE TRUE_PARAMS

! HB linear regression

! Y_i=X_i*Beta_i + epsilon_i

! Beta_i ~ N(Mu, Lambda)

! Mu ~ N (ETA, V0)

!Lambda ~ IW (f0, G0)

! epsilon_i ~ N(0, sigma^2*I)

!sigma^2 ~ IG(r0/2,s0/2)

! INCLUDE 'link_fnl_static.h' ! Include IMSL static library

! USE MKL_VSL_TYPE

! USE MKL_VSL

INCLUDE 'MKL_VSL.FI'

INCLUDE 'LAPACK.F90'

! INCLUDE 'MKL_LAPACK.FI'

! INCLUDE 'MKL_BLAS.FI'

MODULE SETTINGS

! Set sampler parameters

IMPLICIT NONE

INTEGER, PARAMETER :: NITER = 30000 ! Number of iterations

INTEGER, PARAMETER :: NETBURN = 20000 ! Number of additional iterations to burn

INTEGER, PARAMETER :: NSAVE = 25 ! Thining parameter

INTEGER, PARAMETER :: MONITOR = 1 ! Monitoring parameter (1/0)

! Set Data parameters

INTEGER, PARAMETER :: NSUB = 100 ! Number of cross-sectional units

INTEGER, PARAMETER :: NP = 4 ! Number of parameters

INTEGER, PARAMETER :: NVAR = 3 ! Number of explanatory variables

END MODULE SETTINGS

MODULE FILESPEC

IMPLICIT NONE

! Set model number and run number

CHARACTER*10, PARAMETER :: MODEL = 'HBREG' ! Model number

CHARACTER*4, PARAMETER :: RUN = '_1' ! Run number

! set directory for the output data

CHARACTER*60, PARAMETER :: OUTDIR = 'C:\\ALLWORK\\PROJECTS\\SML\\fortran\\output'

END MODULE FILESPEC

MODULE DATASETS

USE SETTINGS

IMPLICIT NONE

REAL*8, SAVE, DIMENSION(:,:), ALLOCATABLE :: XDATA,XI,YI

REAL*8, SAVE, DIMENSION(:), ALLOCATABLE :: Y

REAL*8 :: STARTEND(NSUB,2)

INTEGER, SAVE :: TOTROWS

END MODULE DATASETS

MODULE PARS

USE SETTINGS

IMPLICIT NONE

REAL*8, SAVE :: BETA_S(NSUB,NP),ILAMBDA(NP,NP),LAMBDA(NP,NP),MUB(NP,1),SIGMA

REAL*8, SAVE :: TRUEB_S(NSUB,NP),TRUELAMBDA(NP,NP),TRUELAMBDAINV(NP,NP),TRUEMUB(NP,1),TRUESIGMA

DATA TRUEMUB /2,-1,3,2/

END MODULE PARS

! *************** START MAIN PROGRAM **********************

PROGRAM HBREG

! Modules

USE SETTINGS ! Settings for analysis

USE DATASETS ! Data for analysis

USE PARS ! Model parameters for analysis

USE FILESPEC ! Storage directories and model numbers

! USE LINEAR_OPERATORS

! Variable declaration

IMPLICIT NONE

INTEGER :: COUNT_ITER ! Count actual saved iterations

INTEGER :: I,ITER ! Indices

INTEGER :: IYR, IMON, IDAY, IHR, IMIN, ISEC, I100 ! TO get the day and time

INTEGER :: ISEED, IRANK ! Auxiliary variables

WRITE (6,382)IYR,IMON,IDAY

WRITE (6,383)IHR,IMIN,ISEC,I100

382 FORMAT(" Start Date -- ",I4,":",I2,":",I2)

383 FORMAT(" Start Time -- ",I2,":",I2,":",I2,".",I2)

! GENERATING THE TRUE PARAMETERS

CALL TRUE_PARAMS

! ************* Generating DATA **************

CALL LOAD_DATA(TRUEB_S,TRUESIGMA)

! ********************************************

CALL GETDAT(IYR,IMON,IDAY)

CALL GETTIM(IHR,IMIN,ISEC,I100)

WRITE (6,380)IYR,IMON,IDAY

WRITE (6,381)IHR,IMIN,ISEC,I100

380 FORMAT(" End Date -- ",I4,":",I2,":",I2)

381 FORMAT(" End Time -- ",I2,":",I2,":",I2,".",I2)

! Close all the output files

CLOSE(21)

CLOSE(22)

END PROGRAM HBREG

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

17 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

As you suggest, it would be useful to invoke the appropriate include files to permit argument checking for your lapack calls.
The lapack.f90 is set up for
USE lapack
while the .fi files are set up for include. You must choose one or the other.
With the absence of reasonable formatting and disregard for standard usage, it's difficult to scan your quoted source visually.
You haven't shown essential information such as whether you are in 32-bit mode, or in 64-bit mode, where you have a choice of either 32-bit integer arguments (lp64) or 64-bit (ilp64).
You would probably get more expert help on the MKL forum.

Your code calls the F77 routines DPOTRF and DPOTRI, which must be called with all their parameters (Fortran 77 did not have OPTIONAL arguments).

For example, in your code, the call to the factorization routine should be

CALL dpotrf('U',np,TRUELAMBDAINV,np,info)

Alternatively, you may use the Fortran 9X interfaces in LAPACK95, in which case the call should be

call potrf(TRUELAMBDAINV)

Furthermore, since you did not

USE f95_lapack

which would have provided the compiler with the interfaces for DPOTRF and DPOTRI, you forced the compiler to use the Fortran-77 convention of "user is responsible for providing correct argument list". Had you included this statement, the compiler would have told you

"error #6631: A non-optional actual argument must be present when invoking a procedure with an explicit interface. [N]
CALL dpotrf(TRUELAMBDAINV)"
...

It would benefit you greatly to understand about Fortran interfaces, modules, and the implications of USE versus those of INCLUDE.

Next time you post code, please use the "syntax highlighter" tool (the icon with a diagonally placed pencil visible when you are creating a message).

Thanks for the input.

I tried the USE f95_lapackstatementalong with a call to potrf(truelambdainv) but still get the following error

C:\Allwork\PROJECTS\SML\FORTRAN\PROGRAMS\Test1.f90(123): error #7002: Error in opening the compiled module file. Check INCLUDE paths. [MKL95_LAPACK]

Is theresome part of the documentation that clearly states the steps that one needs to go through in order to get Visual fortran compiler to go through?

Also is there some place which clearly states what I need to do in terms of include files and so on that I must add in for it to work?

Siddarth

Depending on the version of MKL/Intel Fortran that you have installed, you may need to build the Lapack95 module and library files. Sources and a makefile for doing that are provided undern \Compiler\11.1\065\mkl\interfaces. The resulting .mod and .lib files can be installed in different directories, and the directory information needs to be provided to the compiler, either through environment variables,r through command line or IDE options. This is a one-time setup needed to build and install Lapack95.

Alternatively, you may use the F77 interface and call DPOTRF with all its arguments included.

The User Guide does cover the topics you ask about. However, you will probably not find a sequence of instructions that can be mechanically followed, because every installation of Intel Fortran, Visual Studio and other tools can be slightly different.

I see the Makefile and the sources. How do I run it and create the .mod and .lib file?

I also tried to use the F77 version of the command by

a) Using the INCLUDE 'MKL_LAPACK.FI' in the main program (as mentioned in the manual)
b) Including the line call dpotrf( 'up', np, truelambdainv, np, info )

However this gave a number of compiler errors including the following (there were 31 compiler errors). It looks like I am no closer to using these routines.

Any suggestions?

Regards,

Siddarth

C:\PROGRA~2\Intel\Compiler\11.1\065\mkl\include\MKL_LAPACK.FI(31): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: *

C:\PROGRA~2\Intel\Compiler\11.1\065\mkl\include\MKL_LAPACK.FI(32): error #5276: Unbalanced parentheses

C:\PROGRA~2\Intel\Compiler\11.1\065\mkl\include\MKL_LAPACK.FI(32): error #5082: Syntax error, found IDENTIFIER 'RWORK' when expecting one of: ( % : . = =>

C:\PROGRA~2\Intel\Compiler\11.1\065\mkl\include\MKL_LAPACK.FI(32): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: ( % . = =>

C:\PROGRA~2\Intel\Compiler\11.1\065\mkl\include\MKL_LAPACK.FI(63): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: *

You will get these types of error messages as a result of including a fixed format file (MKL_LAPACK.fi) in a free format file. You may either convert one of them into the format of the other or, if you are sure that the arguments are correct, leave out the INCLUDE statement altogether.

How do I use the Make file to create the .mod files and use it within Visual Studio. I looked through the documentation carefully, and there doesn't seem to be any instructions about this. All I found is the following.....

Thanks,

Siddarth

using lapack.f90 that includes improved interfaces. This file is used to generate the

module files lapack95.mod and f95_precision.mod. The module files

mkl95_lapack.mod and mkl95_precision.mod are also generated. See also the

section Fortran 95 interfaces and wrappers to LAPACK and BLAS of Intel MKL User's

Guide for details. The module files are used to process the FORTRAN use clauses

referencing the LAPACK interface: use lapack95 (or an equivalent use

mkl95_lapack) and use f95_precision (or an equivalent use mkl95_precision).

Near the beginning of the makefile, there are given some examples of usage:

## examples of using:
##
## nmake lib32 install_dir=lib95 - build by Intel Fortran Compiler (as default)
## for 32-bit applications, static linking
##
## nmake lib64 install_dir=lib95 - build by Intel Fortran Compiler (as default)
## for 64-bit applications - Intel Itanium, static linking
##
## nmake libem64t install_dir=lib95 - build by Intel Fortran Compiler (as default)
## for 32-bit with Intel EM64T applications - static linking

Replace 'lib95' by the name of the directory where you want the library to be installed.

Thanks for your patience!

Inoticed that the directory C:\Program Files (x86)\Intel\Compiler\11.1\065\mkl\include\em64t\lp64

already contains blas95.mod, f95_precison.mod, lapack95.mod, mkl95_lapack.mod, mkl95_blas.mod, and mkl95_precision.mod

I added this directory to the Additional Include Directories and then I was able to compile and run without error when I used the f77 version of the command.

However, when I used thef90 version, i.e. CALL potrf(TRUELAMBDAINV). I get the following errors.

Error 1 error LNK2019: unresolved external symbol DPOTRF_F95 referenced in function TRUE_PARAMS Test3.obj

Error 2 error LNK2019: unresolved external symbol DPOTRI_F95 referenced in function TRUE_PARAMS Test3.obj

When I changed the above command to CALL DPOTRF(TRUELAMBDAINV) the linking error went away but I got an unhandled exception execution error.

Any suggestions?

The .mod files are required at compile time, so you need them in the include path (either in your environment, or -I directive for compiler). I don't know why the include path doesn't have them by default.
Adding them to link path won't have any effect.

Thanks for your patience!

I noticed that the directory C:\Program Files (x86)\Intel\Compiler\11.1\065\mkl\include\em64t\lp64

already contains blas95.mod, f95_precison.mod, lapack95.mod, mkl95_lapack.mod, mkl95_blas.mod, and mkl95_precision.mod

I added this directory to the Additional Include Directories and then I was able to compile and run without error when I used the f77 version of the command.

However, when I used the f90 version, i.e. CALL potrf(TRUELAMBDAINV). I get the following errors.

Error 1 error LNK2019: unresolved external symbol DPOTRF_F95 referenced in function TRUE_PARAMS Test3.obj

Error 2 error LNK2019: unresolved external symbol DPOTRI_F95 referenced in function TRUE_PARAMS Test3.obj

When I changed the above command to CALL DPOTRF(TRUELAMBDAINV) the linking error went away but I got an unhandled exception execution error.

Any suggestions?

You have, unfortunately, come full-circle and are repeating earlier errors.

Here is working code that calls DPOTRF:

program DPOTRFEX
!DEC$ OBJCOMMENT LIB:'mkl_intel_c_dll'
!DEC$ OBJCOMMENT LIB:'mkl_sequential_dll'

IMPLICIT NONE
INTEGER, PARAMETER :: NP = 4
INTEGER :: INFO,I,J
REAL*8 :: LBD12(NP,NP), TRUELAMBDA(NP,NP), TRUELAMBDAINV(NP,NP)
DATA ((LBD12(I, J), J = 1,4), I = 1,4) / 5, 5, -1, 1, 0, 4, -2, 0, 0, 0, 3, 2, 0, 0,0, 1 /

LBD12=LBD12/2.0D0

TRUELAMBDA=MATMUL(TRANSPOSE(LBD12),LBD12)

TRUELAMBDAINV=TRUELAMBDA

CALL dpotrf('U',np,TRUELAMBDAINV,np,info)
write(*,10)((TRUELAMBDAINV(I,J),J=1,NP),I=1,NP)
10 format(1x,4ES15.7)

end program DPOTRFEX

Compiling:

c:LANG>ifort dpot.f90
Intel Visual Fortran Compiler Professional for applications running on IA-32, Version 11.1    Build 2010041
4 Package ID: w_cprof_p_11.1.065
Copyright (C) 1985-2010 Intel Corporation.  All rights reserved.

Microsoft  Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:dpot.exe
-subsystem:console
dpot.obj

Running:

c:LANG>dpot
   2.5000000E+00  2.5000000E+00 -5.0000000E-01  5.0000000E-01
   6.2500000E+00  2.0000000E+00 -1.0000000E+00  0.0000000E+00
  -1.2500000E+00 -3.2500000E+00  1.5000000E+00  1.0000000E+00
   1.2500000E+00  1.2500000E+00  1.2500000E+00  5.0000000E-01

As I said previously, the F77 version of the code did work for me.

My question was abouthow to make the f95 call work. Inour previous correspondencewe haddiscussed CALLpotrf(TRUELAMBDAINV).

To call the generic subroutine POTRF, add

USE lapack95

and link to lapack95.lib in addition to the other libraries.

Please read the documentation.

That's what I had done (I've pasted the subroutine below) But I get the following build errors




Error 1 error LNK2019: unresolved external symbol DPOTRF_F95 referenced in function TRUE_PARAMS Test3.obj Error 2 error LNK2019: unresolved external symbol DPOTRI_F95 referenced in function TRUE_PARAMS Test3.obj Error 3 fatal error LNK1120: 2 unresolved externals x64SimpleConsole1.exe 
By the way I am linking to the lapack95.lib is by including the following directory in the Additional Include Directories under
the Fortran General tab. This directory contains lapack95.mod (as well as the others).

C:Program Files (x86)IntelCompiler11.165mklincludeem64tlp64;
Is there something else I need to do? Thanks!




SUBROUTINE TRUE_PARAMSUSE SETTINGSUSE PARSUSE MKL_VSL_TYPEUSE MKL_VSLUSE LAPACK95!USE MKL95_LAPACKUSE F95_PRECISION!USE MKL95_PRECISIONIMPLICIT NONEREAL*8 :: LBD12(NP,NP),RDRAW(NP),R(NP,1),TEMP(NP,1)INTEGER :: I, JINTEGER :: mstorage, infoTYPE (VSL_STREAM_STATE) :: streaminteger(kind=4) errcodeinteger brng,method,seed,nbrng=VSL_BRNG_MT19937method=VSL_METHOD_DGAUSSIAN_ICDFseed=777mstorage=VSL_MATRIX_STORAGE_FULLDATA ((LBD12(I, J), J = 1,4), I = 1,4) / 5, 5, -1, 1, 0, 4, -2, 0, 0, 0, 3, 2, 0, 0,0, 1 / LBD12=LBD12/2.0D0TRUELAMBDA=MATMUL(TRANSPOSE(LBD12),LBD12)TRUELAMBDAINV=TRUELAMBDA!call dpotrf( 'up', np, truelambdainv, np, info )CALL potrf(TRUELAMBDAINV)!call dpotri( 'up', np, truelambdainv, np, info )CALL potri(TRUELAMBDAINV)END SUBROUTINE TRUE_PARAMS










You must also tell the linker to use lapack95.lib .

Leave a Comment

Please sign in to add a comment. Not a member? Join today