Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
2287 commits
Select commit Hold shift + click to select a range
2065cd0
need mp4py after all
boeschf Dec 18, 2024
0ac81cf
record mpi4py version during build and warn during runtime if not equ…
boeschf Dec 19, 2024
179c7ed
CI: generate requirements-test.txt dynamically; CMake: configure mpi4…
boeschf Dec 19, 2024
fd9e337
properly generate mpi4py header as custom command and custom target
boeschf Dec 19, 2024
bc5e02e
unconditionally request mpi4py for python build
boeschf Dec 19, 2024
dbb3905
pip: user install
boeschf Dec 19, 2024
4b3b104
need ninja
boeschf Dec 19, 2024
f017a3e
need python-dev again?
boeschf Dec 19, 2024
e2a18dc
no need for action
boeschf Dec 19, 2024
bf60bd8
deleted too much
boeschf Dec 19, 2024
a632e2d
no pip upgrade
boeschf Dec 19, 2024
2ec12dc
simplification: remove build dependency on MPI4PY
boeschf Dec 20, 2024
a1d712c
review suggestion: improve find_python_module cmake script to include…
boeschf Dec 20, 2024
8f6f70c
minimum requirements
boeschf Dec 20, 2024
a124f54
cleanup
boeschf Dec 20, 2024
7f90f33
Add support for bool, int32, int64 in python bindings
tehrengruber Jan 4, 2025
fa0e227
Add tests
tehrengruber Jan 4, 2025
6ef0e7f
Small fix
tehrengruber Jan 5, 2025
c37725c
Merge pull request #176 from boeschf/bump-to-0.4.1
boeschf Jan 6, 2025
c08f987
Merge pull request #177 from havogt/enable_deploy_workflow
boeschf Jan 6, 2025
7077201
use same version for downloading
boeschf Jan 6, 2025
08ba21e
Merge pull request #179 from boeschf/fix/pypi_deploy
boeschf Jan 6, 2025
20de84e
Fix clang compilation error by increasing allowed template depth
tehrengruber Jan 18, 2025
f7ca381
Remove superfluous include
tehrengruber Jan 18, 2025
1b6453b
Fix clang compilation error by increasing allowed bracket depth
tehrengruber Jan 18, 2025
37ab905
Fix issue with int64 on macOS. `py_dtype_to_cpp_name` returns "long l…
tehrengruber Mar 19, 2025
d55498d
Bump submodules
tehrengruber Sep 23, 2025
bea8237
Merge pull request #178 from tehrengruber/bindings_add_bool_int_support
boeschf Sep 30, 2025
b4d486f
Merge pull request #181 from tehrengruber/bump_submodules
boeschf Oct 1, 2025
026cf0d
first few edits
nfarabullini Oct 14, 2025
ec06e95
further edits and fixes
nfarabullini Oct 15, 2025
7efe19c
parallel geometry tests
nfarabullini Oct 15, 2025
f629c32
interpolation mpi tests
nfarabullini Oct 15, 2025
158b5e2
Merge branch 'main' into parallel_impl
nfarabullini Oct 15, 2025
1800282
Merge branch 'main' of https://github.com/C2SM/icon4py into parallel_…
nfarabullini Oct 15, 2025
c976563
Merge branch 'parallel_impl' of https://github.com/C2SM/icon4py into …
nfarabullini Oct 15, 2025
3942340
small edits
nfarabullini Oct 16, 2025
1ec21c4
small import edit
nfarabullini Oct 16, 2025
37f6ba7
pre-commit edits
nfarabullini Oct 16, 2025
69aff63
Merge branch 'main' into parallel_impl
nfarabullini Oct 16, 2025
878789f
edits following review
nfarabullini Oct 16, 2025
661db6e
Merge branch 'main' into parallel_impl
nfarabullini Oct 16, 2025
9f87485
metrics_parallel
nfarabullini Oct 16, 2025
144891b
removed import
nfarabullini Oct 16, 2025
d13b689
ran pre-commit
nfarabullini Oct 16, 2025
ea677cd
test - fixes down to assertion errors
Oct 21, 2025
585b584
fixes
nfarabullini Oct 21, 2025
8a027dc
edits for tests and others
nfarabullini Oct 22, 2025
d64104e
Merge branch 'main' into parallel_impl
nfarabullini Oct 22, 2025
bb41cbd
pre-commit edits
nfarabullini Oct 22, 2025
41caa22
import fixes and small refactoring
nfarabullini Oct 22, 2025
a74dd89
more edits and small refactoring
nfarabullini Oct 23, 2025
f43dd34
first commit lsq standalone
Oct 24, 2025
bb7a9c1
Merge branch 'ajocksch_lsq' of https://github.com/C2SM/icon4py into p…
nfarabullini Oct 24, 2025
ab3075f
edits following review
nfarabullini Oct 31, 2025
8a1f7c4
further edits for fixes
nfarabullini Oct 31, 2025
223af41
Merge branch 'main' into parallel_impl
nfarabullini Nov 3, 2025
1fbcd7b
fixes for interpolation exchange
nfarabullini Nov 5, 2025
9bce637
fixes for metrics exchange and other refactoring
nfarabullini Nov 5, 2025
7db647d
small import fix
nfarabullini Nov 5, 2025
fda4951
Merge branch 'main' into parallel_impl
nfarabullini Nov 5, 2025
2f5ac36
Merge branch 'parallel_impl' of https://github.com/C2SM/icon4py into …
nfarabullini Nov 5, 2025
e92056a
Merge branch 'main' into parallel_impl
nfarabullini Nov 11, 2025
fc6b6a0
Merge branch 'main' into parallel_impl
nfarabullini Nov 11, 2025
ae2274e
very small edits to fix issues
nfarabullini Nov 11, 2025
76dd483
update ghex to master
Nov 11, 2025
b4cb52c
do exchange on FieldProviderLevel
Nov 11, 2025
9c9c6b1
use constants from attrs in test parametrization
Nov 12, 2025
7fd386e
create inplace 2d view of the field for exchange
Nov 12, 2025
a7aad80
Merge branch 'main' into parallel_impl
nfarabullini Nov 12, 2025
aebe29a
Merge branch 'main' into parallel_impl
nfarabullini Nov 12, 2025
34f6e16
small typ hint edit
nfarabullini Nov 12, 2025
b6bf19d
revert small layout change
Nov 13, 2025
26ac1a5
change the local order of e2c2e to match icon, this fixes the computa…
Nov 13, 2025
a840479
Merge branch 'main' into fix_e_flx_average_or_e2c2c
Nov 13, 2025
f5cda28
Merge branch 'main' into parallel_impl
nfarabullini Nov 14, 2025
c8b5cd7
edits for interpolation and metrics wrt new configuration
nfarabullini Nov 14, 2025
bfdc370
fix explicit numpy usage
Nov 14, 2025
b8d7e28
Merge branch 'fix_e_flx_average_or_e2c2c' of https://github.com/C2SM/…
nfarabullini Nov 14, 2025
d5b528e
edits for geometry and others wrt new configuration
nfarabullini Nov 14, 2025
e47602d
Merge branch 'main' into parallel_impl
nfarabullini Nov 14, 2025
83acedf
review fixes
Nov 17, 2025
15d3890
Merge branch 'main' into fix_e_flx_average_or_e2c2c
Nov 17, 2025
319bd21
Merge branch 'fix_e_flx_average_or_e2c2c' of https://github.com/C2SM/…
nfarabullini Nov 17, 2025
ced9aa7
edits for inverse geometry attrs
nfarabullini Nov 17, 2025
135f863
edit to parallel metrics test
nfarabullini Nov 17, 2025
36eabd8
fix numpy conversion after extraction for function
Nov 17, 2025
184eeff
Merge branch 'fix_e_flx_average_or_e2c2c' of https://github.com/C2SM/…
nfarabullini Nov 17, 2025
a700436
uv lock change wrt other PR
nfarabullini Nov 17, 2025
05736f2
small edit to import construct
nfarabullini Nov 17, 2025
46bfa24
further edits
nfarabullini Nov 17, 2025
c6f5777
reverted edit
nfarabullini Nov 17, 2025
b7adb35
added marker
nfarabullini Nov 17, 2025
8d8ea30
some edits
nfarabullini Nov 17, 2025
1015b7d
ran pre-commit
nfarabullini Nov 17, 2025
7c0c0be
Merge branch 'main' into parallel_impl
nfarabullini Nov 17, 2025
7e3aa22
Merge branch 'parallel_impl' of github.com:C2SM/icon4py into parallel…
Nov 17, 2025
13f43a5
remove domain arg from InverseFieldProvider
Nov 17, 2025
46cc0eb
revert wrong dimension in c_bln_avg
Nov 17, 2025
125335f
edits wrt main
nfarabullini Nov 17, 2025
6267b7d
Merge branch 'parallel_impl' of github.com:C2SM/icon4py into parallel…
Nov 17, 2025
eceb021
added marker
nfarabullini Nov 17, 2025
6e66193
ran pre-commit
nfarabullini Nov 17, 2025
679bcef
rename fixtures use _from_savepoint instead of parallel as they could…
Nov 17, 2025
eeb0cbf
add halo exchange callback to compute_mass_conserving_bilinear_cell_a…
Nov 18, 2025
4a37438
pre-commit and typing fixes
Nov 18, 2025
e68d568
Merge branch 'parallel_impl' of github.com:C2SM/icon4py into parallel…
Nov 18, 2025
8f39203
Apply suggestion from @havogt
nfarabullini Nov 18, 2025
d93367d
c_bln_avg
Nov 18, 2025
93f5174
Merge branch 'parallel_impl' of github.com:C2SM/icon4py into parallel…
Nov 18, 2025
467d1fe
remove copies in c_bln_avg computation
Nov 18, 2025
fb126b4
edits for e_flx_avg
nfarabullini Nov 19, 2025
333acc8
Merge branch 'main' into parallel_impl
nfarabullini Nov 19, 2025
3f8ffd3
grg edits for regular interpolation
nfarabullini Nov 19, 2025
e5a84a6
grg edits for parallel interpolation
nfarabullini Nov 19, 2025
8759da0
Merge branch 'main' into parallel_impl
nfarabullini Nov 19, 2025
16189c1
pre-commit edits
nfarabullini Nov 19, 2025
4ab4dd9
some edits
nfarabullini Nov 21, 2025
3d61a96
added tests for non halo field
nfarabullini Nov 21, 2025
005a996
fixes
nfarabullini Nov 21, 2025
cbe5703
Merge branch 'main' into parallel_impl
nfarabullini Nov 24, 2025
3c7043d
other edits
nfarabullini Nov 24, 2025
eb1f80b
test edits
nfarabullini Nov 24, 2025
7ce51e7
geometry tests
nfarabullini Nov 24, 2025
b3058e3
Merge branch 'parallel_impl' of https://github.com/C2SM/icon4py into …
nfarabullini Nov 24, 2025
8c8fd65
Merge branch 'main' into parallel_impl
nfarabullini Nov 24, 2025
9caf706
use max_over in metric_fields.py
Nov 25, 2025
84e9afc
edits for things to run
nfarabullini Nov 25, 2025
9bd1f31
Merge branch 'main' into parallel_impl
nfarabullini Nov 25, 2025
666d2e1
cleanup
nfarabullini Nov 25, 2025
2ec4c41
Merge branch 'parallel_impl' of https://github.com/C2SM/icon4py into …
nfarabullini Nov 25, 2025
d4885ed
Merge branch 'parallel_impl' of github.com:C2SM/icon4py into parallel…
Nov 26, 2025
5e9223f
fix test_metrics fields
Nov 26, 2025
5c92430
remove halo exchange from geometry that is not needed
Nov 26, 2025
789e1eb
add two test cases in metrics fields
Nov 26, 2025
3b59991
add halo_exchange for rho_ref_me and theta_ref_me
Nov 26, 2025
9baea9f
remove obsolete TODO
Nov 27, 2025
5bd1e11
edits following review
nfarabullini Nov 27, 2025
8991cd9
remove equal_nan
Nov 27, 2025
def072a
make geofac_grg validate - add exchange to c_lin_e
Nov 27, 2025
a8e6b02
move exchange_buffer function to decomposition, fix imports in defini…
Nov 28, 2025
d698fff
change exchange pattern for Numpy functions: geofac_n2s
Nov 28, 2025
62c6cb1
change exchange pattern for Numpy functions: geofac_n2s, geofac_grg
Nov 28, 2025
05a7fb7
change exchange pattern for Numpy functions: cell_average_weight, e_f…
Nov 28, 2025
1206758
edits following review
nfarabullini Nov 28, 2025
09fc335
Merge branch 'main' into parallel_impl
nfarabullini Nov 28, 2025
d886638
ran pre-commit
nfarabullini Nov 28, 2025
a66d5a5
Merge branch 'parallel_impl' of https://github.com/C2SM/icon4py into …
nfarabullini Nov 28, 2025
39c8afd
ran pre-commit
nfarabullini Nov 28, 2025
5348e14
change exchange pattern for Numpy functions: cells_aw_verts, pos_on_t…
Nov 28, 2025
7c67708
change exchange pattern for Numpy functions: rbfs
Nov 28, 2025
9e074fd
Merge branch 'parallel_impl' of github.com:C2SM/icon4py into parallel…
Nov 28, 2025
3103aba
remove unused imports
Nov 28, 2025
abcabb8
added global min reduction
nfarabullini Dec 1, 2025
4619251
made `do_exchange=True,` explicit
nfarabullini Dec 1, 2025
fd80c9b
ran pre--commit
nfarabullini Dec 1, 2025
9e0ba60
add exchange config in geometry.py everywhere
Dec 1, 2025
ca7f725
add exchange config in geometry.py everywhere
Dec 1, 2025
0578072
merge without reductions - should go to another PR
Dec 1, 2025
f244461
fix metrics: change exner_exfac (WIP)
Dec 1, 2025
ff8cbad
fix typing
Dec 2, 2025
6bf6d2b
add exchange to composite FieldSource to avoid usage of default
Dec 2, 2025
1043c46
Revert "added global min reduction"
nfarabullini Dec 2, 2025
7d9000a
added `global_min` reduction
nfarabullini Dec 2, 2025
0e4068a
fix diffusion fields
Dec 2, 2025
0d5bbb9
Merge branch 'parallel_impl' of github.com:C2SM/icon4py into parallel…
Dec 2, 2025
6544cb2
fix Squence import
Dec 2, 2025
7085805
fix Squence import, pre-commit
Dec 2, 2025
6fd1b76
cleanup for dummy_exchange
nfarabullini Dec 2, 2025
fd808c2
Merge branch 'parallel_impl' of https://github.com/C2SM/icon4py into …
nfarabullini Dec 2, 2025
6e8b868
edit to accoutn for mpi4py in global reduction
nfarabullini Dec 2, 2025
13665b3
small fixings: typings, add halo exchange for z_me in compute_flat_id…
Dec 2, 2025
3552aad
local dummy callable import
Dec 2, 2025
6a145c9
merge with upstream
Dec 2, 2025
06b9be6
set `do_exchange` to False
nfarabullini Dec 3, 2025
b06a8b1
Merge branch 'parallel_impl' into global_min_reduction
nfarabullini Dec 3, 2025
531832b
removed unused import
nfarabullini Dec 3, 2025
7980164
handle arrays directly in exchange
Dec 3, 2025
690735b
edits following review
nfarabullini Dec 4, 2025
beff174
Merge branch 'parallel_impl' into global_min_reduction
nfarabullini Dec 4, 2025
975e09c
remove duplicate
Dec 4, 2025
48b49a6
remove needs_exchange protocol from numpy data provider
Dec 4, 2025
5db8dd2
move resetting of duplicated indices to test data
Dec 4, 2025
c853076
Merge branch 'main' into parallel_impl
Dec 4, 2025
903cff7
Update model/common/src/icon4py/model/common/decomposition/mpi_decomp…
nfarabullini Dec 4, 2025
5ee409b
Update model/common/src/icon4py/model/common/metrics/metric_fields.py
nfarabullini Dec 4, 2025
ad9e9ab
edits following review
nfarabullini Dec 4, 2025
1c541ac
Update model/common/src/icon4py/model/common/decomposition/definition…
nfarabullini Dec 4, 2025
963ae78
Update model/common/src/icon4py/model/common/decomposition/definition…
nfarabullini Dec 4, 2025
309b374
Update model/common/src/icon4py/model/common/decomposition/definition…
nfarabullini Dec 4, 2025
6482b0d
Update model/common/src/icon4py/model/common/decomposition/mpi_decomp…
nfarabullini Dec 4, 2025
4ede44e
Update model/common/src/icon4py/model/common/decomposition/mpi_decomp…
nfarabullini Dec 4, 2025
43af549
Update model/common/src/icon4py/model/common/decomposition/mpi_decomp…
nfarabullini Dec 4, 2025
90a13c2
edits following review
nfarabullini Dec 4, 2025
29f6dd4
Merge branch 'parallel_impl' into global_min_reduction
nfarabullini Dec 4, 2025
fb1278d
fix np / cupy issue
Dec 5, 2025
87ee7c7
remove unused imports
Dec 5, 2025
02d20fb
use gt4py program in test_mpi_decomposition.py for simply sparse fiel…
Dec 5, 2025
6ca8e94
delete debug print statement
Dec 5, 2025
3d7821b
delete debug print statement
Dec 5, 2025
397c581
pre-commit
Dec 5, 2025
6efefe7
re add local min computation
Dec 5, 2025
6c42b44
Merge branch 'parallel_impl' into global_min_reduction
nfarabullini Dec 15, 2025
cfe3f10
Merge branch 'main' into global_min_reduction
nfarabullini Dec 15, 2025
62891bd
ran pre-commit
nfarabullini Dec 15, 2025
30f8a98
fix for test
nfarabullini Dec 15, 2025
5250ef8
edit to data type
nfarabullini Dec 15, 2025
26b2d0a
Merge branch 'main' into global_min_reduction
nfarabullini Dec 17, 2025
2054228
Merge branch 'main' into global_min_reduction
nfarabullini Dec 17, 2025
fc0720f
small edit
nfarabullini Dec 18, 2025
8a83cf5
added tutorial link
nfarabullini Dec 18, 2025
89d03e2
Merge branch 'main' into global_min_reduction
nfarabullini Dec 19, 2025
cffc977
Merge branch 'global_min_reduction' of https://github.com/C2SM/icon4p…
nfarabullini Jan 9, 2026
064d838
initial commit for mpi red funcs
nfarabullini Jan 9, 2026
168f10d
Merge branch 'main' into global_min_reduction
nfarabullini Jan 9, 2026
7c3b7a2
eidt for global min and metric fields tests
nfarabullini Jan 13, 2026
4663c34
edits to mpi decomposition and interpolation tests to account for tor…
nfarabullini Jan 13, 2026
727e4f1
Merge branch 'global_min_reduction' of https://github.com/C2SM/icon4p…
nfarabullini Jan 14, 2026
01c7c86
Merge branch 'main' into global_ops_reduction
nfarabullini Jan 14, 2026
02f2067
Merge branch 'global_ops_reduction' of https://github.com/C2SM/icon4p…
nfarabullini Jan 14, 2026
51b17d4
minor fix for parallel geometry mpi fields
nfarabullini Jan 14, 2026
829c4d5
other global operations edits
nfarabullini Jan 14, 2026
b305eca
Merge branch 'main' into global_ops_reduction
nfarabullini Jan 14, 2026
002d526
global mean implementation
nfarabullini Jan 14, 2026
69b6191
global mean implementation and changes following review
nfarabullini Jan 14, 2026
f1126bf
further edits following review
nfarabullini Jan 14, 2026
10d7904
further edits and fixes
nfarabullini Jan 14, 2026
1693a66
removed breakpoint
nfarabullini Jan 14, 2026
8b61ac1
Update model/common/src/icon4py/model/common/decomposition/mpi_decomp…
nfarabullini Jan 14, 2026
663de2f
further edits following discussion
nfarabullini Jan 14, 2026
447dd48
tests parametrization
nfarabullini Jan 15, 2026
d78d9cd
Update model/common/tests/common/decomposition/mpi_tests/test_mpi_dec…
nfarabullini Jan 15, 2026
7e5e6f6
Update model/common/src/icon4py/model/common/decomposition/mpi_decomp…
nfarabullini Jan 15, 2026
137f7b8
edits following review
nfarabullini Jan 15, 2026
037964f
Merge branch 'main' into global_ops_reduction
nfarabullini Jan 15, 2026
40dd268
edits in tests for errors
nfarabullini Jan 15, 2026
236603a
add links to new mpi data, update old ones
jcanton Jan 15, 2026
744f0ed
Update model/common/src/icon4py/model/common/decomposition/mpi_decomp…
nfarabullini Jan 15, 2026
9a53f54
Update model/common/src/icon4py/model/common/decomposition/mpi_decomp…
nfarabullini Jan 15, 2026
73f02e0
edits following review
nfarabullini Jan 15, 2026
be65852
minor edits
nfarabullini Jan 16, 2026
afe71ef
Update model/common/src/icon4py/model/common/grid/grid_manager.py
nfarabullini Jan 16, 2026
7ab0cc8
Update model/common/src/icon4py/model/common/grid/icon.py
nfarabullini Jan 16, 2026
99c1bcd
Update model/common/src/icon4py/model/common/decomposition/mpi_decomp…
nfarabullini Jan 16, 2026
af8800e
Update model/common/src/icon4py/model/common/decomposition/mpi_decomp…
nfarabullini Jan 16, 2026
4958d64
Update model/common/src/icon4py/model/common/metrics/metric_fields.py
nfarabullini Jan 16, 2026
677c051
Update model/common/src/icon4py/model/common/decomposition/mpi_decomp…
nfarabullini Jan 16, 2026
3e469c0
Update model/common/tests/common/grid/mpi_tests/test_parallel_geometr…
nfarabullini Jan 16, 2026
5055070
re-added import
nfarabullini Jan 16, 2026
9c8ca85
small re-naming edit
nfarabullini Jan 16, 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
50 changes: 50 additions & 0 deletions model/common/src/icon4py/model/common/decomposition/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import logging
from collections.abc import Sequence
from enum import Enum
from types import ModuleType
from typing import Any, Literal, Protocol, overload, runtime_checkable

