In my code, I have memory problems due to the machine that I use, so I want to allocate the least memory possible during passing arguments. My example code:
program test
double precision, ALLOCATABLE :: arrayA(:)
allocate (arrayA(n))
call mySub (arrayA)
deallocate (arrayA)
stop
end
subroutine mySub ( arrayB )
double precision, ALLOCATABLE :: arrayB(:)
allocate (arrayB(n))
! operations with arrayB
return
end
In main program, I have to use the heap memory. I also want to use heap memory in my subrotuine. Acc to search I did, it gives running error ( Attempting to allocate already allocated array 'arrayb').
Therefore, my purposes are to use heap memory also in my subroutines, and to allocate the least memory possible during argument passing from program to subroutine like in the code above. Now, I think I do copy assignment and as I know, it is not good. I checked module, interface and contains blocks but it is not so clear which one is good to save some space in memory with allocatabel arrays. I appreciate any help fits into my purpose.