Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

## why ifort cann't check array boundary

Beginner
495 Views

Hi

I use Intel Fortran compiler. my array is 2 dimensions an it's boundary is between 1 to 16.

this is my code and why fortran print a(0,0) and a(17,17) equal to 0 and 0

```program hirarchichal_detreministic
implicit none

integer, parameter:: N=4 !initial core
integer, parameter:: ns=1 !number of steps
integer, parameter:: nn = n**(ns+1)
integer, dimension (1:nn,1:nn):: a !adjacency matrix

integer:: i, j, k, ii, m, l

real::p(nn)

open(1,file='out')

a = 0
print*,sum(a), a(0,0), a(17,17)
pause

!******************************************
!initial fully connected network; ns=0
a(1:n,1:n)=1

do i=1,n
a(i,i)=0
enddo
!******************************************
print*,sum(a), a(0,0), a(17,170)
do i=1,ns

do k= 2, n-1

do ii= k*(n**i)+1, (k+1)*(n**i)

do j=k*(n**i)+1, (k+1)*(n**i)
!print*,i,k,ii,j
l = mod(ii,n**i+1)
m = mod(j,n**i+1)
a(ii,j) = a(l,m)
print '(20(I2,2x))',sum(a), i, k, ii, j, l, m
enddo

! pause
enddo
enddo
enddo
print*,"fd"
Do i=1, nn
!k=sum(a(1:nn,i))
!p(k)=p(k)+1.
do j=1,nn
write(1,*)i,j, a(i,j)
enddo
enddo

p=p/sum(a)
print*,"fd/"
do i=1,nn
write(1,*)i,p(i)
enddo
end
```

this is my code and why fortran print a(0,0) and a(17,17)

1 Solution
Black Belt
495 Views

A segmentation fault occurs when the resolved address resides within a virtual memory page that has not been assigned (an marked as not assignable). For a valid array, indexing 1 or a few element before or after the addresses of the array typically resolve to mapped addresses (which in Fortran-speak are undefined). Using bounds checking in most cases will catch these errors. In some cases where the array is a dummy argument, the dummy argument can potentially be specified with incorrect bounds with respect to the actual argument. In these cases the bounds checking asserts the bounds specified for the dummy argument as opposed to the actual argument at the call.

Jim Dempsey

4 Replies
Beginner
495 Views

You need to compile with the compiler options set properly. For example,

ifort -check all drb.f90 <other options that you need>

will add the code to check the bounds at run-time.

Beginner
495 Views

why not a segmentation fault error?

Black Belt
496 Views

A segmentation fault occurs when the resolved address resides within a virtual memory page that has not been assigned (an marked as not assignable). For a valid array, indexing 1 or a few element before or after the addresses of the array typically resolve to mapped addresses (which in Fortran-speak are undefined). Using bounds checking in most cases will catch these errors. In some cases where the array is a dummy argument, the dummy argument can potentially be specified with incorrect bounds with respect to the actual argument. In these cases the bounds checking asserts the bounds specified for the dummy argument as opposed to the actual argument at the call.

Jim Dempsey

Black Belt
495 Views