what's the advantages of fortran pointer over allocatable

what's the advantages of fortran pointer over allocatable

Recently, I am studying the efficiency difference in using pointer and allocatable variables. 

I have tested the character type, but I could not prove that the allocatable is more efficient than the pointer as per http://software.intel.com/en-us/forums/topic/276711

What I could get is opposite. Has anybody experienced the same?

8 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I very much doubt you'd find POINTER has an advantage over ALLOCATABLE. ALLOCATABLE has the advantage that the compiler knows the data is contiguous, allowing it to skip making temporary copies of the data.  ALLOCATABLE also makes it very difficult if not impossible to leak memory. Use ALLOCATABLE unless you must use pointer assignment.

Retired 12/31/2016

It would be nice if more examples can be proving...

I doubt myself also. But I tested the example on two machines, one desktop and one laptop and I got the same results.

Please help with further testing.

Thanks, Kong


My results in win32 release mode are:

Allocatable string Running Time was:  0.1133607     [Min]

Pointer string Running Time was:  5.6420636E-02 [Min]

I re-implemented the reallocate function as a subroutine and got: Allocatable string Running Time was:  5.7720371E-02 [Min].

subroutine reallocate(P,N)
! reallocate=repeat(' ',N) ! should avoid repeat function which consumes too much RAM
allocate(character(n)::R); R(:n)=' ';
end if
call move_alloc(R, P)
END subroutine

Without measuring to confirm, I would have though the IO in the code would have dominated over any memory management strategy.

Thanks a lot. So the finding is that the function is much less effecient than the subroutine. Unfortunately, for years, I have converted subroutines into functions to simulate c style...

I agree with IanH, but could we have some substantially better alternatives?

Leave a Comment

Please sign in to add a comment. Not a member? Join today