Skip to content
Open
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -497,3 +497,53 @@ jobs:
mpiexec -n 2 ./demos/FiniteVolume/finite-volume-burgers --Tf 0.1 --nfiles 1 --max-level 8
# This test is failing with 3 processes due to a bug in the exchange of subdomain corners
# mpiexec -n 3 ./demos/FiniteVolume/finite-volume-burgers --Tf 0.1 --nfiles 1 --max-level 8

#
# Benchmarks build and run (separate runner)
#
#########################################################
linux-benchmarks:
needs: [pre-commit, cppcheck]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Cache
uses: actions/cache@v4
with:
path: |
~/.cache/ccache
~/micromamba-root/envs/samurai-env
key: linux-benchmarks
restore-keys: |
linux-benchmarks

- name: Mamba and samurai env installation
uses: mamba-org/setup-micromamba@v2
with:
environment-file: conda/environment.yml
environment-name: samurai-env
cache-environment: true

- name: Configure (benchmarks only)
shell: bash -l {0}
run: |
cmake \
. \
-Bbuild \
-GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_BENCHMARKS=ON \
-DBUILD_DEMOS=OFF \
-DBUILD_TESTS=OFF

- name: Build benchmarks
shell: bash -l {0}
run: |
cmake --build build --target bench_samurai --parallel 2

- name: Run bench_samurai (quick sanity)
shell: bash -l {0}
run: |
cd build
./benchmark/bench_samurai --benchmark_min_time=0.003 --benchmark_color=no --benchmark_format=console
10 changes: 9 additions & 1 deletion benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ find_package(Threads)
set(SAMURAI_BENCHMARKS
benchmark_celllist_construction.cpp
benchmark_search.cpp
benchmark_set.cpp
benchmark_interval.cpp
benchmark_cellarray.cpp
benchmark_level_cell_array.cpp
benchmark_mesh.cpp
benchmark_stencil.cpp
benchmark_field.cpp
benchmark_bc.cpp
benchmark_cell.cpp
benchmark_subset.cpp
main.cpp
)

Expand Down
91 changes: 91 additions & 0 deletions benchmark/benchmark_bc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include <benchmark/benchmark.h>

#include <xtensor/xfixed.hpp>

#include <samurai/algorithm.hpp>
#include <samurai/amr/mesh.hpp>
#include <samurai/bc.hpp>
#include <samurai/box.hpp>
#include <samurai/cell_array.hpp>
#include <samurai/cell_list.hpp>
#include <samurai/field.hpp>
#include <samurai/list_of_intervals.hpp>
#include <samurai/mr/mesh.hpp>
#include <samurai/static_algorithm.hpp>
#include <samurai/uniform_mesh.hpp>

////////////////////////////////////////////////////////////////////////////////////
/// utils

template <unsigned int dim>
auto unitary_box()
{
using value_t = samurai::default_config::value_t;
using point_t = xt::xtensor_fixed<value_t, xt::xshape<dim>>;
point_t point1;
point_t point2;
if constexpr (dim == 1)
{
point1 = {0};
point2 = {1};
}
if constexpr (dim == 2)
{
point1 = {0, 0};
point2 = {1, 1};
}
if constexpr (dim == 3)
{
point1 = {0, 0, 0};
point2 = {1, 1, 1};
}

samurai::Box<double, dim> box = samurai::Box<double, dim>(point1, point2);
return box;
}

// Mesure : Création d'une condition limite sur un maillage uniforme
template <unsigned int dim, unsigned int n_comp, typename BCType, unsigned int order>
void BC_homogeneous(benchmark::State& state)
{
samurai::Box<double, dim> box = unitary_box<dim>();
using Config = samurai::UniformConfig<dim, static_cast<int>(order)>; // ghost_width = order
auto mesh = samurai::UniformMesh<Config>(box, static_cast<std::size_t>(state.range(0)));
auto u = samurai::make_vector_field<double, n_comp>("u", mesh);

u.fill(1.0);

// Ajout des compteurs personnalisés
state.counters["Dimension"] = dim;
state.counters["Composantes"] = n_comp;
state.counters["Ordre"] = order;
state.counters["Type BC"] = std::is_same_v<BCType, samurai::Dirichlet<order>> ? 0 : 1; // 0 pour Dirichlet, 1 pour Neumann

auto& bc_container = u.get_bc();

for (auto _ : state)
{
state.PauseTiming();
bc_container.clear();
state.ResumeTiming();
samurai::make_bc<BCType>(u);
}
}