import dace # type: ignore[import-untyped]
Expand All @@ -21,6 +22,7 @@

from icon4py.model.common import utils
from icon4py.model.common.orchestration.halo_exchange import DummyNestedSDFG
from icon4py.model.common.states import utils as state_utils
from icon4py.model.common.utils import data_allocation as data_alloc


Expand Down Expand Up @@ -323,6 +325,38 @@ class SingleNodeRun(RunType):
pass


class Reductions(Protocol):
def min(
self, buffer: data_alloc.NDArray, array_ns: ModuleType = np
) -> state_utils.ScalarType: ...

def max(
self, buffer: data_alloc.NDArray, array_ns: ModuleType = np
) -> state_utils.ScalarType: ...

def sum(
self, buffer: data_alloc.NDArray, array_ns: ModuleType = np
) -> state_utils.ScalarType: ...

def mean(
self, buffer: data_alloc.NDArray, array_ns: ModuleType = np
) -> state_utils.ScalarType: ...


class SingleNodeReductions(Reductions):
def min(self, buffer: data_alloc.NDArray, array_ns: ModuleType = np) -> state_utils.ScalarType:
return array_ns.min(buffer).item()

def max(self, buffer: data_alloc.NDArray, array_ns: ModuleType = np) -> state_utils.ScalarType:
return array_ns.max(buffer).item()

