Repository navigation
Week 04 (January 29)
-
Using a pool of workers in Python
- Notebook Demonstration of four modes (blocking and non=blocking) os initiating jobs on a pool of workers.
-
Introduction to MPI
- (demo1) Demonstrate basic MPI routine.
- In class question about
argcandargv. These should be used to get arguments of the executable. See code to see how to include compiler switches.
The version of MPI installed on the virtual machine is MPICH.
-
Write your C program using Nano or some other editor. You may be able to use your local editor to edit remotely stored files. For example, Sublime Text allows remote editing.
-
Compile using the
mpicccommand$ mpicc -o mpi_demo1 demo1.c demo_util.c -
To run the executable, use
mpirun:$ mpirun -n 4 mpi_demo1
That's it!
If you'd like to time the results, you can use
$ time mpirun -n 4 mpi_demo1
There are several implementations of the MPI Standard. These include MPICH, and OpenMPI (not be confused with OpenMP). Hardware vendors also make available their own versions, e.g. Intel MPI.
Most Linux distributions have package utitilies for installing MPI. For example, yum on RedHat Linux, might look like :
$ sudo yum install mpich
On Ubuntu, a typical installation will look like :
$ sudo apt-get install mpich
On OSX, you can use either Home-brew of MacPorts. You can read about installing using MacPorts here.
Analogous commands can be used to install OpenMPI.
You can check your installation by making sure you have mpicc and mpirun (or mpiexec).
$ which mpicc
$ which mpirun
You can also check the version you have using
$ mpicc --version
$ mpirun --version
These two commands are basically scripts (or wrappers) which hides many of the details of compiling and running MPI programs. Here is a very simple MPI program you can cut and paste into an editor and compile :
#include <stdio.h>
#include <mpi.h>
void main(int argc, char** argv)
{
int my_rank;
MPI_Init(&argc, &argv);
/* Some MPI calls here */
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
printf("Hello, World from processor %d\n",my_rank);
MPI_Finalize();
}
Compile this file with the line :
$ mpicc -o mpi_demo0 mpi_demo0.c
This will compile the C program mpi_demo0.c and link to create the executable mpi_demo0, which you can run from a command line. There is usually no need to include paths to libraries and include files.
Run it on four processors with the line
$ mpirun -n 4 mpi_demo0
-
MPI_SendandMPI_Recv. Synchronous message passing -
MPI_Reduce
@DonnaCalhoun Introduction to Parallel Computing (ME471/571, BSU)