#include <iostream.h>
#include <mpi.h>
int main(int argc, char *argv[]) {
int i;
int nitems=10;
int mynode, totalnodes;
MPI_Status status;
double *array;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &totalnodes);
MPI_Comm_rank(MPI_COMM_WORLD, &mynode);
array = new double[nitems];
if(mynode==0){
for(i=0; i<nitems; i++){
array[i] = (double) i;
}
}
if(mynode==0)
for(i=1; i<totalnodes; i++){
MPI_Send(array, nitems, MPI_DOUBLE, i, 1, MPI_COMM_WORLD);
}
}
else{
MPI_Recv(array, nitems, MPI_DOUBLE, 0, 1, MPI_COMM_WORLD, &status)
}
for(i=0; i<nitems; i++){
cout << "Processor" << mynode;
cout << ": array[" << i << "] = " << array[i] << endl;
}
MPI_Finalize();
}
I2luY2x1ZGUgPGlvc3RyZWFtLmg+CiNpbmNsdWRlIDxtcGkuaD4KCmludCBtYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pIHsKCWludCBpOwoJaW50IG5pdGVtcz0xMDsKCWludCBteW5vZGUsIHRvdGFsbm9kZXM7CglNUElfU3RhdHVzIHN0YXR1czsKCWRvdWJsZSAqYXJyYXk7CgkKCU1QSV9Jbml0KCZhcmdjLCAmYXJndik7CglNUElfQ29tbV9zaXplKE1QSV9DT01NX1dPUkxELCAmdG90YWxub2Rlcyk7CglNUElfQ29tbV9yYW5rKE1QSV9DT01NX1dPUkxELCAmbXlub2RlKTsKCQoJYXJyYXkgPSBuZXcgZG91YmxlW25pdGVtc107CgkKCWlmKG15bm9kZT09MCl7CgkJZm9yKGk9MDsgaTxuaXRlbXM7IGkrKyl7CgkJCWFycmF5W2ldID0gKGRvdWJsZSkgaTsKCQkKCQl9Cgl9CgkKCWlmKG15bm9kZT09MCkKCQoJCWZvcihpPTE7IGk8dG90YWxub2RlczsgaSsrKXsKCQkJTVBJX1NlbmQoYXJyYXksIG5pdGVtcywgTVBJX0RPVUJMRSwgaSwgMSwgTVBJX0NPTU1fV09STEQpOwoJCQkKCQl9Cgl9CgllbHNlewoJCU1QSV9SZWN2KGFycmF5LCBuaXRlbXMsIE1QSV9ET1VCTEUsIDAsIDEsIE1QSV9DT01NX1dPUkxELCAmc3RhdHVzKQoJfQoJCglmb3IoaT0wOyBpPG5pdGVtczsgaSsrKXsKCQljb3V0IDw8ICJQcm9jZXNzb3IiIDw8IG15bm9kZTsKCQljb3V0IDw8ICI6IGFycmF5WyIgPDwgaSA8PCAiXSA9ICIgPDwgYXJyYXlbaV0gPDwgZW5kbDsKCX0KCQoJTVBJX0ZpbmFsaXplKCk7Cn0KCg==