Skip to content

Commit 0ce07d2

Browse files
committed
Change NumericVector::upgrade_to_ghosted() -> NumericVector::set_type()
Making this a generic setter opens up the possibility that we will support more complicated/expensive type conversions later. For now, we just throw a libmesh_not_implemented() error when the user requests to change the ParallelType of an already-initialized NumericVector.
1 parent 6de4f1b commit 0ce07d2

3 files changed

Lines changed: 35 additions & 21 deletions

File tree

include/numerics/numeric_vector.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,15 @@ class NumericVector : public ReferenceCountedObject<NumericVector<T>>,
154154
ParallelType type() const { return _type; }
155155

156156
/**
157-
* If this vector's type() is PARALLEL and it is not yet
158-
* initialized, change the type() to GHOSTED.
159-
*
160-
* \returns \p true if the upgrade was performed, false otherwise.
161-
*/
162-
bool upgrade_to_ghosted();
157+
* Allow the user to change the ParallelType of the NumericVector
158+
* under some circumstances. If the NumericVector has not been
159+
* initialized yet, then it is generally safe to change the
160+
* ParallelType. otherwise, if the NumericVector has already been
161+
* initialized with a specific type, we cannot change it without
162+
* doing some extra copying/reinitialization work, and we currently
163+
* throw an error if this is requested.
164+
*/
165+
void set_type(ParallelType t);
163166

164167
/**
165168
* \returns \p true if the vector is closed and ready for

src/numerics/numeric_vector.C

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,24 +83,34 @@ NumericVector<T>::build(const Parallel::Communicator & comm,
8383

8484

8585
template <typename T>
86-
bool NumericVector<T>::upgrade_to_ghosted()
86+
void NumericVector<T>::set_type(ParallelType t)
8787
{
88-
// Can't upgrade to GHOSTED if libMesh was configured with --disable-ghosted
88+
// Check for no-op
89+
if (_type == t)
90+
return;
91+
92+
// If the NumericVector is not yet initialized, then it is generally
93+
// safe to change the ParallelType, with minor restrictions.
94+
if (!this->initialized())
95+
{
96+
// If ghosted vectors are not enabled and the user requested a
97+
// GHOSTED vector, fall back on SERIAL.
8998
#ifndef LIBMESH_ENABLE_GHOSTED
90-
return false;
99+
if (t == GHOSTED)
100+
{
101+
_type = SERIAL;
102+
return;
103+
}
91104
#endif
92105

93-
// We can only upgrade NumericVectors that are currently PARALLEL type
94-
// and not yet initialized.
95-
if (this->type() == PARALLEL && !this->initialized())
96-
{
97-
_type = GHOSTED;
98-
return true;
99-
}
106+
_type = t;
107+
return;
108+
}
100109

101-
// If we made it here, then the upgrade to GHOSTED could not be
102-
// performed for some reason, so return false.
103-
return false;
110+
// If we made it here, then the NumericVector was already
111+
// initialized and we don't currently allow the ParallelType to be
112+
// changed, although this could potentially be added later.
113+
libmesh_not_implemented();
104114
}
105115

106116
template <typename T>

src/systems/system.C

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

0 commit comments

Comments
 (0)