in my program i I use 4 process that fills an array of size i + 1 by the i values, but when I display the RECEIVED table after using the Gatherv function ca not give me the right result: [0][1][-858993460][2][2][-858993460][3][3][3][-858993460]
#include "mpi.h"
#include <stdio.h>
int main(int argc, char *argv[])
{
int buffer[10];
int rank, size, i,receive_counts[4] = { 1, 2, 3,4 },receive_displacements[4] = { 0, 1, 3, 6 };
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (size != 4)
{
if (rank == 0)
{
printf("Please run with 4 processes\n"); fflush(stdout);
}
MPI_Finalize();
return 0;
}
for (i = 0; i<=rank; i++)
{
buffer[i] = rank;
}
printf("\n");
MPI_Gatherv(buffer, rank, MPI_INT, buffer, receive_counts, receive_displacements, MPI_INT, 0, MPI_COMM_WORLD);
if (rank == 0)
{
for (i = 0; i<10; i++)
{
printf("[%d]", buffer[i]);
}
printf("\n");
fflush(stdout);
}
MPI_Finalize();
return 0;
}