HavoqGT
transfer_graph.cpp
Go to the documentation of this file.
1 #include <time.h> /* time_t, struct tm, difftime, time, mktime */
2 #include <fstream> // std::ifstream
3 #include <sstream> // std::stringstream
4 #include <iostream> // std::cout, std::ios
5 #include <havoqgt/mpi.hpp>
6 
7 #include <sys/mman.h>
8 
9 const bool verbose = false;
10 
11 const int processes_per_node = 24;
12 const int node_partions = 8;
13 
14 void execute_command(int backup, std::string fname_input,
15  std::string fname_output);
16 
17 int main(int argc, char** argv) {
18  int mpi_rank(0), mpi_size(0);
19  CHK_MPI(MPI_Init(&argc, &argv));
20  CHK_MPI( MPI_Comm_rank( MPI_COMM_WORLD, &mpi_rank) );
21  CHK_MPI( MPI_Comm_size( MPI_COMM_WORLD, &mpi_size) );
22 
23  int backup;
24  std::string fname_input;
25  std::string fname_output;
26 
27  int pos = 1;
28  if (argc == 3) {
29  fname_input = argv[pos++];
30  fname_output = argv[pos++];
31 
32  } else {
33  if (mpi_rank == 0) {
34  std::cout << "Parameter Error: <input_file> <output_file>" << std::endl;
35  }
36  return -1;
37  }
38 
39  if (mpi_rank == 0) {
40  std::cout << "Restoring File:";
41  std::cout << "Source = '" << fname_input.c_str() << std::endl;
42  std::cout << "Dest = '" << fname_output.c_str() << std::endl;
43  }
44 
45  fname_input += "_" + std::to_string(mpi_rank);
46  {
47  std::ifstream fin(fname_input);
48  bool is_good = fin.good();
49  fin.close();
50  if (!is_good) {
51  std::cout << "[" << mpi_rank << "] File not found: " << fname_input
52  << "." << std::endl;
53  return -1;
54  }
55  }
56 
57  bool hit = false;
58  for (int i = 0; i < node_partions; i++) {
59  if (mpi_rank == 0) {
60  const int lower_bound = (i)*(processes_per_node/node_partions);
61  const int upper_bound = (i+1)*(processes_per_node/node_partions)-1;
62 
63  std::cout << "***(" << i << "/" << node_partions << ") Processes: "
64  << lower_bound << " - " << upper_bound
65  << " executing on each node." << std::endl;
66  }
67  if ((mpi_rank % processes_per_node) % node_partions == i){
68  if (hit) {
69  std::cout << "[" << mpi_rank
70  << "] error: attempting to backup/restor twice." << std::endl;
71  exit(-1);
72  } else {
73  hit = true;
74  if (verbose)
75  std::cout << "[" << mpi_rank << "]";
76  execute_command(backup, fname_input, fname_output);
77  }
78 
79  }
80  MPI_Barrier(MPI_COMM_WORLD);
81  }
82 
83  MPI_Barrier(MPI_COMM_WORLD);
84  if (mpi_rank == 0)
85  std::cout << "Transfer Graph Fin." << std::endl;
86  MPI_Finalize();
87  return 0;
88 
89 };
90 
91 void execute_command(int backup, std::string fname_input,
92  std::string fname_output) {
93 
94  std::string tar_str;
95  if (verbose)
96  std::cout << "Restoring File:";
97 
98  tar_str = "cp " + fname_input + " " + fname_output;
99 
100  if (verbose)
101  std::cout << "Source = '" << fname_input.c_str() << "' "
102  << "Destination = '" << fname_output.c_str() << "'" << std::endl
103  << "Command = '" << tar_str.c_str() << "'" << std::endl;
104 
105  system(tar_str.c_str());
106  std::cout << std::flush;
107 
108 }; // execute_command;
void execute_command(int backup, std::string fname_input, std::string fname_output)
const int node_partions
int main(int argc, char **argv)
const int processes_per_node
#define CHK_MPI(a)
Definition: mpi.hpp:68
const bool verbose