def sum(self, buffer: data_alloc.NDArray, array_ns: ModuleType = np) -> state_utils.ScalarType:
return array_ns.sum(buffer).item()

def mean(self, buffer: data_alloc.NDArray, array_ns: ModuleType = np) -> state_utils.ScalarType:
return array_ns.sum(buffer).item() / buffer.size


@overload
def get_runtype(with_mpi: Literal[True]) -> MultiNodeRun: ...

Expand Down Expand Up @@ -365,4 +399,20 @@ def create_single_node_exchange(
return SingleNodeExchange()


@functools.singledispatch
def create_reduction(props: ProcessProperties) -> Reductions:
"""
Create a Global Reduction depending on the runtime size.

Depending on the number of processor a SingleNode version is returned or a GHEX context created and a Multinode returned.
"""
raise NotImplementedError(f"Unknown ProcessorProperties type ({type(props)})")


@create_reduction.register(SingleNodeProcessProperties)
def create_single_reduction_exchange(props: SingleNodeProcessProperties) -> Reductions:
return SingleNodeReductions()


single_node_default = SingleNodeExchange()
single_node_reductions = SingleNodeReductions()
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

from __future__ import annotations

import dataclasses
import functools
import logging
from collections.abc import Sequence
from collections.abc import Callable, Sequence
from dataclasses import dataclass
from types import ModuleType
from typing import TYPE_CHECKING, Any, ClassVar, Final, Union

import dace # type: ignore[import-untyped]
Expand All @@ -20,8 +22,9 @@

from icon4py.model.common import dimension as dims
from icon4py.model.common.decomposition import definitions
from icon4py.model.common.decomposition.definitions import SingleNodeExchange
from icon4py.model.common.decomposition.definitions import Reductions, SingleNodeExchange
from icon4py.model.common.orchestration import halo_exchange
from icon4py.model.common.states import utils as state_utils
from icon4py.model.common.utils import data_allocation as data_alloc


Expand Down Expand Up @@ -423,3 +426,81 @@ def create_multinode_node_exchange(
return GHexMultiNodeExchange(props, decomp_info)
else:
return SingleNodeExchange()


@dataclasses.dataclass
class GlobalReductions(Reductions):
props: definitions.ProcessProperties

def _reduce(
self,
buffer: data_alloc.NDArray,
local_reduction: Callable[[data_alloc.NDArray], data_alloc.ScalarT],
global_reduction: mpi4py.MPI.Op,
array_ns: ModuleType = np,
) -> state_utils.ScalarType:
local_red_val = local_reduction(buffer)
recv_buffer = array_ns.empty(1, dtype=buffer.dtype)
if hasattr(
array_ns, "cuda"
): # https://mpi4py.readthedocs.io/en/stable/tutorial.html#gpu-aware-mpi-python-gpu-arrays
array_ns.cuda.runtime.deviceSynchronize()
self.props.comm.Allreduce(local_red_val, recv_buffer, global_reduction)
return recv_buffer.item()

def _calc_buffer_size(
self,
buffer: data_alloc.NDArray,
array_ns: ModuleType = np,
) -> state_utils.ScalarType:
return self._reduce(array_ns.asarray([buffer.size]), array_ns.sum, mpi4py.MPI.SUM, array_ns)

def min(self, buffer: data_alloc.NDArray, array_ns: ModuleType = np) -> state_utils.ScalarType:
if self._calc_buffer_size(buffer, array_ns) == 0:
raise ValueError("global_min requires a non-empty buffer")
Comment on lines +459 to +460
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commenting for future reference: if we wanted to avoid this we could supply the neutral element as an initial value.

No change needed now, this is fine.

return self._reduce(
buffer if buffer.size != 0 else array_ns.asarray([array_ns.inf]),
array_ns.min,
mpi4py.MPI.MIN,
array_ns,
)

def max(self, buffer: data_alloc.NDArray, array_ns: ModuleType = np) -> state_utils.ScalarType:
if self._calc_buffer_size(buffer, array_ns) == 0:
raise ValueError("global_max requires a non-empty buffer")
return self._reduce(
buffer if buffer.size != 0 else array_ns.asarray([-array_ns.inf]),
array_ns.max,
mpi4py.MPI.MAX,
array_ns,
)

def sum(self, buffer: data_alloc.NDArray, array_ns: ModuleType = np) -> state_utils.ScalarType:
if self._calc_buffer_size(buffer, array_ns) == 0:
raise ValueError("global_sum requires a non-empty buffer")
return self._reduce(
buffer if buffer.size != 0 else array_ns.asarray([0]),
array_ns.sum,
mpi4py.MPI.SUM,
array_ns,
)

def mean(self, buffer: data_alloc.NDArray, array_ns: ModuleType = np) -> state_utils.ScalarType:
global_buffer_size = self._calc_buffer_size(buffer, array_ns)
if global_buffer_size == 0:
raise ValueError("global_mean requires a non-empty buffer")

return (
self._reduce(
buffer if buffer.size != 0 else array_ns.asarray([0]),
array_ns.sum,
mpi4py.MPI.SUM,
array_ns,
)
/ global_buffer_size
)


@definitions.create_reduction.register(MPICommProcessProperties)
def create_global_reduction(props: MPICommProcessProperties) -> Reductions:
return GlobalReductions(props)
2 changes: 1 addition & 1 deletion model/common/src/icon4py/model/common/grid/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def _inverse_field_provider(self, field_name: str) -> factory.FieldProvider:
self._edge_domain(h_grid.Zone.LOCAL),
)
},
do_exchange=False,
do_exchange=True,
)
return provider

