Dockerfile for run MPI programs
-
Create the image:
- docker build -t="mpi" .
-
Run the image:
- docker run --name mpi -itd mpi
-
Start the container:
- docker exec -it mpi bash
-
Write your code:
- Example: mpi_hello.c:
/* C Example */ #include <mpi.h> #include <stdio.h> int main (int argc, char* argv[]) { int rank, size; MPI_Init (&argc, &argv); /* starts MPI */ MPI_Comm_rank (MPI_COMM_WORLD, &rank); /* get current process id */ MPI_Comm_size (MPI_COMM_WORLD, &size); /* get number of processes */ printf( "Hello world from process %d of %d\n", rank, size ); MPI_Finalize(); return 0; } ``
- Example: mpi_hello.c:
-
Compile:
- mpicc mpi_hello.c -o hello
-
Run:
- mpirun -np 2 ./hello
- Output of example:
Hello world from process 0 of 2 Hello world from process 1 of 2 ``