Quantcast
Channel: Intel® Fortran Compiler
Viewing all articles
Browse latest Browse all 3270

Tree structure using derived type - Slow allocation and recovery

$
0
0

Hi,

I am trying to read and store data in a tree structure using derived types to save memory. My code looks like something like shown below but here I just store a constant value and recover it for simplicity. The array dimensions in my actual problem are so large that I had to use jagged arrays using derived types to mange storage. The issue is that the code becomes very slow. I understand the slowness in the storing part due to multiple allocation since for derived types I had to allocate for each layer. However, the recovery part is also very slow. I was wondering if there is another way around this type of problem to increase the speed. I cannot define a big static array from the beginning since the size will be so large that I get memory errors. Thanks for helps and suggestions in advance. Here is my sample code:

      program arash

 
      integer i,j,k,l,m,n
      real a

          type :: Row5
  real, allocatable :: Row5(:)
          end type Row5
             
             
          type :: Row4
  type(Row5), allocatable  :: Row4(:)
          end type Row4
         
          type :: Row3
  type(Row4), allocatable  :: Row3(:)
          end type Row3
         
          type :: Row2
  type(Row3), allocatable  :: Row2(:)
          end type Row2
         
          type :: Row1
  type(Row2), allocatable  :: Row1(:)
         
          end type Row1
         
          type(Row1), allocatable, dimension(:) :: MainMatrix
 

             
          allocate (MainMatrix(100))
         
C---------------Storing data-----------------------------------  
          do i=1,100
                          if (.not. allocated(MainMatrix(i)%Row1)) allocate (MainMatrix(i)%Row1(8))
           do j=1,8
                           if (.not. allocated(MainMatrix(i)%Row1(j)%Row2)) allocate (MainMatrix(i)%Row1(j)%Row2(54))
            do k=1,54
                            if (.not. allocated(MainMatrix(i)%Row1(j)%Row2(k)%Row3))
     1      allocate (MainMatrix(i)%Row1(j)%Row2(k)%Row3(5))
             do l=1,5
                             if (.not. allocated(MainMatrix(i)%Row1(j)%Row2(k)%Row3(l)%Row4))
     1      allocate (MainMatrix(i)%Row1(j)%Row2(k)%Row3(l)%Row4(10))
              do m=1,10

            if (.not. allocated(MainMatrix(i)%Row1(j)%Row2(k)%Row3(l)%Row4(m)%Row5))
     1      allocate (MainMatrix(i)%Row1(j)%Row2(k)%Row3(l)%Row4(m)%Row5(21))
            do n=1,21
            MainMatrix(i)%Row1(j)%Row2(k)%Row3(l)%Row4(m)%Row5(n)=3.66
            enddo
              enddo
             enddo
            enddo
           enddo
          enddo
            
         
C---------------Recovering data-----------------------------------     
         do i=1,100
           do j=1,8
            do k=1,54
             do l=1,5
              do m=1,10
            do n=1,21
            a=MainMatrix(i)%Row1(j)%Row2(k)%Row3(l)%Row4(m)%Row5(n)
              enddo
              enddo
             enddo
            enddo
           enddo
         enddo
                   
                   
      deallocate (MainMatrix)
     
      end program arash

 


Viewing all articles
Browse latest Browse all 3270

Trending Articles