Object-Oriented Fortran 03

I’ve been looking to use CUDA Fortran and/or OpenACC to accelerate some kernels in a moderately large code I work with (which is written in OO F03). However, I’ve been encountering several issues compiling with PGI.

I’ve created a small test program that demonstrates the current issues I’m observing, which seem to be related to allocatable arrays in user defined derived types. Any thoughts on what sorts of support should be coming out in future releases? Or work-arounds to these issues?


PROGRAM vector

  IMPLICIT NONE

  TYPE,ABSTRACT :: VectorType
    LOGICAL(4) :: isInit=.FALSE.
    INTEGER(4) :: n=0
  ENDTYPE VectorType

  TYPE,EXTENDS(VectorType) :: RealVectorType
    REAL(8),ALLOCATABLE :: b(:)
  ENDTYPE RealVectorType

  TYPE(RealVectorType) :: thisVector
  INTEGER(4) :: n=5

  SELECTTYPE(thisVector); TYPE IS(RealVectorType)
    IF(.NOT. thisVector%isInit) THEN
      IF(n < 1) THEN
        WRITE(*,*) 'fail'
      ELSE
        thisVector%isInit=.TRUE.
        thisVector%n=n
        ALLOCATE(thisVector%b(n))
        WRITE(*,*) 'success'
      ENDIF
    ENDIF
  ENDSELECT

ENDPROGRAM vector

Hi sgs,

The problem with this code is that “thisVector” isn’t polymorphic. What error are you getting? What version of the compiler are you using?

We did add support allocatable arrays in user defined derived types a few years ago (sorry I’ve forgotten the exact version) so you’re issue may be solved by using the latest compiler version.

  • Mat
% pgfortran -c 1_30_13.f90
PGF90-S-0034-Syntax error at or near identifier vectortype (1_30_13.f90: 17)
  0 inform,   0 warnings,   1 severes, 0 fatal for vector

gfortran gives a better error message:

% gfortran -c 1_30_13.f90
1_30_13.f90:17.25:

  SELECTTYPE(thisVector); TYPE IS(RealVectorType)
                         1
Error: Selector shall be polymorphic in SELECT TYPE statement at (1)

Mat,

Thanks for your reply. I see that my small test program was incorrect. However,I’m made a slight modification so thisVector is polymorphic. This compiles fine with gfortran, but not pgi (at least with version 12.9.0) as far as I can tell.

PROGRAM vector

  IMPLICIT NONE

  TYPE,ABSTRACT :: VectorType
    LOGICAL(4) :: isInit=.FALSE.
    INTEGER(4) :: n=0
  ENDTYPE VectorType

  TYPE,EXTENDS(VectorType) :: RealVectorType
    REAL(8),ALLOCATABLE :: b(:)
  ENDTYPE RealVectorType

  CLASS(VectorType),ALLOCATABLE :: thisVector
  INTEGER(4) :: n=5

  ALLOCATE(RealVectorType :: thisVector)

  SELECTTYPE(thisVector); TYPE IS(RealVectorType)
    IF(.NOT. thisVector%isInit) THEN
      IF(n < 1) THEN
        WRITE(*,*) 'fail'
      ELSE
        thisVector%isInit=.TRUE.
        thisVector%n=n
        ALLOCATE(thisVector%b(n))
        WRITE(*,*) 'success'
      ENDIF
    ENDIF
  ENDSELECT

ENDPROGRAM vector

Thanks SGS,

I sent this to one of our engineers who determine it is indeed a compiler error but as he puts it, " albeit a very strange one". I submitted a problem report, TPR#19094.

The work around is to change “TYPE IS” to “CLASS IS”.

Thanks for the report,
Mat

Interesting. Yeah, we’ve definitely had some trouble with some of the object oriented-ness in general. We have a lot of extra SELECTTYPE statements as work arounds for Intel windows compilers. We’ll see how it goes…at least until the next version is released.

Thanks for your time.

A small update…I think the main issue is that the type name starts with an intrinsic type. I encounter similar issues with something like IntegerVectorType, but all types not starting with Real or Integer do not demonstrate the problem.

TPR 19094 has been fixed in the 13.3 release, and is now being closed.

regards,
dave