31#include <unordered_map>
73 std::vector<std::string> tags;
79 for (
u32 i = 0; i < nvars; i++) {
80 tmp.
entries.push_back({tags[i], vals[i]});
97 std::vector<std::string> tags;
99 for (
u32 i = 0; i < nvars; i++) {
112 for (
auto [key, val] :
entries) {
159 for (
u32 j = 0; j < numarray[0]; j++) {
163 for (
u32 j = 0; j < numarray[1]; j++) {
166 for (
u32 j = 0; j < numarray[2]; j++) {
169 for (
u32 j = 0; j < numarray[3]; j++) {
172 for (
u32 j = 0; j < numarray[4]; j++) {
175 for (
u32 j = 0; j < numarray[5]; j++) {
179 for (
u32 j = 0; j < numarray[6]; j++) {
182 for (
u32 j = 0; j < numarray[7]; j++) {
193 for (
u32 j = 0; j < numarray[0]; j++) {
196 for (
u32 j = 0; j < numarray[1]; j++) {
199 for (
u32 j = 0; j < numarray[2]; j++) {
202 for (
u32 j = 0; j < numarray[3]; j++) {
205 for (
u32 j = 0; j < numarray[4]; j++) {
208 for (
u32 j = 0; j < numarray[5]; j++) {
211 for (
u32 j = 0; j < numarray[6]; j++) {
214 for (
u32 j = 0; j < numarray[7]; j++) {
221 s = shambase::format(
"{:16s}", s);
245 s = shambase::format(
"{:16s}", s);
285 int nblocks =
blocks.size();
286 phfile.
write(nblocks);
288 std::vector<i64> block_tot_counts;
289 std::vector<std::array<i32, 8>> block_numarray;
290 for (
u32 i = 0; i < nblocks; i++) {
293 std::array<i32, 8> counts
294 = {
i32(
blocks[i].blocks_fort_int.size()),
303 phfile.
write(tot_count, counts);
304 block_tot_counts.push_back(tot_count);
305 block_numarray.push_back(counts);
308 for (
u32 i = 0; i < nblocks; i++) {
309 blocks[i].write(phfile, block_tot_counts[i], block_numarray[i]);
321 phfile.
read(phdump.i1, phdump.r1, phdump.i2, phdump.iversion, phdump.i3);
322 phdump.check_magic_numbers();
343 phfile.
read(nblocks);
345 std::vector<i64> block_tot_counts;
346 std::vector<std::array<i32, 8>> block_numarray;
348 for (
u32 i = 0; i < nblocks; i++) {
351 std::array<i32, 8> counts;
353 phfile.
read(tot_count, counts);
355 block_tot_counts.push_back(tot_count);
356 block_numarray.push_back(counts);
358 for (
u32 i = 0; i < nblocks; i++) {
359 phdump.blocks.push_back(
390 for (
u32 i = 0; i <
blocks.size(); i++) {
402 std::unordered_map<std::string, f64> header;
404 dump.table_header_fort_int.add_to_map(header);
405 dump.table_header_i8.add_to_map(header);
406 dump.table_header_i16.add_to_map(header);
407 dump.table_header_i32.add_to_map(header);
408 dump.table_header_i64.add_to_map(header);
409 dump.table_header_fort_real.add_to_map(header);
410 dump.table_header_f32.add_to_map(header);
411 dump.table_header_f64.add_to_map(header);
415 std::unordered_map<std::string, f64> header_ref = load_header(dump_ref);
416 std::unordered_map<std::string, f64> header_comp = load_header(dump_comp);
418 auto get_keys = [](std::unordered_map<std::string, f64> &map) {
419 std::set<std::string> ret;
420 for (
auto [key, val] : map) {
426 std::set<std::string> header_key_ref = get_keys(header_ref);
427 std::set<std::string> header_key_comp = get_keys(header_comp);
429 std::vector<std::string> missing = {};
430 std::vector<std::string> matching = {};
431 std::vector<std::string> extra = {};
435 for (std::string &missing_key : missing) {
438 "The dump we are comparing against is missing the key",
443 for (std::string &matching_key : matching) {
444 if (header_ref[matching_key] != header_comp[matching_key]) {
448 "Mismatch in the header key {}, ref={}, comp={}",
450 header_ref[matching_key],
451 header_comp[matching_key]));
455 for (std::string &extra_key : extra) {
458 "The dump we are comparing against has the extra key",
464 logger::info_ln(
"PhantomDump",
"This comparison reported", offenses,
"offenses");
466 return offenses == 0;
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
std::int64_t i64
64 bit integer
std::int32_t i32
32 bit integer
Class for reading and writing Fortran-style binary files.
void write(Args &...args)
Write a list of arguments to the internal buffer.
void write_string_array(std::vector< std::string > &svec, u32 strlen, u32 str_count)
Write a fixed-length string array to the buffer.
void write_val_array(std::vector< T > &vec, u32 val_count)
Write an array of values to the buffer.
void read_fixed_string(std::string &s, u32 len)
Read a fixed-length string from the buffer.
void read(Args &...args)
Read a list of arguments from the internal buffer.
void read_string_array(std::vector< std::string > &svec, u32 strlen, u32 str_count)
Read a fixed-length string array from the buffer.
void read_val_array(std::vector< T > &vec, u32 val_count)
Read an array of values from the buffer.
void write_fixed_string(std::string &s, u32 len)
Write a fixed-length string to the buffer.
bool finished_read()
Check if the end of the file has been reached.
This header file contains utility functions related to exception handling in the code.
void set_diff(Container1 &c1, Container2 &ref, std::vector< T > &missing, std::vector< T > &matching, std::vector< T > &extra)
Compute the difference between two containers as three separate vectors.
bool compare_phantom_dumps(PhantomDump &dump1, PhantomDump &dump2)
Compare two phantom dumps and report offenses.
void raw_ln(Types... var2)
Prints a log message with multiple arguments followed by a newline.
void info_ln(std::string module_name, Types... var2)
Prints a log message with multiple arguments followed by a newline.
void warn_ln(std::string module_name, Types... var2)
Prints a log message with multiple arguments followed by a newline.
This file contains the definition for the stacktrace related functionality.
shambase::details::BasicStackEntry StackEntry
Alias for shambase::details::BasicStackEntry.
A helper class to represent a single block of data in a Phantom dump.
void write(shambase::FortranIOFile &phfile, i64 tot_count)
Writes a block to a file.
std::string tag
The tag of the block.
void print_state()
Prints the state of the block.
std::vector< T > vals
The values of the block.
static PhantomDumpBlockArray from_file(shambase::FortranIOFile &phfile, i64 tot_count)
Reads a block from a file.
A class to represent a single block of data in a Phantom dump.
std::vector< PhantomDumpBlockArray< fort_int > > blocks_fort_int
The blocks of values of type fort_int.
static PhantomDumpBlock from_file(shambase::FortranIOFile &phfile, i64 tot_count, std::array< i32, 8 > numarray)
Reads a block from a file.
u64 get_ref_f32(std::string s)
Gets the index of a block of type f32 with the given name.
std::vector< PhantomDumpBlockArray< i16 > > blocks_i16
The blocks of values of type i16.
std::vector< PhantomDumpBlockArray< i8 > > blocks_i8
The blocks of values of type i8.
std::vector< PhantomDumpBlockArray< f64 > > blocks_f64
The blocks of values of type f64.
std::vector< PhantomDumpBlockArray< i64 > > blocks_i64
The blocks of values of type i64.
void write(shambase::FortranIOFile &phfile, i64 tot_count, std::array< i32, 8 > numarray)
Writes a block to a file.
u64 get_ref_fort_real(std::string s)
Gets the index of a block of type fort_real with the given name.
std::vector< PhantomDumpBlockArray< i32 > > blocks_i32
The blocks of values of type i32.
i64 tot_count
The total number of values in the block.
std::vector< PhantomDumpBlockArray< fort_real > > blocks_fort_real
The blocks of values of type fort_real.
std::vector< PhantomDumpBlockArray< f32 > > blocks_f32
The blocks of values of type f32.
void print_state()
Prints the state of the block.
Class representing a Phantom dump file.
PhantomDumpTableHeader< i16 > table_header_i16
Table header for signed 16-bit integer data.
fort_int i3
Magic number used in the phantom dump format.
PhantomDumpTableHeader< fort_int > table_header_fort_int
Table header for integer data.
std::string fileid
Magic number used in the phantom dump format.
fort_int i1
Magic number used in the phantom dump format.
PhantomDumpTableHeader< f32 > table_header_f32
Table header for 32-bit floating-point data.
PhantomDumpTableHeader< i64 > table_header_i64
Table header for signed 64-bit integer data.
PhantomDumpTableHeader< i32 > table_header_i32
Table header for signed 32-bit integer data.
static PhantomDump from_file(shambase::FortranIOFile &phfile)
Reads a Phantom dump file and returns a PhantomDump object.
shambase::FortranIOFile gen_file()
Generates a Phantom dump file from the current state of the object.
fort_int i2
Magic number used in the phantom dump format.
std::vector< PhantomDumpBlock > blocks
List of blocks in the Phantom dump file.
PhantomDumpTableHeader< fort_real > table_header_fort_real
Table header for floating-point data.
PhantomDumpTableHeader< f64 > table_header_f64
Table header for 64-bit floating-point data.
fort_int iversion
Magic number used in the phantom dump format.
void print_state()
Print current state of the data stored in the class.
PhantomDumpTableHeader< i8 > table_header_i8
Table header for signed 8-bit integer data.
fort_real r1
Magic number used in the phantom dump format.