Skip to content

Commit 6c5f4f1

Browse files
tdavidclaserhani
authored andcommitted
[SPH] improve new SPH setup performance (Shamrock-code#1501)
1 parent f83ad30 commit 6c5f4f1

8 files changed

Lines changed: 347 additions & 144 deletions

File tree

doc/sphinx/examples/sph/run_sphsetup_logs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
gen,
9999
insert_step=int(scheduler_split_val / 4),
100100
msg_count_limit=32,
101-
msg_size_limit=scheduler_split_val // 4,
101+
rank_comm_size_limit=scheduler_split_val // 4,
102102
do_setup_log=True,
103103
)
104104

exemples/benchmarks/sph_weak_scale_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@
7070
setup.apply_setup(
7171
gen,
7272
gen_step=int(scheduler_split_val / 8),
73-
insert_step=int(scheduler_split_val / 2),
74-
msg_count_limit=128,
75-
msg_size_limit=int(scheduler_split_val / 4),
73+
insert_step=int(scheduler_split_val * 2),
74+
msg_count_limit=1024,
75+
rank_comm_size_limit=int(scheduler_split_val) * 2,
76+
max_msg_size=int(scheduler_split_val / 8),
7677
do_setup_log=False,
7778
)
7879

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
// -------------------------------------------------------//
2+
//
3+
// SHAMROCK code for hydrodynamics
4+
// Copyright (c) 2021-2025 Timothée David--Cléris <tim.shamrock@proton.me>
5+
// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6+
// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7+
//
8+
// -------------------------------------------------------//
9+
10+
#pragma once
11+
12+
/**
13+
* @file tabulate.hpp
14+
* @author Timothée David--Cléris (tim.shamrock@proton.me)
15+
* @brief
16+
*
17+
*/
18+
19+
#include "shambase/aliases_int.hpp"
20+
#include "shambase/string.hpp"
21+
#include <string>
22+
#include <variant>
23+
#include <vector>
24+
25+
namespace shambase {
26+
27+
template<size_t cols_count>
28+
struct table {
29+
struct rule {};
30+
struct double_rule {};
31+
struct rulled_data {
32+
std::array<std::string, cols_count> colnames;
33+
};
34+
enum positionning {
35+
left,
36+
right,
37+
center,
38+
};
39+
struct data {
40+
std::array<std::string, cols_count> cols;
41+
positionning position;
42+
};
43+
44+
std::vector<std::variant<rule, double_rule, rulled_data, data>> table_lines;
45+
46+
void add_rule() { table_lines.push_back(rule{}); }
47+
void add_double_rule() { table_lines.push_back(double_rule{}); }
48+
void add_rulled_data(std::array<std::string, cols_count> colnames) {
49+
table_lines.push_back(rulled_data{colnames});
50+
}
51+
void add_data(std::array<std::string, cols_count> cols, positionning position) {
52+
table_lines.push_back(data{cols, position});
53+
}
54+
55+
std::array<size_t, cols_count> compute_widths() {
56+
std::array<size_t, cols_count> widths{};
57+
for (auto &line : table_lines) {
58+
if (data *data_line = std::get_if<data>(&line)) {
59+
for (u32 i = 0; i < cols_count; i++) {
60+
widths[i] = std::max(widths[i], data_line->cols[i].size());
61+
}
62+
} else if (rulled_data *head_and_ruller_line = std::get_if<rulled_data>(&line)) {
63+
for (u32 i = 0; i < cols_count; i++) {
64+
widths[i] = std::max(widths[i], head_and_ruller_line->colnames[i].size());
65+
}
66+
}
67+
}
68+
return widths;
69+
}
70+
71+
std::string render() {
72+
73+
std::array<size_t, cols_count> widths = compute_widths();
74+
75+
std::string print = "";
76+
for (auto &line : table_lines) {
77+
if (data *data_line = std::get_if<data>(&line)) {
78+
print += "\n|";
79+
for (u32 i = 0; i < cols_count; i++) {
80+
if (data_line->position == left) {
81+
print += shambase::format(" {:<{}} |", data_line->cols[i], widths[i]);
82+
} else if (data_line->position == right) {
83+
print += shambase::format(" {:>{}} |", data_line->cols[i], widths[i]);
84+
} else if (data_line->position == center) {
85+
print += shambase::format(" {:^{}} |", data_line->cols[i], widths[i]);
86+
}
87+
}
88+
89+
} else if (rulled_data *head_and_ruller_line = std::get_if<rulled_data>(&line)) {
90+
std::string tmp = "+";
91+
for (u32 i = 0; i < cols_count; i++) {
92+
tmp += shambase::format(
93+
" {:^{}} +", head_and_ruller_line->colnames[i], widths[i]);
94+
}
95+
96+
auto neigh_char_is_good = [&](char c) -> bool {
97+
return c == ' ' || c == '-' || c == '<' || c == '>' || c == '+';
98+
};
99+
100+
std::vector<bool> set_to_space = std::vector<bool>(tmp.size(), false);
101+
// if the next and previous chars are space and i am a space then set me to true
102+
for (size_t i = 1; i < tmp.size() - 1; i++) {
103+
if (tmp[i] == ' ' && neigh_char_is_good(tmp[i - 1])
104+
&& neigh_char_is_good(tmp[i + 1])) {
105+
set_to_space[i] = true;
106+
}
107+
}
108+
// replace the spaces by '-'
109+
for (size_t i = 0; i < tmp.size() - 1; i++) {
110+
if (set_to_space[i]) {
111+
tmp[i] = '-';
112+
}
113+
}
114+
print += "\n" + tmp;
115+
} else if (rule *rule_line = std::get_if<rule>(&line)) {
116+
print += "\n+";
117+
for (u32 i = 0; i < cols_count; i++) {
118+
print += shambase::format(
119+
"-{:<{}}-+", std::string(widths[i], '-'), widths[i]);
120+
}
121+
} else if (double_rule *double_rule_line = std::get_if<double_rule>(&line)) {
122+
print += "\n+";
123+
for (u32 i = 0; i < cols_count; i++) {
124+
print += shambase::format(
125+
"={:<{}}=+", std::string(widths[i], '='), widths[i]);
126+
}
127+
}
128+
}
129+
return print;
130+
}
131+
};
132+
133+
} // namespace shambase

