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

Refactor duplicated code in m_kern_exx_ subroutines #346

Open
tkoskela opened this issue Apr 22, 2024 · 7 comments · Fixed by #352
Open

Refactor duplicated code in m_kern_exx_ subroutines #346

tkoskela opened this issue Apr 22, 2024 · 7 comments · Fixed by #352
Assignees
Labels
needs: diagnosis Diagnosis required for bug or issue time: days type: maintenance Refactoring, updating etc

Comments

@tkoskela
Copy link
Contributor

Based on our meeting with @lionelalexandre on April 12, we need to investigate how much we can reduce code duplication in the subroutines

subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, &

subroutine m_kern_exx_eri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, &

subroutine m_kern_exx_eri_gto(k_off, kpart, ib_nd_acc, ibaddr, nbnab, &

subroutine m_kern_exx_dummy(k_off, kpart, ib_nd_acc, ibaddr, nbnab, &

and do some refactoring before carrying on with the parallelisation work

@tkoskela tkoskela added needs: diagnosis Diagnosis required for bug or issue time: days type: maintenance Refactoring, updating etc labels Apr 22, 2024
@connoraird
Copy link
Contributor

connoraird commented Apr 22, 2024

After comparing m_kern_exx_cri and m_kern_exx_eri, it does not look simple to reduce their duplication through refactoring. Many similar things are happening in both but the loop structures are different. For example in m_kern_exx_cri there is the loop do l = 1, nbnab(k_in_part) and inside this loop K_val and Phy_k are set before the loop is closed. However, in m_kern_exx_eri this same loop contains the setting of K_val as well as the rest of the kernel.

Further down the loop nest, the loop structure differs again. In m_kern_exx_cri there are two nested loops over kg%nsup and jb%nsup but in m_kern_exx_eri the loop is not nested and is only over jb%nsup.

@connoraird
Copy link
Contributor

connoraird commented Apr 22, 2024

After comparing m_kern_exx_eri and m_kern_exx_eri_gto, the only differences seem to be that arrays are allocated in m_kern_exx_eri but not m_kern_exx_eri_gto and that m_kern_exx_eri_gto calls compute_eri_hoh at it's deepest point whereas m_kern_exx_eri calls exx_ewald_charge and exx_v_on_grid and performs calculations in a triple nested loop.

Therefore, it should be possible to reduce code duplication between these two kernels by first moving array allocations in m_kern_exx_eri outside of the duplicated region.

yes, this is correct ; I should have done this before...

@connoraird
Copy link
Contributor

m_kern_exx_eri and m_kern_exx_dummy are also very similar with the main difference being that arrays are allocated at the beginning of m_kern_exx_dummy. Therefore, this can also likely be refactored to deduplicate code.

@lionelalexandre
Copy link
Contributor

m_kern_exx_eri and m_kern_exx_dummy are also very similar with the main difference being that arrays are allocated at the beginning of m_kern_exx_dummy. Therefore, this can also likely be refactored to deduplicate code.

I am not sure but you will need to had a if statement in the nested loops. Can it be a problem ?

@lionelalexandre
Copy link
Contributor

After comparing m_kern_exx_eri and m_kern_exx_eri_gto, the only differences seem to be that arrays are allocated in m_kern_exx_eri but not m_kern_exx_eri_gto and that m_kern_exx_eri_gto calls compute_eri_hoh at it's deepest point whereas m_kern_exx_eri calls exx_ewald_charge and exx_v_on_grid and performs calculations in a triple nested loop.

Therefore, it should be possible to reduce code duplication between these two kernels by first moving array allocations in m_kern_exx_eri outside of the duplicated region.

yes, this is correct ; I should have done this before...

@lionelalexandre
Copy link
Contributor

lionelalexandre commented Apr 22, 2024

After comparing m_kern_exx_cri and m_kern_exx_eri, it does not look simple to reduce their duplication through refactoring. Many similar things are happening in both but the loop structures are different. For example in m_kern_exx_cri there is the loop do l = 1, nbnab(k_in_part) and inside this loop K_val and Phy_k are set before the loop is closed. However, in m_kern_exx_eri this same loop contains the setting of K_val as well as the rest of the kernel.

Further down the loop nest, the loop structure differs again. In m_kern_exx_cri there are two nested loops over kg%nsup and jb%nsup but in m_kern_exx_eri the loop is not nested and is only over jb%nsup.

@connoraird
Copy link
Contributor

connoraird commented Apr 25, 2024

I believe the code inside the do nsf2 = 1, jb%nsup loop is the same for m_kern_exx_cri and m_kern_exx_eri. Therefore, this should be able to be pulled out into a single subroutine.

@connoraird connoraird linked a pull request May 29, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: diagnosis Diagnosis required for bug or issue time: days type: maintenance Refactoring, updating etc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants