Autotool GPTL
Autotool GPTL
James Rosinski 3,
Edward Hartnett 1,2,
1 CIRES, University of Colorado, Boulder, CO 80309, USA
2 NOAA/ESRL/GSD, Boulder, CO 80305, USA
3 NCAR/JCSDA
Important scientific C and Fortran software packages Standard Linux tools autoconf, automake, and (for
are frequently distributed through use of home-grown libraries) libtool are used to configure and build
approaches rather than the standard GNU tools packages in a standard way. Collectively these tools are
autoconf, automake, and libtool. This results in wasted referred to as “autotools”.
effort for the distributors of the software, as they
struggle to achieve portability. Home grown approaches Anyone who has built open-source software on Linux
also tend to waste the time of all software installers, machines has encountered these tools. To build, the
which have to struggle to correctly build the software. In user first (optionally) specifies some standard compiler
this poster the conversion of a scientific software flags, and then runs the configure script. The configure
package, the General Purpose Timing Library (GPTL) script queries the target machine for information needed
from a home-rolled build system to a standard build is to correctly build the software. It then constructs
demonstrated. This results in nearly an order of Makefiles on the build system. The user runs make to
magnitude decrease in build system complexity, build the code, make check to build and run tests, and
measured by lines of code, and an increase in build make install to install the code.
system features for the user, including automatic shared
library builds, standard configure options, and standard To accomplish this, the developer creates an autotools
make options, as well as increased portability and ease build system, which includes one configure.ac file for the
of use. As demonstrated by major scientific software project, which is the basis of the configure script, and
packages like netCDF and HDF5, these tools can be one Makefile.am file for each directory in the build. The
used very effectively to package software portably, Makefile.am files are used to construct the final
including software that is built and run on High makefiles.
Performance Computing (HPC) systems.
1.3 GPTL
1. INTRODUCTION
The General Purpose Timing
1.1 Motivation Library(https://jmrosinski.github.io/GPTL) provides
detailed timing information for an application by
Complex software packages can require considerable instituting calls to start and stop timers. These calls can
effort to build and install. Scientific software, such as be manually inserted by the user, or automatically
numerical models, make frequent use of math, I/O, generated through the use of flags available on most
compression, and other libraries, which must be compilers (e.g. -finstrument-functions on GNU and Intel,
installed, and their location communicated to the -Minstrument=functions on PGI) . The library is
software build. Dependencies between software thread-safe, and provides per-thread timing information.
packages can also become complex; features may be It also can provide optional summary information across
used which require a specific version of a library, or MPI tasks. There are other optional capabilities, such as
specific information about the library’s capabilities. integration with the PAPI performance counter library,
and automatic generation of MPI stats if C-preprocessor
The GPTL legacy build system must determine the flag ENABLE_PMPI is defined.
availability (or not) of several other libraries. It also has
some code that only allies to x86 microprocessors. The 2. LEGACY BUILD SYSTEM
build system was functional, but required manual
intervention from the user. 2.1 Makefiles
In order to reduce the maintenance burden, increase The GPTL libraries were built with make. A selection of
portability, and support shared library builds, a new different Makefiles were included for different systems
autotools-based build system has been developed. and compilers. To build the code, the user first copies
Each directory in the project gets a Makefile.am file. The clean target works as expected. The distclean
This file specifies what is built in that directory. target does an extra level of cleaning, returning the build
to a state before the configure script was run.
In most cases, Makefile.am files are simple. Here is the
Makefile.am that builds the GPTL C library (including 4 FORTRAN LIBRARY
shared library):
4.1 Configuration
libgptl_la_CPPFLAGS = -I$(top_srcdir)/include
As with the configuration of the C library, necessary
# This is our output. The GPTL library. libraries and headers are found when the user runs the
lib_LTLIBRARIES = libgptl.la
configure script. One such library is the GPTL C library,
# These are the source files.
which must be built and installed before the
libgptl_la_SOURCES = f_wrappers.c \ GPTL-Fortran library is built. This is done in
getoverhead.c gptl.c gptl_papi.c \ configure.ac:
hashstats.c memstats.c memusage.c pmpi.c \ # Find the GPTL C library.
AC_CHECK_LIB([gptl], [GPTLinitialize], [], environment, while still maintaining separate C and
[AC_MSG_ERROR([Can't find or Fortran library repositories.
link to the GPTL C library.])])
We start by cloning the combined distribution project,
As is good practice in configure scripts, error out if and using the following commands to add submodules:
required supporting libraries or tools cannot be found.
git submodule add
4.2 Makefiles [email protected]:jmrosinski/GPTL.git
git submodule add
The automake file to build the Fortran library is in the src [email protected]:NOAA-GSD/GPTL-fortran.git
subdirectory. It is slightly more complex than the one
used to build the C library (src/Makefile.am): This creates directories GPTL and GPTL-fortran, which
contain the contents of the C and Fortran library
libgptlf_la_FCFLAGS = -I$(top_srcdir)/include
if HAVE_PAPI
repositories.
libgptlf_la_FCFLAGS += -DHAVE_PAPI
endif Now the C and the Fortran libraries my be edited and
if HAVE_MPI tested as a unit. A separate git commit is required for
libgptlf_la_FCFLAGS += -DHAVE_MPI each of the three repositories which have been
endif changed. But the developer can make changes in either
# This is our output. The GPTL-fortran library, and then use the combined build to ensure that
# library. both libraries still work, and still work together.
lib_LTLIBRARIES = libgptlf.la
libgptlf_la_SOURCES = gptlf.F90 \ 5.2 Configuration
printmpistatussize.F90 \
process_namelist.F90 The configure.ac file for the combined distribution
# Install these in the include directory. project is small. After initializing autoconf, automake,
include_HEADERS = gptl.mod and libtool, the script launches the C and Fortran library
configuration scripts.
Note the .mod file, which will be installed in the include
directory. An additional option, --enable-package-build, has been
added to the Fortran library builds. Setting this option
The Fortran build does not use the config.h file, but notifies the Fortran library build that this is a combined
fortran 90 does support preprocessor ifdefs, and those library build, so it can find the C library.
are supported by setting macros with the -D option in
FCFLAGS. # Build the GPTL C library.
AC_CONFIG_SUBDIRS([GPTL])
4.2.1 Standard Targets
# Add this arg for the fortran build, to tell
As with the C library, standard targets are supported, # it to use the C library we just built.
ac_configure_args="$ac_configure_args \
including all, check, clean, install, dist, distcheck, and --enable-package-build"
uninstall.
# Build the GPTL Fortran library.
5 COMBINED DISTRIBUTION CONTAINING C AND AC_CONFIG_SUBDIRS([GPTL-fortran])
FORTRAN LIBRARIES
AC_OUTPUT
The original GPTL distribution included both C and
Fortran libraries. We have broken these into separate 5.3 Top-Level Makefile.am
projects.
The Makefile.am file for the combined release launches
However, we would still like to have a combined the build in each of the two subdirectories:
distribution which includes both C and Fortran libraries.
SUBDIRS = GPTL GPTL-fortran
There is an easy way to accomplish this using autoconf.
We start by creating a new, third repo, which will hold This will cause first the C, and then the Fortran GPTL
the configuration files for the combined distribution. libraries to be built.
To accommodate this, the following was added to the 6.2 Additional Features
configure.ac:
The autotools packages provide some build and
AC_ARG_ENABLE([package-build], configure features that were not supported in the
[AS_HELP_STRING([--enable-package-build], previous build system:
[Set internally for package builds, \
should not be used by user.])]) ● Shared library builds.
test "x$enable_package_build" = xyes || \
enable_package_build=no
● Standard make targets dist, distcheck,
AM_CONDITIONAL([BUILD_PACKAGE], [test \
"x$enable_package_build" = xyes]) uninstall.
# Find the GPTL C library, unless this is a ● Standardised help setting specific configure
# combined C/Fortran library build. options with configure --help.
if test $enable_package_build = no; then
AC_CHECK_LIB([gptl], [GPTLinitialize], [],\ 6.3 Reduction in Complexity
[AC_MSG_ERROR([Can't find or link to \
the GPTL C library.])]) Significant reduction in complexity has been achieved.
fi The total number of files required to support the build
has dropped from 30 to 14. The number of lines of code
This adds the --enable-package-build option to the (contents of make and configure files) has been reduced
Fortran build. When used, this option tells the configure by almost an order of magnitude.
and Makefiles that the C library is located as part of the
combined package, rather than already being installed.
build system total files lines of code
7 ACKNOWLEDGMENTS
8 REFERENCES