fortran
Just started all over again:
Installed gfortran, ifortran, lapack, blas and related packages for my research purpose
=========================
gfortran is free and simple.. no linking with terminal is required..
==================================
ifort is tricky:
after installing the offline version of the free intel fortran compiler we need to open the terminal and write this in .bashrc file:
source /home/somu/intel/oneapi/setvars.sh
==========================================================
installing lapack and lblas is easy from the synaptic package manager and we select the lapack and blas libraries . Hopefully every thing is correct:
================================================
I checked the gfortran and ifort result. its matching exactly and smoothly.
I was writing a code in fortran for exact diagonaliation and needed to compare ifort and gfortran results. Installed the ifort compiler and facing a problem to link lapack and blas library.
This was the problem in the terminal
somenath@fermi ed-wonderfull $ ifort ed-lapack.f90 -llapack -lblas
ld: /usr/local/lib/liblapack.a(xerbla.o): in function `xerbla_':
xerbla.f:(.text+0x55): undefined reference to `_gfortran_st_write'
ld: xerbla.f:(.text+0x60): undefined reference to `_gfortran_string_len_trim'
ld: xerbla.f:(.text+0x77): undefined reference to `_gfortran_transfer_character_write'
ld: xerbla.f:(.text+0x87): undefined reference to `_gfortran_transfer_integer_write'
ld: xerbla.f:(.text+0x8f): undefined reference to `_gfortran_st_write_done'
ld: xerbla.f:(.text+0x9a): undefined reference to `_gfortran_stop_string'
ld: /usr/local/lib/liblapack.a(dormtr.o): in function `dormtr_':
dormtr.f:(.text+0x2dc): undefined reference to `_gfortran_concat_string'
ld: dormtr.f:(.text+0x476): undefined reference to `_gfortran_concat_string'
ld: dormtr.f:(.text+0x4d9): undefined reference to `_gfortran_concat_string'
ld: dormtr.f:(.text+0x521): undefined reference to `_gfortran_concat_string'
ld: /usr/local/lib/liblapack.a(dormql.o): in function `dormql_':
dormql.f:(.text+0x5a7): undefined reference to `_gfortran_concat_string'
ld: /usr/local/lib/liblapack.a(dormql.o):dormql.f:(.text+0x6e4): more undefined references to `_gfortran_concat_string' follow
========================================================================
What I did was to install
liblapack-dev throgh Ubuntu synaptic package manager and the the problem was solved..
============================================================================
somenath@fermi ed-wonderfull $ ifort ed-lapack.f90 -llapack -lblas
somenath@fermi ed-wonderfull $ ./a.out
6 20
--LAPACK -2.80277563773199
somenath@fermi ed-wonderfull $
somenath@fermi ed-wonderfull $ gfortran ed-lapack.f90 -llapack -lblas
somenath@fermi ed-wonderfull $ ./a.out
6 20
--LAPACK -2.8027756377319948
=====================================================================
compare ifort and gfortran result
--LAPACK -2.80277563773199
--LAPACK -2.8027756377319948
gfortran options
gfortran -fbounds-check code.f90
./a.out
results:
At line 508 of file code.f90
Fortran runtime error: Array reference out of bounds for array 'nl', upper bound of dimension 1 exceeded (4 > 3)
ifort on complex number
Ifort is not recognising complex intrinsic function. it shows eror. the correct for my compiler is
complex*16, allocatable :: hamA(:,:)
do k=2,L-2
hamA(k,k+1) = cmplx((J1 + J2*al(k+1) + J2*al(k-1))/2.0d0, -J2*(ml(k-1) - nl(k+1))/2.0d0)
end do
Use ifort mkl library for matrix diagonalization (not LAPACK from netlib)
In my research maximum time I do matrix diagonalization. So I write the matrix (or its basis) and call lapack subroutine along with the ifort or gfortran to find the eigenvalues and eigenvectors. For that one has to install lapack library and give the correct path to evoke the lapack routines.
We do something like this. In the terminal where there is a code called mycode.f90
I type
ifort mycode.f90 -llapack -lblas
Now the question is, there is MKL library installed when we install intel fortran compiler. Can we use the MKL library (where LAPACK BLAS routines are there) instead of LAPACK for our purpose?
The standard rule is:
Compile by typing
ifort -mkl mycode.f90
Run by typing
./a.out
Now there can be problem like this:
To solve this problem:
do the following:
Type in the terminal
locate compilervars
You shall see something like this:
Now open the .bashrc file inside your home directory. Add this line
source /opt/intel/composer_xe_2013.3.163/bin/compilervars.sh intel64
This you may have done probably while installing ifort compiler. Then you should not face any above said problem.
After adding this line to .bashrc file compile this by typing in the terminal
source .bashrc
Then exit from the terminal. Go to the folder where your f90 code is. Compile and run you f90 code by -mkl option with ifort. It will work.
ifort -mkl mycode.f90
gfortran options important
There are some useful gfortran options I use regularly.
gfortran -Wall -Wtabs filename.f90
gfortran -fbounds-check filename.f90
gfortran -g filename.f90
gdb ./a.out
gfortran -w filename.f90
ifort linux
New ifort license problems?
So,
after installation of ifort (non-commercial for linux) in red-hat there is the problem.
[guest@localhost w0p7-eps0p5]$ ifort
Error: A license for FCompL could not be obtained (-1,359,2).
Is your license file in the right location and readable?
The location of your license file should be specified via
the $INTEL_LICENSE_FILE environment variable.
License file(s) used were (in this order):
1. Trusted Storage
** 2. /opt/intel/composer_xe_2013.3.163/Licenses
** 3. /home/guest/intel/licenses
** 4. /opt/intel/licenses/*.lic
** 5. /Users/Shared/Library/Application Support/Intel/Licenses
** 6. /opt/intel/composer_xe_2013.3.163/bin/intel64/*.lic
Please visit http://software.intel.com/sites/support/ if you require technical assistance.
ifort: error #10052: could not checkout FLEXlm license
Q. How to debug you f90 codes ?
A. One can switch on the warning flags when compiling by ifort.
The commands to remember is follows:
ifort -g -traceback -check all -fp-stack-check mycode.f90
or
ifort -debug all mycode.f90
Hope these will be working in your case and helpful.
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
No LAPACK or BLAS installed along with fortran?
If one is on Mac OS and has not installed LAPACK or BLAS Library, one can do the job of calling LAPACK subroutines as follows. Mac has some inbuilt subroutines which does this jobs. For example:
Instead of this
ifort fortrancode.f90 -llapack -lblas
One can do
ifort fortrancode.f90 -Wl,-framework -Wl,accelerate
This has worked for Mac Pro (Mac OS X 10.6) workstations. I do not know any such things on Linux, though,
One important thing.
If you have installed ifort mkl library there the lapack subroutines are installed by default. The main task is to link them properly and call them during the compilation of your code.
Segmentation fault & Bus error
Very common problem:
ifort :- SIGSEGV, segmentation fault
gfortran :- Bus error
Ifort says:
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image PC Routine Line Source
a.out 000000010000E265 Unknown Unknown Unknown
a.out 000000010000265D Unknown Unknown Unknown
a.out 0000000100000C2C Unknown Unknown Unknown
a.out 0000000100000BE4 Unknown Unknown Unknown
gfortran says :(only)
Bus error
ifort -traceback
There is one option I know now to check where the possible error could be, is using ifort compiler. One has to insert an option like this:
ifort -heap-arrays 1024 mycode.f90
./a.out
somenath@Kanaad$ifort -traceback main.f90
somenath@Kanaad$./a.out
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image PC Routine Line Source
a.out 000000010000E732 _sparseform_ 568 main.f90
a.out 0000000100002B5D _MAIN__ 242 main.f90
a.out 000000010000112C Unknown Unknown Unknown
a.out 00000001000010E4 Unknown Unknown Unknown
fortran subroutine
I don't know any gfortran option of this kind.
Unknown Fortran ld: warning:
ld: warning: for symbol _matrix_ tentative definition of size 12944 from /var/folders/uu/uuDNJbYHHwmD3218GxB09U+++TM/-Tmp-//ifort0QNWDs.o is is smaller than the real definition of size 336 from /var/folders/uu/uuDNJbYHHwmD3218GxB09U+++TM/-Tmp-//ifortQ4bnk9.o
Exact Diagonalization Code
click here
DMRG code
click here
How to handle large Array?
The problem is here.
somenath@RamanujanED$
somenath@RamanujanED$ifort sample-matrix-diagonalised.f90 -llapack -lblas
/tmp/ifortRFLH83.o: In function `MAIN__':
sample-matrix-diagonalised.f90:(.text+0x18a): relocation truncated to fit: R_X86_64_32 against `.bss'
sample-matrix-diagonalised.f90:(.text+0x194): relocation truncated to fit: R_X86_64_32S against `.bss'
sample-matrix-diagonalised.f90:(.text+0x1b4): relocation truncated to fit: R_X86_64_32S against `.bss'
sample-matrix-diagonalised.f90:(.text+0x26b): relocation truncated to fit: R_X86_64_PC32 against `.bss'
sample-matrix-diagonalised.f90:(.text+0x2c0): relocation truncated to fit: R_X86_64_PC32 against `.bss'
sample-matrix-diagonalised.f90:(.text+0x315): relocation truncated to fit: R_X86_64_PC32 against `.bss'
sample-matrix-diagonalised.f90:(.text+0x36a): relocation truncated to fit: R_X86_64_PC32 against `.bss'
sample-matrix-diagonalised.f90:(.text+0x3bf): relocation truncated to fit: R_X86_64_PC32 against `.bss'
sample-matrix-diagonalised.f90:(.text+0x414): relocation truncated to fit: R_X86_64_PC32 against `.bss'
/opt/intel/composer_xe_2011_sp1.9.293/compiler/lib/intel64/libifcore.a(for_init.o): In function `for__signal_handler':
for_init.c:(.text+0xca): relocation truncated to fit: R_X86_64_PC32 against `for__protect_handler_ops'
for_init.c:(.text+0x11b): additional relocation overflows omitted from the output
somenath@RamanujanED$
You can use
ifort -shared-intel -mcmodel=medium codename.f90
there are three mcmodel option
1. -mcmodel=small
2. -mcmodel=medium
3. -mcmodel=large
I acknowledge solution from this website.
http://docs.notur.no/uit/stallo_documentation/error/large-arrays-2gb-memory
How to handle large Array?
The problem is here.
somenath@RamanujanED$
somenath@RamanujanED$ifort sample-matrix-diagonalised.f90 -llapack -lblas
/tmp/ifortRFLH83.o: In function `MAIN__':
sample-matrix-diagonalised.f90:(.text+0x18a): relocation truncated to fit: R_X86_64_32 against `.bss'
sample-matrix-diagonalised.f90:(.text+0x194): relocation truncated to fit: R_X86_64_32S against `.bss'
sample-matrix-diagonalised.f90:(.text+0x1b4): relocation truncated to fit: R_X86_64_32S against `.bss'
sample-matrix-diagonalised.f90:(.text+0x26b): relocation truncated to fit: R_X86_64_PC32 against `.bss'
sample-matrix-diagonalised.f90:(.text+0x2c0): relocation truncated to fit: R_X86_64_PC32 against `.bss'
sample-matrix-diagonalised.f90:(.text+0x315): relocation truncated to fit: R_X86_64_PC32 against `.bss'
sample-matrix-diagonalised.f90:(.text+0x36a): relocation truncated to fit: R_X86_64_PC32 against `.bss'
sample-matrix-diagonalised.f90:(.text+0x3bf): relocation truncated to fit: R_X86_64_PC32 against `.bss'
sample-matrix-diagonalised.f90:(.text+0x414): relocation truncated to fit: R_X86_64_PC32 against `.bss'
/opt/intel/composer_xe_2011_sp1.9.293/compiler/lib/intel64/libifcore.a(for_init.o): In function `for__signal_handler':
for_init.c:(.text+0xca): relocation truncated to fit: R_X86_64_PC32 against `for__protect_handler_ops'
for_init.c:(.text+0x11b): additional relocation overflows omitted from the output
somenath@RamanujanED$
You can use
ifort -shared-intel -mcmodel=medium codename.f90
there are three mcmodel option
1. -mcmodel=small
2. -mcmodel=medium
3. -mcmodel=large
I acknowledge solution from this website.
http://docs.notur.no/uit/stallo_documentation/error/large-arrays-2gb-memory