Software Archive
Read-only legacy content
17061 Discussions

Re: generic+intrinsic procedures

Intel_C_Intel
Employee
255 Views
Tough question! You can't name MATMUL as a specific function in your INTERFACE block where you create the generic name "myMatmul" because it's not a specific name. Indeed, since MATMUL is a transformational intrinsic it has no set of specific names. Here is my attempt, which also doesn't work:

 
module matmul_mod 
   implicit none 
   interface matmul 
      module procedure matmul_3 
   end interface matmul 
   public matmul 
   private matmul_3 
   contains 
      function matmul_3(x,y) 
         real, intent(in) :: x(:,:), y(:,:) 
         real matmul_3(size(x,1),size(y,2)) 
 
         matmul_3 = 42 
      end function matmul_3 
end module matmul_mod 
 
module myMatmul_mod 
   use matmul_mod, only: myMatmul=>matmul 
   implicit none 
end module myMatmul_mod 
 
program matmul_overload 
   use myMatmul_mod 
   implicit none 
   integer :: a(3,3) = reshape((/1,2,3, & 
                                 4,5,6, & 
                                 7,8,9/), & 
                       (/3,3/), order = (/2,1/)) 
   integer :: b(3,3) = reshape((/0,1,0, & 
                                 0,0,1, & 
                                 1,0,0/), & 
                       (/3,3/), order = (/2,1/)) 
   real c(3,3), d(3,3) 
 
   c = a 
   d = b 
 
   write(*,'(3(i2:1x))') transpose(myMatmul(b,a)) 
   write(*,'(3(f4.1:1x))') transpose(myMatmul(d,c)) 
end program matmul_overload 

Now, this all looks plausible becuase I first extend the MATMUL generic name to include my matmul_3 function and then, via a USE statement, rename MATMUL to MYMATMUL. But CVF 6.6 sees only MATMUL_3 as being renamed in this last operation and not the transformational intrinsic MATMUL as we desired, so it prints out a couple of error statements. Indeed, I would have thought that the original interface block should have been an error because the compler has no way of knowing whether to choose MATMUL_3 or the transformational intrinsic MATMUL when called upon to multiply two rank 2 real arrays. You can overload ELEMENTAL functions like this (the compiler selects the non-elemental function where available and the ELEMENTAL function otherwise) but I am not sure about the rules pertaining to transformational intrinsics. CVF 6.6 doesn't complain about this when F95 standard checking is enabled, however.
0 Kudos
0 Replies
Reply