#include<stdio.h>
#include<mpi.h>
#include<math.h>
int main(int argc, char* argv[])
{
int rank,size;
int x;
double power;
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
MPI_Comm_size(MPI_COMM_WORLD,&size);
if(rank == 0){
printf("Please enter the value for x \n"); fflush(stdout
);//To Ensure prompt is printed before waiting for the input //done so that only one thread takes the unput
}
//now broadcast the input to all the processes
MPI_Bcast(&x, 1, MPI_INT, 0 , MPI_COMM_WORLD);
//this is to broadcast so x is the variable, 1 is the one value, MPI int is the datatype and 0 is the rank to broadcast from
printf("the power for the process with rank %d to %d is %f \n",rank
,x
,power
); MPI_Finalize();
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8bXBpLmg+CiNpbmNsdWRlPG1hdGguaD4KaW50IG1haW4oaW50IGFyZ2MsIGNoYXIqIGFyZ3ZbXSkKewogICAgICAgIGludCByYW5rLHNpemU7CiAgICAgICAgaW50IHg7CiAgICAgICAgZG91YmxlIHBvd2VyOwogICAgICAgIE1QSV9Jbml0KCZhcmdjLCZhcmd2KTsKICAgICAgICBNUElfQ29tbV9yYW5rKE1QSV9DT01NX1dPUkxELCZyYW5rKTsKICAgICAgICBNUElfQ29tbV9zaXplKE1QSV9DT01NX1dPUkxELCZzaXplKTsKICAgICAgICBpZihyYW5rID09IDApewogICAgICAgICAgICAgICAgcHJpbnRmKCJQbGVhc2UgZW50ZXIgdGhlIHZhbHVlIGZvciB4IFxuIik7CiAgICAgICAgICAgICAgICBmZmx1c2goc3Rkb3V0KTsvL1RvIEVuc3VyZSBwcm9tcHQgaXMgcHJpbnRlZCBiZWZvcmUgd2FpdGluZyBmb3IgdGhlIGlucHV0CiAgICAgICAgICAgICAgICBzY2FuZigiJWQiLCAmeCk7CiAgICAgICAgICAgICAgICAvL2RvbmUgc28gdGhhdCBvbmx5IG9uZSB0aHJlYWQgdGFrZXMgdGhlIHVucHV0CiAgICAgICAgfQogICAgICAgIC8vbm93IGJyb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