<?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 Re: Wrong Answer from cblas_dgemm and dgemv when matrix not squ in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Wrong-Answer-from-cblas-dgemm-and-dgemv-when-matrix-not-square/m-p/902243#M11342</link>
    <description>&lt;P&gt;To the greatest extent that I can do I think I've proved (to myself atleast) that the A matrix, being loaded into the cblas_dgemm and cblass_dgemv routines must be square in order for the result to be correct?&lt;/P&gt;
&lt;P&gt;Can anyone verify this for me?&lt;/P&gt;
&lt;P&gt;Seems like something that belongs in the documentation.&lt;/P&gt;</description>
    <pubDate>Wed, 08 Nov 2006 03:16:23 GMT</pubDate>
    <dc:creator>bcarlson</dc:creator>
    <dc:date>2006-11-08T03:16:23Z</dc:date>
    <item>
      <title>Wrong Answer from cblas_dgemm and dgemv when matrix not square</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Wrong-Answer-from-cblas-dgemm-and-dgemv-when-matrix-not-square/m-p/902242#M11341</link>
      <description>Hello, I'm new to using the MKL, and I'm getting incorrect answers when my "a" matrix isn't square. I'm running the MKL under Fedora Core 5 with the latest kernel update.&lt;BR /&gt;&lt;BR /&gt;I'm using the following matrices and vectors.&lt;BR /&gt;&lt;BR /&gt;a = [ 1 2 ]   b = [ 11 12 13 ]&lt;BR /&gt; [ 3 4 ]   [ 14 15 16 ]&lt;BR /&gt; [ 5 6 ] &lt;BR /&gt;&lt;BR /&gt;d = [ 2 ]&lt;BR /&gt; [ 4 ]&lt;BR /&gt; &lt;BR /&gt;for a*b using&lt;BR /&gt;cblas_dgemm(order, transa, transb, m, n, k, alpha, (double *) &amp;amp;a[0][0], lda, (double *) &amp;amp;b[0][0], ldb, beta, (double *) &amp;amp;c[0][0], ldc) &lt;BR /&gt;&lt;BR /&gt;with&lt;BR /&gt;&lt;BR /&gt; m = 3 ;&lt;BR /&gt; n = 3 ;&lt;BR /&gt; k = 2 ;&lt;BR /&gt; alpha = 1.0 ;&lt;BR /&gt; lda = 3 ;&lt;BR /&gt; ldb = 2 ;&lt;BR /&gt; ldc = 3 ;&lt;BR /&gt; beta = 1.0 ;&lt;BR /&gt;&lt;BR /&gt; CBLAS_ORDER order = CblasRowMajor ;&lt;BR /&gt;
 CBLAS_TRANSPOSE transa = CblasNoTrans ;&lt;BR /&gt;
 CBLAS_TRANSPOSE transb = CblasNoTrans ;&lt;BR /&gt;
