#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();
}
CiNpbmNsdWRlIDxpb3N0cmVhbS5oPgojaW5jbHVkZSA8bXBpLmg+CgppbnQgbWFpbihpbnQgYXJnYywgY2hhciAqYXJndltdKSB7CglpbnQgaTsKCWludCBuaXRlbXM9MTA7CglpbnQgbXlub2RlLCB0b3RhbG5vZGVzOwoJTVBJX1N0YXR1cyBzdGF0dXM7Cglkb3VibGUgKmFycmF5OwoJCglNUElfSW5pdCgmYXJnYywgJmFyZ3YpOwoJTVBJX0NvbW1fc2l6ZShNUElfQ09NTV9XT1JMRCwgJnRvdGFsbm9kZXMpOwoJTVBJX0NvbW1fcmFuayhNUElfQ09NTV9XT1JMRCwgJm15bm9kZSk7CgkKCWFycmF5ID0gbmV3IGRvdWJsZVtuaXRlbXNdOwoJCglpZihteW5vZGU9PTApewoJCWZvcihpPTA7IGk8bml0ZW1zOyBpKyspewoJCQlhcnJheVtpXSA9IChkb3VibGUpIGk7CgkJCgl9Cgl9CgkKCWlmKG15bm9kZT09MCkKCQoJZm9yKGk9MTsgaTx0b3RhbG5vZGVzOyBpKyspewoJCU1QSV9TZW5kKGFycmF5LCBuaXRlbXMsIE1QSV9ET1VCTEUsIGksIDEsIE1QSV9DT01NX1dPUkxEKTsKCQoJfQoJfQoJZWxzZXsKCQlNUElfUmVjdihhcnJheSwgbml0ZW1zLCBNUElfRE9VQkxFLCAwLCAxLCBNUElfQ09NTV9XT1JMRCwgJnN0YXR1cykKCX0KCQoJZm9yKGk9MDsgaTxuaXRlbXM7IGkrKyl7CgkJY291dCA8PCAiUHJvY2Vzc29yIiA8PCBteW5vZGU7CgkJY291dCA8PCAiOiBhcnJheVsiIDw8IGkgPDwgIl0gPSAiIDw8IGFycmF5W2ldIDw8IGVuZGw7Cgl9Ck1QSV9GaW5hbGl6ZSgpOwp9