*/
std::auto_ptr<Epetra_FECrsGraph> graph;
+ /**
+ * Scratch array that holds several
+ * indices that should be written
+ * into the same row of the sparsity
+ * pattern. This is to increase the
+ * speed of this function.
+ */
+ std::vector<unsigned int> cached_row_indices;
+
+ /**
+ * A number that tells how many
+ * indices currently are active in
+ * the cache.
+ */
+ unsigned int n_cached_elements;
+
+ /**
+ * The row that is currently in the
+ * cache.
+ */
+ unsigned int row_in_cache;
+
friend class SparseMatrix;
friend class SparsityPatternIterators::const_iterator;
};
inline
void
- SparsityPattern::add (const unsigned int i,
- const unsigned int j)
+ SparsityPattern::add (const unsigned int i,
+ const unsigned int j)
{
- add (i, 1, &j);
+ // if we want to write an element to the
+ // row the cache is currently pointed to,
+ // we just append the data to the cache
+ if (i == row_in_cache)
+ {
+ // if the size is too small, extend the
+ // cache by 10 elements
+ if (n_cached_elements > cached_row_indices.size())
+ cached_row_indices.resize(cached_row_indices.size() + 10);
+
+ cached_row_indices[n_cached_elements] = j;
+ ++n_cached_elements;
+ return;
+ }
+
+ // if we are to write another row data,
+ // we write the cache data into the
+ // sparsity pattern, and then call this
+ // function again
+ add (row_in_cache, n_cached_elements, &cached_row_indices[0]);
+ row_in_cache = i;
+ n_cached_elements = 0;
+ add (i,j);
}
const unsigned int n_cols,
const unsigned int *col_indices)
{
+ if (n_cols == 0)
+ return;
+
int * col_index_ptr = (int*)col_indices;
compressed = false;
col_map (row_map),
compressed (true),
graph (std::auto_ptr<Epetra_FECrsGraph>
- (new Epetra_FECrsGraph(View, row_map, 0)))
+ (new Epetra_FECrsGraph(View, row_map, 0))),
+ cached_row_indices (1),
+ n_cached_elements (0),
+ row_in_cache (0)
{
graph->FillComplete();
}
compressed (false),
graph (std::auto_ptr<Epetra_FECrsGraph>
(new Epetra_FECrsGraph(Copy, row_map,
- int(n_entries_per_row), false)))
+ int(n_entries_per_row), false))),
+ cached_row_indices (1),
+ n_cached_elements (0),
+ row_in_cache (0)
{}
SparsityPattern::SparsityPattern (const Epetra_Map &InputMap,
graph (std::auto_ptr<Epetra_FECrsGraph>
(new Epetra_FECrsGraph(Copy, row_map,
(int*)const_cast<unsigned int*>(&(n_entries_per_row[0])),
- false)))
+ false))),
+ cached_row_indices (1),
+ n_cached_elements (0),
+ row_in_cache (0)
{}
SparsityPattern::SparsityPattern (const Epetra_Map &InputRowMap,
compressed (false),
graph (std::auto_ptr<Epetra_FECrsGraph>
(new Epetra_FECrsGraph(Copy, row_map,
- int(n_entries_per_row), false)))
+ int(n_entries_per_row), false))),
+ cached_row_indices (1),
+ n_cached_elements (0),
+ row_in_cache (0)
{}
SparsityPattern::SparsityPattern (const Epetra_Map &InputRowMap,
graph (std::auto_ptr<Epetra_FECrsGraph>
(new Epetra_FECrsGraph(Copy, row_map,
(int*)const_cast<unsigned int*>(&(n_entries_per_row[0])),
- false)))
+ false))),
+ cached_row_indices (1),
+ n_cached_elements (0),
+ row_in_cache (0)
{}
SparsityPattern::SparsityPattern (const unsigned int m,
compressed (false),
graph (std::auto_ptr<Epetra_FECrsGraph>
(new Epetra_FECrsGraph(Copy, row_map,
- int(n_entries_per_row), false)))
+ int(n_entries_per_row), false))),
+ cached_row_indices (1),
+ n_cached_elements (0),
+ row_in_cache (0)
{}
SparsityPattern::SparsityPattern (const unsigned int m,
graph (std::auto_ptr<Epetra_FECrsGraph>
(new Epetra_FECrsGraph(Copy, row_map,
(int*)const_cast<unsigned int*>(&(n_entries_per_row[0])),
- false)))
+ false))),
+ cached_row_indices (1),
+ n_cached_elements (0),
+ row_in_cache (0)
{}
// Copy function is currently not working
col_map (InputSP.col_map),
compressed (false),
graph (std::auto_ptr<Epetra_FECrsGraph>
- (new Epetra_FECrsGraph(*InputSP.graph)))
+ (new Epetra_FECrsGraph(*InputSP.graph))),
+ cached_row_indices (1),
+ n_cached_elements (0),
+ row_in_cache (0)
{}
*/
graph = std::auto_ptr<Epetra_FECrsGraph>
(new Epetra_FECrsGraph(Copy, row_map, n_entries_per_row, false));
+
+ n_cached_elements = 0;
+ row_in_cache = 0;
}
(new Epetra_FECrsGraph(Copy, row_map,
n_entries_per_row[input_row_map.MinMyGID()],
false));
+
+ n_cached_elements = 0;
+ row_in_cache = 0;
}
graph->FillComplete();
+ n_cached_elements = 0;
+ row_in_cache = 0;
+
compressed = true;
}
SparsityPattern::compress ()
{
// flush buffers
+ if (n_cached_elements > 0)
+ {
+ add (row_in_cache, n_cached_elements, &cached_row_indices[0]);
+ n_cached_elements = 0;
+ row_in_cache = 0;
+ }
+
int ierr;
ierr = graph->GlobalAssemble (col_map, row_map, true);
unsigned int
SparsityPattern::max_entries_per_row () const
{
- int nnz = graph->MaxRowDim();
+ int nnz = graph->MaxNumIndices();
return static_cast<unsigned int>(nnz);
}