The IBM Fortran and C compiling environment - Compiling

Document Sample
The IBM Fortran and C compiling environment - Compiling Powered By Docstoc
					 Compiling Environment – HPCF


                           Dominique Lucas
                                     User Support



                                         Slide 1




Com hpcf – Compiling environment         Slide 1
Unit Topics
 the IBM XL FORTRAN compiler
    Compiling
    Linking
    Execution
    Programming environment
        Runtime environment
        Libraries
        Software environment
 the IBM C compiler
 References                        Slide 2

 Addendum

 Com hpcf – Compiling environment   Slide 2
IBM XL FORTRAN compiler (version 12.1)
 full FORTRAN 90
     ● and FORTRAN 77
     ● and FORTRAN 95
     ● and FORTRAN 2003
     ● and most "Industry-standard" extensions
       ● For example "Cray Pointers" as well as FORTRAN
         90 pointers
 OpenMP (versions 2.5 and 3) for SMP parallel
 FORTRAN pthreads interface
 extensive libraries (MASS, ESSL, MPI, etc)
                                   Slide 3
 performance is a key goal

 Com hpcf – Compiling environment   Slide 3
One Compiler – several invocations
 One single fortran compiler
 Several invocations – called stanzas
 Each stanza differs by defaults settings for
  compilation options, e.g.
    Source code format
    Language level
    File suffix **
    MPI environment
 Default settings for stanzas are stored in file
  /etc/xlf.cfg
                                         Slide 4


** less relevant since xlf version 10.

 Com hpcf – Compiling environment        Slide 4
Compiler invocation commands
         AxlfXY
 where:-
   ● A is null or "mp" (MPI extensions)
   ● X is null or "90" or "95" or “2003” (FORTRAN 90,
     95 or 2003)
   ● Y is null or "_r" (POSIX threads safe) or "_r7"
     (draft 7 POSIX threads safe)
 e.g. xlf, xlf90, mpxlf90, xlf90_r, etc
 see XL Fortran Compiler Reference for details.

                                    Slide 5




 Com hpcf – Compiling environment   Slide 5
Compiler invocation - defaults

            Compiler           langlvl   source             Suffix **
            xlf                F95+ext   fixed              .f
            f77                f77       fixed              .f
            f90                F90       free               .f90
            xlf90              F90       free               .f
            f95                F95       free               .f95
            xlf95              F95       free               .f
            f2003              F2003     free               .f03
            xlf2003            F2003     free               .f


            ** irrelevant as of version 10.       Slide 6




 Com hpcf – Compiling environment                 Slide 6
Compiler invocation – thread safe and
MPI
           Compiler            langlvl   source             Suffix **
           xlf_r               F95+ext   fixed              .f
           xlf90_r             F90       free               .f
           xlf95_r             F95       free               .f
           xlf2003_r *         F2003     free               .f
           mpxlf_r             F95+ext   fixed              .f
           mpxlf90_r           F90       free               .f
           mpxlf95_r           F95       free               .f
           mpxlf2003_r         F2003     free               .f
                                                                        * stanzas
           mpxlf               F95+ext   fixed              .f          not defined.

           mpxlf90             F90       free               .f          ** irrelevant
                                                  Slide 7               as of version 10.
           mpxlf95             F95       free               .f
           mpxlf2003 *         F2003     free               .f

 Com hpcf – Compiling environment                 Slide 7
Overruling defaults
 -qfree                            free source format
 -qfixed                           fixed source format
 -qsuffix                          change suffix
                                    less needed since xlf version 10.
 -qsave                            local variables static
 -qnosave                          local variables auto
 -qlanglvl                         language level



                                                  Slide 8




 Com hpcf – Compiling environment                 Slide 8
Compiler options: syntax
 System wide configuration file /etc/xlf.cfg includes
  default settings. ECMWF local changes:
   ● Underscores (_) added to names of global entries
     (option –qextname)
   ● 64bit addressing mode (OBJECT_MODE=64)
● Command line:
   ● -qflttrap=overflow
 @PROCESS directive
   ● appears before first statement of compilation unit
   ● applies ONLY to the single following unit
   ● typically local override to general command line
     options
   ● many options do not have @PROCESS
                                    Slide 9
     alternative

 Com hpcf – Compiling environment   Slide 9
   Options controlling compiler input and output
        -c         compilation only (no link)                   *
        -d         don't delete cpp-processed files             *
        -o         name output file                             *
        -qnoobject syntax check only                            *
        -q32/64    32- or 64-bit addressing                     *
