I have two methods of a function thermo!
function thermo!(cell::FEMCell, mix::Mixture)
# do something with `cell`
return nothing # note, I don't need to collect return value
end
thermo!(problem::Problem) =
foreach(cell -> thermo!(cell, problem.mixture), getcells(problem))
The second method item-independently applies the first to a Vector{FEMCell}
. I want a parallel version of thermo!(problem::Problem)
using threads. (As my laptop has 2 physical cores.)
My synchronization pattern is
- Run using threads
thermo!(problem::Problem)
; - Wait until parallel
thermo!(problem::Problem)
ends; - Go further…
I found Threads.@threads
macro and use it as a solution
function thermo!(problem::ExplicitDarcy)
Threads.@threads for cell in getcells(problem)
thermo!(cell, problem.mixture)
end
return nothing
end
But,
Is there a more elegant solution? (As I have more similar situations in my program.)
Something like
thermo!(problem::Problem) =
Threads.@threaded_foreach foreach(cell -> thermo!(cell, problem.mixture), getcells(problem))
UPD
I’m accidently missedBase.Threads.foreach
. If it’s the solution, how to useChannel
in my situation?