[ previous ] [ Contents ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ 12 ] [ 13 ] [ next ]


Fortran 90 Lessons for Computational Chemistry
Chapter 12 - Instalación y uso de las bibliotecas BLAS y LAPACK


12.1 Objetivos

Los objetivos de esta clase son los siguientes:

  1. familiarizar el alumno con la compilación de programas y la instalación de librerias o biliotecas usando el compilador gfortran.

  1. Instalar las bibliotecas de interés científico BLAS y LAPACK.

  1. Aprender a hacer uso de dichas bibliotecas.

Existe una gran cantidad de código Fortran accesible de forma abierta, ya sea como código fuente o en forma de biblioteca. En la presente clase el alumno se familiariza con la obtención, compilación, instalación y uso de dos bibliotecas de subrutinas de interés algebraico, BLAS y LAPACK.


12.2 Puntos destacables.

Indicaremos de forma escalonada los diferentes pasos que hay que seguir para la instalación de estas bibliotecas.

El código fuente de las bibliotecas BLAS y LAPACK puede descargarse de diferentes lugares, o instalarse a partir de paquetes de la distribución Debian o Ubuntu que se esté utilizando. En vez de ello las instalaremos compilándolas en nuestro ordenador.


12.3 Programas usados como ejemplo.


12.3.1 Ejemplo de fichero make.inc para LAPACK

     ####################################################################
     #  LAPACK make include file.                                       #
     #  LAPACK, Version 3.2.1                                           #
     #  MAY 2009                                                        #
     #  Modified by Currix                                              #
     ####################################################################
     #
     SHELL = /bin/sh
     #
     #  The machine (platform) identifier to append to the library names
     #
     PLAT = _LINUX
     #  
     #  Modify the FORTRAN and OPTS definitions to refer to the
     #  compiler and desired compiler options for your machine.  NOOPT
     #  refers to the compiler options desired when NO OPTIMIZATION is
     #  selected.  Define LOADER and LOADOPTS to refer to the loader and 
     #  desired load options for your machine.
     #
     FORTRAN  = gfortran 
     OPTS     = -O2
     DRVOPTS  = $(OPTS)
     NOOPT    = -O0
     LOADER   = gfortran
     LOADOPTS =
     #
     # Timer for the SECOND and DSECND routines
     #
     # Default : SECOND and DSECND will use a call to the EXTERNAL FUNCTION ETIME
     #TIMER    = EXT_ETIME
     # For RS6K : SECOND and DSECND will use a call to the EXTERNAL FUNCTION ETIME_
     # TIMER    = EXT_ETIME_
     # For gfortran compiler: SECOND and DSECND will use a call to the INTERNAL FUNCTION ETIME
     TIMER    = INT_ETIME
     # If your Fortran compiler does not provide etime (like Nag Fortran Compiler, etc...)
     # SECOND and DSECND will use a call to the INTERNAL FUNCTION CPU_TIME
     # TIMER    = INT_CPU_TIME
     # If neither of this works...you can use the NONE value... In that case, SECOND and DSECND will always return 0
     # TIMER     = NONE
     #
     #  The archiver and the flag(s) to use when building archive (library)
     #  If you system has no ranlib, set RANLIB = echo.
     #
     ARCH     = ar
     ARCHFLAGS= cr
     RANLIB   = ranlib
     #
     #  Location of the extended-precision BLAS (XBLAS) Fortran library
     #  used for building and testing extended-precision routines.  The
     #  relevant routines will be compiled and XBLAS will be linked only if
     #  USEXBLAS is defined.
     #
     # USEXBLAS    = Yes
     XBLASLIB     =
     # XBLASLIB    = -lxblas
     #
     #  The location of the libraries to which you will link.  (The 
     #  machine-specific, optimized BLAS library should be used whenever
     #  possible.)
     #
     #BLASLIB      = ../../blas$(PLAT).a
     BLASLIB      = /usr/local/lib/libblas.a
     LAPACKLIB    = lapack$(PLAT).a
     TMGLIB       = tmglib$(PLAT).a
     EIGSRCLIB    = eigsrc$(PLAT).a
     LINSRCLIB    = linsrc$(PLAT).a

12.3.2 Ejemplo de fichero make.inc para LAPACK95

     #
     #  -- LAPACK95 interface driver routine (version 2.0) --
     #     UNI-C, Denmark; Univ. of Tennessee, USA; NAG Ltd., UK
     #     August 5, 2000
     #
     FC	 = gfortran
     FC1      = gfortran
     # -dcfuns  Enable recognition of non-standard double
     #          precision  complex intrinsic functions
     # -dusty   Allows the compilation and execution of "legacy"
     #          software by downgrading the category  of  common
     #          errors  found  in  such software from "Error" to
     # -ieee=full enables all IEEE arithmetic facilities
     #          including non-stop arithmetic.
     
     OPTS0    = -u -V -dcfuns -dusty -ieee=full
     MODLIB   = -I./../lapack95_modules
     OPTS1    = -c $(OPTS0)
     OPTS3    = $(OPTS1) $(MODLIB)
     OPTL     = -o 
     OPTLIB   =
     
     LAPACK_PATH = /usr/local/lib/
     
     LAPACK95 = ../lapack95.a
     LAPACK77 = $(LAPACK_PATH)/lapack_LINUX.a
     TMG77    = $(LAPACK_PATH)/tmglib_LINUX.a
     BLAS     = $(LAPACK_PATH)/libblas.a
     
     LIBS     = $(LAPACK95) $(TMG77) $(LAPACK77) $(BLAS)
     SUF      = f90
     
     XX = 'rm' -f $@; \
             'rm' -f $@.res; \
     	$(FC) $(OPTS0) -o $@ $(MODLIB) $@.$(SUF) $(OPTLIB) $(LIBS); \
             $@ < $@.dat > $@.res; \
             'rm' -f $@
     
     YY = $(FC) $(OPTS0) -o $@ $(MODLIB) $@.$(SUF) $(OPTLIB) $(LIBS)
     
     .SUFFIXES: .f90 .f .o
     
     .$(SUF).o: 
     	$(FC) $(OPTS3) $<
     
     .f.o:
     	$(FC1) $(OPTS3) $<

