Skip to content

Commit 7f04926

Browse files
committed
updates previous commit
replace get_elements_with_range [Clang-tidy] fix get_elements_with_range' is deprecated in PatchDataLayer.hpp - Replace get_elements_with_range by get_ids_vec_where. - Fix ignoring return value of function declared with 'nodiscard' attribute [clang-diagnostic-unused-result] 156 | patch_list.build_local(); updates updates
1 parent 631650f commit 7f04926

4 files changed

Lines changed: 39 additions & 7 deletions

File tree

src/shamrock/include/shamrock/patch/PatchDataField.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
/**
1313
* @file PatchDataField.hpp
14+
* @author Léodasce Sewanou (leodasce.sewanou@ens-lyon.fr)
1415
* @author Timothée David--Cléris (tim.shamrock@proton.me)
1516
* @brief
1617
*/
@@ -281,14 +282,14 @@ class PatchDataField {
281282
* @return std::vector<u32>
282283
*/
283284
template<class Lambdacd, class... Args>
284-
inline std::vector<u32> get_ids_vec_where(Lambdacd &&cd_true, Args... args) {
285+
inline std::vector<u32> get_ids_vec_where(Lambdacd &&cd_true, Args &&...args) {
285286
StackEntry stack_loc{};
286287
std::vector<u32> idx_cd{};
287288
if (get_obj_cnt() > 0) {
288289
auto acc = buf.copy_to_stdvec();
289290

290291
for (u32 i = 0; i < get_obj_cnt(); i++) {
291-
if (cd_true(acc, i * nvar, args...)) {
292+
if (std::forward<Lambdacd>(cd_true)(acc, i * nvar, std::forward<Args>(args)...)) {
292293
idx_cd.push_back(i);
293294
}
294295
}

src/shamrock/include/shamrock/patch/PatchDataLayer.hpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
/**
1313
* @file PatchDataLayer.hpp
14+
* @author Léodasce Sewanou (leodasce.sewanou@ens-lyon.fr)
1415
* @author Timothée David--Cléris (tim.shamrock@proton.me)
1516
* @author Yona Lapeyre (yona.lapeyre@ens-lyon.fr) --no git blame--
1617
* @brief
@@ -539,10 +540,13 @@ namespace shamrock::patch {
539540

540541
PatchDataField<T> &main_field = pdat.get_field<T>(0);
541542

543+
// Note that using get_ids_vec_where here is safe since nvar for main_field is equal to 1
544+
// hence the Lambda cd_true will be applied to each block on the patch. e.g : i * nvar = i
542545
auto get_vec_idx = [&](T vmin, T vmax) -> std::vector<u32> {
543-
return main_field.get_elements_with_range(
544-
[&](T val, T vmin, T vmax) {
546+
return main_field.get_ids_vec_where(
547+
[&](const auto &acc, u32 idx, T vmin, T vmax) {
545548
if (shambase::VectorProperties<T>::dimension == 3) {
549+
T val = acc[idx];
546550
return shammath::is_in_half_open(val, vmin, vmax);
547551
} else {
548552
throw shambase::make_except_with_loc<std::runtime_error>(
@@ -553,6 +557,20 @@ namespace shamrock::patch {
553557
vmax);
554558
};
555559

560+
// auto get_vec_idx = [&](T vmin, T vmax) -> std::vector<u32> {
561+
// return main_field.get_elements_with_range(
562+
// [&](T val, T vmin, T vmax) {
563+
// if (shambase::VectorProperties<T>::dimension == 3) {
564+
// return shammath::is_in_half_open(val, vmin, vmax);
565+
// } else {
566+
// throw shambase::make_except_with_loc<std::runtime_error>(
567+
// "dimension != 3 is not handled");
568+
// }
569+
// },
570+
// vmin,
571+
// vmax);
572+
// };
573+
556574
std::vector<u32> idx_lst = get_vec_idx(bmin, bmax);
557575

558576
shamlog_debug_sycl_ln("PatchDataLayer", "inserting element cnt =", idx_lst.size());

src/shamrock/src/patch/PatchDataLayer.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* @brief
1515
*/
1616

17+
#include "shambase/aliases_int.hpp"
1718
#include "shambase/exception.hpp"
1819
#include "shambase/stacktrace.hpp"
1920
#include "shambase/string.hpp"
@@ -22,6 +23,7 @@
2223
#include "shamsys/legacy/log.hpp"
2324
#include "shamsys/legacy/sycl_handler.hpp"
2425
#include "shamtree/kernels/geometry_utils.hpp"
26+
#include <vector>
2527

2628
namespace shamrock::patch {
2729

@@ -313,9 +315,19 @@ namespace shamrock::patch {
313315

314316
PatchDataField<T> &main_field = fields[0].get_if_ref_throw<T>();
315317

318+
// auto get_vec_idx = [&](T vmin, T vmax) -> std::vector<u32> {
319+
// return main_field.get_elements_with_range(
320+
// [&](T val, T vmin, T vmax) {
321+
// return Patch::is_in_patch_converted(val, vmin, vmax);
322+
// },
323+
// vmin,
324+
// vmax);
325+
// };
326+
316327
auto get_vec_idx = [&](T vmin, T vmax) -> std::vector<u32> {
317-
return main_field.get_elements_with_range(
318-
[&](T val, T vmin, T vmax) {
328+
return main_field.get_ids_vec_where(
329+
[&](const auto &acc, u32 idx, T vmin, T vmax) {
330+
T val = acc[idx];
319331
return Patch::is_in_patch_converted(val, vmin, vmax);
320332
},
321333
vmin,

src/shamrock/src/scheduler/PatchScheduler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ std::vector<u64> PatchScheduler::add_root_patches(
153153
//);
154154
}
155155

156-
patch_list.build_local();
156+
// build_local() is declared as nodiscard
157+
(void) patch_list.build_local();
157158
patch_list.reset_local_pack_index();
158159
patch_list.build_local_idx_map();
159160
patch_list.build_global_idx_map();

0 commit comments

Comments
 (0)