- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I define my data in a module.
Then I use the "use" instruction in the code where the data are needed.
Now, in my module, if I define one data as COMMON/PA/PAG(200), everything works fine (and the calculation result is correct).
If I define it as: real*8, allocatable :: PAG(:), then allocate it with size 200 at the beginning of the program (I change nothing else in the program), I get a different result after my program calculations (and this result is false).
The calculation procedure is very complicated, so it will be long and hard finding where the difference is.
Is there a theoretical difference betwen a COMMON array and an allocatable array, once they are created ?
Can the allocatable be sor of overwritten somewhere ?
Valrie.
I define my data in a module.
Then I use the "use" instruction in the code where the data are needed.
Now, in my module, if I define one data as COMMON/PA/PAG(200), everything works fine (and the calculation result is correct).
If I define it as: real*8, allocatable :: PAG(:), then allocate it with size 200 at the beginning of the program (I change nothing else in the program), I get a different result after my program calculations (and this result is false).
The calculation procedure is very complicated, so it will be long and hard finding where the difference is.
Is there a theoretical difference betwen a COMMON array and an allocatable array, once they are created ?
Can the allocatable be sor of overwritten somewhere ?
Valrie.
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When you use the COMMON block in your module do you also declare PAG(200) as REAL*8? If not, and if you also aren't using IMPLICIT NONE, then I believe that the PAG(200) array is defaulting to REAL*4, which may account for some of the differences in results.
I think that by default CVF gives variables declared in COMMON blocks static storage. Every subprogram that USEs your module (I'm assuming that your program has functions and subroutines, not just one main routine) with the COMMON declaration is accessing the same storage area in memory.
On the other hand, I believe that your main routine would have to pass your ALLOCATEd PAG array as a parameter to each subprogram to get the same effect. USEing a module that defines the ALLOCATABLE version of PAG might be doing an implicit ALLOCATE of the array in each subprogram. If that's the case, then your program would be allocating a new uninitialized area in memory each time, and your subprograms wouldn't be accessing the same data.
Mike
I think that by default CVF gives variables declared in COMMON blocks static storage. Every subprogram that USEs your module (I'm assuming that your program has functions and subroutines, not just one main routine) with the COMMON declaration is accessing the same storage area in memory.
On the other hand, I believe that your main routine would have to pass your ALLOCATEd PAG array as a parameter to each subprogram to get the same effect. USEing a module that defines the ALLOCATABLE version of PAG might be doing an implicit ALLOCATE of the array in each subprogram. If that's the case, then your program would be allocating a new uninitialized area in memory each time, and your subprograms wouldn't be accessing the same data.
Mike

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page