See all lecture notes here.
mpirun, passing in the MPI arguments before your program's arguments.
int MPI_init(int *argc, char ***argv)MPI_init to initialize MPI. After this call, argc and argv will be modified to be the same as if you had called your program normally in serial. MPI_init returns MPI_SUCCESS on success, otherwise it will return an error code.
int MPI_finalize(void)MPI_finalize to finalize MPI. This will free up any resources that MPI is using. MPI_finalize returns MPI_SUCCESS on success, otherwise it will return an error code. Note that no MPI calls are allowed after this, including MPI_init.
MPI_init and MPI_finalize, otherwise there will be undefined behavior.
MPI_Comm type variables called communicators store info about communication domains. The default communicator is MPI_COMM_WORLD, which includes all processes.
int MPI_Comm_size(MPI_Comm comm, int *size)comm by reference in size.
int MPI_Comm_rank(MPI_Comm comm, int *rank)comm by reference in rank. The rank is a unique integer in the range [0, size) for each communicator.
#include "mpi.h"
#include <stdio.h>
int main(int argc, char *argv[])
{
int rank, size;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
printf("Hello world from process %d of %d\n", rank, size);
MPI_Finalize();
return 0;
}
MPI_Wtime function. This function returns the number of seconds since some arbitrary point in the past as a double. This function is guaranteed to be monotonic, so it can be used to measure elapsed time.
| MPI Type | C Type |
|---|---|
| MPI_CHAR | signed char |
| MPI_SHORT | short |
| MPI_INT | int |
| MPI_LONG | long |
| MPI_UNSIGNED_CHAR | unsigned char |
| MPI_UNSIGNED_SHORT | unsigned short |
| MPI_UNSIGNED | unsigned int |
| MPI_UNSIGNED_LONG | unsigned long |
| MPI_FLOAT | float |
| MPI_DOUBLE | double |
| MPI_BYTE | N/A |
| MPI_PACKED | N/A |