Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Generic argument type function

OP1
New Contributor III
794 Views
I want to create a function CHECK_SIZE_COMPATIBILITY which takes two array arguments. The function returns 1 if the array have the same allocation status, shape and dimension, and 0 otherwise. I want this function to work with multiple array types (for instance, one array would be a logical array, the other a real array; or a integer array and a real array).

One way of doing this is to create a (large) bunch of argument specific procedures, then group them in a generic function. But this is very cumbersome given the number of combinations.

Is there a more convenient way of doing this?

Olivier
0 Kudos
4 Replies
Steven_L_Intel1
Employee
794 Views
There is a proposal to add features to Fortran 2008 (as a "Technical Report", not the official standard) which would help you here. In the meantime, I would suggest using the extension !DEC$ ATTRIBUTES NO_ARG_CHECK on the arguments, which will allow them to match anything. You will then need to write code to decode the descriptors (documented in the manuals) and compare the size and allocation status.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
794 Views
There is a proposal to add features to Fortran 2008 (as a "Technical Report", not the official standard) which would help you here. In the meantime, I would suggest using the extension !DEC$ ATTRIBUTES NO_ARG_CHECK on the arguments, which will allow them to match anything. You will then need to write code to decode the descriptors (documented in the manuals) and compare the size and allocation status.

Here's the example. Adjust the function IsShapeEqual at will. It must be external, because there's inherent interface mismatch.

P.S. Steve, can I officially ask that the type definitions below be added into IFCORE.f90? What we currently have there is half-baked, i.e. only needed to support FOR_DESCRIPTOR_ASSIGN.

[plain]module m_shape

interface
logical function IsShapeEqual(arg1, arg2)
!DEC$ATTRIBUTES NO_ARG_CHECK:: arg1, arg2
integer:: arg1(:,:), arg2(:,:)
end function IsShapeEqual
end interface

end module m_shape
!===============================================================
program Descript

use m_shape

implicit none

real:: x(5,3)
character:: y(5,3)
logical:: z(3,5)
character(17):: u(3,5)
character(17):: w(3,5,7)

write(*,*) shape(x), "| ", shape(y), "| ", IsShapeEqual(x, y)
write(*,*) shape(x(1:2,1:2)), "| ", shape(y), "| ", IsShapeEqual(x(1:2,1:2), y)
write(*,*) shape(x), "| ", shape(z), "| ", IsShapeEqual(x, z)
write(*,*) shape(x), "| ", shape(u), "| ", IsShapeEqual(x, u)
write(*,*) shape(u), "| ", shape(z), "| ", IsShapeEqual(u, z)
write(*,*) shape(x), "| ", shape(w), "| ", IsShapeEqual(x, w)

end program Descript

!===============================================================
logical function IsShapeEqual(arg1, arg2) result(bequal)

use ifcore, only: FOR_DESCRIPTOR_MAX_RANK, &
FOR_DESCRIPTOR_ARRAY_DEFINED, &
FOR_DESCRIPTOR_ARRAY_NODEALLOC , &
FOR_DESCRIPTOR_ARRAY_CONTIGUOUS

type t_dim_info
integer iExtent
integer iStride
integer lBound
end type

type t_array_descriptor
INTEGER(INT_PTR_KIND()) :: pBase
INTEGER(4) :: size
INTEGER(4) :: iOffset
INTEGER(4) :: iFlags
INTEGER(4) :: iRank
INTEGER(4) :: iReserved
type (t_dim_info):: dims(FOR_DESCRIPTOR_MAX_RANK)
end type

type(t_array_descriptor):: arg1, arg2

bEqual = arg1%irank .eq. arg2%irank
if (bEqual) bEqual = all(arg1%dims(1:arg1%irank)%iExtent .eq. &
arg2%dims(1:arg2%irank)%iExtent)

end function IsShapeEqual
[/plain]

0 Kudos
OP1
New Contributor III
794 Views
Thanks to both - that's what I need. I can't wait until these Fortran 2008 features (and some of the others I read about) are implemented as part of the standard. I am amazed at the progress that Fortran has made since I started coding with it in the early 90s. I really like the direction in which it's being headed!

The included example was very helpful.

Olivier
0 Kudos
Steven_L_Intel1
Employee
794 Views
We're more likely to provide an implementation of the F2008 proposal. Indeed, I have had in mind to do that but have been too busy to get to it. See here for the current proposal.
0 Kudos
Reply