Skip to content

Commit

Permalink
reset threads in semidiscretize
Browse files Browse the repository at this point in the history
I added the option to reset the threads from Polyester.jl in semidiscretize.
However, I did not document it in the docstring since we have not documented
that we use Polyester.jl threads in general - and the resetting is specific
to Polyester.jl. I was not sure whether we still would like to keep the option
to change the threading backend any time - although I do not see a good reason
why we should do so.
  • Loading branch information
ranocha committed Jul 24, 2023
1 parent 1aec5fa commit 7703435
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ MuladdMacro = "0.2.2"
Octavian = "0.3.5"
OffsetArrays = "1.3"
P4est = "0.4"
Polyester = "0.3.4, 0.5, 0.6, 0.7"
Polyester = "0.7.5"
PrecompileTools = "1.1"
RecipesBase = "1.1"
Reexport = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion src/Trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ using LoopVectorization: LoopVectorization, @turbo, indices
using StaticArrayInterface: static_length # used by LoopVectorization
using MuladdMacro: @muladd
using Octavian: Octavian, matmul!
using Polyester: @batch # You know, the cheapest threads you can find...
using Polyester: Polyester, @batch # You know, the cheapest threads you can find...
using OffsetArrays: OffsetArray, OffsetVector
using P4est
using Setfield: @set
Expand Down
20 changes: 18 additions & 2 deletions src/semidiscretization/semidiscretization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ end
Wrap the semidiscretization `semi` as an ODE problem in the time interval `tspan`
that can be passed to `solve` from the [SciML ecosystem](https://diffeq.sciml.ai/latest/).
"""
function semidiscretize(semi::AbstractSemidiscretization, tspan)
function semidiscretize(semi::AbstractSemidiscretization, tspan;
reset_threads = true)
# Optionally reset Polyester.jl threads. See
# https://github.com/trixi-framework/Trixi.jl/issues/1583
# https://github.com/JuliaSIMD/Polyester.jl/issues/30
if reset_threads
Polyester.reset_threads!()
end

u0_ode = compute_coefficients(first(tspan), semi)
# TODO: MPI, do we want to synchronize loading and print debug statements, e.g. using
# mpi_isparallel() && MPI.Barrier(mpi_comm())
Expand All @@ -88,7 +96,15 @@ that can be passed to `solve` from the [SciML ecosystem](https://diffeq.sciml.ai
The initial condition etc. is taken from the `restart_file`.
"""
function semidiscretize(semi::AbstractSemidiscretization, tspan,
restart_file::AbstractString)
restart_file::AbstractString;
reset_threads = true)
# Optionally reset Polyester.jl threads. See
# https://github.com/trixi-framework/Trixi.jl/issues/1583
# https://github.com/JuliaSIMD/Polyester.jl/issues/30
if reset_threads
Polyester.reset_threads!()
end

u0_ode = load_restart_file(semi, restart_file)
# TODO: MPI, do we want to synchronize loading and print debug statements, e.g. using
# mpi_isparallel() && MPI.Barrier(mpi_comm())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,15 @@ The parabolic right-hand side is the first function of the split ODE problem and
will be used by default by the implicit part of IMEX methods from the
SciML ecosystem.
"""
function semidiscretize(semi::SemidiscretizationHyperbolicParabolic, tspan)
function semidiscretize(semi::SemidiscretizationHyperbolicParabolic, tspan;
reset_threads = true)
# Optionally reset Polyester.jl threads. See
# https://github.com/trixi-framework/Trixi.jl/issues/1583
# https://github.com/JuliaSIMD/Polyester.jl/issues/30
if reset_threads
Polyester.reset_threads!()
end

u0_ode = compute_coefficients(first(tspan), semi)
# TODO: MPI, do we want to synchronize loading and print debug statements, e.g. using
# mpi_isparallel() && MPI.Barrier(mpi_comm())
Expand Down

0 comments on commit 7703435

Please sign in to comment.