Skip to content

Conversation

Copy link

Copilot AI commented Dec 4, 2025

Description of the feature or the bug

The ccoor*.F files contained repetitive hand-coded loops for array assignments and manual distance calculations that could be replaced with more efficient Fortran intrinsics and array operations.

Description of the changes

Replaced hand-coded loops with array slice operations and intrinsic functions across four files:

Array slice operations:

  • Connectivity/ID assignments: IX1(LFT:LLT)=IXC(2,LFT:LLT) instead of DO loops
  • Scalar assignments: DT1C(JFT:JLT)=DT1 instead of element-by-element assignment
  • 3D velocity/rotation: VL1(I,1:3)=V(1:3,IXCTMP2) instead of 3 separate lines per node
  • Zeroing operations: VL1(I,1:3)=ZERO instead of 3 separate assignments

Intrinsic functions:

  • Surface normal magnitude: HYPOT(HYPOT(E3X,E3Y),E3Z) for better numerical accuracy
  • Kept squared distance calculations unchanged (XN* variables used in comparisons)

Code cleanup:

  • Removed redundant loop in ccoor3.F that set IXCTMP* variables without using them

Example transformation:

! Before (48 lines):
VL1(I,1)=V(1,IXCTMP2)
VL1(I,2)=V(2,IXCTMP2)
VL1(I,3)=V(3,IXCTMP2)
VL2(I,1)=V(1,IXCTMP3)
...
VRL4(I,3)=VR(3,IXCTMP5)

! After (8 lines):
VL1(I,1:3)=V(1:3,IXCTMP2)
VL2(I,1:3)=V(1:3,IXCTMP3)
VL3(I,1:3)=V(1:3,IXCTMP4)
VL4(I,1:3)=V(1:3,IXCTMP5)
VRL1(I,1:3)=VR(1:3,IXCTMP2)
VRL2(I,1:3)=VR(1:3,IXCTMP3)
VRL3(I,1:3)=VR(1:3,IXCTMP4)
VRL4(I,1:3)=VR(1:3,IXCTMP5)

Net reduction: 171 lines → 71 lines (~58% reduction)

Original prompt

Can you have a look at ccoor*F files?
I would like to look for optimization opportunities. In particular by using intrinsic fuctions instead of home made code snippet, and array operations instead of hand-made loops.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 8 commits November 27, 2025 22:55
* Initial plan

* Fix MPI type inconsistencies in SPMD wrapper functions

Co-authored-by: laurent-altr <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: laurent-altr <[email protected]>
…#112)

* Initial plan

* Fix spmd_wait intent: change request from intent(in) to intent(inout)

Co-authored-by: laurent-altr <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: laurent-altr <[email protected]>
* Initial plan

* Clean up spmd_wait.F90 - remove duplicate separator lines

Co-authored-by: laurent-altr <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: laurent-altr <[email protected]>
* Initial plan

* Fix 2D array dimension mismatch in spmd_send.F90

Co-authored-by: laurent-altr <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: laurent-altr <[email protected]>
#118)

* Initial plan

* Add missing non-MPI fallback paths for scalar allgatherv functions

Co-authored-by: laurent-altr <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: laurent-altr <[email protected]>
* Initial plan

* Fix 2D array dimension ordering in spmd_recv.F90 to match spmd_send.F90

Co-authored-by: laurent-altr <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: laurent-altr <[email protected]>
* Initial plan

* Fix inconsistent local variable declarations in spmd_*pack.F90

Co-authored-by: laurent-altr <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: laurent-altr <[email protected]>
Copilot AI changed the title [WIP] Optimize ccoor*F files using intrinsic functions Optimize ccoor*.F files with array operations and intrinsic functions Dec 4, 2025
Copilot AI requested a review from laurent-altr December 4, 2025 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants