- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The first time I submitted this post, it didn't appear in the forum, so I'm posting it again. Each time through a do loop I am allocating, calculating, and deallocating a set of arrays. The second time through the loop all is well until deallocating where an exception is thrown. I am checking the ALLOCATED property before deallocating, and it looks ok. But something is not right and the exception is 100% repeatable. All the arrays are local to the subroutine, and are declared with the ALLOCATABLE property. Is there anything special one should do when using a set of arrays in such a fashion? The arrays are small. Just a few hundred elements each. Some are REAL, some are COMPLEX. Here's how I'm doing it for each array. Complex(8), ALLOCATABLE :: EIVEC_COMPLEX(:,:) do i=1,whatever ALLOCATE (EIVEC_COMPLEX(N4,N4)) if( allocated(EIVEC_COMPLEX) ) DEALLOCATE (EIVEC_COMPLEX) end do Thanks, Brian in Austin, Texas
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Brian,
the following code compiles and runs fine for me - is this what you meant? If so are you definently attempting to deallocate the same array as you are checking on each line? Could you post a complete code which exibits the problem?
Cheers,
Michael
[fortan]
PROGRAM CheckAlloc
IMPLICIT NONE
INTEGER :: i
DOUBLE PRECISION, ALLOCATABLE :: array1(:,:)
COMPLEX(8), ALLOCATABLE :: array2(:,:)
DO i = 1, 10
ALLOCATE(array1(10,100))
ALLOCATE(array2(10,100))
! Do some calcs with the arrays
array1 = 1
array2 = 2
array2 = array1 * array2
! Deallocate
IF (ALLOCATED(array1)) DEALLOCATE(array1)
IF (ALLOCATED(array2)) DEALLOCATE(array2)
END DO
END PROGRAM CheckAlloc
[/fortan]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't know whether it is still the case but I found that I sometimes needed to deallocate the arrays in reverse order (allocate array1 to N, deallocate arrayN to1) although my arrays were quite large (~ MBs) In the end I just got into the habit of doing it that way.
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I just put the dealloc's in reverse order of the alloc's, and it didn't seem to make any difference. It makes it through the loop fine the first time, and fine the second time untill reaching the dealloc's.
I just put in a GOTO to go straight from the alloc's to the dealloc's and that doesn't crash. So I'm on to something. Either I or IMSL must be clobbering something. Hopefully moving the GOTO will enable me to find where that is.
Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Put stat=istat in the deallocate call and then you can check for istat.ne.0 to trap the error and get an error number
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I found it. I was merely overstepping array bounds in an array assignment statement. I sure thought I had run-time error checking set to ALL, but it was CUSTOM with everything off. This isn't the first time that's happened. I wonder if VS2012 has a problem retaining project settings. Anyhow, on with the show.
Brian
![](/skins/images/895D6060305DF45A57FACF854B5A8CD1/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page