mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-07 21:43:33 +00:00
Openmp parallel iterator improvements (#9493)
* More flexibility in OpenMP pragma * Use static to constrain to compile-time annotation string * Update changelog with OpenMP change
This commit is contained in:
committed by
Andreas Rumpf
parent
c844a9169c
commit
5b97762787
@@ -11,6 +11,12 @@
|
||||
use `editdistance.editDistance` or `editdistance.editDistanceAscii`
|
||||
instead.
|
||||
|
||||
- The OpenMP parallel iterator \``||`\` now supports any `#pragma omp directives`
|
||||
and not just `#pragma omp parallel for`. See [OpenMP documentation](https://www.openmp.org/wp-content/uploads/OpenMP-4.5-1115-CPP-web.pdf).
|
||||
|
||||
The default annotation is `parallel for`, if you used OpenMP without annotation
|
||||
the change is transparent, if you used annotations you will have to prefix
|
||||
your previous annotations with `parallel for`.
|
||||
|
||||
#### Breaking changes in the standard library
|
||||
|
||||
|
||||
@@ -557,7 +557,7 @@ proc genParForStmt(p: BProc, t: PNode) =
|
||||
initLocExpr(p, call.sons[1], rangeA)
|
||||
initLocExpr(p, call.sons[2], rangeB)
|
||||
|
||||
lineF(p, cpsStmts, "#pragma omp parallel for $4$n" &
|
||||
lineF(p, cpsStmts, "#pragma omp $4$n" &
|
||||
"for ($1 = $2; $1 <= $3; ++$1)",
|
||||
[forLoopVar.loc.rdLoc,
|
||||
rangeA.rdLoc, rangeB.rdLoc,
|
||||
|
||||
@@ -2041,11 +2041,6 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
|
||||
result = c.graph.emptyNode
|
||||
of mOmpParFor:
|
||||
checkMinSonsLen(n, 3, c.config)
|
||||
if n.sonsLen == 4:
|
||||
let annotationStr = getConstExpr(c.module, semExpr(c, n[^1]), c.graph)
|
||||
if annotationStr == nil or annotationStr.kind notin nkStrKinds:
|
||||
localError(c.config, result[^1].info,
|
||||
"The annotation string for `||` must be known at compile time")
|
||||
result = semDirectOp(c, n, flags)
|
||||
else:
|
||||
result = semDirectOp(c, n, flags)
|
||||
|
||||
@@ -2186,10 +2186,14 @@ else:
|
||||
inc(res)
|
||||
|
||||
|
||||
iterator `||`*[S, T](a: S, b: T, annotation=""): T {.
|
||||
iterator `||`*[S, T](a: S, b: T, annotation: static string = "parallel for"): T {.
|
||||
inline, magic: "OmpParFor", sideEffect.} =
|
||||
## parallel loop iterator. Same as `..` but the loop may run in parallel.
|
||||
## OpenMP parallel loop iterator. Same as `..` 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
|
||||
|
||||
Reference in New Issue
Block a user