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

Lost in MKL

yjyincj
Beginner
712 Views
Hi all
I used to use IMSL for fortran in Windows OS. Now I transfered to Linux and tried to use MKL instead. After I have read the MKL usermanual and library reference for a while, I am still lost. I just could not find an example to walk me through how I can use MKL functions. For example, I found an example as following. I could not even understand these codes.
Could anyone help me out? Great thanks.

program DASUM_MAIN

use mkl95_precision, only: wp => dp
use mkl95_blas, only: asum

implicit none

integer :: n
integer :: incx
integer :: nx, nx1, nx2
real(wp), allocatable :: x(:)
real(wp) :: sum
integer :: i

! Intrinsic Functions
intrinsic abs
! External Subroutines
external PrintVectorD

! Executable Statements

print*
print*,' D A S U M EXAMPLE PROGRAM'
! Read input data from input file
read*
read*, n, incx

nx = 1+(n-1)*abs(incx)

allocate(x(n))
read*, (x(i),i=1,nx)

! Print input data
print*
print*, ' INPUT DATA'
print 100, n
call PrintVectorD(0,n,x,incx,'X ')

! Call DASUM subroutine
if (incx > 0) then
nx1 = 1
nx2 = nx
else
nx1 = nx
nx2 = 1
end if
sum = ASUM(x(nx1:nx2:incx))

print*
print*, ' OUTPUT DATA'
print 101, sum

deallocate(x)

100 format(7x,'N=',i2)
101 format(10x,'DASUM = ',f8.3)
stop
end

0 Kudos
7 Replies
TimP
Honored Contributor III
712 Views
This simply gives an example how to use the BLAS dasum with BLAS95 interface. Unless you are want this particular function (no reason you should), you should be looking at one you are interested in. There are basic examples for both f77 and f95 style in each case.
0 Kudos
ArturGuzik
Valued Contributor I
712 Views
Hi,

if you were using imsl you were also using mkl, as it internally calls it. If you have problems with replacing imsl functions with mkl, post a bit more specific question, and I'm more than sure somebody will provide help on that. Many imsl functions you can get at netlib as well.

For any issues related to linking, link advisor is your friend.

A.
0 Kudos
Gennady_F_Intel
Moderator
712 Views
Quoting - ArturGuzik
Hi,

if you were using imsl you were also using mkl, as it internally calls it. If you have problems with replacing imsl functions with mkl, post a bit more specific question, and I'm more than sure somebody will provide help on that. Many imsl functions you can get at netlib as well.

For any issues related to linking, link advisor is your friend.

A.


as well, many examples of mkl for Fortran 77 and 95 you can find into examples directory
--Gennady
0 Kudos
yjyincj
Beginner
712 Views


as well, many examples of mkl for Fortran 77 and 95 you can find into examples directory
--Gennady
Ok. Here is an specific example.
program dot_main
use blas95
real x(10),y(10),res
integer i
!external sdot
n = 5
incx = 2
incy = 1
do i = 1,10
x(i) = 2.0e0
y(i) = 1.0e0
end do
res = sdot(x,y)
print*,'SDOT = ',res
end program dot_main
I compile it and get error#7002 as shown below.
[Juan@yuejun Fortran]$ ifort BLASsdotExample.f90
BLASsdotExample.f90(2): error #7002: Error in opening the compiled module file. Check INCLUDE paths. [BLAS95]
use blas95
----------^
compilation aborted for BLASsdotExample.f90 (code 1)

Intel MKL is installed in the path /opt/intel/mkl/10.2.2.025/

Environmental variable is set in ~/.bash_profile as following
source /opt/intel/Compiler/11.1/056/bin/ifortvars.sh ia32
. /opt/intel/mkl/10.2.2.025/tools/environment/mklvars32.sh

0 Kudos
TimP
Honored Contributor III
712 Views
Quoting - yjyincj

BLASsdotExample.f90(2): error #7002: Error in opening the compiled module file. Check INCLUDE paths. [BLAS95]
use blas95
----------^

I would guess that you may not have performed a blas95 setup step. There should be a Makefile in the installation to build the blas95 .mod file if it doesn't exist; I don't know whether that would move it automatically to the directory with the other .mod files.
0 Kudos
yjyincj
Beginner
712 Views
Quoting - tim18
I would guess that you may not have performed a blas95 setup step. There should be a Makefile in the installation to build the blas95 .mod file if it doesn't exist; I don't know whether that would move it automatically to the directory with the other .mod files.
Yes. There is a makefile in this path:
/opt/intel/mkl/10.2.2.025/interfaces/blas95
what should I do?

There are examples in the MKL installation folder /opt/intel/mkl/10.2.2.025/examples
In each subfolder under that path, there is a makefile. for example a makefile in folder blas95 looks like this

##
##examples of using:
##make lib32 function=dgemmx
##
##
include blas95.lst
...
...

I tried these examples as instructed by the makefile. the code is compiled successfuly and resutls are printed to
a file. The question is do I need to write a makefile for self-developed code? I don't think this is required.
0 Kudos
yjyincj
Beginner
712 Views
Quoting - yjyincj
Yes. There is a makefile in this path:
/opt/intel/mkl/10.2.2.025/interfaces/blas95
what should I do?

There are examples in the MKL installation folder /opt/intel/mkl/10.2.2.025/examples
In each subfolder under that path, there is a makefile. for example a makefile in folder blas95 looks like this

##
##examples of using:
##make lib32 function=dgemmx
##
##
include blas95.lst
...
...

I tried these examples as instructed by the makefile. the code is compiled successfuly and resutls are printed to
a file. The question is do I need to write a makefile for self-developed code? I don't think this is required.
Finally, I figured out how to compile the codes.
ifort *.f90 -L$MKLROOT/lib/32 -I$MKLROOT/include -I$MKLROOT/include/32 -lmkl_blas95 -Wl,--start-group $MKLROOT/lib/32/libmkl_intel.a $MKLROOT/lib/32/libmkl_intel_thread.a $MKLROOT/lib/32/libmkl_core.a -Wl,--end-group -liomp5 -lpthread -o *.out
0 Kudos
Reply