Skip to content

Commit 6fa3a3b

Browse files
committed
Tim Kroeger's patch for NumericVector::get() and PetscVector speed
improvements git-svn-id: file:///Users/petejw/Documents/libmesh_svn_bak@3445 434f946d-2f3d-0410-ba4c-cb9f52fb0dbf
1 parent 7662586 commit 6fa3a3b

File tree

3 files changed

+268
-48
lines changed

3 files changed

+268
-48
lines changed

trunk/libmesh/include/numerics/numeric_vector.h

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,14 @@ class NumericVector : public ReferenceCountedObject<NumericVector<T> >
308308
*/
309309
virtual T el(const unsigned int i) const { return (*this)(i); }
310310

311+
/**
312+
* Access multiple components at once. \p values will be resized,
313+
* if necessary, and filled. The default implementation calls \p
314+
* operator() for each index, but some implementations may supply
315+
* faster methods here.
316+
*/
317+
virtual void get(const std::vector<unsigned int>& index, std::vector<T>& values) const;
318+
311319
/**
312320
* Addition operator.
313321
* Fast equivalent to \p U.add(1, V).
@@ -558,7 +566,7 @@ class NumericVector : public ReferenceCountedObject<NumericVector<T> >
558566
* enough indirection in subclasses to make this an O(1) header-swap
559567
* operation.
560568
*/
561-
virtual void swap (NumericVector<T> &v) = 0;
569+
virtual void swap (NumericVector<T> &v);
562570

563571
protected:
564572

@@ -693,6 +701,20 @@ void NumericVector<T>::clear ()
693701
_is_closed = false;
694702
_is_initialized = false;
695703
}
704+
705+
706+
707+
template <typename T>
708+
inline
709+
void NumericVector<T>::get(const std::vector<unsigned int>& index, std::vector<T>& values) const
710+
{
711+
const unsigned int num = index.size();
712+
values.resize(num);
713+
for(unsigned int i=0; i<num; i++)
714+
{
715+
values[i] = (*this)(index[i]);
716+
}
717+
}
696718

697719

698720

@@ -775,4 +797,15 @@ void NumericVector<T>::print_global(std::ostream& os) const
775797

776798

777799

800+
template <typename T>
801+
inline
802+
void NumericVector<T>::swap (NumericVector<T> &v)
803+
{
804+
std::swap(_is_closed, v._is_closed);
805+
std::swap(_is_initialized, v._is_initialized);
806+
std::swap(_type, v._type);
807+
}
808+
809+
810+
778811
#endif // #ifdef __numeric_vector_h__

0 commit comments

Comments
 (0)