Q:

Segmentation fault with array indexing in Fortran

Let A and I be an arrays of the integer type with dimension N. In general, I is a permutation of the integers 1:N. I want to do A(1:N) = A(I(1:N)). For small N this works fine, but I got Segmentation fault when N is large. 
Here is an example of what I actually did:
integer N
integer,dimension(:),allocatable::A,I
N = 10000000
allocate(A(N))
allocate(I(N))
A = (/ (i,i=1,N) /)
I = (/ (N-i+1,i=1,N) /)
A(1:N) = A(I(1:N))

Is there a better way to do this?

A:

It seems that A(I(1:N)) is valid syntax, at least in my testing (gfortran 4.8, ifort 16.0, pgfortran 15.10). One problem is that i and I are the same thing, and the array I cannot be used in an implied do as you are doing. Replacing it with j yields a program that runs for me:
program main
   implicit none

   integer :: N, j
   integer, allocatable, dimension(:) :: A, I

   ! -- Setup
   N = 10000000
   allocate(A(N),I(N))
   A = (/ (j,j=1,N) /)
   I = (/ (N-j+1,j=1,N) /)

   ! -- Main operation
   A(1:N) = A(I(1:N))

   write(*,*) 'A(1): ', A(1)
   write(*,*) 'A(N): ', A(N)

end program main

As to why you're seeing a segmentation fault, I guess you're running out of memory when the array sizes get huge. If you're still having trouble, though, I suggest the following.
Instead of using A(1:N) = A(I(1:N)), you really should be using a loop, such as
! -- Main operation
do j=1,N
   Anew(j) = A(I(j))
enddo
A = Anew

This is more readable and easier to debug moving forward.

