Skip to content
Open
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
17 changes: 13 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ jobs:
-DCMAKE_BUILD_TYPE=Release \
-DWITH_PETSC=ON \
-DBUILD_DEMOS=ON \
-DBUILD_TESTS=ON
-DBUILD_TESTS=ON \
-DSAMURAI_ENABLE_INLINE=OFF \
-DSAMURAI_ENABLE_PCH=ON \
-DSAMURAI_INSTANTIATE_TEMPLATES=ON

- name: Build
shell: bash -l {0}
Expand Down Expand Up @@ -245,7 +248,10 @@ jobs:
-DWITH_MPI=ON \
-DWITH_PETSC=ON \
-DBUILD_DEMOS=ON \
-DBUILD_TESTS=ON
-DBUILD_TESTS=ON \
-DSAMURAI_ENABLE_INLINE=OFF \
-DSAMURAI_ENABLE_PCH=ON \
-DSAMURAI_INSTANTIATE_TEMPLATES=ON

- name: Build
shell: bash -l {0}
Expand Down Expand Up @@ -352,7 +358,7 @@ jobs:
- name: Petsc installation
shell: bash -l {0}
run: |
micromamba install -y petsc pkg-config
micromamba install -y petsc pkg-config

- name: Install cxx compiler
shell: bash -l {0}
Expand All @@ -375,7 +381,10 @@ jobs:
-DCMAKE_BUILD_TYPE=Release \
-DWITH_PETSC=ON \
-DBUILD_DEMOS=ON \
-DBUILD_TESTS=ON
-DBUILD_TESTS=ON \
-DSAMURAI_ENABLE_INLINE=OFF \
-DSAMURAI_ENABLE_PCH=ON \
-DSAMURAI_INSTANTIATE_TEMPLATES=ON

- name: Build
shell: bash -l {0}
Expand Down
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ option(WITH_OPENMP "Enable OpenMP" OFF)
option(WITH_PETSC "Enable PETSc" OFF)
option(SAMURAI_ENABLE_INLINE "Enable inline keyword for performance" ON)
option(SAMURAI_FORCE_INLINE "Force aggressive inlining (takes precedence)" OFF)
option(SAMURAI_ENABLE_PCH "Enable precompiled headers for faster builds" OFF)
option(SAMURAI_INSTANTIATE_TEMPLATES "Pre-instantiate templates in shared library for demos" OFF)
option(SAMURAI_CONTAINER_LAYOUT_COL_MAJOR "Set the containers' layout to column-major" OFF)

