Skip to content

Commit

Permalink
Merge pull request #1 from friedmud/vector_comms
Browse files Browse the repository at this point in the history
Work on getting NumericVectors moved over to being ParallelObjects
  • Loading branch information
benkirk committed Apr 4, 2013
2 parents 272c7cf + 3bb4c17 commit 3c7c7ae
Show file tree
Hide file tree
Showing 33 changed files with 395 additions and 317 deletions.
33 changes: 22 additions & 11 deletions include/numerics/distributed_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,25 @@ class DistributedVector : public NumericVector<T>
* Dummy-Constructor. Dimension=0
*/
explicit
DistributedVector (const ParallelType = AUTOMATIC);
DistributedVector (const ParallelType = AUTOMATIC,
const Parallel::Communicator &comm = libMesh::CommWorld);

/**
* Constructor. Set dimension to \p n and initialize all elements with zero.
*/
explicit
DistributedVector (const numeric_index_type n,
const ParallelType ptype = AUTOMATIC);
const ParallelType ptype = AUTOMATIC,
const Parallel::Communicator &comm = libMesh::CommWorld);

/**
* Constructor. Set local dimension to \p n_local, the global dimension
* to \p n, and initialize all elements with zero.
*/
DistributedVector (const numeric_index_type n,
const numeric_index_type n_local,
const ParallelType ptype = AUTOMATIC);
const ParallelType ptype = AUTOMATIC,
const Parallel::Communicator &comm = libMesh::CommWorld);

/**
* Constructor. Set local dimension to \p n_local, the global
Expand All @@ -82,7 +85,8 @@ class DistributedVector : public NumericVector<T>
DistributedVector (const numeric_index_type N,
const numeric_index_type n_local,
const std::vector<numeric_index_type>& ghost,
const ParallelType ptype = AUTOMATIC);
const ParallelType ptype = AUTOMATIC,
const Parallel::Communicator &comm = libMesh::CommWorld);

/**
* Destructor, deallocates memory. Made virtual to allow
Expand Down Expand Up @@ -476,7 +480,8 @@ class DistributedVector : public NumericVector<T>
// DistributedVector inline methods
template <typename T>
inline
DistributedVector<T>::DistributedVector (const ParallelType ptype) :
DistributedVector<T>::DistributedVector (const ParallelType ptype, const Parallel::Communicator &comm)
: NumericVector<T>(ptype, comm),
_global_size (0),
_local_size (0),
_first_local_index(0),
Expand All @@ -490,7 +495,9 @@ DistributedVector<T>::DistributedVector (const ParallelType ptype) :
template <typename T>
inline
DistributedVector<T>::DistributedVector (const numeric_index_type n,
const ParallelType ptype)
const ParallelType ptype,
const Parallel::Communicator &comm)
: NumericVector<T>(ptype, comm)
{
this->init(n, n, false, ptype);
}
Expand All @@ -501,7 +508,9 @@ template <typename T>
inline
DistributedVector<T>::DistributedVector (const numeric_index_type n,
const numeric_index_type n_local,
const ParallelType ptype)
const ParallelType ptype,
const Parallel::Communicator &comm)
: NumericVector<T>(ptype, comm)
{
this->init(n, n_local, false, ptype);
}
Expand All @@ -513,7 +522,9 @@ inline
DistributedVector<T>::DistributedVector (const numeric_index_type n,
const numeric_index_type n_local,
const std::vector<numeric_index_type>& ghost,
const ParallelType ptype)
const ParallelType ptype,
const Parallel::Communicator &comm)
: NumericVector<T>(ptype, comm)
{
this->init(n, n_local, ghost, false, ptype);
}
Expand Down Expand Up @@ -571,7 +582,7 @@ void DistributedVector<T>::init (const numeric_index_type n,

local_sizes[libMesh::processor_id()] = n_local;

CommWorld.sum(local_sizes);
this->communicator().sum(local_sizes);

// _first_local_index is the sum of _local_size
// for all processor ids less than ours
Expand Down Expand Up @@ -834,7 +845,7 @@ Real DistributedVector<T>::min () const
for (numeric_index_type i = 1; i < _values.size(); ++i)
local_min = std::min(libmesh_real(_values[i]), local_min);

CommWorld.min(local_min);
this->communicator().min(local_min);

return local_min;
}
Expand All @@ -857,7 +868,7 @@ Real DistributedVector<T>::max() const
for (numeric_index_type i = 1; i < _values.size(); ++i)
local_max = std::max(libmesh_real(_values[i]), local_max);

CommWorld.max(local_max);
this->communicator().max(local_max);

return local_max;
}
Expand Down
27 changes: 19 additions & 8 deletions include/numerics/eigen_sparse_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,25 @@ class EigenSparseVector : public NumericVector<T>
* Dummy-Constructor. Dimension=0
*/
explicit
EigenSparseVector (const ParallelType = AUTOMATIC);
EigenSparseVector (const ParallelType = AUTOMATIC,
const Parallel::Communicator &comm = libMesh::CommWorld);

