Skip to content

Commit

Permalink
Use planar tendency terms test to test single precision
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarusz committed Oct 30, 2024
1 parent 537bbe1 commit 3c6a1b2
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
20 changes: 20 additions & 0 deletions components/omega/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ target_link_libraries(
OmegaLibFlags
)

# some tests require single precision version of the library
# if OmegaLib is configured to use double precision we need to
# build another version
if(OMEGA_BUILD_TEST AND NOT OMEGA_SINGLE_PRECISION)
add_library(${OMEGA_LIB_NAME}_SP ${_LIBSRC_FILES})

target_link_libraries(
${OMEGA_LIB_NAME}_SP
PRIVATE
OmegaLibFlags
)

target_compile_definitions(
${OMEGA_LIB_NAME}_SP
PUBLIC
OMEGA_SINGLE_PRECISION=1
)
endif()


# build Omega executable
if(OMEGA_BUILD_EXECUTABLE)

Expand Down
38 changes: 37 additions & 1 deletion components/omega/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#####################

function(add_omega_test test_name exe_name source_files mpi_args)
# Copy extra arguments to a local variable so they can be treated
# as a list
set(extra_args ${ARGN})

# Create the executable
add_executable(${exe_name} ${source_files})
Expand All @@ -14,10 +17,35 @@ function(add_omega_test test_name exe_name source_files mpi_args)
target_link_libraries(
${exe_name}
PRIVATE
${OMEGA_LIB_NAME}
OmegaLibFlags
)

list(FIND extra_args single_precision use_sp)

# Link the single precision version if requested and not already configured to
# use single precision
if (NOT use_sp EQUAL -1)
if (OMEGA_SINGLE_PRECISION)
target_link_libraries(
${exe_name}
PRIVATE
${OMEGA_LIB_NAME}
)
else()
target_link_libraries(
${exe_name}
PRIVATE
${OMEGA_LIB_NAME}_SP
)
endif()
else()
target_link_libraries(
${exe_name}
PRIVATE
${OMEGA_LIB_NAME}
)
endif()

set_target_properties(${exe_name} PROPERTIES LINKER_LANGUAGE C)

# Add the test command
Expand Down Expand Up @@ -261,6 +289,14 @@ target_compile_definitions(
TENDENCYTERMS_TEST_PLANE
)

add_omega_test(
TEND_PLANE_SINGLE_PRECISION_TEST
testTendencyTermsPlaneSinglePrecision.exe
ocn/TendencyTermsTest.cpp
"-n 8;--cpu-bind=cores"
single_precision
)

add_omega_test(
TEND_SPHERE_TEST
testTendencyTermsSphere.exe
Expand Down
2 changes: 1 addition & 1 deletion components/omega/test/ocn/TendencyTermsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ int tendencyTermsTest(const std::string &mesh = DefaultMeshFile) {
int NVertLevels = 16;
int NTracers = 3;

const Real RTol = sizeof(Real) == 4 ? 1e-2 : 1e-10;
const Real RTol = sizeof(Real) == 4 ? 2e-2 : 1e-10;

Err += testThickFluxDiv(NVertLevels, RTol);

Expand Down

0 comments on commit 3c6a1b2

Please sign in to comment.