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
2 changes: 1 addition & 1 deletion doc/sphinx/examples/sph/run_sphsetup_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
gen,
insert_step=int(scheduler_split_val / 4),
msg_count_limit=32,
msg_size_limit=scheduler_split_val // 4,
rank_comm_size_limit=scheduler_split_val // 4,
do_setup_log=True,
)

Expand Down
7 changes: 4 additions & 3 deletions exemples/benchmarks/sph_weak_scale_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@
setup.apply_setup(
gen,
gen_step=int(scheduler_split_val / 8),
insert_step=int(scheduler_split_val / 2),
msg_count_limit=128,
msg_size_limit=int(scheduler_split_val / 4),
insert_step=int(scheduler_split_val * 2),
msg_count_limit=1024,
rank_comm_size_limit=int(scheduler_split_val) * 2,
max_msg_size=int(scheduler_split_val / 8),
do_setup_log=False,
)

Expand Down
133 changes: 133 additions & 0 deletions src/shambase/include/shambase/tabulate.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// -------------------------------------------------------//
//
// SHAMROCK code for hydrodynamics
// Copyright (c) 2021-2025 Timothée David--Cléris <tim.shamrock@proton.me>
// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
//
// -------------------------------------------------------//

#pragma once

/**
* @file tabulate.hpp
* @author Timothée David--Cléris (tim.shamrock@proton.me)
* @brief
*
*/

#include "shambase/aliases_int.hpp"
#include "shambase/string.hpp"
#include <string>
#include <variant>
#include <vector>

namespace shambase {

template<size_t cols_count>
struct table {
struct rule {};
struct double_rule {};
struct rulled_data {
std::array<std::string, cols_count> colnames;
};
enum positionning {
left,
right,
center,
};
struct data {
std::array<std::string, cols_count> cols;
positionning position;
};

std::vector<std::variant<rule, double_rule, rulled_data, data>> table_lines;

void add_rule() { table_lines.push_back(rule{}); }
void add_double_rule() { table_lines.push_back(double_rule{}); }
void add_rulled_data(std::array<std::string, cols_count> colnames) {
table_lines.push_back(rulled_data{colnames});
}
void add_data(std::array<std::string, cols_count> cols, positionning position) {
table_lines.push_back(data{cols, position});
}

std::array<size_t, cols_count> compute_widths() {
std::array<size_t, cols_count> widths{};
for (auto &line : table_lines) {
if (data *data_line = std::get_if<data>(&line)) {
for (u32 i = 0; i < cols_count; i++) {
widths[i] = std::max(widths[i], data_line->cols[i].size());
}
} else if (rulled_data *head_and_ruller_line = std::get_if<rulled_data>(&line)) {
for (u32 i = 0; i < cols_count; i++) {
widths[i] = std::max(widths[i], head_and_ruller_line->colnames[i].size());
}
}
}
return widths;
}

std::string render() {

std::array<size_t, cols_count> widths = compute_widths();

std::string print = "";
for (auto &line : table_lines) {
if (data *data_line = std::get_if<data>(&line)) {
print += "\n|";
for (u32 i = 0; i < cols_count; i++) {
if (data_line->position == left) {
print += shambase::format(" {:<{}} |", data_line->cols[i], widths[i]);
} else if (data_line->position == right) {
print += shambase::format(" {:>{}} |", data_line->cols[i], widths[i]);
} else if (data_line->position == center) {
print += shambase::format(" {:^{}} |", data_line->cols[i], widths[i]);
}
}

} else if (rulled_data *head_and_ruller_line = std::get_if<rulled_data>(&line)) {
std::string tmp = "+";
for (u32 i = 0; i < cols_count; i++) {
tmp += shambase::format(
" {:^{}} +", head_and_ruller_line->colnames[i], widths[i]);
}

auto neigh_char_is_good = [&](char c) -> bool {
return c == ' ' || c == '-' || c == '<' || c == '>' || c == '+';
};

std::vector<bool> set_to_space = std::vector<bool>(tmp.size(), false);
// if the next and previous chars are space and i am a space then set me to true
for (size_t i = 1; i < tmp.size() - 1; i++) {
if (tmp[i] == ' ' && neigh_char_is_good(tmp[i - 1])
&& neigh_char_is_good(tmp[i + 1])) {
set_to_space[i] = true;
}
}
// replace the spaces by '-'
for (size_t i = 0; i < tmp.size() - 1; i++) {
if (set_to_space[i]) {
tmp[i] = '-';
}
}
print += "\n" + tmp;
Comment thread
tdavidcl marked this conversation as resolved.
} else if (rule *rule_line = std::get_if<rule>(&line)) {
print += "\n+";
for (u32 i = 0; i < cols_count; i++) {
print += shambase::format(
"-{:<{}}-+", std::string(widths[i], '-'), widths[i]);
}
} else if (double_rule *double_rule_line = std::get_if<double_rule>(&line)) {
print += "\n+";
for (u32 i = 0; i < cols_count; i++) {
print += shambase::format(
"={:<{}}=+", std::string(widths[i], '='), widths[i]);
}
}
}
return print;
}
};

} // namespace shambase
112 changes: 2 additions & 110 deletions src/shammodels/common/src/timestep_report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "shambase/aliases_float.hpp"
#include "shambase/aliases_int.hpp"
#include "shambase/string.hpp"
#include "shambase/tabulate.hpp"
#include "shamalgs/collective/reduction.hpp"
#include "shamcomm/collectives.hpp"
#include "shamcomm/logs.hpp"
Expand All @@ -25,115 +26,6 @@
#include <string>
#include <variant>

