26 Remove macro !$mnh_(un)def(OPENACC) and !$mnh_(un)def(LOOP) directives
27 for other compiler than Cray
30 self.removeComments(exclDirectives=[],
31 pattern=re.compile(
r'^\!\$mnh_undef\(LOOP\)'))
32 self.removeComments(exclDirectives=[],
33 pattern=re.compile(
r'^\!\$mnh_undef\(OPENACC\)'))
34 self.removeComments(exclDirectives=[],
35 pattern=re.compile(
r'^\!\$mnh_define\(LOOP\)'))
36 self.removeComments(exclDirectives=[],
37 pattern=re.compile(
r'^\!\$mnh_define\(OPENACC\)'))
42 By pass a bug of the CRAY compiler in which the vectorisation is not done with
43 BR_ fonctions use or locally.
44 On all expanded compute kernels with !$acc loop independent collapse(X) placed:
45 - if BR_ fonction is used : !$acc loop independent collapse(X) is removed and
46 the nested DO loops are factorised into DO CONCURRENT
47 - if a mnh_undef(OPENACC) macro is in place, !$acc loop collapse independant(X)
49 - if a mnh_undef(LOOP) macro is in place the nested DO loops are factorised into
52 def checkPresenceofBR(node):
53 """Return True if a BR_ (math BIT-REPRODUCTIBILITY) function is present in the node"""
54 mathBRList = [
'ALOG',
'LOG',
'EXP',
'COS',
'SIN',
'ASIN',
'ATAN',
'ATAN2',
56 namedE = node.findall(
'.//{*}named-E/{*}N/{*}n')
58 if alltext(el)
in [
'BR_' + e
for e
in mathBRList]:
62 def getStatementsInDoConstruct(node, savelist):
64 if 'do-construct' in tag(sNode):
65 getStatementsInDoConstruct(sNode, savelist)
66 elif 'do-stmt' not in tag(sNode):
67 savelist.append(sNode)
70 useAccLoopIndependent =
True
72 comments = self.findall(
'.//{*}C')
74 for comment
in comments:
75 if comment.text.startswith(
'!$mnh_undef(LOOP)'):
76 useNestedLoops =
False
77 if comment.text.startswith(
'!$mnh_undef(OPENACC)'):
78 useAccLoopIndependent =
False
80 if comment.text.startswith(
'!$mnh_define(LOOP)'):
82 if comment.text.startswith(
'!$mnh_define(OPENACC)'):
83 useAccLoopIndependent =
True
85 if comment.text.startswith(
'!$acc loop independent collapse('):
87 par = self.getParent(comment)
88 ind = list(par).index(comment)
89 nestedLoop = par[ind + 1]
91 getStatementsInDoConstruct(nestedLoop, statements)
95 for stmt
in statements:
96 if checkPresenceofBR(stmt):
102 if not useAccLoopIndependent
or isBRPresent:
103 toremove.append((self, comment))
106 if not useNestedLoops
or isBRPresent:
108 doStmt = nestedLoop.findall(
'.//{*}do-stmt')
110 for do
in reversed(doStmt):
111 table[do.find(
'.//{*}do-V/{*}named-E/{*}N/{*}n').text] = \
112 [alltext(do.find(
'.//{*}lower-bound')),
113 alltext(do.find(
'.//{*}upper-bound'))]
116 inner, outer, _ = self.createDoConstruct(table,
117 indent=len(nestedLoop.tail),
121 for stmt
in statements:
122 inner.insert(-1, stmt)
125 par.insert(ind, outer)
126 toremove.append((par, nestedLoop))
129 for parent, elem
in toremove:
135 1) Add after declaration:
136 !$acc data present ( list of intent arrays)
137 2) Add at the end of the routine
140 scopes = self.getScopes()
141 if scopes[0].path.split(
'/')[-1].split(
':')[1][:4] ==
'MODD':
148 if 'sub:' in scope.path
and 'func' not in scope.path
and 'interface' not in scope.path:
151 for var
in scope.varList:
153 if var[
'arg']
and var[
'as']
and 'TYPE' not in var[
't']
and \
154 var[
'scopePath'] == scope.path:
155 arraysIntent.append(var[
'n'])
157 if len(arraysIntent) == 0:
161 listVar =
"!$acc data present ( "
163 for var
in arraysIntent:
165 listVar = listVar +
'\n!$acc & '
167 listVar = listVar + var +
", &"
169 listVarEnd = listVar[:-3]
170 accAddMultipleLines = createExpr(listVarEnd +
')')
171 idx = scope.insertStatement(scope.indent(accAddMultipleLines[0]), first=
True)
174 for iLine, line
in enumerate(accAddMultipleLines[1:]):
175 scope.insert(idx + 1 + iLine, line)
178 comment = createElem(
'C', text=
'!$acc end data', tail=
'\n')
179 scope.insertStatement(scope.indent(comment), first=
False)