From c44831ff90b54beff998f4e355d919ccbc512464 Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Mon, 7 Oct 2024 10:40:58 -0600 Subject: [PATCH] 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; }