On Fri, Jun 8, 2012 at 2:31 PM, w_ang_temp <span dir="ltr"><<a href="mailto:w_ang_temp@163.com" target="_blank">w_ang_temp@163.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="line-height:1.7;font-size:14px;font-family:arial"><div>Hello,</div>
<div> When solving a linear system Ax=b, the first step is assigning values to<br>matrix A. In my program, the subroutine PETSCSOLVE, which is used to slove Ax=b<br>with PETSc, gets the CSR format matrix(values, columns, rowIndex) to set values<br>
to PETSc Mat A.</div>
<div> The variables 'values'、'columns'、'rowIndex' belong to the main function.<br>They are used to represent a matrix in CSR format. The following table describes<br>the arrays in terms of the values, row, and column positions of the non-zero<br>
elements in a sparse matrix. <br> values: A real or complex array that contains the non-zero elements of a <br> sparse matrix. The non-zero elements are mapped into the values<br> array using the row-major upper triangular storage mapping described<br>
above. <br> columns: Element i of the integer array columns is the number of the column<br> that contains the i-th element in the values array. <br> rowIndex: Element j of the integer array rowIndex gives the index of the <br>
element in the values array that is first non-zero element in a row j. </div>
<div><br>codes:<br>---------Set Values to A From CSR Format(values,rowIndex,columns)-------------------<br> !values:Non-Symmetric Matrix<br> ione = 1<br> do 10,II=Istart+1,Iend<br> !non-zero numbers of this row<br>
rowNum=rowIndex(II+1)-rowIndex(II)<br> do 11,JJ=1,rowNum<br> <br> !elemnt index of the values/columns<br> kValNn=rowIndex(II)+JJ-1<br> !column index of this element<br>
nCol=columns(kValNn)-1<br> <br> !Setdata:II-RowIndex,nCol-ColIndex<br> nRow=II-1<br> call MatSetValues(A,ione,nRow,ione,nCol,values(kValNn),INSERT_VALUES,ierr)<br> 11 continue <br>
10 continue<br>--------------------------------------------------------------------------------------</div>
<div><br> As we can see, it has to loop a number of times because it can only set one data per<br>time. And this leads to low efficiency.<br></div></div></blockquote><div><br></div><div>Almost certainly, this is not your problem. If anything is slow, its a problem with preallocation.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="line-height:1.7;font-size:14px;font-family:arial"><div> So is there a better way to do this?<br>
</div></div></blockquote><div><br></div><div>You can go directly to the data structure in serial, but then you give up on parallelism.</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="line-height:1.7;font-size:14px;font-family:arial"><div> Thank you.<br> Jim</div>
<div> </div></div><br><br><span title="neteasefooter"><span></span></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener<br>