Uppercase i
                    default: 64-bit ($OBJECT_MODE)
      -I           add directory to search path                 *
      -qci         selectively activate include lines (not portable)
      -qdirective specifies trigger constants
      -q[fixed|free] fixed or free format input                 *
      -k           abbreviation for -qfree=f90
      -qmixed/-U case sensitive names
                                             Slide 10
      -qsuffix     change .f, .F, .f90, .F90, … extensions
      -qmoddir directory for module files                       *
 * the most useful ones
      Com hpcf – Compiling environment    Slide 10
  Listings and messages options
    -qsource list source code                                *
    -qreport -qsmp & -qhot loop information                  *
    -S         create "assembler source" file with .s suffix *
   -qattr      attribute listing                             *
    -qflag/-w controls error messages                        *
    -qlistopt list all options settings                      *
   -qxref      cross reference listing                       *
    -v         verbose: display progress info
    -V         as -v but create executable shell script
   -qversion prints compiler version number                  *
   -qsaveopt includes compiler version and options in object
    file (can be checked with “what”)    Slide 11
                                                              *

* the most useful ones
     Com hpcf – Compiling environment   Slide 11
Compatibility options
  -qautodbl             auto-double and padding                  *
  -qrealsize            specify size of default REAL             *
        over-ridden if also use -qautodbl
  -qintsize             specify size of default INTEGER          *
  -qsave                local variables default to STATIC        *
        can be vital to specify -qnosave for OpenMP
  -qdpc                 treat constants as REAL(8)               *
        if using -qrealsize(8)
                         CALL SUB(X,1.0)       might need -qdpc
                         CALL SUB(X,1.0E0) might need -qdpc=e
  -qctyplss             CHARACTER for typeless consts
                                              Slide 12

  -qddim                re-evaluate POINTER array dimensions
* the most useful ones
   Com hpcf – Compiling environment             Slide 12
 Common compiler options for performance
    -p -pg              compile for prof or gprof         *
    -O[0-5]             Optimization option               *
    -Q                  specify routines to inline
    -qipa               inter-procedural analysis         *
    -qsmp               enable OpenMP                     *
    -qnosave            allocate local variables on the
                         function call stack (generally
                         required for OpenMP programs)*
    -qstrict            ensure bitwise reproducibility *
    -qarch              specifies for which architecture the *
                         compiler should generate code, e.g.
                                         Slide 13

                                -qarch=pwr6
* the most useful ones   for the new system.
Error checking & debugging options
  -C/-qcheck run time array bound checking                      *
  -D/-qdlines compile lines with D in col 1                     *
  -g/-qdbg    generate symbolic information for the debugger    *
  -qoptdebug generates pseudo code corresponding to the optimised
  version of your code                                           *
  -qextchk    detect type errors across routines                *
  -qflttrap   detect floating point exceptions                  *
  -qsigtrap   installs trap-handler                             *
  -qfullpath full names of source files included in object file *
  -qhalt      stop if errors too severe
  -qinitauto initialize automatic variables                     *
  -qlanglvl   specify FORTRAN language level (77, 90, etc)      *
  -qsaa       SAA standard conformance
                                              Slide 14
  -qtbtable   limits size of executables (and core files)
  -qwarn64 detects truncation of 8-byte INTEGER POINTER
* the most useful ones
    Com hpcf – Compiling environment     Slide 14
“Top 5” options for productions runs.
 -g               we’re always ready for debugging …
 -qarch           select instructions for specific architecture
 -O3|-O4          reasonable optimisation level (default –O0)
 -qsaveopt        to see with which options a .o file has been produces
 -qfullpath       points debugger or profiler directly to to the source code

 With the signal trap by ECMWF (cf. debugging on Thursday)




                                                 Slide 15




 Com hpcf – Compiling environment               Slide 15
Compilation – return codes
 Return code
   ● Successful compilation: 0
   ● Failure: (≠0) 1, 40, 41, 250, …

 xlf messages:                                              Error severity

    ● "cpp_radiations.f90", line 191.5: 1514-219 (S) Unable to
      access module symbol file for module mode_fmwrit. Check
      path and file permissions of file. Use association not done
      for this module.


                                      position        Message ID
          Error message


                                                  Slide 16




   Com hpcf – Compiling environment              Slide 16
