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

PDT question

Walt_Brainerd
Beginner
526 Views

<p>I am trying some new things with Beta 2016 (W8.1, cygwin) and have several things working, including submodules, PDTs, and DTIO !

<p>I have encountered a couple of bugs and ICEs, which I have submitted, but this is a question.

<p>I am trying to extend operator (+) and assignment (=) with a PDT. Each seems to work (sort of) but not together. How do I declare the result of the operator extension so that it is compatible with the arguments (other than literal array sizes)? Here is what I have so far (sorry, I have no clue how to format this thing). I am going to try the whole thing again with allocatables, but I think the simpler case should work ???

<pre>

$ ifort addmatrix.f90
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0 Beta Build 20150326
Copyright (C) 1985-2015 Intel Corporation.  All rights reserved.

addmatrix.f90(67): error #6197: An assignment of different structure types is invalid.
   c = a + b
---------^
compilation aborted for addmatrix.f90 (code 1)

</pre>

<pre>

module matrix_mod

   implicit none
   private

   integer, parameter, public :: single = kind(0.0)
   integer, parameter, public :: double = kind(0.0d0)

   type, public :: matrix(rows, cols, k)
      integer, len :: rows, cols
      integer, kind :: k
      real(kind = k), dimension(rows, cols) :: values
   end type matrix

   interface operator (+)
      procedure single_add_matrix   !, double_add_matrix
   end interface

   interface assignment (=)
      procedure single_assign_matrix
   end interface

   public :: operator (+)
   public :: assignment (=)

contains

   function single_add_matrix(x, y) result (rm)
      type (matrix(*, *, single)), intent(in) :: x, y
      type (matrix(x%rows, x%cols, single)) :: rm
!      type (matrix(1000, 200, single)) :: rm
      if (x%rows /= y%rows .or. x%cols /= y%cols) then
         rm%values = -huge(x%values)
      else
         rm%values = x%values + y%values
      end if
   end function single_add_matrix

   subroutine single_assign_matrix(v, e)
      type (matrix(*, *, single)), intent(in) :: e
      type (matrix(*, *, single)), intent(out) :: v
print*, "in assign"
      if (all(shape(v%values) == shape(e%values))) then
         v%values = e%values
      else
         v%values = -huge(e%values)
      end if
   end subroutine single_assign_matrix

end module matrix_mod

</pre>

0 Kudos
2 Replies
Walt_Brainerd
Beginner
526 Views
Sorry, the mail program didn't get posted (the commented print statement causes an ICE): program matrix_add use matrix_mod implicit none type (matrix(1000, 200, k=single)) :: a, b, c type (matrix(1000, 100, k=single)) :: x call random_seed() call random_number(a%values) call random_number(b%values) call random_number(x%values) !print *, a+b c = a c = x c = a + b print *, sum(c%values) print *, c%values(1,1) end program matrix_add
0 Kudos
FortranFan
Honored Contributor III
526 Views

This might be still an open issue in Intel Fortran as mentioned in this thread: https://software.intel.com/pt-br/forums/topic/536542

To get the syntax highlighting, use the "Code" link to paste your code:

code.png

 

0 Kudos
Reply