From c44831ff90b54beff998f4e355d919ccbc512464 Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Mon, 7 Oct 2024 10:40:58 -0600 Subject: [PATCH 1/4] Fix bug when Kokkos atom map is build on host using hash --- src/KOKKOS/atom_map_kokkos.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/KOKKOS/atom_map_kokkos.cpp b/src/KOKKOS/atom_map_kokkos.cpp index 2c4c58ee19..7913efab2e 100644 --- a/src/KOKKOS/atom_map_kokkos.cpp +++ b/src/KOKKOS/atom_map_kokkos.cpp @@ -352,26 +352,17 @@ void AtomKokkos::map_set_host() // use "view" template method to avoid unnecessary deep_copy - auto h_map_hash = k_map_hash.view(); + auto& h_map_hash = k_map_hash.h_view; // must be an alias h_map_hash.clear(); - for (int i = nall - 1; i >= 0; i--) { + for (int i = 0; i < nall; i++) { // search for key // if don't find it, done - previous = -1; global = tag[i]; - ibucket = global % map_nbucket; - index = map_bucket[ibucket]; - while (index > -1) { - if (map_hash[index].global == global) break; - previous = index; - index = map_hash[index].next; - } - if (index == -1) continue; - - int local = map_hash[index].local; + int local = Atom::map_find_hash(global); + if (local == -1) continue; auto insert_result = h_map_hash.insert(global, local); if (insert_result.failed()) error->one(FLERR, "Kokkos::UnorderedMap insertion failed"); @@ -399,7 +390,7 @@ void AtomKokkos::map_one(tagint global, int local) k_map_array.h_view[global] = local; } else { k_map_hash.sync_host(); - auto& h_map_hash = k_map_hash.h_view; + auto& h_map_hash = k_map_hash.h_view; // must be an alias auto insert_result = h_map_hash.insert(global, local); if (insert_result.existing()) @@ -423,6 +414,7 @@ int AtomKokkos::map_find_hash(tagint global) auto index = h_map_hash.find(global); if (h_map_hash.valid_at(index)) local = h_map_hash.value_at(index); + return local; } From 9aaab458e864365d8879b853215ce544b151c13c Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Mon, 7 Oct 2024 10:54:28 -0600 Subject: [PATCH 2/4] Change another shallow copy to alias --- src/KOKKOS/atom_map_kokkos.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/KOKKOS/atom_map_kokkos.cpp b/src/KOKKOS/atom_map_kokkos.cpp index 7913efab2e..63df1dd9a9 100644 --- a/src/KOKKOS/atom_map_kokkos.cpp +++ b/src/KOKKOS/atom_map_kokkos.cpp @@ -212,7 +212,7 @@ void AtomKokkos::map_set_device() Kokkos::sort(LMPDeviceType(),l_sorted,MyComp{}); auto d_map_array = k_map_array.d_view; - auto d_map_hash = k_map_hash.d_view; + auto& d_map_hash = k_map_hash.d_view; if (!map_style_array) d_map_hash.clear(); From 6a46fb034d83798d3fd353bc7b58352b262a0636 Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Mon, 7 Oct 2024 11:11:12 -0600 Subject: [PATCH 3/4] Tweak comments --- src/KOKKOS/atom_kokkos.h | 2 +- src/KOKKOS/atom_map_kokkos.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/KOKKOS/atom_kokkos.h b/src/KOKKOS/atom_kokkos.h index d978a771de..d1d2586749 100644 --- a/src/KOKKOS/atom_kokkos.h +++ b/src/KOKKOS/atom_kokkos.h @@ -151,7 +151,7 @@ class AtomKokkos : public Atom { static int map_find_hash_kokkos(tagint global, const dual_hash_type &k_map_hash) { int local = -1; - auto& d_map_hash = k_map_hash.const_view(); + auto& d_map_hash = k_map_hash.const_view(); // must be alias auto index = d_map_hash.find(global); if (d_map_hash.valid_at(index)) local = d_map_hash.value_at(index); diff --git a/src/KOKKOS/atom_map_kokkos.cpp b/src/KOKKOS/atom_map_kokkos.cpp index 63df1dd9a9..fbb7c11395 100644 --- a/src/KOKKOS/atom_map_kokkos.cpp +++ b/src/KOKKOS/atom_map_kokkos.cpp @@ -212,7 +212,7 @@ void AtomKokkos::map_set_device() Kokkos::sort(LMPDeviceType(),l_sorted,MyComp{}); auto d_map_array = k_map_array.d_view; - auto& d_map_hash = k_map_hash.d_view; + auto& d_map_hash = k_map_hash.d_view; // must be alias if (!map_style_array) d_map_hash.clear(); @@ -352,7 +352,7 @@ void AtomKokkos::map_set_host() // use "view" template method to avoid unnecessary deep_copy - auto& h_map_hash = k_map_hash.h_view; // must be an alias + auto& h_map_hash = k_map_hash.h_view; // must be alias h_map_hash.clear(); for (int i = 0; i < nall; i++) { @@ -390,7 +390,7 @@ void AtomKokkos::map_one(tagint global, int local) k_map_array.h_view[global] = local; } else { k_map_hash.sync_host(); - auto& h_map_hash = k_map_hash.h_view; // must be an alias + auto& h_map_hash = k_map_hash.h_view; // must be alias auto insert_result = h_map_hash.insert(global, local); if (insert_result.existing()) @@ -408,7 +408,7 @@ void AtomKokkos::map_one(tagint global, int local) int AtomKokkos::map_find_hash(tagint global) { k_map_hash.sync_host(); - auto& h_map_hash = k_map_hash.h_view; + auto& h_map_hash = k_map_hash.h_view; // must be alias int local = -1; auto index = h_map_hash.find(global); From e6118412b187b597dfe161acef5345a6eb597ca8 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 7 Oct 2024 13:56:04 -0400 Subject: [PATCH 4/4] remove dead code in fix qeq/ctip --- src/QEQ/fix_qeq_ctip.cpp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/QEQ/fix_qeq_ctip.cpp b/src/QEQ/fix_qeq_ctip.cpp index 77285f1bc7..b86549d2a7 100644 --- a/src/QEQ/fix_qeq_ctip.cpp +++ b/src/QEQ/fix_qeq_ctip.cpp @@ -239,12 +239,6 @@ void FixQEqCTIP::init_matvec() double *q = atom->q, qi; int *type = atom->type; - double r = cutoff; - double rsq = r*r; - - double erfcd_cut = exp(-cdamp * cdamp * rsq); - double t_cut = 1.0 / (1.0 + EWALD_P * cdamp * r); - inum = list->inum; ilist = list->ilist; @@ -283,7 +277,6 @@ void FixQEqCTIP::compute_H() int inum, jnum, *ilist, *jlist, *numneigh, **firstneigh; int i, j, ii, jj; double dx, dy, dz, r_sqr, r, reff; - double cutoffsq, erfcd_cut, t_cut; double erfcc, erfcd, t; double **x = atom->x; @@ -295,10 +288,6 @@ void FixQEqCTIP::compute_H() numneigh = list->numneigh; firstneigh = list->firstneigh; - cutoffsq = cutoff * cutoff; - erfcd_cut = exp(-cdamp * cdamp * cutoffsq); - t_cut = 1.0 / (1.0 + EWALD_P * cdamp * cutoff); - // fill in the H matrix m_fill = 0; for (ii = 0; ii < inum; ii++) {