/**
* Constructor. Set dimension to \p n and initialize all elements with zero.
*/
explicit
EigenSparseVector (const numeric_index_type n,
const ParallelType = AUTOMATIC);
const ParallelType = AUTOMATIC,
const Parallel::Communicator &comm = libMesh::CommWorld);

/**
* Constructor. Set local dimension to \p n_local, the global dimension
* to \p n, and initialize all elements with zero.
*/
EigenSparseVector (const numeric_index_type n,
const numeric_index_type n_local,
const ParallelType = AUTOMATIC);
const ParallelType = AUTOMATIC,
const Parallel::Communicator &comm = libMesh::CommWorld);

/**
* Constructor. Set local dimension to \p n_local, the global
Expand All @@ -86,7 +89,8 @@ class EigenSparseVector : public NumericVector<T>
EigenSparseVector (const numeric_index_type N,
const numeric_index_type n_local,
const std::vector<numeric_index_type>& ghost,
const ParallelType = AUTOMATIC);
const ParallelType = AUTOMATIC,
const Parallel::Communicator &comm = libMesh::CommWorld);

/**
* Destructor, deallocates memory. Made virtual to allow
Expand Down Expand Up @@ -474,7 +478,8 @@ class EigenSparseVector : public NumericVector<T>
// EigenSparseVector inline methods
template <typename T>
inline
EigenSparseVector<T>::EigenSparseVector (const ParallelType ptype)
EigenSparseVector<T>::EigenSparseVector (const ParallelType ptype, const Parallel::Communicator &comm)
: NumericVector<T>(ptype, comm)
{
this->_type = ptype;
}
Expand All @@ -484,7 +489,9 @@ EigenSparseVector<T>::EigenSparseVector (const ParallelType ptype)
template <typename T>
inline
EigenSparseVector<T>::EigenSparseVector (const numeric_index_type n,
const ParallelType ptype)
const ParallelType ptype,
const Parallel::Communicator &comm)
: NumericVector<T>(ptype, comm)
{
this->init(n, n, false, ptype);
}
Expand All @@ -495,7 +502,9 @@ template <typename T>
inline
EigenSparseVector<T>::EigenSparseVector (const numeric_index_type n,
const numeric_index_type n_local,
const ParallelType ptype)
const ParallelType ptype,
const Parallel::Communicator &comm)
: NumericVector<T>(ptype, comm)
{
this->init(n, n_local, false, ptype);
}
Expand All @@ -507,7 +516,9 @@ inline
EigenSparseVector<T>::EigenSparseVector (const numeric_index_type N,
const numeric_index_type n_local,
const std::vector<numeric_index_type>& ghost,
const ParallelType ptype)
const ParallelType ptype,
const Parallel::Communicator &comm)
: NumericVector<T>(ptype, comm)
{
this->init(N, n_local, ghost, false, ptype);
}
Expand Down
28 changes: 20 additions & 8 deletions include/numerics/laspack_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,25 @@ class LaspackVector : public NumericVector<T>
* Dummy-Constructor. Dimension=0
*/
explicit
LaspackVector (const ParallelType = AUTOMATIC);
LaspackVector (const ParallelType = AUTOMATIC,
const Parallel::Communicator &comm = libMesh::CommWorld);

