Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Openmp parallel iterator improvements #9493

Merged
merged 3 commits into from
Oct 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion compiler/ccgstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down