From 99ab2267556a761d41991fd44c7401601b246497 Mon Sep 17 00:00:00 2001 From: Lambert Theisen Date: Wed, 2 Jul 2025 14:54:24 +0200 Subject: [PATCH 1/9] add macos arm64 to ci --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 503857b5..e65d9c99 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,8 +21,10 @@ jobs: - '1' os: - ubuntu-latest + - macos-14 arch: - x64 + - arm64 steps: - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v2 From cc573b7e87c76d3498ca970800d9741d6b749500 Mon Sep 17 00:00:00 2001 From: Lambert Theisen Date: Wed, 2 Jul 2025 15:06:01 +0200 Subject: [PATCH 2/9] update CI to avoid ubuntu+arm64 and macos+x64 --- .github/workflows/ci.yml | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e65d9c99..79217e3a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,12 +19,11 @@ jobs: matrix: version: - '1' - os: - - ubuntu-latest - - macos-14 - arch: - - x64 - - arm64 + include: + - os: ubuntu-latest + arch: x64 + - os: macos-14 + arch: arm64 steps: - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v2 @@ -46,10 +45,11 @@ jobs: matrix: version: - '1' - os: - - ubuntu-latest - arch: - - x64 + include: + - os: ubuntu-latest + arch: x64 + - os: macos-14 + arch: arm64 steps: - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v2 @@ -71,10 +71,11 @@ jobs: matrix: version: - '1' - os: - - ubuntu-latest - arch: - - x64 + include: + - os: ubuntu-latest + arch: x64 + - os: macos-14 + arch: arm64 steps: - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v2 From 41aa1c75d045371e8fc58dc62a24c63a3347d544 Mon Sep 17 00:00:00 2001 From: Lambert Theisen Date: Wed, 2 Jul 2025 15:11:51 +0200 Subject: [PATCH 3/9] try to fix ci (ubuntu didn't run) --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 79217e3a..2b8545a1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: - os: ubuntu-latest arch: x64 - os: macos-14 - arch: arm64 + arch: aarch64 steps: - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v2 @@ -49,7 +49,7 @@ jobs: - os: ubuntu-latest arch: x64 - os: macos-14 - arch: arm64 + arch: aarch64 steps: - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v2 @@ -75,7 +75,7 @@ jobs: - os: ubuntu-latest arch: x64 - os: macos-14 - arch: arm64 + arch: aarch64 steps: - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v2 From ba709a93e78ba6ea93dfd648995103c68a61f85e Mon Sep 17 00:00:00 2001 From: Lambert Theisen Date: Wed, 2 Jul 2025 15:14:05 +0200 Subject: [PATCH 4/9] try to fix ci again --- .github/workflows/ci.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2b8545a1..e5760f59 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,10 +20,8 @@ jobs: version: - '1' include: - - os: ubuntu-latest - arch: x64 - - os: macos-14 - arch: aarch64 + - {os: ubuntu-latest, arch: x64} + - {os: macos-14, arch: aarch64} steps: - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v2 From 38a2fd87102eaf0d33f0d492156443b0c85c995c Mon Sep 17 00:00:00 2001 From: Lambert Theisen Date: Wed, 2 Jul 2025 15:20:02 +0200 Subject: [PATCH 5/9] try to finally fix ci --- .github/workflows/ci.yml | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e5760f59..e9efa075 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,8 +20,8 @@ jobs: version: - '1' include: - - {os: ubuntu-latest, arch: x64} - - {os: macos-14, arch: aarch64} + - {version: '1', os: ubuntu-latest, arch: x64} + - {version: '1', os: macos-14, arch: aarch64} steps: - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v2 @@ -41,13 +41,9 @@ jobs: strategy: fail-fast: false matrix: - version: - - '1' include: - - os: ubuntu-latest - arch: x64 - - os: macos-14 - arch: aarch64 + - {version: '1', os: ubuntu-latest, arch: x64} + - {version: '1', os: macos-14, arch: aarch64} steps: - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v2 @@ -67,13 +63,9 @@ jobs: strategy: fail-fast: false matrix: - version: - - '1' include: - - os: ubuntu-latest - arch: x64 - - os: macos-14 - arch: aarch64 + - {version: '1', os: ubuntu-latest, arch: x64} + - {version: '1', os: macos-14, arch: aarch64} steps: - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v2 From 195317985afc00478c5700c96ee6f6ecc5930272 Mon Sep 17 00:00:00 2001 From: Lambert Theisen Date: Wed, 2 Jul 2025 15:21:01 +0200 Subject: [PATCH 6/9] fixes CI finally --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e9efa075..3ad880eb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,8 +17,6 @@ jobs: strategy: fail-fast: false matrix: - version: - - '1' include: - {version: '1', os: ubuntu-latest, arch: x64} - {version: '1', os: macos-14, arch: aarch64} From 8ca3542b717f98e4de86b70162befd828b2a5894 Mon Sep 17 00:00:00 2001 From: Lambert Theisen Date: Mon, 7 Jul 2025 12:00:41 +0200 Subject: [PATCH 7/9] Change distance reduction for Number type to max/+ - makes these compatible to aarch64 architectures --- src/block_arrays.jl | 6 ++---- src/p_vector.jl | 27 +++++++++++++++++++++++---- src/primitives.jl | 11 ++++------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/block_arrays.jl b/src/block_arrays.jl index dfc47807..fa5a15ff 100644 --- a/src/block_arrays.jl +++ b/src/block_arrays.jl @@ -297,10 +297,8 @@ function distance_eval_body(d,a::BVector,b::BVector) partials = map(blocks(a),blocks(b)) do ai,bi distance_eval_body(d,ai,bi) end - s = reduce((i,j)->Distances.eval_reduce(d,i,j), - partials, - init=Distances.eval_start(d, a, b)) - s + init_val = Distances.eval_start(d, a, b) + combine_distance_partials(d, partials, init_val) end struct BroadcastedBArray{A} diff --git a/src/p_vector.jl b/src/p_vector.jl index dbc0cdf7..161df2ed 100644 --- a/src/p_vector.jl +++ b/src/p_vector.jl @@ -1,6 +1,27 @@ function local_values end +""" + combine_distance_partials(d, partials, init_val) + +Combine the partial distance results `partials` generated on each MPI rank +using built-in reduction operators whenever possible. For metrics that require +more complex reductions (e.g. those returning tuples), we fall back to +`Distances.eval_reduce`. +""" +function combine_distance_partials(d, partials, init_val) + if eltype(partials) <: Number + if d isa Distances.Chebyshev + reduce(max, partials; init=init_val) + else + reduce(+, partials; init=init_val) + end + else + reduce((i, j) -> Distances.eval_reduce(d, i, j), partials; + init=init_val) + end +end + function own_values end function ghost_values end @@ -1328,10 +1349,8 @@ function distance_eval_body(d,a::PVector,b::PVector) return s end end - s = reduce((i,j)->Distances.eval_reduce(d,i,j), - partials, - init=Distances.eval_start(d, a, b)) - s + init_val = Distances.eval_start(d, a, b) + combine_distance_partials(d, partials, init_val) end # New stuff diff --git a/src/primitives.jl b/src/primitives.jl index 86726137..a4183186 100644 --- a/src/primitives.jl +++ b/src/primitives.jl @@ -806,13 +806,10 @@ function ExchangeGraph_impl_with_neighbors(snd_ids,neighbors::ExchangeGraph) is_included_all=map(snd_ids_a, snd_ids_b) do snd_ids_a, snd_ids_b all(i->i in snd_ids_b,snd_ids_a) end - result=false - and(a,b)=a && b - is_included_all=reduction(and,is_included_all,destination=:all,init=one(eltype(is_included_all))) - map(is_included_all) do is_included_all - result = is_included_all - end - result + # perform a global AND using built-in & operator (static MPI-op) + is_included_all = reduction(&, is_included_all; destination=:all, init=one(eltype(is_included_all))) + # extract the single boolean result + collect(is_included_all)[1] end @boundscheck is_included(snd_ids,neighbors.snd) || error("snd_ids must be a subset of neighbors.snd") rank = linear_indices(snd_ids) From 7c0aa214f3ed472a7b822ef4ed80c258186aad52 Mon Sep 17 00:00:00 2001 From: Lambert Theisen Date: Mon, 7 Jul 2025 14:30:55 +0200 Subject: [PATCH 8/9] make combine_distance_partials private --- src/block_arrays.jl | 2 +- src/p_vector.jl | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/block_arrays.jl b/src/block_arrays.jl index fa5a15ff..ee01180d 100644 --- a/src/block_arrays.jl +++ b/src/block_arrays.jl @@ -298,7 +298,7 @@ function distance_eval_body(d,a::BVector,b::BVector) distance_eval_body(d,ai,bi) end init_val = Distances.eval_start(d, a, b) - combine_distance_partials(d, partials, init_val) + _combine_distance_partials(d, partials, init_val) end struct BroadcastedBArray{A} diff --git a/src/p_vector.jl b/src/p_vector.jl index 161df2ed..65a10b13 100644 --- a/src/p_vector.jl +++ b/src/p_vector.jl @@ -1,15 +1,7 @@ function local_values end -""" - combine_distance_partials(d, partials, init_val) - -Combine the partial distance results `partials` generated on each MPI rank -using built-in reduction operators whenever possible. For metrics that require -more complex reductions (e.g. those returning tuples), we fall back to -`Distances.eval_reduce`. -""" -function combine_distance_partials(d, partials, init_val) +function _combine_distance_partials(d, partials, init_val) if eltype(partials) <: Number if d isa Distances.Chebyshev reduce(max, partials; init=init_val) @@ -1350,7 +1342,7 @@ function distance_eval_body(d,a::PVector,b::PVector) end end init_val = Distances.eval_start(d, a, b) - combine_distance_partials(d, partials, init_val) + _combine_distance_partials(d, partials, init_val) end # New stuff From bb2a12f969f399ea279fbaf1912e46913ebd4790 Mon Sep 17 00:00:00 2001 From: Lambert Theisen Date: Mon, 7 Jul 2025 18:38:38 +0200 Subject: [PATCH 9/9] replace if-statements by MP in the distance reductions --- src/block_arrays.jl | 2 +- src/p_vector.jl | 35 +++++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/block_arrays.jl b/src/block_arrays.jl index ee01180d..dfe737eb 100644 --- a/src/block_arrays.jl +++ b/src/block_arrays.jl @@ -298,7 +298,7 @@ function distance_eval_body(d,a::BVector,b::BVector) distance_eval_body(d,ai,bi) end init_val = Distances.eval_start(d, a, b) - _combine_distance_partials(d, partials, init_val) + reduce_for_distance(d, partials, init_val) end struct BroadcastedBArray{A} diff --git a/src/p_vector.jl b/src/p_vector.jl index 65a10b13..9ffffd97 100644 --- a/src/p_vector.jl +++ b/src/p_vector.jl @@ -1,17 +1,28 @@ function local_values end -function _combine_distance_partials(d, partials, init_val) - if eltype(partials) <: Number - if d isa Distances.Chebyshev - reduce(max, partials; init=init_val) - else - reduce(+, partials; init=init_val) - end - else - reduce((i, j) -> Distances.eval_reduce(d, i, j), partials; - init=init_val) - end +function reduce_for_distance(d, partials, init) + reduce((i, j) -> Distances.eval_reduce(d, i, j), partials; init) +end + +reduce_for_distance(::Distances.Chebyshev, partials, init) = + reduce(max, partials; init) + +for T in (Distances.Euclidean, + Distances.SqEuclidean, + Distances.PeriodicEuclidean, + Distances.Cityblock, + Distances.TotalVariation, + Distances.Minkowski, + Distances.Hamming, + Distances.ChiSqDist, + Distances.KLDivergence, + Distances.GenKLDivergence) + # all Distances.metrics except Jaccard, RogersTanimoto, CosineDist, + # RenyiDivergence, BrayCurtis, SpanNormDist, since these either operate with + # tuples or have a complex reduction logic. + @eval reduce_for_distance(::$(T), partials, init) = + reduce(+, partials; init) end function own_values end @@ -1342,7 +1353,7 @@ function distance_eval_body(d,a::PVector,b::PVector) end end init_val = Distances.eval_start(d, a, b) - _combine_distance_partials(d, partials, init_val) + reduce_for_distance(d, partials, init_val) end # New stuff