src/shammodels/common/src/timestep_report.cpp

Lines changed: 2 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "shambase/aliases_float.hpp"
1818
#include "shambase/aliases_int.hpp"
1919
#include "shambase/string.hpp"
20+
#include "shambase/tabulate.hpp"
2021
#include "shamalgs/collective/reduction.hpp"
2122
#include "shamcomm/collectives.hpp"
2223
#include "shamcomm/logs.hpp"
@@ -25,115 +26,6 @@
2526
#include <string>
2627
#include <variant>
2728

28-
namespace shammodels {
29-
30-
template<size_t cols_count>
31-
struct table {
32-
struct rule {};
33-
struct double_rule {};
34-
struct rulled_data {
35-
std::array<std::string, cols_count> colnames;
36-
};
37-
enum positionning {
38-
left,
39-
right,
40-
center,
41-
};
42-
struct data {
43-
std::array<std::string, cols_count> cols;
44-
positionning position;
45-
};
46-
47-
std::vector<std::variant<rule, double_rule, rulled_data, data>> table_lines;
48-
49-
void add_rule() { table_lines.push_back(rule{}); }
50-
void add_double_rule() { table_lines.push_back(double_rule{}); }
51-
void add_rulled_data(std::array<std::string, cols_count> colnames) {
52-
table_lines.push_back(rulled_data{colnames});
53-
}
54-
void add_data(std::array<std::string, cols_count> cols, positionning position) {
55-
table_lines.push_back(data{cols, position});
56-
}
57-
58-
std::array<size_t, cols_count> compute_widths() {
59-
std::array<size_t, cols_count> widths{};
60-
for (auto &line : table_lines) {
61-
if (data *data_line = std::get_if<data>(&line)) {
62-
for (u32 i = 0; i < cols_count; i++) {
63-
widths[i] = std::max(widths[i], data_line->cols[i].size());
64-
}
65-
} else if (rulled_data *head_and_ruller_line = std::get_if<rulled_data>(&line)) {
66-
for (u32 i = 0; i < cols_count; i++) {
67-
widths[i] = std::max(widths[i], head_and_ruller_line->colnames[i].size());
68-
}
69-
}
70-
}
71-
return widths;
72-
}
73-
74-
std::string render() {
75-
76-
std::array<size_t, cols_count> widths = compute_widths();
77-
78-
std::string print = "";
79-
for (auto &line : table_lines) {
80-
if (data *data_line = std::get_if<data>(&line)) {
81-
print += "\n|";
82-
for (u32 i = 0; i < cols_count; i++) {
83-
if (data_line->position == left) {
84-
print += shambase::format(" {:<{}} |", data_line->cols[i], widths[i]);
85-
} else if (data_line->position == right) {
86-
print += shambase::format(" {:>{}} |", data_line->cols[i], widths[i]);
87-
} else if (data_line->position == center) {
88-
print += shambase::format(" {:^{}} |", data_line->cols[i], widths[i]);
89-
}
90-
}
91-
92-
} else if (rulled_data *head_and_ruller_line = std::get_if<rulled_data>(&line)) {
93-
std::string tmp = "+";
94-
for (u32 i = 0; i < cols_count; i++) {
95-
tmp += shambase::format(
96-
" {:^{}} +", head_and_ruller_line->colnames[i], widths[i]);
97-
}
98-
99-
auto neigh_char_is_good = [&](char c) -> bool {
100-
return c == ' ' || c == '-' || c == '<' || c == '>' || c == '+';
101-
};
102-
103-
std::vector<bool> set_to_space = std::vector<bool>(tmp.size(), false);
104-
// if the next and previous chars are space and i am a space then set me to true
105-
for (size_t i = 1; i < tmp.size() - 1; i++) {
106-
if (tmp[i] == ' ' && neigh_char_is_good(tmp[i - 1])
107-
&& neigh_char_is_good(tmp[i + 1])) {
108-
set_to_space[i] = true;
109-
}
110-
}
111-
// replace the spaces by '-'
112-
for (size_t i = 0; i < tmp.size() - 1; i++) {
113-
if (set_to_space[i]) {
114-
tmp[i] = '-';
115-
}
116-
}
117-
print += "\n" + tmp;
118-
} else if (rule *rule_line = std::get_if<rule>(&line)) {
119-
print += "\n+";
120-
for (u32 i = 0; i < cols_count; i++) {
121-
print += shambase::format(
122-
"-{:<{}}-+", std::string(widths[i], '-'), widths[i]);
123-
}
124-
} else if (double_rule *double_rule_line = std::get_if<double_rule>(&line)) {
125-
print += "\n+";
126-
for (u32 i = 0; i < cols_count; i++) {
127-
print += shambase::format(
128-
"={:<{}}=+", std::string(widths[i], '='), widths[i]);
129-
}
130-
}
131-
}
132-
return print;
133-
}
134-
};
135-
} // namespace shammodels
136-
13729
std::string shammodels::report_perf_timestep(
13830
f64 rate,
13931
u64 nobj,
@@ -176,7 +68,7 @@ std::string shammodels::report_perf_timestep(
17668

17769
static constexpr u32 cols_count = 9;
17870

179-
using Table = table<cols_count>;
71+
using Table = shambase::table<cols_count>;
18072

18173
Table table;
18274

src/shammodels/sph/include/shammodels/sph/modules/SPHSetup.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ namespace shammodels::sph::modules {
5656
std::optional<u32> insert_count_per_step = std::nullopt,
5757
std::optional<u64> max_msg_count_per_rank_per_step = std::nullopt,
5858
std::optional<u64> max_data_count_per_rank_per_step = std::nullopt,
59+
std::optional<u64> max_msg_size = std::nullopt,
5960
bool do_setup_log = false);
6061

6162
std::shared_ptr<ISPHSetupNode> make_generator_lattice_hcp(

0 commit comments

Comments
 (0)