From 8132c5a2dbdee51ca90a20f7d75f29708ad85553 Mon Sep 17 00:00:00 2001 From: Dr Weymouth Date: Wed, 20 Apr 2022 16:54:17 +0100 Subject: [PATCH] Update @loop @inside docs --- src/util.jl | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/util.jl b/src/util.jl index 62f2376d..c2262d58 100644 --- a/src/util.jl +++ b/src/util.jl @@ -46,9 +46,9 @@ Simple macro to automate efficient loops over cells excluding ghosts. For exampl becomes - @inbounds @simd for I ∈ inside(p) - p[I] = sum(I.I) - end + @loop p[I] = sum(I.I) over I ∈ inside(p) + +See `inside` and `@loop`. """ macro inside(ex) a,I = Meta.parse.(split(string(ex.args[1]),union("[",",","]"))) @@ -57,6 +57,27 @@ macro inside(ex) end |> esc end +""" + @loop over I ∈ R + +Simple macro to automate efficient loops. For example + + @loop r[I] += sum(I.I) over I ∈ CartesianIndex(r) + +becomes + + @inbounds @simd for I ∈ CartesianIndex(r) + r[I] += sum(I.I) + end + +when running one thread or + + @inbounds Threads.@threads for I ∈ CartesianIndex(r) + r[I] += sum(I.I) + end + +when running multithread. +""" macro loop(args...) ex,_,itr = args op,I,R = itr.args