parallelism. For information about running more complex applications, refer to the HP-MPI user documentation.

8.3.2.1 Example Application hello_world

To quickly become familiar with compiling and running HP-MPI programs, start with the C version of a familiar 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”. In this text string:

r is the rank of the process

s is the size of the communicator

host is the host on which the program is run

The processor name is the host name for this implementation.

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);

}

8.3.2.2 Building and Running hello_world

To build and run hello_world.c on a local host, named penguin2 in this example, perform the following steps:

1.Change to a writable directory.

2.Compile the hello_world executable file:

$ $MPI_ROOT/bin/mpicc -o hello_world $MPI_ROOT/help/hello_world.c

If /opt/hpmpi/bin is in the PATH, as it should be, this command can be simplified to the following:

$ mpicc -o hello_world $MPI_ROOT/help/hello_world.c

3.Run the hello_world executable file:

$ $MPI_ROOT/bin/mpirun -srun -n4 hello_world

If /opt/hpmpi/bin is in the PATH, this command can be simplified to the following:

$ mpirun -srun -n4 hello_world

In this command, -n4specifies that the number of processes to run is four, and the allocated nodes from SLURM are to be used.

4.Analyze hello_world output.

HP-MPI prints the output from running the hello_world executable in nondeterministic order. The following is an example of the output:

Using HP-MPI 8-3

Page 113
Image 113
HP XC System 2.x Software Example Application helloworld, Building and Running helloworld, $ mpirun -srun -n4 helloworld