/**
* Constructor. Set dimension to \p n and initialize all elements with zero.
*/
explicit
LaspackVector (const numeric_index_type n,
const ParallelType = AUTOMATIC);
const ParallelType = AUTOMATIC,
const Parallel::Communicator &comm = libMesh::CommWorld);

/**
* Constructor. Set local dimension to \p n_local, the global dimension
* to \p n, and initialize all elements with zero.
*/
LaspackVector (const numeric_index_type n,
const numeric_index_type n_local,
const ParallelType = AUTOMATIC);
const ParallelType = AUTOMATIC,
const Parallel::Communicator &comm = libMesh::CommWorld);

/**
* Constructor. Set local dimension to \p n_local, the global
Expand All @@ -87,7 +90,8 @@ class LaspackVector : public NumericVector<T>
LaspackVector (const numeric_index_type N,
const numeric_index_type n_local,
const std::vector<numeric_index_type>& ghost,
const ParallelType = AUTOMATIC);
const ParallelType = AUTOMATIC,
const Parallel::Communicator &comm = libMesh::CommWorld);

/**
* Destructor, deallocates memory. Made virtual to allow
Expand Down Expand Up @@ -463,7 +467,9 @@ class LaspackVector : public NumericVector<T>
// LaspackVector inline methods
template <typename T>
inline
LaspackVector<T>::LaspackVector (const ParallelType ptype)
LaspackVector<T>::LaspackVector (const ParallelType ptype,
const Parallel::Communicator &comm)
: NumericVector<T>(ptype, comm)
{
this->_type = ptype;
}
Expand All @@ -473,7 +479,9 @@ LaspackVector<T>::LaspackVector (const ParallelType ptype)
template <typename T>
inline
LaspackVector<T>::LaspackVector (const numeric_index_type n,
const ParallelType ptype)
const ParallelType ptype,
const Parallel::Communicator &comm)
: NumericVector<T>(ptype, comm)
{
this->init(n, n, false, ptype);
}
Expand All @@ -484,7 +492,9 @@ template <typename T>
inline
LaspackVector<T>::LaspackVector (const numeric_index_type n,
const numeric_index_type n_local,
const ParallelType ptype)
const ParallelType ptype,
const Parallel::Communicator &comm)
: NumericVector<T>(ptype, comm)
{
this->init(n, n_local, false, ptype);
}
Expand All @@ -496,7 +506,9 @@ inline
LaspackVector<T>::LaspackVector (const numeric_index_type N,
const numeric_index_type n_local,
const std::vector<numeric_index_type>& ghost,
const ParallelType ptype)
const ParallelType ptype,
const Parallel::Communicator &comm)
: NumericVector<T>(ptype, comm)
{
this->init(N, n_local, ghost, false, ptype);
}
Expand Down
34 changes: 24 additions & 10 deletions include/numerics/numeric_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "libmesh/id_types.h"
#include "libmesh/reference_counted_object.h"
#include "libmesh/libmesh.h"
#include "libmesh/parallel_object.h"

// C++ includes
#include <cstddef>
Expand All @@ -54,30 +55,34 @@ template <typename T> class ShellMatrix;
* @author Benjamin S. Kirk, 2003
*/
template <typename T>
class NumericVector : public ReferenceCountedObject<NumericVector<T> >
class NumericVector : public ReferenceCountedObject<NumericVector<T> >,
public ParallelObject
{
public:

/**
* Dummy-Constructor. Dimension=0
*/
explicit
NumericVector (const ParallelType ptype = AUTOMATIC);
NumericVector (const ParallelType ptype = AUTOMATIC,
const Parallel::Communicator &comm=libMesh::CommWorld);

/**
* Constructor. Set dimension to \p n and initialize all elements with zero.
*/
explicit
NumericVector (const numeric_index_type n,
const ParallelType ptype = AUTOMATIC);
const ParallelType ptype = AUTOMATIC,
const Parallel::Communicator &comm=libMesh::CommWorld);

