// Michael Chen, 11.1.2007 // Wind velocity problem #include #include #include "mpi.h" //defines important variables const double theta = 45; const double v0 = 134.11200; const double rf= 0.0034; const double dt = 0.01; const double pi = 3.1415926; const double g = 9.80665; double ax; double ay; int main(int argc, char* argv[]) { int rank,size; MPI_Status status; int k,tag=0; double y; //initializes MPI MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&size); MPI_Comm_rank(MPI_COMM_WORLD,&rank); double angle; double maxangle=90.0; double wvel; double wmax=50.0; int flag=0; //args is the array passed from master-slave and vice-versa double args[3]; if(rank==0) // parent process { k=1; //k is the processor the parent process passes to flag=1; //values from angle 0 to 50 and wind velocity from -50 to 50 for(angle=0.0;angle<=maxangle;angle+=0.5) for (wvel=-50.0;wvel<=wmax;wvel+=0.1) { //if all child processes are busy, wait to receive info if (flag>=size) { MPI_Recv(args,3,MPI_DOUBLE,k,tag,MPI_COMM_WORLD,&status); printf("receiving! endx:%3.2f\n", args[2]); flag--; } //after receiving, send info to the same process args[0]=wvel; args[1]=angle; args[2]=1337.0; MPI_Send(args,3,MPI_DOUBLE,k,tag,MPI_COMM_WORLD); //move to the next process and go around the for loop k++; flag++; if (k>=size) k=1; //making sure not to exceed number of computers available printf("sending! angle:%3.2f,wvel:%3.2f\n",angle,wvel); } //this section of code makes sure that all values have been received int recall=0; int ori=k-1; if (ori<1) ori=size; //printf("here?\n"); while (recall==0) { if (size==2) { MPI_Recv(args,3,MPI_DOUBLE,k,tag,MPI_COMM_WORLD,&status); printf("%3.2f\n",args[2]); break; } MPI_Recv(args,3,MPI_DOUBLE,k,tag,MPI_COMM_WORLD,&status); printf("%3.2f\n",args[2]); k++; if (k>=size) k=1; if (k==ori) recall=1; } //this portion of code ends all child processes args[0]=0.0; args[1]=0.0; args[2]=666.0; int n; for (n=1;n=0) //as long as the projectile has height { //recalculates acceleration and accounts for it ax = (vx-vw)*(vx-vw)*rf; //acceleration of wind depends on direction of wind //with respect to the direction of the projectile if (vw0.0) ay=-g-rf*vy*vy; else ay=-g+rf*vy*vy; vx+=(ax*dt); vy+=(ay*dt); px+=vx; py+=vy; } //sets value as the ending location of projectile and sends it args[2]=px; MPI_Send(args,3,MPI_DOUBLE,0,tag,MPI_COMM_WORLD); } } //finishes MPI MPI_Finalize(); return 0; }