Sun MPI 4.0 Programming and Reference Guide

Compiling and Linking

Sun MPI programs are compiled with ordinary C, C ++, or Fortran compilers, just like any other C, C ++, or Fortran program, and linked with the Sun MPI library.

The tmf77 and tmcc utilities may be used to compile Fortran 77 and C programs. For example, one might use

% tmf77 -fast -xarch=v8plusa -o a.out a.f -lmpi 

to compile an f77 program that uses Sun MPI.

For performance, the single most important compilation switch is -fast. This is a macro that expands to settings appropriate for high performance for a general set of circumstances. Because its expansion varies from one compiler release to another, you may prefer to specify the underlying switches explicitly. To see what -fast expands to, use -v for "verbose" compilation output. Also, -fast assumes native compilation, so you should compile on UltraSPARC processors.

The next important compilation switch is -xarch. While -fast picks many performance-oriented settings by default, optimizations specific to UltraSPARC must be specified explicitly to override certain binary-compatible defaults. Specify

-xarch=v8plusa

or

-xarch=v9a

after -fast for 32-bit or 64-bit binaries, respectively. To run 64-bit binaries, you must use Solaris 7.

See the documents that came with your compiler for more information.

If you will be using the Prism debugger, you must compile your program with Sun WorkShop(TM) Compilers C/C ++ or Sun WorkShop Compilers Fortran, either v4.2 or v5.0. If the code is threaded, you will not be able to debug with Prism. (See "Debugging ".)

Table 3-1 Compile and Link Line Options for Sun MPI and Sun MPI I/O

When using . . . 

Use . . . 

C (nonthreaded  

example) 

% cc filename.c -o filename \

-I/opt/SUNWhpc/include -L/opt/SUNWhpc/lib \ 

-R/opt/SUNWhpc/lib -lmpi 

C++

Note that x.y represents the version of your C++ compiler.

% CC filename.cc -o filename \

-I/opt/SUNWhpc/include -L/opt/SUNWhpc/lib \ 

-R/opt/SUNWhpc/lib -L/opt/SUNWhpc/lib/SCx.y \

-R/opt/SUNWhpc/lib/SCx.y -mt -lmpi++ -lmpi

tmcc, tmCC

% tmcc -o filename filename.c -lmpi

% tmCC -o filename filename.cc -mt -lmpi

Fortran 77  

(nonthreaded  

example) 

% f77 -dalign filename.f -o filename \

-I/opt/SUNWhpc/include -L/opt/SUNWhpc/lib \  

-R/opt/SUNWhpc/lib -lmpi 

Fortran on a 64-bit system 

% f77 -dalign filename.f -o filename \

-I/opt/SUNWhpc/include/v9 -L/opt/SUNWhpc/lib/sparcv9 \  

-R/opt/SUNWhpc/lib/sparcv9 -lmpi 

Fortran 90 

Replace f77 with f90.

tmf77, tmf90

% tmf77 -o -dalign filename filename.f -lmpi

% tmf90 -o -dalign filename filename.f -lmpi

Multithreaded  

programs and programs containing nonblocking MPI I/O routines 

Replace -lmpi with -lmpi_mt.


Note -

For the Fortran interface, the -dalign option is necessary to avoid the possibility of bus errors. (The underlying C routines in Sun MPI internals assume that parameters and buffer types passed as REALs are double-aligned.)



Note -

If your program has previously been linked to any static libraries, you will have to relink it to libmpi.so before executing it.


Choosing a Library Path

The eight Sun MPI 4.0 libraries are described in "The Libraries". The paths for each of these libraries, which you must specify when you are compiling and linking your program, are listed in the following table.

Table 3-2 Sun MPI 4.0 Libraries

Category 

Description 

Path: /opt/SUNWhpc/lib/...

32-Bit Libraries

Default, not thread-safe 

libmpi.so

C++ (in addition to libmpi.so)

SC4.2/libmpi++.so

 

Thread-safe 

libmpi_mt.so

Trace

Trace, not thread-safe 

tnf/libmpi.so

 

Trace, thread-safe  

tnf/libmpi_mt.so

64-Bit Libraries

Non-thread-safe 

sparcv9/libmpi.so

C++ (in addition to sparcv9/libmpi.so)

SC5.0/libmpi++.so

 

Thread-safe 

sparcv9/libmpi_mt.so

Trace

Trace, not thread-safe 

tnf/sparcv9/libmpi.so

 

Trace, thread-safe 

tnf/sparcv9/libmpi_mt.so

Overriding the Run-Time Library

As shown in the sample compile and link lines in Table 3-1, you use the -R flag in the compile and link line to specify the path for a run-time library when you are compiling. At run time, you can override the library specified in the -R argument by setting the LD_LIBRARY_PATH environment variable. For example, to link to the 32-bit trace libraries before running your program, do this:

% setenv LD_LIBRARY_PATH /opt/SUNWhpc/lib/tnf

(This is a C shell example.)

Stubbing Thread Calls

The libthread.so libraries are automatically linked into the respective libmpi.so libraries. This means that any thread-function calls in your program will be resolved by the libthread.so library. Simply omitting libthread.so from the link line will not cause thread calls to be stubbed out -- you must remove the thread calls yourself. For more information about the libthread.so library, see its man page. (For the location of Solaris man pages at your site, see your system administrator.)