Logo Cineca Logo SCAI

You are here

Exercise 15

 

Write a program that performs the transpose of a square matrix A of arbitrary dimension (multiple of the number of tasks).

The matrix is split among the tasks and initialized so that each element is unique (use row-column number and task rank). 

Thus you need to evaluate B of the form:

B = AT

 

Follows a visual representation of the matrices A and B (8x8 in the example):

 








Solve the problem distributing A and B by lines (or columns) over the tasks and using the collective communication MPI_ALLTOALL. Please note that this collective function works with data stored contiguously in memory, therefore choose carefully whether to store the matrix by lines or or columns. Can you tell why? (answer)  

 

We ask you to:

  • initialize A
  • evaluate B = AT
  • check if the operation was successful

HINTS:


 

C

MPI_ALLTOALL

int MPI_Alltoall(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)

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)

MPI_WTIME

double MPI_Wtime(void)

MPI_ABORT

int MPI_Abort (MPI_Comm comm)

 


FORTRAN

MPI_ALLTOALL

MPI_ALLTOALL(SENDBUF, SENDCOUNT, SENDTYPE, RECVBUF, RECVCOUNT, RECVTYPE, COMM, IERROR)
<type> SENDBUF(*), RECVBUF(*)
INTEGER SENDCOUNT, SENDTYPE, RECVCOUNT, RECVTYPE, COMM, 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

MPI_WTIME

MPI_WTIME()

MPI_ABORT

MPI_ABORT(COMM, ERRCODE, IERROR)
INTEGER COMM, ERRCODE, IERROR