// Tests Dirichlet
BENCHMARK_TEMPLATE(BC_homogeneous, 1, 1, samurai::Dirichlet<1>, 1)->DenseRange(1, 1);
BENCHMARK_TEMPLATE(BC_homogeneous, 2, 1, samurai::Dirichlet<1>, 1)->DenseRange(1, 1);
BENCHMARK_TEMPLATE(BC_homogeneous, 3, 1, samurai::Dirichlet<1>, 1)->DenseRange(1, 1);
BENCHMARK_TEMPLATE(BC_homogeneous, 1, 100, samurai::Dirichlet<1>, 1)->DenseRange(1, 1);

// Tests Neumann
BENCHMARK_TEMPLATE(BC_homogeneous, 1, 1, samurai::Neumann<1>, 1)->DenseRange(1, 1);
BENCHMARK_TEMPLATE(BC_homogeneous, 2, 1, samurai::Neumann<1>, 1)->DenseRange(1, 1);
BENCHMARK_TEMPLATE(BC_homogeneous, 3, 1, samurai::Neumann<1>, 1)->DenseRange(1, 1);
BENCHMARK_TEMPLATE(BC_homogeneous, 1, 100, samurai::Neumann<1>, 1)->DenseRange(1, 1);

// Tests Dirichlet ordre 3
BENCHMARK_TEMPLATE(BC_homogeneous, 1, 1, samurai::Dirichlet<3>, 3)->DenseRange(1, 1);
BENCHMARK_TEMPLATE(BC_homogeneous, 2, 1, samurai::Dirichlet<3>, 3)->DenseRange(1, 1);
BENCHMARK_TEMPLATE(BC_homogeneous, 3, 1, samurai::Dirichlet<3>, 3)->DenseRange(1, 1);
BENCHMARK_TEMPLATE(BC_homogeneous, 1, 100, samurai::Dirichlet<3>, 3)->DenseRange(1, 1);
169 changes: 169 additions & 0 deletions benchmark/benchmark_cell.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
#include <benchmark/benchmark.h>

#include <xtensor/xfixed.hpp>

#include <samurai/algorithm.hpp>
#include <samurai/amr/mesh.hpp>
#include <samurai/box.hpp>
#include <samurai/cell_array.hpp>
#include <samurai/cell_list.hpp>
#include <samurai/field.hpp>
#include <samurai/list_of_intervals.hpp>
#include <samurai/mr/mesh.hpp>
#include <samurai/static_algorithm.hpp>
#include <samurai/uniform_mesh.hpp>

//////////////////////////////////////////////////////////////////
/// utils

template <std::size_t dim>
auto make_cell()
{
using value_t = samurai::default_config::value_t;
using point_t = xt::xtensor_fixed<value_t, xt::xshape<dim>>;

// Initialisation générique des indices et du point de départ
point_t indice = xt::ones<value_t>({dim});
point_t begin = xt::zeros<value_t>({dim});

auto indices = xt::xtensor_fixed<int, xt::xshape<dim>>(indice);
double scaling_factor = 1.0;
auto c = samurai::Cell<dim, samurai::Interval<int>>(begin, scaling_factor, 1, indices, 0);
return c;
}

// Mesure : Construction d'une cellule par défaut
template <unsigned int dim>
void CELL_default(benchmark::State& state)
{
for (auto _ : state)
{
auto c = samurai::Cell<dim, samurai::Interval<int>>();
benchmark::DoNotOptimize(c);
}
}