Linking
 Use xlf – or any other xlf stanza - to link, not ld, e.g.

     $ xlf -o prog prog.o $EMOSLIB

    Beware of duplicated entries, precision and
      addressing mode.

 Static vs. dynamic linking:
    Options –bdynamic or –bstatic and -brtl
    Default: -bdynamic

 Loadmap useful to identify duplicated entries or
  unresolved symbols:

                                         $EMOSLIB
     $ xlf –bloadmap:map –o prog prog.fSlide 17
     $ less map

   Com hpcf – Compiling environment       Slide 17
Linker options
  -L        search directory for libraries                            *
  -l        library to search (lower case "L")                        *
  -bmaxdata extend addressability to 2GB in 32-bit mode               *
                e.g. "-bmaxdata:0x80000000" (0x70000000 for MPI)
       do NOT specify in 64-bit mode - it will limit addressibility
  -bmaxstack like maxdata but for stack
  -b64       64-bit addressing mode
  -bdynamic/shared/static/rtl       specify linking style
  -bloadmap log of linker actions
  -bhalt     error level to cause halt

IMPORTANT: default max stack in 32-bit mode is
equal to 256MB. Maximum available in 64-bit mode is
4GB.                                     Slide 18



* the most useful ones
    Com hpcf – Compiling environment           Slide 18
Running your program …
 Batch mode – Loadleveler – is recommended.
 Serial or parallel program in batch job:
    ● ./a.out
 MPI or MPI/OpenMP parallel executables can also be
  run with poe (cf. “man poe”):
    ● poe –labelio –infolevel 0 –stdoutmode ordered a.out
● MPMD parallel programming model
    ● poe –pgmmodel mpmd –cmdfile <file>
      with <file> like:
             a.out
             b.out
             c.out
 For OpenMP runs, env. variables exist:
    ● export OMP_NUM_THREADS=4
                                        Slide 19




   Com hpcf – Compiling environment    Slide 19
Run-time environment variables
● XLFRTEOPTS                        specify XLF runtime
                                    environment parameters
● XLFSMPOPTS                        specify SMP related
                                    options
● OMP_NUM_THREADS                   specify number of
                                    OpenMP threads

● changing these during execution has no effect
● CALL to SETRTEOPTS changes settings during
  execution
                                         Slide 20




 Com hpcf – Compiling environment       Slide 20
 XLFRTEOPTS keywords
  ● buffering                   controls FORTRAN I/O buffering       *
  ● cnverr                      conversion error takes ERR=exit      *
  ● err_recovery                stop on I/O RECOVERABLE error        *
  ● uwidth                      long records in 64-bit addressing    *
  ● erroreof                    EOF goes to ERR= if no END=
  ● langlvl                     which language std is in effect
  ● multconn                    same file to multiple units
  ● namelist                    new or old NAMELIST formats          *
  ● nlwidth                     length of namelist output lines
  ● random                      specifies random number generator
  ● scratch_vars                name a scratch file
  ● unit_vars                   name implicitly connected file       *
  ● xrf_messages                inhibit error mesages during I/O
                                                         Slide 21
  ● ufmt_littleendian           activates little endian I/O format   *

* the most useful ones
    Com hpcf – Compiling environment                Slide 21
FORTRAN I/O unit associations
 stdin, stdout and stderr are associated with FORTRAN i/o
  units 5, 6 and 0 respectively
 default Unix file name associated with other FORTRAN i/o
  unit n is fort.n
 to override
      set "unit_vars=yes" in XLFRTEOPTS
      set XLFUNIT_n to desired Unix file name
      e.g. assign "molecules.dat" to FORTRAN i/o unit 17:
              $ export XLFRTEOPTS="unit_vars=yes"
              $ export XLFUNIT_17="molecules.dat“
 Alternatively, use the “ln” command, e.g.
                                    Slide 22

      $ ln –s molecules.dat fort.17

 Com hpcf – Compiling environment             Slide 22
Building libraries
 Static and shared/dynamic libraries

 Use "ar" to build static libraries, eg.
    $ ar -vr libmy.a *.o

 Use C compiler to build shared/dynamic libraries,

     $ xlf –c *.f
     $ cc –o libmy.so -G *.o
     $ xlf –brtl –o prog prog.f -L. –lmy
     $ ./prog

    You may need to use $LIBPATH
                                             Slide 23




   Com hpcf – Compiling environment         Slide 23