namespace shammodels {

template<size_t cols_count>
struct table {
struct rule {};
struct double_rule {};
struct rulled_data {
std::array<std::string, cols_count> colnames;
};
enum positionning {
left,
right,
center,
};
struct data {
std::array<std::string, cols_count> cols;
positionning position;
};

std::vector<std::variant<rule, double_rule, rulled_data, data>> table_lines;

void add_rule() { table_lines.push_back(rule{}); }
void add_double_rule() { table_lines.push_back(double_rule{}); }
void add_rulled_data(std::array<std::string, cols_count> colnames) {
table_lines.push_back(rulled_data{colnames});
}
void add_data(std::array<std::string, cols_count> cols, positionning position) {
table_lines.push_back(data{cols, position});
}

std::array<size_t, cols_count> compute_widths() {
std::array<size_t, cols_count> widths{};
for (auto &line : table_lines) {
if (data *data_line = std::get_if<data>(&line)) {
for (u32 i = 0; i < cols_count; i++) {
widths[i] = std::max(widths[i], data_line->cols[i].size());
}
} else if (rulled_data *head_and_ruller_line = std::get_if<rulled_data>(&line)) {
for (u32 i = 0; i < cols_count; i++) {
widths[i] = std::max(widths[i], head_and_ruller_line->colnames[i].size());
}
}
}
return widths;
}

std::string render() {

std::array<size_t, cols_count> widths = compute_widths();

std::string print = "";
for (auto &line : table_lines) {
if (data *data_line = std::get_if<data>(&line)) {
print += "\n|";
for (u32 i = 0; i < cols_count; i++) {
if (data_line->position == left) {
print += shambase::format(" {:<{}} |", data_line->cols[i], widths[i]);
} else if (data_line->position == right) {
print += shambase::format(" {:>{}} |", data_line->cols[i], widths[i]);
} else if (data_line->position == center) {
print += shambase::format(" {:^{}} |", data_line->cols[i], widths[i]);
}
}

} else if (rulled_data *head_and_ruller_line = std::get_if<rulled_data>(&line)) {
std::string tmp = "+";
for (u32 i = 0; i < cols_count; i++) {
tmp += shambase::format(
" {:^{}} +", head_and_ruller_line->colnames[i], widths[i]);
}

auto neigh_char_is_good = [&](char c) -> bool {
return c == ' ' || c == '-' || c == '<' || c == '>' || c == '+';
};

std::vector<bool> set_to_space = std::vector<bool>(tmp.size(), false);
// if the next and previous chars are space and i am a space then set me to true
for (size_t i = 1; i < tmp.size() - 1; i++) {
if (tmp[i] == ' ' && neigh_char_is_good(tmp[i - 1])
&& neigh_char_is_good(tmp[i + 1])) {
set_to_space[i] = true;
}
}
// replace the spaces by '-'
for (size_t i = 0; i < tmp.size() - 1; i++) {
if (set_to_space[i]) {
tmp[i] = '-';
}
}
print += "\n" + tmp;
} else if (rule *rule_line = std::get_if<rule>(&line)) {
print += "\n+";
for (u32 i = 0; i < cols_count; i++) {
print += shambase::format(
"-{:<{}}-+", std::string(widths[i], '-'), widths[i]);
}
} else if (double_rule *double_rule_line = std::get_if<double_rule>(&line)) {
print += "\n+";
for (u32 i = 0; i < cols_count; i++) {
print += shambase::format(
"={:<{}}=+", std::string(widths[i], '='), widths[i]);
}
}
}
return print;
}
};
} // namespace shammodels

std::string shammodels::report_perf_timestep(
f64 rate,
u64 nobj,
Expand Down Expand Up @@ -176,7 +68,7 @@ std::string shammodels::report_perf_timestep(

static constexpr u32 cols_count = 9;

using Table = table<cols_count>;
using Table = shambase::table<cols_count>;

Table table;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace shammodels::sph::modules {
std::optional<u32> insert_count_per_step = std::nullopt,
std::optional<u64> max_msg_count_per_rank_per_step = std::nullopt,
std::optional<u64> max_data_count_per_rank_per_step = std::nullopt,
std::optional<u64> max_msg_size = std::nullopt,
bool do_setup_log = false);

std::shared_ptr<ISPHSetupNode> make_generator_lattice_hcp(
Expand Down
Loading
Loading