- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In my fortran program, I need to calculate matrix direct product(noted by an X in a circle).However there are no any intrinsic function or subroutine can do this,so I need to write it by myself.In order to save memery I use an integer n instead of an n by n
unit matrix. The direct product is not commutable,i.e. A direct-product B isn't equal B direct-product A. Therefore, I have to write 3 subroutines: matrix_unit(A,n,C),unit_matrix(n,A,C),and matrix_matrix(A,B,C).Finally,I want to hvae an interface named direct_product.
unit matrix. The direct product is not commutable,i.e. A direct-product B isn't equal B direct-product A. Therefore, I have to write 3 subroutines: matrix_unit(A,n,C),unit_matrix(n,A,C),and matrix_matrix(A,B,C).Finally,I want to hvae an interface named direct_product.
here is my code:
module matrix_direct_product
use nrtype
implicit none
interface direct_product
module procedure matrix_unit,unit_matrix,matrix_matrix
end interface direct_product
contains
subroutine matrix_unit(A,n,C)
implicit none
real(dp),dimension(:,:),intent(in) :: A
integer(i4b),intent(in) :: n
real(dp),dimension(:,:),intent(inout) :: C
write(*,*)'AxI'
return
end subroutine matrix_unit
subroutine unit_matrix(n,A,C)
implicit none
real(dp),dimension(:,:),intent(in) :: A
integer(i4b),intent(in) :: n
real(dp),dimension(:,:),intent(inout) :: C
write(*,*) 'IxA'
return
end subroutine unit_matrix
subroutine matrix_matrix(f,A,B,C)
implicit none
real(dp),intent(in) :: f
write(*,*) 'AxB'
return
end subroutine matrix_matrix
end module matrix_direct_product
program test
use nrtype
use matrix_direct_product
implicit none
real(dp),dimension(2,2),parameter::Sz=reshape((/0.50_dp,0.0_dp,0.0_dp,-0.50_dp/),(/2,2/))
real(dp),dimension(512,512) :: A,B,C
integer(i4b) :: n,i,j
call direct_product(Sz,2,A)
call direct_product(2,Sz,B)
call direct_product(0.5_dp,A,B,C)
end
It is ok to compile with gfortran and g95 and the result is correct, but when I try to compile with intel fortran compiler 9 I got the error messages:
fortcom: Error: matrix_direct_product.f90, line 18: The
type/rank/keyword signature for this specific procedure matches
another specific procedure that shares the same generic-name.
[UNIT_MATRIX]
subroutine unit_matrix(n,A,C)
-----------^
How to modify the code to suitable for ifort ?
module matrix_direct_product
use nrtype
implicit none
interface direct_product
module procedure matrix_unit,unit_matrix,matrix_matrix
end interface direct_product
contains
subroutine matrix_unit(A,n,C)
implicit none
real(dp),dimension(:,:),intent(in) :: A
integer(i4b),intent(in) :: n
real(dp),dimension(:,:),intent(inout) :: C
write(*,*)'AxI'
return
end subroutine matrix_unit
subroutine unit_matrix(n,A,C)
implicit none
real(dp),dimension(:,:),intent(in) :: A
integer(i4b),intent(in) :: n
real(dp),dimension(:,:),intent(inout) :: C
write(*,*) 'IxA'
return
end subroutine unit_matrix
subroutine matrix_matrix(f,A,B,C)
implicit none
real(dp),intent(in) :: f
real(dp),dimension(:,:),intent(in) :: A,B
real(dp),dimension(:,:),intent(inout) :: Cwrite(*,*) 'AxB'
return
end subroutine matrix_matrix
end module matrix_direct_product
program test
use nrtype
use matrix_direct_product
implicit none
real(dp),dimension(2,2),parameter::Sz=reshape((/0.50_dp,0.0_dp,0.0_dp,-0.50_dp/),(/2,2/))
real(dp),dimension(512,512) :: A,B,C
integer(i4b) :: n,i,j
call direct_product(Sz,2,A)
call direct_product(2,Sz,B)
call direct_product(0.5_dp,A,B,C)
end
It is ok to compile with gfortran and g95 and the result is correct, but when I try to compile with intel fortran compiler 9 I got the error messages:
fortcom: Error: matrix_direct_product.f90, line 18: The
type/rank/keyword signature for this specific procedure matches
another specific procedure that shares the same generic-name.
[UNIT_MATRIX]
subroutine unit_matrix(n,A,C)
-----------^
How to modify the code to suitable for ifort ?
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Both g95 and gfortran have a bug, then. I suggest you report it.
The problem is that the only difference betwen module procedures unit_matrix and matrix_unit is the order of the arguments. Each argument of the same name has the same type, kind and rank. If you had the call:
call direct_product(A=Sz,N=2,C=A)
which procedure would get called?
One solution is to change the argument names in one of the procedures, for example:
subroutine unit_matrix(n,AX,C)
implicit none
real(dp),dimension(:,:),intent(in) :: AX
integer(i4b),intent(in) :: n
real(dp),dimension(:,:),intent(inout) :: C
write(*,*) 'IxA'
return
end subroutine unit_matrix
Then there can be no ambiguity, and as long as you don't use the argument keywords in the calls, none will be the wiser.
Another common error that trips people up is adding an OPTIONAL argument where that is the only thing that distinguishes two procedures. Yet another is making one procedure take a pointer and another not - the language does not consider that in resolving generics.
The problem is that the only difference betwen module procedures unit_matrix and matrix_unit is the order of the arguments. Each argument of the same name has the same type, kind and rank. If you had the call:
call direct_product(A=Sz,N=2,C=A)
which procedure would get called?
One solution is to change the argument names in one of the procedures, for example:
subroutine unit_matrix(n,AX,C)
implicit none
real(dp),dimension(:,:),intent(in) :: AX
integer(i4b),intent(in) :: n
real(dp),dimension(:,:),intent(inout) :: C
write(*,*) 'IxA'
return
end subroutine unit_matrix
Then there can be no ambiguity, and as long as you don't use the argument keywords in the calls, none will be the wiser.
Another common error that trips people up is adding an OPTIONAL argument where that is the only thing that distinguishes two procedures. Yet another is making one procedure take a pointer and another not - the language does not consider that in resolving generics.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page