Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Out of virtual memory!

rahzan
New Contributor I
1,142 Views
CVF 6B
win2k Pro SP3
Intel P3

The following code (as a console app) seems to work fine.
It is a method for creating equivalence on an allocatable array which is passed to a module routine.

I am using the same concept in a (in process) COM DLL where the 2D (target) array size is about 7000x10.

Somewhere in the middle of the run (apparently depending on the virual memory size) I get the windows error "Low on virtual memory". After this windows terminates the whole application.

I used to have the pointer and the target arrays as regular arrays and simple copies of each other.
I thought that the pointer idea would (if anything) cut down on memory usage a little.

I seem to skip the error if the declaration and pointing are done but no other reference is made to either the pointer or the target.

Any clues as to
1.why I'm getting the error.
2. How to fix it or if there is a better way
3. or if this is NOT a good idea and I should go back to TWO separate copies of data.

Will be appreciated.

Tim
----------------------------------------------------------

module m
real, allocatable, target:: z(:,:)
contains

subroutine in(x,I,J)
integer i,j
real,intent(in):: x(i,j)
real, pointer:: zz1(:),zz2(:)

allocate(z(i,j))
z=x
allocate(zz1(i),zz2(i))

zz1=>z(:,1)
zz2=>z(:,2)

print *, 'zz1,zz2 =',zz1,zz2
z1=3; z2=4
print *, 'zz1=',zz1,'zz2=',zz2
end subroutine in
end module m
!--------------------------------------------
use m
real x(2,2)
x(:,1)=1.
x(:,2)=2.
call in(x,2,2)
pause
end
!------------------------------------------
0 Kudos
5 Replies
Steven_L_Intel1
Employee
1,142 Views
Why do you allocate zz1 and zz2? I ask because the very next thing you do is point them at sections of z, thus leaking the memory that was allocated.

Steve
0 Kudos
rahzan
New Contributor I
1,142 Views
Hot Dawg!
I thought I read somewhere that pointer must ALWAYS be allocated.

So you are saying that I do not need to allocate the pointers to point them to the target?

I will try it and post the result.

Tim
0 Kudos
Steven_L_Intel1
Employee
1,142 Views
A pointer is just that, a pointer. It can point to storage that you allocated separately (which is what you want to do), or you can allocate new storage it should point to (the ALLOCATE statement). Pointer assignment is like a forwarding address, and wipes out any previous information in the pointer.

Steve
0 Kudos
rahzan
New Contributor I
1,142 Views
Thanks,
Would you say that the pointer (ZZ) should be declared with (:) or (explicit size)?

Tim
0 Kudos
Steven_L_Intel1
Employee
1,142 Views
(I assume you mean ZZ1 and ZZ2 - you don't have a ZZ.) You don't have a choice here - (:) is correct. The bounds get filled in when you do the pointer assignment.

Steve
0 Kudos
Reply