From da90372f456c04c12b0228efb412629cc963f671 Mon Sep 17 00:00:00 2001 From: "clara.bayley" Date: Fri, 3 May 2024 23:34:42 +0200 Subject: [PATCH 1/3] fix: move gbxvol and gbxarea maps to host from device --- libs/cartesiandomain/cartesianmaps.hpp | 39 +++++++++----------------- libs/kokkosaliases.hpp | 6 ++-- 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/libs/cartesiandomain/cartesianmaps.hpp b/libs/cartesiandomain/cartesianmaps.hpp index cfe98caae..715fe09de 100644 --- a/libs/cartesiandomain/cartesianmaps.hpp +++ b/libs/cartesiandomain/cartesianmaps.hpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Wednesday 1st May 2024 + * Last Modified: Friday 3rd May 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -59,9 +59,9 @@ struct CartesianMaps { kokkos_uintmap to_forward_coord2nghbr; /* additional gridbox / domain information */ - kokkos_dblmap to_area; // map from gbxindex to horizontal (x-y planar) area of gridbox - kokkos_dblmap to_volume; // map from gbxindex to volume of gridbox - viewd_ndims ndims; // dimensions (ie. no. gridboxes) in [coord3, coord1, coord2] directions + kokkos_dblmaph to_area; // map from gbxindex to horizontal (x-y planar) area of gridbox on host + kokkos_dblmaph to_volume; // map from gbxindex to volume of gridbox on host + viewd_ndims ndims; // dimensions (ie. no. gridboxes) in [coord3, coord1, coord2] directions public: /* initialise maps with hint for their capacity @@ -158,19 +158,10 @@ struct CartesianMaps { } /* insert 1 value into to_area map at key = idx with value=area */ - void insert_gbxarea(const unsigned int idx, double area) { - /* parallel for for 1 value so that execution of insert occurs on device if necessary */ - Kokkos::parallel_for( - "gbxarea", 1, KOKKOS_CLASS_LAMBDA(const unsigned int i) { to_area.insert(idx, area); }); - } + void insert_gbxarea(const unsigned int idx, double area) { to_area.insert(idx, area); } /* insert 1 value into to_volume map at key = idx with value=volume */ - void insert_gbxvolume(const unsigned int idx, double volume) { - /* parallel for for 1 value so that execution of insert occurs on device if necessary */ - Kokkos::parallel_for( - "gbxvolume", 1, - KOKKOS_CLASS_LAMBDA(const unsigned int i) { to_volume.insert(idx, volume); }); - } + void insert_gbxvolume(const unsigned int idx, double volume) { to_volume.insert(idx, volume); } /* copies of h_ndims to ndims, possibly into device memory */ @@ -193,6 +184,13 @@ struct CartesianMaps { return h_ndims; } + /* returns volume of gridbox with index 'gbxidx' on host */ + double get_gbxvolume(const unsigned int gbxidx) const { + const auto i(to_volume.find(gbxidx)); // index in map of key 'gbxindex' + + return to_volume.value_at(i); // value returned by map at index i + } + /* returns model dimensions ie. number of gridboxes along [coord3, coord1, coord2] directions */ KOKKOS_INLINE_FUNCTION @@ -206,22 +204,13 @@ struct CartesianMaps { KOKKOS_INLINE_FUNCTION size_t get_ndim(const unsigned int d) const { return ndims(d); } - /* returns horizontal (x-y planar) area of gridbox with index 'gbxidx' on device */ - KOKKOS_INLINE_FUNCTION + /* returns horizontal (x-y planar) area of gridbox with index 'gbxidx' on host */ double get_gbxarea(const unsigned int gbxidx) const { const auto i(to_area.find(gbxidx)); // index in map of key 'gbxindex' return to_area.value_at(i); // value returned by map at index i } - /* returns volume of gridbox with index 'gbxidx' on device */ - KOKKOS_INLINE_FUNCTION - double get_gbxvolume(const unsigned int gbxidx) const { - const auto i(to_volume.find(gbxidx)); // index in map of key 'gbxindex' - - return to_volume.value_at(i); // value returned by map at index i - } - /* returns {lower bound, upper bound} in coord3 (z) direction of gridbox with index 'gbxidx' on device */ diff --git a/libs/kokkosaliases.hpp b/libs/kokkosaliases.hpp index 6a94561c2..6c1453da3 100644 --- a/libs/kokkosaliases.hpp +++ b/libs/kokkosaliases.hpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Wednesday 1st May 2024 + * Last Modified: Friday 3rd May 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -48,8 +48,8 @@ using kokkos_pairmap = Kokkos::UnorderedMap; /**< E.g. for map from one unsigned int gbxindex to another */ -using kokkos_dblmap = Kokkos::UnorderedMap; -/**< E.g. for map from unsigned int gbxindex to gridbox area/volume */ +using kokkos_dblmaph = Kokkos::UnorderedMap; +/**< E.g. for map from unsigned int gbxindex to gridbox area/volume on host*/ using viewd_ndims = Kokkos::View; /**< View in device memory for number of gridboxes in CartesianMaps. */ From 5b3804774ff4941296d67a9a0d2e0d757cec8761 Mon Sep 17 00:00:00 2001 From: "clara.bayley" Date: Fri, 3 May 2024 23:38:32 +0200 Subject: [PATCH 2/3] fix: move gbxvol and gbxarea maps to host from device --- libs/cartesiandomain/cartesianmaps.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/cartesiandomain/cartesianmaps.hpp b/libs/cartesiandomain/cartesianmaps.hpp index 715fe09de..5723a7682 100644 --- a/libs/cartesiandomain/cartesianmaps.hpp +++ b/libs/cartesiandomain/cartesianmaps.hpp @@ -78,8 +78,8 @@ struct CartesianMaps { to_forward_coord1nghbr(kokkos_uintmap(ngbxs)), to_back_coord2nghbr(kokkos_uintmap(ngbxs)), to_forward_coord2nghbr(kokkos_uintmap(ngbxs)), - to_area(kokkos_dblmap(ngbxs)), - to_volume(kokkos_dblmap(ngbxs)), + to_area(kokkos_dblmaph(ngbxs)), + to_volume(kokkos_dblmaph(ngbxs)), ndims("ndims") {} /* insert 1 value into to_coord3bounds From 8550ad4af694d1e4d1a2dd74fbba9a4d02ed66ab Mon Sep 17 00:00:00 2001 From: "clara.bayley" Date: Sat, 4 May 2024 00:02:43 +0200 Subject: [PATCH 3/3] fix: typo falsely renaming function reverted --- examples/divfreemotion/divfree2d.py | 2 +- examples/yac/fromfile/yac1_fromfile.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/divfreemotion/divfree2d.py b/examples/divfreemotion/divfree2d.py index e4374f95e..fd7eabeec 100644 --- a/examples/divfreemotion/divfree2d.py +++ b/examples/divfreemotion/divfree2d.py @@ -101,7 +101,7 @@ # 4. plot results savename = savefigpath + "df2d_maxnsupers_validation.png" -pltmoms.plot_maxnsupers(time, maxnsupers, savename=savename) +pltmoms.plot_totnsupers(time, maxnsupers, savename=savename) nsample = 500 savename = savefigpath + "df2d_motion2d_validation.png" diff --git a/examples/yac/fromfile/yac1_fromfile.py b/examples/yac/fromfile/yac1_fromfile.py index a556bb59a..02db1c001 100644 --- a/examples/yac/fromfile/yac1_fromfile.py +++ b/examples/yac/fromfile/yac1_fromfile.py @@ -108,7 +108,7 @@ # plot super-droplet results savename = savefigpath + "yac1_maxnsupers_validation.png" -pltmoms.plot_maxnsupers(time, maxnsupers, savename=savename) +pltmoms.plot_totnsupers(time, maxnsupers, savename=savename) nsample = 1000 savename = savefigpath + "yac1_motion2d_validation.png"