Alamo
WriteMetaData.cpp
Go to the documentation of this file.
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
8namespace IO
9{
10
11// GLOBAL VARIABLES
12unsigned long hash = 0;
13std::chrono::time_point<std::chrono::system_clock> starttime_cr;
14std::time_t starttime = 0;
15int percent = -1;
16
17void WriteMetaData(std::string plot_file, Status status, int per)
18{
19 if (amrex::ParallelDescriptor::IOProcessor())
20 {
21 amrex::ParmParse pp;
22
23 std::chrono::time_point<std::chrono::system_clock> now_cr = std::chrono::system_clock::now();
24 std::time_t now = std::chrono::system_clock::to_time_t(now_cr);
25
26 if (!starttime)
27 {
28 starttime_cr = now_cr;
29 starttime = now;
30 }
31
32 if (!hash)
33 {
34 std::stringstream ss;
35 pp.dumpTable(ss);
36 std::string dumptable = ss.str();
37 hash = std::hash<std::string>{}(dumptable + std::ctime(&starttime));
38 }
39
40 if (per > percent) percent = per;
41
42 std::ofstream metadatafile;
43 metadatafile.open(plot_file+"/metadata",std::ios_base::out);
44 metadatafile << "# COMPILATION DETAILS" << std::endl;
45 metadatafile << "# ===================" << std::endl;
46 metadatafile << "Git_commit_hash = " << METADATA_GITHASH << std::endl;
47 metadatafile << "AMReX_version = " << amrex::Version() << std::endl;
48 metadatafile << "Dimension = " << AMREX_SPACEDIM << std::endl;
49 metadatafile << "User = " << METADATA_USER << std::endl;
50 metadatafile << "Platform = " << METADATA_PLATFORM << std::endl;
51 metadatafile << "Compiler = " << METADATA_COMPILER << std::endl;
52 metadatafile << "Compilation_Date = " << METADATA_DATE << std::endl;
53 metadatafile << "Compilation_Time = " << METADATA_TIME << std::endl;
54 metadatafile << std::endl;
55
56 metadatafile << "# PARAMETERS" << std::endl;
57 metadatafile << "# ==========" << std::endl;
58
59 pp.dumpTable(metadatafile,true);
60
61 metadatafile << "# RUN DETAILS" << std::endl;
62 metadatafile << "# ===========" << std::endl;
63 metadatafile << "HASH = " << hash << std::endl;
64 {
65 char buffer [80];
66 std::strftime(buffer,80,"%Y-%m-%d %H:%M:%S",std::localtime(&starttime));
67 std::string timefmt(buffer);
68 metadatafile << "Simulation_start_time = " << timefmt << std::endl;
69 }
70 metadatafile << "Number_of_processors = " << amrex::ParallelDescriptor::NProcs() << std::endl;
71 if (status == Status::Running) metadatafile << "Status = Running";
72 else if (status == Status::Complete) metadatafile << "Status = Complete";
73 else if (status == Status::Abort) metadatafile << "Status = Abort";
74 else if (status == Status::Segfault) metadatafile << "Status = Segfault";
75 else if (status == Status::Interrupt) metadatafile << "Status = Interrupt";
76
77 if (percent>0) metadatafile << " (" << percent << "%)";
78 metadatafile << std::endl;
79
80 if (status != Status::Running)
81 {
82 char buffer[80];
83 std::strftime(buffer,80,"%Y-%m-%d %H:%M:%S",std::localtime(&now));
84 std::string timefmt(buffer);
85 metadatafile << "Simulation_end_time = " << timefmt << std::endl;
86 }
87
88 auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now_cr - starttime_cr);
89 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 std::ifstream src(GIT_DIFF_PATCH_OUTPUT,std::ios::binary);
102 if (src.is_open())
103 {
104 std::ofstream dst(plot_file+"/diff.patch",std::ios::binary);
105 dst << src.rdbuf();
106 src.close();
107 dst.close();
108 }
109 else
110 {
111 Util::Warning(INFO,"Could not open ",GIT_DIFF_PATCH_OUTPUT);
112 }
113
114 }
115
116 metadatafile.close();
117 }
118}
119
120}
#define INFO
Definition Util.H:20
void WriteMetaData(std::string plot_file, Status status, int per)
unsigned long hash
int percent
@ Segfault
@ Complete
@ Running
@ Interrupt
@ Abort
std::chrono::time_point< std::chrono::system_clock > starttime_cr
std::time_t starttime
void Warning(std::string file, std::string func, int line, Args const &... args)
Definition Util.H:181