diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 6b77119..7619bfb 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -21,29 +21,29 @@ jobs: run: sudo apt-get install emacs26 - name: install htmlize - run: git clone https://github.com/hniksic/emacs-htmlize && cp emacs-htmlize/htmlize.el docs/ + run: git clone https://github.com/hniksic/emacs-htmlize && cp emacs-htmlize/htmlize.el share/doc/qmckl/html/ - name: make - run: make -C src/ doc && ls -sh ./docs/ + run: make -C src/ doc && ls -sh ./share/doc/qmckl/html/ - name: pwd run: pwd - name: ls - run: ls -sh ./docs + run: ls -sh ./share/doc/qmckl/html/ # - name: Deploy # uses: peaceiris/actions-gh-pages@v3 # with: # github_token: ${{ secrets.GITHUB_TOKEN }} -# publish_dir: ./docs +# publish_dir: ./share/doc/qmckl/html/ - name: Deploy uses: JamesIves/github-pages-deploy-action@4.1.0 with: branch: gh-pages - folder: ./docs + folder: ./share/doc/qmckl/html/ # github_token: ${{ secrets.GITHUB_TOKEN }} -# publish_dir: ./docs +# publish_dir: ./share/doc/qmckl/html/ diff --git a/.gitmodules b/.gitmodules index 6d6dce9..8ad4907 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "munit"] path = munit url = https://github.com/nemequ/munit/ -[submodule "docs/org-html-themes"] - path = docs/org-html-themes - url = https://github.com/fniessen/org-html-themes.git diff --git a/Makefile b/Makefile index 9d09487..7304c53 100644 --- a/Makefile +++ b/Makefile @@ -16,15 +16,19 @@ static_lib=$(QMCKL_ROOT)/lib/libqmckl.a qmckl_h=$(QMCKL_ROOT)/include/qmckl.h qmckl_f=$(QMCKL_ROOT)/share/qmckl/fortran/qmckl_f.f90 +docdir=$(prefix)/share/doc/qmckl +libdir=$(prefix)/lib +includedir=$(prefix)/include +fortrandir=$(prefix)/share/qmckl/fortran + export prefix shared_lib static_lib qmckl_h qmckl_f -all clean doc check install uninstall: +all clean doc install uninstall check: $(MAKE) -C src $@ dist: $(distdir).tar.gz - $(distdir).tar.gz: $(distdir) tar chof - $(distdir) | gzip -9 -c > $@ rm -rf $(distdir) @@ -39,15 +43,15 @@ $(distdir): $(qmckl_h) $(qmckl_f) $(static_lib) $(shared_lib) src/Makefile.gener mkdir -p $(distdir)/share/doc/qmckl/html/ mkdir -p $(distdir)/share/doc/qmckl/text/ mkdir -p $(distdir)/man - cp munit/munit.h munit/munit.c $(distdir)/munit/ - cp src/*.c src/*.h src/*.f90 $(distdir)/src/ - cp src/Makefile.generated $(distdir)/src/Makefile - cp include/* $(distdir)/include - cp Makefile $(distdir)/ - cp docs/*.html $(distdir)/share/doc/qmckl/html/ - cp docs/*.css $(distdir)/share/doc/qmckl/html/ - cp docs/*.txt $(distdir)/share/doc/qmckl/text/ - cp share/qmckl/fortran/* $(distdir)/share/qmckl/fortran + cp $(QMCKL_ROOT)/munit/munit.h munit/munit.c $(distdir)/munit/ + cp $(QMCKL_ROOT)/src/*.c src/*.h src/*.f90 $(distdir)/src/ + cp $(QMCKL_ROOT)/src/Makefile.generated $(distdir)/src/Makefile + cp $(qmckl_h) $(distdir)/include + cp $(QMCKL_ROOT)/Makefile $(distdir)/ + cp $(QMCKL_ROOT)/share/doc/qmckl/html/*.html $(distdir)/share/doc/qmckl/html/ + cp $(QMCKL_ROOT)/share/doc/qmckl/html/*.css $(distdir)/share/doc/qmckl/html/ + cp $(QMCKL_ROOT)/share/doc/qmckl/text/*.txt $(distdir)/share/doc/qmckl/text/ + cp $(qmckl_f) $(distdir)/share/qmckl/fortran/ mkdir -p $(distdir)/lib @@ -58,21 +62,27 @@ FORCE: distcheck: $(distdir).tar.gz gzip -cd $(distdir).tar.gz | tar xvf - - cd $(distdir) && $(MAKE) all check - rm $(distdir)/lib/libqmckl.so - rm $(distdir)/include/qmckl.h - rm $(distdir)/share/qmckl/fortran/qmckl_f.f90 - rm $(distdir)/share/doc/qmckl/html/*.html - rm $(distdir)/share/doc/qmckl/html/*.css - rm $(distdir)/share/doc/qmckl/text/*.txt + cd $(distdir) && $(MAKE) all + cd $(distdir) && $(MAKE) check + cd $(distdir) && $(MAKE) prefix=$${PWD}/_inst install + cd $(distdir) && $(MAKE) prefix=$${PWD}/_inst uninstall + @remaining="`find $${PWD}/$(distdir)/_inst -type f | wc -l`" ;\ + if test "$${remaining}" -ne 0; then \ + echo "*** $${remaining} file(s) remaining in stage directory"; \ + exit 1; \ + fi cd $(distdir) && $(MAKE) clean rm -rf $(distdir) @echo "*** Package $(distdir).tar.gz is ready for distribution." -$(qmckl_h) $(qmckl_f) $(static_lib) $(shared_lib) src/Makefile.generated: +$(qmckl_h) $(qmckl_f) $(static_lib) $(shared_lib): $(MAKE) -C src $@ +src/Makefile.generated: + $(MAKE) -C src Makefile.generated + +veryclean: FORCE clean -.PHONY: all clean dist doc install uninstall FORCE +.PHONY: all veryclean clean dist doc install uninstall FORCE diff --git a/docs/.gitignore b/docs/.gitignore deleted file mode 100644 index 2211df6..0000000 --- a/docs/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.txt diff --git a/docs/org-html-themes b/docs/org-html-themes deleted file mode 160000 index f7224a4..0000000 --- a/docs/org-html-themes +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f7224a489462abc2c2174edbf7d4e82c0e276183 diff --git a/docs/theme.setup b/docs/theme.setup deleted file mode 100644 index bbb2ba6..0000000 --- a/docs/theme.setup +++ /dev/null @@ -1,16 +0,0 @@ -# -*- mode: org; -*- - -#+HTML_LINK_HOME: index.html -#+OPTIONS: H:4 num:t toc:t \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t d:(HIDE) - -# SETUPFILE: ../docs/org-html-themes/org/theme-readtheorg.setup - -#+INFOJS_OPT: toc:t mouse:underline path:org-info.js -#+HTML_HEAD: - -#+STARTUP: align fold nodlcheck hidestars oddeven lognotestate -#+AUTHOR: TREX CoE -#+LANGUAGE: en - - - diff --git a/qmckl.pc b/qmckl.pc new file mode 100644 index 0000000..774f827 --- /dev/null +++ b/qmckl.pc @@ -0,0 +1,12 @@ +prefix=/usr +exec_prefix=${prefix} +includedir=${exec_prefix}/include +libdir=${exec_prefix}/lib + +Name: QMCkl +Description: Quantum Monte Carlo kernel library +URL: https://github.com/trex-coe/qmckl +Version: 1.0.0 +Cflags: -I${includedir} +Libs: -L${libdir} -lqmckl +Requires.private: blas diff --git a/share/doc/qmckl/html/.gitignore b/share/doc/qmckl/html/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/docs/qmckl.css b/share/doc/qmckl/html/qmckl.css similarity index 100% rename from docs/qmckl.css rename to share/doc/qmckl/html/qmckl.css diff --git a/share/doc/qmckl/text/.gitignore b/share/doc/qmckl/text/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/src/Makefile b/src/Makefile index aabe343..bf6ae11 100644 --- a/src/Makefile +++ b/src/Makefile @@ -92,10 +92,13 @@ endif # The Makefile.generated is the one that will be distributed with the library. -.PHONY: clean shared static doc all check install uninstall syntax +.PHONY: clean shared static doc all check install uninstall .SECONDARY: # Needed to keep the produced C and Fortran files -$(shared_lib) $(static_lib) install uninstall: $(qmckl_h) $(qmckl_f) Makefile.generated +$(shared_lib) $(static_lib): $(qmckl_h) $(qmckl_f) Makefile.generated + $(MAKE) -f Makefile.generated $@ + +install uninstall: Makefile.generated $(MAKE) -f Makefile.generated $@ $(qmckl_f) $(qmckl_h): Makefile.generated @@ -108,8 +111,11 @@ all: shared static doc check check: $(static_lib) $(MAKE) -f Makefile.generated check -syntax: - cppcheck --addon=cert qmckl_*.c +cppcheck: + cppcheck \ + --addon=cert \ + --enable=warning,style,performance,portability,information \ + qmckl_*.c doc: $(ORG_SOURCE_FILES) $(QMCKL_ROOT)/tools/build_doc.sh @@ -122,10 +128,10 @@ clean: Makefile.generated *.html *.txt veryclean: clean FORCE - - $(RM) $(QMCKL_ROOT)/docs/*.html \ - $(QMCKL_ROOT)/docs/*.txt + - $(RM) $(QMCKL_ROOT)/share/doc/qmckl/html/*.html \ + $(QMCKL_ROOT)/share/doc/qmckl/text/*.txt -Makefile.generated: Makefile $(QMCKL_ROOT)/tools/create_makefile.sh $(ORG_SOURCE_FILES) +Makefile.generated: Makefile $(QMCKL_ROOT)/tools/create_makefile.sh $(ORG_SOURCE_FILES) ../tools/Building.org $(QMCKL_ROOT)/tools/create_makefile.sh diff --git a/src/README.org b/src/README.org index 86e2908..7660d60 100644 --- a/src/README.org +++ b/src/README.org @@ -1,6 +1,6 @@ #+TITLE: QMCkl source code documentation #+PROPERTY: comments org -#+SETUPFILE: ../docs/theme.setup +#+SETUPFILE: ../tools/theme.setup ------------------ @@ -14,7 +14,7 @@ #+begin_src sh :exports none grep TITLE $(cat table_of_contents) | tr ':' ' ' #+end_src - + #+RESULTS: toc | qmckl.org | #+TITLE | Header | files | | qmckl_error.org | #+TITLE | Error | handling | @@ -43,7 +43,7 @@ return '\n'.join(result) - [[./qmckl_distance.html][Distances]] - [[./qmckl_ao.html][Atomic Orbitals]] - [[./test_qmckl.html][Testing]] - + -------------------------------- @@ -65,4 +65,4 @@ return '\n'.join(result) [[https://trex-coe.eu/sites/default/files/inline-images/euflag.jpg]] [[https://trex-coe.eu][TREX: Targeting Real Chemical Accuracy at the Exascale]] project has received funding from the European Union’s Horizon 2020 - Research and Innovation program - under grant agreement no. 952165. The content of this document does not represent the opinion of the European Union, and the European Union is not responsible for any use that might be made of such content. # -*- mode: org -*- - + diff --git a/src/qmckl.org b/src/qmckl.org index b72d451..b3c0bb4 100644 --- a/src/qmckl.org +++ b/src/qmckl.org @@ -1,6 +1,6 @@ #+TITLE: Introduction #+PROPERTY: comments org -#+SETUPFILE: ../docs/theme.setup +#+SETUPFILE: ../tools/theme.setup # -*- mode: org -*- * Using QMCkl diff --git a/src/qmckl_ao.org b/src/qmckl_ao.org index 2a6cb80..0c6c62a 100644 --- a/src/qmckl_ao.org +++ b/src/qmckl_ao.org @@ -1,5 +1,5 @@ #+TITLE: Atomic Orbitals -#+SETUPFILE: ../docs/theme.setup +#+SETUPFILE: ../tools/theme.setup #+INCLUDE: ../tools/lib.org The atomic basis set is defined as a list of shells. Each shell $s$ is @@ -11,7 +11,7 @@ Gaussian ($p=2$): \[ R_s(\mathbf{r}) = \mathcal{N}_s |\mathbf{r}-\mathbf{R}_A|^{n_s} \sum_{k=1}^{N_{\text{prim}}} a_{ks} - \exp \left( - \gamma_{ks} | \mathbf{r}-\mathbf{R}_A | ^p \right). + \exp \left( - \gamma_{ks} | \mathbf{r}-\mathbf{R}_A | ^p \right). \] In the case of Gaussian functions, $n_s$ is always zero. @@ -26,7 +26,7 @@ Atomic orbitals (AOs) are defined as \[ \chi_i (\mathbf{r}) = P_{\eta(i)}(\mathbf{r})\, R_{\theta(i)} (\mathbf{r}) \] - + where $\theta(i)$ returns the shell on which the AO is expanded, and $\eta(i)$ denotes which angular function is chosen. @@ -34,7 +34,7 @@ In this section we describe the kernels used to compute the values, gradients and Laplacian of the atomic basis functions. * Headers :noexport: - #+begin_src elisp :noexport :results none + #+begin_src elisp :noexport :results none (org-babel-lob-ingest "../tools/lib.org") #+end_src @@ -74,7 +74,7 @@ MunitResult test_<>() { * Context The following arrays are stored in the context: - + | ~type~ | | Gaussian (~'G'~) or Slater (~'S'~) | | ~shell_num~ | | Number of shells | | ~prim_num~ | | Total number of primitives | @@ -150,9 +150,9 @@ typedef struct qmckl_ao_basis_struct { initialization function which has not bee called. It becomes equal to zero after all initialization functions have been called. The struct is then initialized and ~provided == true~. - + ** Access functions - + #+begin_src c :comments org :tangle (eval h_private_func) :exports none char qmckl_get_ao_basis_type (const qmckl_context context); int64_t qmckl_get_ao_basis_shell_num (const qmckl_context context); @@ -179,7 +179,7 @@ if ( (ctx->ao_basis.uninitialized & mask) != 0) { return NULL; } #+end_src - + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none char qmckl_get_ao_basis_type (const qmckl_context context) { @@ -385,12 +385,12 @@ bool qmckl_ao_basis_provided(const qmckl_context context) { return ctx->ao_basis.provided; } #+end_src - + ** Initialization functions To set the basis set, all the following functions need to be called. When - + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_set_ao_basis_type (qmckl_context context, const char t); qmckl_exit_code qmckl_set_ao_basis_shell_num (qmckl_context context, const int64_t shell_num); @@ -415,12 +415,12 @@ qmckl_context_struct* const ctx = (qmckl_context_struct* const) context; #+NAME:post2 #+begin_src c :exports none -ctx->ao_basis.uninitialized &= ~mask; +ctx->ao_basis.uninitialized &= ~mask; ctx->ao_basis.provided = (ctx->ao_basis.uninitialized == 0); return QMCKL_SUCCESS; #+end_src - + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_set_ao_basis_type(qmckl_context context, const char t) { @@ -464,7 +464,7 @@ qmckl_exit_code qmckl_set_ao_basis_shell_num(qmckl_context context, const int64_ <> } - + qmckl_exit_code qmckl_set_ao_basis_prim_num(qmckl_context context, const int64_t prim_num) { <> @@ -490,7 +490,7 @@ qmckl_exit_code qmckl_set_ao_basis_prim_num(qmckl_context context, const int64_ <> } - + qmckl_exit_code qmckl_set_ao_basis_shell_center(qmckl_context context, const int64_t* shell_center) { <> @@ -504,11 +504,11 @@ qmckl_exit_code qmckl_set_ao_basis_shell_center(qmckl_context context, const in "qmckl_set_ao_basis_shell_center", "shell_num is not set"); } - + if (ctx->ao_basis.shell_center != NULL) { qmckl_exit_code rc = qmckl_free(context, ctx->ao_basis.shell_center); if (rc != QMCKL_SUCCESS) { - return qmckl_failwith( context, rc, + return qmckl_failwith( context, rc, "qmckl_set_ao_basis_shell_center", NULL); } @@ -526,13 +526,13 @@ qmckl_exit_code qmckl_set_ao_basis_shell_center(qmckl_context context, const in } memcpy(new_array, shell_center, mem_info.size); - + ctx->ao_basis.shell_center = new_array; <> } - + qmckl_exit_code qmckl_set_ao_basis_shell_ang_mom(qmckl_context context, const char* shell_ang_mom) { <> @@ -545,17 +545,17 @@ qmckl_exit_code qmckl_set_ao_basis_shell_ang_mom(qmckl_context context, const c "qmckl_set_ao_basis_shell_ang_mom", "shell_num is not set"); } - + if (ctx->ao_basis.shell_ang_mom != NULL) { qmckl_exit_code rc = qmckl_free(context, ctx->ao_basis.shell_ang_mom); if (rc != QMCKL_SUCCESS) { - return qmckl_failwith( context, rc, + return qmckl_failwith( context, rc, "qmckl_set_ao_basis_shell_ang_mom", NULL); } } - + qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero; mem_info.size = shell_num * sizeof(char); char* new_array = (char*) qmckl_malloc(context, mem_info); @@ -568,12 +568,12 @@ qmckl_exit_code qmckl_set_ao_basis_shell_ang_mom(qmckl_context context, const c } memcpy(new_array, shell_ang_mom, mem_info.size); - + ctx->ao_basis.shell_ang_mom = new_array; <> } - + qmckl_exit_code qmckl_set_ao_basis_shell_prim_num(qmckl_context context, const int64_t* shell_prim_num) { <> @@ -587,17 +587,17 @@ qmckl_exit_code qmckl_set_ao_basis_shell_prim_num(qmckl_context context, const "qmckl_set_ao_basis_shell_prim_num", "shell_num is not set"); } - + if (ctx->ao_basis.shell_prim_num != NULL) { qmckl_exit_code rc = qmckl_free(context, ctx->ao_basis.shell_prim_num); if (rc != QMCKL_SUCCESS) { - return qmckl_failwith( context, rc, + return qmckl_failwith( context, rc, "qmckl_set_ao_basis_shell_prim_num", NULL); } } - + qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero; mem_info.size = shell_num * sizeof(int64_t); int64_t* new_array = (int64_t*) qmckl_malloc(context, mem_info); @@ -610,13 +610,13 @@ qmckl_exit_code qmckl_set_ao_basis_shell_prim_num(qmckl_context context, const } memcpy(new_array, shell_prim_num, mem_info.size); - + ctx->ao_basis.shell_prim_num = new_array; <> } - + qmckl_exit_code qmckl_set_ao_basis_shell_prim_index(qmckl_context context, const int64_t* shell_prim_index) { <> @@ -629,16 +629,16 @@ qmckl_exit_code qmckl_set_ao_basis_shell_prim_index(qmckl_context context, cons "qmckl_set_ao_basis_shell_prim_index", "shell_num is not set"); } - + if (ctx->ao_basis.shell_prim_index != NULL) { qmckl_exit_code rc = qmckl_free(context, ctx->ao_basis.shell_prim_index); if (rc != QMCKL_SUCCESS) { - return qmckl_failwith( context, rc, + return qmckl_failwith( context, rc, "qmckl_set_ao_basis_shell_prim_index", NULL); } } - + qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero; mem_info.size = shell_num * sizeof(int64_t); int64_t* new_array = (int64_t*) qmckl_malloc(context, mem_info); @@ -651,13 +651,13 @@ qmckl_exit_code qmckl_set_ao_basis_shell_prim_index(qmckl_context context, cons } memcpy(new_array, shell_prim_index, mem_info.size); - + ctx->ao_basis.shell_prim_index = new_array; <> } - + qmckl_exit_code qmckl_set_ao_basis_shell_factor(qmckl_context context, const double* shell_factor) { <> @@ -670,17 +670,17 @@ qmckl_exit_code qmckl_set_ao_basis_shell_factor(qmckl_context context, const do "qmckl_set_ao_basis_shell_factor", "shell_num is not set"); } - - + + if (ctx->ao_basis.shell_factor != NULL) { qmckl_exit_code rc = qmckl_free(context, ctx->ao_basis.shell_factor); if (rc != QMCKL_SUCCESS) { - return qmckl_failwith( context, rc, + return qmckl_failwith( context, rc, "qmckl_set_ao_basis_shell_factor", NULL); } } - + qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero; mem_info.size = shell_num * sizeof(double); double* new_array = (double*) qmckl_malloc(context, mem_info); @@ -693,12 +693,12 @@ qmckl_exit_code qmckl_set_ao_basis_shell_factor(qmckl_context context, const do } memcpy(new_array, shell_factor, mem_info.size); - + ctx->ao_basis.shell_factor = new_array; <> } - + qmckl_exit_code qmckl_set_ao_basis_exponent(qmckl_context context, const double* exponent) { <> @@ -711,16 +711,16 @@ qmckl_exit_code qmckl_set_ao_basis_exponent(qmckl_context context, const double "qmckl_set_ao_basis_exponent", "prim_num is not set"); } - + if (ctx->ao_basis.exponent != NULL) { qmckl_exit_code rc = qmckl_free(context, ctx->ao_basis.exponent); if (rc != QMCKL_SUCCESS) { - return qmckl_failwith( context, rc, + return qmckl_failwith( context, rc, "qmckl_set_ao_basis_exponent", NULL); } } - + qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero; mem_info.size = prim_num * sizeof(double); double* new_array = (double*) qmckl_malloc(context, mem_info); @@ -733,12 +733,12 @@ qmckl_exit_code qmckl_set_ao_basis_exponent(qmckl_context context, const double } memcpy(new_array, exponent, mem_info.size); - + ctx->ao_basis.exponent = new_array; <> } - + qmckl_exit_code qmckl_set_ao_basis_coefficient(qmckl_context context, const double* coefficient) { <> @@ -751,16 +751,16 @@ qmckl_exit_code qmckl_set_ao_basis_coefficient(qmckl_context context, const dou "qmckl_set_ao_basis_coefficient", "prim_num is not set"); } - + if (ctx->ao_basis.coefficient != NULL) { qmckl_exit_code rc = qmckl_free(context, ctx->ao_basis.coefficient); if (rc != QMCKL_SUCCESS) { - return qmckl_failwith( context, rc, + return qmckl_failwith( context, rc, "qmckl_set_ao_basis_coefficient", NULL); } } - + qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero; mem_info.size = prim_num * sizeof(double); double* new_array = (double*) qmckl_malloc(context, mem_info); @@ -773,12 +773,12 @@ qmckl_exit_code qmckl_set_ao_basis_coefficient(qmckl_context context, const dou } memcpy(new_array, coefficient, mem_info.size); - + ctx->ao_basis.coefficient = new_array; <> } - + #+end_src ** TODO Fortran interfaces @@ -817,7 +817,7 @@ double coefficient [prim_num] = 1.0, 1.0, 1.0, 1.0, 1.0, 0.006068, 0.045308, 0.202822, 0.503903, 0.383421, 1.0, 1.0, 1.0, 1.0, 1.0 }; /* --- */ - + qmckl_exit_code rc; munit_assert(!qmckl_ao_basis_provided(context)); @@ -875,11 +875,11 @@ munit_assert(qmckl_ao_basis_provided(context)); :CRetType: qmckl_exit_code :FRetType: qmckl_exit_code :END: - + The ~qmckl_ao_power~ function computes all the powers of the ~n~ input data up to the given maximum value given in input for each of the $n$ points: - + \[ P_{ik} = X_i^k \] #+NAME: qmckl_ao_power_args @@ -911,12 +911,12 @@ munit_assert(qmckl_ao_basis_provided(context)); const double* X, const int32_t* LMAX, double* const P, - const int64_t ldp ); + const int64_t ldp ); #+end_src *** Source - #+begin_src f90 :tangle (eval f) + #+begin_src f90 :tangle (eval f) integer function qmckl_ao_power_f(context, n, X, LMAX, P, ldp) result(info) use qmckl implicit none @@ -955,12 +955,12 @@ integer function qmckl_ao_power_f(context, n, X, LMAX, P, ldp) result(info) do i=1,n P(1,i) = X(i) do k=2,LMAX(i) - P(k,i) = P(k-1,i) * X(i) + P(k,i) = P(k-1,i) * X(i) end do end do end function qmckl_ao_power_f - #+end_src + #+end_src *** C interface #+CALL: generate_c_interface(table=qmckl_ao_power_args,rettyp=get_value("CRetType"),fname="qmckl_ao_power") @@ -1015,15 +1015,15 @@ end function qmckl_ao_power_f *** Test - #+begin_src f90 :tangle (eval f_test) + #+begin_src f90 :tangle (eval f_test) integer(c_int32_t) function test_qmckl_ao_power(context) bind(C) use qmckl implicit none integer(qmckl_context), intent(in), value :: context - integer*8 :: n, LDP - integer, allocatable :: LMAX(:) + integer*8 :: n, LDP + integer, allocatable :: LMAX(:) double precision, allocatable :: X(:), P(:,:) integer*8 :: i,j double precision :: epsilon @@ -1040,7 +1040,7 @@ integer(c_int32_t) function test_qmckl_ao_power(context) bind(C) LMAX(j) = 1 + int(mod(j, 5),4) end do - test_qmckl_ao_power = qmckl_ao_power(context, n, X, LMAX, P, LDP) + test_qmckl_ao_power = qmckl_ao_power(context, n, X, LMAX, P, LDP) if (test_qmckl_ao_power /= QMCKL_SUCCESS) return test_qmckl_ao_power = QMCKL_FAILURE @@ -1073,29 +1073,29 @@ munit_assert_int(0, ==, test_qmckl_ao_power(context)); :END: A polynomial is centered on a nucleus $\mathbf{R}_i$ - + \[ - 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 \] The gradients with respect to electron coordinates are - - \begin{eqnarray*} + + \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 \\ \frac{\partial }{\partial y} P_l\left(\mathbf{r},\mathbf{R}_i \right) & = & b (x-X_i)^a (y-Y_i)^{b-1} (z-Z_i)^c \\ \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*} + \end{eqnarray*} and the Laplacian is - - \begin{eqnarray*} - \left( \frac{\partial }{\partial x^2} + - \frac{\partial }{\partial y^2} + + + \begin{eqnarray*} + \left( \frac{\partial }{\partial x^2} + + \frac{\partial }{\partial y^2} + \frac{\partial }{\partial z^2} \right) P_l - \left(\mathbf{r},\mathbf{R}_i \right) & = & + \left(\mathbf{r},\mathbf{R}_i \right) & = & a(a-1) (x-X_i)^{a-2} (y-Y_i)^b (z-Z_i)^c + \\ && b(b-1) (x-X_i)^a (y-Y_i)^{b-1} (z-Z_i)^c + \\ && c(c-1) (x-X_i)^a (y-Y_i)^b (z-Z_i)^{c-1}. @@ -1115,7 +1115,7 @@ munit_assert_int(0, ==, test_qmckl_ao_power(context)); | int64_t | ldl | in | Leading dimension of ~L~ | | double | VGL[n][ldv] | out | Value, gradients and Laplacian of the polynomials | | int64_t | ldv | in | Leading dimension of array ~VGL~ | - + *** Requirements - ~context~ is not ~QMCKL_NULL_CONTEXT~ @@ -1150,7 +1150,7 @@ munit_assert_int(0, ==, test_qmckl_ao_power(context)); int32_t* const L, const int64_t ldl, double* const VGL, - const int64_t ldv ); + const int64_t ldv ); #+end_src *** Source @@ -1212,9 +1212,9 @@ integer function qmckl_ao_polynomial_vgl_f(context, X, R, lmax, n, L, ldl, VGL, else if (lmax > 0) then pows(-2:0,1:3) = 1.d0 do i=1,lmax - pows(i,1) = pows(i-1,1) * Y(1) - pows(i,2) = pows(i-1,2) * Y(2) - pows(i,3) = pows(i-1,3) * Y(3) + pows(i,1) = pows(i-1,1) * Y(1) + pows(i,2) = pows(i-1,2) * Y(2) + pows(i,3) = pows(i-1,3) * Y(3) end do VGL(1:5,1:4) = 0.d0 @@ -1282,8 +1282,8 @@ integer function qmckl_ao_polynomial_vgl_f(context, X, R, lmax, n, L, ldl, VGL, info = QMCKL_SUCCESS end function qmckl_ao_polynomial_vgl_f - #+end_src - + #+end_src + *** C interface #+CALL: generate_c_interface(table=qmckl_ao_polynomial_vgl_args,rettyp=get_value("CRetType"),fname=get_value("Name")) @@ -1341,7 +1341,7 @@ end function qmckl_ao_polynomial_vgl_f end function qmckl_ao_polynomial_vgl end interface #+end_src - + *** Test #+begin_src f90 :tangle (eval f_test) @@ -1419,13 +1419,13 @@ integer(c_int32_t) function test_qmckl_ao_polynomial_vgl(context) bind(C) test_qmckl_ao_polynomial_vgl = QMCKL_FAILURE w = 0.d0 if (L(1,j) > 1) then - w = w + L(1,j) * (L(1,j)-1) * Y(1)**(L(1,j)-2) * Y(2)**L(2,j) * Y(3)**L(3,j) + w = w + L(1,j) * (L(1,j)-1) * Y(1)**(L(1,j)-2) * Y(2)**L(2,j) * Y(3)**L(3,j) end if if (L(2,j) > 1) then - w = w + L(2,j) * (L(2,j)-1) * Y(1)**L(1,j) * Y(2)**(L(2,j)-2) * Y(3)**L(3,j) + w = w + L(2,j) * (L(2,j)-1) * Y(1)**L(1,j) * Y(2)**(L(2,j)-2) * Y(3)**L(3,j) end if if (L(3,j) > 1) then - w = w + L(3,j) * (L(3,j)-1) * Y(1)**L(1,j) * Y(2)**L(2,j) * Y(3)**(L(3,j)-2) + w = w + L(3,j) * (L(3,j)-1) * Y(1)**L(1,j) * Y(2)**L(2,j) * Y(3)**(L(3,j)-2) end if if (dabs(1.d0 - VGL(5,j) / w) > epsilon ) return end do @@ -1440,14 +1440,14 @@ end function test_qmckl_ao_polynomial_vgl int test_qmckl_ao_polynomial_vgl(qmckl_context context); munit_assert_int(0, ==, test_qmckl_ao_polynomial_vgl(context)); #+end_src - + * Radial part ** Gaussian basis functions - + ~qmckl_ao_gaussian_vgl~ 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) \] \[ \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 \] @@ -1461,7 +1461,7 @@ munit_assert_int(0, ==, test_qmckl_ao_polynomial_vgl(context)); | ~A(n)~ | input | Exponents of the Gaussians | | ~VGL(ldv,5)~ | output | Value, gradients and Laplacian of the Gaussians | | ~ldv~ | input | Leading dimension of array ~VGL~ | - + Requirements - ~context~ is not 0 @@ -1483,7 +1483,7 @@ qmckl_ao_gaussian_vgl(const qmckl_context context, const double *VGL, const int64_t ldv); #+end_src - + #+begin_src f90 :tangle (eval f) integer function qmckl_ao_gaussian_vgl_f(context, X, R, n, A, VGL, ldv) result(info) use qmckl @@ -1497,30 +1497,30 @@ integer function qmckl_ao_gaussian_vgl_f(context, X, R, n, A, VGL, ldv) result(i integer*8 :: i,j real*8 :: Y(3), r2, t, u, v - + info = QMCKL_SUCCESS - + if (context == QMCKL_NULL_CONTEXT) then info = QMCKL_INVALID_CONTEXT return endif - + if (n <= 0) then info = QMCKL_INVALID_ARG_4 return endif - + if (ldv < n) then info = QMCKL_INVALID_ARG_7 return endif - - + + do i=1,3 Y(i) = X(i) - R(i) end do r2 = Y(1)*Y(1) + Y(2)*Y(2) + Y(3)*Y(3) - + do i=1,n VGL(i,1) = dexp(-A(i) * r2) end do @@ -1545,7 +1545,7 @@ integer function qmckl_ao_gaussian_vgl_f(context, X, R, n, A, VGL, ldv) result(i end do end function qmckl_ao_gaussian_vgl_f - #+end_src + #+end_src #+begin_src f90 :tangle (eval f) :exports none integer(c_int32_t) function qmckl_ao_gaussian_vgl(context, X, R, n, A, VGL, ldv) & @@ -1560,14 +1560,14 @@ integer(c_int32_t) function qmckl_ao_gaussian_vgl(context, X, R, n, A, VGL, ldv) integer (c_int64_t) , intent(in) , value :: ldv integer, external :: qmckl_ao_gaussian_vgl_f - info = qmckl_ao_gaussian_vgl_f(context, X, R, n, A, VGL, ldv) + info = qmckl_ao_gaussian_vgl_f(context, X, R, n, A, VGL, ldv) end function qmckl_ao_gaussian_vgl #+end_src #+begin_src f90 :tangle (eval fh_func) :exports none interface integer(c_int32_t) function qmckl_ao_gaussian_vgl(context, X, R, n, A, VGL, ldv) & - bind(C) + bind(C) use, intrinsic :: iso_c_binding integer (c_int64_t) , intent(in) , value :: context integer (c_int64_t) , intent(in) , value :: ldv @@ -1585,7 +1585,7 @@ integer(c_int32_t) function test_qmckl_ao_gaussian_vgl(context) bind(C) implicit none integer(c_int64_t), intent(in), value :: context - + integer*8 :: n, ldv, j, i double precision :: X(3), R(3), Y(3), r2 double precision, allocatable :: VGL(:,:), A(:) @@ -1618,22 +1618,22 @@ integer(c_int32_t) function test_qmckl_ao_gaussian_vgl(context) bind(C) if (dabs(1.d0 - VGL(i,1) / (& dexp(-A(i) * r2) & )) > epsilon ) return - + test_qmckl_ao_gaussian_vgl = -12 if (dabs(1.d0 - VGL(i,2) / (& -2.d0 * A(i) * Y(1) * dexp(-A(i) * r2) & )) > epsilon ) return - + test_qmckl_ao_gaussian_vgl = -13 if (dabs(1.d0 - VGL(i,3) / (& -2.d0 * A(i) * Y(2) * dexp(-A(i) * r2) & )) > epsilon ) return - + test_qmckl_ao_gaussian_vgl = -14 if (dabs(1.d0 - VGL(i,4) / (& -2.d0 * A(i) * Y(3) * dexp(-A(i) * r2) & )) > epsilon ) return - + test_qmckl_ao_gaussian_vgl = -15 if (dabs(1.d0 - VGL(i,5) / (& A(i) * (4.d0*r2*A(i) - 6.d0) * dexp(-A(i) * r2) & @@ -1641,7 +1641,7 @@ integer(c_int32_t) function test_qmckl_ao_gaussian_vgl(context) bind(C) end do test_qmckl_ao_gaussian_vgl = 0 - + deallocate(VGL) end function test_qmckl_ao_gaussian_vgl #+end_src @@ -1650,13 +1650,13 @@ end function test_qmckl_ao_gaussian_vgl int test_qmckl_ao_gaussian_vgl(qmckl_context context); munit_assert_int(0, ==, test_qmckl_ao_gaussian_vgl(context)); #+end_src - + ** TODO Slater basis functions - + ** TODO Radial functions on a grid * Combining radial and polynomial parts * End of files :noexport: - + #+begin_src c :tangle (eval h_private_type) #endif #+end_src @@ -1668,35 +1668,35 @@ munit_assert_int(0, ==, test_qmckl_ao_gaussian_vgl(context)); return MUNIT_OK; } #+end_src - -**✸ Compute file names - #+begin_src emacs-lisp -; The following is required to compute the file names - -(setq pwd (file-name-directory buffer-file-name)) -(setq name (file-name-nondirectory (substring buffer-file-name 0 -4))) -(setq f (concat pwd name "_f.f90")) -(setq fh (concat pwd name "_fh.f90")) -(setq c (concat pwd name ".c")) -(setq h (concat name ".h")) -(setq h_private (concat name "_private.h")) -(setq c_test (concat pwd "test_" name ".c")) -(setq f_test (concat pwd "test_" name "_f.f90")) - -; Minted -(require 'ox-latex) -(setq org-latex-listings 'minted) -(add-to-list 'org-latex-packages-alist '("" "listings")) -(add-to-list 'org-latex-packages-alist '("" "color")) - - #+end_src + +**✸ Compute file names + #+begin_src emacs-lisp +; The following is required to compute the file names + +(setq pwd (file-name-directory buffer-file-name)) +(setq name (file-name-nondirectory (substring buffer-file-name 0 -4))) +(setq f (concat pwd name "_f.f90")) +(setq fh (concat pwd name "_fh.f90")) +(setq c (concat pwd name ".c")) +(setq h (concat name ".h")) +(setq h_private (concat name "_private.h")) +(setq c_test (concat pwd "test_" name ".c")) +(setq f_test (concat pwd "test_" name "_f.f90")) + +; Minted +(require 'ox-latex) +(setq org-latex-listings 'minted) +(add-to-list 'org-latex-packages-alist '("" "listings")) +(add-to-list 'org-latex-packages-alist '("" "color")) + + #+end_src #+RESULTS: | | color | | | listings | - + # -*- mode: org -*- # vim: syntax=c - + diff --git a/src/qmckl_context.org b/src/qmckl_context.org index 7aba5cb..14a2a45 100644 --- a/src/qmckl_context.org +++ b/src/qmckl_context.org @@ -1,6 +1,6 @@ #+TITLE: Context -#+SETUPFILE: ../docs/theme.setup -#+INCLUDE: ../tools/lib.org +#+SETUPFILE: ../tools/theme.setup +#+INCLUDE: ../tools/lib.org * Headers :noexport: @@ -24,7 +24,7 @@ MunitResult test_<>() { #include "qmckl_ao_private_type.h" #+end_src - #+begin_src c :tangle (eval c) + #+begin_src c :tangle (eval c) #include #include #include @@ -63,7 +63,7 @@ typedef int64_t qmckl_context ; integer , parameter :: qmckl_context = c_int64_t integer*8, parameter :: QMCKL_NULL_CONTEXT = 0 #+end_src - + An immutable context would have required to implement a garbage collector. To keep the library simple, we have chosen to implement the context as a mutable data structure, so it has to be handled @@ -73,7 +73,7 @@ typedef int64_t qmckl_context ; and ~ctx~ is a ~qmckl_context_struct*~ pointer. ** Data structure - + #+begin_src c :comments org :tangle (eval h_private_type) :noweb yes :exports none typedef struct qmckl_context_struct { /* -- State of the library -- */ @@ -113,11 +113,11 @@ typedef struct qmckl_context_struct { The context keeps a ``date'' that allows to check which data needs to be recomputed. The date is incremented when the electron coordinates are updated. - + When a new element is added to the context, the functions [[Creation][qmckl_context_create]], [[Destroy][qmckl_context_destroy]] and [[Copy][qmckl_context_copy]] should be updated inorder to make deep copies. - + A tag is used internally to check if the memory domain pointed by a pointer is a valid context. This allows to check that even if @@ -155,7 +155,7 @@ qmckl_context qmckl_context_check(const qmckl_context context) { #+end_src ** Creation - + To create a new context, ~qmckl_context_create()~ should be used. - Upon success, it returns a pointer to a new context with the ~qmckl_context~ type - It returns ~QMCKL_NULL_CONTEXT~ upon failure to allocate the internal data structure @@ -185,17 +185,17 @@ qmckl_context qmckl_context_create() { { pthread_mutexattr_t attr; int rc; - - rc = pthread_mutexattr_init(&attr); + + rc = pthread_mutexattr_init(&attr); assert (rc == 0); - + (void) pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - + rc = pthread_mutex_init ( &(ctx->mutex), &attr); assert (rc == 0); - + (void) pthread_mutexattr_destroy(&attr); - } + } /* Initialize data */ ctx->tag = VALID_TAG; @@ -215,15 +215,15 @@ qmckl_context qmckl_context_create() { qmckl_memory_info_struct * new_array = calloc(size, sizeof(qmckl_memory_info_struct)); if (new_array == NULL) { free(ctx); - return QMCKL_NULL_CONTEXT; + return QMCKL_NULL_CONTEXT; } memset( &(new_array[0]), 0, size * sizeof(qmckl_memory_info_struct) ); - + ctx->memory.element = new_array; ctx->memory.array_size = size; ctx->memory.n_allocated = (size_t) 0; } - + return (qmckl_context) ctx; } #+end_src @@ -304,7 +304,7 @@ void qmckl_unlock(const qmckl_context context) { qmckl_context qmckl_context_copy(const qmckl_context context); #+end_src - + # Source #+begin_src c :tangle (eval c) qmckl_context qmckl_context_copy(const qmckl_context context) { @@ -318,24 +318,24 @@ qmckl_context qmckl_context_copy(const qmckl_context context) { /* qmckl_lock(context); { - + const qmckl_context_struct* const old_ctx = (qmckl_context_struct* const) checked_context; - + qmckl_context_struct* const new_ctx = (qmckl_context_struct* const) malloc (context, sizeof(qmckl_context_struct)); - + if (new_ctx == NULL) { qmckl_unlock(context); return QMCKL_NULL_CONTEXT; } - - * Copy the old context on the new one * - * TODO Deep copies should be done here * + + * Copy the old context on the new one * + * TODO Deep copies should be done here * memcpy(new_ctx, old_ctx, sizeof(qmckl_context_struct)); - + qmckl_unlock( (qmckl_context) new_ctx ); - + return (qmckl_context) new_ctx; } qmckl_unlock(context); @@ -456,4 +456,4 @@ return MUNIT_OK; } #+end_src - + diff --git a/src/qmckl_distance.org b/src/qmckl_distance.org index a4ec5b9..c03155c 100644 --- a/src/qmckl_distance.org +++ b/src/qmckl_distance.org @@ -1,11 +1,11 @@ #+TITLE: Inter-particle distances -#+SETUPFILE: ../docs/theme.setup -#+INCLUDE: ../tools/lib.org +#+SETUPFILE: ../tools/theme.setup +#+INCLUDE: ../tools/lib.org Functions for the computation of distances between particles. * Headers :noexport: - #+begin_src elisp :noexport :results none + #+begin_src elisp :noexport :results none (org-babel-lob-ingest "../tools/lib.org") #+end_src @@ -56,11 +56,11 @@ MunitResult test_<>() { - ~lda >= m~ if ~transa == 'T'~ - ~ldb >= 3~ if ~transb == 'N'~ - ~ldb >= n~ if ~transb == 'T'~ - - ~ldc >= m~ + - ~ldc >= m~ - ~A~ is allocated with at least $3 \times m \times 8$ bytes - ~B~ is allocated with at least $3 \times n \times 8$ bytes - ~C~ is allocated with at least $m \times n \times 8$ bytes - + *** C header #+CALL: generate_c_header(table=qmckl_distance_sq_args,rettyp=get_value("CRetType"),fname=get_value("Name")) @@ -78,7 +78,7 @@ MunitResult test_<>() { const double* B, const int64_t ldb, double* const C, - const int64_t ldc ); + const int64_t ldc ); #+end_src *** Source @@ -137,7 +137,7 @@ integer function qmckl_distance_sq_f(context, transa, transb, m, n, & if (transab < 0) then info = QMCKL_INVALID_ARG_1 - return + return endif if (iand(transab,1) == 0 .and. LDA < 3) then @@ -211,8 +211,8 @@ integer function qmckl_distance_sq_f(context, transa, transb, m, n, & end function qmckl_distance_sq_f #+end_src - -*** Performance + +*** Performance This function might be more efficient when ~A~ and ~B~ are transposed. @@ -220,7 +220,7 @@ end function qmckl_distance_sq_f ** C interface :noexport: #+CALL: generate_c_interface(table=qmckl_distance_sq_args,rettyp=get_value("FRetType"),fname=get_value("Name")) - + #+RESULTS: #+begin_src f90 :tangle (eval f) :comments org :exports none integer(c_int32_t) function qmckl_distance_sq & @@ -287,7 +287,7 @@ integer(qmckl_exit_code) function test_qmckl_distance_sq(context) bind(C) double precision, allocatable :: A(:,:), B(:,:), C(:,:) integer*8 :: m, n, LDA, LDB, LDC double precision :: x - integer*8 :: i,j + integer*8 :: i,j m = 5 n = 6 @@ -311,17 +311,17 @@ integer(qmckl_exit_code) function test_qmckl_distance_sq(context) bind(C) test_qmckl_distance_sq = & qmckl_distance_sq(context, 'X', 't', m, n, A, LDA, B, LDB, C, LDC) - if (test_qmckl_distance_sq == 0) return + if (test_qmckl_distance_sq == 0) return test_qmckl_distance_sq = & qmckl_distance_sq(context, 't', 'X', m, n, A, LDA, B, LDB, C, LDC) - if (test_qmckl_distance_sq == 0) return + if (test_qmckl_distance_sq == 0) return test_qmckl_distance_sq = & qmckl_distance_sq(context, 'T', 't', m, n, A, LDA, B, LDB, C, LDC) - if (test_qmckl_distance_sq /= 0) return + if (test_qmckl_distance_sq /= 0) return test_qmckl_distance_sq = -1 @@ -337,7 +337,7 @@ integer(qmckl_exit_code) function test_qmckl_distance_sq(context) bind(C) test_qmckl_distance_sq = & qmckl_distance_sq(context, 'n', 'T', m, n, A, LDA, B, LDB, C, LDC) - if (test_qmckl_distance_sq /= 0) return + if (test_qmckl_distance_sq /= 0) return test_qmckl_distance_sq = -1 @@ -353,7 +353,7 @@ integer(qmckl_exit_code) function test_qmckl_distance_sq(context) bind(C) test_qmckl_distance_sq = & qmckl_distance_sq(context, 'T', 'n', m, n, A, LDA, B, LDB, C, LDC) - if (test_qmckl_distance_sq /= 0) return + if (test_qmckl_distance_sq /= 0) return test_qmckl_distance_sq = -1 @@ -369,7 +369,7 @@ integer(qmckl_exit_code) function test_qmckl_distance_sq(context) bind(C) test_qmckl_distance_sq = & qmckl_distance_sq(context, 'n', 'N', m, n, A, LDA, B, LDB, C, LDC) - if (test_qmckl_distance_sq /= 0) return + if (test_qmckl_distance_sq /= 0) return test_qmckl_distance_sq = -1 @@ -387,7 +387,7 @@ integer(qmckl_exit_code) function test_qmckl_distance_sq(context) bind(C) deallocate(A,B,C) end function test_qmckl_distance_sq #+end_src - + #+begin_src c :comments link :tangle (eval c_test) int test_qmckl_distance_sq(qmckl_context context); munit_assert_int(0, ==, test_qmckl_distance_sq(context)); @@ -430,11 +430,11 @@ munit_assert_int(0, ==, test_qmckl_distance_sq(context)); - ~lda >= m~ if ~transa == 'T'~ - ~ldb >= 3~ if ~transb == 'N'~ - ~ldb >= n~ if ~transb == 'T'~ - - ~ldc >= m~ + - ~ldc >= m~ - ~A~ is allocated with at least $3 \times m \times 8$ bytes - ~B~ is allocated with at least $3 \times n \times 8$ bytes - ~C~ is allocated with at least $m \times n \times 8$ bytes - + *** C header #+CALL: generate_c_header(table=qmckl_distance_args,rettyp=get_value("CRetType"),fname=get_value("Name")) @@ -452,7 +452,7 @@ munit_assert_int(0, ==, test_qmckl_distance_sq(context)); const double* B, const int64_t ldb, double* const C, - const int64_t ldc ); + const int64_t ldc ); #+end_src *** Source @@ -511,7 +511,7 @@ integer function qmckl_distance_f(context, transa, transb, m, n, & if (transab < 0) then info = QMCKL_INVALID_ARG_1 - return + return endif if (iand(transab,1) == 0 .and. LDA < 3) then @@ -589,8 +589,8 @@ integer function qmckl_distance_f(context, transa, transb, m, n, & end function qmckl_distance_f #+end_src - -*** Performance + +*** Performance This function might be more efficient when ~A~ and ~B~ are transposed. @@ -598,7 +598,7 @@ end function qmckl_distance_f ** C interface :noexport: #+CALL: generate_c_interface(table=qmckl_distance_args,rettyp=get_value("FRetType"),fname=get_value("Name")) - + #+RESULTS: #+begin_src f90 :tangle (eval f) :comments org :exports none integer(c_int32_t) function qmckl_distance & @@ -665,7 +665,7 @@ integer(qmckl_exit_code) function test_qmckl_dist(context) bind(C) double precision, allocatable :: A(:,:), B(:,:), C(:,:) integer*8 :: m, n, LDA, LDB, LDC double precision :: x - integer*8 :: i,j + integer*8 :: i,j m = 5 n = 6 @@ -689,17 +689,17 @@ integer(qmckl_exit_code) function test_qmckl_dist(context) bind(C) test_qmckl_dist = & qmckl_distance(context, 'X', 't', m, n, A, LDA, B, LDB, C, LDC) - if (test_qmckl_dist == 0) return + if (test_qmckl_dist == 0) return test_qmckl_dist = & qmckl_distance(context, 't', 'X', m, n, A, LDA, B, LDB, C, LDC) - if (test_qmckl_dist == 0) return + if (test_qmckl_dist == 0) return test_qmckl_dist = & qmckl_distance(context, 'T', 't', m, n, A, LDA, B, LDB, C, LDC) - if (test_qmckl_dist /= 0) return + if (test_qmckl_dist /= 0) return test_qmckl_dist = -1 @@ -715,7 +715,7 @@ integer(qmckl_exit_code) function test_qmckl_dist(context) bind(C) test_qmckl_dist = & qmckl_distance(context, 'n', 'T', m, n, A, LDA, B, LDB, C, LDC) - if (test_qmckl_dist /= 0) return + if (test_qmckl_dist /= 0) return test_qmckl_dist = -1 @@ -731,7 +731,7 @@ integer(qmckl_exit_code) function test_qmckl_dist(context) bind(C) test_qmckl_dist = & qmckl_distance(context, 'T', 'n', m, n, A, LDA, B, LDB, C, LDC) - if (test_qmckl_dist /= 0) return + if (test_qmckl_dist /= 0) return test_qmckl_dist = -1 @@ -747,7 +747,7 @@ integer(qmckl_exit_code) function test_qmckl_dist(context) bind(C) test_qmckl_dist = & qmckl_distance(context, 'n', 'N', m, n, A, LDA, B, LDB, C, LDC) - if (test_qmckl_dist /= 0) return + if (test_qmckl_dist /= 0) return test_qmckl_dist = -1 @@ -765,7 +765,7 @@ integer(qmckl_exit_code) function test_qmckl_dist(context) bind(C) deallocate(A,B,C) end function test_qmckl_dist #+end_src - + #+begin_src c :comments link :tangle (eval c_test) int test_qmckl_dist(qmckl_context context); munit_assert_int(0, ==, test_qmckl_dist(context)); @@ -779,7 +779,7 @@ munit_assert_int(0, ==, test_qmckl_dist(context)); } #+end_src - + # -*- mode: org -*- # vim: syntax=c diff --git a/src/qmckl_electron.org b/src/qmckl_electron.org index 9bf5c0e..0942421 100644 --- a/src/qmckl_electron.org +++ b/src/qmckl_electron.org @@ -1,5 +1,5 @@ #+TITLE: Electrons -#+SETUPFILE: ../docs/theme.setup +#+SETUPFILE: ../tools/theme.setup #+INCLUDE: ../tools/lib.org In conventional QMC simulations, up-spin and down-spin electrons are @@ -7,7 +7,7 @@ different. The ~electron~ data structure contains the number of up-spin and down-spin electrons, and the electron coordinates. * Headers :noexport: - #+begin_src elisp :noexport :results none + #+begin_src elisp :noexport :results none (org-babel-lob-ingest "../tools/lib.org") #+end_src @@ -51,7 +51,7 @@ MunitResult test_<>() { * Context The following data stored in the context: - + | ~uninitialized~ | int32_t | Keeps bit set for uninitialized data | | ~num~ | int64_t | Total number of electrons | | ~up_num~ | int64_t | Number of up-spin electrons | @@ -86,7 +86,7 @@ typedef struct qmckl_electron_struct { initialization function which has not bee called. It becomes equal to zero after all initialization functions have been called. The struct is then initialized and ~provided == true~. - + ** Access functions #+begin_src c :comments org :tangle (eval h_private_func) :exports none @@ -111,7 +111,7 @@ if ( (ctx->electron.uninitialized & mask) != 0) { return NULL; } #+end_src - + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none int64_t qmckl_get_electron_num (const qmckl_context context) { @@ -203,13 +203,13 @@ bool qmckl_electron_provided(const qmckl_context context) { return ctx->electron.provided; } #+end_src - + ** Initialization functions To set the data relative to the electrons in the context, the following functions need to be called. When the data structure is initialized, the ~coord_new~ and ~coord_old~ arrays are both allocated. - + #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_set_electron_num (qmckl_context context, const int64_t up_num, const int64_t down_num); qmckl_exit_code qmckl_set_electron_walk_num (qmckl_context context, const int64_t walk_num); @@ -227,7 +227,7 @@ qmckl_context_struct* const ctx = (qmckl_context_struct* const) context; #+NAME:post2 #+begin_src c :exports none -ctx->electron.uninitialized &= ~mask; +ctx->electron.uninitialized &= ~mask; ctx->electron.provided = (ctx->electron.uninitialized == 0); if (ctx->electron.provided) { @@ -265,11 +265,11 @@ if (ctx->electron.provided) { return QMCKL_SUCCESS; #+end_src - + To set the number of electrons, we give the number of up-spin and down-spin electrons to the context and we set the number of walkers. - - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_set_electron_num(qmckl_context context, const int64_t up_num, const int64_t down_num) { @@ -298,9 +298,9 @@ qmckl_exit_code qmckl_set_electron_num(qmckl_context context, <> } #+end_src - - - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + + + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_set_electron_walk_num(qmckl_context context, const int64_t walk_num) { <> @@ -317,14 +317,14 @@ qmckl_exit_code qmckl_set_electron_walk_num(qmckl_context context, const int64_t <> } #+end_src - - + + The following function sets the electron coordinates of all the walkers. When this is done, the pointers to the old and new sets of coordinates are swapped, and the new coordinates are overwritten. This can be done only when the data relative to electrons have been set. - + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_set_electron_coord(qmckl_context context, const double* coord) { <> @@ -336,7 +336,7 @@ qmckl_exit_code qmckl_set_electron_coord(qmckl_context context, const double* c "qmckl_set_electron_coord", "num is not set"); } - + const int64_t walk_num = qmckl_get_electron_walk_num(context); if (walk_num == 0L) { return qmckl_failwith( context, @@ -344,11 +344,11 @@ qmckl_exit_code qmckl_set_electron_coord(qmckl_context context, const double* c "qmckl_set_electron_coord", "walk_num is not set"); } - + /* If num and walk_num are set, the arrays should be allocated */ assert (ctx->electron.coord_old != NULL); assert (ctx->electron.coord_new != NULL); - + /* Increment the date of the context */ ctx->date += 1UL; @@ -357,12 +357,12 @@ qmckl_exit_code qmckl_set_electron_coord(qmckl_context context, const double* c swap = ctx->electron.coord_old; ctx->electron.coord_old = ctx->electron.coord_new; ctx->electron.coord_new = swap; - + memcpy(ctx->electron.coord_new, coord, walk_num * num * 3 * sizeof(double)); ctx->electron.coord_new_date = ctx->date; return QMCKL_SUCCESS; - + } #+end_src @@ -377,7 +377,7 @@ qmckl_exit_code qmckl_set_electron_coord(qmckl_context context, const double* c #define num (up_num+down_num) double coord[walk_num*3*num] = - { 7.303633091022677881e+00, 1.375868694453235719e+01, 1.167371490471771217e-01, + { 7.303633091022677881e+00, 1.375868694453235719e+01, 1.167371490471771217e-01, 4.547755371567960836e+00, 3.245907105524011182e+00, 2.410764357550297110e-01, 5.932816068137344523e+00, 1.491671465549257469e+01, 3.825374039119375236e-01, 7.347336142660052083e+00, 1.341946976062362129e+00, 1.648917914228352322e+00, @@ -387,9 +387,9 @@ double coord[walk_num*3*num] = 1.484094322159507051e+01, 9.777903829455864226e+00, 5.243007994024882767e-02, 9.081723054990456845e+00, 5.499568496038920173e+00, 2.910446438899221347e-02, 2.583154239492383653e+00, 1.442282811294904432e+00, 6.387191629878670451e-02 }; - + /* --- */ - + qmckl_exit_code rc; munit_assert(!qmckl_electron_provided(context)); @@ -408,7 +408,7 @@ munit_assert_int64(rc, ==, QMCKL_SUCCESS); #+end_src * Computation - + The computed data is stored in the context so that it can be reused by different kernels. To ensure that the data is valid, for each computed data the date of the context is stored when it is computed. @@ -416,16 +416,16 @@ munit_assert_int64(rc, ==, QMCKL_SUCCESS); the dependencies are more recent than the date of the data to compute. If it is the case, then the data is recomputed and the current date is stored. - + ** Electron-electron distances - + *** Get #+begin_src c :comments org :tangle (eval h_func) :noweb yes qmckl_exit_code qmckl_get_electron_ee_distance(qmckl_context context, double* distance); #+end_src - - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_get_electron_ee_distance(qmckl_context context, double* distance) { /* Check input parameters */ @@ -446,12 +446,12 @@ qmckl_exit_code qmckl_get_electron_ee_distance(qmckl_context context, double* di } #+end_src *** Provide :noexport: - - #+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none + + #+begin_src c :comments org :tangle (eval h_private_func) :noweb yes :exports none qmckl_exit_code qmckl_provide_ee_distance(qmckl_context context); #+end_src - - #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none + + #+begin_src c :comments org :tangle (eval c) :noweb yes :exports none qmckl_exit_code qmckl_provide_ee_distance(qmckl_context context) { /* Check input parameters */ @@ -462,19 +462,18 @@ qmckl_exit_code qmckl_provide_ee_distance(qmckl_context context) qmckl_context_struct* const ctx = (qmckl_context_struct* const) context; assert (ctx != NULL); - + /* Compute if necessary */ if (ctx->electron.coord_new_date > ctx->electron.ee_distance_date) { - fprintf(stderr, "%10ld: provide ee_distance", ctx->date); /* Allocate array */ if (ctx->electron.ee_distance == NULL) { - + qmckl_memory_info_struct mem_info = qmckl_memory_info_struct_zero; mem_info.size = ctx->electron.num * ctx->electron.num * ctx->electron.walk_num * sizeof(double); double* ee_distance = (double*) qmckl_malloc(context, mem_info); - + if (ee_distance == NULL) { return qmckl_failwith( context, QMCKL_ALLOCATION_FAILED, @@ -486,7 +485,7 @@ qmckl_exit_code qmckl_provide_ee_distance(qmckl_context context) qmckl_exit_code rc = qmckl_compute_ee_distance(context, - ctx->electron.num, + ctx->electron.num, ctx->electron.walk_num, ctx->electron.coord_new, ctx->electron.ee_distance); @@ -507,7 +506,7 @@ qmckl_exit_code qmckl_provide_ee_distance(qmckl_context context) :CRetType: qmckl_exit_code :FRetType: qmckl_exit_code :END: - + #+NAME: qmckl_ee_distance_args | qmckl_context | context | in | Global state | | int64_t | elec_num | in | Number of electrons | @@ -530,19 +529,19 @@ integer function qmckl_compute_ee_distance_f(context, elec_num, walk_num, coord, info = QMCKL_SUCCESS - if (context == QMCKL_NULL_CONTEXT) then - info = QMCKL_INVALID_CONTEXT - return + if (context == QMCKL_NULL_CONTEXT) then + info = QMCKL_INVALID_CONTEXT + return endif - if (elec_num <= 0) then + if (elec_num <= 0) then info = QMCKL_INVALID_ARG_2 - return + return endif - if (walk_num <= 0) then + if (walk_num <= 0) then info = QMCKL_INVALID_ARG_3 - return + return endif !$OMP PARALLEL DO DEFAULT(NONE) & @@ -565,11 +564,11 @@ end function qmckl_compute_ee_distance_f const int64_t elec_num, const int64_t walk_num, const double* coord, - double* const ee_distance ); + double* const ee_distance ); #+end_src #+CALL: generate_c_interface(table=qmckl_ee_distance_args,rettyp=get_value("CRetType"),fname=get_value("Name")) - + #+RESULTS: #+begin_src f90 :tangle (eval f) :comments org :exports none integer(c_int32_t) function qmckl_compute_ee_distance & @@ -609,7 +608,7 @@ munit_assert_double_equal(distance[1], 8.6114953086801, 12); #+end_src * End of files :noexport: - + #+begin_src c :tangle (eval h_private_type) #endif #+end_src @@ -621,35 +620,35 @@ munit_assert_double_equal(distance[1], 8.6114953086801, 12); return MUNIT_OK; } #+end_src - -**✸ Compute file names - #+begin_src emacs-lisp -; The following is required to compute the file names - -(setq pwd (file-name-directory buffer-file-name)) -(setq name (file-name-nondirectory (substring buffer-file-name 0 -4))) -(setq f (concat pwd name "_f.f90")) -(setq fh (concat pwd name "_fh.f90")) -(setq c (concat pwd name ".c")) -(setq h (concat name ".h")) -(setq h_private (concat name "_private.h")) -(setq c_test (concat pwd "test_" name ".c")) -(setq f_test (concat pwd "test_" name "_f.f90")) - -; Minted -(require 'ox-latex) -(setq org-latex-listings 'minted) -(add-to-list 'org-latex-packages-alist '("" "listings")) -(add-to-list 'org-latex-packages-alist '("" "color")) - - #+end_src + +**✸ Compute file names + #+begin_src emacs-lisp +; The following is required to compute the file names + +(setq pwd (file-name-directory buffer-file-name)) +(setq name (file-name-nondirectory (substring buffer-file-name 0 -4))) +(setq f (concat pwd name "_f.f90")) +(setq fh (concat pwd name "_fh.f90")) +(setq c (concat pwd name ".c")) +(setq h (concat name ".h")) +(setq h_private (concat name "_private.h")) +(setq c_test (concat pwd "test_" name ".c")) +(setq f_test (concat pwd "test_" name "_f.f90")) + +; Minted +(require 'ox-latex) +(setq org-latex-listings 'minted) +(add-to-list 'org-latex-packages-alist '("" "listings")) +(add-to-list 'org-latex-packages-alist '("" "color")) + + #+end_src #+RESULTS: | | color | | | listings | - + # -*- mode: org -*- # vim: syntax=c - + diff --git a/src/qmckl_error.org b/src/qmckl_error.org index 4bfdfad..da46561 100644 --- a/src/qmckl_error.org +++ b/src/qmckl_error.org @@ -1,6 +1,6 @@ #+TITLE: Error handling -#+SETUPFILE: ../docs/theme.setup -#+INCLUDE: ../tools/lib.org +#+SETUPFILE: ../tools/theme.setup +#+INCLUDE: ../tools/lib.org * Headers :noexport: @@ -32,7 +32,7 @@ MunitResult test_<>() { #+end_src -* +* :PROPERTIES: :UNNUMBERED: t :END: @@ -40,7 +40,7 @@ MunitResult test_<>() { The library should never make the calling programs abort, nor perform any input/output operations. This decision has to be taken by the developer of the code calling the library. - + All the functions return with an exit code, defined as #+NAME: type-exit-code #+begin_src c :comments org :tangle (eval h_type) @@ -82,20 +82,20 @@ typedef int32_t qmckl_exit_code; | ~QMCKL_INVALID_EXIT_CODE~ | 106 | 'Invalid exit code' | # We need to force Emacs not to indent the Python code: - # -*- org-src-preserve-indentation: t - + # -*- org-src-preserve-indentation: t + #+begin_src python :var table=table-exit-codes :results drawer :exports none """ This script generates the C and Fortran constants for the error codes from the org-mode table. """ -result = [ "#+begin_src c :comments org :tangle (eval h_type) :exports none" ] +result = [ "#+begin_src c :comments org :tangle (eval h_type) :exports none" ] for (text, code,_) in table: text=text.replace("~","") result += [ f"#define {text:30s} ((qmckl_exit_code) {code:d})" ] result += [ "#+end_src" ] - -result += [ "" ] + +result += [ "" ] result += [ "#+begin_src f90 :comments org :tangle (eval fh_type) :exports none" ] for (text, code,_) in table: @@ -157,7 +157,7 @@ return '\n'.join(result) * Decoding errors To decode the error messages, ~qmckl_string_of_error~ converts an - error code into a string. + error code into a string. #+NAME: MAX_STRING_LENGTH : 128 @@ -167,7 +167,7 @@ const char* qmckl_string_of_error(const qmckl_exit_code error); void qmckl_string_of_error_f(const qmckl_exit_code error, char result[<>]); #+end_src - + The text strings are extracted from the previous table. #+NAME:cases @@ -179,7 +179,7 @@ void qmckl_string_of_error_f(const qmckl_exit_code error, result = [] for (text, code, message) in table: text = text.replace("~","") - message = message.replace("'",'"') + message = message.replace("'",'"') result += [ f"""case {text}: return {message}; break;""" ] @@ -187,7 +187,7 @@ return '\n'.join(result) #+end_src - # Source + # Source #+begin_src c :comments org :tangle (eval c) :noweb yes const char* qmckl_string_of_error(const qmckl_exit_code error) { switch (error) { @@ -200,7 +200,7 @@ void qmckl_string_of_error_f(const qmckl_exit_code error, char result[<>); } #+end_src - + # Fortran interface #+begin_src f90 :tangle (eval fh_func) :noexport :noweb yes interface @@ -232,7 +232,7 @@ typedef struct qmckl_error_struct { #+end_src * Updating errors in the context - + The error is updated in the context using ~qmckl_set_error~. When the error is set in the context, it is mandatory to specify from which function the error is triggered, and a message @@ -271,13 +271,13 @@ qmckl_set_error(qmckl_context context, { qmckl_context_struct* const ctx = (qmckl_context_struct* const) context; assert (ctx != NULL); /* Impossible because the context is valid. */ - + ctx->error.exit_code = exit_code; strncpy(ctx->error.function, function_name, QMCKL_MAX_FUN_LEN); strncpy(ctx->error.message, message, QMCKL_MAX_MSG_LEN); } qmckl_unlock(context); - + return QMCKL_SUCCESS; } #+end_src @@ -316,13 +316,13 @@ qmckl_exit_code qmckl_failwith(qmckl_context context, if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) return QMCKL_INVALID_CONTEXT; - + if (message == NULL) { - qmckl_exit_code rc = + qmckl_exit_code rc = qmckl_set_error(context, exit_code, function, qmckl_string_of_error(exit_code)); assert (rc == QMCKL_SUCCESS); } else { - qmckl_exit_code rc = + qmckl_exit_code rc = qmckl_set_error(context, exit_code, function, message); assert (rc == QMCKL_SUCCESS); } @@ -337,11 +337,11 @@ qmckl_exit_code qmckl_failwith(qmckl_context context, if (x < 0) { return qmckl_failwith(context, QMCKL_INVALID_ARG_2, - "qmckl_function", + "qmckl_function", "Expected x >= 0"); } #+end_src - + * End of files :noexport: diff --git a/src/qmckl_memory.org b/src/qmckl_memory.org index 6cef69a..f5942f3 100644 --- a/src/qmckl_memory.org +++ b/src/qmckl_memory.org @@ -1,6 +1,6 @@ #+TITLE: Memory management -#+SETUPFILE: ../docs/theme.setup -#+INCLUDE: ../tools/lib.org +#+SETUPFILE: ../tools/theme.setup +#+INCLUDE: ../tools/lib.org We override the allocation functions to enable the possibility of optimized libraries to fine-tune the memory allocation. @@ -43,10 +43,10 @@ MunitResult test_<>() { #+end_src * Memory data structure for the context - + Every time a new block of memory is allocated, the information relative to the allocation is stored in a new ~qmckl_memory_info_struct~. - A ~qmckl_memory_info_struct~ contains the pointer to the memory block, + A ~qmckl_memory_info_struct~ contains the pointer to the memory block, its size in bytes, and extra implementation-specific information such as alignment, pinning, if the memory should be allocated on CPU or GPU /etc/. @@ -63,11 +63,11 @@ static const qmckl_memory_info_struct qmckl_memory_info_struct_zero = .pointer = NULL }; #+end_src - + The ~memory~ element of the context is a data structure which contains an array of ~qmckl_memory_info_struct~, the size of the array, and the number of allocated blocks. - + #+begin_src c :tangle (eval h_private_type) :noweb yes typedef struct qmckl_memory_struct { size_t n_allocated; @@ -80,7 +80,7 @@ typedef struct qmckl_memory_struct { Passing information to the allocation routine should be done by passing an instance of a ~qmckl_memory_info_struct~. - + * Allocation/deallocation functions Memory allocation inside the library should be done with @@ -97,7 +97,7 @@ typedef struct qmckl_memory_struct { void* qmckl_malloc(qmckl_context context, const qmckl_memory_info_struct info); #+end_src - + # Source #+begin_src c :tangle (eval c) void* qmckl_malloc(qmckl_context context, const qmckl_memory_info_struct info) { @@ -126,12 +126,12 @@ void* qmckl_malloc(qmckl_context context, const qmckl_memory_info_struct info) { free(pointer); return NULL; } - + memset( &(new_array[old_size]), 0, old_size * sizeof(qmckl_memory_info_struct) ); ctx->memory.element = new_array; ctx->memory.array_size = 2L * old_size; } - + /* Find first NULL entry */ size_t pos = (size_t) 0; while ( pos < ctx->memory.array_size && ctx->memory.element[pos].size > (size_t) 0) { @@ -145,7 +145,7 @@ void* qmckl_malloc(qmckl_context context, const qmckl_memory_info_struct info) { ctx->memory.n_allocated += (size_t) 1; } qmckl_unlock(context); - + return pointer; } #+end_src @@ -154,7 +154,7 @@ void* qmckl_malloc(qmckl_context context, const qmckl_memory_info_struct info) { # Test :noexport: #+begin_src c :tangle (eval c_test) /* Create a context */ -qmckl_context context = qmckl_context_create(); +qmckl_context context = qmckl_context_create(); qmckl_memory_info_struct info = qmckl_memory_info_struct_zero; info.size = (size_t) 3; @@ -197,14 +197,14 @@ qmckl_exit_code qmckl_free(qmckl_context context, void * const ptr) { "qmckl_free", NULL); } - + if (ptr == NULL) { return qmckl_failwith(context, QMCKL_INVALID_ARG_2, "qmckl_free", "NULL pointer"); } - + qmckl_context_struct* const ctx = (qmckl_context_struct* const) context; qmckl_lock(context); @@ -214,7 +214,7 @@ qmckl_exit_code qmckl_free(qmckl_context context, void * const ptr) { while ( pos < ctx->memory.array_size && ctx->memory.element[pos].pointer != ptr) { pos += (size_t) 1; } - + if (pos >= ctx->memory.array_size) { /* Not found */ qmckl_unlock(context); @@ -276,7 +276,7 @@ munit_assert(rc == QMCKL_SUCCESS); } #+end_src - + # -*- mode: org -*- # vim: syntax=c diff --git a/src/qmckl_numprec.org b/src/qmckl_numprec.org index ea082de..24f6a69 100644 --- a/src/qmckl_numprec.org +++ b/src/qmckl_numprec.org @@ -1,6 +1,6 @@ #+TITLE: Numerical precision -#+SETUPFILE: ../docs/theme.setup -#+INCLUDE: ../tools/lib.org +#+SETUPFILE: ../tools/theme.setup +#+INCLUDE: ../tools/lib.org * Headers :noexport: @@ -17,7 +17,7 @@ MunitResult test_<>() { #include #+end_src - #+begin_src c :tangle (eval c) + #+begin_src c :tangle (eval c) #include #include #include @@ -92,7 +92,7 @@ typedef struct qmckl_numprec_struct { uint32_t range; } qmckl_numprec_struct; #+end_src - + The following functions set and get the required precision and range. ~precision~ is an integer between 2 and 53, and ~range~ is an integer between 2 and 11. @@ -180,7 +180,7 @@ int qmckl_get_numprec_precision(const qmckl_context context) { return ctx->numprec.precision; } #+end_src - + # Fortran interface #+begin_src f90 :tangle (eval fh_func) interface @@ -193,7 +193,7 @@ int qmckl_get_numprec_precision(const qmckl_context context) { #+end_src * Range - + ~qmckl_set_numprec_range~ modifies the parameter for the numerical range in a given context. diff --git a/src/test_qmckl.org b/src/test_qmckl.org index de71b96..6e1b7a9 100644 --- a/src/test_qmckl.org +++ b/src/test_qmckl.org @@ -1,5 +1,5 @@ #+TITLE: Testing -#+SETUPFILE: ../docs/theme.setup +#+SETUPFILE: ../tools/theme.setup * QMCkl test :noexport: @@ -8,7 +8,7 @@ First, we use a script to find the list of all the generated test files: #+NAME: test-files - #+begin_src sh :exports none + #+begin_src sh :exports none FILES=$(cat table_of_contents) grep begin_src $FILES \ | grep c_test \ @@ -48,7 +48,7 @@ echo "#+end_src" MunitResult test_qmckl_distance(); #+end_src :end: - + and the required function calls: #+begin_src sh :var files=test-files :exports output :results drawer echo "#+NAME: calls" @@ -60,7 +60,7 @@ do done echo "#+end_src" #+end_src - + #+RESULTS: :results: #+NAME: calls @@ -78,7 +78,7 @@ echo "#+end_src" allocations with ~mtrace~. Memory allocations will be traced in the file specified by the ~MALLOC_TRACE~ environment variable. - #+begin_src c :comments link :noweb yes :tangle test_qmckl.c + #+begin_src c :comments link :noweb yes :tangle test_qmckl.c #include "qmckl.h" #include "munit.h" #include "mcheck.h" @@ -97,10 +97,10 @@ int main(int argc, char* argv[MUNIT_ARRAY_PARAM(argc + 1)]) { (char*) "", test_suite_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE }; - + int result = munit_suite_main(&test_suite, (void*) "µnit", argc, argv); muntrace(); return result; } #+end_src - + diff --git a/tools/Building.org b/tools/Building.org index d1042a7..6b3d3b5 100644 --- a/tools/Building.org +++ b/tools/Building.org @@ -167,7 +167,10 @@ endif .PHONY: clean shared static doc all check install uninstall .SECONDARY: # Needed to keep the produced C and Fortran files -$(shared_lib) $(static_lib) install uninstall: $(qmckl_h) $(qmckl_f) Makefile.generated +$(shared_lib) $(static_lib): $(qmckl_h) $(qmckl_f) Makefile.generated + $(MAKE) -f Makefile.generated $@ + +install uninstall: Makefile.generated $(MAKE) -f Makefile.generated $@ $(qmckl_f) $(qmckl_h): Makefile.generated @@ -180,6 +183,12 @@ all: shared static doc check check: $(static_lib) $(MAKE) -f Makefile.generated check +cppcheck: + cppcheck \ + --addon=cert \ + --enable=warning,style,performance,portability,information \ + qmckl_*.c + doc: $(ORG_SOURCE_FILES) $(QMCKL_ROOT)/tools/build_doc.sh @@ -191,10 +200,10 @@ clean: Makefile.generated *.html *.txt veryclean: clean FORCE - - $(RM) $(QMCKL_ROOT)/docs/*.html \ - $(QMCKL_ROOT)/docs/*.txt + - $(RM) $(QMCKL_ROOT)/share/doc/qmckl/html/*.html \ + $(QMCKL_ROOT)/share/doc/qmckl/text/*.txt -Makefile.generated: Makefile $(QMCKL_ROOT)/tools/create_makefile.sh $(ORG_SOURCE_FILES) +Makefile.generated: Makefile $(QMCKL_ROOT)/tools/create_makefile.sh $(ORG_SOURCE_FILES) ../tools/Building.org $(QMCKL_ROOT)/tools/create_makefile.sh @@ -361,15 +370,29 @@ check: test_qmckl test_qmckl_shared clean: \$(RM) -- *.o *.mod \$(shared_lib) \$(static_lib) test_qmckl + + + install: install -d \$(prefix)/lib install -d \$(prefix)/include install -d \$(prefix)/share/qmckl/fortran - install -d \$(prefix)/man - install \$(shared_lib) \$(prefix)/lib - install \$(static_lib) \$(prefix)/lib - install \$(qmckl_h) \$(prefix)/include - install \$(qmckl_f) \$(prefix)/share/qmckl/fortran + install -d \$(prefix)/share/doc/qmckl/html/ + install -d \$(prefix)/share/doc/qmckl/text/ + install \$(shared_lib) \$(prefix)/lib + install \$(static_lib) \$(prefix)/lib + install \$(qmckl_h) \$(prefix)/include + install \$(qmckl_f) \$(prefix)/share/qmckl/fortran + install \$(QMCKL_ROOT)/share/doc/qmckl/html/*.html \$(prefix)/share/doc/qmckl/html/ + install \$(QMCKL_ROOT)/share/doc/qmckl/html/*.css \$(prefix)/share/doc/qmckl/html/ + install \$(QMCKL_ROOT)/share/doc/qmckl/text/*.txt \$(prefix)/share/doc/qmckl/text/ + +uninstall: + rm \$(prefix)/lib/libqmckl.so + rm \$(prefix)/lib/libqmckl.a + rm \$(prefix)/include/qmckl.h + rm -rf \$(prefix)/share/qmckl/ + rm -rf \$(prefix)/share/doc/qmckl/ .SUFFIXES: .c .f90 .o @@ -379,7 +402,7 @@ install: .f90.o: qmckl_f.o \$(FC) \$(FFLAGS) -c \$*.f90 -o \$*.o -.PHONY: check clean all +.PHONY: check cppcheck clean all EOF #+end_src @@ -495,9 +518,9 @@ EOF First define readonly global variables. #+begin_src bash :noweb yes -readonly DOCS=${QMCKL_ROOT}/docs/ +readonly DOCS=${QMCKL_ROOT}/share/doc/qmckl/ readonly SRC=${QMCKL_ROOT}/src/ -readonly HTMLIZE=${DOCS}/htmlize.el +readonly HTMLIZE=${DOCS}/html/htmlize.el readonly CONFIG_DOC=${QMCKL_ROOT}/tools/config_doc.el readonly CONFIG_TANGLE=${QMCKL_ROOT}/tools/config_tangle.el #+end_src @@ -513,7 +536,7 @@ function check_preconditions() exit 1 fi - for dir in ${DOCS} ${SRC} + for dir in ${DOCS}/html ${DOCS}/text ${SRC} do if [[ ! -d ${dir} ]] then @@ -543,7 +566,7 @@ function install_htmlize() local repo="emacs-htmlize" [[ -f ${HTMLIZE} ]] || ( - cd ${DOCS} + cd ${DOCS}/html git clone ${url} \ && cp ${repo}/htmlize.el ${HTMLIZE} \ && rm -rf ${repo} @@ -564,7 +587,8 @@ function extract_doc() local org=$1 local local_html=${SRC}/${org%.org}.html local local_text=${SRC}/${org%.org}.txt - local html=${DOCS}/${org%.org}.html + local html=${DOCS}/html/${org%.org}.html + local text=${DOCS}/text/${org%.org}.txt if [[ -f ${html} && ${org} -ot ${html} ]] then @@ -577,7 +601,8 @@ function extract_doc() --load ${CONFIG_TANGLE} \ -f org-html-export-to-html \ -f org-ascii-export-to-ascii - mv ${local_html} ${local_text} ${DOCS} + mv ${local_html} ${DOCS}/html + mv ${local_text} ${DOCS}/text } #+end_src @@ -605,7 +630,7 @@ function main() { if [[ $? -eq 0 ]] then - cd ${DOCS} + cd ${DOCS}/html rm -f index.html ln README.html index.html exit 0 diff --git a/tools/build_doc.sh b/tools/build_doc.sh index 7de7111..ceef3e8 100755 --- a/tools/build_doc.sh +++ b/tools/build_doc.sh @@ -7,9 +7,9 @@ # First define readonly global variables. -readonly DOCS=${QMCKL_ROOT}/docs/ +readonly DOCS=${QMCKL_ROOT}/share/doc/qmckl/ readonly SRC=${QMCKL_ROOT}/src/ -readonly HTMLIZE=${DOCS}/htmlize.el +readonly HTMLIZE=${DOCS}/html/htmlize.el readonly CONFIG_DOC=${QMCKL_ROOT}/tools/config_doc.el readonly CONFIG_TANGLE=${QMCKL_ROOT}/tools/config_tangle.el @@ -26,7 +26,7 @@ function check_preconditions() exit 1 fi - for dir in ${DOCS} ${SRC} + for dir in ${DOCS}/html ${DOCS}/text ${SRC} do if [[ ! -d ${dir} ]] then @@ -57,7 +57,7 @@ function install_htmlize() local repo="emacs-htmlize" [[ -f ${HTMLIZE} ]] || ( - cd ${DOCS} + cd ${DOCS}/html git clone ${url} \ && cp ${repo}/htmlize.el ${HTMLIZE} \ && rm -rf ${repo} @@ -79,7 +79,8 @@ function extract_doc() local org=$1 local local_html=${SRC}/${org%.org}.html local local_text=${SRC}/${org%.org}.txt - local html=${DOCS}/${org%.org}.html + local html=${DOCS}/html/${org%.org}.html + local text=${DOCS}/text/${org%.org}.txt if [[ -f ${html} && ${org} -ot ${html} ]] then @@ -92,7 +93,8 @@ function extract_doc() --load ${CONFIG_TANGLE} \ -f org-html-export-to-html \ -f org-ascii-export-to-ascii - mv ${local_html} ${local_text} ${DOCS} + mv ${local_html} ${DOCS}/html + mv ${local_text} ${DOCS}/text } @@ -121,7 +123,7 @@ function main() { if [[ $? -eq 0 ]] then - cd ${DOCS} + cd ${DOCS}/html rm -f index.html ln README.html index.html exit 0 diff --git a/tools/create_makefile.sh b/tools/create_makefile.sh index 7c15a48..1c10f68 100755 --- a/tools/create_makefile.sh +++ b/tools/create_makefile.sh @@ -117,15 +117,29 @@ check: test_qmckl test_qmckl_shared clean: \$(RM) -- *.o *.mod \$(shared_lib) \$(static_lib) test_qmckl + + + install: install -d \$(prefix)/lib install -d \$(prefix)/include install -d \$(prefix)/share/qmckl/fortran - install -d \$(prefix)/man - install \$(shared_lib) \$(prefix)/lib - install \$(static_lib) \$(prefix)/lib - install \$(qmckl_h) \$(prefix)/include - install \$(qmckl_f) \$(prefix)/share/qmckl/fortran + install -d \$(prefix)/share/doc/qmckl/html/ + install -d \$(prefix)/share/doc/qmckl/text/ + install \$(shared_lib) \$(prefix)/lib + install \$(static_lib) \$(prefix)/lib + install \$(qmckl_h) \$(prefix)/include + install \$(qmckl_f) \$(prefix)/share/qmckl/fortran + install \$(QMCKL_ROOT)/share/doc/qmckl/html/*.html \$(prefix)/share/doc/qmckl/html/ + install \$(QMCKL_ROOT)/share/doc/qmckl/html/*.css \$(prefix)/share/doc/qmckl/html/ + install \$(QMCKL_ROOT)/share/doc/qmckl/text/*.txt \$(prefix)/share/doc/qmckl/text/ + +uninstall: + rm \$(prefix)/lib/libqmckl.so + rm \$(prefix)/lib/libqmckl.a + rm \$(prefix)/include/qmckl.h + rm -rf \$(prefix)/share/qmckl/ + rm -rf \$(prefix)/share/doc/qmckl/ .SUFFIXES: .c .f90 .o @@ -135,5 +149,5 @@ install: .f90.o: qmckl_f.o \$(FC) \$(FFLAGS) -c \$*.f90 -o \$*.o -.PHONY: check clean all +.PHONY: check cppcheck clean all EOF