- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
Hi
The snippet below gives two different answers in release and debug mode. It seems like the pointer OBJ%P gets hooked to the array M instead of staying with G. (I am expecting OBJ%P = 1. But in debug mode I get it = value assigned to M.)
I am suspecting that I am missing crucial point or two here.
This goes away if (a) the dimensions are defined as parameters in module PRAN, or (b) dummy array M is made assumed shape in subroutine Up. Is making a section of G a target in subroutine Ved somehow causing this?
In my original problem, there is no array G. The section of M(1,1:NP) itself is passed to subroutine Ved. I made two separate arrays to bisect the problem.
Sincerely
Abhi
---
Module PRAN
Implicit None
Integer :: NC, NPMAX
Integer :: NS, NP
!Integer, Parameter :: NC = 3, NPMAX = 10
!Integer, Parameter :: NS = 2, NP = 5
End Module PRAN
Module OM
Use PRAN, Only: NC, NPMAX, NS
Implicit None
Type new
Integer, Pointer :: P(:)
End Type new
Type(new) :: OBJ
Contains
Subroutine Ved(n, G)
Implicit None
Integer, Intent(IN) :: n, G(n)
Target :: G
Nullify(OBJ%P)
OBJ%P => G(1:n)
End Subroutine Ved
Subroutine Up(n, M)
Implicit None
Integer, Intent(IN) :: n
Integer, Intent(INOUT) :: M(NC-NS+1,NPMAX) ! M(:,:)
Print *, OBJ%P(1)
End Subroutine Up
End Module OM
Program Test
Use PRAN
Use OM
Implicit None
Integer, Allocatable :: G(:,:), M(:,:)
Integer :: ial
NC = 3; NPMAX = 10
NS = 2; NP = 5
Allocate(G(NC,NPMAX), M(NC,NPMAX), stat=ial)
if (ial /= 0) then
Print *, "Failed to allocate."
Stop
endif
G = 1
M = 2
Call Ved(NP, G(1,1:NP))
Call Up(NP, M(NS:NC,1:NPMAX))
End Program Test
The snippet below gives two different answers in release and debug mode. It seems like the pointer OBJ%P gets hooked to the array M instead of staying with G. (I am expecting OBJ%P = 1. But in debug mode I get it = value assigned to M.)
I am suspecting that I am missing crucial point or two here.
This goes away if (a) the dimensions are defined as parameters in module PRAN, or (b) dummy array M is made assumed shape in subroutine Up. Is making a section of G a target in subroutine Ved somehow causing this?
In my original problem, there is no array G. The section of M(1,1:NP) itself is passed to subroutine Ved. I made two separate arrays to bisect the problem.
Sincerely
Abhi
---
Module PRAN
Implicit None
Integer :: NC, NPMAX
Integer :: NS, NP
!Integer, Parameter :: NC = 3, NPMAX = 10
!Integer, Parameter :: NS = 2, NP = 5
End Module PRAN
Module OM
Use PRAN, Only: NC, NPMAX, NS
Implicit None
Type new
Integer, Pointer :: P(:)
End Type new
Type(new) :: OBJ
Contains
Subroutine Ved(n, G)
Implicit None
Integer, Intent(IN) :: n, G(n)
Target :: G
Nullify(OBJ%P)
OBJ%P => G(1:n)
End Subroutine Ved
Subroutine Up(n, M)
Implicit None
Integer, Intent(IN) :: n
Integer, Intent(INOUT) :: M(NC-NS+1,NPMAX) ! M(:,:)
Print *, OBJ%P(1)
End Subroutine Up
End Module OM
Program Test
Use PRAN
Use OM
Implicit None
Integer, Allocatable :: G(:,:), M(:,:)
Integer :: ial
NC = 3; NPMAX = 10
NS = 2; NP = 5
Allocate(G(NC,NPMAX), M(NC,NPMAX), stat=ial)
if (ial /= 0) then
Print *, "Failed to allocate."
Stop
endif
G = 1
M = 2
Call Ved(NP, G(1,1:NP))
Call Up(NP, M(NS:NC,1:NPMAX))
End Program Test
1 Lösung
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
I'll give you a big hint. Add the option /check:arg_temp_created to your compile.
Link kopiert
2 Antworten
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
I'll give you a big hint. Add the option /check:arg_temp_created to your compile.
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
Got it! I was thinking of using this switch when I observed that using the assumed shape array makes a difference.
In addition to copy in/out, I believe that I also stepped on: If the dummy argument has the TARGET attribute and the actual argument does not, pointers might become associated with the dummy argument during execution of the procedure. Such pointers are not associated with the actual argument-only with the dummy argument.
Thus, without Target attribute for G in the main program, OBJ%P can be anything. And hence, actually, shouldn't be used, although in the present case, if I use Associated(OBJ%P) in the main program after calling subroutine Ved, I will get True.
Few! I need to wake up...
Many thanks
Abhi
In addition to copy in/out, I believe that I also stepped on: If the dummy argument has the TARGET attribute and the actual argument does not, pointers might become associated with the dummy argument during execution of the procedure. Such pointers are not associated with the actual argument-only with the dummy argument.
Thus, without Target attribute for G in the main program, OBJ%P can be anything. And hence, actually, shouldn't be used, although in the present case, if I use Associated(OBJ%P) in the main program after calling subroutine Ved, I will get True.
Few! I need to wake up...
Many thanks
Abhi
Antworten
Themen-Optionen
- RSS-Feed abonnieren
- Thema als neu kennzeichnen
- Thema als gelesen kennzeichnen
- Diesen Thema für aktuellen Benutzer floaten
- Lesezeichen
- Abonnieren
- Drucker-Anzeigeseite