Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions src/overset/oversetUtilities.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ subroutine addToFringeList(fringeList, n, fringe)
integer(kind=intType), intent(inout) :: n

! Working Paramters
integer(kind=intType) :: fSize
integer(kind=intType) :: fSize, i
type(fringeType), dimension(:), pointer :: tmpFringePtr
fSize = size(fringeList)

Expand All @@ -1255,8 +1255,14 @@ subroutine addToFringeList(fringeList, n, fringe)
! Allocate new space
allocate (fringeList(int(1.5 * fSize)))

! Copy exsitng values
fringeList(1:fSize) = tmpFringePtr(1:fSize)
! Copy values to new array. Note: we deliberately use an explicit loop here rather than whole-array
! assignment (`fringeList(1:fSize) = tmpFringePtr(1:fSize)`). Because fringeList and tmpFringePtr are both
! pointers, a whole-array copy forces the compiler to materialise a temporary array. Under -Ofast, `
! -fstack-arrays` is enabled which means this temporary array will be stack allocated. Depending on the size
! of the mesh, the fringe list can exceed the default stack size, leading to a stack overflow.
do i = 1, fSize
fringeList(i) = tmpFringePtr(i)
end do

! Free original memory
deallocate (tmpFringePtr)
Expand All @@ -1274,6 +1280,7 @@ subroutine addToFringeBuffer(intBuffer, realBuffer, n, fringe)

use constants
use block, only: fringeType
use utils, only: reallocateInteger2, reallocateReal2

implicit none

Expand All @@ -1285,29 +1292,16 @@ subroutine addToFringeBuffer(intBuffer, realBuffer, n, fringe)

! Working Paramters
integer(kind=intType) :: fSize
integer(kind=intType), dimension(:, :), pointer :: tmpInt
real(kind=realType), dimension(:, :), pointer :: tmpReal
fSize = size(intBuffer, 2)

! Increment n for next item
n = n + 1

if (n > fSize) then

! Pointers to existing data:
tmpInt => intBuffer
tmpReal => realBuffer

! Allocate new space
allocate (intBuffer(5, int(1.5 * fSize)))
allocate (realBuffer(4, int(1.5 * fSize)))

! Copy exsitng values
intBuffer(:, 1:fSize) = tmpInt(:, 1:fSize)
realBuffer(:, 1:fSize) = tmpReal(:, 1:fSize)

! Free original memory
deallocate (tmpInt, tmpReal)
! Increase the buffer sizes by 50%.
call reallocateInteger2(intBuffer, 5, int(1.5 * fSize), 5, fSize, .true.)
call reallocateReal2(realBuffer, 4, int(1.5 * fSize), 4, fSize, .true.)

end if

Expand Down