- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Here is the code:
......
deallocate(chebft_y)
N2wave=int((xrhomax2-xrhomin)/(2*xwavebjmin))
if (N2wave .lt. 1) then
!c if (.true.) then
!ccccccccccccccccc
!ccccc
write(*,*)'N2wave is less than 1.'
mxy=int(mxyunit1*(xrhomax2-xrhomin)/(2*xwavebjmin))
if (mxy .lt. NPmin) then
mxy = NPmin
endif
write(*,*)'mxy=', mxy
allocate(rkho(0:mxy-1),gllY(mxy),gllX(mxy),gllW(mxy))
......
The array chebft_y is allocated ( I have checked its elements), but when deallocating it, it says 'BSEM_90.exe has triggered a breakpoint' and a No Source Available window comes out. But in the debugging window, no error hints show.
I tried putting this part into a subroutine which is also used in other place. When first call this subroutine, no problems shows. However, when call this subroutine the second time, a similar problem shows. But the strange thing is sometimes the chebft_y can be allocated, sometimes it can't be. When it can be allocated, the last allocate operation for (rkho, gllY...) can not run and also shows ' exe has triggered a breakpoint' and a runtime error window saying 'R6025 - pure virtual function call', still no other error hints in the debugging window.
Where may be the problem? Thanks~ If need further information is needed, please tell me!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
is chebft_y an array declared as ALLOCATABLE...
.OR. is it a POINTER to an array?
Note, a pointer, if not initialized (e.g. => NULL(), or NULLIFY(ptr)) will more likely than not contain junk data, and therefore appear associated, and may even appear allocated. The deallocate-ing of such an object is subject to program crash or corruption.
Can you show more of your program? This can have unrelated lines remove, replace with ...code...
Show how you declare the array, allocate the array and use the array (IOW is it passed into the subroutine as a dummy argument, and if so, show how it is declared in the subroutine).
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks so much for the reply.
chebft_y is declared in another module. The followings are the declaring module, the subroutine with problem, and main program calling the subroutine.
The declaring module
module interpolation_1
...
real,allocatable:: chebft_y(:)
contains
...
if (interpolationID .eq. 4) then
allocate(chebft_y(mxy_subroutine))
...
end module
The module containing the module
module field_inc_sct
...
subroutine interpo_rkho(intid,iNff,interpolationid1,mxyunit1,NPmin,xrhomin1,xrhomax1,xwavebgmin,xwavebjmin,mxy,rkho)
! the iNff only works when intid=1
implicit none
integer,intent(in):: intid,iNff,interpolationid1,mxyunit1,NPmin
real,intent(in):: xrhomin1,xrhomax1,xwavebgmin,xwavebjmin
real,allocatable,intent(out):: rkho(:)
...
real,allocatable:: gllX(:),gllY(:),gllW(:)
...
else if (interpolationid1 .eq. 4) then
if(intid .eq.1) then
if(iNff.gt.1) deallocate(chebft_y)
endif
if(intid.eq.2) then
deallocate(chebft_y)
endif
N2wave=int((xrhomax-xrhomin)/(2*xwavebjmin))
if (N2wave .lt. 1) then
...
else
mxy = mxyunit1
allocate(rkho(0:mxy*N2wave+mxy-1),gllX(mxy),gllY(mxy),gllW(mxy))
CALL GLL(gllX,gllW,mxy-1)
do iN2wave = 1,N2wave
xrhominID = xrhomin + (iN2wave-1)*2*xwavebjmin
xrhomaxID = xrhomin + iN2wave*2*xwavebjmin
do ixy = 1,mxy
gllY(ixy) = 0.50*(xrhomaxID - xrhominID)*gllX(ixy) + &
0.50*(xrhominID + xrhomaxID)
rkho(ixy-1+mxy*(iN2wave-1)) = gllY(ixy)
enddo
enddo
mxy=int(mxyunit1*(xrhomax-N2wave*2*xwavebjmin-xrhomin)/(2*xwavebjmin))
...
CALL GLL(gllX,gllW,mxy-1)
xrhominID = xrhomin + N2wave*2*xwavebjmin
xrhomaxID = xrhomax
do ixy = 1,mxy
gllY(ixy) = 0.50*(xrhomaxID - xrhominID)*gllX(ixy) + &
0.50*(xrhominID + xrhomaxID)
rkho(mxyunit1*N2wave+ixy-1) = gllY(ixy)
enddo
mxy = mxyunit1*N2wave + mxy
deallocate(gllX,gllY,gllW)
endif
endif
end subroutine
end module
Then main program calling the subroutine, here rkho is declared as allocatable, but without allocation.
...
intid=1 ! the iNff only works when intid=1
call interpo_rkho(intid,iNff,interpolationid1,mxyunit1,NPmin,xrhomin,xrhomax1,xwavebgmin,xwavebjmin,mxy,rkho)
! this is the first time calling this subroutine, no problems are showed.Before this calling, chebft_y has not been allocated.
...
deallocate(rkho)
...
intid=2
iNff1=2 ! this iNff1 is an arbitrary number, which will make no sense to this subroutine because intid=2
call interpo_rkho(intid,iNff1,interpolationid1,mxyunit1,NPmin,xrhomin,xrhomax2,xwavebgmin,xwavebjmin,mxy,rkho)
! this is the second time calling this subroutine, the problems mentioned before are showed. The chebft_y is allocated before this calling.
Are all these enough? Tell me if more information is needed. Thanks so much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have seen similar issues and the cause was trampling on the memory used to descibe the allocation status. This can happen if any part of your program uses arrays out of bounds, most likely when you pass wrong size arrays to libraries.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Andrew, thanks so much for the help. But if the array has run out of bounds somewhere before, will the compiler not show errors? Can it continue running?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I also find in the stack frame, it shows that
...
kernel32.dll 759f38f4()
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
ntdll.dll!77b5de3()
ntdll.dll!77b5dae()
What does this mean?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is subroutine interpo_rkho located within a module?
Meaning its interface is shown to the callers? (a requirement for procedure dummies that are allocatable or use assumed shape "(:)" declarations).
I suggest you insert diagnostic code (often called asserts) to assert when you assume the array is allocated, that it is allocated, and when you assume the array is deallocated that it is deallocated. Do not simply coerce it into the state as this will hide an error that you have elsewhere in your program.
The compiler will not tell you about array access out of bounds, but you can compile with runtime checks enabled.
In situations like yours, it is recommended that you make a Debug build with all the runtime checks enabled (including interface checking). If this runs, then you are reasonably assured (not absolutely assured), that most of the common mistakes are caught. Note, this will not tell you why or where the allocation status of this array was made (or not made) correctly.
Also, if this array has different allocations depending on interpolationID, then it may be helpful to place additional asserts that, as an example, when interpolationID==4, and you expect the array to be allocated, that you also assert the size of the allocated array is what you expect. Catching an error like this early on will assist you in finding the point of error in your code.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jim, thanks so much for the answer.
The subroutine interpo_rkho is located in the module field_inc_sct.
As for the diagnostic code, I don't know what this is and also the runtime checks. Could you please show me some links discussing how to do these?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you are using Visual Studio:
Open your Solution
Select Debug build
Open/Use the Solution Explorer and locate the Fortran Project containing the code in question.
Right-Click on the Fortran Project in question
Select Properties
Under: Configuration Properties > Fortran > Run-time
Enable all runtime checks
Then under: Configuration Properties > Fortran > Diagnostics
enable Check Routine Interfaces
If you are using command line, then locate the equivalent options. If you need a list of options. Launch the appropriate command prompt with Intel configuration, then enter
CD \SomeDirectoryYouUse
ifort /? > ifortCommandLineOptons.txt
notepad ifortCommandLineOptions.txt
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jim, thanks so much for the help~
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page