12.3.3 Ejemplo de programa que invoca LAPACK95

     PROGRAM LA_SSPSV_EXAMPLE
       
       !  -- LAPACK95 EXAMPLE DRIVER ROUTINE (VERSION 1.0) --
       !     UNI-C, DENMARK
       !     DECEMBER, 1999
       !
       !  .. "Use Statements"
       USE LA_PRECISION, ONLY: WP => SP
       USE F95_LAPACK, ONLY: LA_SPSV
       !  .. "Implicit Statement" ..
       IMPLICIT NONE
       !  .. "Local Scalars" ..
       INTEGER :: I, N, NN, NRHS
       !  .. "Local Arrays" ..
       INTEGER, ALLOCATABLE :: IPIV(:)
       REAL(WP), ALLOCATABLE :: B(:,:), AP(:)
       !  .. "Executable Statements" ..
       WRITE (*,*) 'SSPSV Example Program Results.'
       N = 5; NRHS = 1
       WRITE(*,'(5H N = , I4, 9H; NRHS = , I4)') N, NRHS
       NN = N*(N+1)/2
       ALLOCATE ( AP(NN), B(N,NRHS), IPIV(N) )
       !
       OPEN(UNIT=21,FILE='spsv.ma',STATUS='UNKNOWN')
       DO I=1,NN 
          READ(21,'(F3.0)') AP(I)
       ENDDO
       CLOSE(21)
       !
       WRITE(*,*)'Matrix AP :'
       DO I=1,NN; WRITE(*,"(15(I3,1X,1X),I3,1X))") INT(AP(I));
       ENDDO
       !
       OPEN(UNIT=21,FILE='spsv.mb',STATUS='UNKNOWN')
       DO I=1,N 
          READ(21,'(F3.0)') B(I,1)
       ENDDO
       CLOSE(21)
       !
       WRITE(*,*)'Matrix B :'
       DO I=1,N; WRITE(*,"(10(I3,1X,1X),I3,1X)')") INT(B(I,1));
       ENDDO
       !
       WRITE(*,*)" CALL LA_SPSV( AP, B, 'L', IPIV )"
       !
       CALL LA_SPSV( AP, B, 'L', IPIV )
       !
       WRITE(*,*)'AP on exit: '
       DO I=1,NN; WRITE(*,"(15(E13.5))") AP(I); 
       ENDDO
       !
       WRITE(*,*)'Matrix B on exit :'
       DO I=1,N; WRITE(*,"(F9.5)") B(I,1);
       ENDDO
       WRITE(*,*)'IPIV = ', IPIV
       !
     END PROGRAM LA_SSPSV_EXAMPLE

12.3.4 Ejemplo de makefile para compilar programas que invocan LAPACK95

     #
     #  -- LAPACK95 makefile (version 1.0) --
     #
     FC	 = gfortran
     #
     MODLIB   = -I/usr/local/lib/lapack95_modules
     OPTS1    = -c
     OPTS3    = $(OPTS1) $(MODLIB)
     OPTL     = -o 
     OPTLIB   =
     
     LAPACK_PATH = /usr/local/lib
     LAPACK95_PATH = /usr/local/lib
     
     LAPACK95 = $(LAPACK95_PATH)/lapack95.a
     LAPACK77 = $(LAPACK_PATH)/lapack_LINUX.a
     TMG77    = $(LAPACK_PATH)/tmglib_LINUX.a
     BLAS     = $(LAPACK_PATH)/libblas.a
     
     LIBS     = $(LAPACK95) $(TMG77) $(LAPACK77) $(BLAS)
     SUF      = f90
     
     YY = $(FC) -o $@ $(MODLIB) $@.$(SUF) $(OPTLIB) $(LIBS)
     
     .SUFFIXES: .f90 .f .o
     
     .$(SUF).o: 
     	$(FC) $(OPTS3) $<
     
     ejemplo_la_spsv: 
     	$(YY)
     
     clean:
     	'rm' -f *.o *.mod core

[ previous ] [ Contents ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ 12 ] [ 13 ] [ next ]


Fortran 90 Lessons for Computational Chemistry

0.0

Curro Pérez-Bernal mailto:francisco.perez@dfaie.uhu.es