Software Archive
Read-only legacy content
17061 Discussions

Allocate and deallocate problem

Deleted_U_Intel
Employee
223 Views
Hi,

We currently have MS Fortran Powerstation 4.0. We are experiencing an important problem regarding the deallocation of pointers. We would like to know if this problem still persists in Compaq Visual Fortran.

Thanks,
Louis

C####################################################################### 
C 
C     This test has been performed with MS Fortran Power Station 4.0 
C 
C     This program creates a linked list of "item". 
C     It test the speed of allocation and speed of deallocation 
C 
C     We found that the deallocation is made from the last item to 
C     the first is adequate.  
C     
C     But the deallocation becomes very slow when it is made from the first item 
C     to the last. It can be more than 100 times slower!!!  
C 
C     If additionnal independent linked lists are defined, the deallocation speed 
C     decreases exponentially when made from the first item to the last. 
C 
C     Can you tell me if this problem still occurs in the new version 
C     of Compaq Visual Fortran 6.5.  
C 
C     To test this program all you need to do is to create a console application 
C     and change the value of KORDER as follows  
C 
C        KORDER = 1 ! 1 = Deallocate from first to last 
C        KORDER = 2 ! 2 = Deallocate from last to first 
C 
C####################################################################### 
C 
        Program Test 
C 
        TYPE item 
         integer      KVAL         
         integer      KOTHER 
C 
         TYPE (item),POINTER  previous_item 
         TYPE (item),POINTER  next_item 
        END TYPE item 
C 
        INTEGER KORDER,II,KTOT 
C 
        TYPE (item),POINTER  first_item 
        TYPE (item),POINTER  last_item 
C 
C------------------      
        type(item), POINTER  parent_item 
        type(item), POINTER  current_item 
C------------------      
C 
        KORDER = 1 ! 1 = Deallocate from first to last 
C        KORDER = 2 ! 2 = Deallocate from last to first 
C 
C       Initialization 
        KTOT = 0 
        NULLIFY(first_item) 
        NULLIFY(last_item) 
C 
C       Add 50000 Items 
        DO II = 1,50000 
          allocate(current_item)  
          nullify(current_item%next_item) 
C 
          IF (KTOT.LE.0) THEN 
            first_item=>current_item 
            nullify(current_item%previous_item) 
            KTOT = 1 
          ELSE 
            parent_item=>last_item 
            parent_item%next_item=>current_item 
            current_item%previous_item=>parent_item 
            KTOT = KTOT + 1 
          END IF 
          current_item%KVAL = II 
          last_item=>current_item 
        END DO 
C 
        IF (KORDER.EQ.1) THEN 
C       SLOW deallocation 
          current_item=>first_item 
          DO II=1,KTOT  
            parent_item=>current_item%next_item 
            if (associated(current_item)) deallocate(current_item) 
           current_item=>parent_item 
          END DO 
        ELSE 
C         QUICK deallocation 
          current_item=>last_item  
          DO II=1,KTOT  
            parent_item=>current_item%previous_item 
            if (associated(current_item)) deallocate(current_item) 
           current_item=>parent_item 
          END DO 
        END IF 
C 
        END  
C 
C#######################################################################
0 Kudos
1 Reply
Steven_L_Intel1
Employee
223 Views
You also sent this to us at vf-support. My response was as follows:

Compaq Visual Fortran's compiler and language libraries are our own and not
derived from Microsoft's. Visual Fortran 6.5 executes your test program very
quickly, using either value of KORDER.

Steve
0 Kudos
Reply