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

#2723 Add some support for dependency analysis involving array ranges. #2880

Merged

Conversation

hiker
Copy link
Collaborator

@hiker hiker commented Feb 3, 2025

Fixes #2723. I am not sure if more support is needed or would be useful (e.g. I could check if two ranges have the same stride, but accesses different elements, ...).

Copy link

codecov bot commented Feb 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.89%. Comparing base (06e0257) to head (4aeae63).
Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2880   +/-   ##
=======================================
  Coverage   99.89%   99.89%           
=======================================
  Files         359      359           
  Lines       50997    51011   +14     
=======================================
+ Hits        50942    50956   +14     
  Misses         55       55           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hiker hiker changed the title #2878 Add some support for dependency analysis involving array ranges. #2723 Add some support for dependency analysis involving array ranges. Feb 3, 2025
@hiker hiker requested a review from sergisiso February 3, 2025 08:48
@hiker
Copy link
Collaborator Author

hiker commented Feb 3, 2025

CI was green. Note that I have some typos in the issue number - I mixed up 2878 and 2723, so e.g. the CI shows 2878, not 2723 :(

Copy link
Collaborator

@sergisiso sergisiso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks to tackling this @hiker, the implementation, docstring and tests all look great. The only comment I have is that when looking for TODOs in the same file I found a reference to #2168 (L401) which I am wondering if it's the same issue and can now also be fixed/closed. But I will approve regardless. Let me know what you think.

@hiker
Copy link
Collaborator Author

hiker commented Feb 3, 2025

Thanks to tackling this @hiker, the implementation, docstring and tests all look great. The only comment I have is that when looking for TODOs in the same file I found a reference to #2168 (L401) which I am wondering if it's the same issue and can now also be fixed/closed. But I will approve regardless. Let me know what you think.

I had a look. That issue is concerned about array-ranges that involve the loop variable that is to be parallelised, e.g.:

do i=1, n
   a(2*i:2*i+1)  = 0
enddo

(stupid example, but you get the idea). The moment the loop variable is involved, this new range comparison is not called at all. I looked if we could simply call this new function here:

Now we could do a similar test to the rest of 'one index that depends on the looppart of the dependency analysis: if there is an overlap between the array ranges for two loop iterationsi1andi2the loop cannot be parallelised. Following the current implementation, that is done by computingd=i2-i1, the distance between the loop iterations for which the indices would overlap. If this has only 0 as solution for d`, the loops can be parallelised, because there exist no other loop iteration that accesses the same range.

That leads to a systems of inequalities (I hope that's the right word), which simplifies to:
-0.5 <=d <= 0.5
So, no integer solution except 0 -> the loop can be parallelised. But you can see that this is not at all trivial, and does require more work than what we now have (atm any array range with the loop index will just be rejected).

So, #2168 is not fixed here. But if you agree that array ranges depending on loop indices do not happen in any realistic code we need to handle (or will in general be not parallelisable anyway, so the current behaviour of rejecting it is good enough), we can close #2168, and replace the #TODO with just a comment for 'the future in case we need to look at it again'?

Copy link
Collaborator

@sergisiso sergisiso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hiker I am ok with keeping the issue, I just wanted to check if it was something easy to solve with the new functionality but I agree is not. This was my only comment, this is ready to merge.

@sergisiso sergisiso merged commit e68fa69 into master Feb 4, 2025
13 checks passed
@sergisiso sergisiso deleted the 2723_improve_handling_of_ranges_in_dependency_analysis branch February 4, 2025 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

can_loop_be_parallelised fails if underlying SymbolicMath comparison produce a TypeError
2 participants