<?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: matrix vector Product/iterative solver in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/matrix-vector-Product-iterative-solver/m-p/743127#M1204</link>
    <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="width: 100%; margin-top: 5px;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Can please somebody help me with the above code problem? Let me know if the question or the pasted code is not clear&lt;/DIV&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Thanks&lt;/DIV&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;&lt;BR /&gt;&lt;/DIV&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/441500"&gt;hashirkk&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt;Hello all,&lt;BR /&gt;I am copying two different codes below for your analysis and help. The first code takes a large Sparse matrix and apply the iterative solution algorithm on that. The second code below, takes the same sparse matrix, apply a simple storage mechanism onto that and convert it into Dense matrix (containing only non-zero values ) and then apply the iterative solver on that matrix to converge. &lt;BR /&gt;&lt;BR /&gt;Problem: If I set the size of the matrix size small i.e. less than 2kx2k, the results of both the code are approximatel same but for large matrices &amp;gt; 2k, the results of both the code donot match at all.&lt;BR /&gt;Note: matrix is a penta-diagonal matrix. &lt;BR /&gt;&lt;BR /&gt;I would really appreciate if somebody can guide me what mistake Am I making or is there any problem in the second code Algorithm.&lt;BR /&gt;&lt;BR /&gt;Code #1:&lt;BR /&gt;&lt;BR /&gt;Generation of a penta-diagonal sparse matrix (A).&lt;BR /&gt;&lt;BR /&gt;for (i = 0; i &amp;lt; ROWS; i++) {&lt;BR /&gt;c&lt;I&gt; = 0.0;&lt;BR /&gt;for (j = 0; j &amp;lt; COLS; j++)&lt;BR /&gt;{&lt;BR /&gt;if (j==i)&lt;BR /&gt;{&lt;BR /&gt;if (i==0 &amp;amp;&amp;amp; j==0)&lt;BR /&gt;{&lt;BR /&gt;matrix&lt;I&gt;j+1 = (float) 1.0;&lt;BR /&gt;matrix&lt;I&gt;&lt;J&gt; = (float) 2.0;&lt;BR /&gt;matrix&lt;I&gt;j+GRID_SIZE = (float) 3.0;&lt;BR /&gt;}&lt;BR /&gt;if (i == ROWS-1)&lt;BR /&gt;{&lt;BR /&gt;matrix&lt;I&gt;j-1 = (float) 1.0;&lt;BR /&gt;matrix&lt;I&gt;&lt;J&gt; = (float) 4.0;&lt;BR /&gt;matrix&lt;I&gt;j-GRID_SIZE = (float) 3.0;&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;if (i % GRID_SIZE == 0 )&lt;BR /&gt;matrix&lt;I&gt;j+1 = (float) 1.0;&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;matrix&lt;I&gt;j-1 = (float) 1.0;&lt;BR /&gt;if ((i+1)%GRID_SIZE !=0)&lt;BR /&gt;matrix&lt;I&gt;j+1 = (float) 1.0;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;matrix&lt;I&gt;&lt;J&gt; = (float) 2.0;&lt;BR /&gt;if ((j+GRID_SIZE)&amp;lt;= COLS)&lt;BR /&gt;matrix&lt;I&gt;j+GRID_SIZE = (float) 3.0;&lt;BR /&gt;if ((j-GRID_SIZE)&amp;gt;= 0)&lt;BR /&gt;matrix&lt;I&gt;j-GRID_SIZE = (float) 3.0;&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;} // j == i&lt;BR /&gt;&lt;BR /&gt;} // j&lt;BR /&gt;} //i&lt;BR /&gt;&lt;BR /&gt;// Generation of dummy constant vector (b)&lt;BR /&gt;b[0] = 3; b[1]= 1; b[2] = 1;b[3] = 1; b[4]= 1; b[5] = 1;b[6] = 1; b[7]= 1; b[8] = 1;&lt;BR /&gt;&lt;BR /&gt;for (i=9;i&lt;ROWS&gt;&lt;/ROWS&gt;b&lt;I&gt; = b[8];&lt;BR /&gt;&lt;BR /&gt;// Start of Iterative Solver&lt;BR /&gt;&lt;BR /&gt;for (it = 0; it &amp;lt; ROWS; it++) {&lt;BR /&gt;&lt;BR /&gt;......&lt;BR /&gt;matrix_vector_product (matrix, x, g,ROWS);&lt;BR /&gt;&lt;BR /&gt;......&lt;BR /&gt;&lt;BR /&gt;matrix_vector_product (matrix, d, tmpvec,ROWS);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;} // end of loop&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;//Matrix Vector product Code.&lt;BR /&gt;void matrix_vector_product (float **a, float *b, float *c,int ROWS)&lt;BR /&gt;{&lt;BR /&gt;int i, j;&lt;BR /&gt;&lt;BR /&gt;int N = ROWS;&lt;BR /&gt;float tmp;&lt;BR /&gt;for (i = 0; i &amp;lt; N; i++) {&lt;BR /&gt;tmp = 0.0;&lt;BR /&gt;for (j = 0; j &amp;lt; N; j++)&lt;BR /&gt;tmp += a&lt;I&gt;&lt;J&gt; * b&lt;J&gt;;&lt;BR /&gt;c&lt;I&gt; = tmp;&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Code #2: Converting sparse matrix to Dense matrix for effecient Data storage&lt;BR /&gt;&lt;BR /&gt;Generation of a penta-diagonal sparse matrix (A).&lt;BR /&gt;&lt;BR /&gt;for (i = 0; i &amp;lt; ROWS; i++) {&lt;BR /&gt;c&lt;I&gt; = 0.0;&lt;BR /&gt;for (j = 0; j &amp;lt; COLS; j++)&lt;BR /&gt;{&lt;BR /&gt;if (j==i)&lt;BR /&gt;{&lt;BR /&gt;if (i==0 &amp;amp;&amp;amp; j==0)&lt;BR /&gt;{&lt;BR /&gt;matrix&lt;I&gt;j+1 = (float) 1.0;&lt;BR /&gt;matrix&lt;I&gt;&lt;J&gt; = (float) 2.0;&lt;BR /&gt;matrix&lt;I&gt;j+GRID_SIZE = (float) 3.0;&lt;BR /&gt;}&lt;BR /&gt;if (i == ROWS-1)&lt;BR /&gt;{&lt;BR /&gt;matrix&lt;I&gt;j-1 = (float) 1.0;&lt;BR /&gt;matrix&lt;I&gt;&lt;J&gt; = (float) 4.0;&lt;BR /&gt;matrix&lt;I&gt;j-GRID_SIZE = (float) 3.0;&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;if (i % GRID_SIZE == 0 )&lt;BR /&gt;matrix&lt;I&gt;j+1 = (float) 1.0;&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;matrix&lt;I&gt;j-1 = (float) 1.0;&lt;BR /&gt;if ((i+1)%GRID_SIZE !=0)&lt;BR /&gt;matrix&lt;I&gt;j+1 = (float) 1.0;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;matrix&lt;I&gt;&lt;J&gt; = (float) 2.0;&lt;BR /&gt;if ((j+GRID_SIZE)&amp;lt;= COLS)&lt;BR /&gt;matrix&lt;I&gt;j+GRID_SIZE = (float) 3.0;&lt;BR /&gt;if ((j-GRID_SIZE)&amp;gt;= 0)&lt;BR /&gt;matrix&lt;I&gt;j-GRID_SIZE = (float) 3.0;&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;} // j == i&lt;BR /&gt;&lt;BR /&gt;} // j&lt;BR /&gt;} //i&lt;BR /&gt;&lt;BR /&gt;// Additional steps to conver the sparse matrix to dense matrix ROWS*DIAGONALS+1 and storing of indices in seperate matrix&lt;BR /&gt;for (i = 0; i &amp;lt; ROWS; i++) {&lt;BR /&gt;k = 0;&lt;BR /&gt;for (j = 0; j &amp;lt; COLS; j++)&lt;BR /&gt;{&lt;BR /&gt;if (matrix&lt;I&gt;&lt;J&gt; != 0.0)&lt;BR /&gt;{&lt;BR /&gt;matrix_min&lt;I&gt;&lt;K&gt; = matrix&lt;I&gt;&lt;J&gt;;&lt;BR /&gt;&lt;BR /&gt;// changes made for the penta_diagonal matrix.The index array&lt;BR /&gt;// will contain the value of the vector j to which the matrix&lt;BR /&gt;// needs to be multiplied.&lt;BR /&gt;index&lt;I&gt;&lt;K&gt; = j;&lt;BR /&gt;k++;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;// Generation of dummy constant vector (b)&lt;BR /&gt;b[0] = 3; b[1]= 1; b[2] = 1;b[3] = 1; b[4]= 1; b[5] = 1;b[6] = 1; b[7]= 1; b[8] = 1;&lt;BR /&gt;&lt;BR /&gt;for (i=9;i&lt;ROWS&gt;&lt;/ROWS&gt;b&lt;I&gt; = b[8];&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;// Start of Iterative Solver&lt;BR /&gt;&lt;BR /&gt;for (it = 0; it &amp;lt; ROWS; it++) {&lt;BR /&gt;&lt;BR /&gt;......&lt;BR /&gt;min_matrix_vector_product (matrix_min,index, x, g,ROWS);&lt;BR /&gt;......&lt;BR /&gt;&lt;BR /&gt;min_matrix_vector_product (matrix_min, index,d, tmpvec,ROWS);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;} // end of loop&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;//Matrix Vector product Code (modified for Dense matrix.&lt;BR /&gt;&lt;BR /&gt;void min_matrix_vector_product (float **a, int **d,float *b, float *c,int ROWS)&lt;BR /&gt;{&lt;BR /&gt;int i, j;&lt;BR /&gt;int N = ROWS;&lt;BR /&gt;float tmp;&lt;BR /&gt;&lt;BR /&gt;for (i = 0; i &amp;lt; N; i++) {&lt;BR /&gt;tmp = 0.0;&lt;BR /&gt;for (j = 0; j &amp;lt; DIAGON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t;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;BR /&gt;</description>
    <pubDate>Fri, 18 Sep 2009 11:08:49 GMT</pubDate>
    <dc:creator>hashirkk</dc:creator>
    <dc:date>2009-09-18T11:08:49Z</dc:date>
    <item>
      <title>matrix vector Product/iterative solver</title>
      <link>https://community.intel.com/t5/Software-Archive/matrix-vector-Product-iterative-solver/m-p/743126#M1203</link>
      <description>Hello all,&lt;BR /&gt;I am copying two different codes below for your analysis and help. The first code takes a large Sparse matrix and apply the iterative solution algorithm on that. The second code below, takes the same sparse matrix, apply a simple storage mechanism onto that and convert it into Dense matrix (containing only non-zero values ) and then apply the iterative solver on that matrix to converge. &lt;BR /&gt;&lt;BR /&gt;Problem: If I set the size of the matrix size small i.e. less than 2kx2k, the results of both the code are approximatel same but for large matrices &amp;gt; 2k, the results of both the code donot match at all.&lt;BR /&gt;Note: matrix is a penta-diagonal matrix. &lt;BR /&gt;&lt;BR /&gt;I would really appreciate if somebody can guide me what mistake Am I making or is there any problem in the second code Algorithm.&lt;BR /&gt;&lt;BR /&gt;Code #1:&lt;BR /&gt;&lt;BR /&gt;Generation of a penta-diagonal sparse matrix (A).&lt;BR /&gt;&lt;BR /&gt;for (i = 0; i &amp;lt; ROWS; i++) {&lt;BR /&gt;c&lt;I&gt; = 0.0;&lt;BR /&gt;for (j = 0; j &amp;lt; COLS; j++)&lt;BR /&gt;{&lt;BR /&gt;if (j==i)&lt;BR /&gt;{&lt;BR /&gt;if (i==0 &amp;amp;&amp;amp; j==0)&lt;BR /&gt;{&lt;BR /&gt;matrix&lt;I&gt;j+1 = (float) 1.0;&lt;BR /&gt;matrix&lt;I&gt;&lt;J&gt; = (float) 2.0;&lt;BR /&gt;matrix&lt;I&gt;j+GRID_SIZE = (float) 3.0;&lt;BR /&gt;}&lt;BR /&gt;if (i == ROWS-1)&lt;BR /&gt;{&lt;BR /&gt;matrix&lt;I&gt;j-1 = (float) 1.0;&lt;BR /&gt;matrix&lt;I&gt;&lt;J&gt; = (float) 4.0;&lt;BR /&gt;matrix&lt;I&gt;j-GRID_SIZE = (float) 3.0;&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;if (i % GRID_SIZE == 0 )&lt;BR /&gt;matrix&lt;I&gt;j+1 = (float) 1.0;&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;matrix&lt;I&gt;j-1 = (float) 1.0;&lt;BR /&gt;if ((i+1)%GRID_SIZE !=0)&lt;BR /&gt;matrix&lt;I&gt;j+1 = (float) 1.0;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;matrix&lt;I&gt;&lt;J&gt; = (float) 2.0;&lt;BR /&gt;if ((j+GRID_SIZE)&amp;lt;= COLS)&lt;BR /&gt;matrix&lt;I&gt;j+GRID_SIZE = (float) 3.0;&lt;BR /&gt;if ((j-GRID_SIZE)&amp;gt;= 0)&lt;BR /&gt;matrix&lt;I&gt;j-GRID_SIZE = (float) 3.0;&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;} // j == i&lt;BR /&gt;&lt;BR /&gt;} // j&lt;BR /&gt;} //i&lt;BR /&gt;&lt;BR /&gt;// Generation of dummy constant vector (b)&lt;BR /&gt;b[0] = 3; b[1]= 1; b[2] = 1;b[3] = 1; b[4]= 1; b[5] = 1;b[6] = 1; b[7]= 1; b[8] = 1;&lt;BR /&gt;&lt;BR /&gt;for (i=9;i&lt;ROWS&gt;&lt;/ROWS&gt;b&lt;I&gt; = b[8];&lt;BR /&gt;&lt;BR /&gt;// Start of Iterative Solver&lt;BR /&gt;&lt;BR /&gt;for (it = 0; it &amp;lt; ROWS; it++) {&lt;BR /&gt;&lt;BR /&gt;......&lt;BR /&gt;matrix_vector_product (matrix, x, g,ROWS);&lt;BR /&gt;&lt;BR /&gt;......&lt;BR /&gt;&lt;BR /&gt;matrix_vector_product (matrix, d, tmpvec,ROWS);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;} // end of loop&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;//Matrix Vector product Code.&lt;BR /&gt;void matrix_vector_product (float **a, float *b, float *c,int ROWS)&lt;BR /&gt;{&lt;BR /&gt;int i, j;&lt;BR /&gt;&lt;BR /&gt;int N = ROWS;&lt;BR /&gt;float tmp;&lt;BR /&gt;for (i = 0; i &amp;lt; N; i++) {&lt;BR /&gt;tmp = 0.0;&lt;BR /&gt;for (j = 0; j &amp;lt; N; j++)&lt;BR /&gt;tmp += a&lt;I&gt;&lt;J&gt; * b&lt;J&gt;;&lt;BR /&gt;c&lt;I&gt; = tmp;&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Code #2: Converting sparse matrix to Dense matrix for effecient Data storage&lt;BR /&gt;&lt;BR /&gt;Generation of a penta-diagonal sparse matrix (A).&lt;BR /&gt;&lt;BR /&gt;for (i = 0; i &amp;lt; ROWS; i++) {&lt;BR /&gt;c&lt;I&gt; = 0.0;&lt;BR /&gt;for (j = 0; j &amp;lt; COLS; j++)&lt;BR /&gt;{&lt;BR /&gt;if (j==i)&lt;BR /&gt;{&lt;BR /&gt;if (i==0 &amp;amp;&amp;amp; j==0)&lt;BR /&gt;{&lt;BR /&gt;matrix&lt;I&gt;j+1 = (float) 1.0;&lt;BR /&gt;matrix&lt;I&gt;&lt;J&gt; = (float) 2.0;&lt;BR /&gt;matrix&lt;I&gt;j+GRID_SIZE = (float) 3.0;&lt;BR /&gt;}&lt;BR /&gt;if (i == ROWS-1)&lt;BR /&gt;{&lt;BR /&gt;matrix&lt;I&gt;j-1 = (float) 1.0;&lt;BR /&gt;matrix&lt;I&gt;&lt;J&gt; = (float) 4.0;&lt;BR /&gt;matrix&lt;I&gt;j-GRID_SIZE = (float) 3.0;&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;if (i % GRID_SIZE == 0 )&lt;BR /&gt;matrix&lt;I&gt;j+1 = (float) 1.0;&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;matrix&lt;I&gt;j-1 = (float) 1.0;&lt;BR /&gt;if ((i+1)%GRID_SIZE !=0)&lt;BR /&gt;matrix&lt;I&gt;j+1 = (float) 1.0;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;matrix&lt;I&gt;&lt;J&gt; = (float) 2.0;&lt;BR /&gt;if ((j+GRID_SIZE)&amp;lt;= COLS)&lt;BR /&gt;matrix&lt;I&gt;j+GRID_SIZE = (float) 3.0;&lt;BR /&gt;if ((j-GRID_SIZE)&amp;gt;= 0)&lt;BR /&gt;matrix&lt;I&gt;j-GRID_SIZE = (float) 3.0;&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;} // j == i&lt;BR /&gt;&lt;BR /&gt;} // j&lt;BR /&gt;} //i&lt;BR /&gt;&lt;BR /&gt;// Additional steps to conver the sparse matrix to dense matrix ROWS*DIAGONALS+1 and storing of indices in seperate matrix&lt;BR /&gt;for (i = 0; i &amp;lt; ROWS; i++) {&lt;BR /&gt;k = 0;&lt;BR /&gt;for (j = 0; j &amp;lt; COLS; j++)&lt;BR /&gt;{&lt;BR /&gt;if (matrix&lt;I&gt;&lt;J&gt; != 0.0)&lt;BR /&gt;{&lt;BR /&gt;matrix_min&lt;I&gt;&lt;K&gt; = matrix&lt;I&gt;&lt;J&gt;;&lt;BR /&gt;&lt;BR /&gt;// changes made for the penta_diagonal matrix.The index array&lt;BR /&gt;// will contain the value of the vector j to which the matrix&lt;BR /&gt;// needs to be multiplied.&lt;BR /&gt;index&lt;I&gt;&lt;K&gt; = j;&lt;BR /&gt;k++;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;// Generation of dummy constant vector (b)&lt;BR /&gt;b[0] = 3; b[1]= 1; b[2] = 1;b[3] = 1; b[4]= 1; b[5] = 1;b[6] = 1; b[7]= 1; b[8] = 1;&lt;BR /&gt;&lt;BR /&gt;for (i=9;i&lt;ROWS&gt;&lt;/ROWS&gt;b&lt;I&gt; = b[8];&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;// Start of Iterative Solver&lt;BR /&gt;&lt;BR /&gt;for (it = 0; it &amp;lt; ROWS; it++) {&lt;BR /&gt;&lt;BR /&gt;......&lt;BR /&gt;min_matrix_vector_product (matrix_min,index, x, g,ROWS);&lt;BR /&gt;......&lt;BR /&gt;&lt;BR /&gt;min_matrix_vector_product (matrix_min, index,d, tmpvec,ROWS);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;} // end of loop&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;//Matrix Vector product Code (modified for Dense matrix.&lt;BR /&gt;&lt;BR /&gt;void min_matrix_vector_product (float **a, int **d,float *b, float *c,int ROWS)&lt;BR /&gt;{&lt;BR /&gt;int i, j;&lt;BR /&gt;int N = ROWS;&lt;BR /&gt;float tmp;&lt;BR /&gt;&lt;BR /&gt;for (i = 0; i &amp;lt; N; i++) {&lt;BR /&gt;tmp = 0.0;&lt;BR /&gt;for (j = 0; j &amp;lt; DIAGONALS+1; j++){&lt;BR /&gt;tmp += a&lt;I&gt;&lt;J&gt; * b[d&lt;I&gt;j];&lt;BR /&gt;}&lt;BR /&gt;c&lt;I&gt; = tmp;&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;/I&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/K&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/K&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/J&gt;&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;</description>
      <pubDate>Thu, 10 Sep 2009 06:56:50 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/matrix-vector-Product-iterative-solver/m-p/743126#M1203</guid>
      <dc:creator>hashirkk</dc:creator>
      <dc:date>2009-09-10T06:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: matrix vector Product/iterative solver</title>
      <link>https://community.intel.com/t5/Software-Archive/matrix-vector-Product-iterative-solver/m-p/743127#M1204</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="width: 100%; margin-top: 5px;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Can please somebody help me with the above code problem? Let me know if the question or the pasted code is not clear&lt;/DIV&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Thanks&lt;/DIV&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;&lt;BR /&gt;&lt;/DIV&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/441500"&gt;hashirkk&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt;Hello all,&lt;BR /&gt;I am copying two different codes below for your analysis and help. The first code takes a large Sparse matrix and apply the iterative solution algorithm on that. The second code below, takes the same sparse matrix, apply a simple storage mechanism onto that and convert it into Dense matrix (containing only non-zero values ) and then apply the iterative solver on that matrix to converge. &lt;BR /&gt;&lt;BR /&gt;Problem: If I set the size of the matrix size small i.e. less than 2kx2k, the results of both the code are approximatel same but for large matrices &amp;gt; 2k, the results of both the code donot match at all.&lt;BR /&gt;Note: matrix is a penta-diagonal matrix. &lt;BR /&gt;&lt;BR /&gt;I would really appreciate if somebody can guide me what mistake Am I making or is there any problem in the second code Algorithm.&lt;BR /&gt;&lt;BR /&gt;Code #1:&lt;BR /&gt;&lt;BR /&gt;Generation of a penta-diagonal sparse matrix (A).&lt;BR /&gt;&lt;BR /&gt;for (i = 0; i &amp;lt; ROWS; i++) {&lt;BR /&gt;c&lt;I&gt; = 0.0;&lt;BR /&gt;for (j = 0; j &amp;lt; COLS; j++)&lt;BR /&gt;{&lt;BR /&gt;if (j==i)&lt;BR /&gt;{&lt;BR /&gt;if (i==0 &amp;amp;&amp;amp; j==0)&lt;BR /&gt;{&lt;BR /&gt;matrix&lt;I&gt;j+1 = (float) 1.0;&lt;BR /&gt;matrix&lt;I&gt;&lt;J&gt; = (float) 2.0;&lt;BR /&gt;matrix&lt;I&gt;j+GRID_SIZE = (float) 3.0;&lt;BR /&gt;}&lt;BR /&gt;if (i == ROWS-1)&lt;BR /&gt;{&lt;BR /&gt;matrix&lt;I&gt;j-1 = (float) 1.0;&lt;BR /&gt;matrix&lt;I&gt;&lt;J&gt; = (float) 4.0;&lt;BR /&gt;matrix&lt;I&gt;j-GRID_SIZE = (float) 3.0;&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;if (i % GRID_SIZE == 0 )&lt;BR /&gt;matrix&lt;I&gt;j+1 = (float) 1.0;&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;matrix&lt;I&gt;j-1 = (float) 1.0;&lt;BR /&gt;if ((i+1)%GRID_SIZE !=0)&lt;BR /&gt;matrix&lt;I&gt;j+1 = (float) 1.0;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;matrix&lt;I&gt;&lt;J&gt; = (float) 2.0;&lt;BR /&gt;if ((j+GRID_SIZE)&amp;lt;= COLS)&lt;BR /&gt;matrix&lt;I&gt;j+GRID_SIZE = (float) 3.0;&lt;BR /&gt;if ((j-GRID_SIZE)&amp;gt;= 0)&lt;BR /&gt;matrix&lt;I&gt;j-GRID_SIZE = (float) 3.0;&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;} // j == i&lt;BR /&gt;&lt;BR /&gt;} // j&lt;BR /&gt;} //i&lt;BR /&gt;&lt;BR /&gt;// Generation of dummy constant vector (b)&lt;BR /&gt;b[0] = 3; b[1]= 1; b[2] = 1;b[3] = 1; b[4]= 1; b[5] = 1;b[6] = 1; b[7]= 1; b[8] = 1;&lt;BR /&gt;&lt;BR /&gt;for (i=9;i&lt;ROWS&gt;&lt;/ROWS&gt;b&lt;I&gt; = b[8];&lt;BR /&gt;&lt;BR /&gt;// Start of Iterative Solver&lt;BR /&gt;&lt;BR /&gt;for (it = 0; it &amp;lt; ROWS; it++) {&lt;BR /&gt;&lt;BR /&gt;......&lt;BR /&gt;matrix_vector_product (matrix, x, g,ROWS);&lt;BR /&gt;&lt;BR /&gt;......&lt;BR /&gt;&lt;BR /&gt;matrix_vector_product (matrix, d, tmpvec,ROWS);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;} // end of loop&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;//Matrix Vector product Code.&lt;BR /&gt;void matrix_vector_product (float **a, float *b, float *c,int ROWS)&lt;BR /&gt;{&lt;BR /&gt;int i, j;&lt;BR /&gt;&lt;BR /&gt;int N = ROWS;&lt;BR /&gt;float tmp;&lt;BR /&gt;for (i = 0; i &amp;lt; N; i++) {&lt;BR /&gt;tmp = 0.0;&lt;BR /&gt;for (j = 0; j &amp;lt; N; j++)&lt;BR /&gt;tmp += a&lt;I&gt;&lt;J&gt; * b&lt;J&gt;;&lt;BR /&gt;c&lt;I&gt; = tmp;&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Code #2: Converting sparse matrix to Dense matrix for effecient Data storage&lt;BR /&gt;&lt;BR /&gt;Generation of a penta-diagonal sparse matrix (A).&lt;BR /&gt;&lt;BR /&gt;for (i = 0; i &amp;lt; ROWS; i++) {&lt;BR /&gt;c&lt;I&gt; = 0.0;&lt;BR /&gt;for (j = 0; j &amp;lt; COLS; j++)&lt;BR /&gt;{&lt;BR /&gt;if (j==i)&lt;BR /&gt;{&lt;BR /&gt;if (i==0 &amp;amp;&amp;amp; j==0)&lt;BR /&gt;{&lt;BR /&gt;matrix&lt;I&gt;j+1 = (float) 1.0;&lt;BR /&gt;matrix&lt;I&gt;&lt;J&gt; = (float) 2.0;&lt;BR /&gt;matrix&lt;I&gt;j+GRID_SIZE = (float) 3.0;&lt;BR /&gt;}&lt;BR /&gt;if (i == ROWS-1)&lt;BR /&gt;{&lt;BR /&gt;matrix&lt;I&gt;j-1 = (float) 1.0;&lt;BR /&gt;matrix&lt;I&gt;&lt;J&gt; = (float) 4.0;&lt;BR /&gt;matrix&lt;I&gt;j-GRID_SIZE = (float) 3.0;&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;if (i % GRID_SIZE == 0 )&lt;BR /&gt;matrix&lt;I&gt;j+1 = (float) 1.0;&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;matrix&lt;I&gt;j-1 = (float) 1.0;&lt;BR /&gt;if ((i+1)%GRID_SIZE !=0)&lt;BR /&gt;matrix&lt;I&gt;j+1 = (float) 1.0;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;matrix&lt;I&gt;&lt;J&gt; = (float) 2.0;&lt;BR /&gt;if ((j+GRID_SIZE)&amp;lt;= COLS)&lt;BR /&gt;matrix&lt;I&gt;j+GRID_SIZE = (float) 3.0;&lt;BR /&gt;if ((j-GRID_SIZE)&amp;gt;= 0)&lt;BR /&gt;matrix&lt;I&gt;j-GRID_SIZE = (float) 3.0;&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;} // j == i&lt;BR /&gt;&lt;BR /&gt;} // j&lt;BR /&gt;} //i&lt;BR /&gt;&lt;BR /&gt;// Additional steps to conver the sparse matrix to dense matrix ROWS*DIAGONALS+1 and storing of indices in seperate matrix&lt;BR /&gt;for (i = 0; i &amp;lt; ROWS; i++) {&lt;BR /&gt;k = 0;&lt;BR /&gt;for (j = 0; j &amp;lt; COLS; j++)&lt;BR /&gt;{&lt;BR /&gt;if (matrix&lt;I&gt;&lt;J&gt; != 0.0)&lt;BR /&gt;{&lt;BR /&gt;matrix_min&lt;I&gt;&lt;K&gt; = matrix&lt;I&gt;&lt;J&gt;;&lt;BR /&gt;&lt;BR /&gt;// changes made for the penta_diagonal matrix.The index array&lt;BR /&gt;// will contain the value of the vector j to which the matrix&lt;BR /&gt;// needs to be multiplied.&lt;BR /&gt;index&lt;I&gt;&lt;K&gt; = j;&lt;BR /&gt;k++;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;// Generation of dummy constant vector (b)&lt;BR /&gt;b[0] = 3; b[1]= 1; b[2] = 1;b[3] = 1; b[4]= 1; b[5] = 1;b[6] = 1; b[7]= 1; b[8] = 1;&lt;BR /&gt;&lt;BR /&gt;for (i=9;i&lt;ROWS&gt;&lt;/ROWS&gt;b&lt;I&gt; = b[8];&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;// Start of Iterative Solver&lt;BR /&gt;&lt;BR /&gt;for (it = 0; it &amp;lt; ROWS; it++) {&lt;BR /&gt;&lt;BR /&gt;......&lt;BR /&gt;min_matrix_vector_product (matrix_min,index, x, g,ROWS);&lt;BR /&gt;......&lt;BR /&gt;&lt;BR /&gt;min_matrix_vector_product (matrix_min, index,d, tmpvec,ROWS);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;} // end of loop&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;//Matrix Vector product Code (modified for Dense matrix.&lt;BR /&gt;&lt;BR /&gt;void min_matrix_vector_product (float **a, int **d,float *b, float *c,int ROWS)&lt;BR /&gt;{&lt;BR /&gt;int i, j;&lt;BR /&gt;int N = ROWS;&lt;BR /&gt;float tmp;&lt;BR /&gt;&lt;BR /&gt;for (i = 0; i &amp;lt; N; i++) {&lt;BR /&gt;tmp = 0.0;&lt;BR /&gt;for (j = 0; j &amp;lt; DIAGONALS+1; j++){&lt;BR /&gt;tmp += a&lt;I&gt;&lt;J&gt; * b[d&lt;I&gt;j];&lt;BR /&gt;}&lt;BR /&gt;c&lt;I&gt; = tmp;&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;/I&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/K&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/K&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/J&gt;&lt;/J&gt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solver/m-p/743127#M1204</guid>
      <dc:creator>hashirkk</dc:creator>
      <dc:date>2009-09-18T11:08:49Z</dc:date>
    </item>
  </channel>
</rss>

