Line data Source code
1 : #include "WriteMetaData.H"
2 : #include <sstream>
3 : #include <functional>
4 : #include "Util/Util.H"
5 :
6 : /// \todo We need to update ParmParse so that the FORMATTED input file gets recorded permanently.
7 :
8 : namespace IO
9 : {
10 :
11 : // GLOBAL VARIABLES
12 : unsigned long hash = 0;
13 : std::chrono::time_point<std::chrono::system_clock> starttime_cr;
14 : std::time_t starttime = 0;
15 : int percent = -1;
16 :
17 533 : void WriteMetaData(std::string plot_file, Status status, int per)
18 : {
19 533 : if (amrex::ParallelDescriptor::IOProcessor())
20 : {
21 533 : amrex::ParmParse pp;
22 :
23 533 : std::chrono::time_point<std::chrono::system_clock> now_cr = std::chrono::system_clock::now();
24 533 : std::time_t now = std::chrono::system_clock::to_time_t(now_cr);
25 :
26 533 : if (!starttime)
27 : {
28 69 : starttime_cr = now_cr;
29 69 : starttime = now;
30 : }
31 :
32 533 : if (!hash)
33 : {
34 69 : std::stringstream ss;
35 69 : pp.dumpTable(ss);
36 69 : std::string dumptable = ss.str();
37 69 : hash = std::hash<std::string>{}(dumptable + std::ctime(&starttime));
38 69 : }
39 :
40 533 : if (per > percent) percent = per;
41 :
42 533 : std::ofstream metadatafile;
43 533 : metadatafile.open(plot_file+"/metadata",std::ios_base::out);
44 533 : metadatafile << "# COMPILATION DETAILS" << std::endl;
45 533 : metadatafile << "# ===================" << std::endl;
46 533 : metadatafile << "Git_commit_hash = " << METADATA_GITHASH << std::endl;
47 533 : metadatafile << "AMReX_version = " << amrex::Version() << std::endl;
48 533 : metadatafile << "Dimension = " << AMREX_SPACEDIM << std::endl;
49 533 : metadatafile << "User = " << METADATA_USER << std::endl;
50 533 : metadatafile << "Platform = " << METADATA_PLATFORM << std::endl;
51 533 : metadatafile << "Compiler = " << METADATA_COMPILER << std::endl;
52 533 : metadatafile << "Compilation_Date = " << METADATA_DATE << std::endl;
53 533 : metadatafile << "Compilation_Time = " << METADATA_TIME << std::endl;
54 533 : metadatafile << std::endl;
55 :
56 533 : metadatafile << "# PARAMETERS" << std::endl;
57 533 : metadatafile << "# ==========" << std::endl;
58 :
59 533 : pp.dumpTable(metadatafile,true);
60 :
61 533 : metadatafile << "# RUN DETAILS" << std::endl;
62 533 : metadatafile << "# ===========" << std::endl;
63 533 : metadatafile << "HASH = " << hash << std::endl;
64 : {
65 : char buffer [80];
66 533 : std::strftime(buffer,80,"%Y-%m-%d %H:%M:%S",std::localtime(&starttime));
67 533 : std::string timefmt(buffer);
68 533 : metadatafile << "Simulation_start_time = " << timefmt << std::endl;
69 533 : }
70 533 : metadatafile << "Number_of_processors = " << amrex::ParallelDescriptor::NProcs() << std::endl;
71 533 : if (status == Status::Running) metadatafile << "Status = Running";
72 100 : else if (status == Status::Complete) metadatafile << "Status = Complete";
73 36 : else if (status == Status::Abort) metadatafile << "Status = Abort";
74 36 : else if (status == Status::Segfault) metadatafile << "Status = Segfault";
75 36 : else if (status == Status::Interrupt) metadatafile << "Status = Interrupt";
76 :
77 533 : if (percent>0) metadatafile << " (" << percent << "%)";
78 533 : metadatafile << std::endl;
79 :
80 533 : if (status != Status::Running)
81 : {
82 : char buffer[80];
83 100 : std::strftime(buffer,80,"%Y-%m-%d %H:%M:%S",std::localtime(&now));
84 100 : std::string timefmt(buffer);
85 100 : metadatafile << "Simulation_end_time = " << timefmt << std::endl;
86 100 : }
87 :
88 533 : auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now_cr - starttime_cr);
89 533 : metadatafile << "Simulation_run_time = " << (float)milliseconds.count()/1000.0 << " " << std::endl;
90 :
91 : #ifdef GIT_DIFF_OUTPUT
92 : {
93 : std::ifstream src(GIT_DIFF_OUTPUT,std::ios::binary);
94 : std::ofstream dst(plot_file+"/diff.html",std::ios::binary);
95 : dst << src.rdbuf();
96 : src.close();
97 : dst.close();
98 : }
99 : #endif
100 : {
101 533 : std::ifstream src(GIT_DIFF_PATCH_OUTPUT,std::ios::binary);
102 533 : if (src.is_open())
103 : {
104 533 : std::ofstream dst(plot_file+"/diff.patch",std::ios::binary);
105 533 : dst << src.rdbuf();
106 533 : src.close();
107 533 : dst.close();
108 533 : }
109 : else
110 : {
111 0 : Util::Warning(INFO,"Could not open ",GIT_DIFF_PATCH_OUTPUT);
112 : }
113 :
114 533 : }
115 :
116 533 : metadatafile.close();
117 533 : }
118 533 : }
119 :
120 : }
|