Biomedical Engineering Reference
In-Depth Information
1: #include <stdio.h>
2: #include <mpi.h>
3:
4: char *msg = "May everyone be happy. May everyone be h$$
5:
6: int main(int argc, char *argv[])
7: {
8: int size, rank;
9:
10: MPI_Init(&argc, &argv);
11: MPI_Comm_size(MPI_COMM_WORLD, &size);
12: MPI_Comm_rank(MPI_COMM_WORLD, &rank);
13:
14: printf("Hello World. There are %d MPI processes. \
15: My rank is %d. My message is: %s\n", size, rank, msg);
16:
17: MPI_Finalize();
18: return 0;
19: }
$ mpirun -partition wR0 -exe mpi-hello.rts -np 4000
Hello World. There are 4000 MPI processes. My rank is 3794. My
message is: May everyone be .... May everyone Hello World. Th
ere are 4000 MPI processes. My rank is 3538. My message is:...
Figure 5.8 An MPI version of a ''hello world'' program and excerpts of its output.
are created and executed as different MPI processes on different processors. The
number of MPI processes in a job and the details of the parallel system where
these processes will be executed are not specified in the MPI program. Instead,
these are specified at the time the job is created. The number of processes in the
job is usually referred to as the job size. When a job starts executing, all its MPI
processes start executing simultaneously in parallel. In the example, all the MPI
processes created for the job will make a call to MPI Init .
The function MPI Comm size may be used in a program to determine the
number of MPI processes running as a part of the current MPI job. Line 11 of
mpi-hello.c contains a call to this function. MPI Comm size takes two arguments.
The first argument is the communicator, which is set to a predefined default MPI
communicator called MPI COMM WORLD . MPI commuincators are discussed later
in Section 5.4.2. The second argument is a pointer to the integer where the job
size is to be returned.
Each MPI process in an MPI job is identified by a unique number called its
rank . The rank of an MPI process in a job varies from zero to one less than the
number of processes in the job. The function MPI Comm rank is used by an MPI
process to determine its rank. The first argument to this function is the commu-
nicator, which is set to the default MPI communicator called MPI COMM WORLD .
The second argument is a pointer to the integer where the rank is to be returned.
Search WWH ::




Custom Search