// Mesure : Initialisation d'une cellule
template <unsigned int dim>
void CELL_init(benchmark::State& state)
{
xt::xtensor_fixed<int, xt::xshape<dim>> indices;
if constexpr (dim == 1)
{
indices = xt::xtensor_fixed<int, xt::xshape<1>>({1});
}
else if constexpr (dim == 2)
{
indices = xt::xtensor_fixed<int, xt::xshape<2>>({1, 1});
}
else if constexpr (dim == 3)
{
indices = xt::xtensor_fixed<int, xt::xshape<3>>({1, 1, 1});
}
double scaling_factor = 1.0;
for (auto _ : state)
{
if constexpr (dim == 1)
{
auto c = samurai::Cell<1, samurai::Interval<int>>({0}, scaling_factor, 1, indices, 0);
benchmark::DoNotOptimize(c);
}
else if constexpr (dim == 2)
{
auto c = samurai::Cell<2, samurai::Interval<int>>({0, 0}, scaling_factor, 1, indices, 0);
benchmark::DoNotOptimize(c);
}
else if constexpr (dim == 3)
{
auto c = samurai::Cell<3, samurai::Interval<int>>({0, 0, 0}, scaling_factor, 1, indices, 0);
benchmark::DoNotOptimize(c);
}
}
}

// Mesure : Récupération du centre d'une cellule
template <unsigned int dim>
void CELL_center(benchmark::State& state)
{
auto c = make_cell<dim>();
for (auto _ : state)
{
auto center = c.center();
benchmark::DoNotOptimize(center);
}
}

// Mesure : Récupérayion du centre de la face d'une cellule
template <unsigned int dim>
void CELL_face_center(benchmark::State& state)
{
auto c = make_cell<dim>();
for (auto _ : state)
{
auto center = c.face_center();
benchmark::DoNotOptimize(center);
}
}

// Mesure : Récupération de l'angle d'une cellule
template <unsigned int dim>
void CELL_corner(benchmark::State& state)
{
auto c = make_cell<dim>();
for (auto _ : state)
{
auto center = c.corner();
benchmark::DoNotOptimize(center);
}
}

// Mesure : Test d'égalité entre deux cellules
template <unsigned int dim>
void CELL_equal(benchmark::State& state)
{
auto c1 = make_cell<dim>();
auto c2 = make_cell<dim>();
for (auto _ : state)
{
auto is_equal = c1 == c2;
benchmark::DoNotOptimize(is_equal);
}
}

// Mesure : Test d'inégalité entre deux cellules
template <unsigned int dim>
void CELL_different(benchmark::State& state)
{
auto c1 = make_cell<dim>();
auto c2 = make_cell<dim>();
for (auto _ : state)
{
auto is_equal = c1 != c2;
benchmark::DoNotOptimize(is_equal);
}
}

BENCHMARK_TEMPLATE(CELL_default, 1);
BENCHMARK_TEMPLATE(CELL_default, 2);
BENCHMARK_TEMPLATE(CELL_default, 3);
BENCHMARK_TEMPLATE(CELL_default, 4);

BENCHMARK_TEMPLATE(CELL_init, 1);
BENCHMARK_TEMPLATE(CELL_init, 2);
BENCHMARK_TEMPLATE(CELL_init, 3);

BENCHMARK_TEMPLATE(CELL_center, 1);
BENCHMARK_TEMPLATE(CELL_center, 2);
BENCHMARK_TEMPLATE(CELL_center, 3);

BENCHMARK_TEMPLATE(CELL_corner, 1);
BENCHMARK_TEMPLATE(CELL_corner, 2);
BENCHMARK_TEMPLATE(CELL_corner, 3);

BENCHMARK_TEMPLATE(CELL_equal, 1);
BENCHMARK_TEMPLATE(CELL_equal, 2);
BENCHMARK_TEMPLATE(CELL_equal, 3);

BENCHMARK_TEMPLATE(CELL_different, 1);
BENCHMARK_TEMPLATE(CELL_different, 2);
BENCHMARK_TEMPLATE(CELL_different, 3);
Loading
Loading