-
Snir, M. (1998). MPI - the complete reference. Cambridge (Mass.): The MIT Press.
-
Delorme, M. (2018). Coding Games and Programming Challenges to Code Better. Retrieved August 12, 2021, from https://www.codingame.com/playgrounds/349/introduction-to-mpi/introduction-to-distributed-computing
-
https://en.wikipedia.org/w/index.php?title=Message_Passing_Interface&oldid=1035542225
-
The Cornell University Center for Advanced Computing. (2015, April). Virtual workshop. Cornell Virtual Workshop: History and Evolution. Retrieved August 15, 2021, from https://cvw.cac.cornell.edu/mpi/history
-
MPI Forum. (2021, June). MPI Documents. Retrieved August 12, 2021, from https://www.mpi-forum.org/docs/
-
https://rantahar.github.io/introduction-to-mpi/aio/index.html
-
https://curc.readthedocs.io/en/latest/programming/MPI-C.html
-
https://rantahar.github.io/introduction-to-mpi/01-introduction/index.html
-
https://wgropp.cs.illinois.edu/courses/cs598-s16/lectures/lecture32.pdf
Some code examples to get started.
- C++
#include <iostream>
#include <mpi.h>
int main(int argc, char** argv) {
// Initialisation
MPI_Init(&argc, &argv);
// Reading size and rank
int size, rank;
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
// Printing
std::cout << "Hello world, from process #" << rank << std::endl;
// Finalisation
MPI_Finalize();
return 0;
}
- C Programming Language
#include <mpi.h>
#include <stdio.h>
int main(int argc, char** argv) {
// Initialize the MPI environment
MPI_Init(NULL, NULL);
// Get the number of processes
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
// Get the rank of the process
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
// Get the name of the processor
char processor_name[MPI_MAX_PROCESSOR_NAME];
int name_len;
MPI_Get_processor_name(processor_name, &name_len);
// Print off a hello world message
printf("Hello world from processor %s, rank %d out of %d processors\n",
processor_name, world_rank, world_size);
// Finalize the MPI environment.
MPI_Finalize();
}
Install MPI
sudo apt install mpich
Now you've written a basic MPI program. You can compile using
C++
Combining compilation and linking in a single command
mpicxx -o foo foo.cpp
mpicxx -o <executable file name> <source file name>.cpp
C
Combining compilation and linking in a single command
mpicc -o foo foo.c
mpicc -o <executable file name> <source file name>.c
To run the executable
mpirun -np <processors to use> ./<executable file name>