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

Problem with user defined operators

Arash_Rasekh
Beginner
1,331 Views

Hi,

I have a problem with user defined type-bound generic operators. The issue occurs when i use dotted string as an operator in UDTs. Here there is an example,

[fortran]

! 10/11/2012
module module_precision
integer, parameter :: sp = kind(1.0e0)
integer, parameter :: dp = kind(1.0d0)
end module module_precision
!====================================================================================
! 10/13/2012
module module_vector
use module_precision,only: wp => dp
implicit none
!====================================================================================
type,abstract :: type_vector_base
real(wp) :: x=0._wp
real(wp) :: y=0._wp
contains
procedure(interface_vector_vector_scalar_real_operator) ,deferred,private :: vector_dot_product
generic :: operator(.dp.)=>vector_dot_product
end type type_vector_base
!------------------------------------------------------------------------------------
type,extends(type_vector_base) :: type_vector_2d
contains
procedure,private :: vector_dot_product =>vector_dot_product_2d
end type type_vector_2d
!====================================================================================
abstract interface
function interface_vector_vector_scalar_real_operator(vector1,vector2) result(scalar_result)
import :: type_vector_base,wp
class(type_vector_base),intent(in) :: vector1
class(type_vector_base),intent(in) :: vector2
real(wp) :: scalar_result
end function interface_vector_vector_scalar_real_operator
!---------------------------------------
end interface
!====================================================================================
contains
!====================================================================================
function vector_dot_product_2d(vector1,vector2) result(scalar_result)
class(type_vector_2d) ,intent(in) :: vector1
class(type_vector_base),intent(in) :: vector2
real(wp):: scalar_result
! body
scalar_result=vector1%x*vector2%x+vector1%y*vector2%y
end function vector_dot_product_2d
!====================================================================================
end module module_vector
!====================================================================================
program test_dot_product
use module_vector
type(type_vector_2d) ::normal1,normal2
real(wp) :: res
res = normal1 .dp. normal2
end

[/fortran]

And the output is

------ Build started: Project: test mkl, Configuration: Debug|x64 ------

Compiling with Intel(R) Visual Fortran Compiler XE 13.0.1.119 [Intel(R) 64]...
test dp.f90
C:\Users\Arash\University Activites\Thesis\test mkl\test mkl\test dp.f90(51): error #6866: Dotted string neither a defined operator nor a structure component [DP]
C:\Users\Arash\University Activites\Thesis\test mkl\test mkl\test dp.f90(49): remark #7712: This variable has not been used. [NORMAL1]
C:\Users\Arash\University Activites\Thesis\test mkl\test mkl\test dp.f90(49): remark #7712: This variable has not been used. [NORMAL2]
compilation aborted for C:\Users\Arash\University Activites\Thesis\test mkl\test mkl\test dp.f90 (code 1)

Build log written to "file://C:\Users\Arash\University Activites\Thesis\test mkl\test mkl\x64\Debug\BuildLog.htm"
test mkl - 2 error(s), 0 warning(s)


---------------------- Done ----------------------

 Any idea?

Best regards, Arash.

0 Kudos
8 Replies
Steven_L_Intel1
Employee
1,331 Views

Nothing jumps out at me as a problem in your code - I will investigate.

0 Kudos
Steven_L_Intel1
Employee
1,331 Views

I have escalated this to development as issue DPD200240115 and will let you know what we find.

0 Kudos
Arash_Rasekh
Beginner
1,331 Views

Thank you Steve.

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,331 Views

what happens if you...

module module_precision 
  integer, parameter :: sp = kind(1.0e0) 
  integer, parameter :: wasdp = kind(1.0d0) 
end module module_precision 
module module_vector 
  use module_precision,only: wp => wasdp 
  ...

 

Jim Dempsey

0 Kudos
Steven_L_Intel1
Employee
1,331 Views

That doesn't change anything - that was the first thing I tried.

If the operator is defined in the extended type, it works, but it should work the way it is.

0 Kudos
FortranFan
Honored Contributor III
1,331 Views

I was also thinking along the same lines as Jim i.e., some conflict between the "dp" kind parameter and ".dp." operator.

If that's not an issue, then could it be that the vector_dot_product procedure associated with the ".dp." public operator should also be public instead of private?

Arash R., have you tried some other operator other than a dotted string?  If not, can you try that out?  Say the simple asterisk (*) which actually would make the code easier to read. Separately, your vector_dot_product_2d function specifies the class type_vector_2d for vector1 but type_vector_base for vector2 - is this intended?  If yes, care to explain why?  Your test program is inconsistent with the function specification, not that this has anything to do with your operator issue.

Regards,

0 Kudos
Steven_L_Intel1
Employee
1,331 Views

The arguments for the procedures are as required by the Fortran standard in this context. Removing PRIVATE doesn't change the beahvior.

0 Kudos
Steven_L_Intel1
Employee
1,331 Views

I expect this bug to be fixed in Update 3 (end of March).

0 Kudos
Reply