- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, Can you help me with the error in the follwing code ? Looks like a bug to me. The problem is described after line 116 of the code.
thanks
Reddy
thanks
Reddy
[fortran]module precision_m
implicit none
integer,parameter :: WP=kind(1.0D0)
end module precision_m
module matrixUtils_m
use precision_m
implicit none
type Matrix_t
integer :: m
integer :: n
complex(WP), allocatable :: cMat(:,:)
contains
procedure :: assigncMatrix_Matrix
procedure :: assignrMatrix_Matrix
generic :: assignment(=) => assigncMatrix_Matrix,assignrMatrix_Matrix
end type Matrix_t
interface new_Matrix
module procedure Matrix_Constructor
end interface new_Matrix
! For now all blocks will be of same size
type :: BlockTriDiagMat_t
integer :: nb !numBlock ! numblock
integer :: bs
!integer,allocatable :: bs(:,:) ! Size [2,nb]
type(Matrix_t), allocatable :: udiag(:) ! size nb-1
type(Matrix_t), allocatable :: diag(:) ! size nb
type(Matrix_t), allocatable :: ldiag(:) ! size nb-1
end type BlockTriDiagMat_t
interface new_BlockTriDiagMatrix
module procedure BlockTriDiagMatrix_Constructor
end interface new_BlockTriDiagMatrix
contains
! %------------------------------------------------------%
! | Matrix Related Routines
! %------------------------------------------------------%
function Matrix_Constructor(m,n,iValue) result(newMatrix)
integer, intent(in) :: m
integer, intent(in), optional :: n
complex(WP), intent(in),optional :: iValue
type(Matrix_t) :: newMatrix
newMatrix%m = m
if(present(n)) then
newMatrix%n = n
else
newMatrix%n = m
end if
allocate(newMatrix%cMat(newMatrix%m,newMatrix%n))
if(present(iValue)) then
newMatrix%cMat = iValue
else
newMatrix%cMat = (0.0_WP, 0.0_WP)
end if
end function Matrix_Constructor
subroutine assigncMatrix_Matrix(this, Mat)
class(Matrix_t), intent(inout) :: this
complex(WP), intent(in) :: Mat(:,:)
print*,'I am assigning complex matrix of size',size(Mat)
this%m = size(Mat,dim=1)
this%n = size(Mat,dim=2)
this%cMat = Mat
end subroutine assigncMatrix_Matrix
subroutine assignrMatrix_Matrix(this, Mat)
class(Matrix_t), intent(inout) :: this
real(WP), intent(in) :: Mat(:,:)
this%m = size(Mat,dim=1)
this%n = size(Mat,dim=2)
this%cMat = Mat
end subroutine assignrMatrix_Matrix
! %------------------------------------------------------%
! | BTDMatrix Related Routines
! %------------------------------------------------------%
function BlockTriDiagMatrix_Constructor(nb,bs,iValue) result(newMatrix)
integer, intent(in) :: nb
integer, intent(in) :: bs
complex(WP), intent(in), optional :: iValue
type(BlockTriDiagMat_t) :: newMatrix
complex(WP) :: iValueCopy
integer :: ic
newMatrix%nb = nb
newMatrix%bs = bs
if(present(iValue)) then
iValueCopy = iValue
else
iValueCopy = (0.0_WP, 0.0_WP)
end if
allocate(newMatrix%diag(nb),newMatrix%udiag(nb-1),newMatrix%ldiag(nb-1))
do ic=1,nb-1
newMatrix%diag(ic) = new_Matrix(bs,bs,iValueCopy)
newMatrix%ldiag(ic) = new_Matrix(bs,bs,iValueCopy)
newMatrix%udiag(ic) = new_Matrix(bs,bs,iValueCopy)
end do
newMatrix%diag(nb) = new_Matrix(bs,bs,iValueCopy)
end function BlockTriDiagMatrix_Constructor
end module matrixUtils_m
program testMatrix
use matrixUtils_m
use precision_m
implicit none
type(BlockTriDiagMat_t) :: TDM
type(Matrix_t), allocatable :: diag(:)
integer :: nb=5
integer :: bs=5
integer :: ic
complex(WP), allocatable :: matValue(:,:)
allocate(matValue(bs,bs))
matValue = (0.0_WP, 0.0_WP)
TDM = new_blocktridiagmatrix(nb,bs)
! This line gives error
print*,'i am here for erro'
TDM%diag(1) = matValue ! <>
! This line doesnot give error
allocate(diag(nb))
! if you enable the follwoing three lines,
! the error in LINE ONE disappears
!do ic=1,nb
! diag(ic) = new_matrix(bs,bs)
!end do
diag(1) = matValue
print*,'i am here for no erro'
end program testMatrix
! compile with
! ifort -assume realloc_lhs matrixUtils.F90
! ifort -V
! Intel Fortran Intel 64 Compiler XE for applications running on Intel 64
!, Version 12.1.0.233 Build 20110811
!Copyright (C) 1985-2011 Intel Corporation. All rights reserved.
!FOR NON-COMMERCIAL USE ONLY
! Error:
!matrixUtils.F90(118): error #6303: The assignment operation or the binary expres
!sion operation is invalid for the data types of the two operands. [MATVALUE]
! TDM%diag(1) = matValue ! <>
!------------------^
!matrixUtils.F90(118): error #6366: The shapes of the array expressions do not co
!nform. [DIAG]
! TDM%diag(1) = matValue ! <>
!--------^
!compilation aborted for matrixUtils.F90 (code 1)
[/fortran]
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The left side of the assignment, TDM%diag(1), is a scalar of type Matrix_t. The right side is a two-dimensional COMPLEX array. What did you want this to do? Perhaps you meant to write:
TDM%diag(1)%cMat = matValue
? Unless you have allocated the cMat component, make sure you compile with -standard-semantics
TDM%diag(1)%cMat = matValue
? Unless you have allocated the cMat component, make sure you compile with -standard-semantics
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I overloaded the assignment using this subroutine.
Also, I compile the code with -assume realloac_lhs.
As I said, the code works well if i enable lines 121 to 125.
I use these derived data types in bigger code and every thing works well but i had insert the fix i mentioned in lines 121 to 125.
Also, I compile the code with -assume realloac_lhs.
As I said, the code works well if i enable lines 121 to 125.
I use these derived data types in bigger code and every thing works well but i had insert the fix i mentioned in lines 121 to 125.
[fortran]subroutine assigncMatrix_Matrix(this, Mat) class(Matrix_t), intent(inout) :: this complex(WP), intent(in) :: Mat(:,:) print*,'I am assigning complex matrix of size',size(Mat) this%m = size(Mat,dim=1) this%n = size(Mat,dim=2) this%cMat = Mat end subroutine assigncMatrix_Matrix[/fortran]
[bash]
[/bash]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry for having overlooked that. I agree that this seems wrong - I will escalate it to development. Issue ID is DPD200177253.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This problem will be fixed in a release later this year.
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