Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pystencils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pycodegen
pystencils
Commits
330ffcf3
Commit
330ffcf3
authored
8 years ago
by
Martin Bauer
Browse files
Options
Downloads
Patches
Plain Diff
Simpler OpenMP handling & OpenMP parallel boundaries
- periodic kernels not yet OpenMP parallel
parent
e2cab929
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cpu/kernelcreation.py
+27
-3
27 additions, 3 deletions
cpu/kernelcreation.py
with
27 additions
and
3 deletions
cpu/kernelcreation.py
+
27
−
3
View file @
330ffcf3
...
...
@@ -126,7 +126,7 @@ def createIndexedKernel(listOfEquations, indexFields, functionName="kernel", typ
return
ast
def
addOpenMP
(
astNode
,
schedule
=
"
static
"
,
numThreads
=
Non
e
):
def
addOpenMP
(
astNode
,
schedule
=
"
static
"
,
numThreads
=
Tru
e
):
"""
Parallelizes the outer loop with OpenMP
...
...
@@ -134,13 +134,37 @@ def addOpenMP(astNode, schedule="static", numThreads=None):
:param schedule: OpenMP scheduling policy e.g.
'
static
'
or
'
dynamic
'
:param numThreads: explicitly specify number of threads
"""
if
not
numThreads
:
return
assert
type
(
astNode
)
is
ast
.
KernelFunction
body
=
astNode
.
body
threadsClause
=
""
if
numThreads
is
None
else
"
num_threads(%s)
"
%
(
numThreads
,)
threadsClause
=
""
if
numThreads
else
"
num_threads(%s)
"
%
(
numThreads
,)
wrapperBlock
=
ast
.
PragmaBlock
(
'
#pragma omp parallel
'
+
threadsClause
,
body
.
takeChildNodes
())
body
.
append
(
wrapperBlock
)
outerLoops
=
[
l
for
l
in
body
.
atoms
(
ast
.
LoopOverCoordinate
)
if
l
.
isOutermostLoop
]
assert
outerLoops
,
"
No outer loop found
"
assert
len
(
outerLoops
)
<=
1
,
"
More than one outer loop found. Which one should be parallelized?
"
outerLoops
[
0
].
prefixLines
.
append
(
"
#pragma omp for schedule(%s)
"
%
(
schedule
,))
loopToParallelize
=
outerLoops
[
0
]
try
:
loopRange
=
int
(
loopToParallelize
.
stop
-
loopToParallelize
.
start
)
except
TypeError
:
loopRange
=
None
if
numThreads
is
None
:
import
multiprocessing
numThreads
=
multiprocessing
.
cpu_count
()
if
loopRange
is
not
None
and
loopRange
<
numThreads
:
containedLoops
=
[
l
for
l
in
loopToParallelize
.
body
.
args
if
isinstance
(
l
,
LoopOverCoordinate
)]
if
len
(
containedLoops
)
==
1
:
containedLoop
=
containedLoops
[
0
]
try
:
containedLoopRange
=
int
(
containedLoop
.
stop
-
containedLoop
.
start
)
if
containedLoopRange
>
loopRange
:
loopToParallelize
=
containedLoop
except
TypeError
:
pass
loopToParallelize
.
prefixLines
.
append
(
"
#pragma omp for schedule(%s)
"
%
(
schedule
,))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment