Equivalence question

Equivalence question

Consider the situation:

use Y
Call routineX(tweedles,nRow,nCol)
module Y
real,allocatable:: tweedles(:,:)
real,allocatable:: tweedleDee(:),tweedleDum(:)

real, intent(in):: tweedles_in(nRow,nCol)

In other words I would like to be able to refer to the data arrays either by their explicit names:
or by their index e.g. in loop ops. using tweedles.

Question 1: is the memory used for "tweedles_in" actually allocated in the module but in a sense "wasted" because we only need it for input? does the intent(in) help in this regard?

Question 2:This would normally be the perfect place for making the 2d array EQUIVALENT with the 1d arrays. However this is not possible when they are allocatable.

Is there another way to do this and Avoid the double usage of memory for the same data which only have different names?


3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

What you are trying to do is not allowed in Fortran. You cannot refer to the same chunk of memory by two different names if there is any redefinition or change in definition status of the memory.

In your example, there is only one "copy" of the memory in array tweedles. In routineX, this memory is referenced as both tweedles (through host association) and as tweedles_in (argument association). tweedles gets is definition status changed by the allocate (and later assignment). Illegal.

(By the way, what do you think the assignment

You're right that you can't EQUIVALENCE to ALLOCATABLE (or POINTER) arrays. You could fudge this with the "Compaq POINTER extension", declaring two different arrays that are the pointee of the same pointer variable, and assigning LOC(tweedles) to the pointer variable. Non-standard.


Retired 12/31/2016

I'm sorry I've asked two ostensibly different questions in the same thread.

The statemet
makes a copy of one into a completely independent array. I do not know of any bad consequences of this. Otherwise tweedles (in the module is undefined). I already use this without problems.

ON the first Question: I wanted to know if intent(in) saves memory usage since the tweedles_in is only an input vehicle.

Are you saying that it is possible to simply use tweedles_in in the rest of the module (not just routineX) without copying it? if so How?
Or are you (Also) saying that what I've stated has more diabolical consequences?

As for the SECOND question:
I gathered as much about using pointers. Can anyone provide a sample?

Leave a Comment

Please sign in to add a comment. Not a member? Join today