From d5f6519db2f64ad83de9f3820bd91ce95f48a231 Mon Sep 17 00:00:00 2001
From: Pradipta Samanta <samanta@dkrz.de>
Date: Thu, 2 Jan 2025 22:29:20 +0100
Subject: [PATCH] added the test for the cpp binding of tdma_solver_vec

fixed a bug in testing
---
 src/support/CMakeLists.txt           |  2 +-
 test/fortran/test_math_utilities.f90 | 29 ++++++++++++++++++++++++----
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/src/support/CMakeLists.txt b/src/support/CMakeLists.txt
index 35e1c71..7af714e 100644
--- a/src/support/CMakeLists.txt
+++ b/src/support/CMakeLists.txt
@@ -43,7 +43,7 @@ if(IM_ENABLE_DIM_SWAP)
 endif()
 
 if(IM_USE_CPP_BINDINGS)
-  target_compile_definitions(iconmath-support PRIVATE __USE_CPP_BINDINGS)
+  target_compile_definitions(iconmath-support PUBLIC __USE_CPP_BINDINGS)
 endif()
 
 if(IM_ENABLE_OPENACC)
diff --git a/test/fortran/test_math_utilities.f90 b/test/fortran/test_math_utilities.f90
index 70fd9ab..8dcf5b3 100644
--- a/test/fortran/test_math_utilities.f90
+++ b/test/fortran/test_math_utilities.f90
@@ -248,7 +248,9 @@ CONTAINS
     INTEGER, PARAMETER :: n = 10
     REAL(wp) :: a(n, n), b(n, n), c(n, n), d(n, n), x(n, n)
     INTEGER :: i, j
-    REAL(wp) :: sum, sum_ref
+    REAL(wp) :: sum, sum_ref, tol
+    REAL(wp) :: start_time, end_time, elapsed_time
+
     DO i = 1, n
       DO j = 1, n
         a(i, j) = 1.0_wp
@@ -257,14 +259,33 @@ CONTAINS
         d(i, j) = 1.0_wp
       END DO
     END DO
+
+    CALL CPU_TIME(start_time)
+#ifndef __USE_CPP_BINDINGS
     CALL tdma_solver_vec(a, b, c, d, 1, n, 1, n, x)
+#else
+    CALL tdma_solver_vec(a, b, c, d, 0, n, 0, n, x, -1)
+#endif
+    CALL CPU_TIME(end_time)
+
+    ! Compute elapsed time
+    elapsed_time = end_time - start_time
+
+    ! Output timing result
+    write(*,*) "Elapsed time for tdma_solver_vec: ", elapsed_time, " seconds"
+
     sum = 0.0_wp
     DO i = 1, n
-      sum = sum + x(i, 1)
+      DO j = 1, n
+        sum = sum + x(i, j)
+      ! write(*,"(a,f24.16)") ' x(i, 1): ', x(i, 1)
+      END DO
     END DO
-    sum_ref = 4.5454545454545467_wp
+    sum_ref = 27.2727272727272769_wp
+    tol = 1d-15
     CALL TAG_TEST("TEST_tdma_solver_vec")
-    CALL ASSERT_EQUAL(sum, sum_ref)
+    CALL ASSERT_ALMOST_EQUAL(sum, sum_ref, tol)
+
   END SUBROUTINE TEST_tdma_solver_vec
 
 END MODULE TEST_mo_math_utilities
-- 
GitLab