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

Bounds remapping error on derived type component

Wukie__Nathan
Beginner
667 Views

I am experiencing what appears to be incorrect behavior when attempting to remap the bounds of an array within a derived type. Given an allocatable array of components(elements), within a 'mesh' type, I am trying to remap the rank-1 'elems' array within a 'mesh' type to a rank-3 view. Unfortunately I have not yet had luck trying to produce a minimum working example so the following code is just to convey the concept here.

type :: element_t
   integer :: ielem
end type

type :: mesh_t
  type(element_t), allocatable :: elems(:)
end type

type :: domain_t
 type(mesh_t) :: mesh
end type

I encounter the behavior in a situation like the following, where I have a domain%mesh%elems component that I would like to remap as a matrix:

type(domain_t)           :: domain
type(element_t), pointer :: elems_m(:,:,:)

% Domain is initialized with 2 elements

elems_m(1:2,1:1,1:1) => domain%mesh%elems(1:2)


When I access the elements of elems_m(1,1,1) and elems_m(2,1,1), they both point to domain%mesh%elems(1).

I am using ifort 15.0.3 on OS X. I have observed gfortran 4.9.2 produces the expected results of elems_m(1,1,1) => elems(1) and elems_m(2,1,1) => elems(2).

I did find a work around via an entry on https://wiki.ucar.edu/display/ccsm/Fortran+Compiler+Bug+List with regards to the NAG compiler. In the workaround, I first create a temporary rank-1 pointer and associate it with the rank-1 derived-type component. I then remap the bounds using the temporary pointer as follows:

type(domain_t)           :: domain
type(element_t), pointer :: elems_m(:,:,:)
type(element_t), pointer :: temp(:)

% Initialize domain%mesh with 2 elements

temp => domain%mesh%elems

elems_m(1:2,1:1,1:1) => temp(1:2)

Now, accessing the components of elems_m produces the expected results as elems_m(1,1,1) => elems(1) and elems_m(2,1,1) => elems(2)

 

 

 

 

 

0 Kudos
1 Solution
Steven_L_Intel1
Employee
667 Views

I was able to reproduce the problem in 15.0.4, but not in 16.0. The 16.0 compiler will be released in August.

View solution in original post

0 Kudos
3 Replies
Steven_L_Intel1
Employee
667 Views

Thanks, I'll see if I can take your snippets and construct a reproducer.

0 Kudos
Steven_L_Intel1
Employee
668 Views

I was able to reproduce the problem in 15.0.4, but not in 16.0. The 16.0 compiler will be released in August.

0 Kudos
Wukie__Nathan
Beginner
667 Views

Great, thanks for the follow-up Steve.

0 Kudos
Reply