From bba54a4e48138b1a8524f8e2b76b7d38f41194e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Riette?= Date: Tue, 15 Oct 2024 09:57:21 +0200 Subject: [PATCH] Option --restrictScope added --- bin/pyft_parallel_tool.py | 2 +- bin/pyft_tool.py | 10 +++++--- doc/Documentation.md | 43 +++++++++++++++++++------------- examples/addArgInTree_after.F90 | 19 ++++++++++++++ examples/addArgInTree_before.F90 | 17 +++++++++++++ src/pyft/scripting.py | 40 +++++++++++++++++------------ 6 files changed, 93 insertions(+), 38 deletions(-) create mode 100644 examples/addArgInTree_after.F90 create mode 100644 examples/addArgInTree_before.F90 diff --git a/bin/pyft_parallel_tool.py b/bin/pyft_parallel_tool.py index 6b2dbe5..da1c545 100755 --- a/bin/pyft_parallel_tool.py +++ b/bin/pyft_parallel_tool.py @@ -44,7 +44,7 @@ def init(cls): epilog="The argument order matters.") updateParser(parser, withInput=False, withOutput=False, withXml=False, withPlotCentralFile=True, - treeIsOptional=False, nbPar=True) + treeIsOptional=False, nbPar=True, restrictScope=False) commonArgs, getFileArgs = getArgs(parser) # Manager to share the Tree instance diff --git a/bin/pyft_tool.py b/bin/pyft_tool.py index 0626e2f..42e845d 100755 --- a/bin/pyft_tool.py +++ b/bin/pyft_tool.py @@ -17,7 +17,7 @@ epilog="The argument order matters.") updateParser(parser, withInput=True, withOutput=True, withXml=True, withPlotCentralFile=False, - treeIsOptional=True, nbPar=False) + treeIsOptional=True, nbPar=False, restrictScope=True) args, orderedOptions = getArgs(parser)[1]() parserOptions = getParserOptions(args) @@ -28,6 +28,8 @@ pft = PYFT(args.INPUT, args.OUTPUT, parser=args.parser, parserOptions=parserOptions, verbosity=args.logLevel, wrapH=args.wrapH, tree=descTree, enableCache=args.enableCache) + if args.restrictScope != '': + pft = pft.getScopeNode(args.restrictScope) # apply the transformation in the order they were specified for arg in orderedOptions: @@ -39,12 +41,12 @@ if descTree is not None: descTree.toJson(args.descTree) if args.xml is not None: - pft.writeXML(args.xml) + pft.mainScope.writeXML(args.xml) if not args.dryRun: - pft.write() + pft.mainScope.write() # Closing - pft.close() + pft.mainScope.close() except: # noqa E722 # 'exept' everything and re-raise error systematically diff --git a/doc/Documentation.md b/doc/Documentation.md index 9e69c5b..49f88ee 100644 --- a/doc/Documentation.md +++ b/doc/Documentation.md @@ -101,6 +101,9 @@ applicable line is used. A line can take one of these two forms: * "OPTIONS": if the line doesn\'t contain the FILE\_DESCRIPTOR part, it applies to all source code. +**--restrictScope SCOPEPATH** Limit the action to this scope path (as described in +[Concepts](#concepts)). + ### Dealing with variables **\--showVariables** displays a list of all the declared variables @@ -130,15 +133,11 @@ the third one is the variable name. **\--attachArraySpecToEntity** move the array declaration attributes to the right part of the declaration statement (e.g. "REAL, DIMENSION(5) :: X" becomes "REAL :: X(5)") -**\--showUnusedVariables [SCOPEPATH]** lists the unused varibales. Without argument all the -unused variables are shown. If one argument is given it is the scope path (as described -in [Concepts](#concepts)) where unused variables are searched for. +**\--showUnusedVariables** lists the unused varibales. -**\--removeUnusedLocalVariables SCOPEPATH EXCLUDE** remove unused local variables. Without argument all the -unused variables are suppressed. If one argument is given it is the scope path (as described -in [Concepts](#concepts)) where unused variables are searched for. +**\--removeUnusedLocalVariables EXCLUDE** remove unused local variables. -**\--removePHYEXUnusedLocalVariables SCOPEPATH EXCLUDE** variation aroud the \--removeUnusedLocalVariables +**\--removePHYEXUnusedLocalVariables EXCLUDE** variation aroud the \--removeUnusedLocalVariables to deal with the variables declared in the mnh\_expand directives. **\--addExplicitArrayBounds** Adds explicit bounds to arrays that already have parentheses. @@ -156,11 +155,12 @@ replaces automatic arrays by allocatables. **\--replaceAutomaticWithAllocatable** replace all automatic arrays with allocatables -**\--addArgInTree** Add an argument variable recursively. First argument is the scope (as -described in [Concepts](#concepts), the second is the variable name, the third is the -declarative statement to insert, the fourth is the position (python indexing) the new -variable will have in the calling statment of the routine. The recursive inclusion of -the argument variable stop at the scopes defined by the --stopScopes option. +**\--addArgInTree** Add an argument variable recursively begining at the scope path +defined with the --restrictScope option. The first argument is the variable name, +the second one is the declarative statement to insert, the third one fourth is the position +(python indexing) the new variable will have in the calling statment of the routine. +The recursive inclusion of the argument variable stops at the scopes defined by the +--stopScopes option. ### Cosmetics @@ -214,9 +214,7 @@ if option is 'Warn'; otherwise issue an error message and raise an exception. ### Dealing with statements -**\--removeCall SCOPEPATH CALLNAME** removes call statements. The first argument describes from where the -call statements must be suppressed (it is a scope path as described in [Concepts](#concepts)). -The second argument is the subprogram name. +**\--removeCall CALLNAME** removes call statements. The argument is the subprogram name. **\--removePrints** removes print statements. The argument describes from where the call statements must be suppressed (it is a scope path as described in [Concepts](#concepts)). @@ -239,6 +237,9 @@ call statements must be suppressed (it is a scope path as described in [Concepts **\--deleteBudgetDDH** delete Budget/DDH use. +**--deleteRoutineCallsMesoNHGPU** Delete parts of the code not compatible with MesoNH-OpenACC +such as OCND2 blocks. + **\--deleteNonColumnCallsPHYEX** delete call to PHYEX routines that needs information on horizontal points (multiple column dependency). @@ -274,17 +275,25 @@ inout arrays in subroutines. **\--mathFunctoBRFunc** Convert intrinsic math functions **, LOG, ATAN, **2, **3, **4, EXP, COS, SIN, ATAN2 into a self defined function BR_ for MesoNH bit-repro. +**--convertTypesInCompute** Use single variable instead of variable contained in structure +in compute statement for optimization issue. + ### OpenACC -**\--addACC_data** add !$acc data present and !$acc end data directives +**\--addACCData** add !$acc data present and !$acc end data directives -**\--addACC_routine_seq** add "!$acc routine seq" to routines called directly or indirectly +**\--addACCRoutineSeq** add "!$acc routine seq" to routines called directly or indirectly by scopes defined by the --stopScopes option. **\--buildACCTypeHelpers** build module files containing helpers to copy user type structures. +**--craybyPassDOCONCURRENT** remove acc loop independant collapse for BR_ fonctions and +mnh\_undef(OPENACC) macro use DO CONCURRENT with mnh\_undef(LOOP) + **\--removeACC** remove ACC directives +**--removebyPassDOCONCURRENT** remove macro !$mnh\_(un)def(OPENACC) and !$mnh\_(un)def(LOOP) directives + ### Preprocessor **\--applyCPPifdef** This option is followed by the list of defined or undefined CPP keys. diff --git a/examples/addArgInTree_after.F90 b/examples/addArgInTree_after.F90 new file mode 100644 index 0000000..c4a62ab --- /dev/null +++ b/examples/addArgInTree_after.F90 @@ -0,0 +1,19 @@ +!#PYFT transfo: --addArgInTree XX REAL::XX 0 --restrictScope module:ADDARGINTREE/sub:FOO1/sub:FOO3 --stopScopes module:ADDARGINTREE/sub:FOO1/sub:FOO2 + +MODULE ADDARGINTREE + CONTAINS + SUBROUTINE FOO1() + CALL FOO2() + CONTAINS + SUBROUTINE FOO2(XX) +REAL::XX + CALL FOO3(XX) + CALL FOO4() + END SUBROUTINE FOO2 + SUBROUTINE FOO3(XX) +REAL::XX + END SUBROUTINE FOO3 + SUBROUTINE FOO4() + END SUBROUTINE FOO4 + END SUBROUTINE FOO1 +END MODULE ADDARGINTREE diff --git a/examples/addArgInTree_before.F90 b/examples/addArgInTree_before.F90 new file mode 100644 index 0000000..73080a8 --- /dev/null +++ b/examples/addArgInTree_before.F90 @@ -0,0 +1,17 @@ +!#PYFT transfo: --addArgInTree XX REAL::XX 0 --restrictScope module:ADDARGINTREE/sub:FOO1/sub:FOO3 --stopScopes module:ADDARGINTREE/sub:FOO1/sub:FOO2 + +MODULE ADDARGINTREE + CONTAINS + SUBROUTINE FOO1() + CALL FOO2() + CONTAINS + SUBROUTINE FOO2() + CALL FOO3() + CALL FOO4() + END SUBROUTINE FOO2 + SUBROUTINE FOO3() + END SUBROUTINE FOO3 + SUBROUTINE FOO4() + END SUBROUTINE FOO4 + END SUBROUTINE FOO1 +END MODULE ADDARGINTREE diff --git a/src/pyft/scripting.py b/src/pyft/scripting.py index f77c480..3e9ed19 100644 --- a/src/pyft/scripting.py +++ b/src/pyft/scripting.py @@ -98,7 +98,7 @@ def getDescTree(args, cls=Tree): def updateParser(parser, withInput, withOutput, withXml, withPlotCentralFile, treeIsOptional, - nbPar): + nbPar, restrictScope): """ Updates an argparse parser with arguments common to all the different tools :param parser: parser in which arguments are added @@ -108,6 +108,7 @@ def updateParser(parser, withInput, withOutput, withXml, withPlotCentralFile, tr :param withPlotCentralFile: to add the --plotCentralFile argument :param treeIsOptional: is the --tree argument optional? :param nbPar: number of parallel processes + :param restrictScope: can we specify the scope path """ # ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! @@ -145,6 +146,14 @@ def updateParser(parser, withInput, withOutput, withXml, withPlotCentralFile, tr '2) "OPTIONS" (if the line doesn\'t contain the FILE_DESCRIPTOR ' + 'part, it applies to all source code).') + if restrictScope: + parser.add_argument('--restrictScope', default=None, type=str, metavar='SCOPEPATH', + help="Limit the action to this scope path (SUBROUTINE/FUNCTION/" + + "MODULE/TYPE). It is '/'-separated path with each element " + + "having the form 'module:', " + + "'sub:', " + + "'func:' or 'type:'.") + # Inputs and outputs updateParserInputsOutputs(parser, withInput, withOutput, withXml) @@ -282,13 +291,12 @@ def updateParserVariables(parser): 'will replace automatic arrays by allocatables.') gVariables.add_argument('--replaceAutomaticWithAllocatable', action='store_true', help='Replace all automatic arrays with allocatable arrays.') - gVariables.add_argument('--addArgInTree', default=None, action='append', nargs=4, - metavar=('SCOPEPATH', 'VARNAME', 'DECLARATION', 'POSITION'), - help='Add an argument variable. The argument is the scope path (as ' + - 'for the --removeVariable option. The second is the variable ' + - 'name, the third is the declarative statement to insert, ' + - 'the fourth is the position (python indexing) the new ' + - 'variable will have in the calling statment of the ' + + gVariables.add_argument('--addArgInTree', default=None, action='append', nargs=3, + metavar=('VARNAME', 'DECLARATION', 'POSITION'), + help='Add an argument variable. The first argument is the variable ' + + 'name, the second one is the declarative statement to insert, ' + + 'the third one is the position (python indexing) the new ' + + 'variable will have in the calling statement of the ' + 'routine. Needs the --stopScopes argument') @@ -384,9 +392,6 @@ def updateParserApplications(parser): 'all in and inout arrays in subroutines') gApplications.add_argument('--shumanFUNCtoCALL', default=False, action='store_true', help='Transform shuman functions to call statements') - gApplications.add_argument('--buildACCTypeHelpers', default=False, action='store_true', - help='build module files containing helpers to copy user ' + - 'type structures') gApplications.add_argument('--mathFunctoBRFunc', default=False, action='store_true', help='Convert intrinsic math functions **, LOG, ATAN, **2, **3, ' + '**4, EXP, COS, SIN, ATAN2 into a self defined function BR_ ' + @@ -414,6 +419,9 @@ def updateParserOpenACC(parser): gOpenACC.add_argument('--removebyPassDOCONCURRENT', default=False, action='store_true', help='remove macro !$mnh_(un)def(OPENACC) and !$mnh_(un)def(LOOP) ' + 'directives') + gOpenACC.add_argument('--buildACCTypeHelpers', default=False, action='store_true', + help='build module files containing helpers to copy user ' + + 'type structures') def updateParserChecks(parser): @@ -601,11 +609,11 @@ def applyTransfoVariables(pft, arg, args, simplify, parserOptions, stopScopes): "{type}, DIMENSION({doubledotshape}), ALLOCATABLE :: {name}", "ALLOCATE({name}({shape}))", "DEALLOCATE({name})") elif arg == '--addArgInTree': - for scopePath, varName, declStmt, pos in args.addArgInTree: - pft.getScopeNode(scopePath).addArgInTree(varName, declStmt, int(pos), stopScopes, - parser=args.parser, - parserOptions=parserOptions, - wrapH=args.wrapH) + for varName, declStmt, pos in args.addArgInTree: + pft.addArgInTree(varName, declStmt, int(pos), stopScopes, + parser=args.parser, + parserOptions=parserOptions, + wrapH=args.wrapH) def applyTransfoApplications(pft, arg, args, simplify, parserOptions, stopScopes):