HP-MPI Version 2.0 for Windows Release Note
9 Compiling and Running Applications
This section provides instructions for building, compiling, and running applications.
9.1 Compiling and Running Your First Application
To quickly become familiar with compiling and running HP-MPI programs, start with the C
version of the hello_world program. This program is called hello_world.c and prints out the
text string "Hello world! I’m r of s on host" where r is a process’s rank, s is the size of the
communicator, and host is the host on which the program is run. The processor name is the
host name for this implementation. HP-MPI returns the hostname for
MPI_Get_processor_name. The source code for hello_world.c is stored in %MPI_ROOT%\
help and is shown below.
#include <stdio.h>
#include "mpi.h"
void main(argc, argv)
int argc;
char *argv[];
{
int rank, size, len;
char name[MPI_MAX_PROCESSOR_NAME];
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Get_processor_name(name, &len);
printf("Hello world!I'm %d of %d on %s\n", rank, size, name);
MPI_Finalize();
exit(0);
}
9.2 Building and Running on a Single Host
The following example describes the basic compilation and run steps to execute hello_world.c
on your local host with 4-way parallelism. To build and run hello_world.c on a local host
named banach1:
1. Change to a writable directory, and copy hello_world.c from the help directory:
C:\> copy "%MPI_ROOT%\help\hello_world.c" .
2. Compile the hello_world executable file.
In a proper compiler command window (for example, Visual Studio command window),
use mpicc to compile your program:
C:\> "%MPI_ROOT%\bin\mpicc" -mpi64 hello_world.c
NOTE: Specify the bitness using -mpi64 or -mpi32 for mpicc to link in the correct
libraries. Verify you are in the correct 'bitness' compiler window. Using -mpi64 in a Visual
Studio 32-bit command window does not work.
3. Run the hello_world executable file:
C:\> "%MPI_ROOT%\bin\mpirun" -np 4 hello_world.exe
where -np 4 specifies 4 as the number of processors to run.
4. Analyze hello_world output.
HP-MPI prints the output from running the hello_world executable in non-deterministic
order. The following is an example of the output:
9.1 Compiling and Running Your First Application 39