Skip to content

Commit

Permalink
Making NodeToElements faster (#439)
Browse files Browse the repository at this point in the history
Updating AbstractMesh_Class

This work is related to reducing the code in Mesh_Class and putting it to AbstractMesh_Class. Also, we are making InitiateNodeElements routine faster. 

---

<details open="true"><summary>Generated summary (powered by <a href="https://app.graphite.dev">Graphite</a>)</summary>

> ## TL;DR
> This pull request introduces a change in the `AbstractMesh_Class@NodeDataMethods.F90` file. The change involves the addition of a new variable `nodewise_size` and a new parameter `chunk_size`. The `Append` method has been replaced with the `Expand` method to improve the efficiency of the code.
> 
> ## What changed
> The `obj_InitiateNodeToElements` method in the `AbstractMesh_Class@NodeDataMethods.F90` file has been modified. A new variable `nodewise_size` has been introduced to keep track of the size of each node. A new parameter `chunk_size` has been introduced to control the size of chunks when expanding the `nodeData%globalElements` vector. The `Append` method, which was previously used to add elements to the `nodeData%globalElements` vector, has been replaced with the `Expand` method. This change is expected to improve the efficiency of the code by reducing the number of memory reallocations.
> 
> ## How to test
> To test this change, you can run the existing unit tests in the `AbstractMesh` module. If the tests pass, it means that the change has not broken any existing functionality. To test the efficiency improvement, you can run a performance benchmark that measures the time taken to execute the `obj_InitiateNodeToElements` method.
> 
> ## Why make this change
> This change is made to improve the efficiency of the `obj_InitiateNodeToElements` method. The `Append` method, which was previously used to add elements to the `nodeData%globalElements` vector, can be inefficient because it may cause multiple memory reallocations. By replacing it with the `Expand` method and controlling the size of chunks with the `chunk_size` parameter, we can reduce the number of memory reallocations and thus improve the efficiency of the code.
</details>
  • Loading branch information
vickysharma0812 authored Feb 1, 2024
2 parents 6ed414c + a96f92a commit 70372e8
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
MODULE PROCEDURE obj_InitiateNodeToElements
CHARACTER(*), PARAMETER :: myName = "obj_InitiateNodeToElements()"
INTEGER(I4B) :: ii, jj, globalElemNum, nn, localNodeNum, &
& globalNodeNum
& globalNodeNum, nodewise_size(obj%tNodes)
TYPE(CPUTime_) :: TypeCPUTime
INTEGER(I4B), PARAMETER :: chunk_size = 32

#ifdef DEBUG_VER
CALL e%RaiseInformation(modName//'::'//myName//' - '// &
Expand All @@ -47,6 +48,8 @@

obj%isNodeToElementsInitiated = .TRUE.

nodewise_size = 0

DO ii = 1, obj%tElements
globalElemNum = obj%elementData(ii)%globalElemNum

Expand All @@ -56,13 +59,19 @@
globalNodeNum = obj%elementData(ii)%globalNodes(jj)
localNodeNum = obj%local_nptrs(globalNodeNum)

CALL Append(obj%nodeData(localNodeNum)%globalElements, &
& globalElemNum)

CALL Expand(vec=obj%nodeData(localNodeNum)%globalElements, &
& n=nodewise_size(localNodeNum), chunk_size=chunk_size, &
& val=globalElemNum)
END DO

END DO

! Now we have to fix the size of `nodeData%globalElements`
DO ii = 1, obj%tNodes
CALL Expand(vec=obj%nodeData(ii)%globalElements, &
& n=nodewise_size(ii), chunk_size=chunk_size, finished=.TRUE.)
END DO

IF (obj%showTime) THEN
CALL TypeCPUTime%SetEndTime()
CALL Display(modName//" : "//myName// &
Expand Down

0 comments on commit 70372e8

Please sign in to comment.