Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change multithreading backend to Base.Threads #153

Merged
merged 5 commits into from
Jul 24, 2024
Merged
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
6 changes: 4 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ authors:
- family-names: Partmann
given-names: Kai
orcid: https://orcid.org/0000-0002-5238-4355
- family-names: Dienst
given-names: Manuel
orcid: https://orcid.org/0009-0004-9195-0112
- family-names: Weinberg
given-names: Kerstin
orcid: https://orcid.org/0000-0002-2213-8401
title: "Peridynamics.jl"
version: 0.2.0
doi: 10.5281/zenodo.8187478
doi: 10.5281/zenodo.8187477
date-released: 2023-07-26
url: "https://github.com/kaipartmann/Peridynamics.jl"
4 changes: 1 addition & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ LightXML = "9c8b4983-aa76-5018-a973-4c85ecc9e179"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
PointNeighbors = "1c4d5385-0a27-49de-8e2c-43b175c8985c"
Polyester = "f517fe37-dbe3-4b94-8317-1923a5111588"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
Expand All @@ -31,8 +30,7 @@ LibGit2 = "1.8"
LightXML = "0.9"
LinearAlgebra = "1.8"
MPI = "0.20.0"
PointNeighbors = "0.4"
Polyester = "0.7.5"
PointNeighbors = "0.4.5"
PrecompileTools = "1.0"
Printf = "1.8"
ProgressMeter = "1.0"
Expand Down
1 change: 0 additions & 1 deletion src/Peridynamics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ using Base.Threads, Printf, LinearAlgebra, StaticArrays, PointNeighbors, Progres
end

import LibGit2, Dates
import Polyester: @batch

# Material models
export BBMaterial, OSBMaterial, NOSBMaterial, CKIMaterial
Expand Down
3 changes: 1 addition & 2 deletions src/VtkReader/VtkReader.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module VtkReader

