2

So I am working on a simple matrix multiplication code using MPI. One of the problems I am facing is in scattering one of the matrices to all the processors. I am assuming that the dimension of my matrix might not be divisible by the number of processors.

Also I have used a variable col_id which calculates the number of columns alloted to each processor by using the mod function. For example if we have 9 columns and 6 processors, the first 3 processors will have a col_id value of 2 while other three processors will have a col_id value of 1.

So I used a basic scattering operation.

call MPI_Scatter(b, dim2*col_id, MPI_Integer, b1, dim2*col_id, MPI_Integer, 0, MPI_COMM_WORLD, ierr)

col_id will be different for different processors. Are we allowed to use this variable to specify dimensions in MPI_scatter?

Utsav Jain
  • 21
  • 3
  • Welcome to SO. Please consider adding the programming language you are using to the tags to enable syntax highlighting. It might also help to show us more of your code, especially how you compute `col_id`. – m00am Mar 09 '16 at 06:24
  • I am using FORTRAN 90 and col_id is just computed by using mod function. For example if we have 9 columns and 6 processors, the first 3 processors will have a col_id value of 2 while other three processors will have a col_id value of 1. – Utsav Jain Mar 09 '16 at 06:27
  • Thanks. I took the liberty of adding this to the post. Be sure to always add the programming language to your questions tag list (the list of items in the edit field below the question text). These are how questions can be filtered. Now a FORTRAN expert (which I certainly am not) can find the question using the filter system. – m00am Mar 09 '16 at 07:49
  • 1
    @m00am Not really, most subscribe to the fortran tag, only a small number to fortran90. Use versions only for a detailed specification when applicable. It is the same as [tag:python] vs [tag:python-3]. – Vladimir F Героям слава Mar 09 '16 at 09:24
  • @Vladimir F Thank you for the correction. I was not aware of that, but taking a better look at the tags would certainly have show me. – m00am Mar 09 '16 at 10:19

1 Answers1

3

The function MPI_Scatterv is made for exactly that purpose. Instead of a sendcount you specify sendcounts - an integer array of the size of the communicator.

Zulan
  • 21,896
  • 6
  • 49
  • 109