diff --git a/changelog.md b/changelog.md index e9e48d035b..b7fdc5a42a 100644 --- a/changelog.md +++ b/changelog.md @@ -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 diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index 907b56dacd..7905d3daf9 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -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, diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index a13281cd66..1725d7a310 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -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) diff --git a/lib/system.nim b/lib/system.nim index 05ffa63b4c..f852a0aede 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -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`_ + ## 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