/**
* Constructor. Set local dimension to \p n_local, the global dimension
* to \p n, and initialize all elements with zero.
*/
NumericVector (const numeric_index_type n,
const numeric_index_type n_local,
const ParallelType ptype = AUTOMATIC);
const ParallelType ptype = AUTOMATIC,
const Parallel::Communicator &comm=libMesh::CommWorld);

/**
* Constructor. Set local dimension to \p n_local, the global
Expand All @@ -87,7 +92,8 @@ class NumericVector : public ReferenceCountedObject<NumericVector<T> >
NumericVector (const numeric_index_type N,
const numeric_index_type n_local,
const std::vector<numeric_index_type>& ghost,
const ParallelType ptype = AUTOMATIC);
const ParallelType ptype = AUTOMATIC,
const Parallel::Communicator &comm=libMesh::CommWorld);

public:

Expand All @@ -102,7 +108,8 @@ class NumericVector : public ReferenceCountedObject<NumericVector<T> >
* \p solver_package
*/
static AutoPtr<NumericVector<T> >
build(const SolverPackage solver_package = libMesh::default_solver_package());
build(const SolverPackage solver_package = libMesh::default_solver_package(),
const Parallel::Communicator &comm = libMesh::CommWorld);

/**
* @returns true if the vector has been initialized,
Expand Down Expand Up @@ -646,7 +653,8 @@ class NumericVector : public ReferenceCountedObject<NumericVector<T> >

template <typename T>
inline
NumericVector<T>::NumericVector (const ParallelType ptype) :
NumericVector<T>::NumericVector (const ParallelType ptype, const Parallel::Communicator &comm) :
ParallelObject(comm),
_is_closed(false),
_is_initialized(false),
_type(ptype)
Expand All @@ -658,7 +666,9 @@ NumericVector<T>::NumericVector (const ParallelType ptype) :
template <typename T>
inline
NumericVector<T>::NumericVector (const numeric_index_type /*n*/,
const ParallelType ptype) :
const ParallelType ptype,
const Parallel::Communicator &comm) :
ParallelObject(comm),
_is_closed(false),
_is_initialized(false),
_type(ptype)
Expand All @@ -673,7 +683,9 @@ template <typename T>
inline
NumericVector<T>::NumericVector (const numeric_index_type /*n*/,
const numeric_index_type /*n_local*/,
const ParallelType ptype) :
const ParallelType ptype,
const Parallel::Communicator &comm) :
ParallelObject(comm),
_is_closed(false),
_is_initialized(false),
_type(ptype)
Expand All @@ -689,7 +701,9 @@ inline
NumericVector<T>::NumericVector (const numeric_index_type /*n*/,
const numeric_index_type /*n_local*/,
const std::vector<numeric_index_type>& /*ghost*/,
const ParallelType ptype) :
const ParallelType ptype,
const Parallel::Communicator &comm) :
ParallelObject(comm),
_is_closed(false),
_is_initialized(false),
_type(ptype)
Expand Down
2 changes: 2 additions & 0 deletions include/numerics/petsc_macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ typedef enum { PETSC_COPY_VALUES, PETSC_OWN_POINTER, PETSC_USE_POINTER} PetscCop
# define ISCreateLibMesh(comm,n,idx,mode,is) ISCreateGeneral((comm),(n),(idx),(mode),(is))
#endif

#define LIBMESH_CHKERRABORT(ierr) CHKERRABORT(this->communicator().get(), ierr);

#else // LIBMESH_HAVE_PETSC

#define PETSC_VERSION_LESS_THAN(major,minor,subminor) 1
Expand Down
Loading

0 comments on commit 3c7c7ae

Please sign in to comment.