program MaxAllocate ! This file: http://ftp.aset.psu.edu/pub/ger/fortran/hdk/dynmax.f90 ! !=== Example of Allocating a 1D DP Array as large as possible (to about ! the nearest MB DP elements) on the platform running this code. integer :: AllocStatus, DeallocStatus, MB integer(kind=selected_int_kind(18)) :: na ! for > 2GB real(kind(1.D0)), allocatable, dimension(:) :: a MB=1024**2 ! Allocate to nearest Megabyte. !---Kind=DP array assumed to have 8-byte elements. na=0 ! na is a test amount to allocate. do na=na+MB allocate( a(na), stat=AllocStatus) if (AllocStatus /= 0) then na=na-MB ! When no more heap storage is availabe, quit. exit else deallocate(a,stat=DeallocStatus) ! if this Allocate worked, deallocate and iterate. if (DeallocStatus /= 0) then print *, "Could not Deallocate??" stop endif endif end do allocate( a(na)) print *, "Size of DP allocated array is: ",na print *, "Size of the allocated array is: ",(na*8)/MB,"MB" a(na)=0 ! Test the allocated array. deallocate(a) ! When run this on our 64-bit Linux cluster, which allows one to utilize ! up to 32GB, the above program, when compiled using the Intel Fortran ! compiler (v9.1), or the PathScale compiler (v2.3) displays the ! followig results: ! ! Hammer: ! Size of DP allocated array is: 4073717760 ! Size of the allocated array is: 31080 MB ! ! Unisys3: ! Size of DP allocated array is: 16131293184 ! Size of the allocated array is: 123072 MB ! end program