Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
abkein committed Feb 9, 2025
1 parent 816a1a4 commit 2c72fff
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/compute_cluster_size_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <cstddef>
#include <cstring>
#include <utility>
#include <algorithm>

using namespace LAMMPS_NS;
using namespace NUCC;
Expand Down Expand Up @@ -141,17 +142,22 @@ void ComputeClusterSizeExt::init()
clusters.grow(memory, nloc, "size/cluster/ext:clusters");
ns.grow(memory, 2 * nloc, "size/cluster/ext:ns");
monomers.grow(memory, nloc, "size/cluster/ext:monomers");
clusters.reset();
ns.reset();
monomers.reset();
ns.reset_unsafe<int>(0);
// clusters.reset();
for (int i = 0; i < nloc; ++i) {
clusters[i] = cluster_data();
}
}

if (ns.empty() || clusters.empty() || monomers.empty()) { error->one(FLERR, "{}: Inconsistent arrays state", style); }

if ((gathered.empty()) || (natom_loc < atom->natoms)) {
natom_loc = static_cast<bigint>(static_cast<long double>(atom->natoms) * LMP_NUCC_ALLOC_COEFF);
gathered.grow(memory, natom_loc, "size/cluster/ext:gathered");
gathered.reset();
// gathered.reset();
gathered.reset_unsafe<int>(0);
// for (int i = 0; i < natom_loc; ++i) { gathered[i] = cldata(); }
}

if ((peratom_size.empty()) || (nloc_peratom < atom->nlocal)) {
Expand Down Expand Up @@ -192,6 +198,12 @@ void ComputeClusterSizeExt::compute_vector()
clusters.grow(memory, nloc, "size/cluster/ext:clusters");
ns.grow(memory, 2 * nloc, "size/cluster/ext:ns");
monomers.grow(memory, nloc, "size/cluster/ext:monomers");
monomers.reset();
ns.reset_unsafe<int>(0);
// clusters.reset();
for (int i = 0; i < nloc; ++i) {
clusters[i] = cluster_data();
}
}

// Sort atom IDs by cluster IDs
Expand Down Expand Up @@ -251,7 +263,8 @@ void ComputeClusterSizeExt::compute_vector()
if (tcon > natom_loc) {
natom_loc = static_cast<int>(tcon * LMP_NUCC_ALLOC_COEFF);
gathered.grow(memory, natom_loc, "gathered");
gathered.reset();
// gathered.reset();
gathered.reset_unsafe<int>(0);
}

// communicate about local cluster sizes
Expand All @@ -277,6 +290,7 @@ void ComputeClusterSizeExt::compute_vector()
nloc_peratom = static_cast<int>(atom->nlocal * LMP_NUCC_ALLOC_COEFF);
peratom_size.grow(memory, nloc_peratom, "size/cluster/ext:peratom");
peratom_size.reset();
peratom_size.reset();
vector_atom = peratom_size.data();
}

Expand Down
1 change: 1 addition & 0 deletions src/nucc_cluster_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace NUCC {

struct cluster_data {
cluster_data() {}
explicit cluster_data(const int _clid) : clid(_clid) {}

// void rearrange() noexcept { ::memcpy(_atoms + l_size, _ghost, nghost * sizeof(int)); }
Expand Down
16 changes: 16 additions & 0 deletions src/nucc_cspan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,22 @@ class cspan {
if (!span_.empty()) { std::fill_n(span_.data(), span_.size(), zero_value<T>()); }
}

template<typename U>
inline void reset_unsafe(const U& value)
requires(!std::is_const_v<T>)
{
static_assert(sizeof(T) % sizeof(U) == 0, "Object size is not multiple of target value size");
if (!span_.empty()) { std::fill(reinterpret_cast<U*>(span_.data()), reinterpret_cast<U*>(span_.data() + span_.size()), value); }
}

template<typename U>
inline void reset_unsafe(U&& value)
requires(!std::is_const_v<T>)
{
static_assert(sizeof(T) % sizeof(U) == 0, "Object size is not multiple of target value size");
if (!span_.empty()) { std::fill(reinterpret_cast<std::remove_const_t<U>*>(span_.data()), reinterpret_cast<std::remove_const_t<U>*>(span_.data() + span_.size()), value); }
}

inline constexpr std::size_t memory_usage() const noexcept { return size() * sizeof(T) + sizeof(std::size_t) + sizeof(T *); }

private:
Expand Down

0 comments on commit 2c72fff

Please sign in to comment.