1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2024-07-18 08:53:47 +02:00

Merge pull request #74 from GianFree/jastrow_hpc

Jastrow hpc
This commit is contained in:
Anthony Scemama 2022-04-06 16:06:19 +02:00 committed by GitHub
commit 4224991b12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3279,7 +3279,7 @@ qmckl_exit_code qmckl_provide_een_rescaled_e(qmckl_context context)
| ~een_rescaled_e~ | ~double[walk_num][0:cord_num][elec_num][elec_num]~ | out | Electron-electron rescaled distances |
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
integer function qmckl_compute_een_rescaled_e_f( &
integer function qmckl_compute_een_rescaled_e_doc_f( &
context, walk_num, elec_num, cord_num, rescale_factor_kappa_ee, &
ee_distance, een_rescaled_e) &
result(info)
@ -3298,7 +3298,6 @@ integer function qmckl_compute_een_rescaled_e_f( &
allocate(een_rescaled_e_ij(elec_num * (elec_num - 1) / 2, cord_num + 1))
info = QMCKL_SUCCESS
if (context == QMCKL_NULL_CONTEXT) then
@ -3327,6 +3326,7 @@ integer function qmckl_compute_een_rescaled_e_f( &
een_rescaled_e_ij = 0.0d0
een_rescaled_e_ij(:, 1) = 1.0d0
k = 0
do j = 1, elec_num
do i = 1, j - 1
@ -3335,6 +3335,7 @@ integer function qmckl_compute_een_rescaled_e_f( &
end do
end do
do l = 2, cord_num
do k = 1, elec_num * (elec_num - 1)/2
een_rescaled_e_ij(k, l + 1) = een_rescaled_e_ij(k, l + 1 - 1) * een_rescaled_e_ij(k, 2)
@ -3343,6 +3344,7 @@ integer function qmckl_compute_een_rescaled_e_f( &
! prepare the actual een table
een_rescaled_e(:, :, 0, nw) = 1.0d0
do l = 1, cord_num
k = 0
do j = 1, elec_num
@ -3363,29 +3365,15 @@ integer function qmckl_compute_een_rescaled_e_f( &
end do
end function qmckl_compute_een_rescaled_e_f
end function qmckl_compute_een_rescaled_e_doc_f
#+end_src
#+CALL: generate_c_header(table=qmckl_factor_een_rescaled_e_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
#+RESULTS:
#+begin_src c :tangle (eval h_func) :comments org
qmckl_exit_code qmckl_compute_een_rescaled_e (
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t cord_num,
const double rescale_factor_kappa_ee,
const double* ee_distance,
double* const een_rescaled_e );
#+end_src
#+CALL: generate_c_interface(table=qmckl_factor_een_rescaled_e_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
#+CALL: generate_c_interface(table=qmckl_factor_een_rescaled_e_args,rettyp=get_value("CRetType"),fname="qmckl_compute_een_rescaled_e_doc")
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
integer(c_int32_t) function qmckl_compute_een_rescaled_e &
(context, walk_num, elec_num, cord_num, rescale_factor_kappa_ee, &
integer(c_int32_t) function qmckl_compute_een_rescaled_e_doc &
(context, walk_num, elec_num, cord_num, rescale_factor_kappa_ee, &
ee_distance, een_rescaled_e) &
bind(C) result(info)
@ -3400,13 +3388,188 @@ end function qmckl_compute_een_rescaled_e_f
real (c_double ) , intent(in) :: ee_distance(elec_num,elec_num,walk_num)
real (c_double ) , intent(out) :: een_rescaled_e(elec_num,elec_num,0:cord_num,walk_num)
integer(c_int32_t), external :: qmckl_compute_een_rescaled_e_f
info = qmckl_compute_een_rescaled_e_f &
(context, walk_num, elec_num, cord_num, rescale_factor_kappa_ee, ee_distance, een_rescaled_e)
integer(c_int32_t), external :: qmckl_compute_een_rescaled_e_doc_f
info = qmckl_compute_een_rescaled_e_doc_f &
(context, walk_num, elec_num, cord_num, rescale_factor_kappa_ee, ee_distance, een_rescaled_e)
end function qmckl_compute_een_rescaled_e
end function qmckl_compute_een_rescaled_e_doc
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes
qmckl_exit_code qmckl_compute_een_rescaled_e_hpc (
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t cord_num,
const double rescale_factor_kappa_ee,
const double* ee_distance,
double* const een_rescaled_e ) {
double *een_rescaled_e_ij;
double x;
const int64_t elec_pairs = (elec_num * (elec_num - 1)) / 2;
const int64_t len_een_ij = elec_pairs * (cord_num + 1);
int64_t k;
// number of element for the een_rescaled_e_ij[N_e*(N_e-1)/2][cord+1]
// probably in C is better [cord+1, Ne*(Ne-1)/2]
//elec_pairs = (elec_num * (elec_num - 1)) / 2;
//len_een_ij = elec_pairs * (cord_num + 1);
een_rescaled_e_ij = (double *) malloc (len_een_ij * sizeof(double));
if (context == QMCKL_NULL_CONTEXT) {
return QMCKL_INVALID_CONTEXT;
}
if (walk_num <= 0) {
return QMCKL_INVALID_ARG_2;
}
if (elec_num <= 0) {
return QMCKL_INVALID_ARG_3;
}
if (cord_num <= 0) {
return QMCKL_INVALID_ARG_4;
}
// Prepare table of exponentiated distances raised to appropriate power
// init
for (int kk = 0; kk < walk_num*(cord_num+1)*elec_num*elec_num; ++kk) {
een_rescaled_e[kk]= 0.0;
}
/*
for (int nw = 0; nw < walk_num; ++nw) {
for (int l = 0; l < (cord_num + 1); ++l) {
for (int i = 0; i < elec_num; ++i) {
for (int j = 0; j < elec_num; ++j) {
een_rescaled_e[j + i*elec_num + l*elec_num*elec_num + nw*(cord_num+1)*elec_num*elec_num]= 0.0;
}
}
}
}
*/
for (int nw = 0; nw < walk_num; ++nw) {
for (int kk = 0; kk < len_een_ij; ++kk) {
// this array initialized at 0 except een_rescaled_e_ij(:, 1) = 1.0d0
// and the arrangement of indices is [cord_num+1, ne*(ne-1)/2]
een_rescaled_e_ij[kk]= ( kk < (elec_pairs) ? 1.0 : 0.0 );
}
k = 0;
for (int i = 0; i < elec_num; ++i) {
for (int j = 0; j < i; ++j) {
// een_rescaled_e_ij(k, 2) = dexp(-rescale_factor_kappa_ee * ee_distance(i, j, nw));
een_rescaled_e_ij[k + elec_pairs] = exp(-rescale_factor_kappa_ee * \
ee_distance[j + i*elec_num + nw*(elec_num*elec_num)]);
k = k + 1;
}
}
for (int l = 2; l < (cord_num+1); ++l) {
for (int k = 0; k < elec_pairs; ++k) {
// een_rescaled_e_ij(k, l + 1) = een_rescaled_e_ij(k, l + 1 - 1) * een_rescaled_e_ij(k, 2)
een_rescaled_e_ij[k+l*elec_pairs] = een_rescaled_e_ij[k + (l - 1)*elec_pairs] * \
een_rescaled_e_ij[k + elec_pairs];
}
}
// prepare the actual een table
for (int i = 0; i < elec_num; ++i){
for (int j = 0; j < elec_num; ++j) {
een_rescaled_e[j + i*elec_num + 0 + nw*(cord_num+1)*elec_num*elec_num] = 1.0;
}
}
// Up to here it should work.
for ( int l = 1; l < (cord_num+1); ++l) {
k = 0;
for (int i = 0; i < elec_num; ++i) {
for (int j = 0; j < i; ++j) {
x = een_rescaled_e_ij[k + l*elec_pairs];
een_rescaled_e[j + i*elec_num + l*elec_num*elec_num + nw*elec_num*elec_num*(cord_num+1)] = x;
een_rescaled_e[i + j*elec_num + l*elec_num*elec_num + nw*elec_num*elec_num*(cord_num+1)] = x;
k = k + 1;
}
}
}
for (int l = 0; l < (cord_num + 1); ++l) {
for (int j = 0; j < elec_num; ++j) {
een_rescaled_e[j + j*elec_num + l*elec_num*elec_num + nw*elec_num*elec_num*(cord_num+1)] = 0.0;
}
}
}
free(een_rescaled_e_ij);
return QMCKL_SUCCESS;
}
#+end_src
#+CALL: generate_c_header(table=qmckl_factor_een_rescaled_e_args,rettyp=get_value("CRetType"),fname="qmckl_compute_een_rescaled_e_doc")
#+RESULTS:
#+begin_src c :tangle (eval h_func) :comments org
qmckl_exit_code qmckl_compute_een_rescaled_e (
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t cord_num,
const double rescale_factor_kappa_ee,
const double* ee_distance,
double* const een_rescaled_e );
#+end_src
#+begin_src c :tangle (eval h_private_func) :comments org
qmckl_exit_code qmckl_compute_een_rescaled_e_doc (
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t cord_num,
const double rescale_factor_kappa_ee,
const double* ee_distance,
double* const een_rescaled_e );
#+end_src
#+begin_src c :tangle (eval h_private_func) :comments org
qmckl_exit_code qmckl_compute_een_rescaled_e_hpc (
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t cord_num,
const double rescale_factor_kappa_ee,
const double* ee_distance,
double* const een_rescaled_e );
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes
qmckl_exit_code qmckl_compute_een_rescaled_e (
const qmckl_context context,
const int64_t walk_num,
const int64_t elec_num,
const int64_t cord_num,
const double rescale_factor_kappa_ee,
const double* ee_distance,
double* const een_rescaled_e ) {
#ifdef HAVE_HPC
return qmckl_compute_een_rescaled_e_hpc(context, walk_num, elec_num, cord_num, rescale_factor_kappa_ee, ee_distance, een_rescaled_e);
#else
return qmckl_compute_een_rescaled_e_doc(context, walk_num, elec_num, cord_num, rescale_factor_kappa_ee, ee_distance, een_rescaled_e);
#endif
}
#+end_src
*** Test
#+begin_src python :results output :exports none :noweb yes
@ -3481,7 +3644,6 @@ assert(fabs(een_rescaled_e[0][1][0][4]-0.01754273169464735) < 1.e-12);
assert(fabs(een_rescaled_e[0][2][1][3]-0.02214680362033448) < 1.e-12);
assert(fabs(een_rescaled_e[0][2][1][4]-0.0005700154999202759) < 1.e-12);
assert(fabs(een_rescaled_e[0][2][1][5]-0.3424402276009091) < 1.e-12);
#+end_src
** Electron-electron rescaled distances for each order and derivatives
@ -5178,7 +5340,7 @@ qmckl_exit_code qmckl_compute_dim_cord_vect (
| ~cord_vect_full~ | ~double[dim_cord_vect][nucl_num]~ | out | Full list of coefficients |
#+begin_src f90 :comments org :tangle (eval f) :noweb yes
integer function qmckl_compute_cord_vect_full_f( &
integer function qmckl_compute_cord_vect_full_doc_f( &
context, nucl_num, dim_cord_vect, type_nucl_num, &
type_nucl_vector, cord_vector, cord_vect_full) &
result(info)
@ -5221,31 +5383,16 @@ integer function qmckl_compute_cord_vect_full_f( &
cord_vect_full(a,1:dim_cord_vect) = cord_vector(type_nucl_vector(a),1:dim_cord_vect)
end do
end function qmckl_compute_cord_vect_full_f
end function qmckl_compute_cord_vect_full_doc_f
#+end_src
#+CALL: generate_c_header(table=qmckl_factor_cord_vect_full_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
#+RESULTS:
#+begin_src c :tangle (eval h_func) :comments org
qmckl_exit_code qmckl_compute_cord_vect_full (
const qmckl_context context,
const int64_t nucl_num,
const int64_t dim_cord_vect,
const int64_t type_nucl_num,
const int64_t* type_nucl_vector,
const double* cord_vector,
double* const cord_vect_full );
#+end_src
#+CALL: generate_c_interface(table=qmckl_factor_cord_vect_full_args,rettyp=get_value("CRetType"),fname=get_value("Name"))
#+CALL: generate_c_interface(table=qmckl_factor_cord_vect_full_args,rettyp=get_value("CRetType"),fname="qmckl_compute_cord_vect_full_doc")
#+RESULTS:
#+begin_src f90 :tangle (eval f) :comments org :exports none
integer(c_int32_t) function qmckl_compute_cord_vect_full &
(context, nucl_num, dim_cord_vect, type_nucl_num, type_nucl_vector, cord_vector, cord_vect_full) &
bind(C) result(info)
integer(c_int32_t) function qmckl_compute_cord_vect_full_doc &
(context, nucl_num, dim_cord_vect, type_nucl_num, type_nucl_vector, cord_vector, cord_vect_full) &
bind(C) result(info)
use, intrinsic :: iso_c_binding
implicit none
@ -5258,13 +5405,106 @@ end function qmckl_compute_cord_vect_full_f
real (c_double ) , intent(in) :: cord_vector(type_nucl_num,dim_cord_vect)
real (c_double ) , intent(out) :: cord_vect_full(nucl_num,dim_cord_vect)
integer(c_int32_t), external :: qmckl_compute_cord_vect_full_f
info = qmckl_compute_cord_vect_full_f &
(context, nucl_num, dim_cord_vect, type_nucl_num, type_nucl_vector, cord_vector, cord_vect_full)
integer(c_int32_t), external :: qmckl_compute_cord_vect_full_doc_f
info = qmckl_compute_cord_vect_full_doc_f &
(context, nucl_num, dim_cord_vect, type_nucl_num, type_nucl_vector, cord_vector, cord_vect_full)
end function qmckl_compute_cord_vect_full
end function qmckl_compute_cord_vect_full_doc
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes
qmckl_exit_code qmckl_compute_cord_vect_full_hpc (
const qmckl_context context,
const int64_t nucl_num,
const int64_t dim_cord_vect,
const int64_t type_nucl_num,
const int64_t* type_nucl_vector,
const double* cord_vector,
double* const cord_vect_full ) {
if (context == QMCKL_NULL_CONTEXT) {
return QMCKL_INVALID_CONTEXT;
}
if (nucl_num <= 0) {
return QMCKL_INVALID_ARG_2;
}
if (type_nucl_num <= 0) {
return QMCKL_INVALID_ARG_4;
}
if (dim_cord_vect <= 0) {
return QMCKL_INVALID_ARG_5;
}
for (int i=0; i < dim_cord_vect; ++i) {
for (int a=0; a < nucl_num; ++a){
cord_vect_full[a + i*nucl_num] = cord_vector[(type_nucl_vector[a]-1)+i*type_nucl_num];
}
}
return QMCKL_SUCCESS;
}
#+end_src
#+CALL: generate_c_header(table=qmckl_factor_cord_vect_full_args,rettyp=get_value("CRetType"),fname="qmckl_compute_cord_vect_full_doc")
#+RESULTS:
#+begin_src c :tangle (eval h_func) :comments org
qmckl_exit_code qmckl_compute_cord_vect_full (
const qmckl_context context,
const int64_t nucl_num,
const int64_t dim_cord_vect,
const int64_t type_nucl_num,
const int64_t* type_nucl_vector,
const double* cord_vector,
double* const cord_vect_full );
#+end_src
#+begin_src c :tangle (eval h_private_func) :comments org
qmckl_exit_code qmckl_compute_cord_vect_full_doc (
const qmckl_context context,
const int64_t nucl_num,
const int64_t dim_cord_vect,
const int64_t type_nucl_num,
const int64_t* type_nucl_vector,
const double* cord_vector,
double* const cord_vect_full );
#+end_src
#+begin_src c :tangle (eval h_private_func) :comments org
qmckl_exit_code qmckl_compute_cord_vect_full_hpc (
const qmckl_context context,
const int64_t nucl_num,
const int64_t dim_cord_vect,
const int64_t type_nucl_num,
const int64_t* type_nucl_vector,
const double* cord_vector,
double* const cord_vect_full );
#+end_src
#+begin_src c :comments org :tangle (eval c) :noweb yes
qmckl_exit_code qmckl_compute_cord_vect_full (
const qmckl_context context,
const int64_t nucl_num,
const int64_t dim_cord_vect,
const int64_t type_nucl_num,
const int64_t* type_nucl_vector,
const double* cord_vector,
double* const cord_vect_full ) {
#ifdef HAVE_HPC
return qmckl_compute_cord_vect_full_hpc(context, nucl_num, dim_cord_vect, type_nucl_num, type_nucl_vector, cord_vector, cord_vect_full);
#else
return qmckl_compute_cord_vect_full_doc(context, nucl_num, dim_cord_vect, type_nucl_num, type_nucl_vector, cord_vector, cord_vect_full);
#endif
}
#+end_src
*** Compute lkpm_combined_index
:PROPERTIES:
:Name: qmckl_compute_lkpm_combined_index
@ -6422,6 +6662,7 @@ rc = qmckl_get_jastrow_dtmp_c(context, &(dtmp_c[0][0][0][0][0][0]));
assert(fabs(tmp_c[0][0][1][0][0] - 2.7083473948352403) < 1e-12);
assert(fabs(dtmp_c[0][1][0][0][0][0] - 0.237440520852232) < 1e-12);
return QMCKL_SUCCESS;
#+end_src
** Electron-electron-nucleus Jastrow \(f_{een}\)
@ -6922,6 +7163,7 @@ double factor_een[walk_num];
rc = qmckl_get_jastrow_factor_een(context, &(factor_een[0]),walk_num);
assert(fabs(factor_een[0] + 0.37407972141304213) < 1e-12);
return QMCKL_SUCCESS;
#+end_src
** Electron-electron-nucleus Jastrow \(f_{een}\) derivative