Skip to content

Commit

Permalink
Fix Julia code thread safety (#88)
Browse files Browse the repository at this point in the history
Co-authored-by: zhanglw0521 <[email protected]>
Co-authored-by: Christoph Ortner <[email protected]>
  • Loading branch information
3 people committed Nov 27, 2023
1 parent 0c9951e commit 451b051
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion julia/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SpheriCart"
uuid = "5caf2b29-02d9-47a3-9434-5931c85ba645"
authors = ["Christoph Ortner <[email protected]> and contributors"]
version = "0.0.2-dev"
version = "0.0.3"

[deps]
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Expand Down
2 changes: 2 additions & 0 deletions julia/benchmarks/benchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ end
@info("compute! vs compute_with_gradients! (using 32 inputs)")

for L = 1:2:15
local Rs
@show L
nX = 32
basis = SolidHarmonics(L)
Expand All @@ -84,6 +85,7 @@ end

@info("compute vs compute_with_gradients for code-generated basis")
for L = 1:10
local 𝐫
@show L
basis = SolidHarmonics(L; static=true)
𝐫 = @SVector randn(3)
Expand Down
4 changes: 2 additions & 2 deletions julia/src/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ See documentation for more details.
"""
struct SolidHarmonics{L, NORM, STATIC, T1}
Flm::OffsetMatrix{T1, Matrix{T1}}
cache::ArrayPool{FlexArrayCache}
cache::TSafe{ArrayPool{FlexArrayCache}}
end

function SolidHarmonics(L::Integer;
Expand All @@ -45,7 +45,7 @@ function SolidHarmonics(L::Integer;
T = Float64)
Flm = generate_Flms(L; normalisation = normalisation, T = T)
@assert eltype(Flm) == T
SolidHarmonics{L, normalisation, static, T}(Flm, ArrayPool(FlexArrayCache))
SolidHarmonics{L, normalisation, static, T}(Flm, TSafe(ArrayPool(FlexArrayCache)))
end

@inline (basis::SolidHarmonics)(args...) = compute(basis, args...)
Expand Down
6 changes: 3 additions & 3 deletions julia/src/spherical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ See documentation for more details.
struct SphericalHarmonics{L, NORM, STATIC, T1}
solids::SolidHarmonics{L, NORM, STATIC, T1}
# Flm::OffsetMatrix{T1, Matrix{T1}}
cache::ArrayPool{FlexArrayCache}
cache::TSafe{ArrayPool{FlexArrayCache}}
end

SphericalHarmonics(L::Integer; kwargs...) =
SphericalHarmonics(SolidHarmonics(L, kwargs...),
ArrayPool(FlexArrayCache))
SphericalHarmonics(SolidHarmonics(L; kwargs...),
TSafe(ArrayPool(FlexArrayCache)))


@inline (basis::SphericalHarmonics)(args...) = compute(basis, args...)
Expand Down

0 comments on commit 451b051

Please sign in to comment.