how to use MPI_Scatterv() properly
Asked Answered
C

1

2

I am having a problem using MPI_Scatterv in a parallel program. Here is how it is defined :

int MPI_Scatterv(const void *sendbuf, const int *sendcounts,
    const int *displs, MPI_Datatype sendtype, void *recvbuf,
    int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)

The way I understood it , the difference between MPI_Scatterv and MPI_Scatter is the fact that in MPI_Scatterv segments do not have to be of the same length and they don't have to be continuous (gaps in memory are allowed). The part I do not understand is if the recvbuf can be an array of different size for each process then what should be used for recvcount. Let's say I want to send 5 elements of sendbuf to process 0 and 15 to process 1. What should the value of recvcount be?

Catechol answered 29/3, 2015 at 12:57 Comment(0)
E
7

Each process has to call MPI_Scatterv with the right recvcount. You can pass a variable whose value depends on the rank of each process.

For example:

int recvcount = (rank == 0) ? 5 : 15;

MPI_Scatterv( sendbuf, sendcounts, displs, sendtype,
              recvbuf, recvcount, recvtype, 0, MPI_COMM_WORLD );

Process with rank 0 calls MPI_Scatterv with a recvcount of 5 whereas process 1 passes a count of 15.

Edgardoedge answered 29/3, 2015 at 13:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.