我预计在乘以不符合矩阵时内在matmul会失败。在这个简单的例子中(参见下面的简单代码),我使用matmul将4x3矩阵乘以4x4矩阵。有趣的是,intel编译器不会在运行时或编译时发出任何警告或致命错误消息。我试过了 - 检查所有'标志,它也没有发现这个错误。有没有人对此有任何想法?
P.S。 gfortran确实抱怨此操作
program main
implicit none
interface
subroutine shouldFail(arrayInput, scalarOutput)
implicit none
real (8), intent(in) :: arrayInput(:,:)
real (8), intent(out) :: scalarOutput
end
end interface
real (8) :: scalarOutput, arrayInput(4, 3)
arrayInput(:,:) = 1.0
call shouldFail(arrayInput, scalarOutput)
write(*,*) scalarOutput
end program main
!#############################################
subroutine shouldFail(arrayInput, scalarOutput)
implicit none
real (8), intent(in) :: arrayInput(:,:)
real (8), intent(out) :: scalarOutput
real (8) :: jacobian(3, 4), derivative(4, 4)
derivative(:,:) = 1.0
jacobian = matmul(arrayInput, derivative)
scalarOutput = jacobian(1, 2)
end subroutine shouldFail
答案 0 :(得分:0)
在英特尔REAL(8)上是一致的,所以转到这个问题......
答案如下:software.intel.com/en-us/node/693211
如果数组输入具有形状(n,m)并且导数具有形状(m,k),则结果是具有形状(n,k)的二级数组(Jacobite)......
是否需要/想要添加USE ISO_C_BINDING然后使用REAL(KIND = C_FLOAT)对于需要可移植的概念性未来是值得的...(通常在MATMUL说服它有效之后) 。
看起来像这样:
subroutine shouldFail(arrayInput, scalarOutput)
USE ISO_C_BINDING
implicit none
real(KIND=C_DOUBLE), DIMENSION(:,:), intent(in ) :: arrayInput
real(KIND=C_DOUBLE) , intent( out) :: scalarOutput
real(KIND=C_DOUBLE), DIMENSION(3,4) :: Jacobian
real(KIND=C_DOUBLE), DIMENSION(4,4) :: derivative
(Here: You may want to consider checking the rank/shape before the MATMUL call if you are concerned.)