|
|
Up |
|
|
  |
Author: jeljel Date: Jun 9, 2008 14:06
Given the following code:
module simple
implicit none
save
real(8) :: x = 0.0d0
contains
subroutine accum(dx)
implicit none
real(8), intent(in) :: dx
x = x + dx
return
end subroutine accum
end module simple
I seem to be having difficulty with Intel Fortran 10 not "saving" the
modified values of x after every call to the subroutine accum.
Because x is a shared module variable I thought the save statement
would apply to x even if x is modified in a module procedure.
|
| Show full article (1.24Kb) |
|
| | 41 Comments |
|
  |
Author: nospamnospam Date: Jun 9, 2008 14:23
jel jhuapl.edu> wrote:
> The actual code where I'm having this problem is more complex than the
> example above but I believe I've captured the basic issue. In my
> actual code x seems to change as expected most of the time but then at
> regular intervals turns to garbage.
...
> I'm guessing that there may be some other problem in the code that
> might be causing the flaky behavior (I haven't tried reproducing the
> problem in simpler code) but I guess my real question is whether (per
> the Fortran standard) I should at least expect x to be SAVEd and for
> the above code to work.
Yes, you should expect that per the standard. But I'd say that your
guess that there may be some other problem with the code is all but
certain to be correct. The odds that adding an explicit SAVE statement
"fixed" it seem low. I'd say more likely is that this had nothing to do
with it, but that you noticed an apparent coincidence (particularly
since you say that the behavior is only occasional anyway).
|
| Show full article (1.43Kb) |
|
| | no comments |
|
  |
Author: Craig PowersCraig Powers Date: Jun 9, 2008 15:01
jel wrote:
> Given the following code:
>
> module simple
>
> implicit none
> save
>
> real(8) :: x = 0.0d0
>
> contains
>
> subroutine accum(dx)
> implicit none
>
> real(8), intent(in) :: dx
>
> x = x + dx
>
> return ...
|
| Show full article (1.68Kb) |
| 3 Comments |
|
  |
Author: nospamnospam Date: Jun 9, 2008 15:43
Craig Powers wrote:
> The way you describe the problem, I rather suspect that the real issue
> is hidden in the complexity that you cut out. A possibility might be if
> the variable in the subroutine is actually not the module variable.
> That would at least be consistent with a procedure-level (or
> program-global) SAVE being necessary to get the behavior that you want.
Oh. I missed the fact that the added SAVE statement was a
procedure-level one instead of a module-level one. That makes a big
difference. If you add a procedure-level SAVE, that would effectively
declare a *DIFFERENT* variable of that name in that procedure. It would
have nothing to do with the module variable of the same name.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
|
| |
| no comments |
|
  |
Author: Gib BogleGib Bogle Date: Jun 9, 2008 19:36
Richard Maine wrote:
> Craig Powers wrote:
>
>> The way you describe the problem, I rather suspect that the real issue
>> is hidden in the complexity that you cut out. A possibility might be if
>> the variable in the subroutine is actually not the module variable.
>> That would at least be consistent with a procedure-level (or
>> program-global) SAVE being necessary to get the behavior that you want.
>
> Oh. I missed the fact that the added SAVE statement was a
> procedure-level one instead of a module-level one. That makes a big
> difference. If you add a procedure-level SAVE, that would effectively
> declare a *DIFFERENT* variable of that name in that procedure. It would
> have nothing to do with the module variable of the same name.
>
What is the effect of the module-level SAVE? I thought all module variables were automatically SAVEd.
|
| |
| 1 Comment |
|
  |
Author: James GilesJames Giles Date: Jun 9, 2008 20:38
Gib Bogle wrote:
...
> What is the effect of the module-level SAVE? I thought all module
> variables were automatically SAVEd.
Nope. That's what I've usually argued *should* be the rule,
but Fortran doesn't say that. Unless you have the save attribute,
all module variables become officially undefined when the
last USE for the module (the one highest in your call sequence)
goes out of scope.
Having to remember whether a module USE is still in scope
or not is something many users are not particularly good at.
Those that *can* keep track of such things would rather
not be required to do so. That's why I think module variables
should always be considered SAVEd. The definition of
Fortran should be changes to require it.
--
J. Giles
|
| Show full article (1.01Kb) |
| no comments |
|
  |
Author: Ron FordRon Ford Date: Jun 9, 2008 20:59
On Tue, 10 Jun 2008 03:38:59 GMT, James Giles wrote:
> The definition of
> Fortran should be [changed] to require it.
This sounded like an awfully strong statement, what with "should" in it,
but that was exactly what Richard claims. Does anyone claim to the
contrary?
--
The only really happy folk are married women and single men.
H. L. Mencken
|
| |
| no comments |
|
  |
Author: glen herrmannsfeldtglen herrmannsfeldt Date: Jun 9, 2008 21:45
Ron Ford wrote:
> On Tue, 10 Jun 2008 03:38:59 GMT, James Giles wrote:
>>The definition of
>>Fortran should be [changed] to require it.
> This sounded like an awfully strong statement, what with "should" in it,
> but that was exactly what Richard claims. Does anyone claim to the
> contrary?
The rules for named COMMON allow named common to be become undefined
if no routines referencing it are active. As I understand it,
that used to happen on some systems with overlays. It seems to
me that MODULE inherited this attribute from COMMON.
For named COMMON, and I believe MODULE, the choices are to put
such statement in the main program or use a SAVE statement for it.
With the larger available memory in machines today, it would
not seem too much to change the standard such that both were
always SAVEd.
-- glen
|
| |
| no comments |
|
  |
Author: nospamnospam Date: Jun 9, 2008 21:42
Gib Bogle auckland.no.spam.ac.nz> wrote:
> Richard Maine wrote:
>> Oh. I missed the fact that the added SAVE statement was a
>> procedure-level one instead of a module-level one. That makes a big
>> difference. If you add a procedure-level SAVE, that would effectively
>> declare a *DIFFERENT* variable of that name in that procedure. It would
>> have nothing to do with the module variable of the same name.
>
> What is the effect of the module-level SAVE?
To declare all module-level variables to be saved.
> I thought all module variables were automatically SAVEd.
No. That's just plain wrong. It is possible, even likely, that you are
confusing typical implementations with the requirements of the standard.
The typical implementation of module-level variables is for them to be
statically allocated, in such a way that they behave as though they were
saved, even if they don't have the save attribute. However
1. This is not what the standard requires. Such compilers are standard
conforming, but code that depends on the behavior is not.
|
| Show full article (2.74Kb) |
| no comments |
|
  |
|
|
  |
Author: nospamnospam Date: Jun 9, 2008 21:54
glen herrmannsfeldt ugcs.caltech.edu> wrote:
> The rules for named COMMON allow named common to be become undefined
> if no routines referencing it are active. As I understand it,
> that used to happen on some systems with overlays. It seems to
> me that MODULE inherited this attribute from COMMON.
>
> For named COMMON, and I believe MODULE, the choices are to put
> such statement in the main program or use a SAVE statement for it.
> With the larger available memory in machines today, it would
> not seem too much to change the standard such that both were
> always SAVEd.
While there is certainly simillarity between the situation for common
and modules, the above seems to carry that simillarity farther than it
goes.
There is no way to specify a SAVE attribute for a module. In a module,
it is the individual variables that are saved (or not); the module as a
whole cannot have a SAVE attribute. In a common, it is the common block
as a whole that is saved (or not). The individual variables in a common
block cannot be given the SAVE attribute.
|
| Show full article (2.03Kb) |
| no comments |
|
|
|
|