Skip to content

Instantly share code, notes, and snippets.

@wwoods
Created February 5, 2014 20:49
Show Gist options
  • Save wwoods/8832751 to your computer and use it in GitHub Desktop.
Save wwoods/8832751 to your computer and use it in GitHub Desktop.
boost::mpi::environment env(argc, argv);
boost::mpi::communicator world;
if (world.rank() == 0) {
std::ofstream ofile;
ofile.open("overtraining_20k.txt");
int workers = world.size() - 1;
int pending = 0;
for(int sets = 10000; sets <= 20000; sets+=10)
{
int dest = pending + 1;
if (pending >= workers) {
//Wait for any worker to finish, they'll be our next destination
std::string result;
boost::mpi::status s = world.recv(boost::mpi::any_source, 0, result);
pending -= 1;
ofile << result << std::endl;
//Give this worker more work now that they're done
dest = s.source();
}
world.send(dest, 0, sets);
pending += 1;
}
while (pending > 0) {
std::string result;
world.recv(boost::mpi::any_source, 0, result);
pending -= 1;
ofile << result << std::endl;
}
//Notify all workers we're done so they can exit cleanly
for (int i = 0; i < workers; i++) {
world.send(i + 1, 0, -1);
}
ofile.close();
}
else {
while (true) {
int sets;
world.recv(0, 0, sets);
if (sets < 0) {
//Exit message
break;
}
double mean = 0;
for(int i=0; i<10; i++)
mean = sallsa_mnist(100, sets, false);
mean /= (double)10.0;
std::ostringstream lineOut;
lineOut << sets << "," << mean;
world.send(0, 0, lineOut.str());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment