Skip to content

Commit 6352f9f

Browse files
committed
add 2D structure function output bins
1 parent 204a991 commit 6352f9f

9 files changed

Lines changed: 712 additions & 11 deletions

ext/StructureFunctionsDistributedExt.jl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,54 @@ function SFC._dispatch_single_pass(
231231
return SFC.postprocess_single_pass_results(sums, counts, distance_bins)
232232
end
233233

234+
function SFC.parallel_calculate_structure_function(
235+
structure_function_type::SFT.AbstractStructureFunctionType,
236+
x_vecs::Tuple,
237+
u_vecs::Tuple,
238+
distance_bins::AbstractVector,
239+
value_bins::AbstractVector;
240+
distance_metric::DI.PreMetric = DI.Euclidean(),
241+
verbose = true,
242+
show_progress = true,
243+
)
244+
if verbose
245+
@info("calculating 2D joint structure function (distributed reduction)")
246+
end
247+
248+
sums_and_counts =
249+
PM.@showprogress enabled = show_progress Distributed.@distributed (+) for i in eachindex(x_vecs[1])
250+
SFC.calculate_structure_function_2d_i(
251+
structure_function_type,
252+
i,
253+
x_vecs,
254+
u_vecs,
255+
distance_bins,
256+
value_bins;
257+
distance_metric = distance_metric,
258+
)
259+
end
260+
return sums_and_counts
261+
end
262+
263+
function SFC.parallel_calculate_structure_function(
264+
structure_function_type::SFT.AbstractStructureFunctionType,
265+
x_arr::AbstractArray{FT1},
266+
u_arr::AbstractArray{FT2},
267+
distance_bins::AbstractVector{Tuple{FT3, FT3}},
268+
value_bins::AbstractVector;
269+
kwargs...,
270+
) where {FT1 <: Number, FT2 <: Number, FT3 <: Number}
271+
N_dims = size(x_arr, 1)
272+
x_tuple = ntuple(k -> view(x_arr, k, :), N_dims)
273+
u_tuple = ntuple(k -> view(u_arr, k, :), N_dims)
274+
return SFC.parallel_calculate_structure_function(
275+
structure_function_type,
276+
x_tuple,
277+
u_tuple,
278+
distance_bins,
279+
value_bins;
280+
kwargs...,
281+
)
282+
end
283+
234284
end

ext/StructureFunctionsOhMyThreadsExt.jl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,55 @@ function SFC._dispatch_single_pass(
263263
return SFC.postprocess_single_pass_results(sums, counts, distance_bins)
264264
end
265265

266+
function SFC.threaded_calculate_structure_function(
267+
structure_function_type::SFT.AbstractStructureFunctionType,
268+
x_vecs::Tuple,
269+
u_vecs::Tuple,
270+
distance_bins::AbstractVector,
271+
value_bins::AbstractVector;
272+
distance_metric::DI.PreMetric = DI.Euclidean(),
273+
verbose = true,
274+
show_progress = true,
275+
)
276+
if verbose
277+
@info("calculating 2D joint structure function (threaded reduction via OhMyThreads)")
278+
end
279+
_ = show_progress
280+
281+
sums_and_counts = OMT.tmapreduce(+, eachindex(x_vecs[1])) do i
282+
SFC.calculate_structure_function_2d_i(
283+
structure_function_type,
284+
i,
285+
x_vecs,
286+
u_vecs,
287+
distance_bins,
288+
value_bins;
289+
distance_metric = distance_metric,
290+
)
291+
end
292+
293+
return sums_and_counts
294+
end
295+
296+
function SFC.threaded_calculate_structure_function(
297+
structure_function_type::SFT.AbstractStructureFunctionType,
298+
x_arr::AbstractArray{FT1},
299+
u_arr::AbstractArray{FT2},
300+
distance_bins::AbstractVector{Tuple{FT3, FT3}},
301+
value_bins::AbstractVector;
302+
kwargs...,
303+
) where {FT1 <: Number, FT2 <: Number, FT3 <: Number}
304+
N_dims = size(x_arr, 1)
305+
x_tuple = ntuple(k -> view(x_arr, k, :), N_dims)
306+
u_tuple = ntuple(k -> view(u_arr, k, :), N_dims)
307+
return SFC.threaded_calculate_structure_function(
308+
structure_function_type,
309+
x_tuple,
310+
u_tuple,
311+
distance_bins,
312+
value_bins;
313+
kwargs...,
314+
)
315+
end
316+
266317
end

0 commit comments

Comments
 (0)