C H A P T E R 3 |
Getting Started |
This chapter explains how to develop, compile and link, execute, and debug a Sun MPI program. The chapter focuses on what is specific to the Sun MPI implementation and, for the most part, does not repeat information that can be found in related documents. Information about programming with the Sun MPI I/O routines is in Chapter 4.
Include syntax must be placed at the top of any program that calls Sun MPI routines.
These lines enable the program to access the Sun MPI version of the mpi header file, which contains the definitions, macros, and function prototypes required when compiling the program. Ensure that you are referencing the Sun MPI include file.
The include files are usually found in /opt/SUNWhpc/include/ or /opt/SUNWhpc/include/v9/. If the compiler cannot find them, verify that they exist and are accessible from the machine on which you are compiling your code. The location of the include file is specified by a compiler option (see Compiling and Linking).
Two simple Sun MPI programs are available in /opt/SUNWhpc/examples/mpi and are included here in their entirety. In the same directory you will find the Readme file, which provides instructions for using the examples, and the make file Makefile.
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 mpf77, mpf90, mpcc, and mpCC utilities can be used to compile Fortran 77, Fortran 90, C, and C++ programs, respectively. For example, you might use the following entry to compile a Fortran 77 program that uses Sun MPI:
% mpf77 -fast -xarch=v8plusa -o a.out a.f -lmpi |
See the man pages for more information on these utilities.
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 might prefer to specify the underlying switches. To see what -fast expands to, use -v for "verbose" compilation output in Fortran, and -# for C. Also, -fast assumes native compilation, so you should compile on UltraSPARC processors.
The next important compilation switch is -xarch. Sun ONE Studio 7 Compiler Collection compilers set -xarch by default when you select -fast for native compilations. If you plan to compile on one type of processor and run the program on another type (nonnative compilation), be sure to use the -xarch flag. Also use it to compile in 64-bit mode. For UltraSPARC II processors, specify:
-xarch=v8plusa
-xarch=v9a
after -fast for 32-bit or 64-bit binaries, respectively. This version is only supported on Solaris 8 software. For UltraSPARC III processors, specify:
-xarch=v8plusb
-xarch=v9b
The v8plusb and v9b flags apply only to running on UltraSPARC III processors, and do not work when running on UltraSparc II processors. For more information, see the Sun HPC ClusterTools Software Performance Guide and the documents that came with your compiler.
Sun MPI programs compiled using the Sun ONE Studio 7 Compiler Collection Fortran compiler should be compiled with -xalias=actual. The
-xalias=actual workaround requires patch 111718-01 (which requires 111714-01).
This recommendation arises because the MPI Fortran binding is inconsistent with the Fortran 90 standard in several respects. Specifically, this is documented in the MPI 2 standard, which you can find on the World Wide Web:
http://www-unix.mcs.anl.gov/mpi/mpi-standard/mpi-report-2.0/node19.htm#Node19
This recommendation applies to the use of high levels of compiler optimization. A highly optimizing Fortran compiler could break MPI codes that use nonblocking operations.
The failure modes are varied and insidious and include the following:
If you will be using the Prism debugger, you must compile your program with compilers from the Forte 6 update 2, or Sun ONE Studio 7 (formerly Forte Development 7 software) Compiler Collections (see Debugging).
Note - If your program has previously been linked to any static libraries, you must relink it to libmpi.so before executing it. |
The paths for the MPI libraries, which you must specify when you are compiling and linking your program, are listed in TABLE 3-2.
The libthread.so libraries are automatically linked into the respective libmpi.so libraries. This means that any thread-function calls in your program can be resolved by the libthread.so library. Simply omitting libthread.so from the link line does 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.)
If you plan to extract MPI profiling information from the execution of a job, you need to set the MPI_PROFILE environment variable to 1 before you start the job execution.
% setenv MPI_PROFILE 1 |
If you want to set any other mpprof environment variables, you must set them also before starting the job. See Appendix B for detailed descriptions of the mpprof environment variables.
The CRE environment provides close integration with batch-processing systems, also known as resource managers. You can launch parallel jobs from a batch system to control resource allocation, and continue to use the CRE environment to monitor job status. For a list of currently supported resource managers, see TABLE 3-3.
To enable the integration between the CRE environment and the supported resource managers, you must call mprun from a script in the resource manager. Use the -x flag to specify the resource manager, and the -np and -nr flags to specify the resources you need. Instructions and examples for each resource manager are provided in the Sun HPC ClusterTools Software User's Guide.
Before starting your job, you might want to set one or more environment variables, which are also described in Appendix B and in the Sun HPC ClusterTools Software Performance Guide.
When using CRE software, parallel jobs are launched using the mprun command. For example, to start a job with six processes named mpijob, use this command:
% mprun -np 6 mpijob |
Parallel jobs can be either launched by the LSF Parallel Application Manager (PAM) or submitted in queues configured to run PAM as the parallel job starter. LSF's bsub command launches both parallel interactive and batch jobs. For example, to start a batch job named mpijob on four CPUs, use this command:
% bsub -n 4 pam mpijob |
To launch an interactive job, add the -I argument to the command line. For example, to launch an interactive job named earth on a single CPU in the queue named sun, which is configured to launch jobs with PAM, use this command:
% bsub -q sun -Ip -n 1 earth |
Debugging parallel programs is notoriously difficult, because you are in effect debugging a program potentially made up of many distinct programs executing simultaneously. Even if the application is an SPMD (single-program, multiple-data) application, each instance can be executing a different line of code at any instant. The Prism development environment eases the debugging process considerably and is recommended for debugging with Sun HPC ClusterTools software.
This section provides a brief introduction to the Prism development environment.
You can use a Prism session to debug more than one Sun MPI job at a time. To debug a child or client program it is necessary to launch an additional Prism session. If the child program is spawned using calls to MPI_Comm_spawn() or MPI_Comm_spawn_multiple(), Prism can (if enabled) debug the child program as well.
However, if an MPI job connects to another job, the current Prism session has control only of the parent or server MPI job. It cannot debug the children or clients of that job. This might occur, for example, when an MPI job sets up a client/server connection to another MPI job with MPI_Comm_accept or MPI_Comm_connect.
With the exception of programs using calls to MPI_Comm_spawn() or MPI_Comm_spawn_multiple(), to use the Prism environment to debug a Sun MPI program the program must be written in the SPMD style. In other words, all processes that make up a Sun MPI program must be running the same executable.
MPI_Comm_spawn_multiple can create multiple executables with only one job ID. Therefore, you can use the Prism environment to debug jobs with various executables that have been spawned with this command.
To start Prism with a Sun MPI program, launch it from within the mprun command.
% mprun -np 4 -x lsf prism -np 4 foo |
launches Prism on executable foo with four processes.
This starts up a graphical version of Prism with your program loaded. You can then debug and visualize data in your Sun MPI program.
You can also attach Prism to running processes. First determine the job ID (not the individual process ID), jobname (or jid), using mpps. (See the Sun HPC ClusterTools Software User`s Guide for further information about mpps.) Then specify the jid at the command line:
% prism foo 12345 |
This launches Prism and attaches it to the processes running in job 12345.
One important feature of the Prism environment is that it enables you to debug the Sun MPI program at any level of detail. You can look at the program as a whole, or you can look at subsets of processes within the program (for example, those that have an error condition) or at individual processes, all within the same debugging session. For complete information, see the Prism Software User's Guide.
TotalView is a third-party multiprocess debugger from Etnus that runs on many platforms. Support for using the TotalView debugger on Sun MPI applications includes:
The following sections provide a brief description of how to use the TotalView debugger with Sun MPI applications, including:
Refer to your TotalView documentation for more information about using TotalView.
For more information, refer to the following related documentation:
You can start a new job from the Total View Graphical User Interface (GUI) using:
% totalview mprun [totalview args] -a [mprun args] |
% totalview mprun -bg blue -a -np 4 /opt/SUNWhpc/mpi/conn.x |
2. When the GUI appears, type g for go, or click Go in the TotalView window.
TotalView may display a dialog box:
Process mprun is a parallel job. Do you want to stop the job now? |
3. Click Yes to open the TotalView debugger window with the Sun MPI source window, if compiled with option -g, and to leave all processes in a traced state.
% totalview |
2. Select the menu option File and then New Program.
3. Type mprun as the executable name in the dialog box.
TotalView displays the main debug window.
5. Select the menu option Process and then Startup Parameters, which are the mprun args.
% totalviewcli mprun [totalview args] -a [mprun args] |
% totalviewcli mprun -a -np 4 /opt/SUNWhpc/mpi/conn.x |
2. When the job starts, type dgo.
TotalView displays this message:
Process mprun is a parallel job. Do you want to stop the job now? |
3. Type y to start the MPI job, attach TotalView, and leave all processes in a traced state.
This section describes how to attach to an already running mprun job from both the TotalView GUI and CLI.
1. Find the host name and process identifier (PID) of the mprun job by typing:
% mpps -b |
mprun displays the PID and host name in a similar manner to this example:
JOBNAME MPRUN_PID MPRUN_HOST cre.99 12345 hpc-u2-9 cre.100 12601 hpc-u2-8 |
For more information, refer to the mpps(1M) man page, option -b.
2. In the TotalView GUI, select File and then New Program.
3. Type the PID in Process ID.
4. Type mprun in the field Executable Name.
1. Find the process identifier (PID) of the launched job.
See the example under the preceding GUI procedure. For more information, refer to the mpps(1M) man page, option -b.
2. Start totalviewcli by typing:
% totalviewcli |
3. Attach the executable program to the mprun PID:
% dattach mprun mprun_pid |
% dattach mprun 12601 |
This section describes how to launch Sun MPI batch jobs, including:
This section provides examples of launching batch jobs in Sun Grid Engine (SGE). Refer to Chapter 5 of the Sun HPC ClusterTools Software User's Guide for descriptions of launching batch jobs in the Load Sharing Facility (LSF) and the Portable Batch System (PBS).
Executing startup in batch mode for the TotalView CLI is not practical, because there is no controlling terminal for input and output. This procedure describes executing startup in batch mode for the TotalView GUI:
1. Write a batch script, which contains a line similar to the following:
% totalview mprun -a -x SGE /opt/SUNWhpc/mpi/conn.x |
2. Then submit the script to SGE for execution with a command similar to the following:
% qsub -l crfe 4 batch_script |
The TotalView GUI appears upon successful allocation of resources and execution of the batch script in SGE.
The interactive mode creates an xterm window for your use, so you can use either the TotalView GUI or the CLI.
1. Submit an interactive mode job to SGE with a command similar to the following:
% qsh -l cre 4 |
The system displays an xterm window.
2. Run the following, or an equivalent path, to source the SGE environment:
% source /opt/sge/default/common/settings.csh |
3. Execute a typical totalview or totalviewcli command.
% totalview mprun -a -x SGE /opt/SUNWhpc/mpi/conn.x |
% totalviewcli mprun -a -x SGE /opt/SUNWhpc/mpi/conn.x |
The multiprocessing environment (MPE) available from Argonne National Laboratory includes a debugger that can also be used for debugging at the thread level. For information about obtaining and building MPE, see MPE: Extensions to the Library.
Copyright © 2002, Sun Microsystems, Inc. All rights reserved.