rayla_lsy,
I have modified (untested!!) the code you posted to replace local and automatic arrays with ALLOCATE arrays. This should reduce the stack requirement. Compile and test and hopefully it will work better.
John
program test
integer, parameter :: ikind_real = selected_real_kind(p=8 )
integer, parameter :: NP106 = 70695
real(kind = ikind_real), ALLOCATABLE :: rcoeff_dist(:,:)
integer :: stat, n
allocate ( rcoeff_dist (NP106,28 ), stat=stat )
call check_allocate ( 'rcoeff_dist (NP106,28 )', stat )
call init_random_seed()
n=28
call r8_normal_mn(rcoeff_dist,NP106,n)
end program test
!========================================================================================================================================
!A subroutine to generate random variable from N(0,1)
!========================================================================================================================================
subroutine r8_normal_mn(X,m,n)
implicit none
integer, parameter :: ikind_real= selected_real_kind(p=8 )
integer :: m,n, i,j, stat
real(kind = ikind_real), allocatable, dimension(:,:) :: r1,r2
real, parameter :: r4_pi = 3.141592653589793E+00
real(kind = ikind_real), dimension(m,n) :: X
allocate ( r1(m,n), stat = stat ) ; call check_allocate ( 'r1(m,n)', stat )
allocate ( r2(m,n), stat = stat ) ; call check_allocate ( 'r2(m,n)', stat )
call psurand(r1,m,n)
call psurand(r2,m,n)
do i = 1,m
do j = 1,n
X(i,j) = sqrt ( - 2.0E+00 * log ( r1(i,j) ) ) * cos ( 2.0E+00 * r4_pi * r2(i,j) )
end do
end do
write (*,*) 'X initialised'
return
end subroutine r8_normal_mn
! ========================================================================================================================================
! A subroutine to generate random vector for uniform distribution
! ========================================================================================================================================
subroutine psurand(X,m,n)
implicit none
integer :: m,n
integer, parameter :: ikind_real = selected_real_kind(p=8 )
real(kind = ikind_real), dimension(m,n) :: X
CALL RANDOM_NUMBER(HARVEST = X)
END subroutine psurand
!========================================================================================================================================
! A subroutine to generate seed
!========================================================================================================================================
!We just need to regenerate the seed each time I am starting the program.
subroutine init_random_seed()
INTEGER :: i, n, clock
INTEGER, DIMENSION( : ), ALLOCATABLE :: seed
CALL RANDOM_SEED(size = n)
ALLOCATE(seed(n))
CALL SYSTEM_CLOCK(COUNT=clock)
seed = clock + 37 * (/ (i - 1, i = 1, n) /)
CALL RANDOM_SEED(PUT = seed)
DEALLOCATE(seed)
end subroutine init_random_seed
subroutine check_allocate ( array, stat )
character array*(*)
integer stat
!
if ( stat /= 0 ) then
write (*,*) 'Unable to allocate array ',array,' stat=',stat
stop
else
write (*,*) 'array :',array,' allocated sucessfully'
end if
end subroutine check_allocate