Add OpenMP overload with stepping (#10891)
This commit is contained in:
parent
04ad200b40
commit
25649616ea
3 changed files with 35 additions and 5 deletions
|
|
@ -20,6 +20,8 @@
|
||||||
the change is transparent, if you used annotations you will have to prefix
|
the change is transparent, if you used annotations you will have to prefix
|
||||||
your previous annotations with `parallel for`.
|
your previous annotations with `parallel for`.
|
||||||
|
|
||||||
|
Furthermore, an overload with positive stepping is available.
|
||||||
|
|
||||||
- The `unchecked` pragma was removed, instead use `system.UncheckedArray`.
|
- The `unchecked` pragma was removed, instead use `system.UncheckedArray`.
|
||||||
|
|
||||||
- The undocumented ``#? strongSpaces`` parsing mode has been removed.
|
- The undocumented ``#? strongSpaces`` parsing mode has been removed.
|
||||||
|
|
|
||||||
|
|
@ -622,15 +622,25 @@ proc genParForStmt(p: BProc, t: PNode) =
|
||||||
#initLoc(forLoopVar.loc, locLocalVar, forLoopVar.typ, onStack)
|
#initLoc(forLoopVar.loc, locLocalVar, forLoopVar.typ, onStack)
|
||||||
#discard mangleName(forLoopVar)
|
#discard mangleName(forLoopVar)
|
||||||
let call = t.sons[1]
|
let call = t.sons[1]
|
||||||
|
assert(sonsLen(call) in {4, 5})
|
||||||
initLocExpr(p, call.sons[1], rangeA)
|
initLocExpr(p, call.sons[1], rangeA)
|
||||||
initLocExpr(p, call.sons[2], rangeB)
|
initLocExpr(p, call.sons[2], rangeB)
|
||||||
|
|
||||||
# $n at the beginning because of #9710
|
# $n at the beginning because of #9710
|
||||||
|
if call.sonsLen == 4: # `||`(a, b, annotation)
|
||||||
lineF(p, cpsStmts, "$n#pragma omp $4$n" &
|
lineF(p, cpsStmts, "$n#pragma omp $4$n" &
|
||||||
"for ($1 = $2; $1 <= $3; ++$1)",
|
"for ($1 = $2; $1 <= $3; ++$1)",
|
||||||
[forLoopVar.loc.rdLoc,
|
[forLoopVar.loc.rdLoc,
|
||||||
rangeA.rdLoc, rangeB.rdLoc,
|
rangeA.rdLoc, rangeB.rdLoc,
|
||||||
call.sons[3].getStr.rope])
|
call.sons[3].getStr.rope])
|
||||||
|
else: # `||`(a, b, step, annotation)
|
||||||
|
var step: TLoc
|
||||||
|
initLocExpr(p, call.sons[3], step)
|
||||||
|
lineF(p, cpsStmts, "$n#pragma omp $5$n" &
|
||||||
|
"for ($1 = $2; $1 <= $3; $1 += $4)",
|
||||||
|
[forLoopVar.loc.rdLoc,
|
||||||
|
rangeA.rdLoc, rangeB.rdLoc, step.rdLoc,
|
||||||
|
call.sons[4].getStr.rope])
|
||||||
|
|
||||||
p.breakIdx = startBlock(p)
|
p.breakIdx = startBlock(p)
|
||||||
p.blocks[p.breakIdx].isLoop = true
|
p.blocks[p.breakIdx].isLoop = true
|
||||||
|
|
|
||||||
|
|
@ -2681,6 +2681,24 @@ iterator `||`*[S, T](a: S, b: T, annotation: static string = "parallel for"): T
|
||||||
## and GC.
|
## and GC.
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
iterator `||`*[S, T](a: S, b: T, step: Positive, annotation: static string = "parallel for"): T {.
|
||||||
|
inline, magic: "OmpParFor", sideEffect.} =
|
||||||
|
## OpenMP parallel loop iterator with stepping.
|
||||||
|
## Same as `countup` but the loop may run in parallel.
|
||||||
|
##
|
||||||
|
## `annotation` is an additional annotation for the code generator to use.
|
||||||
|
## The default annotation is `parallel for`.
|
||||||
|
## Please refer to the `OpenMP Syntax Reference
|
||||||
|
## <https://www.openmp.org/wp-content/uploads/OpenMP-4.5-1115-CPP-web.pdf>`_
|
||||||
|
## for further information.
|
||||||
|
##
|
||||||
|
## Note that the compiler maps that to
|
||||||
|
## the ``#pragma omp parallel for`` construct of `OpenMP`:idx: and as
|
||||||
|
## such isn't aware of the parallelism in your code! Be careful! Later
|
||||||
|
## versions of ``||`` will get proper support by Nim's code generator
|
||||||
|
## and GC.
|
||||||
|
discard
|
||||||
|
|
||||||
{.push stackTrace:off.}
|
{.push stackTrace:off.}
|
||||||
proc min*(x, y: int): int {.magic: "MinI", noSideEffect.} =
|
proc min*(x, y: int): int {.magic: "MinI", noSideEffect.} =
|
||||||
if x <= y: x else: y
|
if x <= y: x else: y
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue