Skip to content

Commit

Permalink
(#44, #8) unsafe memory allocation of listneigh fixed, which also fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljprice committed Aug 5, 2020
1 parent 69b31ba commit b1f6930
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/main/dens.F90
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ subroutine densityiterate(icall,npart,nactive,xyzh,vxyzu,divcurlv,divcurlB,Bevol
mhd_nonideal,nalpha,use_dust
use io, only:iprint,fatal,iverbose,id,master,real4,warning,error,nprocs
use linklist, only:ifirstincell,ncells,get_neighbour_list,get_hmaxcell,&
get_cell_location,set_hmaxcell,sync_hmax_mpi
listneigh,get_cell_location,set_hmaxcell,sync_hmax_mpi
use part, only:mhd,rhoh,dhdrho,rhoanddhdrho,&
ll,get_partinfo,iactive,&
hrho,iphase,igas,idust,iamgas,periodic,&
Expand Down Expand Up @@ -162,9 +162,8 @@ subroutine densityiterate(icall,npart,nactive,xyzh,vxyzu,divcurlv,divcurlB,Bevol
real, intent(in) :: rad(:,:)
real, intent(inout) :: radprop(:,:)

integer, save :: listneigh(maxneigh)
real, save :: xyzcache(isizecellcache,3)
!$omp threadprivate(xyzcache,listneigh)
!$omp threadprivate(xyzcache)

integer :: i,icell
integer :: nneigh,np
Expand Down
5 changes: 2 additions & 3 deletions src/main/force.F90
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ subroutine force(icall,npart,xyzh,vxyzu,fxyzu,divcurlv,divcurlB,Bevol,dBevol,&

use dim, only:maxvxyzu,maxneigh,mhd,mhd_nonideal,lightcurve
use io, only:iprint,fatal,iverbose,id,master,real4,warning,error,nprocs
use linklist, only:ncells,get_neighbour_list,get_hmaxcell,get_cell_location
use linklist, only:ncells,get_neighbour_list,get_hmaxcell,get_cell_location,listneigh
use options, only:iresistive_heating
use part, only:rhoh,dhdrho,rhoanddhdrho,alphaind,iactive,gradh,&
hrho,iphase,igas,maxgradh,dvdx,eta_nimhd,deltav,poten,iamtype
Expand Down Expand Up @@ -226,8 +226,7 @@ subroutine force(icall,npart,xyzh,vxyzu,fxyzu,divcurlv,divcurlB,Bevol,dBevol,&
real, intent(in) :: dens(:), metrics(:,:,:,:)

real, save :: xyzcache(maxcellcache,4)
integer, save :: listneigh(maxneigh)
!$omp threadprivate(xyzcache,listneigh)
!$omp threadprivate(xyzcache)
integer :: i,icell,nneigh
integer :: nstokes,nsuper,ndrag,ndustres
real :: dtmini,dtohm,dthall,dtambi,dtvisc
Expand Down
11 changes: 9 additions & 2 deletions src/main/linklist_kdtree.F90
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ module linklist
type(kdnode), allocatable :: nodeglobal(:)
type(kdnode), public, allocatable :: node(:)
integer, allocatable :: nodemap(:)

integer, public , allocatable :: listneigh(:)
!$omp threadprivate(listneigh)
integer(kind=8), public :: ncells
real, public :: dxcell
real, public :: dcellx = 0.,dcelly = 0.,dcellz = 0.
Expand All @@ -54,13 +55,17 @@ module linklist
subroutine allocate_linklist
use allocutils, only:allocate_array
use kdtree, only:allocate_kdtree
use dim, only:maxneigh

call allocate_array('cellatid', cellatid, ncellsmax+1)
call allocate_array('ifirstincell', ifirstincell, ncellsmax+1)
call allocate_array('nodeglobal', nodeglobal, ncellsmax+1)
call allocate_array('node', node, ncellsmax+1)
call allocate_array('nodemap', nodemap, ncellsmax+1)
call allocate_kdtree()
!$omp parallel
call allocate_array('listneigh',listneigh,maxneigh)
!$omp end parallel

end subroutine allocate_linklist

Expand All @@ -72,7 +77,9 @@ subroutine deallocate_linklist
if (allocated(nodeglobal)) deallocate(nodeglobal)
if (allocated(node)) deallocate(node)
if (allocated(nodemap)) deallocate(nodemap)

!$omp parallel
if (allocated(listneigh)) deallocate(listneigh)
!$omp end parallel
call deallocate_kdtree()

end subroutine deallocate_linklist
Expand Down

0 comments on commit b1f6930

Please sign in to comment.