using Polyester: @batch
using Base64: base64decode
using CodecZlib: ZlibDecompressor
using LightXML: LightXML, XMLDocument, XMLElement, parse_string, attribute, child_elements,
Expand Down Expand Up @@ -89,7 +88,7 @@ end
function get_raw_xml_and_data(files::Vector{String})
vec_raw_xml_str = Vector{String}(undef, length(files))
vec_raw_data = Vector{Vector{UInt8}}(undef, length(files))
@batch for i in eachindex(files)
Threads.@threads for i in eachindex(files)
raw_xml_str, raw_data = get_raw_xml_and_data(files[i])
vec_raw_xml_str[i] = raw_xml_str
vec_raw_data[i] = raw_data
Expand Down
2 changes: 1 addition & 1 deletion src/auxiliary/process_each_export.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function process_each_export_threads(f::F, vtk_files::Vector{String}) where {F<:
ref_result = read_vtk(first(vtk_files))
p = Progress(length(vtk_files); dt=1, color=:normal, barlen=20,
enabled=progress_bars())
@batch for file_id in eachindex(vtk_files)
@threads :static for file_id in eachindex(vtk_files)
process_step(f, ref_result, vtk_files[file_id], file_id)
next!(p)
end
Expand Down
8 changes: 4 additions & 4 deletions src/core/threads_body_data_handler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function _chop_body_threads(::Type{ChunkType}, body::AbstractBody,
solver::AbstractTimeSolver, point_decomp::PointDecomposition,
param_spec::AbstractParamSpec) where {ChunkType}
chunks = Vector{ChunkType}(undef, point_decomp.n_chunks)
@batch for chunk_id in eachindex(point_decomp.decomp)
@threads :static for chunk_id in eachindex(point_decomp.decomp)
chunk = BodyChunk(body, solver, point_decomp, chunk_id, param_spec)
apply_precracks!(chunk, body)
apply_initial_conditions!(chunk, body)
Expand All @@ -38,7 +38,7 @@ end
function find_halo_exchanges(chunks::Vector{B}) where {B<:AbstractBodyChunk}
lth_exs = Vector{Vector{HaloExchange}}(undef, length(chunks))
htl_exs = Vector{Vector{HaloExchange}}(undef, length(chunks))
@batch for chunk_id in eachindex(chunks)
@threads :static for chunk_id in eachindex(chunks)
_lth_exs, _htl_exs = find_exs(chunks, chunk_id)
lth_exs[chunk_id] = _lth_exs
htl_exs[chunk_id] = _htl_exs
Expand All @@ -63,7 +63,7 @@ end

function reorder_htl_exs!(htl_exs::Vector{Vector{HaloExchange}})
all_htl_exs = reduce(vcat, htl_exs)
@batch for chunk_id in eachindex(htl_exs)
@threads :static for chunk_id in eachindex(htl_exs)
htl_exs[chunk_id] = filter(x -> x.dest_chunk_id == chunk_id, all_htl_exs)
end
return nothing
Expand Down Expand Up @@ -166,7 +166,7 @@ end

function export_reference_results(dh::ThreadsBodyDataHandler, options::AbstractJobOptions)
options.export_allowed || return nothing
@batch for chunk_id in eachindex(dh.chunks)
@threads :static for chunk_id in eachindex(dh.chunks)
_export_results(options, dh.chunks[chunk_id], chunk_id, dh.n_chunks, 0, 0.0)
end
return nothing
Expand Down
2 changes: 1 addition & 1 deletion src/core/threads_multibody_data_handler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function update_caches!(dh::ThreadsMultibodyDataHandler)
for body_idx in each_body_idx(dh)
body_dh = get_body_dh(dh, body_idx)
position_cache = dh.position_caches[body_idx]
@batch for chunk in body_dh.chunks
@threads :static for chunk in body_dh.chunks
@inbounds for (li, i) in enumerate(chunk.ch.loc_points)
position_cache[1, i] = chunk.storage.position[1, li]
position_cache[2, i] = chunk.storage.position[2, li]
Expand Down
4 changes: 2 additions & 2 deletions src/discretization/bond_system_corrections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ end

function initialize!(dh::AbstractThreadsBodyDataHandler{BondSystem{EnergySurfaceCorrection}},
::AbstractTimeSolver)
@batch for chunk in dh.chunks
@threads :static for chunk in dh.chunks
calc_mfactor!(chunk)
end
@batch for chunk_id in eachindex(dh.chunks)
@threads :static for chunk_id in eachindex(dh.chunks)
exchange_loc_to_halo!(get_mfactor, dh, chunk_id)
calc_scfactor!(dh.chunks[chunk_id])
end
Expand Down
4 changes: 2 additions & 2 deletions src/physics/short_range_force_contact.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ function calc_short_range_force_contacts!(dh::AbstractThreadsMultibodyDataHandle
# update neighborhoodsearches
posc_a = dh.position_caches[body_a_idx]
posc_b = dh.position_caches[body_b_idx]
update_grid!(contact.nhs, posc_b)
update_grid!(contact.nhs, posc_b; parallelization_backend=ThreadsStaticBackend())

# calc contact
body_dh_a = get_body_dh(dh, body_a_idx)
volc_b = dh.volume_caches[body_b_idx]
@batch for chunk_a in body_dh_a.chunks
@threads :static for chunk_a in body_dh_a.chunks
calc_contact_force_density!(chunk_a, contact, posc_a, posc_b, volc_b)
end
end
Expand Down
8 changes: 4 additions & 4 deletions src/time_solvers/dynamic_relaxation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function solve!(dh::AbstractDataHandler, dr::DynamicRelaxation,
end

function init_density_matrix!(dh::AbstractThreadsBodyDataHandler, dr::DynamicRelaxation)
@batch for chunk in dh.chunks
@threads :static for chunk in dh.chunks
_init_density_matrix!(chunk, dr, chunk.paramsetup)
end
return nothing
Expand Down Expand Up @@ -168,16 +168,16 @@ function relaxation_timestep!(dh::AbstractThreadsBodyDataHandler,
options::AbstractJobOptions,
Δt::Float64, n::Int)
t = n * Δt
@batch for chunk_id in eachindex(dh.chunks)
@threads :static for chunk_id in eachindex(dh.chunks)
chunk = dh.chunks[chunk_id]
apply_boundary_conditions!(chunk, t)
update_disp_and_pos!(chunk, Δt)
end
@batch for chunk_id in eachindex(dh.chunks)
@threads :static for chunk_id in eachindex(dh.chunks)
exchange_loc_to_halo!(dh, chunk_id)
calc_force_density!(dh.chunks[chunk_id])
end
@batch for chunk_id in eachindex(dh.chunks)
@threads :static for chunk_id in eachindex(dh.chunks)
exchange_halo_to_loc!(dh, chunk_id)
chunk = dh.chunks[chunk_id]
calc_damage!(chunk)
Expand Down
14 changes: 7 additions & 7 deletions src/time_solvers/velocity_verlet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ end

function calc_stable_timestep(dh::ThreadsBodyDataHandler, safety_factor::Float64)
Δt = zeros(length(dh.chunks))
@batch for chunk_id in eachindex(dh.chunks)
@threads :static for chunk_id in eachindex(dh.chunks)
Δt[chunk_id] = calc_timestep(dh.chunks[chunk_id])
end
return minimum(Δt) * safety_factor
Expand Down Expand Up @@ -181,17 +181,17 @@ end
function verlet_timestep!(dh::AbstractThreadsBodyDataHandler, options::AbstractJobOptions,
Δt::Float64, Δt½::Float64, n::Int)
t = n * Δt
@batch for chunk_id in eachindex(dh.chunks)
@threads :static for chunk_id in eachindex(dh.chunks)
chunk = dh.chunks[chunk_id]
update_vel_half!(chunk, Δt½)
apply_boundary_conditions!(chunk, t)
update_disp_and_pos!(chunk, Δt)
end
@batch for chunk_id in eachindex(dh.chunks)
@threads :static for chunk_id in eachindex(dh.chunks)
exchange_loc_to_halo!(dh, chunk_id)
calc_force_density!(dh.chunks[chunk_id])
end
@batch for chunk_id in eachindex(dh.chunks)
@threads :static for chunk_id in eachindex(dh.chunks)
exchange_halo_to_loc!(dh, chunk_id)
chunk = dh.chunks[chunk_id]
calc_damage!(chunk)
Expand All @@ -206,13 +206,13 @@ function verlet_timestep!(dh::AbstractThreadsMultibodyDataHandler,
t = n * Δt
for body_idx in each_body_idx(dh)
body_dh = get_body_dh(dh, body_idx)
@batch for chunk_id in eachindex(body_dh.chunks)
@threads :static for chunk_id in eachindex(body_dh.chunks)
chunk = body_dh.chunks[chunk_id]
update_vel_half!(chunk, Δt½)
apply_boundary_conditions!(chunk, t)
update_disp_and_pos!(chunk, Δt)
end
@batch for chunk_id in eachindex(body_dh.chunks)
@threads :static for chunk_id in eachindex(body_dh.chunks)
exchange_loc_to_halo!(body_dh, chunk_id)
calc_force_density!(body_dh.chunks[chunk_id])
end
Expand All @@ -222,7 +222,7 @@ function verlet_timestep!(dh::AbstractThreadsMultibodyDataHandler,
for body_idx in each_body_idx(dh)
body_dh = get_body_dh(dh, body_idx)
body_name = get_body_name(dh, body_idx)
@batch for chunk_id in eachindex(body_dh.chunks)
@threads :static for chunk_id in eachindex(body_dh.chunks)
exchange_halo_to_loc!(body_dh, chunk_id)
chunk = body_dh.chunks[chunk_id]
calc_damage!(chunk)
Expand Down
Loading