Commit c295f119 authored by Radu Popescu's avatar Radu Popescu
Browse files

Fixing redundancy in MatrixEpetra::addToCoefficients

Index vectors were passed by value into the method and, additionally, copied element by element into new vectors, to remove the const attribute (which is no longer necessary), before calling the Epetra method. This resulted in two additional copy operations for each vector.
parent 4729fc2f
......@@ -413,7 +413,7 @@ public:
@param format Format of the matrix (Epetra_FECrsMatrix::COLUMN_MAJOR or Epetra_FECrsMatrix::ROW_MAJOR)
*/
void addToCoefficients( Int const numRows, Int const numColumns,
std::vector<Int> const rowIndices, std::vector<Int> const columnIndices,
std::vector<Int> const& rowIndices, std::vector<Int> const& columnIndices,
DataType* const* const localValues,
Int format = Epetra_FECrsMatrix::COLUMN_MAJOR );
......@@ -1251,26 +1251,12 @@ addToCoefficient( UInt row, UInt column, DataType localValue )
template <typename DataType>
void MatrixEpetra<DataType>::
addToCoefficients( Int const numRows, Int const numColumns,
std::vector<Int> const rowIndices, std::vector<Int> const columnIndices,
std::vector<Int> const& rowIndices, std::vector<Int> const& columnIndices,
DataType* const* const localValues,
Int format )
{
std::vector<Int> irow( numRows );
std::vector<Int> icol( numColumns );
std::vector<Int>::const_iterator pt;
pt = rowIndices.begin();
for ( std::vector<Int>::iterator i( irow.begin() ); i != irow.end() && pt != rowIndices.end(); ++i, ++pt )
*i = *pt;
pt = columnIndices.begin();
for ( std::vector<Int>::iterator i( icol.begin() ); i != icol.end() && pt != columnIndices.end(); ++i, ++pt )
*i = *pt;
Int ierr = M_epetraCrs->InsertGlobalValues( numRows, &irow[0], numColumns, &icol[0], localValues, format );
Int ierr = M_epetraCrs->InsertGlobalValues( numRows, &rowIndices[0], numColumns,
&columnIndices[0], localValues, format );
if ( ierr < 0 ) std::cout << " error in matrix insertion " << ierr << std::endl;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment