Fortran recursion segmentation faults
- by ConnorG
Hey all -
I have to design and implement a Fortran routine to determine the size of clusters on a square lattice, and it seemed extremely convenient to code the subroutine recursively. However, whenever my lattice size grows beyond a certain value (around 200/side), the subroutine consistently segfaults. Here's my cluster-detection routine:
RECURSIVE SUBROUTINE growCluster(lattice, adj, idx, area)
INTEGER, INTENT(INOUT) :: lattice(:), area
INTEGER, INTENT(IN) :: adj(:,:), idx
lattice(idx) = -1
area = area + 1
IF (lattice(adj(1,idx)).GT.0) &
CALL growCluster(lattice,adj,adj(1,idx),area)
IF (lattice(adj(2,idx)).GT.0) &
CALL growCluster(lattice,adj,adj(2,idx),area)
IF (lattice(adj(3,idx)).GT.0) &
CALL growCluster(lattice,adj,adj(3,idx),area)
IF (lattice(adj(4,idx)).GT.0) &
CALL growCluster(lattice,adj,adj(4,idx),area)
END SUBROUTINE growCluster
where adj(1,n) represents the north neighbor of site n, adj(2,n) represents the west and so on. What would cause the erratic segfault behavior? Is the cluster just "too huge" for large lattice sizes?