From 7b18f79cca9a2e30dc98ba7022cc238b792e8d3c Mon Sep 17 00:00:00 2001 From: Harshada Balasubramanian <harshada.balasubramanian@mpimet.mpg.de> Date: Mon, 24 Feb 2025 14:42:04 +0100 Subject: [PATCH 1/7] restructure --- src/support/CMakeLists.txt | 3 +- src/support/mo_lib_loopindices.cpp | 100 ++++++++++++++++++----------- src/support/mo_lib_loopindices.hpp | 20 +++--- src/support/mo_math_utilities.cpp | 16 +++-- src/support/mo_math_utilities.hpp | 8 +-- src/support/support_bindings.cpp | 41 ++++++++++++ src/support/support_bindings.h | 35 ++++++++++ test/c/test_tdma_solver.cpp | 4 +- 8 files changed, 165 insertions(+), 62 deletions(-) create mode 100644 src/support/support_bindings.cpp create mode 100644 src/support/support_bindings.h diff --git a/src/support/CMakeLists.txt b/src/support/CMakeLists.txt index e78fc16..44f60aa 100644 --- a/src/support/CMakeLists.txt +++ b/src/support/CMakeLists.txt @@ -19,7 +19,8 @@ add_library( mo_math_types.f90 mo_math_utilities.cpp mo_math_utilities.F90 - mo_random_number_generators.F90) + mo_random_number_generators.F90 + support_bindings.cpp) add_library(${PROJECT_NAME}::support ALIAS iconmath-support) diff --git a/src/support/mo_lib_loopindices.cpp b/src/support/mo_lib_loopindices.cpp index e6d9d21..3fb0a6a 100644 --- a/src/support/mo_lib_loopindices.cpp +++ b/src/support/mo_lib_loopindices.cpp @@ -11,47 +11,75 @@ #include <algorithm> // For std::max -extern "C" { - // get_indices_c_lib function - void get_indices_c_lib(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, - int &i_startidx_out, int &i_endidx_out) { - if (i_blk == i_startblk) { - i_startidx_out = std::max(1, i_startidx_in); - i_endidx_out = nproma; - if (i_blk == i_endblk) { - i_endidx_out = i_endidx_in; - } - } else if (i_blk == i_endblk) { - i_startidx_out = 1; +// get_indices_c_lib function +void get_indices_c_lib(const int i_startidx_in, const int i_endidx_in, const int nproma, + const int i_blk, const int i_startblk, const int i_endblk, + int &i_startidx_out, int &i_endidx_out, const bool called_from_cpp=false) { + + //Since code is ported incremently from Fortran to C++, depending on where the function is called from + //(either fortran or c++), the first index should be either 0 or 1. + int first_index; + if (called_from_cpp) + first_index = 0; + else + first_index = 1; + + if (i_blk == i_startblk) { + i_startidx_out = std::max(first_index, i_startidx_in); + i_endidx_out = nproma; + if (i_blk == i_endblk) { i_endidx_out = i_endidx_in; - } else { - i_startidx_out = 1; - i_endidx_out = nproma; } + } else if (i_blk == i_endblk) { + i_startidx_out = first_index; + i_endidx_out = i_endidx_in; + } else { + i_startidx_out = first_index; + i_endidx_out = nproma; } +} - // get_indices_e_lib function - void get_indices_e_lib(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, - int &i_startidx_out, int &i_endidx_out) { - i_startidx_out = (i_blk != i_startblk) ? 1 : std::max(1, i_startidx_in); - i_endidx_out = (i_blk != i_endblk) ? nproma : i_endidx_in; - } +// get_indices_e_lib function +void get_indices_e_lib(const int i_startidx_in, const int i_endidx_in, const int nproma, + const int i_blk, const int i_startblk, const int i_endblk, + int &i_startidx_out, int &i_endidx_out, const bool called_from_cpp=false) { + + //Since code is ported incremently from Fortran to C++, depending on where the function is called from, + //the first index should be either 0 or 1. + int first_index; + if (called_from_cpp) + first_index = 0; + else + first_index = 1; + + i_startidx_out = (i_blk != i_startblk) ? first_index : std::max(first_index, i_startidx_in); + i_endidx_out = (i_blk != i_endblk) ? nproma : i_endidx_in; +} + +// get_indices_v_lib function +void get_indices_v_lib(const int i_startidx_in, const int i_endidx_in, const int nproma, + const int i_blk, const int i_startblk, const int i_endblk, + int &i_startidx_out, int &i_endidx_out, const bool called_from_cpp=false) { + + //Since code is ported incremently from Fortran to C++, depending on where the function is called from, + //the first index should be either 0 or 1. + int first_index; + if (called_from_cpp) + first_index = 0; + else + first_index = 1; - // get_indices_v_lib function - void get_indices_v_lib(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, - int &i_startidx_out, int &i_endidx_out) { - if (i_blk == i_startblk) { - i_startidx_out = i_startidx_in; - i_endidx_out = nproma; - if (i_blk == i_endblk) { - i_endidx_out = i_endidx_in; - } - } else if (i_blk == i_endblk) { - i_startidx_out = 1; + if (i_blk == i_startblk) { + i_startidx_out = i_startidx_in; + i_endidx_out = nproma; + if (i_blk == i_endblk) { i_endidx_out = i_endidx_in; - } else { - i_startidx_out = 1; - i_endidx_out = nproma; } + } else if (i_blk == i_endblk) { + i_startidx_out = first_index; + i_endidx_out = i_endidx_in; + } else { + i_startidx_out = first_index; + i_endidx_out = nproma; } -} +} \ No newline at end of file diff --git a/src/support/mo_lib_loopindices.hpp b/src/support/mo_lib_loopindices.hpp index 03eb977..ecc2422 100644 --- a/src/support/mo_lib_loopindices.hpp +++ b/src/support/mo_lib_loopindices.hpp @@ -8,15 +8,17 @@ // See LICENSES/ for license information // SPDX-License-Identifier: BSD-3-Clause // --------------------------------------------------------------- +#pragma once -extern "C" { - // get_indices_c_lib function - void get_indices_c_lib(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, - int &i_startidx_out, int &i_endidx_out); +void get_indices_c_lib(const int i_startidx_in, const int i_endidx_in, const int nproma, + const int i_blk, const int i_startblk, const int i_endblk, + int &i_startidx_out, int &i_endidx_out, const bool called_from_cpp=false); - void get_indices_e_lib(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, - int &i_startidx_out, int &i_endidx_out); +void get_indices_e_lib(const int i_startidx_in, const int i_endidx_in, const int nproma, + const int i_blk, const int i_startblk, const int i_endblk, + int &i_startidx_out, int &i_endidx_out, const bool called_from_cpp=false); - void get_indices_v_lib(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, - int &i_startidx_out, int &i_endidx_out); -} +void get_indices_v_lib(const int i_startidx_in, const int i_endidx_in, const int nproma, + const int i_blk, const int i_startblk, const int i_endblk, + int &i_startidx_out, int &i_endidx_out, const bool called_from_cpp=false); + \ No newline at end of file diff --git a/src/support/mo_math_utilities.cpp b/src/support/mo_math_utilities.cpp index 6a60f2c..5859b9d 100644 --- a/src/support/mo_math_utilities.cpp +++ b/src/support/mo_math_utilities.cpp @@ -75,11 +75,13 @@ void tdma_solver_vec(const T* a, const T* b, const T* c, const T* d, std::cout << "Elapsed time for tdma_solver_vec (Kokkos): " << elapsed_time.count() << " seconds" << std::endl; } -extern "C" { +template +void tdma_solver_vec<double>(const double* a, const double* b, const double* c, const double* d, + int slev, int elev, int startidx, int endidx, + int nrows, int ncols, double* varout); + +template +void tdma_solver_vec<float>(const float* a, const float* b, const float* c, const float* d, + int slev, int elev, int startidx, int endidx, + int nrows, int ncols, float* varout); - void tdma_solver_vec_double(const double* a, const double* b, const double* c, const double* d, - int slev, int elev, int startidx, int endidx, - int nrows, int ncols, double* varout) { - tdma_solver_vec<double>(a, b, c, d, slev, elev, startidx, endidx, nrows, ncols, varout); - } -} diff --git a/src/support/mo_math_utilities.hpp b/src/support/mo_math_utilities.hpp index 4ee5dc9..a3f3ba1 100644 --- a/src/support/mo_math_utilities.hpp +++ b/src/support/mo_math_utilities.hpp @@ -17,10 +17,4 @@ template <typename T> void tdma_solver_vec(const T* a, const T* b, const T* c, const T* d, int slev, int elev, int startidx, int endidx, - int nrows, int ncols, T* varout); - -extern "C" { - void tdma_solver_vec_double(const double* a, const double* b, const double* c, const double* d, - int slev, int elev, int startidx, int endidx, - int nrows, int ncols, double* varout); -} + int nrows, int ncols, T* varout); \ No newline at end of file diff --git a/src/support/support_bindings.cpp b/src/support/support_bindings.cpp new file mode 100644 index 0000000..6a2c5f8 --- /dev/null +++ b/src/support/support_bindings.cpp @@ -0,0 +1,41 @@ +// ICON +// +// --------------------------------------------------------------- +// Copyright (C) 2004-2024, DWD, MPI-M, DKRZ, KIT, ETH, MeteoSwiss +// Contact information: icon-model.org +// +// See AUTHORS.TXT for a list of authors +// See LICENSES/ for license information +// SPDX-License-Identifier: BSD-3-Clause +// --------------------------------------------------------------- + +#include "support_bindings.h" +#include "mo_lib_loopindices.hpp" +#include "mo_math_utilities.hpp" + + +// mo_loop_indices.F90 +void get_indices_c_lib_c(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, + int &i_startidx_out, int &i_endidx_out){ + get_indices_c_lib(i_startidx_in, i_endidx_in, nproma, i_blk, i_startblk, + i_endblk, i_startidx_out, i_endidx_out); +} +void get_indices_e_lib_c(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, + int &i_startidx_out, int &i_endidx_out){ + get_indices_e_lib(i_startidx_in, i_endidx_in, nproma,i_blk, i_startblk, i_endblk, + i_startidx_out, i_endidx_out); +} + +void get_indices_v_lib_c(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, + int &i_startidx_out, int &i_endidx_out){ + get_indices_v_lib(i_startidx_in, i_endidx_in, nproma, i_blk, i_startblk, i_endblk, + i_startidx_out,i_endidx_out); +} + +//mo_math_utilities.F90 +void tdma_solver_vec_c(const wp* a, const wp* b, const wp* c, const wp* d, + int slev, int elev, int startidx, int endidx, + int nrows, int ncols, wp* varout) { + tdma_solver_vec<wp>(a, b, c, d, slev, elev, startidx, endidx, nrows, ncols, varout); + +} \ No newline at end of file diff --git a/src/support/support_bindings.h b/src/support/support_bindings.h new file mode 100644 index 0000000..55e96dc --- /dev/null +++ b/src/support/support_bindings.h @@ -0,0 +1,35 @@ +// ICON +// +// --------------------------------------------------------------- +// Copyright (C) 2004-2024, DWD, MPI-M, DKRZ, KIT, ETH, MeteoSwiss +// Contact information: icon-model.org +// +// See AUTHORS.TXT for a list of authors +// See LICENSES/ for license information +// SPDX-License-Identifier: BSD-3-Clause +// --------------------------------------------------------------- +#pragma once + +#ifdef __SINGLE_PRECISION + using wp = single; +#else + using wp = double; +#endif + +extern "C" { + // mo_loop_indices.F90 + void get_indices_c_lib_c(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, + int &i_startidx_out, int &i_endidx_out); + + void get_indices_e_lib_c(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, + int &i_startidx_out, int &i_endidx_out); + + void get_indices_v_lib_c(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, + int &i_startidx_out, int &i_endidx_out); + + //mo_math_utilities.F90 + void tdma_solver_vec_c(const wp* a, const wp* b, const wp* c, const wp* d, + int slev, int elev, int startidx, int endidx, + int nrows, int ncols, wp* varout); + +} diff --git a/test/c/test_tdma_solver.cpp b/test/c/test_tdma_solver.cpp index 8f120ef..4e09ff3 100644 --- a/test/c/test_tdma_solver.cpp +++ b/test/c/test_tdma_solver.cpp @@ -51,7 +51,7 @@ protected: TEST_F(TDMASolverTestFixture, FullTest) { // Call the solver over the full range: - tdma_solver_vec_double(a.data(), b.data(), c.data(), d.data(), + tdma_solver_vec<double>(a.data(), b.data(), c.data(), d.data(), 0, n, 0, n, n, n, x.data()); // Compute the sum of all elements in the output matrix. @@ -71,7 +71,7 @@ TEST_F(TDMASolverTestFixture, FullTest) { TEST_F(TDMASolverTestFixture, PartialTest) { // Call the solver for a partial region: // For C++: slev = 1, elev = n-1, startidx = 1, endidx = n-1. - tdma_solver_vec_double(a.data(), b.data(), c.data(), d.data(), + tdma_solver_vec<double>(a.data(), b.data(), c.data(), d.data(), 1, n - 1, 1, n - 1, n, n, x.data()); // Compute the sum over a region -- GitLab From 13f1c14e92a22c12999461da80037111c4179bea Mon Sep 17 00:00:00 2001 From: Harshada Balasubramanian <harshada.balasubramanian@mpimet.mpg.de> Date: Mon, 24 Feb 2025 14:44:27 +0100 Subject: [PATCH 2/7] fix typo --- src/support/mo_lib_loopindices.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/support/mo_lib_loopindices.cpp b/src/support/mo_lib_loopindices.cpp index 3fb0a6a..79e8895 100644 --- a/src/support/mo_lib_loopindices.cpp +++ b/src/support/mo_lib_loopindices.cpp @@ -16,7 +16,7 @@ void get_indices_c_lib(const int i_startidx_in, const int i_endidx_in, const int const int i_blk, const int i_startblk, const int i_endblk, int &i_startidx_out, int &i_endidx_out, const bool called_from_cpp=false) { - //Since code is ported incremently from Fortran to C++, depending on where the function is called from + //Since code is ported incrementally from Fortran to C++, depending on where the function is called from //(either fortran or c++), the first index should be either 0 or 1. int first_index; if (called_from_cpp) @@ -44,7 +44,7 @@ void get_indices_e_lib(const int i_startidx_in, const int i_endidx_in, const int const int i_blk, const int i_startblk, const int i_endblk, int &i_startidx_out, int &i_endidx_out, const bool called_from_cpp=false) { - //Since code is ported incremently from Fortran to C++, depending on where the function is called from, + //Since code is ported incrementally from Fortran to C++, depending on where the function is called from, //the first index should be either 0 or 1. int first_index; if (called_from_cpp) @@ -61,7 +61,7 @@ void get_indices_v_lib(const int i_startidx_in, const int i_endidx_in, const int const int i_blk, const int i_startblk, const int i_endblk, int &i_startidx_out, int &i_endidx_out, const bool called_from_cpp=false) { - //Since code is ported incremently from Fortran to C++, depending on where the function is called from, + //Since code is ported incrementally from Fortran to C++, depending on where the function is called from, //the first index should be either 0 or 1. int first_index; if (called_from_cpp) -- GitLab From ea47fe7fe11febd15003ddd332d15f408cc8a881 Mon Sep 17 00:00:00 2001 From: Harshada Balasubramanian <harshada.balasubramanian@mpimet.mpg.de> Date: Mon, 24 Feb 2025 15:19:34 +0100 Subject: [PATCH 3/7] make the default value true --- src/support/mo_lib_loopindices.cpp | 2 +- src/support/mo_lib_loopindices.hpp | 6 +++--- src/support/support_bindings.cpp | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/support/mo_lib_loopindices.cpp b/src/support/mo_lib_loopindices.cpp index 79e8895..0fb79fb 100644 --- a/src/support/mo_lib_loopindices.cpp +++ b/src/support/mo_lib_loopindices.cpp @@ -14,7 +14,7 @@ // get_indices_c_lib function void get_indices_c_lib(const int i_startidx_in, const int i_endidx_in, const int nproma, const int i_blk, const int i_startblk, const int i_endblk, - int &i_startidx_out, int &i_endidx_out, const bool called_from_cpp=false) { + int &i_startidx_out, int &i_endidx_out, const bool called_from_cpp=true) { //Since code is ported incrementally from Fortran to C++, depending on where the function is called from //(either fortran or c++), the first index should be either 0 or 1. diff --git a/src/support/mo_lib_loopindices.hpp b/src/support/mo_lib_loopindices.hpp index ecc2422..5136c6a 100644 --- a/src/support/mo_lib_loopindices.hpp +++ b/src/support/mo_lib_loopindices.hpp @@ -12,13 +12,13 @@ void get_indices_c_lib(const int i_startidx_in, const int i_endidx_in, const int nproma, const int i_blk, const int i_startblk, const int i_endblk, - int &i_startidx_out, int &i_endidx_out, const bool called_from_cpp=false); + int &i_startidx_out, int &i_endidx_out, const bool called_from_cpp=true); void get_indices_e_lib(const int i_startidx_in, const int i_endidx_in, const int nproma, const int i_blk, const int i_startblk, const int i_endblk, - int &i_startidx_out, int &i_endidx_out, const bool called_from_cpp=false); + int &i_startidx_out, int &i_endidx_out, const bool called_from_cpp=true); void get_indices_v_lib(const int i_startidx_in, const int i_endidx_in, const int nproma, const int i_blk, const int i_startblk, const int i_endblk, - int &i_startidx_out, int &i_endidx_out, const bool called_from_cpp=false); + int &i_startidx_out, int &i_endidx_out, const bool called_from_cpp=true); \ No newline at end of file diff --git a/src/support/support_bindings.cpp b/src/support/support_bindings.cpp index 6a2c5f8..44b0610 100644 --- a/src/support/support_bindings.cpp +++ b/src/support/support_bindings.cpp @@ -18,18 +18,18 @@ void get_indices_c_lib_c(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, int &i_startidx_out, int &i_endidx_out){ get_indices_c_lib(i_startidx_in, i_endidx_in, nproma, i_blk, i_startblk, - i_endblk, i_startidx_out, i_endidx_out); + i_endblk, i_startidx_out, i_endidx_out, false); } void get_indices_e_lib_c(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, int &i_startidx_out, int &i_endidx_out){ get_indices_e_lib(i_startidx_in, i_endidx_in, nproma,i_blk, i_startblk, i_endblk, - i_startidx_out, i_endidx_out); + i_startidx_out, i_endidx_out, false); } void get_indices_v_lib_c(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, int &i_startidx_out, int &i_endidx_out){ get_indices_v_lib(i_startidx_in, i_endidx_in, nproma, i_blk, i_startblk, i_endblk, - i_startidx_out,i_endidx_out); + i_startidx_out,i_endidx_out, false); } //mo_math_utilities.F90 -- GitLab From b069404cefec0a911c4918bbd3d984986995927e Mon Sep 17 00:00:00 2001 From: Harshada Balasubramanian <harshada.balasubramanian@mpimet.mpg.de> Date: Mon, 24 Feb 2025 15:26:25 +0100 Subject: [PATCH 4/7] remove _c --- src/support/support_bindings.cpp | 9 +++++---- src/support/support_bindings.h | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/support/support_bindings.cpp b/src/support/support_bindings.cpp index 44b0610..b3d98e4 100644 --- a/src/support/support_bindings.cpp +++ b/src/support/support_bindings.cpp @@ -15,25 +15,26 @@ // mo_loop_indices.F90 -void get_indices_c_lib_c(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, +// C wrappers for C++ functionality +void get_indices_c_lib(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, int &i_startidx_out, int &i_endidx_out){ get_indices_c_lib(i_startidx_in, i_endidx_in, nproma, i_blk, i_startblk, i_endblk, i_startidx_out, i_endidx_out, false); } -void get_indices_e_lib_c(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, +void get_indices_e_lib(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, int &i_startidx_out, int &i_endidx_out){ get_indices_e_lib(i_startidx_in, i_endidx_in, nproma,i_blk, i_startblk, i_endblk, i_startidx_out, i_endidx_out, false); } -void get_indices_v_lib_c(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, +void get_indices_v_lib(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, int &i_startidx_out, int &i_endidx_out){ get_indices_v_lib(i_startidx_in, i_endidx_in, nproma, i_blk, i_startblk, i_endblk, i_startidx_out,i_endidx_out, false); } //mo_math_utilities.F90 -void tdma_solver_vec_c(const wp* a, const wp* b, const wp* c, const wp* d, +void tdma_solver_vec(const wp* a, const wp* b, const wp* c, const wp* d, int slev, int elev, int startidx, int endidx, int nrows, int ncols, wp* varout) { tdma_solver_vec<wp>(a, b, c, d, slev, elev, startidx, endidx, nrows, ncols, varout); diff --git a/src/support/support_bindings.h b/src/support/support_bindings.h index 55e96dc..b3f4258 100644 --- a/src/support/support_bindings.h +++ b/src/support/support_bindings.h @@ -18,17 +18,17 @@ extern "C" { // mo_loop_indices.F90 - void get_indices_c_lib_c(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, + void get_indices_c_lib(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, int &i_startidx_out, int &i_endidx_out); - void get_indices_e_lib_c(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, + void get_indices_e_lib(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, int &i_startidx_out, int &i_endidx_out); - void get_indices_v_lib_c(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, + void get_indices_v_lib(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, int &i_startidx_out, int &i_endidx_out); //mo_math_utilities.F90 - void tdma_solver_vec_c(const wp* a, const wp* b, const wp* c, const wp* d, + void tdma_solver_vec(const wp* a, const wp* b, const wp* c, const wp* d, int slev, int elev, int startidx, int endidx, int nrows, int ncols, wp* varout); -- GitLab From 5664299ee8b0d941dbf745285e09fff4325d361e Mon Sep 17 00:00:00 2001 From: Harshada Balasubramanian <harshada.balasubramanian@mpimet.mpg.de> Date: Mon, 24 Feb 2025 15:51:57 +0100 Subject: [PATCH 5/7] dp sp version --- src/support/mo_math_utilities.F90 | 8 ++++---- src/support/support_bindings.cpp | 18 +++++++++++++----- src/support/support_bindings.h | 14 ++++++-------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/support/mo_math_utilities.F90 b/src/support/mo_math_utilities.F90 index 168ec26..d1cf120 100644 --- a/src/support/mo_math_utilities.F90 +++ b/src/support/mo_math_utilities.F90 @@ -82,7 +82,7 @@ MODULE mo_math_utilities #ifndef __USE_CPP_BINDINGS PUBLIC :: tdma_solver_vec #else - PUBLIC :: tdma_solver_vec_double + PUBLIC :: tdma_solver_vec_dp #endif PUBLIC :: check_orientation @@ -246,14 +246,14 @@ CONTAINS ! C++ binding for tdma_solver_vec INTERFACE - SUBROUTINE tdma_solver_vec_double(a, b, c, d, slev, elev, startidx, endidx, nrows, ncols, varout, opt_acc_queue) & - BIND(C, NAME="tdma_solver_vec_double") + SUBROUTINE tdma_solver_vec_dp(a, b, c, d, slev, elev, startidx, endidx, nrows, ncols, varout, opt_acc_queue) & + BIND(C, NAME="tdma_solver_vec_dp") IMPORT :: c_double, c_int REAL(c_double), INTENT(IN) :: a(*), b(*), c(*), d(*) INTEGER(c_int), VALUE :: slev, elev, startidx, endidx, nrows, ncols REAL(c_double), INTENT(OUT) :: varout(*) INTEGER(c_int), OPTIONAL :: opt_acc_queue - END SUBROUTINE tdma_solver_vec_double + END SUBROUTINE tdma_solver_vec_dp END INTERFACE CONTAINS diff --git a/src/support/support_bindings.cpp b/src/support/support_bindings.cpp index b3d98e4..664fc1e 100644 --- a/src/support/support_bindings.cpp +++ b/src/support/support_bindings.cpp @@ -33,10 +33,18 @@ void get_indices_v_lib(int i_startidx_in, int i_endidx_in, int nproma, int i_blk i_startidx_out,i_endidx_out, false); } -//mo_math_utilities.F90 -void tdma_solver_vec(const wp* a, const wp* b, const wp* c, const wp* d, +void tdma_solver_vec_dp(const double* a, const double* b, const double* c, const double* d, int slev, int elev, int startidx, int endidx, - int nrows, int ncols, wp* varout) { - tdma_solver_vec<wp>(a, b, c, d, slev, elev, startidx, endidx, nrows, ncols, varout); + int nrows, int ncols, double* varout){ + + tdma_solver_vec<double>(a, b, c, d, slev, elev, startidx, endidx, nrows, ncols, varout); -} \ No newline at end of file +} + +void tdma_solver_vec_sp(const float* a, const float* b, const float* c, const float* d, + int slev, int elev, int startidx, int endidx, + int nrows, int ncols, float* varout){ + + tdma_solver_vec<float>(a, b, c, d, slev, elev, startidx, endidx, nrows, ncols, varout); + +} diff --git a/src/support/support_bindings.h b/src/support/support_bindings.h index b3f4258..df452e4 100644 --- a/src/support/support_bindings.h +++ b/src/support/support_bindings.h @@ -10,12 +10,6 @@ // --------------------------------------------------------------- #pragma once -#ifdef __SINGLE_PRECISION - using wp = single; -#else - using wp = double; -#endif - extern "C" { // mo_loop_indices.F90 void get_indices_c_lib(int i_startidx_in, int i_endidx_in, int nproma, int i_blk, int i_startblk, int i_endblk, @@ -28,8 +22,12 @@ extern "C" { int &i_startidx_out, int &i_endidx_out); //mo_math_utilities.F90 - void tdma_solver_vec(const wp* a, const wp* b, const wp* c, const wp* d, + void tdma_solver_vec_dp(const double* a, const double* b, const double* c, const double* d, int slev, int elev, int startidx, int endidx, - int nrows, int ncols, wp* varout); + int nrows, int ncols, double* varout); + + void tdma_solver_vec_sp(const float* a, const float* b, const float* c, const float* d, + int slev, int elev, int startidx, int endidx, + int nrows, int ncols, float* varout); } -- GitLab From c136e438eb8e076c25a9b2f56bc80a7b535d50f0 Mon Sep 17 00:00:00 2001 From: Harshada Balasubramanian <harshada.balasubramanian@mpimet.mpg.de> Date: Mon, 24 Feb 2025 16:34:28 +0100 Subject: [PATCH 6/7] small fix --- src/support/mo_lib_loopindices.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/support/mo_lib_loopindices.cpp b/src/support/mo_lib_loopindices.cpp index 0fb79fb..30c82bd 100644 --- a/src/support/mo_lib_loopindices.cpp +++ b/src/support/mo_lib_loopindices.cpp @@ -42,7 +42,7 @@ void get_indices_c_lib(const int i_startidx_in, const int i_endidx_in, const int // get_indices_e_lib function void get_indices_e_lib(const int i_startidx_in, const int i_endidx_in, const int nproma, const int i_blk, const int i_startblk, const int i_endblk, - int &i_startidx_out, int &i_endidx_out, const bool called_from_cpp=false) { + int &i_startidx_out, int &i_endidx_out, const bool called_from_cpp=true) { //Since code is ported incrementally from Fortran to C++, depending on where the function is called from, //the first index should be either 0 or 1. @@ -59,7 +59,7 @@ void get_indices_e_lib(const int i_startidx_in, const int i_endidx_in, const int // get_indices_v_lib function void get_indices_v_lib(const int i_startidx_in, const int i_endidx_in, const int nproma, const int i_blk, const int i_startblk, const int i_endblk, - int &i_startidx_out, int &i_endidx_out, const bool called_from_cpp=false) { + int &i_startidx_out, int &i_endidx_out, const bool called_from_cpp=true) { //Since code is ported incrementally from Fortran to C++, depending on where the function is called from, //the first index should be either 0 or 1. -- GitLab From 49ff25f20fae06dd32a0d3ebff5ce90887966097 Mon Sep 17 00:00:00 2001 From: Pradipta Samanta <samanta@dkrz.de> Date: Mon, 24 Feb 2025 18:23:49 +0100 Subject: [PATCH 7/7] fixed the test file for mo_lib_interpolation_vector --- test/c/test_interpolation_vector.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/test/c/test_interpolation_vector.cpp b/test/c/test_interpolation_vector.cpp index a33673c..0eb5a8d 100644 --- a/test/c/test_interpolation_vector.cpp +++ b/test/c/test_interpolation_vector.cpp @@ -75,12 +75,6 @@ TEST(Edges2CellsTest, DPTest) { // Check that for each computed cell in p_u_out and p_v_out, the value is 6. // This is because for each cell, the kernel adds 6 terms of 1*1. - p_u_ref[0] = 0.0; - p_u_ref[8] = 0.0; - p_u_ref[10] = 0.0; - p_v_ref[0] = 0.0; - p_v_ref[8] = 0.0; - p_v_ref[10] = 0.0; for (size_t idx = 0; idx < p_u_out.size(); ++idx) { EXPECT_NEAR(p_u_out[idx], p_u_ref[idx], 1e-12); EXPECT_NEAR(p_v_out[idx], p_v_ref[idx], 1e-12); @@ -120,12 +114,6 @@ TEST(Edges2CellsTest, SPTest) { nproma, nlev, nblks_e, nblks_c); - p_u_ref[0] = 0.0f; - p_u_ref[8] = 0.0f; - p_u_ref[10] = 0.0f; - p_v_ref[0] = 0.0f; - p_v_ref[8] = 0.0f; - p_v_ref[10] = 0.0f; // Verify that every computed output equals 6. for (size_t idx = 0; idx < p_u_out.size(); ++idx) { EXPECT_NEAR(p_u_out[idx], p_u_ref[idx], 1e-5f); -- GitLab