Expand Down
13 changes: 11 additions & 2 deletions model/common/src/icon4py/model/common/grid/grid_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import functools
import logging
import pathlib
from collections.abc import Callable
from types import ModuleType
from typing import Literal, Protocol, TypeAlias

Expand Down Expand Up @@ -87,6 +88,7 @@ def __init__(
transformation: IndexTransformation,
grid_file: pathlib.Path | str,
config: v_grid.VerticalGridConfig, # TODO(halungge): remove to separate vertical and horizontal grid
global_reductions: decomposition.Reductions = decomposition.single_node_reductions,
):
self._transformation = transformation
self._file_name = str(grid_file)
Expand All @@ -96,6 +98,7 @@ def __init__(
self._geometry: GeometryDict = {}
self._reader = None
self._coordinates: CoordinateDict = {}
self._global_reductions = global_reductions

def open(self):
"""Open the gridfile resource for reading."""
Expand Down Expand Up @@ -130,7 +133,10 @@ def __call__(self, allocator: gtx_typing.FieldBufferAllocationUtil, keep_skip_va

self._geometry = self._read_geometry_fields(allocator)
self._grid = self._construct_grid(
allocator=allocator, with_skip_values=keep_skip_values, geometry_type=geometry_type
allocator=allocator,
with_skip_values=keep_skip_values,
geometry_type=geometry_type,
mean_reduction=self._global_reductions.mean,
)
self._coordinates = self._read_coordinates(allocator, geometry_type)
self.close()
Expand Down Expand Up @@ -353,6 +359,9 @@ def _construct_grid(
allocator: gtx_typing.FieldBufferAllocationUtil | None,
with_skip_values: bool,
geometry_type: base.GeometryType,
mean_reduction: Callable[
[data_alloc.NDArray, ModuleType], data_alloc.ScalarT
] = decomposition.single_node_reductions.mean,
) -> icon.IconGrid:
"""Construct the grid topology from the icon grid file.

Expand Down Expand Up @@ -386,7 +395,6 @@ def _construct_grid(
mean_dual_cell_area = self._reader.try_attribute(
gridfile.MPIMPropertyName.MEAN_DUAL_CELL_AREA
)

edge_lengths = self.geometry_fields[gridfile.GeometryName.EDGE_LENGTH.value].ndarray
dual_edge_lengths = self.geometry_fields[
gridfile.GeometryName.DUAL_EDGE_LENGTH.value
Expand All @@ -412,6 +420,7 @@ def _construct_grid(
dual_edge_lengths=dual_edge_lengths,
cell_areas=cell_areas,
dual_cell_areas=dual_cell_areas,
mean_reduction=mean_reduction,
)
grid_size = base.HorizontalGridSize(
num_vertices=num_vertices, num_edges=num_edges, num_cells=num_cells
Expand Down
6 changes: 5 additions & 1 deletion model/common/src/icon4py/model/common/grid/icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from gt4py.next import allocators as gtx_allocators

from icon4py.model.common import constants, dimension as dims
from icon4py.model.common.decomposition import definitions as decomposition
from icon4py.model.common.grid import base, horizontal as h_grid
from icon4py.model.common.utils import data_allocation as data_alloc

Expand Down Expand Up @@ -97,13 +98,16 @@ def from_fields(
cell_areas: data_alloc.NDArray | None = None,
mean_dual_cell_area: float | None = None,
dual_cell_areas: data_alloc.NDArray | None = None,
mean_reduction: Callable[
[data_alloc.NDArray, ModuleType], data_alloc.ScalarT
] = decomposition.single_node_reductions.mean,
**kwargs,
) -> _T:
def init_mean(value: float | None, data: data_alloc.NDArray | None) -> float | None:
if value is not None:
return value
if data is not None:
return array_ns.mean(data).item()
return mean_reduction(data, array_ns=array_ns)
return None

mean_edge_length = init_mean(mean_edge_length, edge_lengths)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#
# Please, refer to the LICENSE file in the root directory.
# SPDX-License-Identifier: BSD-3-Clause
from collections.abc import Callable
from types import ModuleType

import gt4py.next as gtx
Expand All @@ -17,6 +18,7 @@ def compute_coeff_gradekin(
edge_cell_length: data_alloc.NDArray,
inv_dual_edge_length: data_alloc.NDArray,
horizontal_start: gtx.int32,
exchange: Callable[[data_alloc.NDArray], None],
array_ns: ModuleType = np,
) -> data_alloc.NDArray:
"""
Expand All @@ -41,4 +43,5 @@ def compute_coeff_gradekin(
* inv_dual_edge_length[horizontal_start:]
)
coeff_gradekin_full = array_ns.column_stack((coeff_gradekin_0, coeff_gradekin_1))
exchange(coeff_gradekin_full)
return coeff_gradekin_full
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from gt4py.next.experimental import concat_where

from icon4py.model.common import constants, dimension as dims, field_type_aliases as fa
from icon4py.model.common.decomposition import definitions as decomposition
from icon4py.model.common.dimension import C2E, C2E2C, C2E2CO, E2C, C2E2CODim, Koff
from icon4py.model.common.interpolation.stencils.cell_2_edge_interpolation import (
_cell_2_edge_interpolation,
Expand Down Expand Up @@ -596,6 +597,9 @@ def compute_nflat_gradp(
e_owner_mask: data_alloc.NDArray,
lateral_boundary_level: int,
nlev: int,
min_reduction: Callable[
[data_alloc.NDArray, ModuleType], data_alloc.ScalarT
] = decomposition.single_node_reductions.min,
array_ns: ModuleType = np,
) -> int:
"""
Expand All @@ -607,8 +611,8 @@ def compute_nflat_gradp(
flat_idx_max,
nlev,
)
nflat_gradp = array_ns.min(mask_array)
return nflat_gradp.item()
nflat_gradp = min_reduction(mask_array, array_ns=array_ns)
return nflat_gradp


@gtx.field_operator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def __init__(
exner_expol: float,
vwind_offctr: float,
exchange: decomposition.ExchangeRuntime = decomposition.single_node_default,
global_reductions: decomposition.Reductions = decomposition.single_node_reductions,
):
self._backend = backend
self._xp = data_alloc.import_array_ns(backend)
Expand All @@ -81,6 +82,7 @@ def __init__(
self._geometry = geometry_source
self._exchange = exchange
self._interpolation_source = interpolation_source
self._global_reductions = global_reductions
log.info(
f"initialized metrics factory for backend = '{self._backend_name()}' and grid = '{self._grid}'"
)
Expand Down Expand Up @@ -657,7 +659,11 @@ def _register_computed_fields(self) -> None: # noqa: PLR0915 [too-many-statemen
self.register_provider(max_flat_index_provider)

nflat_gradp_provider = factory.NumpyDataProvider(
func=functools.partial(mf.compute_nflat_gradp, array_ns=self._xp),
func=functools.partial(
mf.compute_nflat_gradp,
array_ns=self._xp,
min_reduction=self._global_reductions.min,
),
domain=(),
deps={
"flat_idx_max": attrs.FLAT_IDX_MAX,
Expand Down Expand Up @@ -779,6 +785,7 @@ def _register_computed_fields(self) -> None: # noqa: PLR0915 [too-many-statemen
func=functools.partial(
compute_coeff_gradekin.compute_coeff_gradekin,
array_ns=self._xp,
exchange=functools.partial(self._exchange.exchange_and_wait, dims.EdgeDim),
),
domain=(dims.EdgeDim, dims.E2CDim),
fields=(attrs.COEFF_GRADEKIN,),
Expand Down
Loading
Loading