1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2024-12-22 12:23:56 +01:00

qmckl_memory

This commit is contained in:
Anthony Scemama 2021-02-19 01:39:42 +01:00
parent 680a0880b4
commit 6f2adf2921
2 changed files with 25 additions and 13 deletions

View File

@ -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
\]
\begin{eqnarray*}
\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 \\
@ -38,6 +39,8 @@ MunitResult test_qmckl_ao() {
\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} \\
\end{eqnarray*}
\begin{eqnarray*}
\left( \frac{\partial }{\partial x^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
~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_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 \]
@ -740,7 +743,6 @@ munit_assert_int(0, ==, test_qmckl_ao_gaussian_vgl(context));
return QMCKL_FAILURE;
return MUNIT_OK;
}
#+END_SRC

View File

@ -10,6 +10,7 @@
*** Headers :noexport:
#+BEGIN_SRC C :tangle qmckl_memory.c
#include "qmckl.h"
#include <assert.h>
#+END_SRC
#+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 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
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
#+BEGIN_SRC C :tangle qmckl_memory.c
void* qmckl_malloc(const qmckl_context ctx, const size_t size) {
if (ctx == (qmckl_context) 0) {
/* Avoids unused parameter error */
return malloc( (size_t) size );
}
return malloc( (size_t) size );
if (ctx == (qmckl_context) 0) {}; /* Avoid unused argument warning */
void * result = malloc( (size_t) size );
assert (result != NULL) ;
return result;
}
#+END_SRC
**** Test :noexport:
#+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));
munit_assert(a != NULL);
a[0] = 1;
a[1] = 2;
a[2] = 3;
@ -64,27 +68,33 @@ munit_assert_int(a[2], ==, 3);
*** ~qmckl_free~
#+BEGIN_SRC C :tangle qmckl.h
void qmckl_free(void *ptr);
void* qmckl_free(void *ptr);
#+END_SRC
#+BEGIN_SRC f90 :tangle qmckl_f.f90
interface
subroutine qmckl_free (ptr) bind(C)
type (c_ptr) function qmckl_free (ptr) bind(C)
use, intrinsic :: iso_c_binding
type (c_ptr), intent(in), value :: ptr
end subroutine qmckl_free
end function qmckl_free
end interface
#+END_SRC
**** Source
#+BEGIN_SRC C :tangle qmckl_memory.c
void qmckl_free(void *ptr) {
void* qmckl_free(void *ptr) {
assert (ptr != NULL);
free(ptr);
return NULL;
}
#+END_SRC
**** Test :noexport:
#+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 of files :noexport: