1

Hello everyone i am trying to do matrix transpose but i am complete newbie please help me to complete the matrix transpose: Please suggest me if there is any source on internet for learning about mpi. Should i start parallel programming first? Please solve the below blank code...

#include <stdio.h>
#include <mpi.h>

int main(int argc,char* argv[])
{
int rank,size,m[4];
int matrix[4][4]={
    {1,2,3,4},
    {5,6,7,8},
    {9,10,11,12},
    {13,14,15,16}
}
int transpose[4][4];

MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
MPI_Comm_size(MPI_COMM_WORLD,&size);

if (rank==0)
{
//Store first row of the matrix.
}
if(size!=4)
{
 exit(0);
}
else
{

}

MPI_Finalize();
}
isubhamb
  • 91
  • 1
  • 1
  • 9

2 Answers2

1

Solving matrix transpose with no knowledge in MPI is indeed difficult. If you know the basic concepts, then it is very easy to solve. As a starting point, you can visit the website for MPI lessons.

As a first step, get familiarised with the point to point communication mechanisms and try to use MPI_Send and MPI_Recv to solve some simple tasks as pointed out in comments by High Performance Mark.

Secondly, move on to collective operations like MPI_Scatter, MPI_Gather etc to do the same tasks.

Then you will familiarise with the basic concepts and with this knowledge you can tackle your task.

This solution 1, 2 solves matrix transpose using MPI_Alltoall routine (as mentioned in comment by Gilles Gouaillardet).

j23
  • 3,139
  • 1
  • 6
  • 13
0

You can see the references here: 1. Can you transpose array when sending using MPI_Type_create_subarray? 2. http://suraj.lums.edu.pk/~ahmadh/resources/code/matrixtransp.c 3. https://www.macs.hw.ac.uk/~hwloidl/Courses/F21DP/srcs/matrix4.c

But first I thing you should try with simple examples like parallel some for loop for calculation like sum or multi.

HellboyVN
  • 144
  • 4
  • These examples are unnecessarily convoluted imho. `MPI_Scatter(); MPI_Alltoall(); MPI_Gather()` is a very simple way to perform the transposition (and learn MPI too). – Gilles Gouaillardet Jun 09 '20 at 13:00