From 04d2ec2d7098f2ac3f8e1539ab139aa35dfabe45 Mon Sep 17 00:00:00 2001 From: vijay gopal chilkuri Date: Tue, 20 Jul 2021 19:34:51 +0200 Subject: [PATCH] Added an example usage of qmckl_sherman_morrison function as a test. #25 --- org/qmckl_sherman_morrison_woodbury.org | 30 ++++++++++++++++++------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/org/qmckl_sherman_morrison_woodbury.org b/org/qmckl_sherman_morrison_woodbury.org index bebfc70..e5c221b 100644 --- a/org/qmckl_sherman_morrison_woodbury.org +++ b/org/qmckl_sherman_morrison_woodbury.org @@ -25,6 +25,7 @@ int main() { qmckl_context context; context = qmckl_context_create(); + qmckl_exit_code rc; #+end_src * Sherman-Morrison Helper Functions @@ -58,7 +59,7 @@ This function is used to set the threshold value that is used in the kernels to #define THRESHOLD 1e-3 #endif - qmckl_exit_code qmckl_sherman_morrison_threshold ( + qmckl_exit_code qmckl_sherman_morrison_threshold_c ( double* const thresh ); #+end_src @@ -83,11 +84,12 @@ end function qmckl_sherman_morrison_threshold_f #include "qmckl.h" // Sherman-Morrison-Woodbury break-down threshold -static double qmckl_shreman_morrison_threshold(double* const threshold) { +qmckl_exit_code qmckl_sherman_morrison_threshold_c(double* const threshold) { *threshold = THRESHOLD; // #ifdef DEBUG // std::cerr << "Break-down threshold set to: " << threshold << std::endl; // #endif +return QMCKL_SUCCESS; } #+end_src @@ -109,8 +111,8 @@ static double qmckl_shreman_morrison_threshold(double* const threshold) { real (c_double ) , intent(out) :: thresh - integer(c_int32_t), external :: qmckl_sherman_morrison_threshold_f - info = qmckl_sherman_morrison_threshold_f & + integer(c_int32_t), external :: qmckl_sherman_morrison_threshold_c + info = qmckl_sherman_morrison_threshold_c & (thresh) end function qmckl_sherman_morrison_threshold @@ -193,7 +195,7 @@ integer function qmckl_sherman_morrison_f(context, Slater_inv, Dim, N_updates, use qmckl implicit none integer(qmckl_context) , intent(in) :: context - integer*8 , intent(in) :: Dim, N_updates + integer*8 , intent(in), value :: Dim, N_updates integer*8 , intent(in) :: Updates_index(N_updates) real*8 , intent(in) :: Updates(N_updates*Dim) real*8 , intent(inout) :: Slater_inv(Dim*Dim) @@ -222,7 +224,7 @@ qmckl_exit_code qmckl_sherman_morrison_c(const qmckl_context context, double D[Dim]; double threshold = 0.0; - qmckl_sherman_morrison_threshold(&threshold); + qmckl_exit_code rc = qmckl_sherman_morrison_threshold_c(&threshold); unsigned int l = 0; // For each update @@ -237,8 +239,8 @@ qmckl_exit_code qmckl_sherman_morrison_c(const qmckl_context context, // Denominator double den = 1 + C[Updates_index[l] - 1]; - double const thresh; - qmckl_sherman_morrison_threshold(&thresh); + double thresh = 0.0; + qmckl_exit_code rc = qmckl_sherman_morrison_threshold_c(&thresh); if (fabs(den) < thresh) { return QMCKL_FAILURE; } @@ -322,6 +324,18 @@ qmckl_exit_code qmckl_sherman_morrison_c(const qmckl_context context, [TODO: FMJC] Write tests for the Sherman-Morrison part. + + #+begin_src c :tangle (eval c_test) +const uint64_t Dim = 2; +const uint64_t N_updates = 2; +const uint64_t Updates_index[2] = {0, 0}; +const double Updates[4] = {0.0, 0.0, 0.0, 0.0}; +double Slater_inv[4] = {0.0, 0.0, 0.0, 0.0}; + +rc = qmckl_sherman_morrison_c(context, Dim, N_updates, Updates, Updates_index, Slater_inv); +assert(rc == QMCKL_SUCCESS); + #+end_src + * End of files #+begin_src c :comments link :tangle (eval c_test)