Skip to content

Commit

Permalink
attempt fix empty domains also in non-Kokkos pair and compute (#45), …
Browse files Browse the repository at this point in the history
…also force C++17 because of insert_or_assign. Compiles but untested.
  • Loading branch information
anjohan committed Jun 4, 2024
1 parent 1709eae commit 89e3ce1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
46 changes: 30 additions & 16 deletions compute_allegro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,27 @@ void ComputeAllegro<peratom>::compute_vector()
{
invoked_vector = update->ntimestep;

const torch::Tensor &quantity_tensor =
((PairAllegro<lowhigh> *) force->pair)->custom_output.at(quantity).cpu().ravel();
// empty domain, pair style won't store tensor
// note: assumes nlocal == inum
if (atom->nlocal == 0) {
for (int i = 0; i < size_vector; i++) {
vector[i] = 0.0;
}
} else {
const torch::Tensor &quantity_tensor =
((PairAllegro<lowhigh> *) force->pair)->custom_output.at(quantity).cpu().ravel();

auto quantity = quantity_tensor.data_ptr<double>();
auto quantity = quantity_tensor.data_ptr<double>();

if (quantity_tensor.size(0) != size_vector) {
error->one(FLERR, "size {} of quantity tensor {} does not match expected {} on rank {}",
quantity_tensor.size(0), this->quantity, size_vector, comm->me);
}
if (quantity_tensor.size(0) != size_vector) {
error->one(FLERR, "size {} of quantity tensor {} does not match expected {} on rank {}",
quantity_tensor.size(0), this->quantity, size_vector, comm->me);
}

for (int i = 0; i < size_vector; i++) { vector[i] = quantity[i]; }
for (int i = 0; i < size_vector; i++) { vector[i] = quantity[i]; }
}

// even if empty domain
MPI_Allreduce(MPI_IN_PLACE, vector, size_vector, MPI_DOUBLE, MPI_SUM, world);
}

Expand All @@ -128,18 +137,23 @@ void ComputeAllegro<peratom>::compute_peratom()
if (nperatom==1) vector_atom = &array_atom[0][0];
}

const torch::Tensor &quantity_tensor =
((PairAllegro<lowhigh> *) force->pair)->custom_output.at(quantity).cpu().contiguous().reshape({-1,nperatom});
// guard against empty domain (pair style won't store tensor)
if (atom->nlocal > 0) {
const torch::Tensor &quantity_tensor =
((PairAllegro<lowhigh> *) force->pair)->custom_output.at(quantity).cpu().contiguous().reshape({-1,nperatom});

auto quantity = quantity_tensor.accessor<double,2>();
quantityptr = quantity_tensor.data_ptr<double>();
auto quantity = quantity_tensor.accessor<double,2>();
quantityptr = quantity_tensor.data_ptr<double>();

int nlocal = atom->nlocal;
for (int i = 0; i < nlocal; i++) {
for (int j = 0; j < nperatom; j++) {
array_atom[i][j] = quantity[i][j];
int nlocal = atom->nlocal;
for (int i = 0; i < nlocal; i++) {
for (int j = 0; j < nperatom; j++) {
array_atom[i][j] = quantity[i][j];
}
}
}

// even if empty domain
if (newton) comm->reverse_comm(this);
}

Expand Down
3 changes: 3 additions & 0 deletions pair_allegro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ template <Precision precision> void PairAllegro<precision>::compute(int eflag, i
// Neighbor list per atom
int **firstneigh = list->firstneigh;

// Skip calculation if empty domain
if (inum==0) return;

// Total number of bonds (sum of number of neighbors)
int nedges = 0;

Expand Down
2 changes: 1 addition & 1 deletion patch_lammps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fi

echo "Updating CMakeLists.txt..."

sed -i "s/set(CMAKE_CXX_STANDARD 11)/set(CMAKE_CXX_STANDARD 14)/" $lammps_dir/cmake/CMakeLists.txt
sed -i "s/set(CMAKE_CXX_STANDARD 11)/set(CMAKE_CXX_STANDARD 17)/" $lammps_dir/cmake/CMakeLists.txt

# Add libtorch
cat >> $lammps_dir/cmake/CMakeLists.txt << "EOF2"
Expand Down

0 comments on commit 89e3ce1

Please sign in to comment.