ACENET Summer School - MPI

What's a communicator?

Overview

Teaching: 10 min
Exercises: 0 min
Questions
Objectives

What the code does

program helloworld
use mpi
implicit none
integer :: rank, comsize, ierr

call MPI_Init(ierr)
call MPI_Comm_size(MPI_COMM_WORLD, comsize, ierr)
call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierr)

print *,'Hello World, from task ', rank, 'of', comsize

call MPI_Finalize(ierr)
end program helloworld

Communicators

MPI_COMM_WORLD: size=4, ranks=0..3

MPI_Comm_world: size=4, ranks=0..3

New communicators

program helloworld
use mpi
implicit none
integer :: rank, comsize, ierr

call MPI_Init(ierr)
call MPI_Comm_size(MPI_COMM_WORLD, comsize, ierr)
call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierr)

print *,'Hello World, from task ', rank, 'of', comsize

call MPI_Finalize(ierr)
end program helloworld

Rank and Size much more important in MPI than OpenMP

Rank and Size much

Let’s look at the same program in c:

#include <stdio.h>
#include <mpi.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 task %d of %d\n",rank,  size);

    MPI_Finalize();
    return 0;
}

Key Points