<div style="line-height:1.7;color:#000000;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> So is there a better way to do this?<BR> Thank you.<BR> Jim</DIV>
<DIV> </DIV></div><br><br><span title="neteasefooter"><span id="netease_mail_footer"></span></span>