- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The following piece of code thorws a run-time error in my code and I do not understand why, since what I do seems to be standard to me and is done at many other positions in my code wihtout problem. Moreover the code is been used for 5 years now with an older compiler version without any problems.
The error appears only in the release version with maximal speed optimization.
[fortran]
! variables: Reference is a own structure holding a logical member "Master"
Type(Reference), pointer :: pReference
! execute that throws a run-time exception only in release version if maximize speed optimization is enabled:
! namely: "Attempt to use pointer pReference when it is nit associated with a target"
pReference => Null()
allocate(pReference, stat = ierr(1))
if (ierr(1) .NE. 0) then
my_status = 3
if(present(STATUS)) STATUS = my_status
return
end if
if(associated( pReference)) then
! set flag
pReference%Master = .FALSE.
end if
[/fortran]
As I said the error appears only in the release version so it is hard to judge what actually happens. But even inside the if clause where I checked if the pointer is associated another if clause checking the same statement will tell me that this is not the case... which obvioulsy cannot be true otherwise the code would no enter the clause.
Thanks everybody for your help!
Regards,
Felix
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Actually I have to correct myself, the above version is already the corrected version as I just realized since it works fine.
Now the same error appears again some lines below in the same subroutine (thats why i didnt realize that the above statement solves the problem)...
so what follows is the original code that throws an error. It seems the lines are not processed in serial, right?! However those lines are used in the program before in a similar style working fine with older versions of the fortran compiler:
[fortran]
! variables: Edge is a own structure holding a member of type Reference called pReference
Type(Edge), pointer :: pSlaveEdge
! execute that throws a run-time exception only in release version if maximize speed optimization is enabled:
! namely: "Attempt to use pointer pReference when it is nit associated with a target"
pSlaveEdge%pReference => Null()
allocate(pSlaveEdge%pReference, stat = ierr(1))
if (ierr(1) .NE. 0) then
my_status = 3
if(present(STATUS)) STATUS = my_status
return
end if
if(associated( pSlaveEdge%pReference)) then
! set flag --> location of run-time error
pSlaveEdge%pReference%Master = .FALSE.
end if
[/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, but there's nothing we can do with an excerpt of code. I could see the second code getting an error if pSlaveEdge was not allocated. You don't show that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes sorry, its hard to cut out a representative piece of code from the entire routine..
The problem is not the pointer to pSlaveEdge. This will be checked before and i am sure there is no access violation. In the first case I allocate "pReference" and work with it and afterwards assign it to the member of "pSlaveEdge" with
[fortran]
pSlaveEdge%pReference => pReference
[/fortran]
... and everything works fine. In the second version I allocate "pSlaveEdge%pReference" and work with the member directly which seems to fail because for some reason even if I allocate it in the next lines I can not be sure it is associated. The error message I get also does indicate me clearly that the probleme is the pointer pReference of the variable pSlaveEdge and not the pointer to pSlaveEdge itself.
So could it be that due to optimization the lines:
[fortran]
allocate(pSlaveEdge%pReference, stat = ierr(1))
if(associated( pSlaveEdge%pReference)) then
pSlaveEdge%pReference%Master = .FALSE.
end if
[/fortran]
are not executed sequential?
Moreover without optimization there is no error at all.
Regards,
Felix
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, they are executed sequentially. But use of ASSOCIATED here is undefined if the allocation failed and the association status was undefined before the ALLOCATE.
If you can come up with a self-contained example I can build and run, I'll be glad to look at it. There's nothing I can do with an excerpt.

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