Index
HPC - Universidad de Sevilla

MPI Essentials

MPI initialization
------------------------    C    -------------------------
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&np);
MPI_Comm_rank(MPI_COMM_WORLD,&myid);

------------------------ Fortran -------------------------
call MPI_INIT(ierror)
call MPI_COMM_SIZE(MPI_COMM_WORLD, np, ierror)
call MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierror)
MPI finalize
------------------------    C    -------------------------
MPI_Finalize();

------------------------ Fortran -------------------------
call MPI_FINALIZE(ierror)
Barrier
------------------------    C    -------------------------
MPI_Barrier(MPI_COMM_WORLD);

------------------------ Fortran -------------------------
call MPI_BARRIER(MPI_COMM_WORLD, ierror)
Runtime environment
------------------------    C    -------------------------
secs = MPI_Wtime();

------------------------ Fortran -------------------------
secs = MPI_Wtime()
Send data
------------------------    C    -------------------------
MPI_Send(buffer,nmax, MPI_INT, np_to, 0, MPI_COMM_WORLD);

------------------------ Fortran -------------------------
call MPI_SEND(BUF, NMAX, MPI_INT, NP_TO, 0, MPI_COMM_WORLD, IERROR)
Receive data
------------------------    C    -------------------------
MPI_Recv(buffer,nmax, MPI_INT, np_from, 0, MPI_COMM_WORLD,&status);

------------------------ Fortran -------------------------
call MPI_RECV(BUF, NMAX, MPI_INT, NP_FROM, 0, MPI_COMM_WORLD, IERROR)
Reduce
------------------------    C    -------------------------
MPI_Reduce(sum,res,1,MPI_DOUBLE,MPI_SUM, root,MPI_COMM_WORLD);

------------------------ Fortran -------------------------
soon available :)
Cartesian topologies
------------------------    C    -------------------------
// create cartesian grid
for (n=0;n<3;n++) {         // no periodicity
  periods[n]=0;
}
dims[0]=NDIVX;
dims[1]=NDIVY;
dims[2]=NDIVZ;
MPI_Cart_create(MPI_COMM_WORLD,3,dims,periods,1,&comm_cart);

// get my own coordinates in topology
MPI_Cart_coords(comm_cart,myid,3,mycoords);

// shift right (1) in first dimension (0)
me=myid;
MPI_Cart_shift(comm_cart,0,1,&me,&other);
// shift left (1) in second dimension (1)
me=myid;
MPI_Cart_shift(comm_cart,1,-1,&me,&other);


------------------------ Fortran -------------------------
soon available :)
Define own data types

Example:

vector_example

------------------------    C    -------------------------
// create vector type with stride
MPI_Type_vector(NY-2,NZ-2,NZ,MPI_DOUBLE,&cutx);
MPI_Type_commit(&cutx);

------------------------ Fortran -------------------------
soon available :)