Logo Cineca Logo SCAI

You are here

Exercise 11

Write a program working only with 2 MPI processes.

For each process, define a square matrix A (nXn). Rank 0 fills the matrix with 0, while rank 1 fills it with 1. Define a datatype that handles a column (if C) or a row (If Fortran) of A.

Extract size and extent of this type: is the result what you expect?

Now begin the communication: rank 0 sends the first column/row of A to rank 1, overwriting its own first column/row. Check the results by printing the matrix on the screen.Modify the code by sending the first nb columns/rows of A: do you have to change the type? Can you send two items of the new type?

 

 

 

 

 

C

MPI_TYPE_VECTOR

int MPI_Type_vector(int count, int blocklength, int stride, MPI_Datatype oldtype, MPI_Datatype *newtype)

MPI_TYPE_COMMIT

int MPI_Type_commit(MPI_Datatype *datatype)

MPI_TYPE_FREE

int MPI_Type_free(MPI_Datatype *datatype)

MPI_TYPE_SIZE

int MPI_Type_size(MPI_Datatype *datatype, int *size)

MPI_TYPE_GET_EXTENT

int MPI_Type_get_extent(MPI_Datatype *datatype, MPI_Aint *lb, MPI_Aint *extent)

MPI_SEND

int MPI_Send(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)

MPI_RECV

int MPI_Recv(void* buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status)

MPI_INIT

int MPI_Init(int *argc, char ***argv)

MPI_COMM_SIZE

int MPI_Comm_size(MPI_Comm comm, int *size)

MPI_COMM_RANK

int MPI_Comm_rank(MPI_Comm comm, int *rank)

MPI_FINALIZE

int MPI_Finalize(void)

 


FORTRAN

MPI_TYPE_VECTOR

MPI_TYPE_VECTOR(COUNT, BLOCKLENGTH, STRIDE, OLDTYPE, NEWTYPE, IERROR)
INTEGER COUNT, BLOCKLENGTH, STRIDE, OLDTYPE, NEWTYPE, IERROR

MPI_TYPE_COMMIT

MPI_TYPE_COMMIT(DATATYPE, IERROR)
INTEGER DATATYPE, IERROR

MPI_TYPE_FREE

MPI_TYPE_FREE(DATATYPE, IERROR)
INTEGER DATATYPE, IERROR

MPI_TYPE_SIZE

MPI_TYPE_SIZE(DATATYPE, SIZE, IERROR)
INTEGER DATATYPE, SIZE, IERROR

MPI_TYPE_GET_EXTENT

MPI_TYPE_GET_EXTENT(DATATYPE, LB, EXTENT, IERROR)
INTEGER DATATYPE, IERROR
INTEGER (KIND=MPI_ADDRESS_KIND) LB, EXTENT

MPI_SEND

MPI_SEND(BUF, COUNT, DATATYPE, DEST, TAG, COMM, IERROR)
<type> BUF(*)
INTEGER COUNT, DATATYPE, DEST, TAG, COMM, IERROR

MPI_RECV

MPI_RECV(BUF, COUNT, DATATYPE, SOURCE, TAG, COMM, STATUS, IERROR)
<type> BUF(*)
INTEGER COUNT, DATATYPE, SOURCE, TAG, COMM, STATUS(MPI_STATUS_SIZE), IERROR

MPI_INIT

MPI_INIT(IERROR)
INTEGER IERROR

MPI_COMM_SIZE

MPI_COMM_SIZE(COMM, SIZE, IERROR)
INTEGER COMM, SIZE, IERROR

MPI_COMM_RANK

MPI_COMM_RANK(COMM, RANK, IERROR)
INTEGER COMM, RANK, IERROR

MPI_FINALIZE

MPI_FINALIZE(IERROR)
INTEGER IERROR