<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic about matmul() in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/about-matmul/m-p/892926#M78723</link>
    <description>&lt;P&gt;MKL supports BLAS functions ?GEMM for rank 2 by rank 2 multiplication (including OpenMP parallelization and much additional optimization for Xeon), and ?GEMV for rank 2 by rank 1 multiplication.&lt;/P&gt;
&lt;P&gt;For rank 1 by rank 1 multiplication, DOT_PRODUCT usually is optimized better by ifort than what is possible with BLAS ?DOT. Also, for problems too small to benefit from threading, MATMUL, compiled at -O3, is often better than BLAS ?GEMV or ?GEMM.&lt;/P&gt;
&lt;P&gt;It may be possible to write a Fortran generic interface replacement for MATMUL which could recognize various BLAS cases and select among BLAS95 GEMM, GEMV, and DOT. Not having seen it done, I suppose there are more difficulties than meet the eye.&lt;/P&gt;</description>
    <pubDate>Mon, 15 Feb 2010 16:18:49 GMT</pubDate>
    <dc:creator>TimP</dc:creator>
    <dc:date>2010-02-15T16:18:49Z</dc:date>
    <item>
      <title>about matmul()</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/about-matmul/m-p/892922#M78719</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;My question is about the function matmul(). As we know, matmul() is used to multiply two matrixs, A, B. However, I have the question that how to do when I want to multiply one row of A and one column of B? For example, I define three matrixs, A, B and C&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;real, allocatable:: A(:,:), B(:,:),C(:,:)&lt;/P&gt;
&lt;P&gt;allocate(A(5,3),B(3,4),C(1,1))&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Now, if I run&lt;/P&gt;
&lt;P&gt;C=matmul(A(2,:),B(:,2))&lt;/P&gt;
&lt;P&gt;I get the error message,&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;test1.f90(40): error #6366: The shapes of the array expressions do not conform. &lt;C&gt;&lt;BR /&gt;C=matmul(A(2,:),B(:,2))&lt;/C&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;However, if I use&lt;/P&gt;
&lt;P&gt;C=matmul(reshape(A(2,:),(/1,3/)),reshape(B(:,2),(/3,1/)))&lt;/P&gt;
&lt;P&gt;There is no problem. Moreover, I find if I have two matrix, A(a,b) and B(c,d), I must reshape the sub-matrix when either a or b or c or d=1. This is very boring (I must use reshape() very time). Why cannot the compiler automatically detect the shape of sub-matrix in matmul()? In matlab, it is very easy, and I just use C=A(2,:)*B(:,2).&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Thanks very much.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Feb 2010 21:41:39 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/about-matmul/m-p/892922#M78719</guid>
      <dc:creator>IDZ_A_Intel</dc:creator>
      <dc:date>2010-02-14T21:41:39Z</dc:date>
    </item>
    <item>
      <title>about matmul()</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/about-matmul/m-p/892923#M78720</link>
      <description>&lt;P&gt;This is simply the way the Fortran standard defines the intrinsic MATMUL, which is not really a general purpose matrix multiply. A(2,:) ad B(:,2) are rank 1 arrays, and the standard says that if either of the arguments are rank 1, the other must be rank 2. This is why you have to use reshape, and you have to reshape both to rank 2 because otherwise the result will be rank 1 and won't conform to C.&lt;/P&gt;
&lt;P&gt;You might want to look at the matrix multiply routines in Intel Math Kernel Library to see if they better meet your needs (though for small arrays they will be slower than using MATMUL.)&lt;/P&gt;</description>
      <pubDate>Sun, 14 Feb 2010 22:00:47 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/about-matmul/m-p/892923#M78720</guid>
      <dc:creator>IDZ_A_Intel</dc:creator>
      <dc:date>2010-02-14T22:00:47Z</dc:date>
    </item>
    <item>
      <title>about matmul()</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/about-matmul/m-p/892924#M78721</link>
      <description>&lt;P&gt;Hi Steve,&lt;/P&gt;
&lt;P&gt;Could I ask what matrix multiply routines the MKL have provided? Do you mean BLAS and LAPACK routines? Thanks very much.&lt;/P&gt;
&lt;P&gt;Ying&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2010 09:40:16 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/about-matmul/m-p/892924#M78721</guid>
      <dc:creator>IDZ_A_Intel</dc:creator>
      <dc:date>2010-02-15T09:40:16Z</dc:date>
    </item>
    <item>
      <title>about matmul()</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/about-matmul/m-p/892925#M78722</link>
      <description>I was thinking of GEMV in MKL, but I'll admit that this is a topic I'm not intimately familiar with. I'm sure there are others here, such as tim18, who can probably offer more cogent advice.</description>
      <pubDate>Mon, 15 Feb 2010 14:42:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/about-matmul/m-p/892925#M78722</guid>
      <dc:creator>IDZ_A_Intel</dc:creator>
      <dc:date>2010-02-15T14:42:59Z</dc:date>
    </item>
    <item>
      <title>about matmul()</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/about-matmul/m-p/892926#M78723</link>
      <description>&lt;P&gt;MKL supports BLAS functions ?GEMM for rank 2 by rank 2 multiplication (including OpenMP parallelization and much additional optimization for Xeon), and ?GEMV for rank 2 by rank 1 multiplication.&lt;/P&gt;
