Hi,
I have an issue with the compilation of my code related with the resolution of generic interfaces. I cannot post my code due to its large extent, but I isolated the origin of the problem and I pasted a simple example below. I apologize for the length of the code. I signaled the most important lines with commented out labelled arrows:
MODULE su2_matrix
IMPLICIT NONE
PRIVATE
PUBLIC :: su2, trace
TYPE :: su2
COMPLEX :: a = CMPLX(1.,0.) ! <=== [1]
COMPLEX :: b = CMPLX(0.,0.) ! <=== [2]
END TYPE su2
INTERFACE trace
MODULE PROCEDURE tr_su2
END INTERFACE trace
CONTAINS
PURE ELEMENTAL FUNCTION tr_su2(u) RESULT(z)
TYPE(su2), INTENT(in) :: u
COMPLEX :: z
z = CMPLX(2.*REAL(u%a),0.)
END FUNCTION tr_su2
END MODULE su2_matrix
MODULE suN_matrix
USE su2_matrix ! <=== [3]
IMPLICIT NONE
PRIVATE
PUBLIC :: suN, trace
INTEGER, PARAMETER, PRIVATE :: N = 3
TYPE :: suN
COMPLEX :: idx(N,N)
END TYPE suN
INTERFACE trace
MODULE PROCEDURE tr_suN
END INTERFACE trace
CONTAINS
PURE ELEMENTAL FUNCTION tr_suN(a) RESULT(z)
TYPE(suN), INTENT(in) :: a
COMPLEX :: z
INTEGER :: i
z = CMPLX(0.,0.)
DO i=1,N
z = z + a%idx(i,i)
END DO
END FUNCTION tr_suN
END MODULE suN_matrix
MODULE dof
USE suN_matrix ! <=== [4]
USE su2_matrix ! <=== [5]
IMPLICIT NONE
PRIVATE
PUBLIC :: su2, suN, trace
END MODULE dof
MODULE lattfield
USE dof ! <=== [6]
!USE suN_matrix ! <=== [7]
!USE su2_matrix ! <=== [8]
IMPLICIT NONE
PRIVATE
PUBLIC :: cpx_field, su2_field, suN_field, trace
INTEGER, PARAMETER :: l(3) = [ 8,8,8 ]
TYPE :: cpx_field
COMPLEX :: site(l(1),l(2),l(3))
END TYPE cpx_field
TYPE :: su2_field
TYPE(su2) :: site(l(1),l(2),l(3))
END TYPE su2_field
TYPE :: suN_field
TYPE(suN) :: site(l(1),l(2),l(3))
END TYPE suN_field
INTERFACE trace
MODULE PROCEDURE tr_su2f
MODULE PROCEDURE tr_suNf
END INTERFACE trace
CONTAINS
PURE ELEMENTAL FUNCTION tr_su2f(a) RESULT(z)
TYPE(su2_field), INTENT(in) :: a
TYPE(cpx_field) :: z
z%site = trace(a%site)
END FUNCTION tr_su2f
PURE ELEMENTAL FUNCTION tr_suNf(a) RESULT(z)
TYPE(suN_field), INTENT(in) :: a
TYPE(cpx_field) :: z
z%site = trace(a%site) ! <=== [9]
END FUNCTION tr_suNf
END MODULE lattfield
The code contains 4 modules, the 3rd of which, “MODULE dof”, is an umbrella module that I use for pure convenience. All it does is to collect the public objects in the 1st and 2nd modules and make them public again, so I can use them in “MODULE lattfield”.
In principle, there is nothing wrong in doing this that I know of. In fact, it compiles and behaves perfectly well with the Intel and GNU compilers. However, when I compile it with pgf90 (PGI Workstation v12.5 for Linux) it issues the following error, associated with line [9]:
PGF90-S-0155-Could not resolve generic procedure trace (test.f90: 119)
0 inform, 0 warnings, 1 severes, 0 fatal for tr_sunf
The error message vanishes and the compilation is successful in any of the following situations:
-
- if I swap the lines labelled by [4] and [5] like this:
USE su2_matrix ! <=== [5]
USE suN_matrix ! <=== [4]
-
if I simply avoid calling “USE dof” in the last module, line [6], and call the 1st and 2nd modules directly, lines [7] and [8].
-
if I delete the line [3] (but it should be there for future use).
-
and also, curiously, if I avoid instantiating the components of the derived type “su2” with default values, in lines [1] and [2] (This one is puzzling).
Thus the question is: Why is this so? Why can’t I use an umbrella module in this way? Why is the order of the lines [4] and [5] important? I don’t remember the order being relevant in the Fortran standard. Also, the derived types “su2” and “suN” are very different and there is no apparent ambiguity in the generic interface for “trace”.
Thank you,
helvio
Update: I made corrections to the code above.