I am trying to do some MPI parallel work. I am able to run this on any number of processors. The issue is that each processor will take one job, execute it and send it back then the program is done. I want to be able to send a processor another job when it has finished. Im not sure how to implement this. Basically I am trying to send each core 10 jobs.
if (myRank == 0) {
int numCores = MPI::COMM_WORLD.Get_size();
for (int rank = 1; rank < numCores; rank++) {
MPI::COMM_WORLD.Send(&yarray[0], imax, MPI::DOUBLE, rank, 0);
MPI::COMM_WORLD.Send(&tarray[0], imax, MPI::DOUBLE, rank, 0);
MPI::COMM_WORLD.Recv(&ans, imax, MPI::DOUBLE, MPI::ANY_SOURCE, MPI_ANY_TAG, mystatus);
answers[counter] = ans;
counter++;
}
}
else
{
MPI::COMM_WORLD.Recv(&yarray1, imax, MPI::DOUBLE, MPI::ANY_SOURCE, MPI_ANY_TAG, mystatus);
MPI::COMM_WORLD.Recv(&tarray1, imax, MPI::DOUBLE, MPI::ANY_SOURCE, MPI_ANY_TAG, mystatus);
double floor = 0.5, ceiling = 3.5, range = (ceiling - floor);
double rnd = floor + double((range * rand()) / (RAND_MAX + 1.0));
yarray [0] = rnd;
yarray1 [0] = rnd;
double temp = 0;
for (int k = 0; k < imax; k++) {
tarray1[k+1] = tarray1[k] + h;
yarray1[k+1] = yarray1[k] + h * (2 * yarray1[k] - 2 * tarray1[k] * tarray1[k] - 3);
}
temp = yarray1[int(imax)];
//cout << "Rank = " << myRank << " Solution = " << temp << endl;
MPI::COMM_WORLD.Send(&temp, 1, MPI::DOUBLE, 0, 0);
}
Update: within in myrank == 0
while(counter != jobs){
MPI::COMM_WORLD.Recv(&ans, imax, MPI::DOUBLE, MPI::ANY_SOURCE, MPI_ANY_TAG, mystatus);
answers[counter] = ans;
counter++;
}