mirror of
https://github.com/TREX-CoE/qmckl.git
synced 2024-08-26 07:01:46 +02:00
Started adding the pedagogical kernels for the HAVE_DOC builds.
This commit is contained in:
parent
2e45927e04
commit
d3aebe52ff
@ -32,7 +32,6 @@ range(2, 22)
|
|||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
* Naïve Sherman-Morrison
|
* Naïve Sherman-Morrison
|
||||||
|
|
||||||
** ~qmckl_sherman_morrison_naive~
|
** ~qmckl_sherman_morrison_naive~
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:Name: qmckl_sherman_morrison_naive
|
:Name: qmckl_sherman_morrison_naive
|
||||||
@ -90,6 +89,31 @@ range(2, 22)
|
|||||||
* ~breakdown~ is a small number such that $0 < breakdown << 1$
|
* ~breakdown~ is a small number such that $0 < breakdown << 1$
|
||||||
* ~Slater_inv~ is allocated with $Dim \times Dim$ elements
|
* ~Slater_inv~ is allocated with $Dim \times Dim$ elements
|
||||||
|
|
||||||
|
*** Fortran source
|
||||||
|
|
||||||
|
#+begin_src f90 :tangle (eval f)
|
||||||
|
integer function qmckl_sherman_morrison_naive_doc_f &
|
||||||
|
(context, Dim, N_updates, Updates, Updates_index, breakdown, Slater_inv, determinant) &
|
||||||
|
bind(C)
|
||||||
|
|
||||||
|
use, intrinsic :: iso_c_binding
|
||||||
|
implicit none
|
||||||
|
|
||||||
|
integer (c_int64_t) , intent(in) , value :: context
|
||||||
|
integer (c_int64_t) , intent(in) , value :: Dim
|
||||||
|
integer (c_int64_t) , intent(in) , value :: N_updates
|
||||||
|
real (c_double ) , intent(in) :: Updates(N_updates*Dim)
|
||||||
|
integer (c_int64_t) , intent(in) :: Updates_index(N_updates)
|
||||||
|
real (c_double ) , intent(in) , value :: breakdown
|
||||||
|
real (c_double ) , intent(inout) :: Slater_inv(Dim*Dim)
|
||||||
|
real (c_double ) , intent(inout) :: determinant
|
||||||
|
|
||||||
|
write(*,*) "Function 'qmckl_sherman_morrison_naive_doc_f' does nothing for now..."
|
||||||
|
|
||||||
|
end function qmckl_sherman_morrison_naive_doc_f
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
|
||||||
*** C header
|
*** C header
|
||||||
|
|
||||||
#+CALL: generate_c_header(table=qmckl_sherman_morrison_naive_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
|
#+CALL: generate_c_header(table=qmckl_sherman_morrison_naive_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
|
||||||
@ -108,9 +132,19 @@ range(2, 22)
|
|||||||
double* determinant);
|
double* determinant);
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
#+begin_src c :tangle (eval h_func) :comments org
|
||||||
|
qmckl_exit_code qmckl_sherman_morrison_naive_doc(
|
||||||
|
const qmckl_context context,
|
||||||
|
const uint64_t Dim,
|
||||||
|
const uint64_t N_updates,
|
||||||
|
const double* Updates,
|
||||||
|
const uint64_t* Updates_index,
|
||||||
|
const double breakdown,
|
||||||
|
double* Slater_inv,
|
||||||
|
double* determinant);
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
*** C source
|
||||||
|
|
||||||
|
|
||||||
#+begin_src c :tangle (eval c) :comments org
|
#+begin_src c :tangle (eval c) :comments org
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@ -173,9 +207,9 @@ qmckl_exit_code qmckl_sherman_morrison_naive_hpc(
|
|||||||
const int cui = Updates_index[l] - 1;
|
const int cui = Updates_index[l] - 1;
|
||||||
double den = 1.0f + C[cui];
|
double den = 1.0f + C[cui];
|
||||||
|
|
||||||
if (fabs(den) < breakdown) {
|
if (fabs(den) < breakdown)
|
||||||
return QMCKL_FAILURE;
|
return QMCKL_FAILURE;
|
||||||
}
|
|
||||||
double iden = 1.0f / den;
|
double iden = 1.0f / den;
|
||||||
|
|
||||||
// Update det(A)
|
// Update det(A)
|
||||||
@ -204,10 +238,6 @@ qmckl_exit_code qmckl_sherman_morrison_naive_hpc(
|
|||||||
}
|
}
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#+NAME:naive_template_code
|
#+NAME:naive_template_code
|
||||||
#+begin_src c
|
#+begin_src c
|
||||||
static inline qmckl_exit_code qmckl_sherman_morrison_naive_{Dim}(
|
static inline qmckl_exit_code qmckl_sherman_morrison_naive_{Dim}(
|
||||||
@ -281,10 +311,6 @@ static inline qmckl_exit_code qmckl_sherman_morrison_naive_{Dim}(
|
|||||||
}
|
}
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#+NAME:naive_kernel_generator
|
#+NAME:naive_kernel_generator
|
||||||
#+begin_src python :noweb yes :exports none
|
#+begin_src python :noweb yes :exports none
|
||||||
text="""
|
text="""
|
||||||
@ -298,10 +324,6 @@ for Dim in <<kernel_generator_range>>:
|
|||||||
return '\n'.join(result)
|
return '\n'.join(result)
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#+NAME:naive_switch-case_generator
|
#+NAME:naive_switch-case_generator
|
||||||
#+begin_src python :noweb yes :exports none
|
#+begin_src python :noweb yes :exports none
|
||||||
text="""
|
text="""
|
||||||
@ -322,10 +344,6 @@ for Dim in <<kernel_generator_range>>:
|
|||||||
return '\n'.join(result)
|
return '\n'.join(result)
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#+begin_src c :tangle (eval c) :comments org :noweb yes
|
#+begin_src c :tangle (eval c) :comments org :noweb yes
|
||||||
<<naive_kernel_generator()>>
|
<<naive_kernel_generator()>>
|
||||||
|
|
||||||
@ -346,6 +364,7 @@ qmckl_exit_code qmckl_sherman_morrison_naive(const qmckl_context context,
|
|||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_HPC
|
||||||
if (LDS == (1+(Dim-1)/SIMD_LENGTH)*SIMD_LENGTH) { // Most cases
|
if (LDS == (1+(Dim-1)/SIMD_LENGTH)*SIMD_LENGTH) { // Most cases
|
||||||
switch (Dim) {
|
switch (Dim) {
|
||||||
<<naive_switch-case_generator()>>
|
<<naive_switch-case_generator()>>
|
||||||
@ -363,58 +382,30 @@ qmckl_exit_code qmckl_sherman_morrison_naive(const qmckl_context context,
|
|||||||
determinant);
|
determinant);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
return qmckl_sherman_morrison_naive_doc(context,
|
||||||
|
Dim,
|
||||||
|
N_updates,
|
||||||
|
Updates,
|
||||||
|
Updates_index,
|
||||||
|
breakdown,
|
||||||
|
Slater_inv,
|
||||||
|
determinant);
|
||||||
|
#endif
|
||||||
|
|
||||||
return QMCKL_FAILURE;
|
return QMCKL_FAILURE;
|
||||||
}
|
}
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
*** Performance
|
|
||||||
|
|
||||||
This function performs best when there is only 1 rank-1 update in the update cycle. It is not useful to
|
|
||||||
use Sherman-Morrison with update splitting for these cycles since splitting can never resolve a situation
|
|
||||||
where applying the update causes singular behaviour.
|
|
||||||
|
|
||||||
** Fortran interface :noexport:
|
|
||||||
:PROPERTIES:
|
|
||||||
:Name: qmckl_sherman_morrison_naive
|
|
||||||
:CRetType: qmckl_exit_code
|
|
||||||
:FRetType: qmckl_exit_code
|
|
||||||
:END:
|
|
||||||
|
|
||||||
#+CALL: generate_f_interface(table=qmckl_sherman_morrison_naive_args,rettyp=get_value("FRetType"),fname=get_value("Name"))
|
|
||||||
|
|
||||||
#+RESULTS:
|
|
||||||
#+begin_src f90 :tangle (eval fh_func) :comments org :exports none
|
|
||||||
interface
|
|
||||||
integer(c_int32_t) function qmckl_sherman_morrison_naive &
|
|
||||||
(context, LDS, Dim, N_updates, Updates, Updates_index, breakdown, Slater_inv, determinant) &
|
|
||||||
bind(C)
|
|
||||||
|
|
||||||
use, intrinsic :: iso_c_binding
|
|
||||||
import
|
|
||||||
implicit none
|
|
||||||
|
|
||||||
integer (c_int64_t) , intent(in) , value :: context
|
|
||||||
integer (c_int64_t) , intent(in) , value :: LDS
|
|
||||||
integer (c_int64_t) , intent(in) , value :: Dim
|
|
||||||
integer (c_int64_t) , intent(in) , value :: N_updates
|
|
||||||
real (c_double ) , intent(in) :: Updates(N_updates*Dim)
|
|
||||||
integer (c_int64_t) , intent(in) :: Updates_index(N_updates)
|
|
||||||
real (c_double ) , intent(in) , value :: breakdown
|
|
||||||
real (c_double ) , intent(inout) :: Slater_inv(LDS*Dim)
|
|
||||||
real (c_double ) , intent(inout) :: determinant
|
|
||||||
|
|
||||||
end function qmckl_sherman_morrison_naive
|
|
||||||
end interface
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
*** Test :noexport:
|
*** Test :noexport:
|
||||||
|
|
||||||
The tests for the kernels are executed on datasets that are extracted from a run of QMC=Chem on Benzene (21 spin-up/21 spin down electrons) using 329 unique alpha determinants. The tests are run such that the kernels reject the computed inverse whenever the computed intermediate determinants or denominators are smaller than 1e-3. This is the default value in QMC=Chem. The tests will return QMCKL_SUCCESS whenever all the elements of the final matrix $R=S.S^-1 - 1$ are smaller than the given tolerance value of 1e-3, and will return QMCKL_FAILURE if the values are larger than this tolerance value.
|
The tests for the kernels are executed on datasets that are extracted from a run of
|
||||||
|
QMC=Chem on Benzene (21 spin-up/21 spin down electrons) using 329 unique alpha determinants.
|
||||||
|
The tests are run such that the kernels reject the computed inverse whenever the computed
|
||||||
|
intermediate determinants or denominators are smaller than 1e-3. This is the default value in
|
||||||
|
QMC=Chem. The tests will return QMCKL_SUCCESS whenever all the elements of the final matrix
|
||||||
|
$R=S.S^-1 - 1$ are smaller than the given tolerance value of 1e-3, and will return
|
||||||
|
QMCKL_FAILURE if the values are larger than this tolerance value.
|
||||||
|
|
||||||
#+begin_src c :tangle (eval c_test)
|
#+begin_src c :tangle (eval c_test)
|
||||||
const uint64_t Dim = 21;
|
const uint64_t Dim = 21;
|
||||||
@ -466,8 +457,99 @@ for (unsigned int i = 0; i < Dim; i++) {
|
|||||||
assert(rc == QMCKL_SUCCESS);
|
assert(rc == QMCKL_SUCCESS);
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
* Woodbury 2x2
|
** Performance
|
||||||
|
|
||||||
|
This function performs best when there is only 1 rank-1 update in the update cycle. It is
|
||||||
|
not useful to use Sherman-Morrison with update splitting for these cycles since splitting
|
||||||
|
can never resolve a situation where applying the update causes singular behaviour.
|
||||||
|
|
||||||
|
** C interface
|
||||||
|
#+begin_src f90 :tangle (eval f) :comments org :exports none
|
||||||
|
interface
|
||||||
|
integer(c_int32_t) function qmckl_sherman_morrison_naive_doc &
|
||||||
|
(context, Dim, N_updates, Updates, Updates_index, breakdown, Slater_inv, determinant) &
|
||||||
|
bind(C)
|
||||||
|
|
||||||
|
use, intrinsic :: iso_c_binding
|
||||||
|
import
|
||||||
|
implicit none
|
||||||
|
|
||||||
|
integer (c_int64_t) , intent(in) , value :: context
|
||||||
|
integer (c_int64_t) , intent(in) , value :: Dim
|
||||||
|
integer (c_int64_t) , intent(in) , value :: N_updates
|
||||||
|
real (c_double ) , intent(in) :: Updates(N_updates*Dim)
|
||||||
|
integer (c_int64_t) , intent(in) :: Updates_index(N_updates)
|
||||||
|
real (c_double ) , intent(in) , value :: breakdown
|
||||||
|
real (c_double ) , intent(inout) :: Slater_inv(Dim*Dim)
|
||||||
|
real (c_double ) , intent(inout) :: determinant
|
||||||
|
|
||||||
|
integer(c_int32_t), external :: qmckl_sherman_morrison_naive_doc_f
|
||||||
|
info = qmckl_sherman_morrison_naive_doc_f &
|
||||||
|
(context, Dim, N_updates, Updates, &
|
||||||
|
Updates_index, breakdown, Slater_inv, determinant)
|
||||||
|
|
||||||
|
end function qmckl_sherman_morrison_naive_doc
|
||||||
|
end interface
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
** Fortran interface :noexport:
|
||||||
|
:PROPERTIES:
|
||||||
|
:Name: qmckl_sherman_morrison_naive
|
||||||
|
:CRetType: qmckl_exit_code
|
||||||
|
:FRetType: qmckl_exit_code
|
||||||
|
:END:
|
||||||
|
|
||||||
|
#+CALL: generate_f_interface(table=qmckl_sherman_morrison_naive_args,rettyp=get_value("FRetType"),fname=get_value("Name"))
|
||||||
|
|
||||||
|
#+RESULTS:
|
||||||
|
#+begin_src f90 :tangle (eval fh_func) :comments org :exports none
|
||||||
|
interface
|
||||||
|
integer(c_int32_t) function qmckl_sherman_morrison_naive &
|
||||||
|
(context, LDS, Dim, N_updates, Updates, Updates_index, breakdown, Slater_inv, determinant) &
|
||||||
|
bind(C)
|
||||||
|
|
||||||
|
use, intrinsic :: iso_c_binding
|
||||||
|
import
|
||||||
|
implicit none
|
||||||
|
|
||||||
|
integer (c_int64_t) , intent(in) , value :: context
|
||||||
|
integer (c_int64_t) , intent(in) , value :: LDS
|
||||||
|
integer (c_int64_t) , intent(in) , value :: Dim
|
||||||
|
integer (c_int64_t) , intent(in) , value :: N_updates
|
||||||
|
real (c_double ) , intent(in) :: Updates(N_updates*Dim)
|
||||||
|
integer (c_int64_t) , intent(in) :: Updates_index(N_updates)
|
||||||
|
real (c_double ) , intent(in) , value :: breakdown
|
||||||
|
real (c_double ) , intent(inout) :: Slater_inv(LDS*Dim)
|
||||||
|
real (c_double ) , intent(inout) :: determinant
|
||||||
|
|
||||||
|
end function qmckl_sherman_morrison_naive
|
||||||
|
end interface
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+begin_src f90 :tangle (eval fh_func) :comments org :exports none
|
||||||
|
interface
|
||||||
|
integer(c_int32_t) function qmckl_sherman_morrison_naive_doc &
|
||||||
|
(context, Dim, N_updates, Updates, Updates_index, breakdown, Slater_inv, determinant) &
|
||||||
|
bind(C)
|
||||||
|
|
||||||
|
use, intrinsic :: iso_c_binding
|
||||||
|
import
|
||||||
|
implicit none
|
||||||
|
|
||||||
|
integer (c_int64_t) , intent(in) , value :: context
|
||||||
|
integer (c_int64_t) , intent(in) , value :: Dim
|
||||||
|
integer (c_int64_t) , intent(in) , value :: N_updates
|
||||||
|
real (c_double ) , intent(in) :: Updates(N_updates*Dim)
|
||||||
|
integer (c_int64_t) , intent(in) :: Updates_index(N_updates)
|
||||||
|
real (c_double ) , intent(in) , value :: breakdown
|
||||||
|
real (c_double ) , intent(inout) :: Slater_inv(Dim*Dim)
|
||||||
|
real (c_double ) , intent(inout) :: determinant
|
||||||
|
|
||||||
|
end function qmckl_sherman_morrison_naive_doc
|
||||||
|
end interface
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
* Woodbury 2x2
|
||||||
** ~qmckl_woodbury_2x2~
|
** ~qmckl_woodbury_2x2~
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:Name: qmckl_woodbury_2x2
|
:Name: qmckl_woodbury_2x2
|
||||||
@ -790,7 +872,6 @@ qmckl_exit_code qmckl_woodbury_2x2(const qmckl_context context,
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
*** Performance
|
*** Performance
|
||||||
|
|
||||||
This function is most efficient when used in cases where there are only 2 rank-1 updates and
|
This function is most efficient when used in cases where there are only 2 rank-1 updates and
|
||||||
@ -860,7 +941,6 @@ assert(rc == QMCKL_SUCCESS);
|
|||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
* Woodbury 3x3
|
* Woodbury 3x3
|
||||||
|
|
||||||
** ~qmckl_woodbury_3x3~
|
** ~qmckl_woodbury_3x3~
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:Name: qmckl_woodbury_3x3
|
:Name: qmckl_woodbury_3x3
|
||||||
@ -1209,7 +1289,6 @@ qmckl_exit_code qmckl_woodbury_3x3(const qmckl_context context,
|
|||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
*** Performance...
|
*** Performance...
|
||||||
|
|
||||||
This function is most efficient when used in cases where there are only 3 rank-1 updates and
|
This function is most efficient when used in cases where there are only 3 rank-1 updates and
|
||||||
@ -1279,7 +1358,6 @@ assert(rc == QMCKL_SUCCESS);
|
|||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
* Sherman-Morrison with update splitting
|
* Sherman-Morrison with update splitting
|
||||||
|
|
||||||
** ~qmckl_sherman_morrison_splitting~
|
** ~qmckl_sherman_morrison_splitting~
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:Name: qmckl_sherman_morrison_splitting
|
:Name: qmckl_sherman_morrison_splitting
|
||||||
@ -1314,7 +1392,6 @@ assert(rc == QMCKL_SUCCESS);
|
|||||||
If the determinant of the Slater-matrix is passed, it will be updated to the determinant resulting
|
If the determinant of the Slater-matrix is passed, it will be updated to the determinant resulting
|
||||||
from applying the updates to the original matrix.
|
from applying the updates to the original matrix.
|
||||||
|
|
||||||
|
|
||||||
*** Requirements
|
*** Requirements
|
||||||
|
|
||||||
* ~context~ is not ~QMCKL_NULL_CONTEXT~
|
* ~context~ is not ~QMCKL_NULL_CONTEXT~
|
||||||
@ -1454,7 +1531,6 @@ assert(rc == QMCKL_SUCCESS);
|
|||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
* Woodbury 3x3 and 2x2 with Sherman-Morrison and update splitting
|
* Woodbury 3x3 and 2x2 with Sherman-Morrison and update splitting
|
||||||
|
|
||||||
** ~qmckl_sherman_morrison_smw32s~
|
** ~qmckl_sherman_morrison_smw32s~
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:Name: qmckl_sherman_morrison_smw32s
|
:Name: qmckl_sherman_morrison_smw32s
|
||||||
|
Loading…
Reference in New Issue
Block a user