mirror of
https://github.com/TREX-CoE/qmckl.git
synced 2025-01-03 10:06:09 +01:00
Added make doc
This commit is contained in:
parent
3286145e66
commit
9fde54922e
1
src/.gitignore
vendored
1
src/.gitignore
vendored
@ -2,6 +2,7 @@
|
||||
*.c
|
||||
*.f90
|
||||
*.h
|
||||
*.html
|
||||
*~
|
||||
*.so
|
||||
Makefile.generated
|
||||
|
@ -21,6 +21,9 @@ libqmckl.so: Makefile.generated
|
||||
test: Makefile.generated
|
||||
$(MAKE) -f Makefile.generated test
|
||||
|
||||
doc:$(ORG_SOURCE_FILES)
|
||||
./create_doc.sh $(ORG_SOURCE_FILES)
|
||||
|
||||
clean:
|
||||
rm -f qmckl.h test_qmckl_* qmckl_*.f90 qmckl_*.c qmckl_*.o qmckl_*.h Makefile.generated libqmckl.so
|
||||
|
||||
|
285
src/README.org
285
src/README.org
@ -1,53 +1,60 @@
|
||||
* QMCkl source code
|
||||
#+TITLE: QMCkl source code documentation
|
||||
|
||||
** Introduction
|
||||
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/htmlize.css"/>
|
||||
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/readtheorg.css"/>
|
||||
#+HTML_HEAD: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
|
||||
#+HTML_HEAD: <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
|
||||
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/lib/js/jquery.stickytableheaders.js"></script>
|
||||
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/readtheorg/js/readtheorg.js"></script>
|
||||
|
||||
The ultimate goal of QMCkl is to provide a high-performance
|
||||
implementation of the main kernels of QMC. In this particular
|
||||
repository, we focus on the definition of the API and the tests,
|
||||
and on a /pedagogical/ presentation of the algorithms. We expect the
|
||||
HPC experts to use this repository as a reference for re-writing
|
||||
optimized libraries.
|
||||
* Introduction
|
||||
|
||||
Literate programming is particularly adapted in this context.
|
||||
Source files are written in [[ottps://karl-voit.at/2017/09/23/orgmode-as-markup-only/][org-mode]] format, to provide useful
|
||||
comments and LaTex formulas close to the code. There exists multiple
|
||||
possibilities to convert org-mode files into different formats such as
|
||||
HTML or pdf.
|
||||
For a tutorial on literate programming with org-mode, follow
|
||||
[[http://www.howardism.org/Technical/Emacs/literate-programming-tutorial.html][this link]].
|
||||
The ultimate goal of QMCkl is to provide a high-performance
|
||||
implementation of the main kernels of QMC. In this particular
|
||||
repository, we focus on the definition of the API and the tests,
|
||||
and on a /pedagogical/ presentation of the algorithms. We expect the
|
||||
HPC experts to use this repository as a reference for re-writing
|
||||
optimized libraries.
|
||||
|
||||
The code is extracted from the org files using Emacs as a command-line
|
||||
tool in the =Makefile=, and then the produced files are compiled.
|
||||
Literate programming is particularly adapted in this context.
|
||||
Source files are written in [[https://karl-voit.at/2017/09/23/orgmode-as-markup-only/][org-mode]] format, to provide useful
|
||||
comments and LaTex formulas close to the code. There exists multiple
|
||||
possibilities to convert org-mode files into different formats such as
|
||||
HTML or pdf.
|
||||
For a tutorial on literate programming with org-mode, follow
|
||||
[[http://www.howardism.org/Technical/Emacs/literate-programming-tutorial.html][this link]].
|
||||
|
||||
*** Language used
|
||||
The code is extracted from the org files using Emacs as a command-line
|
||||
tool in the =Makefile=, and then the produced files are compiled.
|
||||
|
||||
Fortran is one of the most common languages used by the community,
|
||||
and is simple enough to make the algorithms readable. Hence we
|
||||
propose in this pedagogical implementation of QMCkl to use Fortran
|
||||
to express the algorithms. For specific internal functions where
|
||||
the C language is more natural, C is used.
|
||||
** Language used
|
||||
|
||||
As Fortran modules generate compiler-dependent files, the use of
|
||||
modules is restricted to the internal use of the library, otherwise
|
||||
the compliance with C is violated.
|
||||
Fortran is one of the most common languages used by the community,
|
||||
and is simple enough to make the algorithms readable. Hence we
|
||||
propose in this pedagogical implementation of QMCkl to use Fortran
|
||||
to express the algorithms. For specific internal functions where
|
||||
the C language is more natural, C is used.
|
||||
|
||||
The external dependencies should be kept as small as possible, so
|
||||
external libraries should be used /only/ if their used is strongly
|
||||
justified.
|
||||
As Fortran modules generate compiler-dependent files, the use of
|
||||
modules is restricted to the internal use of the library, otherwise
|
||||
the compliance with C is violated.
|
||||
|
||||
*** Source code editing
|
||||
The external dependencies should be kept as small as possible, so
|
||||
external libraries should be used /only/ if their used is strongly
|
||||
justified.
|
||||
|
||||
Any text editor can be used to edit org-mode files. For a better
|
||||
user experience Emacs is recommended.
|
||||
For users hating Emacs, it is good to know that Emacs can behave
|
||||
like Vim when switched into ``Evil'' mode. There also exists
|
||||
[[https://www.spacemacs.org][Spacemacs]] which helps the transition for Vim users.
|
||||
** Source code editing
|
||||
|
||||
For users with a preference for Jupyter notebooks, the following
|
||||
script can convert jupyter notebooks to org-mode files:
|
||||
Any text editor can be used to edit org-mode files. For a better
|
||||
user experience Emacs is recommended.
|
||||
For users hating Emacs, it is good to know that Emacs can behave
|
||||
like Vim when switched into ``Evil'' mode. There also exists
|
||||
[[https://www.spacemacs.org][Spacemacs]] which helps the transition for Vim users.
|
||||
|
||||
#+BEGIN_SRC sh tangle: nb_to_org.sh
|
||||
For users with a preference for Jupyter notebooks, the following
|
||||
script can convert jupyter notebooks to org-mode files:
|
||||
|
||||
#+BEGIN_SRC sh tangle: nb_to_org.sh
|
||||
#!/bin/bash
|
||||
# $ nb_to_org.sh notebook.ipynb
|
||||
# produces the org-mode file notebook.org
|
||||
@ -58,143 +65,143 @@ nb=$(basename $1 .ipynb)
|
||||
jupyter nbconvert --to markdown ${nb}.ipynb --output ${nb}.md
|
||||
pandoc ${nb}.md -o ${nb}.org
|
||||
rm ${nb}.md
|
||||
#+END_SRC
|
||||
#+END_SRC
|
||||
|
||||
And pandoc can convert multiple markdown formats into org-mode.
|
||||
And pandoc can convert multiple markdown formats into org-mode.
|
||||
|
||||
*** Writing in Fortran
|
||||
** Writing in Fortran
|
||||
|
||||
The Fortran source files should provide a C interface using
|
||||
iso-c-binding. The name of the Fortran source files should end
|
||||
with =_f.f90= to be properly handled by the Makefile.
|
||||
The Fortran source files should provide a C interface using
|
||||
iso-c-binding. The name of the Fortran source files should end
|
||||
with =_f.f90= to be properly handled by the Makefile.
|
||||
|
||||
*** Coding style
|
||||
# TODO: decide on a coding style
|
||||
** Coding style
|
||||
# TODO: decide on a coding style
|
||||
|
||||
To improve readability, we maintain a consistent coding style in the library.
|
||||
To improve readability, we maintain a consistent coding style in the library.
|
||||
|
||||
- For C source files, we will use __(decide on a coding style)__
|
||||
- For Fortran source files, we will use __(decide on a coding style)__
|
||||
- For C source files, we will use __(decide on a coding style)__
|
||||
- For Fortran source files, we will use __(decide on a coding style)__
|
||||
|
||||
Coding style can be automatically checked with [[https://clang.llvm.org/docs/ClangFormat.html][clang-format]].
|
||||
Coding style can be automatically checked with [[https://clang.llvm.org/docs/ClangFormat.html][clang-format]].
|
||||
|
||||
** Design of the library
|
||||
* Design of the library
|
||||
|
||||
The proposed API should allow the library to:
|
||||
- deal with memory transfers between CPU and accelerators
|
||||
- use different levels of floating-point precision
|
||||
The proposed API should allow the library to:
|
||||
- deal with memory transfers between CPU and accelerators
|
||||
- use different levels of floating-point precision
|
||||
|
||||
We chose a multi-layered design with low-level and high-level
|
||||
functions (see below).
|
||||
We chose a multi-layered design with low-level and high-level
|
||||
functions (see below).
|
||||
|
||||
*** Naming conventions
|
||||
** Naming conventions
|
||||
|
||||
Use =qmckl_= as a prefix for all exported functions and variables.
|
||||
All exported header files should have a filename with the prefix
|
||||
=qmckl_=.
|
||||
Use =qmckl_= as a prefix for all exported functions and variables.
|
||||
All exported header files should have a filename with the prefix
|
||||
=qmckl_=.
|
||||
|
||||
If the name of the org-mode file is =xxx.org=, the name of the
|
||||
produced C files should be =xxx.c= and =xxx.h= and the name of the
|
||||
produced Fortran files should be =xxx.f90=
|
||||
If the name of the org-mode file is =xxx.org=, the name of the
|
||||
produced C files should be =xxx.c= and =xxx.h= and the name of the
|
||||
produced Fortran files should be =xxx.f90=
|
||||
|
||||
*** Application programming interface
|
||||
** Application programming interface
|
||||
|
||||
The application programming interface (API) is designed to be
|
||||
compatible with the C programming language (not C++), to ensure
|
||||
that the library will be easily usable in any language.
|
||||
This implies that only the following data types are allowed in the API:
|
||||
The application programming interface (API) is designed to be
|
||||
compatible with the C programming language (not C++), to ensure
|
||||
that the library will be easily usable in any language.
|
||||
This implies that only the following data types are allowed in the API:
|
||||
|
||||
- 32-bit and 64-bit floats and arrays
|
||||
- 32-bit and 64-bit integers and arrays
|
||||
- Pointers should be represented as 64-bit integers (even on
|
||||
32-bit architectures)
|
||||
- ASCII strings are represented as a pointers to a character arrays
|
||||
and terminated by a zero character (C convention).
|
||||
- 32-bit and 64-bit floats and arrays
|
||||
- 32-bit and 64-bit integers and arrays
|
||||
- Pointers should be represented as 64-bit integers (even on
|
||||
32-bit architectures)
|
||||
- ASCII strings are represented as a pointers to a character arrays
|
||||
and terminated by a zero character (C convention).
|
||||
|
||||
To facilitate the use in other languages than C, we provide some
|
||||
bindings in other languages in other repositories.
|
||||
To facilitate the use in other languages than C, we provide some
|
||||
bindings in other languages in other repositories.
|
||||
|
||||
# TODO : Link to repositories for bindings
|
||||
# TODO : Link to repositories for bindings
|
||||
|
||||
*** Global state
|
||||
** Global state
|
||||
|
||||
Global variables should be avoided in the library, because it is
|
||||
possible that one single program needs to use multiple instances of
|
||||
the library. To solve this problem we propose to use a pointer to a
|
||||
=context= variable, built by the library with the
|
||||
=qmckl_context_create= function. The =context= contains the global
|
||||
state of the library, and is used as the first argument of many
|
||||
QMCkl functions.
|
||||
Global variables should be avoided in the library, because it is
|
||||
possible that one single program needs to use multiple instances of
|
||||
the library. To solve this problem we propose to use a pointer to a
|
||||
=context= variable, built by the library with the
|
||||
=qmckl_context_create= function. The =context= contains the global
|
||||
state of the library, and is used as the first argument of many
|
||||
QMCkl functions.
|
||||
|
||||
Modifying the state is done by setters and getters, prefixed
|
||||
by =qmckl_context_set_= an =qmckl_context_get_=.
|
||||
When a context variable is modified by a setter, a copy of the old
|
||||
data structure is made and updated, and the pointer to the new data
|
||||
structure is returned, such that the old contexts can still be
|
||||
accessed.
|
||||
It is also possible to modify the state in an impure fashion, using
|
||||
the =qmckl_context_update_= functions.
|
||||
The context and its old versions can be destroyed with
|
||||
=qmckl_context_destroy=.
|
||||
Modifying the state is done by setters and getters, prefixed
|
||||
by =qmckl_context_set_= an =qmckl_context_get_=.
|
||||
When a context variable is modified by a setter, a copy of the old
|
||||
data structure is made and updated, and the pointer to the new data
|
||||
structure is returned, such that the old contexts can still be
|
||||
accessed.
|
||||
It is also possible to modify the state in an impure fashion, using
|
||||
the =qmckl_context_update_= functions.
|
||||
The context and its old versions can be destroyed with
|
||||
=qmckl_context_destroy=.
|
||||
|
||||
*** Low-level functions
|
||||
** Low-level functions
|
||||
|
||||
Low-level functions are very simple functions which are leaves of the
|
||||
function call tree (they don't call any other QMCkl function).
|
||||
Low-level functions are very simple functions which are leaves of the
|
||||
function call tree (they don't call any other QMCkl function).
|
||||
|
||||
This functions are /pure/, and unaware of the QMCkl =context=. They are
|
||||
not allowed to allocate/deallocate memory, and if they need
|
||||
temporary memory it should be provided in input.
|
||||
This functions are /pure/, and unaware of the QMCkl =context=. They are
|
||||
not allowed to allocate/deallocate memory, and if they need
|
||||
temporary memory it should be provided in input.
|
||||
|
||||
*** High-level functions
|
||||
** High-level functions
|
||||
|
||||
High-level functions are at the top of the function call tree.
|
||||
They are able to choose which lower-level function to call
|
||||
depending on the required precision, and do the corresponding type
|
||||
conversions.
|
||||
These functions are also responsible for allocating temporary
|
||||
storage, to simplify the use of accelerators.
|
||||
High-level functions are at the top of the function call tree.
|
||||
They are able to choose which lower-level function to call
|
||||
depending on the required precision, and do the corresponding type
|
||||
conversions.
|
||||
These functions are also responsible for allocating temporary
|
||||
storage, to simplify the use of accelerators.
|
||||
|
||||
The high-level functions should be pure, unless the introduction of
|
||||
non-purity is justified. All the side effects should be made in the
|
||||
=context= variable.
|
||||
The high-level functions should be pure, unless the introduction of
|
||||
non-purity is justified. All the side effects should be made in the
|
||||
=context= variable.
|
||||
|
||||
# TODO : We need an identifier for impure functions
|
||||
# TODO : We need an identifier for impure functions
|
||||
|
||||
*** Numerical precision
|
||||
** Numerical precision
|
||||
|
||||
The number of bits of precision required for a function should be
|
||||
given as an input of low-level computational functions. This input will
|
||||
be used to define the values of the different thresholds that might
|
||||
be used to avoid computing unnecessary noise.
|
||||
High-level functions will use the precision specified in the
|
||||
=context= variable.
|
||||
The number of bits of precision required for a function should be
|
||||
given as an input of low-level computational functions. This input will
|
||||
be used to define the values of the different thresholds that might
|
||||
be used to avoid computing unnecessary noise.
|
||||
High-level functions will use the precision specified in the
|
||||
=context= variable.
|
||||
|
||||
** Algorithms
|
||||
* Algorithms
|
||||
|
||||
Reducing the scaling of an algorithm usually implies also reducing
|
||||
its arithmetic complexity (number of flops per byte). Therefore,
|
||||
for small sizes \(\mathcal{O}(N^3)\) and \(\mathcal{O}(N^2)\) algorithms
|
||||
are better adapted than linear scaling algorithms.
|
||||
As QMCkl is a general purpose library, multiple algorithms should
|
||||
be implemented adapted to different problem sizes.
|
||||
Reducing the scaling of an algorithm usually implies also reducing
|
||||
its arithmetic complexity (number of flops per byte). Therefore,
|
||||
for small sizes \(\mathcal{O}(N^3)\) and \(\mathcal{O}(N^2)\) algorithms
|
||||
are better adapted than linear scaling algorithms.
|
||||
As QMCkl is a general purpose library, multiple algorithms should
|
||||
be implemented adapted to different problem sizes.
|
||||
|
||||
|
||||
** Rules for the API
|
||||
* Rules for the API
|
||||
|
||||
- =stdint= should be used for integers (=int32_t=, =int64_t=)
|
||||
- integers used for counting should always be =int64_t=
|
||||
- floats should be by default =double=, unless explicitly mentioned
|
||||
- pointers are converted to =int64_t= to increase portability
|
||||
- =stdint= should be used for integers (=int32_t=, =int64_t=)
|
||||
- integers used for counting should always be =int64_t=
|
||||
- floats should be by default =double=, unless explicitly mentioned
|
||||
- pointers are converted to =int64_t= to increase portability
|
||||
|
||||
** Documentation
|
||||
* Documentation
|
||||
|
||||
- [[qmckl.org][Main QMCkl header file]]
|
||||
- [[qmckl_memory.org][Memory management]]
|
||||
- [[qmckl_context.org][Context]]
|
||||
- [[qmckl_distance.org][Distance]]
|
||||
- [[./qmckl.org][Main QMCkl header file]]
|
||||
- [[./qmckl_memory.org][Memory management]]
|
||||
- [[./qmckl_context.org][Context]]
|
||||
- [[./qmckl_distance.org][Distance]]
|
||||
|
||||
** Acknowledgments
|
||||
* Acknowledgments
|
||||
|
||||
[[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.
|
||||
[[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.
|
||||
|
22
src/create_doc.sh
Executable file
22
src/create_doc.sh
Executable file
@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Tangle org files
|
||||
|
||||
emacsclient -a "" \
|
||||
--socket-name=org_to_code \
|
||||
--eval "(require 'org)"
|
||||
|
||||
for INPUT in $@ ; do
|
||||
echo $INPUT
|
||||
emacsclient \
|
||||
--no-wait \
|
||||
--socket-name=org_to_code \
|
||||
--eval "(find-file \"$INPUT\")" \
|
||||
--eval "(org-html-export-to-html)"
|
||||
done
|
||||
|
||||
emacsclient \
|
||||
--no-wait \
|
||||
--socket-name=org_to_code \
|
||||
--eval '(kill-emacs)'
|
||||
|
@ -2,6 +2,13 @@
|
||||
# vim: syntax=c
|
||||
#+TITLE: QMCkl C header
|
||||
|
||||
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/htmlize.css"/>
|
||||
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/readtheorg.css"/>
|
||||
#+HTML_HEAD: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
|
||||
#+HTML_HEAD: <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
|
||||
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/lib/js/jquery.stickytableheaders.js"></script>
|
||||
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/readtheorg/js/readtheorg.js"></script>
|
||||
|
||||
This file produces the =qmckl.h= header file, which is included in all
|
||||
other C header files. It is the main entry point to the library.
|
||||
|
||||
|
@ -2,6 +2,14 @@
|
||||
# vim: syntax=c
|
||||
#+TITLE: Context
|
||||
|
||||
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/htmlize.css"/>
|
||||
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/readtheorg.css"/>
|
||||
#+HTML_HEAD: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
|
||||
#+HTML_HEAD: <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
|
||||
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/lib/js/jquery.stickytableheaders.js"></script>
|
||||
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/readtheorg/js/readtheorg.js"></script>
|
||||
|
||||
|
||||
This file is written in C because it is more natural to express the context in
|
||||
C than in Fortran.
|
||||
|
||||
@ -36,7 +44,7 @@ MunitResult test_qmckl_context() {
|
||||
outside of the library. To simplify compatibility with other
|
||||
languages, the pointer to the internal data structure is converted
|
||||
into a 64-bit signed integer, defined in the =qmckl_context= type.
|
||||
A value of 0 for the context is equivalent to a NULL pointer.
|
||||
A value of 0 for the context is equivalent to a =NULL= pointer.
|
||||
|
||||
*** Source
|
||||
#+BEGIN_SRC C :comments link :tangle qmckl_context.c
|
||||
|
@ -2,6 +2,13 @@
|
||||
# vim: syntax=c
|
||||
#+TITLE: Computation of distances
|
||||
|
||||
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/htmlize.css"/>
|
||||
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/readtheorg.css"/>
|
||||
#+HTML_HEAD: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
|
||||
#+HTML_HEAD: <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
|
||||
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/lib/js/jquery.stickytableheaders.js"></script>
|
||||
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/readtheorg/js/readtheorg.js"></script>
|
||||
|
||||
Function for the computation of distances between particles.
|
||||
|
||||
3 files are produced:
|
||||
@ -65,7 +72,7 @@ MunitResult test_qmckl_distance() {
|
||||
Computes the matrix of the squared distances between all pairs of
|
||||
points in two sets, one point within each set:
|
||||
\[
|
||||
C_{ij^2} = \sum_{k=1}^3 (A_{i,k}-B_{j,k})^2
|
||||
C_{ij} = \sum_{k=1}^3 (A_{i,k}-B_{j,k})^2
|
||||
\]
|
||||
|
||||
*** Arguments
|
||||
|
@ -2,6 +2,14 @@
|
||||
# vim: syntax=c
|
||||
#+TITLE: Memory management
|
||||
|
||||
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/htmlize.css"/>
|
||||
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/readtheorg.css"/>
|
||||
#+HTML_HEAD: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
|
||||
#+HTML_HEAD: <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
|
||||
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/lib/js/jquery.stickytableheaders.js"></script>
|
||||
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/readtheorg/js/readtheorg.js"></script>
|
||||
|
||||
|
||||
We override the allocation functions to enable the possibility of
|
||||
optimized libraries to fine-tune the memory allocation.
|
||||
|
||||
@ -10,35 +18,35 @@ optimized libraries to fine-tune the memory allocation.
|
||||
- a source file : =qmckl_memory.c=
|
||||
- a test file : =test_qmckl_memory.c=
|
||||
|
||||
*** Header
|
||||
#+BEGIN_SRC C :comments link :tangle qmckl_memory.h
|
||||
** Header
|
||||
#+BEGIN_SRC C :comments link :tangle qmckl_memory.h
|
||||
#ifndef QMCKL_MEMORY_H
|
||||
#define QMCKL_MEMORY_H
|
||||
#include "qmckl.h"
|
||||
#+END_SRC
|
||||
#+END_SRC
|
||||
|
||||
*** Source
|
||||
#+BEGIN_SRC C :comments link :tangle qmckl_memory.c
|
||||
** Source
|
||||
#+BEGIN_SRC C :comments link :tangle qmckl_memory.c
|
||||
#include <stdlib.h>
|
||||
#include "qmckl_memory.h"
|
||||
#+END_SRC
|
||||
#+END_SRC
|
||||
|
||||
*** Test
|
||||
#+BEGIN_SRC C :comments link :tangle test_qmckl_memory.c
|
||||
** Test
|
||||
#+BEGIN_SRC C :comments link :tangle test_qmckl_memory.c
|
||||
#include "qmckl.h"
|
||||
#include "munit.h"
|
||||
MunitResult test_qmckl_memory() {
|
||||
#+END_SRC
|
||||
#+END_SRC
|
||||
|
||||
** =qmckl_malloc=
|
||||
Analogous of =malloc, but passing a context and a signed 64-bit integers as argument.=
|
||||
*** Header
|
||||
#+BEGIN_SRC C :comments link :tangle qmckl_memory.h
|
||||
* =qmckl_malloc=
|
||||
Analogous of =malloc, but passing a context and a signed 64-bit integers as argument.=
|
||||
** Header
|
||||
#+BEGIN_SRC C :comments link :tangle qmckl_memory.h
|
||||
void* qmckl_malloc(const qmckl_context ctx, const size_t size);
|
||||
#+END_SRC
|
||||
#+END_SRC
|
||||
|
||||
*** Source
|
||||
#+BEGIN_SRC C :comments link :tangle qmckl_memory.c
|
||||
** Source
|
||||
#+BEGIN_SRC C :comments link :tangle qmckl_memory.c
|
||||
void* qmckl_malloc(const qmckl_context ctx, const size_t size) {
|
||||
if (ctx == (qmckl_context) 0) {
|
||||
/* Avoids unused parameter error */
|
||||
@ -47,10 +55,10 @@ void* qmckl_malloc(const qmckl_context ctx, const size_t size) {
|
||||
return malloc( (size_t) size );
|
||||
}
|
||||
|
||||
#+END_SRC
|
||||
#+END_SRC
|
||||
|
||||
*** Test
|
||||
#+BEGIN_SRC C :comments link :tangle test_qmckl_memory.c
|
||||
** Test
|
||||
#+BEGIN_SRC C :comments link :tangle test_qmckl_memory.c
|
||||
int *a;
|
||||
a = (int*) qmckl_malloc( (qmckl_context) 1, 3*sizeof(int));
|
||||
a[0] = 1;
|
||||
@ -59,37 +67,37 @@ void* qmckl_malloc(const qmckl_context ctx, const size_t size) {
|
||||
munit_assert_int(a[0], ==, 1);
|
||||
munit_assert_int(a[1], ==, 2);
|
||||
munit_assert_int(a[2], ==, 3);
|
||||
#+END_SRC
|
||||
#+END_SRC
|
||||
|
||||
** =qmckl_free=
|
||||
* =qmckl_free=
|
||||
|
||||
*** Header
|
||||
#+BEGIN_SRC C :comments link :tangle qmckl_memory.h
|
||||
** Header
|
||||
#+BEGIN_SRC C :comments link :tangle qmckl_memory.h
|
||||
void qmckl_free(void *ptr);
|
||||
#+END_SRC
|
||||
#+END_SRC
|
||||
|
||||
*** Source
|
||||
#+BEGIN_SRC C :comments link :tangle qmckl_memory.c
|
||||
** Source
|
||||
#+BEGIN_SRC C :comments link :tangle qmckl_memory.c
|
||||
void qmckl_free(void *ptr) {
|
||||
free(ptr);
|
||||
}
|
||||
#+END_SRC
|
||||
#+END_SRC
|
||||
|
||||
*** Test
|
||||
#+BEGIN_SRC C :comments link :tangle test_qmckl_memory.c
|
||||
** Test
|
||||
#+BEGIN_SRC C :comments link :tangle test_qmckl_memory.c
|
||||
qmckl_free(a);
|
||||
#+END_SRC
|
||||
#+END_SRC
|
||||
|
||||
* End of files
|
||||
|
||||
*** Header
|
||||
#+BEGIN_SRC C :comments link :tangle qmckl_memory.h
|
||||
** Header
|
||||
#+BEGIN_SRC C :comments link :tangle qmckl_memory.h
|
||||
#endif
|
||||
#+END_SRC
|
||||
#+END_SRC
|
||||
|
||||
*** Test
|
||||
#+BEGIN_SRC C :comments link :tangle test_qmckl_memory.c
|
||||
** Test
|
||||
#+BEGIN_SRC C :comments link :tangle test_qmckl_memory.c
|
||||
return MUNIT_OK;
|
||||
}
|
||||
|
||||
#+END_SRC
|
||||
#+END_SRC
|
||||
|
@ -1,5 +1,12 @@
|
||||
#+TITLE: QMCkl test
|
||||
|
||||
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/htmlize.css"/>
|
||||
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/readtheorg.css"/>
|
||||
#+HTML_HEAD: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
|
||||
#+HTML_HEAD: <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
|
||||
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/lib/js/jquery.stickytableheaders.js"></script>
|
||||
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/readtheorg/js/readtheorg.js"></script>
|
||||
|
||||
This file is the main program of the unit tests. The tests rely on the
|
||||
$\mu$unit framework, which is provided as a git submodule.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user