Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • icon-libraries/libiconmath
1 result
Show changes
Commits on Source (42)
Showing
with 3948 additions and 11 deletions
......@@ -37,3 +37,4 @@ with section("lint"):
local_var_pattern = '[a-zA-Z][0-9a-zA-z_]+'
private_var_pattern = '[a-z][a-z0-9_]+'
public_var_pattern = '[A-Z][0-9a-zA-Z_]+'
global_var_pattern = '[A-Z][0-9a-zA-Z_]+'
......@@ -8,6 +8,12 @@ cmake_install.cmake
iconmath-config-version.cmake
iconmath-config.cmake
iconmath-targets.cmake
KokkosConfig.cmake
KokkosConfigVersion.cmake
KokkosTargets.cmake
KokkosConfigCommon.cmake
Kokkos_Version_Info.cpp
Kokkos_Version_Info.hpp
# Build stage files:
*.L
......@@ -22,4 +28,5 @@ iconmath_Tests
# Test stage files:
/**/Testing/*
iconmath_Tests
run_tests.f90
......@@ -14,7 +14,9 @@ cmake_minimum_required(VERSION 3.18)
project(
iconmath
VERSION 1.0.0
LANGUAGES Fortran)
LANGUAGES Fortran CXX)
set(CMAKE_CXX_STANDARD 17)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(BUILD_TESTING "Build tests" ON)
......@@ -23,9 +25,11 @@ option(BUILD_ICONMATH_HORIZONTAL "Build horizontal library" ON)
option(IM_ENABLE_MIXED_PRECISION "Enable mixed precision" OFF)
option(IM_ENABLE_LOOP_EXCHANGE "Enable loop exchange" OFF)
option(IM_USE_CPP_BINDINGS "Use C++ bindings" OFF)
option(IM_ENABLE_DIM_SWAP "Enable dimension swap" OFF)
option(IM_ENABLE_OPENACC "Enable OpenACC support" OFF)
option(IM_ENABLE_OPENMP "Enable OpenMP support" OFF)
set(IM_ENABLE_GPU OFF CACHE STRING "Enable Kokkos GPU support for arch. Valid values: OFF, nvidia-sm80")
# GNUInstallDirs issues a warning if CMAKE_SIZEOF_VOID_P is not defined, which
# is the case with NAG. One way to circumvent that is to enable C language for
......@@ -107,6 +111,32 @@ else()
endif()
endif()
include(FetchContent)
# configure kokkos 4.4 repository link
FetchContent_Declare(
kokkos
URL https://github.com/kokkos/kokkos/releases/download/4.4.01/kokkos-4.4.01.tar.gz
URL_HASH MD5=eafd0d42c9831858aa84fde78576644c)
# disable build of C++23 mdspan experimental support for now
set(Kokkos_ENABLE_IMPL_MDSPAN OFF CACHE BOOL "Experimental mdspan support")
# by default, build the Kokkos serial backend for CPU
set(Kokkos_ENABLE_SERIAL ON CACHE BOOL "Kokkos Serial backend")
set(Kokkos_ARCH_NATIVE ON CACHE BOOL "Kokkos native architecture optimisations")
if ("${IM_ENABLE_GPU}" STREQUAL "nvidia-sm80")
# NVIDIA A100
set(Kokkos_ENABLE_CUDA ON CACHE BOOL "Kokkos CUDA backend")
set(Kokkos_ARCH_AMPERE80 ON CACHE BOOL "CUDA architecture: Ampere cc80")
endif()
if (${IM_ENABLE_OPENMP})
set(Kokkos_ENABLE_OPENMP ON CACHE BOOL "Kokkos OpenMP backend")
endif()
FetchContent_MakeAvailable(kokkos)
add_subdirectory(src)
# Allow for 'make test' even if the tests are disabled:
......
[default]
extend-ignore-re = [
".*_pn",
"f4dout_*",
]
extend-ignore-words-re = [
"Comput",
......@@ -10,6 +11,7 @@ extend-ignore-words-re = [
Wirth = "Wirth" # author name
nin = "nin" # number of inputs
Pilar = "Pilar" # author name
Comput = "Comput" # abbreviation for Computational
[default.extend-identifiers]
f4dout = "f4dout" # file name
......@@ -53,6 +53,9 @@ function(get_library package_target tag)
if(NOT TARGET ${target})
find_package(${package} CONFIG QUIET)
if(NOT ${package}_FOUND)
if("${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.24")
cmake_policy(SET CMP0135 NEW)
endif()
include(FetchContent)
if(NOT ARG_QUIET)
......@@ -61,7 +64,7 @@ function(get_library package_target tag)
FetchContent_Declare(
lib${package}
GIT_REPOSITORY git@gitlab.dkrz.de:icon-libraries/lib${package}.git
GIT_REPOSITORY https://gitlab.dkrz.de/icon-libraries/lib${package}.git
GIT_TAG ${tag})
set(save_BUILD_TESTING "${BUILD_TESTING}")
......
......@@ -11,6 +11,7 @@
add_library(
iconmath-horizontal
mo_lib_divrot.cpp
mo_lib_divrot.F90
mo_lib_laplace.F90
mo_lib_gradients.F90)
......@@ -39,7 +40,9 @@ if(IM_ENABLE_OPENACC)
# If _OPENACC is defined, assume that the required compiler flags are already
# provided, e.g. in CMAKE_Fortran_FLAGS:
if(NOT HAS_OPENACC_MACRO)
target_compile_options(iconmath-horizontal PRIVATE ${OpenACC_Fortran_OPTIONS})
target_compile_options(iconmath-horizontal
PRIVATE
$<$<COMPILE_LANGUAGE:Fortran>:${OpenACC_Fortran_OPTIONS}>)
# This make sures that unit tests (FortUTF) compiles without the need of
# passing OpenACC compile option.
target_link_libraries(iconmath-horizontal PRIVATE OpenACC::OpenACC_Fortran)
......@@ -52,11 +55,22 @@ target_include_directories(
# Path to the Fortran modules:
$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:Fortran>:${Fortran_MODULE_DIRECTORY}>>
$<INSTALL_INTERFACE:$<$<COMPILE_LANGUAGE:Fortran>:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>>
# Path to the internal C/C++ headers (for testing): Requires CMake 3.15+ for
# multiple compile languages
# https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html
$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:C,CXX>:${PROJECT_SOURCE_DIR}/src>>
PRIVATE
# Path to config.h (for C and C++ only): Requires CMake 3.15+ for multiple
# compile languages
# https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html
$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:C,CXX>:${CMAKE_CURRENT_BINARY_DIR}>>
)
target_link_libraries(iconmath-horizontal PUBLIC fortran-support::fortran-support)
target_link_libraries(iconmath-horizontal PUBLIC iconmath-support)
target_link_libraries(iconmath-horizontal PUBLIC iconmath-interpolation)
target_link_libraries(iconmath-horizontal PRIVATE Kokkos::kokkos)
set_target_properties(iconmath-horizontal PROPERTIES LINKER_LANGUAGE Fortran)
install(TARGETS iconmath-horizontal EXPORT "${PROJECT_NAME}-targets")
......
This diff is collapsed.
// ICON
//
// ---------------------------------------------------------------
// Copyright (C) 2004-2025, 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
#include <Kokkos_Core.hpp>
#include <types.hpp>
#define ICONMATH_DECLARE_RECON_LSQ_CELL_L(_type) \
void recon_lsq_cell_l( \
const _type *p_cc, const int *cell_neighbor_idx, \
const int *cell_neighbor_blk, const _type *lsq_qtmat_c, \
const _type *lsq_rmat_rdiag_c, const _type *lsq_rmat_utri_c, \
const _type *lsq_moments, _type *p_coeff, int i_startblk, int i_endblk, \
int i_startidx_in, int i_endidx_in, int slev, int elev, int nproma, \
bool l_consv, bool lacc, bool acc_async, int nblks_c, int nlev, \
int lsq_dim_unk, int lsq_dim_c)
#define ICONMATH_DECLARE_RECON_LSQ_CELL_L_SVD(_type) \
void recon_lsq_cell_l_svd( \
const _type *p_cc, const int *cell_neighbor_idx, \
const int *cell_neighbor_blk, const _type *lsq_pseudoinv, \
const _type *lsq_moments, _type *p_coeff, int i_startblk, int i_endblk, \
int i_startidx_in, int i_endidx_in, int slev, int elev, int nproma, \
bool l_consv, bool lacc, bool acc_async, int nblks_c, int nlev, \
int lsq_dim_unk, int lsq_dim_c)
#define ICONMATH_DECLARE_RECON_LSQ_CELL_Q(_type) \
void recon_lsq_cell_q( \
const _type *p_cc, const int *lsq_idx_c, const int *lsq_blk_c, \
const _type *lsq_qtmat_c, const _type *lsq_rmat_rdiag_c, \
const _type *lsq_rmat_utri_c, const _type *lsq_moments, _type *p_coeff, \
int i_startblk, int i_endblk, int i_startidx_in, int i_endidx_in, \
int slev, int elev, int nproma, int patch_id, bool l_limited_area, \
bool lacc, int nblks_c, int nlev, int lsq_dim_unk, int lsq_dim_c)
#define ICONMATH_DECLARE_RECON_LSQ_CELL_Q_SVD(_type) \
void recon_lsq_cell_q_svd( \
const _type *p_cc, const int *lsq_idx_c, const int *lsq_blk_c, \
const _type *lsq_pseudoinv, const _type *lsq_moments, _type *p_coeff, \
int i_startblk, int i_endblk, int i_startidx_in, int i_endidx_in, \
int slev, int elev, int nproma, int patch_id, bool l_limited_area, \
bool lacc, int nblks_c, int nlev, int lsq_dim_unk, int lsq_dim_c)
#define ICONMATH_DECLARE_RECON_LSQ_CELL_C(_type) \
void recon_lsq_cell_c( \
const _type *p_cc, const int *lsq_idx_c, const int *lsq_blk_c, \
const _type *lsq_qtmat_c, const _type *lsq_rmat_rdiag_c, \
const _type *lsq_rmat_utri_c, const _type *lsq_moments, _type *p_coeff, \
int i_startblk, int i_endblk, int i_startidx_in, int i_endidx_in, \
int slev, int elev, int nproma, int patch_id, bool l_limited_area, \
bool lacc, int nblks_c, int nlev, int lsq_dim_unk, int lsq_dim_c)
#define ICONMATH_DECLARE_RECON_LSQ_CELL_C_SVD(_type) \
void recon_lsq_cell_c_svd( \
const _type *p_cc, const int *lsq_idx_c, const int *lsq_blk_c, \
const _type *lsq_pseudoinv, const _type *lsq_moments, _type *p_coeff, \
int i_startblk, int i_endblk, int i_startidx_in, int i_endidx_in, \
int slev, int elev, int nproma, int patch_id, \
bool l_limited_area, bool lacc, int nblks_c, int nlev, int lsq_dim_unk, \
int lsq_dim_c)
#define ICONMATH_DECLARE_DIV3D(_type) \
void div3d(const _type *vec_e, const int *cell_edge_idx, \
const int *cell_edge_blk, const _type *geofac_div, \
_type *div_vec_c, int i_startblk, int i_endblk, \
int i_startidx_in, int i_endidx_in, int slev, int elev, \
int nproma, bool lacc, int nlev, int nblks_c, int nblks_e)
#define ICONMATH_DECLARE_DIV3D_2FIELD(_type) \
void div3d_2field(const _type *vec_e, const int *cell_edge_idx, \
const int *cell_edge_blk, const _type *geofac_div, \
_type *div_vec_c, const _type *in2, _type *out2, \
int i_startblk, int i_endblk, int i_startidx_in, \
int i_endidx_in, int slev, int elev, int nproma, \
bool lacc, int nlev, int nblks_c, int nblks_e)
#define ICONMATH_DECLARE_DIV4D(_type) \
void div4d(const int *cell_edge_idx, const int *cell_edge_blk, \
const _type *geofac_div, const _type *f4din, _type *f4dout, \
int dim4d, int i_startblk, int i_endblk, int i_startidx_in, \
int i_endidx_in, const int *slev, const int *elev, int nproma, \
bool lacc, int nlev, int nblks_c, int nblks_e)
#define ICONMATH_DECLARE_DIV_AVG(_type) \
void div_avg(const _type *vec_e, const int *cell_neighbor_idx, \
const int *cell_neighbor_blk, const int *cell_edge_idx, \
const int *cell_edge_blk, const _type *geofac_div, \
const _type *avg_coeff, _type *div_vec_c, const _type *opt_in2, \
_type *opt_out2, const int *i_startblk_in, \
const int *i_endblk_in, const int *i_startidx_in, \
const int *i_endidx_in, int slev, int elev, int nproma, \
int patch_id, bool l_limited_area, bool l2fields, bool lacc, \
int nlev, int nblks_c, int nblks_e)
#define ICONMATH_DECLARE_ROT_VERTEX_ATMOS(_type) \
void rot_vertex_atmos( \
const _type *vec_e, const int *vert_edge_idx, const int *vert_edge_blk, \
const _type *geofac_rot, _type *rot_vec, int i_startblk, int i_endblk, \
int i_startidx_in, int i_endidx_in, int slev, int elev, int nproma, \
bool lacc, int nlev, int nblks_e, int nblks_v)
#define ICONMATH_DECLARE_ROT_VERTEX_RI(_type) \
void rot_vertex_ri( \
const _type *vec_e, const int *vert_edge_idx, const int *vert_edge_blk, \
const _type *geofac_rot, _type *rot_vec, int i_startblk, int i_endblk, \
int i_startidx_in, int i_endidx_in, int slev, int elev, int nproma, \
bool lacc, bool acc_async, int nlev, int nblks_e, int nblks_v)
// Declare as templates
template <typename T> ICONMATH_DECLARE_RECON_LSQ_CELL_L(T);
template <typename T> ICONMATH_DECLARE_RECON_LSQ_CELL_L_SVD(T);
template <typename T> ICONMATH_DECLARE_RECON_LSQ_CELL_Q(T);
template <typename T> ICONMATH_DECLARE_RECON_LSQ_CELL_Q_SVD(T);
template <typename T> ICONMATH_DECLARE_RECON_LSQ_CELL_C(T);
template <typename T> ICONMATH_DECLARE_RECON_LSQ_CELL_C_SVD(T);
template <typename T> ICONMATH_DECLARE_DIV3D(T);
template <typename T> ICONMATH_DECLARE_DIV3D_2FIELD(T);
template <typename T> ICONMATH_DECLARE_DIV4D(T);
template <typename T> ICONMATH_DECLARE_DIV_AVG(T);
template <typename T> ICONMATH_DECLARE_ROT_VERTEX_ATMOS(T);
template <typename T> ICONMATH_DECLARE_ROT_VERTEX_RI(T);
......@@ -12,8 +12,12 @@
add_library(
iconmath-interpolation
mo_lib_interpolation_scalar.F90
mo_lib_interpolation_scalar.cpp
mo_lib_interpolation_vector.F90
mo_lib_intp_rbf.F90)
mo_lib_interpolation_vector.cpp
mo_lib_intp_rbf.F90
mo_lib_intp_rbf.cpp
interpolation_bindings.cpp)
add_library(${PROJECT_NAME}::interpolation ALIAS iconmath-interpolation)
......@@ -40,7 +44,8 @@ if(IM_ENABLE_OPENACC)
# provided, e.g. in CMAKE_Fortran_FLAGS:
if(NOT HAS_OPENACC_MACRO)
target_compile_options(iconmath-interpolation
PRIVATE ${OpenACC_Fortran_OPTIONS})
PRIVATE
$<$<COMPILE_LANGUAGE:Fortran>:${OpenACC_Fortran_OPTIONS}>)
# This make sures that unit tests (FortUTF) compiles without the need of
# passing OpenACC compile option.
target_link_libraries(iconmath-interpolation PRIVATE OpenACC::OpenACC_Fortran)
......@@ -55,10 +60,21 @@ target_include_directories(
$<INSTALL_INTERFACE:$<$<COMPILE_LANGUAGE:Fortran>:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>>
# Path to internal include directory
$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:Fortran>:${PROJECT_SOURCE_DIR}/include>>
# Path to the internal C/C++ headers (for testing): Requires CMake 3.15+ for
# multiple compile languages
# https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html
$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:C,CXX>:${CMAKE_CURRENT_SOURCE_DIR}>>
PRIVATE
# Path to config.h (for C and C++ only): Requires CMake 3.15+ for multiple
# compile languages
# https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html
$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:C,CXX>:${CMAKE_CURRENT_BINARY_DIR}>>
)
target_link_libraries(iconmath-interpolation PUBLIC fortran-support::fortran-support)
target_link_libraries(iconmath-interpolation PUBLIC iconmath-support)
target_link_libraries(iconmath-interpolation PRIVATE Kokkos::kokkos)
set_target_properties(iconmath-interpolation PROPERTIES LINKER_LANGUAGE Fortran)
install(TARGETS iconmath-interpolation EXPORT "${PROJECT_NAME}-targets")
......
This diff is collapsed.
// 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
extern "C" {
// mo_lib_interpolation_vector.F90
void edges2cells_vector_lib_dp(const double *p_vn_in, const double *p_vt_in,
const int *cell_edge_idx,
const int *cell_edge_blk,
const double *e_bln_c_u, const double *e_bln_c_v,
double *p_u_out, double *p_v_out, int i_startblk,
int i_endblk, int i_startidx_in, int i_endidx_in,
int slev, int elev, int nproma, int nlev,
int nblks_e, int nblks_c);
void edges2cells_vector_lib_sp(const float *p_vn_in, const float *p_vt_in,
const int *cell_edge_idx,
const int *cell_edge_blk, const float *e_bln_c_u,
const float *e_bln_c_v, float *p_u_out,
float *p_v_out, int i_startblk, int i_endblk,
int i_startidx_in, int i_endidx_in, int slev,
int elev, int nproma, int nlev, int nblks_e,
int nblks_c);
// mo_lib_interpolation_scalar.F90
void verts2edges_scalar_lib_dp(
const double *p_vertex_in, const int *edge_vertex_idx,
const int *edge_vertex_blk, const double *coeff_int, double *p_edge_out,
const int i_startblk, const int i_endblk, const int i_startidx_in,
const int i_endidx_in, const int slev, const int elev, const int nproma,
const int nlev, const int nblks_v, const int nblks_e, const bool lacc);
void verts2edges_scalar_lib_sp(
const float *p_vertex_in, const int *edge_vertex_idx,
const int *edge_vertex_blk, const float *coeff_int, float *p_edge_out,
const int i_startblk, const int i_endblk, const int i_startidx_in,
const int i_endidx_in, const int slev, const int elev, const int nproma,
const int nlev, const int nblks_v, const int nblks_e, const bool lacc);
void cells2edges_scalar_lib_dp(
const double *p_cell_in, const int *edge_cell_idx, const int *edge_cell_blk,
const double *coeff_int, double *p_edge_out, const int *i_startblk_in,
const int *i_endblk_in, const int *i_startidx_in, const int *i_endidx_in,
const int slev, const int elev, const int nproma, const int nlev,
const int nblk_c, const int nblks_e, const int patch_id,
const bool l_limited_area, const bool lfill_latbc, const bool lacc);
void cells2edges_scalar_lib_sp(const float *p_cell_in, const int *edge_cell_idx,
const int *edge_cell_blk, const float *coeff_int,
float *p_edge_out, const int *i_startblk_in,
const int *i_endblk_in, const int *i_startidx_in,
const int *i_endidx_in, const int slev,
const int elev, const int nproma, const int nlev,
const int nblk_c, const int nblks_e,
const int patch_id, const bool l_limited_area,
const bool lfill_latbc, const bool lacc);
void cells2edges_scalar_lib_sp2dp(
const float *p_cell_in, const int *edge_cell_idx, const int *edge_cell_blk,
const double *coeff_int, double *p_edge_out, const int *i_startblk_in,
const int *i_endblk_in, const int *i_startidx_in, const int *i_endidx_in,
const int slev, const int elev, const int nproma, const int nlev,
const int nblk_c, const int nblks_e, const int patch_id,
const bool l_limited_area, const bool lfill_latbc, const bool lacc);
void edges2verts_scalar_lib_dp(
const double *p_edge_in, const int *vert_edge_idx, const int *vert_edge_blk,
const double *v_int, double *p_vert_out, const int i_startblk,
const int i_endblk, const int i_startidx_in, const int i_endidx_in,
const int slev, const int elev, const int nproma, const int nlev,
const int nblks_e, const int nblks_v, const bool lacc);
void edges2verts_scalar_lib_sp(const float *p_edge_in, const int *vert_edge_idx,
const int *vert_edge_blk, const float *v_int,
float *p_vert_out, const int i_startblk,
const int i_endblk, const int i_startidx_in,
const int i_endidx_in, const int slev,
const int elev, const int nproma, const int nlev,
const int nblks_e, const int nblks_v,
const bool lacc);
void edges2cells_scalar_lib_dp(const double *p_edge_in, const int *edge_idx,
const int *edge_blk, const double *coeff_int,
double *p_cell_out, const int i_startblk,
const int i_endblk, const int i_startidx_in,
const int i_endidx_in, const int slev,
const int elev, const int nproma, const int nlev,
const int nblks_e, const int nblks_c,
const bool lacc);
void edges2cells_scalar_lib_sp(const float *p_edge_in, const int *edge_idx,
const int *edge_blk, const float *coeff_int,
float *p_cell_out, const int i_startblk,
const int i_endblk, const int i_startidx_in,
const int i_endidx_in, const int slev,
const int elev, const int nproma, const int nlev,
const int nblks_e, const int nblks_c,
const bool lacc);
/////////////////////////////////////////////
void cells2verts_scalar_lib_dp(
const double *p_cell_in, const int *vert_cell_idx, const int *vert_cell_blk,
const double *coeff_int, double *p_vert_out, const int i_startblk,
const int i_endblk, const int i_startidx_in, const int i_endidx_in,
const int slev, const int elev, const int nproma, const int nlev,
const int nblks_c, const int nblks_v, const bool lacc,
const bool acc_async);
void cells2verts_scalar_lib_dp2sp(
const double *p_cell_in, const int *vert_cell_idx, const int *vert_cell_blk,
const float *coeff_int, float *p_vert_out, const int i_startblk,
const int i_endblk, const int i_startidx_in, const int i_endidx_in,
const int slev, const int elev, const int nproma, const int nlev,
const int nblks_c, const int nblks_v, const bool lacc,
const bool acc_async);
void cells2verts_scalar_lib_sp(const float *p_cell_in, const int *vert_cell_idx,
const int *vert_cell_blk, const float *coeff_int,
float *p_vert_out, const int i_startblk,
const int i_endblk, const int i_startidx_in,
const int i_endidx_in, const int slev,
const int elev, const int nproma, const int nlev,
const int nblks_c, const int nblks_v,
const bool lacc, const bool acc_async);
/////////////////////////////////////////////
void cells2verts_scalar_ri_lib_dp(
const double *p_cell_in, const int *vert_cell_idx, const int *vert_cell_blk,
const double *coeff_int, double *p_vert_out, const int i_startblk,
const int i_endblk, const int i_startidx_in, const int i_endidx_in,
const int slev, const int elev, const int nproma, const int nlev,
const int nblks_c, const int nblks_v, const bool lacc,
const bool acc_async);
void cells2verts_scalar_ri_lib_dp2sp(
const double *p_cell_in, const int *vert_cell_idx, const int *vert_cell_blk,
const double *coeff_int, float *p_vert_out, const int i_startblk,
const int i_endblk, const int i_startidx_in, const int i_endidx_in,
const int slev, const int elev, const int nproma, const int nlev,
const int nblks_c, const int nblks_v, const bool lacc,
const bool acc_async);
void cells2verts_scalar_ri_lib_sp(
const float *p_cell_in, const int *vert_cell_idx, const int *vert_cell_blk,
const float *coeff_int, float *p_vert_out, const int i_startblk,
const int i_endblk, const int i_startidx_in, const int i_endidx_in,
const int slev, const int elev, const int nproma, const int nlev,
const int nblks_c, const int nblks_v, const bool lacc,
const bool acc_async);
/////////////////////////////////////////////
void verts2cells_scalar_lib_dp(
const double *p_vert_in, const int *cell_index_idx,
const int *cell_vertex_blk, const double *coeff_int, double *p_cell_out,
const int nblks_c, const int npromz_c, const int slev, const int elev,
const int nproma, const int nlev, const int nblks_v, const bool lacc);
void verts2cells_scalar_lib_sp(
const float *p_vert_in, const int *cell_index_idx,
const int *cell_vertex_blk, const float *coeff_int, float *p_cell_out,
const int nblks_c, const int npromz_c, const int slev, const int elev,
const int nproma, const int nlev, const int nblks_v, const bool lacc);
/////////////////////////////////////////////
void cell_avg_lib_dp(const double *psi_c, const int *cell_neighbor_idx,
const int *cell_neighbor_blk, const double *avg_coeff,
double *avg_psi_c, const int i_startblk,
const int i_endblk, const int i_startidx_in,
const int i_endidx_in, const int slev, const int elev,
const int nproma, const int nlev, const int nblks_c,
const bool lacc);
void cell_avg_lib_sp(const float *psi_c, const int *cell_neighbor_idx,
const int *cell_neighbor_blk, const float *avg_coeff,
float *avg_psi_c, const int i_startblk, const int i_endblk,
const int i_startidx_in, const int i_endidx_in,
const int slev, const int elev, const int nproma,
const int nlev, const int nblks_c, const bool lacc);
void rbf_vec_interpol_vertex_lib_dp(
const double *p_e_in, const int *rbf_vec_idx_v, const int *rbf_vec_blk_v,
const double *rbf_vec_coeff_v, double *p_u_out, double *p_v_out,
const int i_startblk, const int i_endblk, const int i_startidx_in,
const int i_endidx_in, const int slev, const int elev, const int nproma,
const bool lacc, const bool acc_async, const int nlev, const int nblks_e,
const int nblks_v);
void rbf_vec_interpol_vertex_lib_sp(
const float *p_e_in, const int *rbf_vec_idx_v, const int *rbf_vec_blk_v,
const float *rbf_vec_coeff_v, float *p_u_out, float *p_v_out,
const int i_startblk, const int i_endblk, const int i_startidx_in,
const int i_endidx_in, const int slev, const int elev, const int nproma,
const bool lacc, const bool acc_async, const int nlev, const int nblks_e,
const int nblks_v);
void rbf_vec_interpol_vertex_lib_dpsp(
const double *p_e_in, const int *rbf_vec_idx_v, const int *rbf_vec_blk_v,
const double *rbf_vec_coeff_v, float *p_u_out, float *p_v_out,
const int i_startblk, const int i_endblk, const int i_startidx_in,
const int i_endidx_in, const int slev, const int elev, const int nproma,
const bool lacc, const bool acc_async, const int nlev, const int nblks_e,
const int nblks_v);
void rbf_interpol_c2grad_lib_sp(
const float *p_cell_in, const int *rbf_c2grad_idx,
const int *rbf_c2grad_blk, const float *rbf_c2grad_coeff, float *grad_x,
const float *grad_y, int i_startblk, int i_endblk, int i_startidx_in,
int i_endidx_in, int slev, int elev, int nproma, int rbf_c2grad_dim,
int nlev, int nblk_c, bool lacc);
void rbf_interpol_c2grad_lib_dp(
const double *p_cell_in, const int *rbf_c2grad_idx,
const int *rbf_c2grad_blk, const double *rbf_c2grad_coeff, double *grad_x,
const double *grad_y, int i_startblk, int i_endblk, int i_startidx_in,
int i_endidx_in, int slev, int elev, int nproma, int rbf_c2grad_dim,
int nlev, int nblk_c, bool lacc);
void rbf_vec_interpol_cell_lib_sp(
const float *p_vn_in, const int *rbf_vec_idx_c, const int *rbf_vec_blk_c,
const float *rbf_vec_coeff_c, float *p_u_out, float *p_v_out,
int i_startblk, int i_endblk, int i_startidx_in, int i_endidx_in, int slev,
int elev, int nproma, int nlev, int nblks_c, int nblks_e, int rbf_vec_dim_c,
bool lacc, bool acc_async);
void rbf_vec_interpol_cell_lib_dp(
const double *p_vn_in, const int *rbf_vec_idx_c, const int *rbf_vec_blk_c,
const double *rbf_vec_coeff_c, double *p_u_out, double *p_v_out,
int i_startblk, int i_endblk, int i_startidx_in, int i_endidx_in, int slev,
int elev, int nproma, int nlev, int nblks_c, int nblks_e, int rbf_vec_dim_c,
bool lacc, bool acc_async);
void rbf_vec_interpol_edge_lib_dp(
const double *p_vn_in, const int *rbf_vec_idx_e, const int *rbf_vec_blk_e,
const double *rbf_vec_coeff_e, double *p_vt_out, int i_startblk,
int i_endblk, int i_startidx_in, int i_endidx_in, int slev, int elev,
int nlev, int nproma, int rbf_vec_dim_e, int nblks_e, bool lacc,
bool acc_async);
void rbf_vec_interpol_edge_lib_sp(
const float *p_vn_in, const int *rbf_vec_idx_e, const int *rbf_vec_blk_e,
const float *rbf_vec_coeff_e, float *p_vt_out, int i_startblk, int i_endblk,
int i_startidx_in, int i_endidx_in, int slev, int elev, int nlev,
int nproma, int rbf_vec_dim_e, int nblks_e, bool lacc, bool acc_async);
}
This diff is collapsed.
// 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
template <typename T>
void verts2edges_scalar_lib(const T *p_vertex_in, const int *edge_vertex_idx,
const int *edge_vertex_blk, const T *coeff_int,
T *p_edge_out, const int i_startblk,
const int i_endblk, const int i_startidx_in,
const int i_endidx_in, const int slev,
const int elev, const int nproma, const int nlev,
const int nblks_v, const int nblks_e,
const bool lacc);
;
template <typename T, typename S>
void cells2edges_scalar_lib(const T *p_cell_in, const int *edge_cell_idx,
const int *edge_cell_blk, const S *coeff_int,
S *p_edge_out, const int *i_startblk_in,
const int *i_endblk_in, const int *i_startidx_in,
const int *i_endidx_in, const int slev,
const int elev, const int nproma, const int nlev,
const int nblk_c, const int nblks_e,
const int patch_id, const bool l_limited_area,
const bool lfill_latbc, const bool lacc);
template <typename T>
void edges2verts_scalar_lib(const T *p_edge_in, const int *vert_edge_idx,
const int *vert_edge_blk, const T *v_int,
T *p_vert_out, const int i_startblk,
const int i_endblk, const int i_startidx_in,
const int i_endidx_in, const int slev,
const int elev, const int nproma, const int nlev,
const int nblks_e, const int nblks_v,
const bool lacc);
template <typename T>
void edges2cells_scalar_lib(const T *p_edge_in, const int *edge_idx,
const int *edge_blk, const T *coeff_int,
T *p_cell_out, const int i_startblk,
const int i_endblk, const int i_startidx_in,
const int i_endidx_in, const int slev,
const int elev, const int nproma, const int nlev,
const int nblks_e, const int nblks_c,
const bool lacc);
template <typename T, typename S>
void cells2verts_scalar_lib(const T *p_cell_in, const int *vert_cell_idx,
const int *vert_cell_blk, const S *coeff_int,
S *p_vert_out, const int i_startblk,
const int i_endblk, const int i_startidx_in,
const int i_endidx_in, const int slev,
const int elev, const int nproma, const int nlev,
const int nblks_c, const int nblks_v,
const bool lacc, const bool acc_async);
template <typename T, typename S>
void cells2verts_scalar_ri_lib(const T *p_cell_in, const int *vert_cell_idx,
const int *vert_cell_blk, const T *coeff_int,
S *p_vert_out, const int i_startblk,
const int i_endblk, const int i_startidx_in,
const int i_endidx_in, const int slev,
const int elev, const int nproma, const int nlev,
const int nblks_c, const int nblks_v,
const bool lacc, const bool acc_async);
template <typename T>
void verts2cells_scalar_lib(const T *p_vert_in, const int *cell_index_idx,
const int *cell_vertex_blk, const T *coeff_int,
T *p_cell_out, const int nblks_c,
const int npromz_c, const int slev, const int elev,
const int nproma, const int nlev, const int nblks_v,
const bool lacc);
template <typename T>
void cell_avg_lib(const T *psi_c, const int *cell_neighbor_idx,
const int *cell_neighbor_blk, const T *avg_coeff,
T *avg_psi_c, const int i_startblk, const int i_endblk,
const int i_startidx_in, const int i_endidx_in,
const int slev, const int elev, const int nproma,
const int nlev, const int nblks_c, const bool lacc);
// 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 "mo_lib_interpolation_vector.hpp"
template <typename T>
void edges2cells_vector_lib(const T *p_vn_in, const T *p_vt_in,
const int *cell_edge_idx, const int *cell_edge_blk,
const T *e_bln_c_u, const T *e_bln_c_v, T *p_u_out,
T *p_v_out,
// Additional integer parameters.
int i_startblk, int i_endblk, int i_startidx_in,
int i_endidx_in, int slev, int elev, int nproma,
// Dimensions for the arrays.
int nlev, int nblks_e, int nblks_c) {
// Wrap raw pointers in unmanaged Kokkos Views.
typedef Kokkos::View<const T ***, Kokkos::LayoutLeft, Kokkos::MemoryUnmanaged>
UnmanagedConstT3D;
typedef Kokkos::View<T ***, Kokkos::LayoutLeft, Kokkos::MemoryUnmanaged>
UnmanagedT3D;
typedef Kokkos::View<const int ***, Kokkos::LayoutLeft,
Kokkos::MemoryUnmanaged>
UnmanagedConstInt3D;
UnmanagedConstT3D p_vn_in_view(p_vn_in, nproma, nlev, nblks_e);
UnmanagedConstT3D p_vt_in_view(p_vt_in, nproma, nlev, nblks_e);
UnmanagedConstInt3D cell_edge_idx_view(cell_edge_idx, nproma, nblks_c, 3);
UnmanagedConstInt3D cell_edge_blk_view(cell_edge_blk, nproma, nblks_c, 3);
UnmanagedConstT3D e_bln_c_u_view(e_bln_c_u, nproma, 6, nblks_c);
UnmanagedConstT3D e_bln_c_v_view(e_bln_c_v, nproma, 6, nblks_c);
UnmanagedT3D p_u_out_view(p_u_out, nproma, nlev, nblks_c);
UnmanagedT3D p_v_out_view(p_v_out, nproma, nlev, nblks_c);
// Loop over cell blocks as in the original Fortran code.
for (int jb = i_startblk; jb <= i_endblk; ++jb) {
// Call get_indices_c_lib to get inner loop indices for block jb.
int i_startidx, i_endidx;
get_indices_c_lib(i_startidx_in, i_endidx_in, nproma, jb, i_startblk,
i_endblk, i_startidx, i_endidx);
Kokkos::MDRangePolicy<Kokkos::Rank<2>> innerPolicy(
{slev, i_startidx}, {elev + 1, i_endidx + 1});
Kokkos::parallel_for(
"edges2cells_inner", innerPolicy,
KOKKOS_LAMBDA(const int jk, const int jc) {
// Compute the bilinear interpolation for cell (jc, jk, jb).
p_u_out_view(jc, jk, jb) =
e_bln_c_u_view(jc, 0, jb) *
p_vn_in_view(cell_edge_idx_view(jc, jb, 0) - 1, jk,
cell_edge_blk_view(jc, jb, 0) - 1) +
e_bln_c_u_view(jc, 1, jb) *
p_vt_in_view(cell_edge_idx_view(jc, jb, 0) - 1, jk,
cell_edge_blk_view(jc, jb, 0) - 1) +
e_bln_c_u_view(jc, 2, jb) *
p_vn_in_view(cell_edge_idx_view(jc, jb, 1) - 1, jk,
cell_edge_blk_view(jc, jb, 1) - 1) +
e_bln_c_u_view(jc, 3, jb) *
p_vt_in_view(cell_edge_idx_view(jc, jb, 1) - 1, jk,
cell_edge_blk_view(jc, jb, 1) - 1) +
e_bln_c_u_view(jc, 4, jb) *
p_vn_in_view(cell_edge_idx_view(jc, jb, 2) - 1, jk,
cell_edge_blk_view(jc, jb, 2) - 1) +
e_bln_c_u_view(jc, 5, jb) *
p_vt_in_view(cell_edge_idx_view(jc, jb, 2) - 1, jk,
cell_edge_blk_view(jc, jb, 2) - 1);
p_v_out_view(jc, jk, jb) =
e_bln_c_v_view(jc, 0, jb) *
p_vn_in_view(cell_edge_idx_view(jc, jb, 0) - 1, jk,
cell_edge_blk_view(jc, jb, 0) - 1) +
e_bln_c_v_view(jc, 1, jb) *
p_vt_in_view(cell_edge_idx_view(jc, jb, 0) - 1, jk,
cell_edge_blk_view(jc, jb, 0) - 1) +
e_bln_c_v_view(jc, 2, jb) *
p_vn_in_view(cell_edge_idx_view(jc, jb, 1) - 1, jk,
cell_edge_blk_view(jc, jb, 1) - 1) +
e_bln_c_v_view(jc, 3, jb) *
p_vt_in_view(cell_edge_idx_view(jc, jb, 1) - 1, jk,
cell_edge_blk_view(jc, jb, 1) - 1) +
e_bln_c_v_view(jc, 4, jb) *
p_vn_in_view(cell_edge_idx_view(jc, jb, 2) - 1, jk,
cell_edge_blk_view(jc, jb, 2) - 1) +
e_bln_c_v_view(jc, 5, jb) *
p_vt_in_view(cell_edge_idx_view(jc, jb, 2) - 1, jk,
cell_edge_blk_view(jc, jb, 2) - 1);
});
// Optionally fence after each block if required.
Kokkos::fence();
}
}
template void edges2cells_vector_lib<double>(
const double *p_vn_in, const double *p_vt_in, const int *cell_edge_idx,
const int *cell_edge_blk, const double *e_bln_c_u, const double *e_bln_c_v,
double *p_u_out, double *p_v_out,
// Additional integer parameters.
int i_startblk, int i_endblk, int i_startidx_in, int i_endidx_in, int slev,
int elev, int nproma,
// Dimensions for the arrays.
int nlev, int nblks_e, int nblks_c);
template void edges2cells_vector_lib<float>(
const float *p_vn_in, const float *p_vt_in, const int *cell_edge_idx,
const int *cell_edge_blk, const float *e_bln_c_u, const float *e_bln_c_v,
float *p_u_out, float *p_v_out,
// Additional integer parameters.
int i_startblk, int i_endblk, int i_startidx_in, int i_endidx_in, int slev,
int elev, int nproma,
// Dimensions for the arrays.
int nlev, int nblks_e, int nblks_c);
\ No newline at end of file
// 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
#include "mo_lib_loopindices.hpp"
#include <Kokkos_Core.hpp>
#include <vector>
// The templated C++ function using Kokkos.
// Raw pointer arguments are wrapped into unmanaged Kokkos::Views.
// Note: The dimensions below must match the Fortran arrays.
// - p_vn_in and p_vt_in: dimensions [nproma, nlev, nblks_e]
// - cell_edge_idx and cell_edge_blk: dimensions [nproma, nblks_c, 3]
// - e_bln_c_u and e_bln_c_v: dimensions [nproma, 6, nblks_c]
// - p_u_out and p_v_out: dimensions [nproma, nlev, nblks_c]
template <typename T>
void edges2cells_vector_lib(const T *p_vn_in, const T *p_vt_in,
const int *cell_edge_idx, const int *cell_edge_blk,
const T *e_bln_c_u, const T *e_bln_c_v, T *p_u_out,
T *p_v_out,
// Additional integer parameters.
int i_startblk, int i_endblk, int i_startidx_in,
int i_endidx_in, int slev, int elev, int nproma,
// Dimensions for the arrays.
int nlev, int nblks_e, int nblks_c);
\ No newline at end of file
This diff is collapsed.
// 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
#include "mo_lib_loopindices.hpp"
#include <Kokkos_Core.hpp>
#include <vector>
template <typename T, typename S>
void rbf_vec_interpol_vertex_lib(
const T *p_e_in, const int *rbf_vec_idx_v, const int *rbf_vec_blk_v,
const T *rbf_vec_coeff_v, S *p_u_out, S *p_v_out, const int i_startblk,
const int i_endblk, const int i_startidx_in, const int i_endidx_in,
const int slev, const int elev, const int nproma, const bool lacc,
const bool acc_async, const int nlev, const int nblks_e, const int nblks_c);
template <typename T>
void rbf_interpol_c2grad_lib(const T *p_cell_in, const int *rbf_c2grad_idx,
const int *rbf_c2grad_blk,
const T *rbf_c2grad_coeff, T *grad_x, T *grad_y,
int i_startblk, int i_endblk, int i_startidx_in,
int i_endidx_in, int slev, int elev, int nproma,
int rbf_c2grad_dim, int nlev, int nblks_c,
bool lacc);
template <typename T>
void rbf_vec_interpol_cell_lib(const T *p_vn_in, const int *rbf_vec_idx_c,
const int *rbf_vec_blk_c,
const T *rbf_vec_coeff_c, T *p_u_out, T *p_v_out,
int i_startblk, int i_endblk, int i_startidx_in,
int i_endidx_in, int slev, int elev, int nproma,
int nlev, int nblks_c, int nblks_e,
int rbf_vec_dim_c, bool lacc, bool acc_async);
template <typename T>
void rbf_vec_interpol_edge_lib(const T *p_vn_in, const int *rbf_vec_idx_e,
const int *rbf_vec_blk_e,
const T *rbf_vec_coeff_e, T *p_vt_out,
int i_startblk, int i_endblk, int i_startidx_in,
int i_endidx_in, int slev, int elev, int nlev,
int nproma, int rbf_vec_dim_e, int nblks_e,
bool lacc, bool acc_async);
......@@ -13,11 +13,14 @@ add_library(
iconmath-support
mo_gridman_constants.f90
mo_lib_grid_geometry_info.f90
mo_lib_loopindices.f90
mo_lib_loopindices.cpp
mo_lib_loopindices.F90
mo_math_constants.f90
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)
......@@ -40,11 +43,17 @@ if(IM_ENABLE_DIM_SWAP)
target_compile_definitions(iconmath-support PRIVATE __SWAPDIM)
endif()
if(IM_USE_CPP_BINDINGS)
target_compile_definitions(iconmath-support PUBLIC __USE_CPP_BINDINGS)
endif()
if(IM_ENABLE_OPENACC)
# If _OPENACC is defined, assume that the required compiler flags are already
# provided, e.g. in CMAKE_Fortran_FLAGS:
if(NOT HAS_OPENACC_MACRO)
target_compile_options(iconmath-support PRIVATE ${OpenACC_Fortran_OPTIONS})
target_compile_options(iconmath-support
PRIVATE
$<$<COMPILE_LANGUAGE:Fortran>:${OpenACC_Fortran_OPTIONS}>)
# This make sures that unit tests (FortUTF) compiles without the need of
# passing OpenACC compile option.
target_link_libraries(iconmath-support PRIVATE OpenACC::OpenACC_Fortran)
......@@ -57,9 +66,24 @@ target_include_directories(
# Path to the Fortran modules:
$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:Fortran>:${Fortran_MODULE_DIRECTORY}>>
$<INSTALL_INTERFACE:$<$<COMPILE_LANGUAGE:Fortran>:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>>
)
INTERFACE
# Path to the internal C/C++ headers (for testing): Requires CMake 3.15+ for
# multiple compile languages
# https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html
$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:C,CXX>:${CMAKE_CURRENT_SOURCE_DIR}>>
PRIVATE
# Path to config.h (for C and C++ only): Requires CMake 3.15+ for multiple
# compile languages
# https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html
$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:C,CXX>:${CMAKE_CURRENT_BINARY_DIR}>>)
target_link_libraries(iconmath-support PUBLIC fortran-support::fortran-support)
target_link_libraries(iconmath-support
PUBLIC
fortran-support::fortran-support
PRIVATE
Kokkos::kokkos
)
set_target_properties(iconmath-support PROPERTIES LINKER_LANGUAGE Fortran)
install(TARGETS iconmath-support EXPORT "${PROJECT_NAME}-targets")
......
......@@ -16,12 +16,18 @@
MODULE mo_lib_loopindices
#ifdef __USE_CPP_BINDINGS
USE, INTRINSIC :: ISO_C_BINDING
#endif
IMPLICIT NONE
PRIVATE
PUBLIC :: get_indices_c_lib, get_indices_e_lib, get_indices_v_lib
#ifndef __USE_CPP_BINDINGS
CONTAINS
!-------------------------------------------------------------------------
......@@ -121,5 +127,31 @@ CONTAINS
END SUBROUTINE get_indices_v_lib
END MODULE mo_lib_loopindices
#else
INTERFACE
SUBROUTINE get_indices_c_lib(i_startidx_in, i_endidx_in, nproma, i_blk, i_startblk, i_endblk, &
i_startidx_out, i_endidx_out) BIND(C, NAME="get_indices_c_lib")
IMPORT :: c_int
INTEGER(c_int), VALUE :: i_startidx_in, i_endidx_in, nproma, i_blk, i_startblk, i_endblk
INTEGER(c_int) :: i_startidx_out, i_endidx_out
END SUBROUTINE get_indices_c_lib
SUBROUTINE get_indices_e_lib(i_startidx_in, i_endidx_in, nproma, i_blk, i_startblk, i_endblk, &
i_startidx_out, i_endidx_out) BIND(C, NAME="get_indices_e_lib")
IMPORT :: c_int
INTEGER(c_int), VALUE :: i_startidx_in, i_endidx_in, nproma, i_blk, i_startblk, i_endblk
INTEGER(c_int) :: i_startidx_out, i_endidx_out
END SUBROUTINE get_indices_e_lib
SUBROUTINE get_indices_v_lib(i_startidx_in, i_endidx_in, nproma, i_blk, i_startblk, i_endblk, &
i_startidx_out, i_endidx_out) BIND(C, NAME="get_indices_v_lib")
IMPORT :: c_int
INTEGER(c_int), VALUE :: i_startidx_in, i_endidx_in, nproma, i_blk, i_startblk, i_endblk
INTEGER(c_int) :: i_startidx_out, i_endidx_out
END SUBROUTINE get_indices_v_lib
END INTERFACE
#endif
END MODULE mo_lib_loopindices
// 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 <algorithm> // For std::max
// 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=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.
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 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(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=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.
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=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.
int first_index;
if (called_from_cpp)
first_index = 0;
else
first_index = 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 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