- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I write a program to allocate memory, like ffree 10. Then the ffree will allocate 10G memory.
This is my code
program ffree
character :: buf * 255
integer :: size, info
integer(8) :: num, i
real(8),dimension(:),allocatable :: ff
call getarg(1, buf)
read(buf, *)size
num = size * 1024 * 1024 * 1024_8 / 8
print*, "total number", num
allocate(ff(num), stat = info)
if(info.ne.0) stop ("Don't have enough memory")
ff = 0
forall(i = 1:num)
ff(i) = 0
end forall
print*, "there are ", size, " G memory at least."
print*, "allocate finished"
read*, i
deallocate(ff)
print*, "deallocate finished"
end program ffree
When the type of ff is real, the program is normal. I mean when I use ffree like `ffree 10`, the command free show 10G used.
But I change the type to complex. When I use free like `ffree 10`, the command free show 20 G used. Why?
Figures below(before I run the program, 4 G has been used)
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
complex(kind=8) internally is an ordered pair of real(kind=8) variables, so it occupies 16 bytes rather than 8.
There is also complex*8 which internally is an ordered pair of real*4 variables, therefore 8 bytes in memory.
If you use the standard-conforming complex(kind=8) declaration style, you have to take into account the extra storage, while if you use the nonstandard complex*8 notation you have to take into account the lower precision. There is the C_SIZEOF function from the standard intrinsic ISO_C_BINDING module and the almost equivalent intrinsic extension SIZEOF that can tell you the size of a data item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sometimes printing out the size and value of the first element can be useful.
D WRITE(*,*)' SIZEOF(C(1)=',SIZEOF(C(1)), ' C=',C
Using the "D" you can compile with -d-lines when you are debugging and then -no-d-lines when you get past that point,
(better check the -d-lines and -no-d-lines, as I usually get them misspelled...)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
D lines work only for fixed-form source.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page