Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
22 Views

Calling MKL functions/subroutines in Fortran 95

I was wondering if someone can tell me how to call Intel MKL subroutines using Fortran 95 syntax. For example, I have modified the provided example code using the ?copy subroutine (copy_main.f90):

program copy_main

implicit none

real(8) :: x(10), y(10)
integer :: n, incx, incy, i

n=3
incx=3
incy=1

do i=1,10
x(i) = i
end do

call copy (x, y)
print*, 'Y = ', (y(i), i=1,n)

end

Upon execution (ifort copy_main.f90 -L$MKLPATH -I$MKLINCLUDE -lmkl_intel -lmkl_intel_thread -lmkl_core -lguide -lpthread) I get the message:

ld: Undefined symbols:
_copy_

Do I need a USE statement (I don't need a USE statement in Fortran 77)? If so, what file do I need to reference for this? Any help would be greatly appreciated. I am running Mac OS X 10.4.11.

mandrew
0 Kudos
6 Replies
Highlighted
Black Belt
22 Views

Re: Calling MKL functions/subroutines in Fortran 95

In order to define the generic interface, you require the
use mkl_blas
as described in the Fortran 95 interface section of the manual. You would be able to avoid a USE or include file in either f95 or f77 only by using the specific function names, and forgoing a compile-time check on correctness of interface.
0 Kudos
Highlighted
Beginner
22 Views

Re: Calling MKL functions/subroutines in Fortran 95

Thanks for your help. I followed the instructions for creating the mkl95_blas.mod file and inserted it into my directory and modified the previous program to include the USE statement:

program copy_main

use mkl95_blas
implicit none
real(8) :: x(10), y(10)
integer :: n, incx, incy, i

n=3
incx=3
incy=1

do i=1,10
x(i) = i
end do

call copy (x, y)
print*, 'Y = ', (y(i), i=1,n)

end

Upon compilation I get the following:

copy_main.f90(12): (col. 7) remark: LOOP WAS VECTORIZED.
ld: Undefined symbols:
_dcopy_mkl95_

Any suggestions as to why this is occurring?

Also, what do you mean by "specific function names?" Using the F77 syntax:

program copy_main

real x(10), y(10)
integer n, incx incy, i

n=3
incx=3
incy=1

do i=1,10
x(i) = i
end do

call scopy (n, x, incx, y, incy)
print*, 'Y = ', (y(i), i=1,n)

end

gives satisfactory results without a USE statement.

0 Kudos
Highlighted
New Contributor III
22 Views

Re: Calling MKL functions/subroutines in Fortran 95

mandrew,

Of course, USE statement is required to call MKL blas95 and lapack95 subroutines.

As you can find in the Intel Fortran documentation,

You need an interface block for a subroutine when:

  • Calling arguments use argument keywords.

  • Some arguments are optional.

  • A dummy argument is an assumed-shape array, a pointer, or a target.

  • The subroutine extends intrinsic assignment.

  • The subroutine can be referenced by a generic name.

  • The subroutine is in a dynamic-link library.

So, if you compile your program without USE statement, usual Fortran 77 interface is assumed.

You can find the correspondent MKL examples, for instance:

/examples/blas95/source/dcopyx.f90

Note, you can build .mod files and Fortran 95 libraries first.

To do this just run blas95 examples as described in the MKL user guide.

See examples execution command line also for the proper linking options.

Thanks,

Vladimir

0 Kudos
Highlighted
Beginner
22 Views

Re: Calling MKL functions/subroutines in Fortran 95

Vladimir,

I've tried running the example dcopyx.f90 as you suggested. I first built the .mod files (mkl95_blas, mkl95_precision) and placed them in the same directory as dcopyx.f90. When I compile (ifort dcopyx.f90 -L$MKLPATH -I$MKLINCLUDE -lmkl_intel -lmkl_intel_thread -lmkl_core -lguide -lpthread), I get the following message:

ld: Undefined symbols:
_printvectord_
_dcopy_mkl95_

Can you tell me why I get this message? Am I not compiling correctly, or do I need another file of some sort?

Thanks,

mandrew
0 Kudos
Highlighted
New Contributor III
22 Views

Re: Calling MKL functions/subroutines in Fortran 95

mandrew,

You forgot to add mkl_blas95 library (_dcopy_mkl95_ Undefined symbols) and source/common_func.f file (_printvectord_ Undefined symbols). So, try the next command line:

ifort dcopyx.f90 common_func.f -I$MKLINCLUDE -L$MKLPATH -lmkl_blas95 -lmkl_intel -lmkl_intel_thread -lmkl_core -lguide lpthread

You can find libmkl_blas95.a library in the same directory as .mod files after examples run. Copy it into $MKLPATH directory, where other MKL libraries are located.

Thanks,

Vladimir

0 Kudos
Highlighted
Beginner
22 Views

Re: Calling MKL functions/subroutines in Fortran 95

Vladimir,

Many thanks for your help - things are working great now.

mandrew
0 Kudos