Multi-threading
Tesserae.@threaded
— Macro@threaded [scheduler] for ...
@threaded [scheduler] @P2G ...
@threaded @P2G ...
A macro similar to Threads.@threads
, but also works with @P2G
, @G2P
, @G2P2G
, and @P2G_Matrix
macros for particle-grid transfers.
The optional scheduler
can be :static
, :dynamic
, :greedy
, or :nothing
(sequential execution). The default is :dynamic
.
See also ColorPartition
.
If multi-threading is disabled or only one thread is available, this macro falls back to sequential execution.
Examples
# Parallel loop
@threaded :static for i in 1:100
println(i)
end
# Particle-to-grid transfer
@threaded @P2G grid=>i particles=>p mpvalues=>ip partition begin
m[i] += @∑ w[ip] * m[p]
end
Tesserae.ColorPartition
— TypeColorPartition(::CartesianMesh)
ColorPartition
stores partitioning information used by the @P2G
and @G2P2G
macros to avoid write conflicts during parallel particle-to-grid transfers.
Examples
# Construct ColorPartition
partition = ColorPartition(mesh)
# Update coloring using current particle positions
update!(partition, particles.x)
# P2G transfer
@threaded @P2G grid=>i particles=>p mpvalues=>ip partition begin
m[i] = @∑ w[ip] * m[p]
mv[i] = @∑ w[ip] * m[p] * v[p]
end