1
votes

I'm new to mpi and I'm testing out MPI_Scatterv to use in a different program. My test code for MPI_Scatterv is:

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

int main(int argc,char *argv[])
{

    int a[8]={1,2,3,4,5,6,7,8};
    int rcounts[4]={2,2,2,2};
    int disp[4]={0,2,4,6};
    int b[8]={0,0,0,0,0,0,0,0};
    int procid;
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD,&procid);

    MPI_Scatterv(&a, &rcounts, 0, MPI_INT, &b, 100, MPI_INT, 0, MPI_COMM_WORLD);
    printf("%d",b[0]);
    MPI_Finalize();
    return 0;
}    

I'm getting the following warnings when compiling:

./examples/Scatterv.c: In function ‘main’:
./examples/Scatterv.c:15:2: warning: passing argument 2 of ‘MPI_Scatterv’ from 
incompatible pointer type [enabled by default]
/home/tarek/mpich-install/include/mpi.h:941:5: note: expected ‘const int *’ but 
argument is of type ‘int (*)[4]’

I'm getting the following error when running:

 ./examples/Scatterv.c: In function ‘main’:
 ./examples/Scatterv.c:15:2: warning: passing argument 2 of ‘MPI_Scatterv’ from
  incompatible pointer type [enabled by default]
  /home/tarek/mpich-install/include/mpi.h:941:5: note: expected ‘const int *’ but
  argument is of type ‘int (*)[4]’

Any idea what's the problem?

1

1 Answers

0
votes

You have copied incorrectly the compiler output instead of your run-time error, but I would say that you receive an error that the displacements array is a NULL pointer since you pass 0 as the third argument to MPI_Scatterv while you should be passing disp. Also you have specified the size of b to be 100. This is violation of the MPI standard - the number of basic elements in the recieve part should match the number of basic elements specified in the send part for the particualar rank. The correct call would be:

MPI_Scatterv(a, rcounts, disps, MPI_INT,
             b, rcounts[procid], MPI_INT, 0, MPI_COMM_WORLD);

For your incorrect use of the address-of operator & see the answer of Domi. It is the reason for the compiler warnings but it should not have bad run-time effects.