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

File I/O and memory

weichao_hsu
Beginner
640 Views
I am trying to storedata to a file for saving memory, but the program uses more memory to read and write data. Here is a example, the program creates 400 MB memoryfor reading and writing. After the array is deallocated and the file is closed, there are still 200MB memory in the program.
!-------------------------------------------------
program test
implicit none
complex(8),pointer::A(:)
integer::N,i

open(1,file="test.txt",form='unformatted')

N=13000000
!2 MB
allocate(A(N))
!2 MB
do i=1,N
A(i)=real(i)
end do
!205 MB
write(1)A
!409 MB
rewind(1)
read(1)A
!613MB
deallocate(A)
!409 MB
close(1,status='delete')
!206 MB
end program test
0 Kudos
3 Replies
Steven_L_Intel1
Employee
640 Views
Deallocated memory generally does not cause the virtual memory used by a running program to decrease - that memory is in a pool available for future allocations, but the OS believes it is in use.
0 Kudos
weichao_hsu
Beginner
640 Views

Thank you. sblionel!

My question is why the program creats memory for reading and writing. It makesmy computer need more memory to run. If my computer doen't hasenough physical memory, the disk will be used for swapping and it will run slowly.

0 Kudos
Steven_L_Intel1
Employee
640 Views
I think the run-time library allocates its own buffer for the record.
0 Kudos
Reply