program test
implicit none
real(dp),allocatable :: a(:), b(:)
allocate (a(10))
a = 1.d0
(*) b = a
end program
In the above code, I set two allocatables - a and b - and only allocated a in the code. I expected the code to fail to be compiled, but it is compiled well and it seems to work well while the code below, which does a similar job,shows SEGFAULT.
program test_fail
implicit none
real(dp),allocatable :: a(:), b(:)
integer :: i
allocate ( a(10) )
a = 1.d0
do i = 1, 10
b(i) = a(i)
enddo
end program
Is it fine to understand that the former code allocates b automatically?
subroutine test_sub(a)
implicit none
real(dp),intent(inout) :: a(:,:)
...
end program
And also in above subroutine with shaped-array input, is it fine to understand that the code automatically detects the size of input array a, and allocates its own array in the subroutine and deallocates it returning to its upper frame?
And for the last, which is faster when I copy an array to another array?
program speed1
implicit none
real(dp), allocatable :: a(:,:,:), b(:,:,:)
allocate( a(10000,10000,10000) )
a = 1.d0
b = a
end program
program speed2
implicit none
real(dp), allocatable :: a(:,:,:), b(:,:,:)
integer :: i, j, k
allocate( a(10000,10000,10000), b(10000,10000,10000) )
a = 1.d0
do i = 1,10000
do j = 1,10000
do k = 1,10000
b(i,j,k) = a(i,j,k)
enddo
enddo
enddo
end program