-
Notifications
You must be signed in to change notification settings - Fork 67
Adjust the bdy_lyr local script, and housekeeping #231
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
70b50c7
eb004a0
5448515
db6c499
cd76b02
86496e8
df13819
d7b7c83
4ff21c4
515366b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -27,13 +27,14 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Routine, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Loop, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| OMPParallelDirective, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| IfBlock, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Reference, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| from psyclone.transformations import (TransformationError) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| from transmute_psytrans.transmute_functions import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| loop_replacement_of, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| get_compiler, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| first_priv_red_init, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| remove_unspanable_nodes, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| set_pure_subroutines, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| replace_n_threads, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| OMP_PARALLEL_REGION_TRANS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -53,7 +54,6 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||
| "i": {"variable": "i"}}) # For bdy_impl3.F90 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Longer term we will raise some of these into a override import, see Apps#900 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # pylint: disable=too-many-locals | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # pylint: disable=too-many-statements | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # pylint: disable=too-many-branches | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -130,19 +130,62 @@ def trans(psyir): | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Span a parallel section across the whole routine, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # apart for a few exceptions provided | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| for routine in psyir.walk(Routine): | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| routine_children = remove_unspanable_nodes( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| routine, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| timer_routine_names, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| loop_type_init | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Span the region across filtered down node list | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| OMP_PARALLEL_REGION_TRANS.apply( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| routine_children) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| except (TransformationError, IndexError) as err: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| logging.warning("OMPParallelTrans failed: %s", err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| for routine in psyir.walk(Routine): #pylint: disable=R1702 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Get the list of children of the routine | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| routine_children = routine.children | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Default reference for start_node | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| start_node = None | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Work through the routine's children from the start. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| for index, routine_child in enumerate(routine_children): | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # When the first loop or if block is found, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # place it as the start reference index. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if isinstance(routine_child, Loop): #pylint: disable=R1723 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| start_node = index | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| elif isinstance(routine_child, IfBlock): | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| found_valid_if = True | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Often timing handles are placed inside if blocks, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # check if it is not a known timing call, which should be | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # ignored for spanning a parallel section. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| for routine_grandchild in routine_child.walk(Reference): | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if str(routine_grandchild.name) in timer_routine_names: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| found_valid_if = False | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| except ValueError: # noqa: E722 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if found_valid_if: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| start_node = index | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Default reference for end_node | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| end_node = None | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| for index in range((len(routine_children)-1), 0, -1): | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Like above, work backwards through the routine's children. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if isinstance(routine_children[index], Loop): #pylint: disable=R1723 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| end_node = index + 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| elif isinstance(routine_children[index], IfBlock): | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| found_valid_if = True | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| for routine_grandchild in \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| routine_children[index].walk(Reference): | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if str(routine_grandchild.name) in timer_routine_names: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| found_valid_if = False | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| except ValueError: # noqa: E722 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if found_valid_if: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| end_node = index + 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| found_valid_if = True | |
| for routine_grandchild in \ | |
| routine_children[index].walk(Reference): | |
| try: | |
| if str(routine_grandchild.name) in timer_routine_names: | |
| found_valid_if = False | |
| except ValueError: # noqa: E722 | |
| continue | |
| if found_valid_if: | |
| end_node = index + 1 | |
| break | |
| for routine_grandchild in \ | |
| routine_children[index].walk(Reference): | |
| if str(routine_grandchild.name) in timer_routine_names: | |
| # end_node remains None. | |
| end_node = None | |
| break | |
| else: | |
| # Otherwise, set to correct position and continue | |
| # checking for calls that invalidate this. | |
| end_node = index + 1 | |
| # Now check to see if we have a satisfactory end_node | |
| if end_node is not None: | |
| break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can break out of this for loop much quicker by using this setup. I have tested this on
bl_diags_mod.F90and the PSyclone generated output is the same.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only concern with this, and why I opted for a try / except, is when PSyclone runs into an occurrence where a grandchild node doesn't have a name property, it will just crash.
Wrapping it in a try / except protects us from this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the breaking early on a if not none test I'm pro
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't aware of that. Perhaps adding this in a comment would be a good idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, hopefully this covers it:
4ff21c4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And for above and below SR advice with try / except preserved:
86496e8