beautypg.com

Developing libraries, Designing libraries for the cp4000 platform – HP XC System 3.x Software User Manual

Page 43

background image

Examples of Compiling and Linking HP-MPI Applications

The following examples show how to compile and link your application code by invoking a compiler utility.

If you have not already loaded the mpi compiler utilities module , load it now as follows:

$ module load mpi

To compile and link a C application using the mpicc command:

$ mpicc -o mycode hello.c

To compile and link a Fortran application using the mpif90 command:

$ mpif90 -o mycode hello.f

In the above examples, the HP-MPI commands invoke compiler utilities which call the C and Fortran compilers
with appropriate libraries and search paths specified to build the parallel application called hello. The
-o

specifies that the resulting program is called mycode.

Developing Libraries

This section discusses developing shared and archive libraries for HP XC applications. Building a library
generally consists of two phases:

Compiling sources to objects

Assembling the objects into a library

Using the ar archive tool for archive (.a) libraries


Using the linker (possibly indirectly by means of a compiler) for shared (.so) libraries.

For sufficiently small shared objects, it is often possible to combine the two steps.

A common technique is to build the archive library first, and then build the shared library from the archive
library (using the linker's -whole-archive switch).

For libraries that do not use HP-MPI, it is recommended that the sources be compiled with the standard
compilers (such as gcc), just as they would be on other UNIX-like platforms.

For libraries that do use HP-MPI, it is possible to use the HP-MPI compiler utilities (such as mpicc) to compile
the sources to objects. For example:

$ mpicc -c -g foo.c

To assemble an archive library, use the ar archive tool as you would on other UNIX-like platforms. To
assemble a shared library, use the linker (possibly indirectly by means of a compiler) as you would on other
UNIX-like platforms.

Once the library is built, it can be used to build applications, just as other libraries are used, for both serial
applications (with the standard compilers) and parallel applications (with the HP-MPI compiler utilities).

Note that for shared libraries it is necessary to use LD_LIBRARY_PATH to include the directory containing
the shared library, just as you would on other UNIX-like platforms.

Designing Libraries for the CP4000 Platform

This section discusses the issues surrounding the design of libraries for CP4000 platform on the HP XC system.

A user designing a library for use on an HP XC CP4000 platform can supply a 32-bit library and/or a 64-bit
library. HP recommends both, to provide flexibility and to make it easy to get the 64-bit advantages locally,
but be able to take the 32-bit variant to an x86-class machine or run a 32-bit variant imported from an
x86-class machine.

It is the library designer's responsibility to make sure 32-bit and 64-bit object files do not collide during the
build process. This can be done by "cleaning" object files from the directories between builds, or (as is more
common) maintaining separate directories for the different types of objects. Separate directories also makes
it easy to maintain production versions distinct from debuggable versions.

Different compilers have different ways to select 32-bit or 64-bit compilations and links. Consult the
documentation for the compiler for this information.

For released libraries, dynamic and archive, the usual custom is to have a ../lib directory that contains
the libraries. This, by itself, will work if the 32-bit and 64-bit libraries have different names. However, HP

Developing Libraries

43