Reference to a non-target variable

Reference to a non-target variable

Hi,

A really simple question: is there any way (trick?) to point/save a reference to a non-target variable?

Why do I want to do that?
I'm developping a module for a huge f77 code that I cannot change, and it would be very neat to be able to use pointers to reference the old variables (mainly multidimensional arrays here).
Many thanks in advance,

Nick

Nick
publicaciones de 6 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.
Imagen de Steve Lionel (Intel)

Do I understand correctly that you want routines in your module to save pointers to arguments passed in without requiring that the caller give the passed variables the TARGET attribute? If not, please explain in more detail what you'd like to do - show a short example.

Steve

Hi Steve,

You understood well. My apologies for the bad explanation.
Cheers,

Nick

Nick
Imagen de Steve Lionel (Intel)
Best Reply

The problem is bigger than TARGET - you need to make sure that the variable passed in remains "in scope" at all times while you may be referencing it, and that the compiled code of the caller makes no assumptions about asynchronous reads or writes of the variable. You can't impose this arbitrarily - the caller needs to cooperate.

The mechanics of saving the pointer are pretty easy - you can use C_F_POINTER(C_LOC(arg), pointername) to create a pointer to anything. But it's then up to you to make sure the pointer remains valid. The caller would, at the least, need to give the variable the VOLATILE attribute (in the next Fortran standard, the ASYNCHRONOUS attribute would be applicable to such variables without the heavier weight of VOLATILE), but the caller would still need to make sure that the variable stayed "in scope" until your module was done with it. MPI has similar issues.

Steve

Many thanks Steve, it just might be what I need.
I'm gonna take a wild guess and assume that this issue is especially sensitive in the case of non-blocking MPI calls.
Therefore, I suppose that everything should be ok as long as the caller does not touch the variable before the callee has finished its operations –and this even without the VOLATILE attribute. Does it make sense?

Nick
Imagen de Steve Lionel (Intel)

Yes, it's much the same as non-blocking MPI calls. You do have to worry about the compiler moving references to the variable, which it can do if the variable is not declared VOLATILE.

Steve

Inicie sesión para dejar un comentario.