&lt;P&gt;For rank 1 by rank 1 multiplication, DOT_PRODUCT usually is optimized better by ifort than what is possible with BLAS ?DOT. Also, for problems too small to benefit from threading, MATMUL, compiled at -O3, is often better than BLAS ?GEMV or ?GEMM.&lt;/P&gt;
&lt;P&gt;It may be possible to write a Fortran generic interface replacement for MATMUL which could recognize various BLAS cases and select among BLAS95 GEMM, GEMV, and DOT. Not having seen it done, I suppose there are more difficulties than meet the eye.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2010 16:18:49 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/about-matmul/m-p/892926#M78723</guid>
      <dc:creator>TimP</dc:creator>
      <dc:date>2010-02-15T16:18:49Z</dc:date>
    </item>
    <item>
      <title>about matmul()</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/about-matmul/m-p/892927#M78724</link>
      <description>&lt;P&gt;Hi tim18,&lt;/P&gt;
&lt;P&gt;Yes, that is what I want if there could be a generic interface replacement for MATMUL which could recognize various BLAS cases. That will be very useful, because when I see the user manual for BLAS functions, I find the functions need many many parameters. How can I remember all the functions with all the parameters? Besides, there has not been a fortran IDE to remind me. It should be easier for C++, because VS2008+visual Assistant is very comfortable.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Anyway, thanks for your very helpful information. I am using -O3, which is very fast to run the code. And I will try openMP to make use of the rest of cores in my PC.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Ying&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2010 16:56:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/about-matmul/m-p/892927#M78724</guid>
      <dc:creator>IDZ_A_Intel</dc:creator>
      <dc:date>2010-02-15T16:56:44Z</dc:date>
    </item>
    <item>
      <title>about matmul()</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/about-matmul/m-p/892928#M78725</link>
      <description>&lt;DIV id="tiny_quote"&gt;
&lt;DIV style="margin-left: 2px; margin-right: 2px;"&gt;Quoting &lt;A rel="/en-us/services/profile/quick_profile.php?is_paid=&amp;amp;user_id=336209" class="basic" href="https://community.intel.com/en-us/profile/336209/"&gt;Steve Lionel (Intel)&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="border: 1px inset; padding: 5px; background-color: #e5e5e5; margin-left: 2px; margin-right: 2px;"&gt;&lt;I&gt;
&lt;P&gt;This is simply the way the Fortran standard defines the intrinsic MATMUL, which is not really a general purpose matrix multiply. A(2,:) ad B(:,2) are rank 1 arrays, and the standard says that if either of the arguments are rank 1, the other must be rank 2. This is why you have to use reshape, and you have to reshape both to rank 2 because otherwise the result will be rank 1 and won't conform to C.&lt;/P&gt;
&lt;P&gt;You might want to look at the matrix multiply routines in Intel Math Kernel Library to see if they better meet your needs (though for small arrays they will be slower than using MATMUL.)&lt;/P&gt;
&lt;/I&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;But you missed a much simpler way to make a rank-2 column- (or row-) matrix than RESHAPE; namely, if X(:) is an array, then X(1) is a scalar, but X(1:1) is still an array (and, for that matter, X(1:0) is also a zero-sized array). Thus:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;PRE&gt;[fortran]real, allocatable:: A(:,:), B(:,:),C(:,:)&lt;BR /&gt;&lt;BR /&gt;allocate(A(5,3),B(3,4),C(1,1))&lt;BR /&gt;&lt;BR /&gt;C=matmul(A(2:2,:),B(:,2:2))&lt;BR /&gt;[/fortran]&lt;/PRE&gt;
works as expected.
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Feb 2010 08:25:39 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/about-matmul/m-p/892928#M78725</guid>
      <dc:creator>Jugoslav_Dujic</dc:creator>
      <dc:date>2010-02-16T08:25:39Z</dc:date>
    </item>
    <item>
      <title>about matmul()</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/about-matmul/m-p/892929#M78726</link>
      <description>Yes, it is a very good idea. Very simple but workable. Thanks very much.</description>
      <pubDate>Tue, 16 Feb 2010 11:35:37 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/about-matmul/m-p/892929#M78726</guid>
      <dc:creator>IDZ_A_Intel</dc:creator>
      <dc:date>2010-02-16T11:35:37Z</dc:date>
    </item>
  </channel>
</rss>

