mirror of
https://github.com/TREX-CoE/qmckl.git
synced 2025-01-03 18:16:28 +01:00
qmckl_memory
This commit is contained in:
parent
680a0880b4
commit
6f2adf2921
@ -30,6 +30,7 @@ MunitResult test_qmckl_ao() {
|
|||||||
\[
|
\[
|
||||||
P_l(\mathbf{r},\mathbf{R}_i) = (x-X_i)^a (y-Y_i)^b (z-Z_i)^c
|
P_l(\mathbf{r},\mathbf{R}_i) = (x-X_i)^a (y-Y_i)^b (z-Z_i)^c
|
||||||
\]
|
\]
|
||||||
|
|
||||||
\begin{eqnarray*}
|
\begin{eqnarray*}
|
||||||
\frac{\partial }{\partial x} P_l\left(\mathbf{r},\mathbf{R}_i \right) &
|
\frac{\partial }{\partial x} P_l\left(\mathbf{r},\mathbf{R}_i \right) &
|
||||||
= & a (x-X_i)^{a-1} (y-Y_i)^b (z-Z_i)^c \\
|
= & a (x-X_i)^{a-1} (y-Y_i)^b (z-Z_i)^c \\
|
||||||
@ -38,6 +39,8 @@ MunitResult test_qmckl_ao() {
|
|||||||
\frac{\partial }{\partial z} P_l\left(\mathbf{r},\mathbf{R}_i \right) &
|
\frac{\partial }{\partial z} P_l\left(\mathbf{r},\mathbf{R}_i \right) &
|
||||||
= & c (x-X_i)^a (y-Y_i)^b (z-Z_i)^{c-1} \\
|
= & c (x-X_i)^a (y-Y_i)^b (z-Z_i)^{c-1} \\
|
||||||
\end{eqnarray*}
|
\end{eqnarray*}
|
||||||
|
|
||||||
|
|
||||||
\begin{eqnarray*}
|
\begin{eqnarray*}
|
||||||
\left( \frac{\partial }{\partial x^2} +
|
\left( \frac{\partial }{\partial x^2} +
|
||||||
\frac{\partial }{\partial y^2} +
|
\frac{\partial }{\partial y^2} +
|
||||||
@ -527,7 +530,7 @@ munit_assert_int(0, ==, test_qmckl_ao_polynomial_vgl(context));
|
|||||||
Computes the values, gradients and Laplacians at a given point of
|
Computes the values, gradients and Laplacians at a given point of
|
||||||
~n~ Gaussian functions centered at the same point:
|
~n~ Gaussian functions centered at the same point:
|
||||||
|
|
||||||
\[ v_i = exp(-a_i |X-R|^2) \]
|
\[ v_i = \exp(-a_i |X-R|^2) \]
|
||||||
\[ \nabla_x v_i = -2 a_i (X_x - R_x) v_i \]
|
\[ \nabla_x v_i = -2 a_i (X_x - R_x) v_i \]
|
||||||
\[ \nabla_y v_i = -2 a_i (X_y - R_y) v_i \]
|
\[ \nabla_y v_i = -2 a_i (X_y - R_y) v_i \]
|
||||||
\[ \nabla_z v_i = -2 a_i (X_z - R_z) v_i \]
|
\[ \nabla_z v_i = -2 a_i (X_z - R_z) v_i \]
|
||||||
@ -740,7 +743,6 @@ munit_assert_int(0, ==, test_qmckl_ao_gaussian_vgl(context));
|
|||||||
return QMCKL_FAILURE;
|
return QMCKL_FAILURE;
|
||||||
return MUNIT_OK;
|
return MUNIT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
*** Headers :noexport:
|
*** Headers :noexport:
|
||||||
#+BEGIN_SRC C :tangle qmckl_memory.c
|
#+BEGIN_SRC C :tangle qmckl_memory.c
|
||||||
#include "qmckl.h"
|
#include "qmckl.h"
|
||||||
|
#include <assert.h>
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
#+BEGIN_SRC C :tangle test_qmckl_memory.c
|
#+BEGIN_SRC C :tangle test_qmckl_memory.c
|
||||||
@ -22,6 +23,8 @@ MunitResult test_qmckl_memory() {
|
|||||||
|
|
||||||
Memory allocation function, letting the library choose how the
|
Memory allocation function, letting the library choose how the
|
||||||
memory will be allocated, and a pointer is returned to the user.
|
memory will be allocated, and a pointer is returned to the user.
|
||||||
|
The context is passed to let the library store data related to the
|
||||||
|
allocation inside the context.
|
||||||
|
|
||||||
#+BEGIN_SRC C :tangle qmckl.h
|
#+BEGIN_SRC C :tangle qmckl.h
|
||||||
void* qmckl_malloc(const qmckl_context ctx, const size_t size);
|
void* qmckl_malloc(const qmckl_context ctx, const size_t size);
|
||||||
@ -40,19 +43,20 @@ void* qmckl_malloc(const qmckl_context ctx, const size_t size);
|
|||||||
**** Source
|
**** Source
|
||||||
#+BEGIN_SRC C :tangle qmckl_memory.c
|
#+BEGIN_SRC C :tangle qmckl_memory.c
|
||||||
void* qmckl_malloc(const qmckl_context ctx, const size_t size) {
|
void* qmckl_malloc(const qmckl_context ctx, const size_t size) {
|
||||||
if (ctx == (qmckl_context) 0) {
|
if (ctx == (qmckl_context) 0) {}; /* Avoid unused argument warning */
|
||||||
/* Avoids unused parameter error */
|
void * result = malloc( (size_t) size );
|
||||||
return malloc( (size_t) size );
|
assert (result != NULL) ;
|
||||||
}
|
return result;
|
||||||
return malloc( (size_t) size );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
**** Test :noexport:
|
**** Test :noexport:
|
||||||
#+BEGIN_SRC C :tangle test_qmckl_memory.c
|
#+BEGIN_SRC C :tangle test_qmckl_memory.c
|
||||||
int *a;
|
int *a = NULL;
|
||||||
|
munit_assert(a == NULL);
|
||||||
a = (int*) qmckl_malloc( (qmckl_context) 1, 3*sizeof(int));
|
a = (int*) qmckl_malloc( (qmckl_context) 1, 3*sizeof(int));
|
||||||
|
munit_assert(a != NULL);
|
||||||
a[0] = 1;
|
a[0] = 1;
|
||||||
a[1] = 2;
|
a[1] = 2;
|
||||||
a[2] = 3;
|
a[2] = 3;
|
||||||
@ -64,27 +68,33 @@ munit_assert_int(a[2], ==, 3);
|
|||||||
*** ~qmckl_free~
|
*** ~qmckl_free~
|
||||||
|
|
||||||
#+BEGIN_SRC C :tangle qmckl.h
|
#+BEGIN_SRC C :tangle qmckl.h
|
||||||
void qmckl_free(void *ptr);
|
void* qmckl_free(void *ptr);
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
#+BEGIN_SRC f90 :tangle qmckl_f.f90
|
#+BEGIN_SRC f90 :tangle qmckl_f.f90
|
||||||
interface
|
interface
|
||||||
subroutine qmckl_free (ptr) bind(C)
|
type (c_ptr) function qmckl_free (ptr) bind(C)
|
||||||
use, intrinsic :: iso_c_binding
|
use, intrinsic :: iso_c_binding
|
||||||
type (c_ptr), intent(in), value :: ptr
|
type (c_ptr), intent(in), value :: ptr
|
||||||
end subroutine qmckl_free
|
end function qmckl_free
|
||||||
end interface
|
end interface
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
**** Source
|
**** Source
|
||||||
#+BEGIN_SRC C :tangle qmckl_memory.c
|
#+BEGIN_SRC C :tangle qmckl_memory.c
|
||||||
void qmckl_free(void *ptr) {
|
void* qmckl_free(void *ptr) {
|
||||||
|
assert (ptr != NULL);
|
||||||
free(ptr);
|
free(ptr);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
**** Test :noexport:
|
**** Test :noexport:
|
||||||
#+BEGIN_SRC C :tangle test_qmckl_memory.c
|
#+BEGIN_SRC C :tangle test_qmckl_memory.c
|
||||||
qmckl_free(a);
|
munit_assert(a != NULL);
|
||||||
|
a = qmckl_free(a);
|
||||||
|
munit_assert(a == NULL);
|
||||||
|
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
*** End of files :noexport:
|
*** End of files :noexport:
|
||||||
|
Loading…
Reference in New Issue
Block a user