Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
21b0792
ensure that the covariance is SPD
anand-avinash Jul 10, 2026
c7133df
refactored compute_weights.cpp to retain only mpi parallelized functi…
anand-avinash Jul 10, 2026
c8928be
check during setup if compiler_so_cxx executable is needed. Newer ver…
anand-avinash Jul 10, 2026
e41ecc0
moved the computations of sin2phi and cos2phi from compute_weight_com…
anand-avinash Jul 10, 2026
632f734
moved get_pixel_mask_pol() from compute_weights.cpp to the compute_we…
anand-avinash Jul 15, 2026
635cb63
removed importing brahmap to avoid circular import; added SharedMemor…
anand-avinash Jul 15, 2026
79c7e1a
added SharedMemoryAllocator class to facilitate allocating MPI shared…
anand-avinash Jul 15, 2026
2de7cae
added an MPI shared memory based analogue of compute_weights.cpp
anand-avinash Jul 15, 2026
fff1408
implemented an MPI shared memory based analogue of ProcessTimeSamples
anand-avinash Jul 15, 2026
3eee1ac
allowed module level import of SharedMemProcessTimeSamples
anand-avinash Jul 15, 2026
fbbe377
added new extension module for compute_weights_shared
anand-avinash Jul 15, 2026
12fc0b3
added a base class for process time samples
anand-avinash Jul 15, 2026
2578e5e
updated the implementation of ProcessTimeSamples and SharedMemProcess…
anand-avinash Jul 15, 2026
020cb1b
renamed docs/api_reference/base_operators to docs/api_reference/base_…
anand-avinash Jul 15, 2026
eb2d0b1
added the pages and indices for BaseProcessTimeSamples and SharedMemP…
anand-avinash Jul 15, 2026
5a6f17c
updated the docstrings for BaseProcessTimeSamples
anand-avinash Jul 15, 2026
1fa98a2
updated the docstrings for ProcessTimeSamples and SharedMemProcessTim…
anand-avinash Jul 15, 2026
2a645cb
updated the docstrings of SharedMemoryManager
anand-avinash Jul 16, 2026
5ba22e0
updated the docstrings of class attributes in shmempts
anand-avinash Jul 16, 2026
e1a7d89
updated the docstrings of SharedMemoryManager and added to the docume…
anand-avinash Jul 16, 2026
3ed8c04
added the member functions alloc_shared_array_node and free_shared_ar…
anand-avinash Jul 16, 2026
53f6adc
replaced alloc_shared_array() to alloc_shared_array_node() in SharedM…
anand-avinash Jul 16, 2026
ebde7b0
cleaned separate_map_vectors() for np.reshape() arguments
anand-avinash Jul 16, 2026
b585941
fixed typing errors reported by pyrefly
anand-avinash Jul 16, 2026
cafe81f
added type hinting for compute_weights_shared extension
anand-avinash Jul 16, 2026
c01667a
replaced the dictionary key in the list attributes of SharedMemoryMan…
anand-avinash Jul 22, 2026
e884ee6
added tests for SharedMemoryManager and MPI_UTILS
anand-avinash Jul 22, 2026
25266ef
added docstring descriptions in mpi.py
anand-avinash Jul 22, 2026
992bb8e
added the documentation for MPI_UTILS
anand-avinash Jul 22, 2026
b8f1bd9
Added the tests for compute_weights_shared.cpp
anand-avinash Jul 22, 2026
2ca3e45
fixed the key usage for shared memory initialization; fixed integer b…
anand-avinash Jul 22, 2026
c996828
fixed the bug that was preventing tree group reduction with a deadloc…
anand-avinash Jul 22, 2026
ba50063
updated the type-hinting for compute_weights_shared()
anand-avinash Jul 22, 2026
613581f
updated the test for compute_weight_shared to supply the grp_reduce a…
anand-avinash Jul 22, 2026
8ceae87
added a test for SharedMemProcessTimeSamples
anand-avinash Jul 22, 2026
9fea926
enabled a global fixture to set the test parameters for test_linalg_t…
anand-avinash Jul 23, 2026
62f2cb9
defined a global fixture for setting the sky scan parameters for pytest
anand-avinash Jul 23, 2026
5580f1d
updated test_PointingLO_tools_cpp.py to use global setup fixture
anand-avinash Jul 23, 2026
9f90d4a
updated test_BlkDiagPrecondLO_tools_cpp.py to use global setup fixtur…
anand-avinash Jul 23, 2026
d22d381
updated test_BlkDiagPrecondLO.py to use global setup fixture
anand-avinash Jul 23, 2026
9365823
updated test_compute_weights_cpp.py to use global setup fixture
anand-avinash Jul 23, 2026
ff01ee5
updated test_compute_weights_shared_cpp.py to use global setup fixture
anand-avinash Jul 23, 2026
fcbe0d0
added the generation of constant and random maps to the setup_scan py…
anand-avinash Jul 24, 2026
f8a5eb5
updated test_GLSmapmakers.py to use global setup fixture
anand-avinash Jul 24, 2026
7bfa03b
moved linear_system fixture from test_linalg.py to common fixture_set…
anand-avinash Jul 24, 2026
7144299
updated test_PointingLO.py to use global setup fixture
anand-avinash Jul 24, 2026
ec3e669
updated test_SharedMemProcessTimeSamples.py to use global setup fixture
anand-avinash Jul 24, 2026
52526fa
updated test_ProcessTimeSamples.py to use global setup fixture
anand-avinash Jul 24, 2026
cf7a72a
updated test_repixelization_cpp.py to use global setup fixture
anand-avinash Jul 24, 2026
6d792eb
updated test_unary_functions_cpp.py to remove redundancies
anand-avinash Jul 24, 2026
f485bbd
now searching for the attribute callspec instead of parameterize to l…
anand-avinash Jul 24, 2026
34b2a6c
added decorator pytest.mark.ignore_param_count wherever needed
anand-avinash Jul 24, 2026
38d9e06
parameterized test_LBSim_GLS.py in a robust manner
anand-avinash Jul 24, 2026
d005c41
parameterized test_LBSim_noise_ops.py in a robust manner
anand-avinash Jul 24, 2026
07a8e23
fixed the type-hinting in mpi.py
anand-avinash Jul 29, 2026
1d7b93e
updated PointingLO_tools.cpp to enable MPI shared memory based comput…
anand-avinash Jul 29, 2026
4e5c545
updated PointingLO to consume SharedMemProcessTimeSamples and to allo…
anand-avinash Jul 29, 2026
ca643ea
added the stubs for shmem_PLO_rmult_* from PointingLO_tools.cpp
anand-avinash Jul 29, 2026
f1b465f
added an argument to PointingLO to specify whether to return a copy o…
anand-avinash Jul 29, 2026
1471670
added a test for the case when PointingLO uses SharedMemProcessTimeSa…
anand-avinash Jul 29, 2026
39e98be
refactored the test TestPointingLO_Cpp
anand-avinash Jul 29, 2026
8d7fbd0
Added type-hints for SharedMemProcessTimeSamples in BlockDiagonalPrec…
anand-avinash Jul 30, 2026
ed71d37
refactored test_BlkDiagPrecondLO.py and added the test for a case whe…
anand-avinash Jul 30, 2026
1d425b9
added the test for shared memory cpp functions for pointing operator
anand-avinash Jul 30, 2026
001bfc2
documentation udpates and beautification
anand-avinash Jul 30, 2026
c8b6f48
added open in colab badge for the example notebooks
anand-avinash Jul 31, 2026
cac702a
added the option for returning a shared memory buffer as the product …
anand-avinash Jul 31, 2026
40dda29
updated TestShMemBlkDiagPrecondLO to include the case when the block-…
anand-avinash Jul 31, 2026
ac973f2
added return_copy as the class property
anand-avinash Jul 31, 2026
7327b5d
added options to the gls map-making functions to enable using mpi sha…
anand-avinash Jul 31, 2026
4bbee4f
added tests for mpi shared memory versions of gls map-making functions
anand-avinash Jul 31, 2026
6cbd2ef
added a mpi shared memory version of LBSimProcessTimeSamples
anand-avinash Jul 31, 2026
277fb61
updated the lbsim interface to gls map-making to allow using mpi shar…
anand-avinash Jul 31, 2026
5ce413b
added the tests for the mpi shared memory version of lbsim gls map-maker
anand-avinash Jul 31, 2026
150491c
updated docstrings and test params
anand-avinash Jul 31, 2026
1ad68ba
fixed the docstring reference
anand-avinash Jul 31, 2026
0f04340
added documentations for LBSimSharedMemProcessTimeSamples
anand-avinash Jul 31, 2026
a463f96
reduced the number of cg iterations in tests
anand-avinash Jul 31, 2026
d843927
added pre and post synchronization of tests in mpi environment using …
anand-avinash Aug 1, 2026
b872862
now shared memory allocator on cpp side initializes the allocated arr…
anand-avinash Aug 1, 2026
66aab77
Merge remote-tracking branch 'origin/main' into shmem
anand-avinash Aug 1, 2026
590d744
shifted the barrier from cpp shared memory allocator to the location …
anand-avinash Aug 1, 2026
0897841
added --tb=short option to pytest
anand-avinash Aug 1, 2026
86ebbbb
restrict the macos runner for github action to use max 2 mpi processes
anand-avinash Aug 1, 2026
75af279
updated the versions used in github actions
anand-avinash Aug 1, 2026
d32f14e
updated documentation layout and formatting
anand-avinash Aug 1, 2026
ccb3c8a
added timeout for the github test action
anand-avinash Aug 1, 2026
a77c7b7
added fence() as the class method for SharedMemoryAllocator class on …
anand-avinash Aug 1, 2026
14f16c9
replace barrier with fence before local accumulation function calls i…
anand-avinash Aug 1, 2026
f8dde3f
added global fence method to SharedMemoryManager for a given communic…
anand-avinash Aug 4, 2026
19b7a94
added benchmark test for compute_weights_shared extension
anand-avinash Aug 4, 2026
3c10cff
renamed alloc_shared_array_comm() to alloc_shared_comm(); alloc_share…
anand-avinash Aug 4, 2026
e2ecf2a
updated the function calls alloc_shared_array_node() with alloc_share…
anand-avinash Aug 4, 2026
5c6a9bf
updated the function calls alloc_shared_array_nodes() with alloc_shar…
anand-avinash Aug 4, 2026
d890f12
updated the function calls alloc_shared_array_nodes() with alloc_shar…
anand-avinash Aug 4, 2026
f282d00
updated the function calls alloc_shared_array_node() with alloc_share…
anand-avinash Aug 4, 2026
71b4510
added a destructor to SharedMemoryManager and removed the destructor …
anand-avinash Aug 4, 2026
d37b4ca
updated test_mpi.py to use the renamed mpi shared memory allocation f…
anand-avinash Aug 4, 2026
2966377
fixed the fence calls in linearoperator.py and compute_weights_shared…
anand-avinash Aug 4, 2026
5fd96e4
removed the destructor from SharedMemoryManager; and added a method t…
anand-avinash Aug 4, 2026
fc4179a
updated the gls wrappers to call free_shmem_arrays() method of shared…
anand-avinash Aug 4, 2026
643f059
added the calls to free the shared memory arrays in pytest in order t…
anand-avinash Aug 4, 2026
fe0e607
added tests for alloc_shared_zeros_comm() and alloc_shared_ones_comm(…
anand-avinash Aug 4, 2026
1161eed
updated the test script to evaluate the test status correctly
anand-avinash Aug 4, 2026
b87398e
fixed inconsistent shared memory fence calls and tree grp memory allo…
anand-avinash Aug 5, 2026
e6f917b
added the test benchmarks for compute_weights_shared extension
anand-avinash Aug 5, 2026
e264b62
added a new method free_all_resources() to the shared memory manager …
anand-avinash Aug 5, 2026
f5845d8
added a fixture to benchmarks conftest.py to fix the number of rounds…
anand-avinash Aug 5, 2026
c17a1ed
updated test_bench_extensions.py to use mpi_benchmark wherever necces…
anand-avinash Aug 5, 2026
4da33c6
added benchmark tests for shared memory pointing operator
anand-avinash Aug 5, 2026
1056721
updated the benchmark documentation; added the details of new fixture…
anand-avinash Aug 5, 2026
1005e10
updated test_bench_core.py to use mpi_benchmark fixture
anand-avinash Aug 5, 2026
d091583
added benchmark tests for the shared memory version of process time s…
anand-avinash Aug 5, 2026
8b510d3
added the support to call the teardown function for mpi_benchmark fix…
anand-avinash Aug 5, 2026
4373f33
used teardown function in test_bench_core to free shared memory usage…
anand-avinash Aug 5, 2026
b1a5a8c
added the benchmark test for lbsim shared memory process time samples…
anand-avinash Aug 5, 2026
5048437
added a fixture in benchmark conftest to capture nproc_reduce argument
anand-avinash Aug 5, 2026
13bfa5b
updated relevant benchmark tests to accept nproc_reduce argument from…
anand-avinash Aug 5, 2026
8848373
updated the benchmark docs to add the option for nproc_reduce
anand-avinash Aug 5, 2026
332057e
removed grp_reduce argument from all the function calls; now grp comm…
anand-avinash Aug 6, 2026
d961ad3
removed grp_reduce argument from all function calls to pointinglo ext…
anand-avinash Aug 6, 2026
b24cfbc
removed grp_reduce arguments from tests
anand-avinash Aug 6, 2026
c30a6ac
removed grp_reduce property from shared memory manager class and remo…
anand-avinash Aug 6, 2026
14469ca
removed the conditional allocation of grp level arrays from pointingl…
anand-avinash Aug 6, 2026
849243b
set OMP_NUM_THREADS=1 in test script to prevent overusing and stall w…
anand-avinash Aug 6, 2026
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
6 changes: 3 additions & 3 deletions .github/workflows/documentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ jobs:
if: "!contains(github.event.head_commit.message, 'skip docs')"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5.0.0
- uses: actions/checkout@v7
- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- uses: actions/setup-python@v6.0.0
- uses: actions/setup-python@v7
with:
python-version: 3.11
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- uses: actions/cache@v4.3.0
- uses: actions/cache@v6
with:
key: mkdocs-material-${{ env.cache_id }}
path: .cache
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:
test:
if: "!contains(github.event.head_commit.message, 'skip ci')"
runs-on: ${{ matrix.os }}
timeout-minutes: 30

env:
MACOSX_DEPLOYMENT_TARGET: "10.15" # To be removed when support for Python 3.11 is dropped
Expand All @@ -23,17 +24,17 @@ jobs:

steps:
- name: Checkout BrahMap repository
uses: actions/checkout@v6.0.2
uses: actions/checkout@v7
with:
submodules: true

- name: Install MPI - ${{ matrix.mpi }}
uses: mpi4py/setup-mpi@v1.4.2
uses: mpi4py/setup-mpi@v1.4.4
with:
mpi: ${{ matrix.mpi }}

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6.2.0
uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python-version }}

