KratosMultiphysics / Kratos

Kratos Multiphysics (A.K.A Kratos) is a framework for building parallel multi-disciplinary simulation software. Modularity, extensibility and HPC are the main objectives. Kratos has BSD license and is written in C++ with extensive Python interface.
https://kratosmultiphysics.github.io/Kratos/
Other
1.05k stars 246 forks source link

[External] Adding Google benchmark option in CMake #12867

Closed loumalouomega closed 2 days ago

loumalouomega commented 4 days ago

📝 Description

Related https://github.com/KratosMultiphysics/Kratos/pull/12861

This PR adds (as external download like in GTest) Google benchmark, see https://github.com/google/benchmark. It will generate one binary per file automatically detected in the benchmark folder. The executable will be in the binary benchmark folder.

It is activated with KRATOS_BUILD_BENCHMARK, which is disabled by default.

Here an example of usage:

// System includes

// External includes
#include <benchmark/benchmark.h>

// Project includes
#include "geometries/point.h"
#include "geometries/triangle_3d_3.h"
#include "utilities/geometry_utilities/nearest_point_utilities.h"

namespace Kratos
{

// Sample data for benchmarking
Point::Pointer p_point_1(make_shared<Point>( 0.0, 0.0, 0.0));
Point::Pointer p_point_2(make_shared<Point>( 1.0, 0.0, 0.0));
Point::Pointer p_point_3(make_shared<Point>( 0.0, 1.0, 0.0));

Triangle3D3<Point> triangle(p_point_1, p_point_3, p_point_2);
Point nearest_point(0.0, 0.0, 0.0);
Point inside_point(0.2, 0.1, 0.00);

static void BM_TriangleNearestPoint(benchmark::State& state) {
    for (auto _ : state) {
        NearestPointUtilities::TriangleNearestPoint(inside_point, triangle, nearest_point);
    }
}

// Register the function as a benchmark
BENCHMARK(BM_TriangleNearestPoint);

}  // namespace Kratos

BENCHMARK_MAIN();

It also includes a python script in order to compare the results (exported as json), example:

image

🆕 Changelog

loumalouomega commented 2 days ago

Could you add a kratos_add_benchmarks call into the core to compile the example maybe? or you plan to do it in another PR¿

I don't get you

roigcarlo commented 2 days ago

You add an example but its not compiling, or I am missing something?

loumalouomega commented 2 days ago

You add an example but its not compiling, or I am missing something?

Nope, because default is disabled. Can be activated to CI if you like