&lt;BR /&gt;Results in a Segmentation Fault.&lt;BR /&gt;&lt;BR /&gt;When I do the matrix-vector multiplication a*d&lt;BR /&gt;with the following parameters &lt;BR /&gt;&lt;BR /&gt; m = 3 ;&lt;BR /&gt; n = 2 ;&lt;BR /&gt; alpha = 1.0 ;&lt;BR /&gt; lda = 3 ;&lt;BR /&gt; beta = 1.0 ;&lt;BR /&gt;incx = incy = 1.0 ;&lt;BR /&gt;&lt;BR /&gt;i get..&lt;BR /&gt;&lt;BR /&gt;e = [ 10.000000 ] when it should be e = [ 10.0 ]&lt;BR /&gt; [ 28.000000 ] [ 22.0 ]&lt;BR /&gt; [ 132.000000 ] [ 34. 0 ]&lt;BR /&gt;&lt;BR /&gt;I've attached my makefile and code (matmult.CPP) below.&lt;BR /&gt;&lt;BR /&gt;Thank you for any help you can provide. &lt;BR /&gt;&lt;BR /&gt;Brian&lt;BR /&gt;&lt;BR /&gt;----- MAKEFILE --------------&lt;BR /&gt;&lt;BR /&gt;OBJECTS = matmult.CPP&lt;BR /&gt;&lt;BR /&gt;MKL_DIR = /opt/intel/mkl/8.1.1/lib/32/&lt;BR /&gt;&lt;BR /&gt;HEADERS = &lt;BR /&gt;&lt;BR /&gt;matmult: $(OBJECTS)&lt;BR /&gt; g++ $(OBJECTS) -L$(MKL_DIR) -lguide -lmkl -lmkl_lapack -lmkl_ia32 -o matmult -lm&lt;BR /&gt;&lt;BR /&gt;matmult.o: $(HEADERS) matmult.CPP&lt;BR /&gt; g++ -c matmult.CPP &lt;BR /&gt;&lt;BR /&gt;----- CODE (matmult.CPP) ------------&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;#include &lt;MATH.H&gt;&lt;BR /&gt;#include "/opt/intel/mkl/8.1.1/include/mkl.h"&lt;BR /&gt;&lt;BR /&gt;#define A_ROWS 3&lt;BR /&gt;#define A_COLS 2&lt;BR /&gt;#define B_ROWS 2&lt;BR /&gt;#define B_COLS 3&lt;BR /&gt;#define C_ROWS 3&lt;BR /&gt;#define C_COLS 3&lt;BR /&gt;#define D_ROWS 2&lt;BR /&gt;#define E_ROWS 3&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;int main ()&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt; int i,j,counter ;&lt;BR /&gt; int m, n, k ;&lt;BR /&gt;&lt;BR /&gt; int a_rows = A_ROWS ;&lt;BR /&gt; int a_cols = A_COLS ;&lt;BR /&gt; int b_rows = B_ROWS ;&lt;BR /&gt; int b_cols = B_COLS ;&lt;BR /&gt; int c_rows = C_ROWS ;&lt;BR /&gt; int c_cols = C_COLS ;&lt;BR /&gt; int d_rows = D_ROWS ;&lt;BR /&gt; int e_rows = E_ROWS ;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; double alpha, beta ;&lt;BR /&gt; int lda, ldb, ldc ;&lt;BR /&gt;&lt;BR /&gt; double a[A_ROWS][A_COLS], b[B_ROWS][B_COLS], c[A_ROWS][B_COLS] ;&lt;BR /&gt; double d[A_COLS], e[A_ROWS] ;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; CBLAS_ORDER order = CblasRowMajor ;&lt;BR /&gt;// CBLAS_ORDER order = CblasColMajor ;&lt;BR /&gt; CBLAS_T
RANSPOSE transa = CblasNoTrans ;&lt;BR /&gt; CBLAS_TRANSPOSE transb = CblasNoTrans ;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; for ( i = 0 ; i &amp;lt; a_rows ; i++ )&lt;BR /&gt; {&lt;BR /&gt; for ( j = 0 ; j &amp;lt; a_cols ; j++ )&lt;BR /&gt; {&lt;BR /&gt; counter++ ;&lt;BR /&gt; a&lt;I&gt;&lt;J&gt; = counter ;&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt; for ( i = 0 ; i &amp;lt; b_rows ; i++ )&lt;BR /&gt; {&lt;BR /&gt; for ( j = 0 ; j &amp;lt; b_cols ; j++ )&lt;BR /&gt; {&lt;BR /&gt; counter++ ;&lt;BR /&gt; b&lt;I&gt;&lt;J&gt; = counter ; &lt;BR /&gt; }&lt;BR /&gt; } &lt;BR /&gt;&lt;BR /&gt; for ( i = 0 ; i &amp;lt; c_rows ; i++ )&lt;BR /&gt; for ( j = 0 ; j &amp;lt; c_cols ; j++ )&lt;BR /&gt; c&lt;I&gt;&lt;J&gt; = 0.0 ; &lt;BR /&gt;&lt;BR /&gt; counter = 0 ;&lt;BR /&gt; for ( i = 0 ; i &amp;lt; d_rows ; i++ )&lt;BR /&gt; {&lt;BR /&gt; counter++ ;&lt;BR /&gt; counter++ ;&lt;BR /&gt; d&lt;I&gt; = counter ;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt; for ( i = 0 ; i &amp;lt; e_rows ; i++ )&lt;BR /&gt; e&lt;I&gt; = 0.0 ;&lt;BR /&gt;&lt;BR /&gt; printf("
a = 
") ;&lt;BR /&gt; for ( i = 0 ; i &amp;lt; a_rows ; i++ )&lt;BR /&gt; {&lt;BR /&gt; for ( j = 0 ; j &amp;lt; a_cols ; j++ )&lt;BR /&gt; {&lt;BR /&gt; printf(" %lf ",a&lt;I&gt;&lt;J&gt;) ;&lt;BR /&gt; }&lt;BR /&gt; printf("
") ;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt; printf("
b = 
") ;&lt;BR /&gt; for ( i = 0 ; i &amp;lt; b_rows ; i++ )&lt;BR /&gt; {&lt;BR /&gt; for ( j = 0 ; j &amp;lt; b_cols ; j++ )&lt;BR /&gt; {&lt;BR /&gt; printf(" %lf ",b&lt;I&gt;&lt;J&gt;) ;&lt;BR /&gt; }&lt;BR /&gt; printf("
") ;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt; printf("
d = 
") ;&lt;BR /&gt; for ( i = 0 ; i &amp;lt; a_cols ; i++ )&lt;BR /&gt; {&lt;BR /&gt; printf(" %lf
 ",d&lt;I&gt;) ;&lt;BR /&gt; }&lt;BR /&gt; printf("
") ;&lt;BR /&gt;&lt;BR /&gt; m = a_rows ;&lt;BR /&gt; n = b_cols ;&lt;BR /&gt; k = a_cols ;&lt;BR /&gt; alpha = 1.0 ;&lt;BR /&gt; lda = m ;&lt;BR /&gt; ldb = k ;&lt;BR /&gt; ldc = m ;&lt;BR /&gt; beta = 1.0 ;&lt;BR /&gt;&lt;BR /&gt;// CALLING matrix-matrix multiplication function (cblass_dgemm)&lt;BR /&gt; cblas_dgemm(order, transa, transa, m, n, k, alpha, (double *) &amp;amp;a[0][0], lda, (double *) &amp;amp;b[0][0], ldb, beta,&lt;BR /&gt; (double *) &amp;amp;c[0][0], ldc) ;&lt;BR /&gt;&lt;BR /&gt; m = a_rows ;&lt;BR /&gt; n = a_cols ;&lt;BR /&gt; alpha = 1.0 ;&lt;BR /&gt; lda = m ;&lt;BR /&gt; beta = 1.0 ;&lt;BR /&gt;&lt;BR /&gt;// CALLING matrix-vector multiplication function (cblass_dgemv)&lt;BR /&gt; cblas_dgemv(order, transa, m, n, alpha, (double *) &amp;amp;a[0][0], lda, &amp;amp;d[0], 1, beta, &amp;amp;e[0], 1) ;&lt;BR /&gt;&lt;BR /&gt; printf("
c = 
") ;&lt;BR /&gt; for ( i = 0 ; i &amp;lt; a_rows ; i++ )&lt;BR /&gt; {&lt;BR /&gt; for ( j = 0 ; j &amp;lt; b_cols ; j++ )&lt;BR /&gt; {&lt;BR /&gt; printf(" %lf ",c&lt;I&gt;&lt;J&gt;) ;&lt;BR /&gt; }&lt;BR /&gt; printf("
") ;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt; printf("
e = 
") ;&lt;BR /&gt; for ( i = 0 ; i &amp;lt; a_rows ; i++ )&lt;BR /&gt; {&lt;BR /&gt; printf(" %lf
 ",e&lt;I&gt;) ;&lt;BR /&gt; }&lt;BR /&gt; printf("
") ;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; exit(0) ;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/MATH.H&gt;&lt;/STDLIB.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Sat, 04 Nov 2006 04:07:52 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Wrong-Answer-from-cblas-dgemm-and-dgemv-when-matrix-not-square/m-p/902242#M11341</guid>
      <dc:creator>bcarlson</dc:creator>
      <dc:date>2006-11-04T04:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong Answer from cblas_dgemm and dgemv when matrix not squ</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Wrong-Answer-from-cblas-dgemm-and-dgemv-when-matrix-not-square/m-p/902243#M11342</link>
      <description>&lt;P&gt;To the greatest extent that I can do I think I've proved (to myself atleast) that the A matrix, being loaded into the cblas_dgemm and cblass_dgemv routines must be square in order for the result to be correct?&lt;/P&gt;
&lt;P&gt;Can anyone verify this for me?&lt;/P&gt;
&lt;P&gt;Seems like something that belongs in the documentation.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2006 03:16:23 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Wrong-Answer-from-cblas-dgemm-and-dgemv-when-matrix-not-square/m-p/902243#M11342</guid>
      <dc:creator>bcarlson</dc:creator>
      <dc:date>2006-11-08T03:16:23Z</dc:date>
    </item>
  </channel>
</rss>

