Software Archive
Read-only legacy content

Allocation

Intel_C_Intel
Employee
568 Views
Usually allocated array will be automatically deallocated by leaving a subroutine. In some cases we are using recursive functions. If the result has the attribute 'allocatable', the compiler complains:

"Error: The array-spec for a function name with no POINTER attribute must be an explicit shape array (R505.9)"

Compilation succeeds using the attribute 'pointer' for the result (array). One cannot deallocate the array, because it is needed after completion of the function. But now we are facing the problem, that the used memory grows with every calling of the function. How can we free the memory after a function call, so that the stack does not overflow?
0 Kudos
3 Replies
Steven_L_Intel1
Employee
568 Views
The version of Visual Fortran you are using doesn't support ALLOCATABLE functions - that is a Fortran 2000 (draft) feature that was added to version 6.6A.

If you do pointer assignment of the result to a local pointer, you should be able to deallocate it when done.

Steve
0 Kudos
Intel_C_Intel
Employee
568 Views
Steve,
I have same problem with fbucher, on calling of function. I have tried using allocatable (in CVF 6.6A), but the used memory is bigger then using conventional dimension.

My function as below:

  function a_multiply(C, iA, jA, B) result(r_v) 
    ! ... 
    ! ...  argument list 
    ! ... 
    real(kind=kv), intent(in), dimension(:) :: C, B 
    integer, intent(in), dimension(:) :: iA, jA 
    ! ... 
    ! ...  result 
    ! ...  
!    real(kind=kv), dimension(1:size(B)) :: r_v 
    real(kind=kv), allocatable, dimension(:) :: r_v 
    ! ...   
    ! ...  local variables 
    ! ... 
    integer :: i, j 
    !................... 
    allocate(r_v(1:size(B))); r_v = n0 
    ! ... 
    do i = 1, size(B) 
       r_v(i)=C(iA(i))*B(i) 
       do j = iA(i)+1, iA(i+1)-1 
          r_v(i)=r_v(i)+A(j)*B(jA(j)) 
       enddo 
    enddo 
    ! ... 
  end function a_multiply 


Anyone can help?

Thank
toppo
0 Kudos
Steven_L_Intel1
Employee
568 Views
toppo,

I don't get any errors with your code. Since this is just a fragment, I suspect the problem is elsewhere. Please send a small but complete example with the exact error message, or even better, a ZIP archive of your project, to vf-support@compaq.com and we'll take a look.

Steve
0 Kudos
Reply