I'm very new to using MPI; I seem to be struggling to get a basic understanding of the MPI::Comm_World.Scatter Operation, It seem's as though a may be misunderstanding how the scatter operation works. Suppose i have an Array of x amount of doubles, let's say 3 doubles that i want to spread across three processes.

I have -

#include <iostream>

#include <mpi.h>

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

{

MPI_Init(&argc, &argv);

int rank, procs;

MPI_Comm_size(MPI_COMM_WORLD, &procs);

MPI_Comm_rank(MPI_COMM_WORLD, &rank);

double stat[3] ;

stat[0] = 1.2;

stat[1] = 65.3;

stat[2] = 45.3;

double test3[3];

if (rank==0) {

MPI::COMM_WORLD.Scatter(

stat,

1,

MPI::DOUBLE,

&test3,

1,

MPI::DOUBLE,

0);

}

std::cout << rank <<" rec'd " << test3[0] << std::endl;

MPI_Finalize();

}

Unfortunately, this doesn't output what i'd like. I'd like: Process 0 to output 1.2, process 1 to output 65.3 and process 2 to output 45.3 etc etc. I apologise if this question is very trivial.

Regards,

Win John Lewis vouchers with BigSnapSearch.com Search now