Skip to content

Commit

Permalink
Make local size atomic.
Browse files Browse the repository at this point in the history
  • Loading branch information
grmnptr committed Mar 19, 2024
1 parent 18c3cb3 commit 2ca4eb6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions include/numerics/petsc_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,19 +370,31 @@ class PetscVector final : public NumericVector<T>
*
* Only valid when _array_is_present
*/
#ifdef LIBMESH_HAVE_CXX11_THREAD
mutable std::atomic<numeric_index_type> _first;
#else
mutable numeric_index_type _first;
#endif

/**
* Last local index.
*
* Only valid when _array_is_present
*/
#ifdef LIBMESH_HAVE_CXX11_THREAD
mutable std::atomic<numeric_index_type> _last;
#else
mutable numeric_index_type _last;
#endif

/**
* Size of the local values from _get_array()
*/
#ifdef LIBMESH_HAVE_CXX11_THREAD
mutable std::atomic<numeric_index_type> _local_size;
#else
mutable numeric_index_type _local_size;
#endif

/**
* PETSc vector datatype to hold the local form of a ghosted vector.
Expand Down
4 changes: 2 additions & 2 deletions src/numerics/petsc_vector.C
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ void PetscVector<T>::add (const T v_in)
{
this->_get_array(false);

for (numeric_index_type i=0; i<_local_size; i++)
for (const auto i : make_range(_local_size.load()))
_values[i] += PetscScalar(v_in);
}

Expand Down Expand Up @@ -617,7 +617,7 @@ PetscVector<T>::operator = (const std::vector<T> & v)
*/
else
{
for (numeric_index_type i=0; i<_local_size; i++)
for (const auto i : make_range(_local_size.load()))
_values[i] = PS(v[i]);
}

Expand Down

0 comments on commit 2ca4eb6

Please sign in to comment.