Repository navigation
Expand file tree
/
Copy pathread_exit_file.cpp
More file actions
111 lines (100 loc) · 4.08 KB
/
Copy pathread_exit_file.cpp
File metadata and controls
111 lines (100 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "read_exit_file.h"
#include <fstream>
#include <iostream>
#include <sstream>
#ifdef __MPI
#include <mpi.h>
#endif
namespace ModuleIO
{
int read_exit_file(const int& my_rank, const std::string& filename, std::ofstream& ofs_running)
{
auto str2bool = [](std::string str) {
for (auto& i: str)
{
i = tolower(i);
}
if (str == "true" || str == "t" || str == "1")
{
return true;
}
else
{
return false;
}
};
int stop = 0;
if (my_rank == 0)
{
std::ifstream ifs(filename.c_str(), std::ios::in);
if (ifs)
{
ifs.clear();
ifs.seekg(0);
ifs.rdstate();
while (ifs.good())
{
std::string line;
std::getline(ifs, line);
if (line.empty())
{
continue;
}
std::istringstream iss(line);
std::string word, result;
iss >> word;
if (iss.eof())
{
continue;
}
else
{
iss >> result;
}
if (word == "stop_ion" && str2bool(result) && stop < 1)
{
stop = 1;
}
else if (word == "stop_elec" && str2bool(result) && stop < 2)
{
stop = 2;
}
}
}
}
#ifdef __MPI
MPI_Bcast(&stop, 1, MPI_INT, 0, MPI_COMM_WORLD);
#endif
if (stop == 1)
{
std::cout << "\n\n--------------------------------------------------------------------" << std::endl;
std::cout << "--------------------------------------------------------------------" << std::endl;
std::cout << " Read in stop_ion = true from " << filename << std::endl;
std::cout << " The current execution stops at the ionic step " << std::endl;
std::cout << "--------------------------------------------------------------------" << std::endl;
std::cout << "--------------------------------------------------------------------\n" << std::endl;
ofs_running << "\n\n--------------------------------------------------------------------" << std::endl;
ofs_running << "--------------------------------------------------------------------" << std::endl;
ofs_running << " Read in stop_ion = true from " << filename << std::endl;
ofs_running << " The current execution stops at the ionic step " << std::endl;
ofs_running << "--------------------------------------------------------------------" << std::endl;
ofs_running << "--------------------------------------------------------------------\n" << std::endl;
}
else if (stop == 2)
{
std::cout << "\n\n--------------------------------------------------------------------" << std::endl;
std::cout << "--------------------------------------------------------------------" << std::endl;
std::cout << " Read in stop_elec = true from " << filename << std::endl;
std::cout << " The current execution stops at the electronic step " << std::endl;
std::cout << "--------------------------------------------------------------------" << std::endl;
std::cout << "--------------------------------------------------------------------\n" << std::endl;
ofs_running << "\n\n--------------------------------------------------------------------" << std::endl;
ofs_running << "--------------------------------------------------------------------" << std::endl;
ofs_running << " Read in stop_elec = true from " << filename << std::endl;
ofs_running << " The current execution stops at the electronic step " << std::endl;
ofs_running << "--------------------------------------------------------------------" << std::endl;
ofs_running << "--------------------------------------------------------------------\n" << std::endl;
}
return stop;
}
} // namespace ModuleIO