HP-MPI Version 1.1 for Windows Release Note

HP-MPI V1.1 for Windows Release Note
Building and running applications
34
Building and running applications
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 processs 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);
}
Building and running on a single host
The example teaches you 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:
Step 1. Change to a writable directory, and copy hello_world.c from the help directory:
> copy "%MPI_ROOT%\help\hello_world.c" .
Step 2. Compile the hello_world executable file.
In a proper compiler command window (e.g. Visual Studio command window), use
mpicc to compile your program: