A. Install OpenMPI
$ sudo apt-get install libopenmpi-dev openmpi-bin openmpi-doc
$ sudo apt-get install ssh
B. Configure SSH
$ ssh-keygen -t dsa
$ cd ~/.ssh
$ cat id_dsa.pub >> authorized_keys
C. MPI Program Example
Filename:
MPI_Hello.c
#include <stdio.h>
#include <mpi.h>
int main(int argc, char** argv) {
int myrank, nprocs;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
printf("Hello from processor %d of %d\n", myrank, nprocs);
MPI_Finalize();
return 0;
}
D. Compilation
$ mpicc MPI_Hello.c -o MPI_Hello
E. Execution
$ mpiexec -n 5 MPI_Hello
F. Integrated Development Environment
We will use
Geany as an
IDE to make compilation process easier and faster. To compile MPI program with
Geany, follow these steps:
- Install Geany.
$ sudo apt-get install geany
- Download MPI tags file and copy to
~/.config/geany/tags/
$ wget http://auriza.site40.net/docs/paralel/openmpi.c.tags
$ cp openmpi.c.tags ~/.config/geany/tags/
- Start Geany, and write MPI program example above.
- Compilation setting: Build - Set Includes
and Arguments.
Compile:
mpicc -Wall "%f" -o "%e"
Execute:
mpiexec -n 5 "%e"
- To compile program: click Compile.
- To execute program: click Execute.