26/6/14

OpenMPI on Ubuntu

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
[MPI program compilation and execution on terminal]

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:
  1. Install Geany.
    $ sudo apt-get install geany
  2. 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/
  3. Start Geany, and write MPI program example above.
  4. Compilation setting: Build - Set Includes and Arguments.
    Compile:
    mpicc -Wall "%f" -o "%e"
    Execute:
    mpiexec -n 5 "%e"
    [Geany 'Set Includes and Arguments' dialog window]
  5. To compile program: click Compile.
  6. To execute program: click Execute.

Bài đăng phổ biến