Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/output/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,21 @@ namespace stats {

void Writer::writeHeader() {
CallOnce(
[](auto& fname, auto& stat_writers) {
[this](auto& fname, auto& stat_writers) {
std::fstream StatsOut(fname, std::fstream::out | std::fstream::app);
StatsOut << std::setw(14) << "step" << "," << std::setw(14) << "time"
StatsOut << std::setw(io_precision + 8)
<< "step"
<< ","
<< std::setw(io_precision + 8)
<< "time"
<< ",";
for (const auto& stat : stat_writers) {
if (stat.is_vector()) {
for (auto i { 0u }; i < stat.comp.size(); ++i) {
StatsOut << std::setw(14) << stat.name(i) << ",";
StatsOut << std::setw(io_precision + 8) << stat.name(i) << ",";
}
} else {
StatsOut << std::setw(14) << stat.name() << ",";
StatsOut << std::setw(io_precision + 8) << stat.name() << ",";
}
}
StatsOut << std::endl;
Expand Down
33 changes: 25 additions & 8 deletions src/output/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ namespace stats {
tools::Tracker m_tracker;

public:
const int io_precision = 18;

Writer() {}

~Writer() = default;
Expand Down Expand Up @@ -185,14 +187,29 @@ namespace stats {
(void)communicate;
tot_value = value;
#endif
CallOnce(
[](auto&& fname, auto&& value) {
std::fstream StatsOut(fname, std::fstream::out | std::fstream::app);
StatsOut << std::setw(14) << value << ",";
StatsOut.close();
},
m_fname,
tot_value);

if constexpr (std::is_floating_point_v<T>) {
CallOnce(
[this](auto&& fname, auto&& value) {
std::fstream StatsOut(fname, std::fstream::out | std::fstream::app);
StatsOut << std::setw(io_precision + 8)
<< std::setprecision(io_precision)
<< value
<< ",";
StatsOut.close();
},
m_fname,
tot_value);
} else {
CallOnce(
[this](auto&& fname, auto&& value) {
std::fstream StatsOut(fname, std::fstream::out | std::fstream::app);
StatsOut << std::setw(io_precision + 8) << value << ",";
StatsOut.close();
},
m_fname,
tot_value);
}
}

void endWriting();
Expand Down