[Trilinos-Users] A problem about the performance when using method Epetra_CrsMatrix::ReplaceGlobalValues()

Heroux, Michael A maherou at sandia.gov
Wed Mar 23 15:47:42 MDT 2011


Henian,

Since you already have your data in Crs format, you would be better off using the “View” mode.  This mode allows you to pass in pointers to your data.  We will  use your data and not copy it.  To use view mode, just replace Copy with View when you call the constructor for your Epetra_CrsMatrix.

If for some reason this will not work for you, you can improve your performance by making the “3” argument in the constructor call “200” and replace your “for(j” loop with a single call to [Insert|ReplaceGlobalValues that passes all of the values and indices.

I hope this is helpful.

Mike


On 3/23/11 4:14 PM, "Henian Xia" <xiahenian at gmail.com> wrote:

Hi everyone,

I have a problem with the use of the class "Epetra_CrsMatrix". In my application, I already have assembled a compressed-row-storage matrix, and I need to convert this matrix to the data structure of "Epetra_CrsMatrix" so that I can then use the class Epetra_LinearProblem. To do that, I define an object equA and insert values to equA at the first time step. Then after the first step, I use the method "Epetra_CrsMatrix::ReplaceGlobalValues()" to update the values in the "Epetra_CrsMatrix". Each time I update only one value of the
Epetra_CrsMatrix, and I will need to call the ReplaceGlobalValues() about 1 million times, and then it costs 5 seconds each time step. I also tried to update one row of the Epetra_CrsMatrix each time, but that is even slower.

Did I do anything wrong please?

Thank you very much,
Henian

 if( timeStep == 1 )
    equA = new Epetra_CrsMatrix(Copy, *Map, 3);

  if( timeStep == 1 ) {
        for( i = 0 ; i < 4600 ; i++ )
        {
                GlobalRow = (*equA).GRID( i );
                //The variables Matrix_ia, Matrix_ja and matrix_a are respectively the pointers to the row index vector,
                //the column index vector and the value vector of the compressed-row-storage matrix.
                //Matrix_ia[ i + 1 ] -Matrix_ia[ i ] is about  200
               for( j = Matrix_ia[ i ] ; j < Matrix_ia[ i + 1 ] ; j ++ )  {
                    (*equA).InsertGlobalValues( GlobalRow , 1 , Matrix_a + j , Matrix_ja + j );
                }
        }
   }

   if( timeStep > 1 ) {
        for( i = 0 ; i < 4600 ; i++ )
        {
                GlobalRow = (*equA).GRID( i );
                 for( j = Matrix_ia[ i ] ; j < Matrix_ia[ i + 1 ] ; j ++ )  {
                    (*equA).ReplaceGlobalValues( GlobalRow , 1 , Matrix_a + j , Matrix_ja + j );
                }
        }
   }
   (*equA).FillComplete();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://software.sandia.gov/pipermail/trilinos-users/attachments/20110323/5e45102d/attachment.html 


More information about the Trilinos-Users mailing list