Skip to content

Instantly share code, notes, and snippets.

@kohnakagawa
Created April 22, 2016 00:57
Show Gist options
  • Save kohnakagawa/ee047133308dc45bf6123b902b1ee2ba to your computer and use it in GitHub Desktop.
Save kohnakagawa/ee047133308dc45bf6123b902b1ee2ba to your computer and use it in GitHub Desktop.
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <mpi.h>
int main(int argc, char* argv[]) {
MPI_Init(&argc, &argv);
if (argc < 2) {
std::cerr << "# of arguments should be >= 2.\n";
std::cerr << "argv[1] == script name.\n";
std::cerr << "argv[l] (l >= 2) are target directory names.\n";
std::exit(1);
}
int my_rank = -1;
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
std::stringstream ss;
ss << "bash " << argv[1] << " " << my_rank; // $ bash script.bash rank
for (int i = 2; i < argc; i++) ss << " " << argv[i];
system(ss.str().c_str()); // $ bash lstress_multi.bash rank dir0 dir1 dir2 ...
MPI_Barrier(MPI_COMM_WORLD);
MPI_Finalize();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment