- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Treating a module like an object, I allow a "constructor" called setInput to receive the necessary data (such as an array), so that other methods in the module can operate on it. However, I do not wish to duplicate the memory usage by having an array input and acopy which is the property of the module. So I tried to use F90 pointers.
TWO questions:
1. Do these f90 pointer arrays need to be deallocated?
2. Similar to the input, I thought I canavoid duplicating an output array. But pointer and intent cannot mix. So I allocated an module pointer array for output. Does this need to be deallocated somehow, since it was explicitly allocated? if so how?
This routine works in console mode, but I can't be sure if it leaves memory leaks behind in a windows or com-dll project type.
module test
real,pointer:: inputX(:,:)
real,pointer:: Row1(:),Row2(:),Output(:)
integer:: nout
contains
subroutine SetInput(xin,n,m)
implicit none
integer,intent(in)::n,m
real, intent(in):: xin(n,m)
inputX=>xin
nout=n
end subroutine SetInput
subroutine run
implicit none
Row1=>inputX(:,1)
Row2=>inputX(:,2)
allocate(output(nout))
Output=3*Row1
write(*,*)inputX
write(*,*)"Row1";write(*,*)Row1
write(*,*)'Row2';write(*,*)Row2
end subroutine run
subroutine GetOutput(xout,n)
implicit none
integer,intent(in)::n
real, intent(out):: xout(n)
xout=Output
end subroutine GetOutput
end module
program main
use test
implicit none
real,allocatable:: xin(:,:),xout(:)
allocate(xin(5,2),xout(5))
xin(:,1)=1
xin(:,2)=2
write(*,*)xin
call setinput(xin,5,2)
call run
call getoutput(xout,5)
write(*,*)xout
pause
end
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
implicit none
integer,intent(in)::n,m
real, intent(in):: xin(n,m)
inputX=>xin
real, allocatable, target:: Output(:)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Jugoslav,
1. I tried downloading the link for the 6.6C upgrade but it leads nowhere.
I manually went to the cvf ftp site and found something called cvf-66-66cX.exe
But I'm not sure if it the right file. can you or steve confirm?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the quick reply,
Item 3 is not suitable since I intend for the computation and the getoutput to be in different routines.
But while I have your attention, . Instead of the MAIN, above, the caller is a routine in a com-module, and it gets xin from the outside. Is it ok/safe/reliable to add the pointer attribute to the interface of the com-module eventhough it was not something the com-wizard generated? I suspect the answer is no.
Alternatively, I assume it is also NOT ok to simply pass the loc(Xin) from the caller to a routine which expects a cvf pointer?
lastly, assuming the answer is NO to both of the options above, is it possible to use loc(xin) in the module to "define" an array which is "equivalent" to xin?
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Having in mind the restrictions you just mentioned, I retreat and I state the opposite :-). Youroriginal design (with data copy) looks simplest & cleanest in such setup (apart from IMO unnecessary POINTER attribute -- why not using an ALLOCATABLE instead).
(Your both assumptions are correct and no, it's not possible to convert a non-pointer original xin (wherever it comes from) into a pointer).
Jugoslav
Message Edited by jugoslavdujic on 12-23-2003 07:50 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok,. we've comefull circle to the origianl question which I should have asked:
Does creating an allocatable array and copying a passed array (with intent(in)) double the memory usage?
If yes, then I prefer the Pointer method which I assumeuses only one copy of the data.
Thanks again for your patience.
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
To Tim: depends on what youmean by"double the memory usage". As Steve said, you're guaranteed to get no temporaries which carry extra overhead. But by design, you have an output allocatable/pointer (doesn't really matter) array, whichstores the results, and you have a xin array which comes somewhere from deep space and whose size must be >= size(output). At the end, you copy from output array to xin.
In theory, you could avoid it by using only the storage provided by the shell, but that leads to certain design limitations, i.e. that storage must be known to you from the beginning and the original caller should provide enough space, I mean:
voidDeepSpace{
//written in another language somewhere unknown to you
float* Results;
int nSize; //Assumed that size of results is known
Results = new float[nSize];
TimsCOMServer(someInputs, Results, nSize);}
subroutine TimsCOMServer(someInputs, xout, nSize)
real xout(nSize);
call SetInput(someInputs, xout)
call NumberCrunch()
!call GetOutput() when NumberCrunch is done, you don't need
!GetOutput, as xout will be filed OK
end subroutine TimsCOMServer
module TimsCalculations
real, pointer:: Output(:)
contains
subroutine SetInput(someInputs, xout)
real, target:: xout(:)
Output => xout
!Now you use the storage provided by DeepSpace
...
end subroutine SetInput
subroutine NumberCrunch()
!Fill in the Output array here
end subroutine
end module
This uses only one storage for output data, but it may not be possible for some reasons in your setup (e.g. nSize is not known in advance, or there are multithreading issues, or you can't guarantee that Results willremain allocated during the process).
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Jugoslav,
This is just the way I had intended to do things. I think that I was not aware that the line
real, target:: xout(:)
is all that I need, as opposed to
real, target:: xout(nsize)
which (I understand) creates another copy.
Tim
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page