set(FIELD_CONTAINER_LIST "xtensor" "eigen3")
Expand Down Expand Up @@ -105,6 +107,14 @@ set(INCLUDE_DIR "include") # must be relative paths
target_include_directories(samurai INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${INCLUDE_DIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")

# Precompiled headers setup
if(SAMURAI_ENABLE_PCH)
target_precompile_headers(samurai INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/demos/pch.hpp>"
)
message(STATUS "Samurai PCH enabled")
endif()

# Find dependencies:
set(DEPENDENCIES_CONFIGURED HighFive pugixml fmt CLI11)

Expand Down
10 changes: 10 additions & 0 deletions demos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Template instantiation library (optional, for faster demo compilation)
# NOTE: Uses shared library to avoid duplicate symbol linker errors
# The instantiations are compiled once and shared across all demos
if(SAMURAI_INSTANTIATE_TEMPLATES)
add_library(samurai_instantiations SHARED samurai_template_instantiations.cpp)
target_link_libraries(samurai_instantiations PUBLIC samurai)
target_compile_features(samurai_instantiations PRIVATE cxx_std_20)
message(STATUS "Template pre-instantiation enabled for demos (shared library)")
endif()

add_subdirectory(from_obj)
add_subdirectory(FiniteVolume)
# add_subdirectory(MPI)
Expand Down
10 changes: 10 additions & 0 deletions demos/FiniteVolume/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ if(${WITH_PETSC})
add_executable(${executable_name} ${source_file})
target_compile_definitions(${executable_name} PUBLIC SAMURAI_WITH_PETSC)
target_link_libraries(${executable_name} samurai ${PETSC_LINK_LIBRARIES})

# Link pre-instantiated templates if enabled
if(SAMURAI_INSTANTIATE_TEMPLATES)
target_link_libraries(${executable_name} samurai_instantiations)
endif()
endforeach()
endif()

Expand All @@ -54,6 +59,11 @@ foreach(demo_entry ${STANDARD_DEMOS})

add_executable(${executable_name} ${source_file})
target_link_libraries(${executable_name} samurai)

# Link pre-instantiated templates if enabled
if(SAMURAI_INSTANTIATE_TEMPLATES)
target_link_libraries(${executable_name} samurai_instantiations)
endif()
endforeach()

# Specific options for MSVC
Expand Down
5 changes: 5 additions & 0 deletions demos/highorder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ if(${WITH_PETSC})
add_executable(highorder main.cpp)
target_compile_definitions(highorder PUBLIC SAMURAI_WITH_PETSC)
target_link_libraries(highorder samurai ${PETSC_LINK_LIBRARIES})

# Link pre-instantiated templates if enabled
if(SAMURAI_INSTANTIATE_TEMPLATES)
target_link_libraries(highorder samurai_instantiations)
endif()
endif()
5 changes: 5 additions & 0 deletions demos/multigrid/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ if(${WITH_PETSC})
add_executable(multigrid main.cpp)
target_compile_definitions(multigrid PUBLIC SAMURAI_WITH_PETSC)
target_link_libraries(multigrid samurai ${PETSC_LINK_LIBRARIES})

# Link pre-instantiated templates if enabled
if(SAMURAI_INSTANTIATE_TEMPLATES)
target_link_libraries(multigrid samurai_instantiations)
endif()
endif()
52 changes: 52 additions & 0 deletions demos/pch.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2018-2025 the samurai's authors
// SPDX-License-Identifier: BSD-3-Clause

#pragma once

/**
* @file pch.hpp
* @brief Precompiled header for Samurai library
*
* This header includes the most frequently used Samurai components
* to accelerate compilation when PCH is enabled. Speeds up header
* parsing across all compilation units using the library.
*
* Enable via CMake: -DSAMURAI_ENABLE_PCH=ON
*/

// Core Samurai headers (alphabetical order)
#include <samurai/algorithm.hpp>
#include <samurai/bc.hpp>
#include <samurai/cell_array.hpp>
#include <samurai/field.hpp>
#include <samurai/interval.hpp>
#include <samurai/mesh.hpp>
#include <samurai/mr/adapt.hpp>
#include <samurai/mr/mesh.hpp>
#include <samurai/samurai.hpp>
#include <samurai/schemes/fv.hpp>
#include <samurai/stencil_field.hpp>
#include <samurai/subset/node.hpp>

// I/O headers
#include <samurai/io/hdf5.hpp>
#include <samurai/io/restart.hpp>

// External dependencies that are heavy
#include <xtensor/containers/xfixed.hpp>
#include <xtensor/containers/xtensor.hpp>
#include <xtensor/io/xio.hpp>

// Standard library (frequently used)
#include <algorithm>
#include <array>
#include <cmath>
#include <cstddef>
#include <filesystem>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <stdexcept>
#include <string>
#include <vector>
90 changes: 90 additions & 0 deletions demos/samurai_template_instantiations.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright 2018-2025 the samurai's authors
// SPDX-License-Identifier: BSD-3-Clause

/**
* @file samurai_template_instantiations.cpp
* @brief Explicit template instantiations for demos (shared library)
*
* This file pre-instantiates common template specializations used
* across FiniteVolume demos to reduce compilation time in each demo.
*
* Compiled as a shared library (.dylib/.so) to avoid duplicate symbol
* linker errors. The instantiations are compiled once and shared across
* all demos that link against this library.
*
* Build with: -DSAMURAI_INSTANTIATE_TEMPLATES=ON
*
* Compilation speedup: ~20-30% faster per-demo compilation
* (first-time compilation of library is ~30-60s, subsequent demos are faster)
*/

#include <samurai/algorithm.hpp>
#include <samurai/bc.hpp>
#include <samurai/cell_array.hpp>
#include <samurai/field.hpp>
#include <samurai/interval.hpp>
#include <samurai/mesh.hpp>
#include <samurai/mr/adapt.hpp>
#include <samurai/mr/mesh.hpp>
#include <samurai/samurai.hpp>
#include <samurai/schemes/fv.hpp>
#include <samurai/stencil_field.hpp>

namespace samurai
{
// ===== Interval Instantiations =====
// Core data structures that appear in every compilation unit

template struct Interval<int, signed long long int>;
template struct Interval<long, signed long long int>;

// ===== CellArray Instantiations =====
// Foundation for mesh representation across dimensions

template class CellArray<1>;
template class CellArray<2>;
template class CellArray<3>;

// ===== ScalarField Instantiations =====
// Most commonly used field type in demos

template class ScalarField<MRMesh<MRConfig<1>>, double>;
template class ScalarField<MRMesh<MRConfig<1>>, float>;

template class ScalarField<MRMesh<MRConfig<2>>, double>;
template class ScalarField<MRMesh<MRConfig<2>>, float>;

template class ScalarField<MRMesh<MRConfig<3>>, double>;
template class ScalarField<MRMesh<MRConfig<3>>, float>;

// ===== VectorField Instantiations =====
// Vector-valued field instantiations for common dimensions

template class VectorField<MRMesh<MRConfig<1>>, double, 1>;
template class VectorField<MRMesh<MRConfig<1>>, double, 2>;
template class VectorField<MRMesh<MRConfig<1>>, double, 3>;

template class VectorField<MRMesh<MRConfig<2>>, double, 1>;
template class VectorField<MRMesh<MRConfig<2>>, double, 2>;
template class VectorField<MRMesh<MRConfig<2>>, double, 3>;

template class VectorField<MRMesh<MRConfig<3>>, double, 1>;
template class VectorField<MRMesh<MRConfig<3>>, double, 2>;
template class VectorField<MRMesh<MRConfig<3>>, double, 3>;

// ===== MRAdapt Instantiations =====
// Adaptation operator for multiresolution meshes

// 1D MRAdapt with single scalar field
template auto make_MRAdapt<ScalarField<MRMesh<MRConfig<1>>, double>>(ScalarField<MRMesh<MRConfig<1>>, double>&);

// 2D MRAdapt with single scalar field (most common)
template auto make_MRAdapt<ScalarField<MRMesh<MRConfig<2>>, double>>(ScalarField<MRMesh<MRConfig<2>>, double>&);

// 2D MRAdapt with vector field
template auto make_MRAdapt<VectorField<MRMesh<MRConfig<2>>, double, 2>>(VectorField<MRMesh<MRConfig<2>>, double, 2>&);

// 3D MRAdapt with single scalar field
template auto make_MRAdapt<ScalarField<MRMesh<MRConfig<3>>, double>>(ScalarField<MRMesh<MRConfig<3>>, double>&);

} // namespace samurai
7 changes: 6 additions & 1 deletion demos/tutorial/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ foreach(demo_entry ${TUTORIAL_DEMOS})
list(GET demo_parts 1 executable_name)

add_executable(${executable_name} ${source_file})
target_link_libraries(${executable_name} PRIVATE samurai)
target_link_libraries(${executable_name} samurai)

# Link pre-instantiated templates if enabled
if(SAMURAI_INSTANTIATE_TEMPLATES)
target_link_libraries(${executable_name} samurai_instantiations)
endif()
endforeach()

# Specific options for MSVC
Expand Down
Loading