Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Necessity of the TARGET attribute?

0 views
Skip to first unread message

Patrick

unread,
Aug 23, 2002, 3:42:27 AM8/23/02
to
Why is it necessary to declare variables, to which a pointer can be
associated, with the TARGET attribute?

As I understand it, a pointer indicates a memory address. Every
variable has one, so why is it necessary to give an extra attribute?

Pat

Michel OLAGNON

unread,
Aug 23, 2002, 4:33:28 AM8/23/02
to
In article <f7a75888.02082...@posting.google.com>, pez3...@yahoo.com (Patrick) writes:
>Why is it necessary to declare variables, to which a pointer can be
>associated, with the TARGET attribute?
>
>As I understand it, a pointer indicates a memory address.

That is the C view of pointers. With Fortran, a pointer is a way
to alias all or part of an entity. Many practical implementation
points need to know whether the entity is going to be called
only via its declared name, or may also be accessed through aliases.
For instance, A2 = EOSHIFT (A1, N) will not be implemented thesame way
depending whether A1 and A2 may overlap due to aliasing, or are disctinct.

>Every
>variable has one, so why is it necessary to give an extra attribute?
>
>Pat

Michel

--
Michel OLAGNON email : Michel....@ifremer.fr
http://www.ifremer.fr/metocean/group/michel/michel_olagnon.htm
http://www.fortran-2000.com/


Michael Metcalf

unread,
Aug 23, 2002, 5:22:58 AM8/23/02
to

"Patrick" <pez3...@yahoo.com> wrote in message
news:f7a75888.02082...@posting.google.com...

> Why is it necessary to declare variables, to which a pointer can be
> associated, with the TARGET attribute?
>

The TARGET attribute was introduced solely to aid optimization. It is very
helpful to the compiler to know that a variable that is not a pointer or a
target may not be accessed by a pointer. This contrasts with the situation
in, for instance, C, where any variable is a potential target and often only
less aggressive optimizations can be undertaken.

Regards,

Mike Metcalf


James Giles

unread,
Aug 23, 2002, 12:09:56 PM8/23/02
to

"Patrick" <pez3...@yahoo.com> wrote in message
news:f7a75888.02082...@posting.google.com...

When some optimizations occur, not every variable has an address.
A variable local to a procedure that is not read, written, an argument
to another procedure, or in a COMMON or MODULE may be
completely optimized out.

Many other optimizations can result in variables not being kept in
any address much of the time (it may be that some values are written
to memory only when the registers are needed for other data, for
example). Implementations are possible in which data is kept
wherever convenient for most efficient access rather than any fixed
locations.

The TARGET attribute tells the compiler that such optimizations
are not allowed for the variable. The real purpose of the TARGET
attribute is that variables that *don't* have it can be optimized with
safety (and the compiler doesn't even have to have clever checking
abilities to see if it's safe).

--
J. Giles


Ron Shepard

unread,
Aug 23, 2002, 10:17:33 PM8/23/02
to
In article <o7t99.439$p%3.3...@bgtnsc05-news.ops.worldnet.att.net>,
"James Giles" <james...@worldnet.att.net> wrote:

> Many other optimizations can result in variables not being kept in
> any address much of the time (it may be that some values are written
> to memory only when the registers are needed for other data, for
> example). Implementations are possible in which data is kept
> wherever convenient for most efficient access rather than any fixed
> locations.

I used a cpu once that had pipelined floating point operations and
parallel execution units. There were instructions that would pipe the
output from one floating point unit (say the adder) directly into the
input of the other floating point unit (say the multiplier). The
variable did exist momentarily as signals on a buss, but the value never
lived in a register. This meant that the registers could be used for
other things. BTW, you could program this machine in fortran or in
assembler, nothing else. I think you can see why C, if it had been
available, would not have been efficient on such a machine.

$.02 -Ron Shepard

Dr Chaos

unread,
Aug 24, 2002, 7:30:07 PM8/24/02
to
On 23 Aug 2002 00:42:27 -0700, Patrick <pez3...@yahoo.com> wrote:
> Why is it necessary to declare variables, to which a pointer can be
> associated, with the TARGET attribute?
>
> As I understand it, a pointer indicates a memory address. Every
> variable has one

Does it?

> , so why is it necessary to give an extra attribute?

Because this makes Fortran better than a language where you
can take addresses of almost anything, like, say, C.

In sum, because C and C++ pointers can point to any 'thing' of a certain
type (and often in actual C code, anything) the compiler cannot make
as many assumptions about what entities may be aliased or accessible
through multiple variables.

This results in slower code in a number of circumstances.

Consdider also that the memory architecture may not be as simple as
the standard PC model; imagine a a large parallel supercomputer with a
significant hierarchy of local to distant memories, each decreasing in
speed.

This can render programs with arbitrary C-style pointer dereferencing
difficult to compile efficiently.

In practice, in typical Fortran programs, only a few things need to
be TARGETs of pointers, and the rest can be assumed won't be so.

> Pat


Philippe Blaise - GRENOBLE

unread,
Aug 26, 2002, 5:21:10 AM8/26/02
to
Have a look to your C Compiler - you will probably find something
about optimization and pointers.

For example, on a VPP5000 - (Fujitsu vector machine) :

-K{popt|nopopt}
Specifies whether the optimization for pointer is
performed or not.
The default is -Knopopt.

-Kpopt
Optimization that more than one pointer vari-
ables are not assumed to point the same area,
is performed.

-Knopopt
Optimization that more than one pointer
variables are not assumed to point the same
area, is not performed.

in many cases, you must use -Kpopt to obtain perf. comparable
to fortran.

Philippe.


0 new messages