Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid potential float precision error in temperature translation #379

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/CAtemperature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ struct Temperature {
// Based on the X coordinate compared to the global domain bounds and the Y coordinate compared to the MPI rank Y
// bounds (integers), return whether or not this translated coordinate is in bounds on this rank
bool translatedXYInBounds(const double x_translated, const double y_translated, const Grid grid) {
const int coord_x = Kokkos::round((x_translated - grid.x_min) / grid.deltax);
const int coord_y_global = Kokkos::round((y_translated - grid.y_min) / grid.deltax);
bool xy_in_bounds;
if ((grid.x_min <= x_translated) && (grid.x_max >= x_translated) && (coord_y_global >= grid.y_offset) &&
if ((coord_x >= 0) && (coord_x < grid.nx) && (coord_y_global >= grid.y_offset) &&
(coord_y_global < grid.y_offset + grid.ny_local))
xy_in_bounds = true;
else
Expand Down
69 changes: 31 additions & 38 deletions unit_test/tstTemperature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ void checkTemperatureResults(Inputs &inputs, Grid &grid, Temperature<MemorySpace
const bool x_coord_mirrored = ((mirror_x) && (coord_y % 2 == 1));
double loc_along_scan;
if (x_coord_mirrored)
loc_along_scan = static_cast<double>(grid.nx - coord_x);
loc_along_scan = static_cast<double>((grid.nx - 1) - coord_x);
else
loc_along_scan = static_cast<double>(coord_x);
const double expected_tm = loc_along_scan + static_cast<double>(coord_y) * inputs.temperature.temporal_offset;
Expand Down Expand Up @@ -358,35 +358,27 @@ void checkTemperatureResults(Inputs &inputs, Grid &grid, Temperature<MemorySpace
}
}

// Test storing temperature data from Finch on the correct ExaCA ranks, optionally mirroring and translating the data
void testInitTemperatureFromFinch(const bool mirror_x, const int number_of_copies) {

using memory_space = TEST_MEMSPACE;
using view_type_coupled = Kokkos::View<double **, Kokkos::LayoutLeft, Kokkos::HostSpace>;

int id, np;
// Get number of processes
MPI_Comm_size(MPI_COMM_WORLD, &np);
// Get individual process ID
MPI_Comm_rank(MPI_COMM_WORLD, &id);

// Default inputs struct - manually set temperature values for test
Inputs inputs;
// Initialize test input values for InitTemperatureFromFinch and InitTemperatureFromFile
void initTestInputs(const bool mirror_x, const int number_of_copies, Inputs &inputs) {
inputs.temperature.x_offset = 0.0;
inputs.temperature.y_offset = 1.0 * pow(10, -6);
inputs.temperature.mirror_x = mirror_x;
inputs.temperature.mirror_y = false;
inputs.temperature.temporal_offset = 100.0;
inputs.temperature.number_of_copies = number_of_copies;
}

// Default grid struct - manually set up domain for test
Grid grid;
// Initialize test grid for InitTemperatureFromFinch and InitTemperatureFromFile
void initTestGrid(const int id, const int np, Grid &grid) {
grid.deltax = 1.0 * pow(10, -6);
grid.x_min = -2.0 * pow(10, -6);
grid.nx = 2;
grid.x_max = grid.x_min + grid.deltax * (grid.nx - 1);
grid.y_min = 0.0;
grid.ny_local = 3;
grid.ny = grid.ny_local * np;
grid.y_offset = id * grid.ny_local;
grid.y_max = grid.y_min + grid.deltax * (grid.ny - 1);
grid.z_min = 0.0;
grid.z_min_layer[0] = grid.z_min;
grid.nz = np;
Expand All @@ -395,6 +387,26 @@ void testInitTemperatureFromFinch(const bool mirror_x, const int number_of_copie
grid.number_of_layers = 1;
grid.layer_height = 0;
grid.layer_range = std::make_pair(0, grid.domain_size);
}

// Test storing temperature data from Finch on the correct ExaCA ranks, optionally mirroring and translating the data
void testInitTemperatureFromFinch(const bool mirror_x, const int number_of_copies) {

using memory_space = TEST_MEMSPACE;
using view_type_coupled = Kokkos::View<double **, Kokkos::LayoutLeft, Kokkos::HostSpace>;

int id, np;
// Get number of processes
MPI_Comm_size(MPI_COMM_WORLD, &np);
// Get individual process ID
MPI_Comm_rank(MPI_COMM_WORLD, &id);

// Default inputs struct - manually set temperature values for test
Inputs inputs;
// Default grid struct - manually set up domain for test
Grid grid;
initTestInputs(mirror_x, number_of_copies, inputs);
initTestGrid(id, np, grid);

// Create dummy Finch temperature data stored on various ranks, to be mapped to ExaCA ranks
view_type_coupled input_temperature_data(Kokkos::ViewAllocateWithoutInitializing("FinchData"), grid.nx * np, 6);
Expand Down Expand Up @@ -435,29 +447,10 @@ void testInitTemperatureFromFile(const bool mirror_x, const int number_of_copies

// Default inputs struct - manually set temperature values for test
Inputs inputs;
inputs.temperature.x_offset = 0.0;
inputs.temperature.y_offset = 1.0 * pow(10, -6);
inputs.temperature.mirror_x = mirror_x;
inputs.temperature.mirror_y = false;
inputs.temperature.temporal_offset = 100.0;
inputs.temperature.number_of_copies = number_of_copies;

// Default grid struct - manually set up domain for test
Grid grid;
grid.deltax = 1.0 * pow(10, -6);
grid.x_min = -2.0 * pow(10, -6);
grid.nx = 2;
grid.y_min = 0.0;
grid.ny_local = 3;
grid.y_offset = id * grid.ny_local;
grid.z_min = 0.0;
grid.z_min_layer[0] = grid.z_min;
grid.nz = np;
grid.domain_size = grid.nx * grid.ny_local * grid.nz;
grid.domain_size_all_layers = grid.domain_size;
grid.number_of_layers = 1;
grid.layer_height = 0;
grid.layer_range = std::make_pair(0, grid.domain_size);
initTestInputs(mirror_x, number_of_copies, inputs);
initTestGrid(id, np, grid);

// Create dummy file temperature data on rank 0, including data to be mapped to other ExaCA ranks
if (id == 0) {
Expand Down
Loading