Showing posts with label fortran. Show all posts
Showing posts with label fortran. Show all posts

2014-08-22

Compiling OpenMPI with the NAG Fortran Compiler

As the most popular search engine was only partially useful when looking for information about compiling OpenMPI with the NAG compiler, below a short summary of my recent (successful) efforts. I've tried to get something working out of the following components:
  • NAG Fortran Compiler Release 6.0(Hibiya) Build 107
  • OpenMPI 1.8.1
  • GCC 4.8.2
  • Ubuntu 14.4 (x86_64/Linux)

Configuration and compilation

The configure combination working was the following:

./configure FC=nagfor FCFLAGS="-mismatch" --enable-static --disable-shared --prefix=${HOME}/local/opt/openmpi/1.8.1-nag6.0

The rationale behind the options:
  • FC=nagfor: Use the NAG Fortran compiler
  • FCFLAGS="-mismatch": Convince the excellent NAG compiler not to be too picky about calling conventions. Otherwise one ends up with error messages like

    Error: mpi_comm_spawn_multiple_f90.f90: Argument 3 to MPI_COMM_SPAWN_MULTIPLE has data type DOUBLE PRECISION in reference from MPI_COMM_SPAWN_MULTIPLEN and CHARACTER in reference from MPI_COMM_SPAWN_MULTIPLEA
     
  •  --enable-static --disable-shared: Apparently, libtool passes the inappropriate option -shared to the NAG compiler, resulting in the error

    Option error: Unrecognised option -shared

    during the compilation process. Probably, it can be fixed somehow within libtool itself. My preference was to build only a static version of OpenMPI rather than messing around with the innards of libtool.

Fixing the wrapper options

Unfortunately, libtools inability to cope with the NAG compiler had further consequences. When compiling the parallel version of our DFTB+ code,I've ended up with the error message:

gcc: error: unrecognized command line option ‘-rpath’

Fortunately, a similar issue has been already discussed on the OpenMPI mailing list. Accordingly, I've replaced in all Fortran related wrapper files the -Wl, flag in the linker options to -Wl,-Wl,,. This was easily achieved by executing the following bash commands in the shared/openmpi directory (relative to the root directory of the installed OpenMPI).

for file in mpifort-vt-wrapper-data.txt mpifort-wrapper-data.txt shmemfort-wrapper-data.txt;  do
  cp $file ${file}.orig
  sed -e 's/-Wl,/-Wl,-Wl,,/g' $file.orig > $file
done


This fixes the broken linking workflow: OpenMPI passes the options meant for the linker to the NAG compiler with the -Wl,-Wl,, prefix. The NAG compiler subsequently passes them to GCC with the -Wl prefix, so that GCC can finally properly pass them to the linker itself (without any suffix). Without the changes above, the linker options would arrive already at GCC without any prefix, causing GCC to raise an error about unknown options.

After that, OpenMPI and the NAG Fortran compiler worked together like charm.

2012-12-18

modFileSys: directory and file manipulation in Fortran

Update (2016-02-24): I have moved the content of modfilesys into the Fortyxima library.

Recently, the DFTB+ project needed a simple feature extension: The main program had to delete/create a scratch directory which stores a bunch of auxiliary files (surface Greens functions). Until now, we have relied on the fact, that the directory is just there (e.g. being magically created by some wrapper script around the code), which turned out to be a pain as nobody wrote such a magical script and consequently we usually just forgot to create that directory.  Quite annoying if your job waits a few days in the queue just to produce a reminder about you being fool enough having forgotten to create the obligatory directory...

Simple tasks usually require simple solutions, unless they are operating system related and the programming language of your choice happens to be Fortran; for this special combination things tend to be rather complicated. The first quick and dirty approach coming up was to (ab)use the system call:

call system("rm –rf directory")
call system("mkdir directory")

While working as expected, it felt like a punch in the face to mix shell commands with  Fortran statements. So, why not writing something more appropriate, maybe using the shiny standardized C-interface feature of Fortran 2003, which is by now supported by practically all Fortran compilers? Should not take more than an afternoon, should it?

Well, it took somewhat longer, but finally the first working version of MODFILESYS was created. Now, after having wrapped the libc file system interface with modern Fortran 2003 wrappers, we can create and remove directories (even recursively!), check the existence of files, manipulate links and symlinks, and list the content of directories. Things I always missed in Fortran, now being there, being simple and fortranic! So, from now on, we just simply issue

call rmdir("directory", children=.true.)
call mkdir("directory")

in order to remove and recreate our beloved/behated scratch folders. Although being only subtle differences in the actual program lines, what an aesthetic difference in the method under the hood!