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