Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28632 Discussions

Move_alloc function on derived-type with allocatable components gives segmentation fault

FlyingHermes
New Contributor I
739 Views
Hi,

I am using ifort version 12.1.0 on an linux Ferdora 15 32b computer.
I having an segmentation fault error using allocatable derived-type with allocatable components when I am trying to extend the size of the allocatable derived-type using the move_alloc function.

I think the problem come from the fact that, using the move_alloc function, I am just allocating the overall derived-type structure and not the individual allocatable components.
Could someone please confirms that this is the origine of the error.

Assuming that it is, how can I performed a nested allocation of my derived-type structure ?
Does the "allocate(X, source=Y)" can be anny help ?

Thanks for helping.
0 Kudos
3 Replies
jimdempseyatthecove
Honored Contributor III
739 Views
Hi,

I have not experimented with your situation and cannot comment as if you are seeing a bug or if you are attempting to do something not supported. You might try recoding along the line of:

allocate(temp(size(Array)+expandBy)
temp(1:size(Array)) = Array
call move_alloc(temp, Array)
*** the above assumes your user defined type has proper initialization ***

Jim Dempsey
0 Kudos
FlyingHermes
New Contributor I
739 Views
Thanks.
However, the problem is that , in your example, the "Array" variable is a allocatable derived-typed with allocatable component.
So the "allocate(temp(size(Array)+expandBy)" statement do not allocatae the componene tof the "Temp" derived-type structure.
When doing "temp(1:size(Array)) = Array" I do not know how does the allocatable component of "Array" (which have been allocated) are store in the un-allocataed component of "Temp".
0 Kudos
jimdempseyatthecove
Honored Contributor III
739 Views
Fortran 2003 has the ability to auto allocate (and/or reallocate)objects on the left hand side of an assignment

-assume:realloc_lhs (or -assume:norealloc_lhs to disable)

The method (with -assume:realloc_lhs) should work, although I haven't tried it with derived-type allocatable components.

Jim Dempsey
0 Kudos
Reply