- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all.
I'm using Intel(R) Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 18.0.1.163 Build 20171018.
It seems to me that the shapes of MATMUL arguments are not checked for conformability if some of them is an allocatable array.
The consequent result are clearly wrong.
Here is a short example, in which the two arguments are clearly non conformable, being one a 1-by-1 array and the other a 5-by-5 array.
Nevertheless, neither at compile-time (that's understandable) nor at runtime there is a complain when performing MATMUL.
That does not change if the arrays are allocated explicitly.
Note that when compiled using gfortran (I used version 4.9.2) a runtime error is issued.
Did I miss some specific compiling option ?
Is it left to the programmer to ensure arguments conformability ?
Thanks a lot.
GM
t_matmul.f90
integer, parameter :: n = 5 real, allocatable :: y(:, :) real, allocatable :: z(:, :) integer :: i, j y = reshape( [ ((i+j/100.0 , i = 1, n), j=1, n) ], [ n, n ]) z = reshape([1.0], [1, 1]) write(*, *) "z: size ", size(z), " shape ", shape(z) write(*, *) "y: size ", size(y), " shape ", shape(y) write(*, *) DO i = 1, size(y,1) WRITE(*, '(19F10.2)') (y(i, j), j=1, size(y,2)) ENDDO write(*, *) write (*, *) "trying y = matmul(z, y) " write(*, *) y = matmul(z, y) DO i = 1, size(y,1) WRITE(*, '(19F10.2)') (y(i, j), j=1, size(y,2)) ENDDO write(*, *) end
$ ifort -warn All -check All -stdlev=f2008 t_matmul.f90 -o t_matmul $ ./t_matmul z: size 1 shape 1 1 y: size 25 shape 5 5 1.01 1.02 1.03 1.04 1.05 2.01 2.02 2.03 2.04 2.05 3.01 3.02 3.03 3.04 3.05 4.01 4.02 4.03 4.04 4.05 5.01 5.02 5.03 5.04 5.05 trying y = matmul(z, y) 1.01 1.02 1.03 1.04 1.05 $ gfortran t_matmul.f90 && ./a.out Z: size 1 shape 1 1 y: size 25 shape 5 5 1.01 1.02 1.03 1.04 1.05 2.01 2.02 2.03 2.04 2.05 3.01 3.02 3.03 3.04 3.05 4.01 4.02 4.03 4.04 4.05 5.01 5.02 5.03 5.04 5.05 trying y = matmul(z, y) Fortran runtime error: dimension of array B incorrect in MATMUL intrinsic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
MATMUL needs to validate array dimensions.
The array shape checking feature was implemented in Intel Fortran Compiler 19.0 Beta and it checks for array shape conformance.
If you write your own MATMUL and it inlines, then the compiler should catch the mismatch in shape at runtime when compiled with –check shape. See https://software.intel.com/en-us/articles/array-shape-check-new-in-intel-fortran-compiler-190
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The compiler is not obligated by the standard to find such a mismatch in shapes. It is a quality of implementation though. Nagfor (which is considered to be a very good analysing/debugging compiler gets it when compiled with -C=all):
Runtime Error: matmul.f90, line 21: Incompatible argument shapes (1x1 and 5x5) to intrinsic MATMUL
gfortran with -fcheck=all gets it as well as you recognised. Indeed, after a quick glance I could also not find a flag for the Intel compiler to diagnose this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your answer, Juergen.
Yes, I understand, and that's why I often use different compilers to catch all possible flaws in my code.
Expecially when you are using automatically allocated allocatable arrays, it would be a valuable help having the compiler checking these issues.
I expected Intel compiler (as well as other commmercial compilers) would be able to do that, given that even gfortan does.
I'll try to live with this.
GM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just wait, maybe one of the Intel folks knows something that is not directly visible in the list of options.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That would be great !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
MATMUL needs to validate array dimensions.
The array shape checking feature was implemented in Intel Fortran Compiler 19.0 Beta and it checks for array shape conformance.
If you write your own MATMUL and it inlines, then the compiler should catch the mismatch in shape at runtime when compiled with –check shape. See https://software.intel.com/en-us/articles/array-shape-check-new-in-intel-fortran-compiler-190
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, Devorah.
I'll be waiting for the Intel Fortran Compiler 19.0 final relase.
GM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Confirmed fixed in upcoming 19.0 final release:
ifort /check:shape matmul001.f90 d:\matmul001.exe z: size 1 shape 1 1 y: size 25 shape 5 5 1.01 1.02 1.03 1.04 1.05 2.01 2.02 2.03 2.04 2.05 3.01 3.02 3.03 3.04 3.05 4.01 4.02 4.03 4.04 4.05 5.01 5.02 5.03 5.04 5.05 trying y = matmul(z, y) forrtl: severe (408): fort: (33): Shape mismatch: The extent of dimension 2 of array Z is 1 and the corresponding extent of array Y is 5 Image PC Routine Line Source matmul001.exe 000000013F433911 Unknown Unknown Unknown matmul001.exe 000000013F4218C7 Unknown Unknown Unknown matmul001.exe 000000013F48BD82 Unknown Unknown Unknown matmul001.exe 000000013F47395B Unknown Unknown Unknown kernel32.dll 0000000076C759CD Unknown Unknown Unknown ntdll.dll 0000000076ED383D Unknown Unknown Unknown !!! matmul001.f90 integer, parameter :: n = 5 real, allocatable :: y(:, :) real, allocatable :: z(:, :) integer :: i, j y = reshape( [ ((i+j/100.0 , i = 1, n), j=1, n) ], [ n, n ]) z = reshape([1.0], [1, 1]) write(*, *) "z: size ", size(z), " shape ", shape(z) write(*, *) "y: size ", size(y), " shape ", shape(y) write(*, *) DO i = 1, size(y,1) WRITE(*, '(19F10.2)') (y(i, j), j=1, size(y,2)) ENDDO write(*, *) write (*, *) "trying y = matmul(z, y) " write(*, *) y = matmul(z, y) DO i = 1, size(y,1) WRITE(*, '(19F10.2)') (y(i, j), j=1, size(y,2)) ENDDO write(*, *) end
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Wonderful ! Thanks.
GM

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