Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

"matmul" function problem

alsoran
Beginner
1,144 Views
[sectionbodytext]the last line  "mtpl(b,a)"  means matrix b * matrix a[/sectionbodytext]
[sectionbodytext]absolutely,it is illegal b is 3*2,and a is 1*3.  my question is [/sectionbodytext]
[sectionbodytext]why can it be Compiled Successfully[/sectionbodytext]

here is my simplified codes:

[fortran]module mat
contains
    function mtpl(x,y)
    implicit none
        real:: x(:,:),y(:,:)
        real,allocatable:: mtpl(:,:)
        integer:: row_x,col_x,row_y,col_y
        !-----------------------------------
        row_x = ubound(x,1)
        col_x = ubound(x,2)
        row_y = ubound(y,1)
        col_y = ubound(y,2)       !--------(1)------
        allocate(mtpl(row_x,col_y))
        mtpl = matmul(x,y)
    end function mtpl
end module mat
!----------------------------------------------------
program problem
use mat
implicit none
    real:: a(1,3)=(/1,2,3/)
    real:: b(3,2)=reshape((/1,2,3,4,5,6/),(/3,2/))
    write(*,*) mtpl(b,a)          !--------(2)-------
end program problem[/fortran]
0 Kudos
2 Replies
mecej4
Honored Contributor III
1,144 Views
There are many things that are mathematical nonsense (or "illegal", as you say) that can be programmed in Fortran (or C, PL/I, etc.). The Fortran compiler does not know more than rudimentary mathematics. In particular, it does not know that mtpl is a matrix multiplication routine, that the two arguments have to conform, what "conform" means, etc. It is up to you to program checks for conformability, if you desire.

More generally, it is possible to write a syntactically correct Fortran program that happens to implement an incorrect calculation or even a faulty algorithm. That is why one has test problems and other checks to examine whether the program is performing correctly.
0 Kudos
alsoran
Beginner
1,144 Views
Thank you for your answer!
I know there's something wrong in my codes, and it exists some differences between compiler and me in understanding the codes. However, the Detailsof the problem is what I 'm mostconcerned about, if you want , please give me someProposal
0 Kudos
Reply