Expand Down
3 changes: 3 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ repos:
hooks:
- id: check-toml
- id: check-yaml
args: [--unsafe]
- id: check-merge-conflict

- repo: local
Expand All @@ -37,3 +38,5 @@ repos:
name: Building the markdown documentation with `mkdocs build`
entry: bash -c 'mkdocs build'
language: system
pass_filenames: false
require_serial: true
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
![BrahMap documentation build status](https://github.com/anand-avinash/BrahMap/actions/workflows/documentation.yaml/badge.svg)
<!-- markdownlint-enable MD013 -->

<!-- markdownlint-disable MD033 -->
<font color="red"> **This project is currently under active development!!!** </font>
<!-- markdownlint-enable MD033 -->

`BrahMap` is a scalable and modular map-making framework for CMB experiments.
It features a user-friendly Python interface for the linear operators used in
map-making. The Python interface seamlessly handles the workflow while
Expand All @@ -43,8 +39,9 @@ For a complete reference to the `BrahMap` API, refer to the
Complete example notebooks and scripts can be
[found here](./examples).

You can find detailed information on the implementation and features of
`BrahMap` at [arXiv:2501.16122](https://arxiv.org/abs/2501.16122).
For detailed information on the implementation and features of `BrahMap`,
please refer to the paper
[arXiv:2501.16122](https://arxiv.org/abs/2501.16122).

## Installation

Expand Down Expand Up @@ -91,7 +88,7 @@ of its numerical routines and linear operators. The benchmarks are based on
`pytest-benchmark` and support both serial and MPI-parallel execution.

For detailed instructions on how to run and customize the benchmarks, refer to
the [benchmarks documentation](./benchmarks/README.md).
the [benchmarks documentation](./benchmarks).

## Citation

Expand All @@ -100,7 +97,7 @@ This work can be cited with:
<!-- markdownlint-disable MD013 -->
```text
@misc{anand2025brahmap,
title={\texttt{BrahMap}: A scalable and modular map-making framework for the CMB experiments},
title={BrahMap: A scalable and modular map-making framework for the CMB experiments},
author={Avinash Anand and Giuseppe Puglisi},
year={2025},
eprint={2501.16122},
Expand Down
67 changes: 48 additions & 19 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<!-- markdownlint-disable MD013 -->

# Benchmarking BrahMap

This directory contains scripts for benchmarking the performance of BrahMap components. While the benchmark scripts are primarily designed for serial execution, they can also be used for parallel execution with `mpirun/mpiexec`, though one has to be careful while saving the benchmark results.
Expand Down Expand Up @@ -55,12 +57,16 @@ This allows for quick sanity checks with `small` or more robust performance meas

You can override specific parameters regardless of the `--size` flag:

| Option | Values | Description |
| :-------------- | :------------------- | :-------------------------------------------------------- |
| `--nside` | e.g. `128` | Sets $N_{side}$ (overrides npix) |
| `--nsamples` | e.g. `1000000` | Sets global number of samples (overrides global nsamples) |
| `--dtype-float` | `float32`, `float64` | Sets floating point precision (default: float64) |
| `--dtype-int` | `int32`, `int64` | Sets integer precision (default: int64) |
| Option | Values | Description |
| :----------------- | :------------------- | :-------------------------------------------------------- |
| `--nside` | e.g. `128` | Sets $N_{side}$ (overrides npix) |
| `--nsamples` | e.g. `1000000` | Sets global number of samples (overrides global nsamples) |
| `--dtype-float` | `float32`, `float64` | Sets floating point precision (default: float64) |
| `--dtype-int` | `int32`, `int64` | Sets integer precision (default: int64) |
| `--mpi-rounds` | e.g. `20` | Sets number of rounds for `mpi_benchmark` (default: 20) |
| `--mpi-iterations` | e.g. `1` | Sets iterations per round for `mpi_benchmark` (default: 1) |
| `--mpi-warmup-rounds` | e.g. `0` | Sets number of warmup rounds for `mpi_benchmark` (default: 0)|
| `--nproc-reduce` | e.g. `1` | Sets the size of each sub-communicator group witin the node-level communicator (default: 1) |

Example usage:

Expand All @@ -84,6 +90,15 @@ pytest-benchmark compare results_v1.json results_v2.json

This will show a detailed comparison table with percentage differences. You can also use the option `--sort=...` to sort the comparison results.

### Rounds vs. Iterations

- **Iterations (per round):** The number of times the function is called consecutively **within a single timed measurement round**. The iteration count should be set according to the function being benchmarked:
- For fast functions (taking microseconds), a higher value (e.g., `100` or `1000`) is more suitable to amortize timing overhead.
- For computationally heavy/slower functions (taking milliseconds/seconds), a lower value (e.g., `1` or `5`) is sufficient.
- For MPI-related benchmarks, the default number of iterations is `1`. It can be overridden using `--mpi-iterations=<num_iterations>`.
- **Rounds:** The number of independent measurements taken to compute statistics. A round **constitutes a single timed measurement event**. This should be set to achieve a balance between total run time and the statistical stability of the measurements.
- For MPI-related tests, the default number of rounds is `20`. It can be overridden using `--mpi-rounds=<num_rounds>`.

## Parallel Execution (with MPI)

To run benchmarks in parallel:
Expand All @@ -102,22 +117,36 @@ For collective operations (like `*_rmult`), it is recommended to call the indivi

New benchmarks should follow the class-based structure as in `test_bench_extensions.py`. This groups related benchmarks in the final report.

### 1. Choosing the Right Benchmark Fixture

When writing a benchmark, request the appropriate fixture depending on the operations being measured:

- **`benchmark` (Standard):** For non-MPI / local operations (e.g. math functions, local matrix multiplications). It uses dynamic calibration to scale rounds and iterations automatically.

- **`mpi_benchmark` (Custom):** For collective MPI or shared-memory operations (e.g., projection operators, weight computation). It uses fixed numbers of rounds and iterations (default: 20 rounds of 1 iteration) to prevent rank desynchronization.

### 2. Writing the Benchmark Code

```python
# Case A: Standard local benchmark using 'benchmark'
@pytest.mark.benchmark(group="extensions::my_group")
class TestMyComponent:
def test_bench_my_function_1(self, benchmark, data):
# Setup randomized buffers using the module-level data fixture
rng = data["rng"]
vec = rng.random(data["npix"]).astype(data["dtype_float"])

# Run benchmark
benchmark(my_function1, vec)
def test_bench_my_function(self, benchmark, data):
vec = data["rng"].random(data["npix"]).astype(data["dtype_float"])
benchmark(my_function, vec)

def test_bench_my_function_2(self, benchmark, data):
# Setup randomized buffers using the module-level data fixture
rng = data["rng"]
vec = rng.random(data["npix"]).astype(data["dtype_float"])
# Case B: MPI collective benchmark using 'mpi_benchmark' with setup reset
@pytest.mark.benchmark(group="extensions::my_group")
class TestMyMPIComponent:
def test_bench_my_mpi_function(self, mpi_benchmark, data):
prod = np.zeros(data["npix"])
vec = data["rng"].random(data["npix"]).astype(data["dtype_float"])

# Run benchmark
benchmark(my_function2, vec)
# Setup runs before each round to reset arrays and prevent numerical
# overflow
def setup():
prod.fill(0)
return (data["npix"], vec, prod), {}

mpi_benchmark(my_mpi_function, setup=setup)
```
78 changes: 78 additions & 0 deletions benchmarks/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,39 @@ def pytest_addoption(parser):
type=int,
help="Nside for the healpix map",
)
parser.addoption(
"--mpi-rounds",
action="store",
type=int,
default=20,
help="Number of rounds for mpi_benchmark",
)
parser.addoption(
"--mpi-iterations",
action="store",
type=int,
default=1,
help="Number of iterations for mpi_benchmark",
)
parser.addoption(
"--mpi-warmup-rounds",
action="store",
type=int,
default=0,
help="Number of warmup rounds for mpi_benchmark",
)
parser.addoption(
"--nproc-reduce",
action="store",
type=int,
default=1,
help="Number of processes used in parallel Reduction within nodes for shared memory mode",
)


@pytest.fixture(scope="session")
def nproc_reduce(request):
return request.config.getoption("--nproc-reduce")


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -95,3 +128,48 @@ def pytest_report_header(config):
def pytest_benchmark_update_machine_info(config, machine_info):
"""Add resolved benchmark parameters to the JSON report."""
machine_info["benchmark_params"] = _resolve_params(config)


@pytest.fixture
def mpi_benchmark(benchmark, request):
"""A fixture to enable pedantic benchmark in order to enforce fixed
iterations and rounds across all MPI ranks.
"""
# For a generic benchmark, the rounds and the iterations are determined
# individually by each MPI process. If the number of iterations or the
# rounds are not equal across all MPI ranks, the standard benchmark runs
# in segmentation faults. Setting the rounds and the iterations to the
# same value for all MPI ranks avoids this issue.

# Retrieve default CLI overrides
cli_rounds = request.config.getoption("--mpi-rounds")
cli_iterations = request.config.getoption("--mpi-iterations")
cli_warmup = request.config.getoption("--mpi-warmup-rounds")

def _run(func, *args, **kwargs):
# Extract benchmark configuration, defaulting to CLI values (or their defaults)
rounds = kwargs.pop("rounds", cli_rounds)
iterations = kwargs.pop("iterations", cli_iterations)
warmup_rounds = kwargs.pop("warmup_rounds", cli_warmup)
setup = kwargs.pop("setup", None)
teardown = kwargs.pop("teardown", None)

# Setup function when used in benchmark.pedantic, can also be used to
# supply the benchmark parameters. The setup functions is called at
# the first iteration of every round. In some of the cases, we need
# to supply the zero-ed arrays as the function/class arguments every
# once in a while to prevent overflow/underflow. There, we can use
# the setup argument to do so (for example, in `test_bench_extensions.py`)
# See <https://pytest-benchmark.readthedocs.io/en/latest/pedantic.html#reference>
return benchmark.pedantic(
func,
args=args,
kwargs=kwargs,
setup=setup,
teardown=teardown,
iterations=iterations,
rounds=rounds,
warmup_rounds=warmup_rounds,
)

return _run
Loading
Loading