170 likes | 282 Views
Compiling Environment – ecgate. Dominique Lucas User Support. Content. Introduction Fortran Compiler Compiler Options Word Lengths Fortran I/O Linking Libraries Debugging Profiling Practical session. Introduction. Why compiling at ECMWF?
E N D
Compiling Environment – ecgate Dominique Lucas User Support
Content • Introduction • Fortran Compiler • Compiler Options • Word Lengths • Fortran I/O • Linking • Libraries • Debugging • Profiling • Practical session
Introduction • Why compiling at ECMWF? • decoding of (MARS) data • model runs • Which platforms available? • Unix IBM server (ecgate) • IBM Supercomputers (hpca) • Which compilers? • Fortran (77/90/95) • C/C++ • Which platform to use? • High Performance Computing Facility (HPCF) for computing intensive work, including any // work. • IBM server for decoding or I/O bound work.
Compilers • IBM compilers: • xlf[90|95] for Fortran • xlc for C • xlC for C++ • Which version do I use? • lslpp –l xlf* • lslpp –l xlC* • How to select a different version of a Compiler? • If a different version is available, this can be set with a ECMWF local utility called “use”, e.g.: • use xlf_8113
Compilers • File suffixes for fortran • “.f” or “.F” to run the C preprocessor • “.f90” with -qsuffix=f=f90 • .F90 with –qsuffix=f=f90:cpp=F90
Compilers • Common file suffixes and files • .o : object file • .a : archive file (library) • .so: share object (library) • .s: assembler listing • .list: source listing • .mod: fortran 90 module files • a.out: default name of executable
Fortran compiler • Fortran source code format • Fixed with xlf • Free with xlf[90|95] • Format can be given with options “–qfixed” or “-qfree” • A few examples • $ xlf prog.f # fixed f77 • $ xlf prog.F # fixed f77 via cpp • $ xlf90 –qsuffix=f=f90 prog.f90 # free f90 • $ xlf90 prog.F # free f90 via cpp
Fortran Compiler options • Setting options – given by increasing precedence • In the configuration file – system wide • less /etc/xlf.cfg • At the command line – used for all the file • xlf –qfixed prog.f • As a directive in the source code – for the next unit. • head prog.f @PROCESS FIXED
Fortran Compiler common options • Fortran 77 / f90 • -c compilation only, no linking • -qsource listing • -qrealsize=8 64bit real variables • -O optimisation • -g debugging • -v verbose • -help display usage • Defaults: underscores (-qextname) and 32-bit addressing mode (-q32) • Well over 100 options. See man page for full list of options.
Word lengths – precision • 32bit reals and integer by default • The option –qrealsize=8 promotes real variables to 64bit • Integer*8 and 128bit floating point computation available and slightly slower than integer*4 or real*8 computation. • When using a library, check its precision, e.g. for EMOSLIB.
Fortran I/O • Unit numbers: • Units 0, 5 and 6 reserved, respectively for STD error, input and output. • Connecting files to Units: • open (1,file="data",...) • ln -s data fort.1 • Fortran record types: • formatted/unformatted • read (1)length • list-directed • write(*,*)'lenght=',length • Namelist • read(5,NML=name_l)
Fortran I/O – data representation • Access method: • sequential access • direct access • record length - in bytes • IEEE format - big-endian • real*4 • bit 31: sign • bits 30-23: exponent • bits 22-0: mantissa • real*8 • bit 63: sign • bits 62-52: exponent • bits 51-0: mantissa
Linking • Use xlf to link, eg. • $ xlf -o prog prog.f $EMOSLIB duplicated entries. • Static vs. dynamic linking: • Option –bdynamic or –bstatic • Default: -bdynamic • Loadmap useful to identify duplicated entries or unresolved symbols • $ xlf –bloadmap:map –o prog prog.f $EMOSLIB • $ less map
Building libraries • Static and shared/dynamic libraries • Use "ar" to build static libraries, eg. • $ ar -vr libmy.a *.o • Use “xlc" to build shared/dynamic libraries, • $ cc -G *.o –o libmy.a • $ xlf -o prog prog.f -L. –lmy • $ export LIBPATH=${LIBPATH}:. • $ ./prog • Alternatively, see http://publibn.boulder.ibm.com/doc_link/en_US/a_doc_lib/aixprggd/genprogc/create_shared_lib.htm#HDRA144C1671
Debugging • checking: • argument checking: -qextchk • xlf –qextchk prog.f –o prog checking done at compilation/linking • array bounds checking: -C • xlf –C prog.f –o prog • ./prog checking done at runtime • undefined reference checking • xlf –qinitauto=FF –qflttrap prog.f –o prog checking done at runtime
Debugging – floating point exceptions • nothing generated on floating point exception. • Floating point trapping • % xlf –qflttrap=overflow:invalid:zerodivide:enable \ –qsigtrap prog.f –o prog • % ./prog • ... • interactive window based debugger: - totalview • Core files – how to get a traceback • % dbx ./prog core <<eof where eof
Profiling - tuning • timex - command timer • $ timex [-ops] a.out • -O and other options at compilation for faster execution. • See man page. • other AIX applications, like prof, gprof • $ xlf –p prog.f • $ a.out • $ prof