Q-Logic IB6054601-00 D 用户手册
3 – Using InfiniPath MPI
Getting Started with MPI
IB6054601-00 D
3-3
Q
Here
./cpi
designates the executable of the example program in the working
directory. The -np parameter to
mpirun
defines the number of processes to be
used in the parallel computation. Now try it with four processes:
$ mpirun -np 4 -m mpihosts ./cpi
Process 3 on hostname1
Process 0 on hostname2
Process 2 on hostname2
Process 1 on hostname1
pi is approximately 3.1416009869231249,
Error is 0.0000083333333318
wall clock time = 0.000603
If you run the program several times with the same value of the
-np
parameter, you
may get the output lines in different orders. This is because they are issued by
independent asynchronous processes, so their order is non-deterministic.
independent asynchronous processes, so their order is non-deterministic.
The number of processes can be greater than the number of nodes. In this
four-process example, the
four-process example, the
mpihosts
file listed only two hosts, hostname1 and
hostname2. Generally,
mpirun
will try to distribute the specified number of
processes evenly among the nodes listed in the
mpihosts
file, but if the number of
processes exceeds the number of nodes listed in the
mpihosts
file, then some
nodes will be assigned more than one instance of the program.
Up to a limit, the number of processes can even exceed the total number of
processors on the specified set of nodes, although it is usually detrimental to
performance to have more than one node program per processor. This limit is eight
processes per node with the QHT7140, and four processes per node with the
QLE7140. See
processors on the specified set of nodes, although it is usually detrimental to
performance to have more than one node program per processor. This limit is eight
processes per node with the QHT7140, and four processes per node with the
QLE7140. See
for further discussion.
Details on alternate means of specifying the
mpihosts
file are given in
.
Further information on the
mpirun
and
3.3.2
Examples Using Other Languages
This section gives more examples, one for Fortran77, one for Fortran90, and one
for C++. Fortran95 usage will be similar to that for Fortran90.
for C++. Fortran95 usage will be similar to that for Fortran90.
fpi.f
is a Fortran77 program that computes pi in a way similar to
cpi.c
. Compile
and link it with:
$ mpif77 -o fpi3 fpi3.f
and run it with:
$ mpirun -np 2 -m mpihosts ./fpi3
pi3f90.f90
in the same directory is a Fortran90 program that does essentially the
same computation. Compile and link it with:
$ mpif90 -o pi3f90 pi3f90.f90