Paramotopy
parallel parameter homotopy through bertini
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
step2readandwrite.cpp
Go to the documentation of this file.
1 #include "step2readandwrite.hpp"
2 
3 
4 
5 
6 
7 
8 
9 
10 int GetStart(boost::filesystem::path dir,
11  std::string & start,
12  std::string startfilename){
13 
14 
15  std::stringstream tempss;
16 
17  std::ifstream fin;
18  //get start file in memory
19  std::string copyme;
20 
21  boost::filesystem::path startstring=dir;
22  startstring /= "step1";
23  startstring /= startfilename;
24  fin.open(startstring.c_str());
25 
26  if (!fin.is_open()) {
27  std::cout << "failed to open specified solutions file: " << startstring <<"\n";
28  exit(721);
29  }
30 
31  getline(fin,copyme);
32  std::stringstream converter;
33  tempss << copyme << "\n";
34  converter << copyme;
35  int numsolutions;
36  converter >> numsolutions;
37 
38  while (!fin.eof()) {
39  getline(fin,copyme);
40  tempss << copyme << "\n";
41  }
42  fin.close();
43  //end get start in memory
44  start = tempss.str();
45 
46  return numsolutions;
47 }
48 
49 
50 
51 
52 
53 
54 int GetLastNumSent(std::string base_dir,
55  std::vector< int > & lastnumsent,
56  int numprocs){
57 
58  std::ifstream fin;
59  std::string blank;
60  std::stringstream commandss;
61  // query whether had run or not yet.
62  std::string lastoutfilename0 = base_dir;
63  lastoutfilename0.append("/step2/lastnumsent0");
64  fin.open(lastoutfilename0.c_str());
65  std::vector< int > lastnumsent0;
66  lastnumsent0.push_back(0);
67  int tmpint, smallest = 0;
68  if (fin.is_open()){
69  int lastoutcounter=1;
70  for (int ii=1; ii<numprocs; ++ii) {
71  getline(fin,blank);
72  if (blank=="") {
73  break;
74  }
75  commandss << blank;
76  commandss >> tmpint;
77  lastnumsent0.push_back(tmpint);
78  lastoutcounter++;
79  commandss.clear();
80  commandss.str("");
81  }
82 
83  }
84  fin.close();
85 
86 
87  std::string lastoutfilename1 = base_dir;
88  lastoutfilename1.append("/step2/lastnumsent1");
89  fin.open(lastoutfilename1.c_str());
90  std::vector< int > lastnumsent1;
91  lastnumsent1.push_back(0);
92  if (fin.is_open()){
93  int lastoutcounter=1;
94  for (int ii=1; ii<numprocs; ++ii) {
95  getline(fin,blank);
96  if (blank=="") {
97  break;
98  }
99  commandss << blank;
100  commandss >> tmpint;
101  lastnumsent1.push_back(tmpint);
102  lastoutcounter++;
103  commandss.clear();
104  commandss.str("");
105  }
106 
107  }
108  fin.close();
109 
110 
111  int vectortosave = -1;
112  if ( (int(lastnumsent1.size())<numprocs) && int(lastnumsent0.size())<numprocs ) {//failed overall...suck.
113  return 0;
114  //both vectors fail. initialize fresh run.
115  }
116  else if (int(lastnumsent0.size())<numprocs){//failed during writing of 0?
117  vectortosave = 1;
118  }
119  else if (int(lastnumsent1.size())<numprocs){//failed during writing of 1?
120  vectortosave = 0;
121  }
122  else {//not possible for exactly one of the two following things to happen, given the previous 3 failed
123  for (int ii=1; ii<numprocs; ++ii) {
124  if (lastnumsent0[ii]<lastnumsent1[ii]) {
125  vectortosave = 1;
126  break;
127  }
128  else if (lastnumsent1[ii]<lastnumsent0[ii]){
129  vectortosave = 0;
130  break;
131  }
132  }
133  }
134 
135  //not possible for them to be the same. vectortosave==(-1) if neither size matched. fresh run if -1
136  lastnumsent.push_back(0);
137  if (vectortosave==0) {
138  smallest = lastnumsent0[0];
139  for (int ii=1; ii<numprocs; ++ii) {
140  lastnumsent.push_back(lastnumsent0[ii]);
141  if (lastnumsent0[ii] < smallest) {
142  smallest = lastnumsent0[ii];
143  }
144  }
145 
146  }
147  else if (vectortosave==1){
148  smallest = lastnumsent1[0];
149  for (int ii=1; ii<numprocs; ++ii) {
150  lastnumsent.push_back(lastnumsent1[ii]);
151  if (lastnumsent1[ii] < smallest) {
152  smallest = lastnumsent1[ii];
153  }
154  }
155 
156  }
157  return smallest;
158 }
159 
160 
161 
162 
163 
164 
165 
166 
167 int GetMcNumLines(boost::filesystem::path base_dir, int numparam){
168  boost::filesystem::path mcfname = base_dir;
169  mcfname /= "mc";
170 
171  std::ifstream fin(mcfname.c_str());
172 
173  if (!fin.is_open()){
174  std::cerr << "failed to open mc file to get line count" << std::endl;
175  exit(2132);
176  }
177 
178  std::string tmpstr;
179  std::getline(fin,tmpstr);
180  std::stringstream converter;
181  int terminationint;
182  converter << tmpstr;
183  converter >> terminationint;
184  fin.close();
185 
186 
187  return terminationint;
188 
189 }
190 
191 
192 
int GetLastNumSent(std::string base_dir, std::vector< int > &lastnumsent, int numprocs)
int GetMcNumLines(boost::filesystem::path base_dir, int numparam)
int GetStart(boost::filesystem::path dir, std::string &start, std::string startfilename)