Commit 95f4b315 authored by Bednárek David RNDr. Ph.D.'s avatar Bednárek David RNDr. Ph.D.
Browse files

machine name print etc.

parent adcb106f
......@@ -21,6 +21,8 @@
#include <variant>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <cmath>
namespace fmwkng {
namespace impl {
......@@ -334,16 +336,23 @@ namespace fmwkng {
inline void print_list(element_list_view el, element_list_view prefix = {})
{
#ifdef PRINT_META
prefix.metadata_text(std::cout);
el.metadata_text(std::cout);
#endif
if (prefix.data_size())
{
#ifdef PRINT_META
std::cout << '\t';
#endif
prefix.data_text(std::cout);
}
if (el.data_size())
{
std::cout << '\t';
#ifndef PRINT_META
if (prefix.data_size())
#endif
std::cout << '\t';
el.data_text(std::cout);
}
std::cout << std::endl;
......@@ -564,29 +573,40 @@ namespace fmwkng {
auto gold_value = gd.find(key);
#ifdef PRINT_META
for (auto&& a : openers)
{
a->metadata_marker(std::cout);
}
rn.reduced_children.metadata_text(std::cout);
std::size_t s = 1;
#else
std::size_t s = 0;
#endif
for (auto&& a : openers)
{
for (std::size_t i = 0; i < a->data_size(); ++i)
{
std::cout << '\t';
if ( !!s )
std::cout << '\t';
a->data_text(std::cout, i);
++s;
}
}
if (rn.reduced_children.data_size())
{
std::cout << '\t';
if (!!s)
std::cout << '\t';
rn.reduced_children.data_text(std::cout);
++s;
}
if (!!gold_value && gold_value->data_size())
{
std::cout << '\t';
if (!!s)
std::cout << '\t';
rn.reduced_children.gold_comparison_text(std::cout, *gold_value);
++s;
}
std::cout << std::endl;
......@@ -1747,10 +1767,31 @@ namespace fmwkng {
static void metadata_marker(std::ostream& os)
{
}
using data_type = void;
using data_type = std::string;
static void data_text(std::ostream& os, const data_type&d)
{
os << d;
}
static void gold_comparison_text(std::ostream& os, const data_type& d, const data_type& gold_d)
{
assert(0);
}
static void code_data(std::ostream& os, const data_type& d)
{
os << "\"" << d << "\"";
}
static constexpr bool useful = false;
static constexpr bool reducible = false;
template< element_sense sense>
using aggregator = element_t< root_tag< config_t>, sense>;
static data_type aggregator_data(const data_type& v)
{
return v;
}
static void aggregate(data_type&, const data_type&)
{
// the first wins
}
};
template< typename config_t>
......@@ -1771,7 +1812,7 @@ namespace fmwkng {
using self_ = root_data_holder< config_t>;
public:
root_data_holder(int argc, char** argv, const gold_data& gd = gold_data{})
: gd_(gd)
: gd_(gd), direct_print_(true)
{
std::fill(platform_enablers_.begin(), platform_enablers_.end(), true);
process_arguments(std::vector< std::string>(argv + 1, argv + argc));
......@@ -1803,7 +1844,13 @@ namespace fmwkng {
template< typename dt_t>
void entry(const dt_t&)
{
push_element<root_tag<config_t>, element_sense::OPEN>();
push_element<root_tag<config_t>, element_sense::OPEN>(
#ifdef NDEBUG
machine_name_
#else
machine_name_ + "/Debug"
#endif
);
//std::cout << "enter_root" << std::endl;
}
......@@ -1913,6 +1960,10 @@ namespace fmwkng {
{
return el_;
}
bool direct_print() const
{
return direct_print_;
}
private:
std::array<bool, config_t::platforms::size_v> platform_enablers_;
typename config_t::ranges::tuple_t range_configs_;
......@@ -1921,15 +1972,21 @@ namespace fmwkng {
mutable element_list all_el_;
std::string code_fn_;
gold_data gd_;
std::string machine_name_;
bool direct_print_;
void print_elements() const
{
if (el_.useful())
if (direct_print_ && el_.useful())
{
#ifdef PRINT_META
el_.metadata_text(std::cout);
#endif
if (el_.data_size())
{
#ifdef PRINT_META
std::cout << '\t';
#endif
el_.data_text(std::cout);
}
std::cout << std::endl;
......@@ -1943,6 +2000,36 @@ namespace fmwkng {
void process_arguments(const std::vector< std::string>& arg)
{
{
#pragma warning(push)
#pragma warning(disable: 4996)
auto slurm_partition = getenv("SLURM_PARTITION");
#pragma warning(pop)
if (slurm_partition)
{
machine_name_ = slurm_partition;
auto pos = machine_name_.find('-');
if (pos != std::string::npos)
{
machine_name_.resize(pos);
}
}
else
{
#ifdef __linux__
auto comp_name = getenv("HOSTNAME");
#else
#pragma warning(push)
#pragma warning(disable: 4996)
auto comp_name = getenv("COMPUTERNAME");
#pragma warning(pop)
#endif
if (comp_name)
{
machine_name_ = comp_name;
}
}
}
for (auto it = arg.begin(); it != arg.end(); ++it)
{
auto& a = *it;
......@@ -1961,6 +2048,17 @@ namespace fmwkng {
{
code_fn_ = value;
}
else if (name == "machine")
{
machine_name_ = value;
}
else if (name == "direct-print")
{
if (value == "1" || value == "true" || value == "on")
direct_print_ = true;
else
direct_print_ = false;
}
else
{
config_t::ranges::for_each([this, name, value](auto rs) {
......@@ -2549,20 +2647,28 @@ namespace fmwkng {
template< typename dt_t>
void print_elements(const dt_t& dt) const
{
if (el_.useful())
if (root_pointer(dt)->direct_print() && el_.useful())
{
auto g = guard();
auto&& rel = root_pointer(dt)->el();
#ifdef PRINT_META
rel.metadata_text(std::cout);
el_.metadata_text(std::cout);
#endif
if (rel.data_size())
{
#ifdef PRINT_META
std::cout << '\t';
#endif
rel.data_text(std::cout);
}
if (el_.data_size())
{
std::cout << '\t';
#ifndef PRINT_META
if (rel.data_size())
#endif
std::cout << '\t';
el_.data_text(std::cout);
}
std::cout << std::endl;
......@@ -2769,6 +2875,10 @@ namespace fmwkng {
static void code_data(std::ostream& os, const data_type& d)
{
os << d;
if constexpr (std::is_unsigned_v<data_type>)
{
os << "U";
}
}
static constexpr bool useful = true;
static constexpr bool reducible = true;
......@@ -2946,7 +3056,8 @@ namespace fmwkng {
static void gold_comparison_text(std::ostream& os, const data_type& d, const data_type& gold_d)
{
auto ratio = d / gold_d;
os << (ratio*100) << "%";
//os << (ratio*100) << "%";
os << ratio;
}
static void code_data(std::ostream& os, const data_type& d)
{
......@@ -2988,7 +3099,8 @@ namespace fmwkng {
static void gold_comparison_text(std::ostream& os, const data_type& d, const data_type& gold_d)
{
auto logratio = (d.first / d.second) - (gold_d.first / gold_d.second);
os << (std::exp(logratio)*100) << "%";
//os << std::fixed << std::setprecision(0) << (std::exp(logratio)*100) << "%";
os << std::exp(logratio);
}
static void code_data(std::ostream& os, const data_type& d)
{
......
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment