Skip to content

Commit 6de4f1b

Browse files
committed
Add ParallelType argument to NumericVector::build()
The new arg defaults to AUTOMATIC, so the behavior should be exactly the same as it was previously, although now we have the chance to set a custom ParallelType via the NumericVector::build() API.
1 parent 91351a5 commit 6de4f1b

3 files changed

Lines changed: 23 additions & 11 deletions

File tree

include/numerics/numeric_vector.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ class NumericVector : public ReferenceCountedObject<NumericVector<T>>,
139139
*/
140140
static std::unique_ptr<NumericVector<T>>
141141
build(const Parallel::Communicator & comm,
142-
const SolverPackage solver_package = libMesh::default_solver_package());
142+
SolverPackage solver_package = libMesh::default_solver_package(),
143+
ParallelType parallel_type = AUTOMATIC);
143144

144145
/**
145146
* \returns \p true if the vector has been initialized,

src/numerics/numeric_vector.C

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,34 +47,36 @@ namespace libMesh
4747
// Full specialization for Real datatypes
4848
template <typename T>
4949
std::unique_ptr<NumericVector<T>>
50-
NumericVector<T>::build(const Parallel::Communicator & comm, const SolverPackage solver_package)
50+
NumericVector<T>::build(const Parallel::Communicator & comm,
51+
SolverPackage solver_package,
52+
ParallelType parallel_type)
5153
{
5254
// Build the appropriate vector
5355
switch (solver_package)
5456
{
5557

5658
#ifdef LIBMESH_HAVE_LASPACK
5759
case LASPACK_SOLVERS:
58-
return std::make_unique<LaspackVector<T>>(comm, AUTOMATIC);
60+
return std::make_unique<LaspackVector<T>>(comm, parallel_type);
5961
#endif
6062

6163
#ifdef LIBMESH_HAVE_PETSC
6264
case PETSC_SOLVERS:
63-
return std::make_unique<PetscVector<T>>(comm, AUTOMATIC);
65+
return std::make_unique<PetscVector<T>>(comm, parallel_type);
6466
#endif
6567

6668
#ifdef LIBMESH_TRILINOS_HAVE_EPETRA
6769
case TRILINOS_SOLVERS:
68-
return std::make_unique<EpetraVector<T>>(comm, AUTOMATIC);
70+
return std::make_unique<EpetraVector<T>>(comm, parallel_type);
6971
#endif
7072

7173
#ifdef LIBMESH_HAVE_EIGEN
7274
case EIGEN_SOLVERS:
73-
return std::make_unique<EigenSparseVector<T>>(comm, AUTOMATIC);
75+
return std::make_unique<EigenSparseVector<T>>(comm, parallel_type);
7476
#endif
7577

7678
default:
77-
return std::make_unique<DistributedVector<T>>(comm, AUTOMATIC);
79+
return std::make_unique<DistributedVector<T>>(comm, parallel_type);
7880
}
7981
}
8082

src/systems/system.C

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -792,19 +792,28 @@ NumericVector<Number> & System::add_vector (std::string_view vec_name,
792792
vec.swap(*new_vec);
793793
}
794794
else
795-
vec.type() = type;
795+
// The PARALLEL vec is not yet initialized, so we can just "upgrade" it to GHOSTED
796+
vec.upgrade_to_ghosted();
796797
}
797798
}
798799

799800
// Any upgrades are done; we're happy here.
800801
return vec;
801802
}
802803

803-
// Otherwise build the vector
804-
auto pr = _vectors.emplace(vec_name, NumericVector<Number>::build(this->comm()));
804+
// Otherwise, build the vector. The following emplace() is
805+
// guaranteed to succeed because, if we made it here, we don't
806+
// already have a vector named "vec_name". We pass the user's
807+
// requested ParallelType directly to NumericVector::build() so
808+
// that, even if the vector is not initialized now, it will get the
809+
// right type when it is initialized later.
810+
auto pr =
811+
_vectors.emplace(vec_name,
812+
NumericVector<Number>::build(this->comm(),
813+
libMesh::default_solver_package(),
814+
type));
805815
auto buf = pr.first->second.get();
806816
_vector_projections.emplace(vec_name, projections);
807-
buf->type() = type;
808817

809818
// Vectors are primal by default
810819
_vector_is_adjoint.emplace(vec_name, -1);

0 commit comments

Comments
 (0)