Modules - http://modules.sourceforge.net/
 Dynamic modification of users environment
     ● “module” command alters the user environment, e.g. changing a
       version of a compiler, enabling a software package.
     ● Modules can be set up for systems widely used packages and for
       user private packages.
     ● Modules includes some scripts (or environmental variables) to
       compile code.
 First implementation and usage at ECMWF on c1a. Full
  benefit from Modules will appear when it is installed on all
  platforms.
 See http://www.ecmwf.int/services/computing/docs/modules/

                                               Slide 24




 Com hpcf – Compiling environment             Slide 24
Modules - examples
 List modules loaded or modules available:
     $ module list
     $ module avail

 Display information on module:
     $ module display grib_api
     $ module explain grib_api

 Load module, change module version, or unload module:
     $ module load netcdf
     $ module switch grib_api grib_api/1.7.0
     $ module unload netcdf

 Change initial setting:
     $ module initadd netcdf

 Compile using modules environment: Slide 25
     $ ec_f90 grib_api.f90


 Com hpcf – Compiling environment              Slide 25
Software environment – new hpcf system
 ECMWF local libraries:
     ECLIB, accessible through environment variable
      $ECLIB
           Default is 64-bit reals (8-byte REALs)
     EMOSLIB, version 320, accessible through
      environment variable $EMOSLIB
           Default is 64-bit reals (8-byte REALs)
     GRIB_API, version 1.6.4, accessible through different
      environmental variables.
           32/64-bit reals combined, through fortran 90 interface block.
     NAGLIB, version 21, available from /usr/local/lib/nag,
      accessible through environment variable $NAGLIB
           Default is 64-bit reals (8-byte REALs)
                                                Slide 26




 Com hpcf – Compiling environment              Slide 26
Software environment
 ECMWF local libraries:
     netCDF, version 3.6.3, available through Modules
     HDF, version 4.2r3, available through Modules.
     HDF5, version 1.8.1, available through Modules.
     cdo, version 1.1.0, available through Modules.
     BLAS, LAPACK available through Modules.
           Some blas routines are also in an IBM library libxlopt




                                               Slide 27




 Com hpcf – Compiling environment             Slide 27
Software environment
 IBM local libraries
      MASS, Mathematical Accelerated SubSystem available in
       /usr/local/lib/mass.
           http://www-01.ibm.com/software/awdtools/mass/aix/mass-aix.html
     MPI trace and HPM libraries in /usr/local/lib/trace
         /usr/local/lib/trace/README
 IBM libraries
      ESSL/PESSL – Engineering and Scientific Subroutine
       Library.
           http://www.ecmwf.int/publications/manuals/hpcf_power6/index.html


                                                   Slide 28




 Com hpcf – Compiling environment                 Slide 28
IBM XL C compiler (version 10.1)
● K&R C and ANSI C
● OpenMP and POSIX threads for SMP parallel
● MPI for distributed memory parallel
● support for profiling
● source level debugging
● multiple stanzas, like for xlf, including cc, xlc,
  …
● Configuration file available from /etc/vac.cfg
                                     Slide 29




 Com hpcf – Compiling environment   Slide 29
IBM documentation
 XL Fortran v12.1 documentation
    http://www-01.ibm.com/software/awdtools/fortran/xlfortran/aix/library/?S_CMP=rnav

 XL C/C++ AIX v10. documentation
    http://www-01.ibm.com/software/awdtools/xlcpp/aix/library/?S_CMP=rnav

    Some of the above documents will be added on our web site.
 XLF and XLC/C++ HOME pages
    http://www-01.ibm.com/software/awdtools/fortran/xlfortran/aix/
    http://www-01.ibm.com/software/awdtools/xlcpp/aix/
 The online man pages.
    $ man xlf
    $ man xlc

                                                     Slide 30




  Com hpcf – Compiling environment                  Slide 30
Addendum – related commands …
●    ld   – run link edition
●    ar   – access archive libraries
●    nm   – print symbols in object file or executable
●    ldd  – lists dynamic dependencies of shared library or
          executable
●    size – prints sections’ sizes of object or executable file
●    file – prints file type
●    fsplit – separates fortran source file in different files
●    strip – reduces size of an object or executable file
●    make/gmake – maintenance of programs
       ● gmake more portable and allows for parallel make.
●    what – displays identifying information in (object) files.
                                             Slide 31




    Com hpcf – Compiling environment        Slide 31

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:22
posted:3/13/2011
language:English
pages:31