mirror of
https://github.com/TREX-CoE/qmckl.git
synced 2025-01-08 04:19:15 +01:00
Deploying to gh-pages from @ TREX-CoE/qmckl@03c0abbf4e 🚀
This commit is contained in:
parent
42b3cf591f
commit
0c67ce7a46
@ -3,7 +3,7 @@
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<!-- 2021-03-28 Sun 23:40 -->
|
||||
<!-- 2021-04-20 Tue 22:01 -->
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>QMCkl source code documentation</title>
|
||||
@ -315,8 +315,8 @@ for the JavaScript code in this tag.
|
||||
<li><a href="./qmckl_error.html">Error handling</a></li>
|
||||
<li><a href="./qmckl_context.html">Context</a></li>
|
||||
<li><a href="./qmckl_memory.html">Memory management</a></li>
|
||||
<li><a href="./qmckl_distance.html">Inter-particle distances</a></li>
|
||||
<li><a href="./qmckl_ao.html">Atomic Orbitals</a></li>
|
||||
<li><a href="./qmckl_distance.html">Inter-particle distances</a></li>
|
||||
<li><a href="./test_qmckl.html">Testing</a></li>
|
||||
</ul>
|
||||
|
||||
@ -348,7 +348,7 @@ and bug reports should be submitted at
|
||||
</div>
|
||||
<div id="postamble" class="status">
|
||||
<p class="author">Author: TREX CoE</p>
|
||||
<p class="date">Created: 2021-03-28 Sun 23:40</p>
|
||||
<p class="date">Created: 2021-04-20 Tue 22:01</p>
|
||||
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
||||
</div>
|
||||
</body>
|
||||
|
@ -3,7 +3,7 @@
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<!-- 2021-03-28 Sun 23:40 -->
|
||||
<!-- 2021-04-20 Tue 22:01 -->
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>QMCkl source code documentation</title>
|
||||
@ -315,8 +315,8 @@ for the JavaScript code in this tag.
|
||||
<li><a href="./qmckl_error.html">Error handling</a></li>
|
||||
<li><a href="./qmckl_context.html">Context</a></li>
|
||||
<li><a href="./qmckl_memory.html">Memory management</a></li>
|
||||
<li><a href="./qmckl_distance.html">Inter-particle distances</a></li>
|
||||
<li><a href="./qmckl_ao.html">Atomic Orbitals</a></li>
|
||||
<li><a href="./qmckl_distance.html">Inter-particle distances</a></li>
|
||||
<li><a href="./test_qmckl.html">Testing</a></li>
|
||||
</ul>
|
||||
|
||||
@ -348,7 +348,7 @@ and bug reports should be submitted at
|
||||
</div>
|
||||
<div id="postamble" class="status">
|
||||
<p class="author">Author: TREX CoE</p>
|
||||
<p class="date">Created: 2021-03-28 Sun 23:40</p>
|
||||
<p class="date">Created: 2021-04-20 Tue 22:01</p>
|
||||
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
||||
</div>
|
||||
</body>
|
||||
|
238
qmckl.html
238
qmckl.html
@ -3,7 +3,7 @@
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<!-- 2021-03-28 Sun 23:40 -->
|
||||
<!-- 2021-04-20 Tue 22:01 -->
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Introduction</title>
|
||||
@ -333,30 +333,30 @@ for the JavaScript code in this tag.
|
||||
<h2>Table of Contents</h2>
|
||||
<div id="text-table-of-contents">
|
||||
<ul>
|
||||
<li><a href="#orgb70c621">1. Using QMCkl</a></li>
|
||||
<li><a href="#org5805181">2. Developing in QMCkl</a>
|
||||
<li><a href="#orgfad701e">1. Using QMCkl</a></li>
|
||||
<li><a href="#org666b0a8">2. Developing in QMCkl</a>
|
||||
<ul>
|
||||
<li><a href="#org6703b2b">2.1. Literate programming</a></li>
|
||||
<li><a href="#org99f235d">2.2. Source code editing</a></li>
|
||||
<li><a href="#org0e38020">2.3. Choice of the programming language</a></li>
|
||||
<li><a href="#org573c8ad">2.4. Coding rules</a></li>
|
||||
<li><a href="#org05713f0">2.5. Design of the library</a></li>
|
||||
<li><a href="#org15f5922">2.6. Naming conventions</a></li>
|
||||
<li><a href="#org2016963">2.7. Application programming interface</a></li>
|
||||
<li><a href="#orgc412529">2.8. Global state</a></li>
|
||||
<li><a href="#orgf43aa74">2.9. Low-level functions</a></li>
|
||||
<li><a href="#org9191e07">2.10. High-level functions</a></li>
|
||||
<li><a href="#org28587b9">2.11. Numerical precision</a></li>
|
||||
<li><a href="#orgc0ec3d1">2.12. Algorithms</a></li>
|
||||
<li><a href="#org9c9e3a2">2.13. Rules for the API</a></li>
|
||||
<li><a href="#orgc90ef5a">2.1. Literate programming</a></li>
|
||||
<li><a href="#orgcd82212">2.2. Source code editing</a></li>
|
||||
<li><a href="#orga892df6">2.3. Choice of the programming language</a></li>
|
||||
<li><a href="#org91f35ed">2.4. Coding rules</a></li>
|
||||
<li><a href="#org4363ef9">2.5. Design of the library</a></li>
|
||||
<li><a href="#orgb99ff1c">2.6. Naming conventions</a></li>
|
||||
<li><a href="#org33dc21d">2.7. Application programming interface</a></li>
|
||||
<li><a href="#org99e6046">2.8. Global state</a></li>
|
||||
<li><a href="#org8d8ca42">2.9. Headers</a></li>
|
||||
<li><a href="#org813fe30">2.10. Low-level functions</a></li>
|
||||
<li><a href="#org0fbd9f2">2.11. High-level functions</a></li>
|
||||
<li><a href="#org649b7e0">2.12. Numerical precision</a></li>
|
||||
<li><a href="#org83f62db">2.13. Algorithms</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-orgb70c621" class="outline-2">
|
||||
<h2 id="orgb70c621"><span class="section-number-2">1</span> Using QMCkl</h2>
|
||||
<div id="outline-container-orgfad701e" class="outline-2">
|
||||
<h2 id="orgfad701e"><span class="section-number-2">1</span> Using QMCkl</h2>
|
||||
<div class="outline-text-2" id="text-1">
|
||||
<p>
|
||||
The <code>qmckl.h</code> header file has to be included in C codes when
|
||||
@ -385,12 +385,12 @@ Both files are located in the <code>include/</code> directory.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org5805181" class="outline-2">
|
||||
<h2 id="org5805181"><span class="section-number-2">2</span> Developing in QMCkl</h2>
|
||||
<div id="outline-container-org666b0a8" class="outline-2">
|
||||
<h2 id="org666b0a8"><span class="section-number-2">2</span> Developing in QMCkl</h2>
|
||||
<div class="outline-text-2" id="text-2">
|
||||
</div>
|
||||
<div id="outline-container-org6703b2b" class="outline-3">
|
||||
<h3 id="org6703b2b"><span class="section-number-3">2.1</span> Literate programming</h3>
|
||||
<div id="outline-container-orgc90ef5a" class="outline-3">
|
||||
<h3 id="orgc90ef5a"><span class="section-number-3">2.1</span> Literate programming</h3>
|
||||
<div class="outline-text-3" id="text-2-1">
|
||||
<p>
|
||||
In a traditional source code, most of the lines of source files of a program
|
||||
@ -435,9 +435,8 @@ interactively, in the same spirit as Jupyter notebooks.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="outline-container-org99f235d" class="outline-3">
|
||||
<h3 id="org99f235d"><span class="section-number-3">2.2</span> Source code editing</h3>
|
||||
<div id="outline-container-orgcd82212" class="outline-3">
|
||||
<h3 id="orgcd82212"><span class="section-number-3">2.2</span> Source code editing</h3>
|
||||
<div class="outline-text-3" id="text-2-2">
|
||||
<p>
|
||||
For a tutorial on literate programming with org-mode, follow <a href="http://www.howardism.org/Technical/Emacs/literate-programming-tutorial.html">this link</a>.
|
||||
@ -468,9 +467,8 @@ org-mode.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="outline-container-org0e38020" class="outline-3">
|
||||
<h3 id="org0e38020"><span class="section-number-3">2.3</span> Choice of the programming language</h3>
|
||||
<div id="outline-container-orga892df6" class="outline-3">
|
||||
<h3 id="orga892df6"><span class="section-number-3">2.3</span> Choice of the programming language</h3>
|
||||
<div class="outline-text-3" id="text-2-3">
|
||||
<p>
|
||||
Most of the codes of the <a href="https://trex-coe.eu">TREX CoE</a> are written in Fortran with some scripts in
|
||||
@ -508,7 +506,7 @@ The Fortran source files should provide a C interface using the
|
||||
<code>iso_c_binding</code> module. The name of the Fortran source files should end with
|
||||
<code>_f.f90</code> to be properly handled by the <code>Makefile</code>. The names of the functions
|
||||
defined in Fortran should be the same as those exposed in the API suffixed by
|
||||
<code>_f</code>. Fortran interfaces should also be written in the <code>qmckl_f.f90</code> file.
|
||||
<code>_f</code>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
@ -518,25 +516,27 @@ For more guidelines on using Fortran to generate a C interface, see
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org573c8ad" class="outline-3">
|
||||
<h3 id="org573c8ad"><span class="section-number-3">2.4</span> Coding rules</h3>
|
||||
<div id="outline-container-org91f35ed" class="outline-3">
|
||||
<h3 id="org91f35ed"><span class="section-number-3">2.4</span> Coding rules</h3>
|
||||
<div class="outline-text-3" id="text-2-4">
|
||||
<p>
|
||||
The authors should follow the recommendations of the
|
||||
<a href="https://wiki.sei.cmu.edu/confluence/display/c/SEI+CERT+C+Coding+Standard">SEI+CERT+C+Coding+Standard</a>.
|
||||
The authors should follow the recommendations of the C99
|
||||
<a href="https://wiki.sei.cmu.edu/confluence/display/c/SEI+CERT+C+Coding+Standard">SEI+CERT C Coding Standard</a>.
|
||||
</p>
|
||||
|
||||
<ul class="org-ul">
|
||||
<li>Store a new value in pointers immediately after the memory is
|
||||
freed</li>
|
||||
<li>Free dynamically allocated memory when no longer needed</li>
|
||||
</ul>
|
||||
<p>
|
||||
Compliance can be checked with <code>cppcheck</code> as:
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-bash">cppcheck --addon=cert --enable=all *.c &> cppcheck.out
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="outline-container-org05713f0" class="outline-3">
|
||||
<h3 id="org05713f0"><span class="section-number-3">2.5</span> Design of the library</h3>
|
||||
<div id="outline-container-org4363ef9" class="outline-3">
|
||||
<h3 id="org4363ef9"><span class="section-number-3">2.5</span> Design of the library</h3>
|
||||
<div class="outline-text-3" id="text-2-5">
|
||||
<p>
|
||||
The proposed API should allow the library to: deal with memory transfers
|
||||
@ -547,8 +547,8 @@ functions (see below).
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org15f5922" class="outline-3">
|
||||
<h3 id="org15f5922"><span class="section-number-3">2.6</span> Naming conventions</h3>
|
||||
<div id="outline-container-orgb99ff1c" class="outline-3">
|
||||
<h3 id="orgb99ff1c"><span class="section-number-3">2.6</span> Naming conventions</h3>
|
||||
<div class="outline-text-3" id="text-2-6">
|
||||
<p>
|
||||
To avoid namespace collisions, we use <code>qmckl_</code> as a prefix for all exported
|
||||
@ -573,8 +573,8 @@ form is allowed.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org2016963" class="outline-3">
|
||||
<h3 id="org2016963"><span class="section-number-3">2.7</span> Application programming interface</h3>
|
||||
<div id="outline-container-org33dc21d" class="outline-3">
|
||||
<h3 id="org33dc21d"><span class="section-number-3">2.7</span> Application programming interface</h3>
|
||||
<div class="outline-text-3" id="text-2-7">
|
||||
<p>
|
||||
In the C language, the number of bits used by the integer types can change
|
||||
@ -595,8 +595,7 @@ than C, we restrict the data types in the interfaces to the following:
|
||||
and terminated by a <code>'\0'</code> character (C convention).</li>
|
||||
<li>Complex numbers can be represented by an array of 2 floats.</li>
|
||||
<li>Boolean variables are stored as integers, <code>1</code> for <code>true</code> and <code>0</code> for <code>false</code></li>
|
||||
<li>Floating point variables should be by default</li>
|
||||
<li><code>double</code> unless explicitly mentioned</li>
|
||||
<li>Floating point variables should be by default <code>double</code> unless explicitly mentioned</li>
|
||||
<li>integers used for counting should always be <code>int64_t</code></li>
|
||||
</ul>
|
||||
|
||||
@ -607,15 +606,15 @@ bindings in other languages in other repositories.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-orgc412529" class="outline-3">
|
||||
<h3 id="orgc412529"><span class="section-number-3">2.8</span> Global state</h3>
|
||||
<div id="outline-container-org99e6046" class="outline-3">
|
||||
<h3 id="org99e6046"><span class="section-number-3">2.8</span> Global state</h3>
|
||||
<div class="outline-text-3" id="text-2-8">
|
||||
<p>
|
||||
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 <a href="./qmckl_context.html"><code>context</code></a> variable, built by the library with the
|
||||
<code>qmckl_context_create</code> function. The <a id="orgab1c430">=context=</a> contains the global
|
||||
<code>qmckl_context_create</code> function. The <a id="org8da452a">=context=</a> contains the global
|
||||
state of the library, and is used as the first argument of many
|
||||
QMCkl functions.
|
||||
</p>
|
||||
@ -624,36 +623,119 @@ QMCkl functions.
|
||||
The internal structure of the context is not specified, to give a
|
||||
maximum of freedom to the different implementations. Modifying
|
||||
the state is done by setters and getters, prefixed by
|
||||
<code>qmckl_context_set_</code> an <code>qmckl_context_get_</code>. 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
|
||||
<code>qmckl_context_update_</code> functions. The context and its old
|
||||
versions can be destroyed with <code>qmckl_context_destroy</code>.
|
||||
<code>qmckl_set_</code> an <code>qmckl_get_</code>.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-orgf43aa74" class="outline-3">
|
||||
<h3 id="orgf43aa74"><span class="section-number-3">2.9</span> Low-level functions</h3>
|
||||
<div id="outline-container-org8d8ca42" class="outline-3">
|
||||
<h3 id="org8d8ca42"><span class="section-number-3">2.9</span> Headers</h3>
|
||||
<div class="outline-text-3" id="text-2-9">
|
||||
<p>
|
||||
A single <code>qmckl.h</code> header to be distributed by the library
|
||||
is built by concatenating some of the produced header files.
|
||||
To facilitate building the <code>qmckl.h</code> file, we separate types from
|
||||
function declarations in headers. Types should be defined in header
|
||||
files suffixed by <code>_type.h</code>, and functions in files suffixed by
|
||||
<code>_func.h</code>.
|
||||
As these files will be concatenated in a single file, they should
|
||||
not be guarded by <code>#ifndef *_H</code>, and they should not include other
|
||||
produced headers.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Some particular types that are not exported need to be known by the
|
||||
context, and there are some functions to update instances of these
|
||||
types contained inside the context. For example, a
|
||||
<code>qmckl_numprec_struct</code> is present in the context, and the function
|
||||
<code>qmckl_set_numprec_range</code> takes a context as a parameter, and set a
|
||||
value in the <code>qmckl_numprec_struct</code> contained in the context.
|
||||
Because of these intricate dependencies, a private header is
|
||||
created, containing the <code>qmckl_numprec_struct</code>. This header is
|
||||
included in the private header which defines the type of the
|
||||
context. Headers for private types are suffixed by <code>_private_type.h</code>
|
||||
and headers for private functions, <code>_private_func.h</code>.
|
||||
Fortran interfaces should also be written in the <code>*_f_func.f90</code> file,
|
||||
and the types definitions should be written in the <code>*_f_type.f90</code> file.
|
||||
</p>
|
||||
|
||||
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
|
||||
|
||||
|
||||
<colgroup>
|
||||
<col class="org-left" />
|
||||
|
||||
<col class="org-left" />
|
||||
|
||||
<col class="org-left" />
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" class="org-left">File</th>
|
||||
<th scope="col" class="org-left">Scope</th>
|
||||
<th scope="col" class="org-left">Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="org-left"><code>*_type.h</code></td>
|
||||
<td class="org-left">Public</td>
|
||||
<td class="org-left">Type definitions</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="org-left"><code>*_func.h</code></td>
|
||||
<td class="org-left">Public</td>
|
||||
<td class="org-left">Function definitions</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="org-left"><code>*_private_type.h</code></td>
|
||||
<td class="org-left">Private</td>
|
||||
<td class="org-left">Type definitions</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="org-left"><code>*_private_func.h</code></td>
|
||||
<td class="org-left">Private</td>
|
||||
<td class="org-left">Function definitions</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="org-left"><code>*fh_type.f90</code></td>
|
||||
<td class="org-left">Public</td>
|
||||
<td class="org-left">Fortran type definitions</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="org-left"><code>*fh_func.f90</code></td>
|
||||
<td class="org-left">Public</td>
|
||||
<td class="org-left">Fortran function definitions</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org813fe30" class="outline-3">
|
||||
<h3 id="org813fe30"><span class="section-number-3">2.10</span> Low-level functions</h3>
|
||||
<div class="outline-text-3" id="text-2-10">
|
||||
<p>
|
||||
Low-level functions are very simple functions which are leaves of
|
||||
the function call tree (they don't call any other QMCkl function).
|
||||
</p>
|
||||
|
||||
<p>
|
||||
These functions are <i>pure</i>, and unaware of the QMCkl
|
||||
<a href="#orgab1c430"><code>context</code></a>. They are not allowed to allocate/deallocate memory, and
|
||||
<a href="#org8da452a"><code>context</code></a>. They are not allowed to allocate/deallocate memory, and
|
||||
if they need temporary memory it should be provided in input.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org9191e07" class="outline-3">
|
||||
<h3 id="org9191e07"><span class="section-number-3">2.10</span> High-level functions</h3>
|
||||
<div class="outline-text-3" id="text-2-10">
|
||||
<div id="outline-container-org0fbd9f2" class="outline-3">
|
||||
<h3 id="org0fbd9f2"><span class="section-number-3">2.11</span> High-level functions</h3>
|
||||
<div class="outline-text-3" id="text-2-11">
|
||||
<p>
|
||||
High-level functions are at the top of the function call tree.
|
||||
They are able to choose which lower-level function to call
|
||||
@ -665,28 +747,28 @@ temporary storage, to simplify the use of accelerators.
|
||||
<p>
|
||||
The high-level functions should be pure, unless the introduction
|
||||
of non-purity is justified. All the side effects should be made in
|
||||
the <a href="#orgab1c430"><code>context</code></a> variable.
|
||||
the <a href="#org8da452a"><code>context</code></a> variable.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org28587b9" class="outline-3">
|
||||
<h3 id="org28587b9"><span class="section-number-3">2.11</span> Numerical precision</h3>
|
||||
<div class="outline-text-3" id="text-2-11">
|
||||
<div id="outline-container-org649b7e0" class="outline-3">
|
||||
<h3 id="org649b7e0"><span class="section-number-3">2.12</span> Numerical precision</h3>
|
||||
<div class="outline-text-3" id="text-2-12">
|
||||
<p>
|
||||
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 <a href="#orgab1c430"><code>context</code></a>
|
||||
functions will use the precision specified in the <a href="#org8da452a"><code>context</code></a>
|
||||
variable.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-orgc0ec3d1" class="outline-3">
|
||||
<h3 id="orgc0ec3d1"><span class="section-number-3">2.12</span> Algorithms</h3>
|
||||
<div class="outline-text-3" id="text-2-12">
|
||||
<div id="outline-container-org83f62db" class="outline-3">
|
||||
<h3 id="org83f62db"><span class="section-number-3">2.13</span> Algorithms</h3>
|
||||
<div class="outline-text-3" id="text-2-13">
|
||||
<p>
|
||||
Reducing the scaling of an algorithm usually implies also reducing
|
||||
its arithmetic complexity (number of flops per byte). Therefore,
|
||||
@ -697,23 +779,11 @@ implemented adapted to different problem sizes.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org9c9e3a2" class="outline-3">
|
||||
<h3 id="org9c9e3a2"><span class="section-number-3">2.13</span> Rules for the API</h3>
|
||||
<div class="outline-text-3" id="text-2-13">
|
||||
<ul class="org-ul">
|
||||
<li><code>stdint</code> should be used for integers (<code>int32_t</code>, <code>int64_t</code>)</li>
|
||||
<li>integers used for counting should always be <code>int64_t</code></li>
|
||||
<li>floats should be by default <code>double</code>, unless explicitly mentioned</li>
|
||||
<li>pointers are converted to <code>int64_t</code> to increase portability</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="postamble" class="status">
|
||||
<p class="author">Author: TREX CoE</p>
|
||||
<p class="date">Created: 2021-03-28 Sun 23:40</p>
|
||||
<p class="date">Created: 2021-04-20 Tue 22:01</p>
|
||||
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
||||
</div>
|
||||
</body>
|
||||
|
1411
qmckl_ao.html
1411
qmckl_ao.html
File diff suppressed because it is too large
Load Diff
1455
qmckl_context.html
1455
qmckl_context.html
File diff suppressed because it is too large
Load Diff
@ -3,7 +3,7 @@
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<!-- 2021-03-28 Sun 23:40 -->
|
||||
<!-- 2021-04-20 Tue 22:01 -->
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Inter-particle distances</title>
|
||||
@ -333,14 +333,14 @@ for the JavaScript code in this tag.
|
||||
<h2>Table of Contents</h2>
|
||||
<div id="text-table-of-contents">
|
||||
<ul>
|
||||
<li><a href="#org65df30a">1. Squared distance</a>
|
||||
<li><a href="#org6d00580">1. Squared distance</a>
|
||||
<ul>
|
||||
<li><a href="#orgbd56de8">1.1. <code>qmckl_distance_sq</code></a>
|
||||
<li><a href="#orgf62fddd">1.1. <code>qmckl_distance_sq</code></a>
|
||||
<ul>
|
||||
<li><a href="#org1f5c068">1.1.1. Requirements</a></li>
|
||||
<li><a href="#orga04895c">1.1.2. C header</a></li>
|
||||
<li><a href="#orgff832ca">1.1.3. Source</a></li>
|
||||
<li><a href="#org626a84c">1.1.4. Performance</a></li>
|
||||
<li><a href="#org9acdf00">1.1.1. Requirements</a></li>
|
||||
<li><a href="#orgd54da10">1.1.2. C header</a></li>
|
||||
<li><a href="#org2fdb853">1.1.3. Source</a></li>
|
||||
<li><a href="#orgea3b568">1.1.4. Performance</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
@ -348,16 +348,13 @@ for the JavaScript code in this tag.
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<p>
|
||||
Functions for the computation of distances between particles.
|
||||
</p>
|
||||
|
||||
<div id="outline-container-org65df30a" class="outline-2">
|
||||
<h2 id="org65df30a"><span class="section-number-2">1</span> Squared distance</h2>
|
||||
<div id="outline-container-org6d00580" class="outline-2">
|
||||
<h2 id="org6d00580"><span class="section-number-2">1</span> Squared distance</h2>
|
||||
<div class="outline-text-2" id="text-1">
|
||||
</div>
|
||||
<div id="outline-container-orgbd56de8" class="outline-3">
|
||||
<h3 id="orgbd56de8"><span class="section-number-3">1.1</span> <code>qmckl_distance_sq</code></h3>
|
||||
<div id="outline-container-orgf62fddd" class="outline-3">
|
||||
<h3 id="orgf62fddd"><span class="section-number-3">1.1</span> <code>qmckl_distance_sq</code></h3>
|
||||
<div class="outline-text-3" id="text-1-1">
|
||||
<p>
|
||||
<code>qmckl_distance_sq</code> computes the matrix of the squared distances
|
||||
@ -370,7 +367,7 @@ between all pairs of points in two sets, one point within each set:
|
||||
\]
|
||||
</p>
|
||||
|
||||
<table id="org39fb159" border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
|
||||
<table id="org8266f3b" border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
|
||||
|
||||
|
||||
<colgroup>
|
||||
@ -420,7 +417,7 @@ between all pairs of points in two sets, one point within each set:
|
||||
|
||||
<tr>
|
||||
<td class="org-left">double</td>
|
||||
<td class="org-left">A[3][lda]</td>
|
||||
<td class="org-left">A[][lda]</td>
|
||||
<td class="org-left">in</td>
|
||||
<td class="org-left">Array containing the \(m \times 3\) matrix \(A\)</td>
|
||||
</tr>
|
||||
@ -434,7 +431,7 @@ between all pairs of points in two sets, one point within each set:
|
||||
|
||||
<tr>
|
||||
<td class="org-left">double</td>
|
||||
<td class="org-left">B[3][ldb]</td>
|
||||
<td class="org-left">B[][ldb]</td>
|
||||
<td class="org-left">in</td>
|
||||
<td class="org-left">Array containing the \(n \times 3\) matrix \(B\)</td>
|
||||
</tr>
|
||||
@ -463,8 +460,8 @@ between all pairs of points in two sets, one point within each set:
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org1f5c068" class="outline-4">
|
||||
<h4 id="org1f5c068"><span class="section-number-4">1.1.1</span> Requirements</h4>
|
||||
<div id="outline-container-org9acdf00" class="outline-4">
|
||||
<h4 id="org9acdf00"><span class="section-number-4">1.1.1</span> Requirements</h4>
|
||||
<div class="outline-text-4" id="text-1-1-1">
|
||||
<ul class="org-ul">
|
||||
<li><code>context</code> is not <code>QMCKL_NULL_CONTEXT</code></li>
|
||||
@ -482,8 +479,8 @@ between all pairs of points in two sets, one point within each set:
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-orga04895c" class="outline-4">
|
||||
<h4 id="orga04895c"><span class="section-number-4">1.1.2</span> C header</h4>
|
||||
<div id="outline-container-orgd54da10" class="outline-4">
|
||||
<h4 id="orgd54da10"><span class="section-number-4">1.1.2</span> C header</h4>
|
||||
<div class="outline-text-4" id="text-1-1-2">
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-c"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_distance_sq</span> (
|
||||
@ -496,21 +493,21 @@ between all pairs of points in two sets, one point within each set:
|
||||
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">lda</span>,
|
||||
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span>* <span style="color: #a0522d;">B</span>,
|
||||
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">ldb</span>,
|
||||
<span style="color: #228b22;">double</span>* <span style="color: #a0522d;">C</span>,
|
||||
<span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">C</span>,
|
||||
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">ldc</span> );
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-orgff832ca" class="outline-4">
|
||||
<h4 id="orgff832ca"><span class="section-number-4">1.1.3</span> Source</h4>
|
||||
<div id="outline-container-org2fdb853" class="outline-4">
|
||||
<h4 id="org2fdb853"><span class="section-number-4">1.1.3</span> Source</h4>
|
||||
<div class="outline-text-4" id="text-1-1-3">
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-f90"><span style="color: #228b22;">integer </span><span style="color: #a020f0;">function</span><span style="color: #a0522d;"> </span><span style="color: #0000ff;">qmckl_distance_sq_f</span><span style="color: #000000; background-color: #ffffff;">(context, transa, transb, m, n, A, LDA, B, LDB, C, LDC) result(info)</span>
|
||||
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">qmckl</span>
|
||||
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</span>
|
||||
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> context</span>
|
||||
<span style="color: #228b22;">integer</span>(qmckl_context) , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> context</span>
|
||||
<span style="color: #228b22;">character</span> , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> transa, transb</span>
|
||||
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> m, n</span>
|
||||
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> lda</span>
|
||||
@ -637,8 +634,8 @@ between all pairs of points in two sets, one point within each set:
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org626a84c" class="outline-4">
|
||||
<h4 id="org626a84c"><span class="section-number-4">1.1.4</span> Performance</h4>
|
||||
<div id="outline-container-orgea3b568" class="outline-4">
|
||||
<h4 id="orgea3b568"><span class="section-number-4">1.1.4</span> Performance</h4>
|
||||
<div class="outline-text-4" id="text-1-1-4">
|
||||
<p>
|
||||
This function might be more efficient when <code>A</code> and <code>B</code> are
|
||||
@ -651,7 +648,7 @@ transposed.
|
||||
</div>
|
||||
<div id="postamble" class="status">
|
||||
<p class="author">Author: TREX CoE</p>
|
||||
<p class="date">Created: 2021-03-28 Sun 23:40</p>
|
||||
<p class="date">Created: 2021-04-20 Tue 22:01</p>
|
||||
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
||||
</div>
|
||||
</body>
|
||||
|
169
qmckl_error.html
169
qmckl_error.html
@ -3,7 +3,7 @@
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<!-- 2021-03-28 Sun 23:40 -->
|
||||
<!-- 2021-04-20 Tue 22:01 -->
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Error handling</title>
|
||||
@ -311,14 +311,18 @@ for the JavaScript code in this tag.
|
||||
<h2>Table of Contents</h2>
|
||||
<div id="text-table-of-contents">
|
||||
<ul>
|
||||
<li><a href="#orgd7973f6"></a></li>
|
||||
<li><a href="#org6298949"></a></li>
|
||||
<li><a href="#org7d7c090">1. Decoding errors</a></li>
|
||||
<li><a href="#orged55d75">2. Data structure in context</a></li>
|
||||
<li><a href="#org213eefa">3. Updating errors in the context</a></li>
|
||||
<li><a href="#orgf2919cf">4. Failing</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-orgd7973f6" class="outline-2">
|
||||
<h2 id="orgd7973f6"></h2>
|
||||
<div class="outline-text-2" id="text-orgd7973f6">
|
||||
<div id="outline-container-org6298949" class="outline-2">
|
||||
<h2 id="org6298949"></h2>
|
||||
<div class="outline-text-2" id="text-org6298949">
|
||||
<p>
|
||||
The library should never make the calling programs abort, nor
|
||||
perform any input/output operations. This decision has to be taken
|
||||
@ -329,10 +333,11 @@ by the developer of the code calling the library.
|
||||
All the functions return with an exit code, defined as
|
||||
</p>
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-c" id="org6cac882"><span style="color: #a020f0;">typedef</span> <span style="color: #228b22;">int32_t</span> <span style="color: #228b22;">qmckl_exit_code</span>;
|
||||
<pre class="src src-c" id="orgbc1078d"><span style="color: #a020f0;">typedef</span> <span style="color: #228b22;">int32_t</span> <span style="color: #228b22;">qmckl_exit_code</span>;
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
|
||||
<p>
|
||||
The exit code returns the completion status of the function to the
|
||||
calling program. When a function call completed successfully,
|
||||
@ -345,7 +350,7 @@ error code is returned to the program.
|
||||
Here is the complete list of exit codes.
|
||||
</p>
|
||||
|
||||
<table id="orgd252c8d" border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
|
||||
<table id="orgc6473bc" border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
|
||||
|
||||
|
||||
<colgroup>
|
||||
@ -468,10 +473,20 @@ Here is the complete list of exit codes.
|
||||
</table>
|
||||
|
||||
<p>
|
||||
The <code>qmckl_strerror</code> converts an exit code into a string. The
|
||||
The <code>qmckl_string_of_error</code> converts an exit code into a string. The
|
||||
string is assumed to be large enough to contain the error message
|
||||
(typically 128 characters).
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org7d7c090" class="outline-2">
|
||||
<h2 id="org7d7c090"><span class="section-number-2">1</span> Decoding errors</h2>
|
||||
<div class="outline-text-2" id="text-1">
|
||||
<p>
|
||||
To decode the error messages, <code>qmckl_string_of_error</code> converts an
|
||||
error code into a string.
|
||||
</p>
|
||||
|
||||
<pre class="example">
|
||||
128
|
||||
@ -550,7 +565,8 @@ The text strings are extracted from the previous table.
|
||||
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
||||
<span style="color: #a020f0;">subroutine</span> <span style="color: #0000ff;">qmckl_string_of_error</span> (error, string) <span style="color: #a020f0;">bind</span>(C, name=<span style="color: #8b2252;">'qmckl_string_of_error_f'</span>)
|
||||
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
|
||||
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> error</span>
|
||||
<span style="color: #a020f0;">import</span>
|
||||
<span style="color: #228b22;">integer</span> (qmckl_exit_code), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> error</span>
|
||||
<span style="color: #228b22;">character</span>, <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> string(128)</span>
|
||||
<span style="color: #a020f0;">end subroutine</span> <span style="color: #0000ff;">qmckl_string_of_error</span>
|
||||
<span style="color: #a020f0;">end interface</span>
|
||||
@ -558,10 +574,143 @@ The text strings are extracted from the previous table.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-orged55d75" class="outline-2">
|
||||
<h2 id="orged55d75"><span class="section-number-2">2</span> Data structure in context</h2>
|
||||
<div class="outline-text-2" id="text-2">
|
||||
<p>
|
||||
The strings are declared with a maximum fixed size to avoid
|
||||
dynamic memory allocation.
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-c"><span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_MAX_FUN_LEN</span> 256
|
||||
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_MAX_MSG_LEN</span> 1024
|
||||
|
||||
<span style="color: #a020f0;">typedef</span> <span style="color: #a020f0;">struct</span> <span style="color: #228b22;">qmckl_error_struct</span> {
|
||||
|
||||
<span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #a0522d;">exit_code</span>;
|
||||
<span style="color: #228b22;">char</span> <span style="color: #a0522d;">function</span>[QMCKL_MAX_FUN_LEN];
|
||||
<span style="color: #228b22;">char</span> <span style="color: #a0522d;">message</span> [QMCKL_MAX_MSG_LEN];
|
||||
|
||||
} <span style="color: #228b22;">qmckl_error_struct</span>;
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org213eefa" class="outline-2">
|
||||
<h2 id="org213eefa"><span class="section-number-2">3</span> Updating errors in the context</h2>
|
||||
<div class="outline-text-2" id="text-3">
|
||||
<p>
|
||||
The error is updated in the context using <code>qmckl_set_error</code>.
|
||||
When the error is set in the context, it is mandatory to specify
|
||||
from which function the error is triggered, and a message
|
||||
explaining the error. The exit code can't be <code>QMCKL_SUCCESS</code>.
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-c"><span style="color: #228b22;">qmckl_exit_code</span>
|
||||
<span style="color: #0000ff;">qmckl_set_error</span>(<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>,
|
||||
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #a0522d;">exit_code</span>,
|
||||
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span>* <span style="color: #a0522d;">function_name</span>,
|
||||
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span>* <span style="color: #a0522d;">message</span>)
|
||||
{
|
||||
/* <span style="color: #b22222;">Passing a function name and a message is mandatory. </span>*/
|
||||
assert (function_name != <span style="color: #008b8b;">NULL</span>);
|
||||
assert (message != <span style="color: #008b8b;">NULL</span>);
|
||||
|
||||
/* <span style="color: #b22222;">Exit codes are assumed valid. </span>*/
|
||||
assert (exit_code >= 0);
|
||||
assert (exit_code != QMCKL_SUCCESS);
|
||||
assert (exit_code < QMCKL_INVALID_EXIT_CODE);
|
||||
|
||||
/* <span style="color: #b22222;">The context is assumed to exist. </span>*/
|
||||
assert (qmckl_context_check(context) != QMCKL_NULL_CONTEXT);
|
||||
|
||||
qmckl_lock(context);
|
||||
{
|
||||
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a020f0;">const</span>) context;
|
||||
assert (ctx != <span style="color: #008b8b;">NULL</span>); /* <span style="color: #b22222;">Impossible because the context is valid. </span>*/
|
||||
|
||||
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);
|
||||
|
||||
<span style="color: #a020f0;">return</span> QMCKL_SUCCESS;
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-orgf2919cf" class="outline-2">
|
||||
<h2 id="orgf2919cf"><span class="section-number-2">4</span> Failing</h2>
|
||||
<div class="outline-text-2" id="text-4">
|
||||
<p>
|
||||
To make a function fail, the <code>qmckl_failwith</code> function should be
|
||||
called, such that information about the failure is stored in
|
||||
the context. The desired exit code is given as an argument, as
|
||||
well as the name of the function and an error message. If the
|
||||
message is <code>NULL</code>, then the default message obtained by
|
||||
<code>qmckl_string_of_error</code> is used. The return code of the function is
|
||||
the desired return code.
|
||||
Upon failure, a <code>QMCKL_NULL_CONTEXT</code> is returned.
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-c"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_failwith</span>(<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>,
|
||||
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #a0522d;">exit_code</span>,
|
||||
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span>* <span style="color: #a0522d;">function</span>,
|
||||
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span>* <span style="color: #a0522d;">message</span>) {
|
||||
|
||||
assert (exit_code > 0);
|
||||
assert (exit_code < QMCKL_INVALID_EXIT_CODE);
|
||||
assert (function != <span style="color: #008b8b;">NULL</span>);
|
||||
assert (strlen(function) < QMCKL_MAX_FUN_LEN);
|
||||
<span style="color: #a020f0;">if</span> (message != <span style="color: #008b8b;">NULL</span>) {
|
||||
assert (strlen(message) < QMCKL_MAX_MSG_LEN);
|
||||
}
|
||||
|
||||
<span style="color: #a020f0;">if</span> (qmckl_context_check(context) == QMCKL_NULL_CONTEXT)
|
||||
<span style="color: #a020f0;">return</span> QMCKL_INVALID_CONTEXT;
|
||||
|
||||
<span style="color: #a020f0;">if</span> (message == <span style="color: #008b8b;">NULL</span>) {
|
||||
<span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #a0522d;">rc</span> =
|
||||
qmckl_set_error(context, exit_code, function, qmckl_string_of_error(exit_code));
|
||||
assert (rc == QMCKL_SUCCESS);
|
||||
} <span style="color: #a020f0;">else</span> {
|
||||
<span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #a0522d;">rc</span> =
|
||||
qmckl_set_error(context, exit_code, function, message);
|
||||
assert (rc == QMCKL_SUCCESS);
|
||||
}
|
||||
|
||||
<span style="color: #a020f0;">return</span> exit_code;
|
||||
}
|
||||
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
For example, this function can be used as
|
||||
</p>
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-c"><span style="color: #a020f0;">if</span> (x < 0) {
|
||||
<span style="color: #a020f0;">return</span> qmckl_failwith(context,
|
||||
QMCKL_INVALID_ARG_2,
|
||||
<span style="color: #8b2252;">"qmckl_function"</span>,
|
||||
<span style="color: #8b2252;">"Expected x >= 0"</span>);
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="postamble" class="status">
|
||||
<p class="author">Author: TREX CoE</p>
|
||||
<p class="date">Created: 2021-03-28 Sun 23:40</p>
|
||||
<p class="date">Created: 2021-04-20 Tue 22:01</p>
|
||||
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
||||
</div>
|
||||
</body>
|
||||
|
@ -3,7 +3,7 @@
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<!-- 2021-03-28 Sun 23:40 -->
|
||||
<!-- 2021-04-20 Tue 22:01 -->
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Memory management</title>
|
||||
@ -311,19 +311,69 @@ for the JavaScript code in this tag.
|
||||
<h2>Table of Contents</h2>
|
||||
<div id="text-table-of-contents">
|
||||
<ul>
|
||||
<li><a href="#orga97b5ff"></a></li>
|
||||
<li><a href="#orgbe3847d">1. Memory data structure for the context</a></li>
|
||||
<li><a href="#org72f037a">2. Passing info to allocation routines</a></li>
|
||||
<li><a href="#org7b74e31">3. Allocation/deallocation functions</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-orgbe3847d" class="outline-2">
|
||||
<h2 id="orgbe3847d"><span class="section-number-2">1</span> Memory data structure for the context</h2>
|
||||
<div class="outline-text-2" id="text-1">
|
||||
<p>
|
||||
We override the allocation functions to enable the possibility of
|
||||
optimized libraries to fine-tune the memory allocation.
|
||||
Every time a new block of memory is allocated, the information
|
||||
relative to the allocation is stored in a new <code>qmckl_memory_info_struct</code>.
|
||||
A <code>qmckl_memory_info_struct</code> 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
|
||||
<i>etc</i>.
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-c"><span style="color: #a020f0;">typedef</span> <span style="color: #a020f0;">struct</span> <span style="color: #228b22;">qmckl_memory_info_struct</span> {
|
||||
<span style="color: #228b22;">size_t</span> <span style="color: #a0522d;">size</span>;
|
||||
<span style="color: #228b22;">void</span>* <span style="color: #a0522d;">pointer</span>;
|
||||
} <span style="color: #228b22;">qmckl_memory_info_struct</span>;
|
||||
|
||||
<div id="outline-container-orga97b5ff" class="outline-2">
|
||||
<h2 id="orga97b5ff"></h2>
|
||||
<div class="outline-text-2" id="text-orga97b5ff">
|
||||
<span style="color: #a020f0;">static</span> <span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_memory_info_struct</span> <span style="color: #a0522d;">qmckl_memory_info_struct_zero</span> =
|
||||
{
|
||||
.size = (<span style="color: #228b22;">size_t</span>) 0,
|
||||
.pointer = <span style="color: #008b8b;">NULL</span>
|
||||
};
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
The <code>memory</code> element of the context is a data structure which
|
||||
contains an array of <code>qmckl_memory_info_struct</code>, the size of the
|
||||
array, and the number of allocated blocks.
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-c"><span style="color: #a020f0;">typedef</span> <span style="color: #a020f0;">struct</span> <span style="color: #228b22;">qmckl_memory_struct</span> {
|
||||
<span style="color: #228b22;">size_t</span> <span style="color: #a0522d;">n_allocated</span>;
|
||||
<span style="color: #228b22;">size_t</span> <span style="color: #a0522d;">array_size</span>;
|
||||
<span style="color: #228b22;">qmckl_memory_info_struct</span>* <span style="color: #a0522d;">element</span>;
|
||||
} <span style="color: #228b22;">qmckl_memory_struct</span>;
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org72f037a" class="outline-2">
|
||||
<h2 id="org72f037a"><span class="section-number-2">2</span> Passing info to allocation routines</h2>
|
||||
<div class="outline-text-2" id="text-2">
|
||||
<p>
|
||||
Passing information to the allocation routine should be done by
|
||||
passing an instance of a <code>qmckl_memory_info_struct</code>.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org7b74e31" class="outline-2">
|
||||
<h2 id="org7b74e31"><span class="section-number-2">3</span> Allocation/deallocation functions</h2>
|
||||
<div class="outline-text-2" id="text-3">
|
||||
<p>
|
||||
Memory allocation inside the library should be done with
|
||||
<code>qmckl_malloc</code>. It lets the library choose how the memory will be
|
||||
@ -337,51 +387,87 @@ If the allocation failed, the <code>NULL</code> pointer is returned.
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-c"><span style="color: #228b22;">void</span>* <span style="color: #0000ff;">qmckl_malloc</span>(<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>,
|
||||
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">size_t</span> <span style="color: #a0522d;">size</span>);
|
||||
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_memory_info_struct</span> <span style="color: #a0522d;">info</span>);
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
In this implementation, we use <code>calloc</code> because it initializes the
|
||||
memory block to zero, so structs will have <code>NULL</code>-initialized pointers.
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-c"><span style="color: #228b22;">void</span>* <span style="color: #0000ff;">qmckl_malloc</span>(<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">size_t</span> <span style="color: #a0522d;">size</span>) {
|
||||
<pre class="src src-c"><span style="color: #228b22;">void</span>* <span style="color: #0000ff;">qmckl_malloc</span>(<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_memory_info_struct</span> <span style="color: #a0522d;">info</span>) {
|
||||
|
||||
<span style="color: #228b22;">void</span> * <span style="color: #a0522d;">pointer</span> = calloc(size, (<span style="color: #228b22;">size_t</span>) 1);
|
||||
assert (qmckl_context_check(context) != QMCKL_NULL_CONTEXT);
|
||||
|
||||
<span style="color: #a020f0;">if</span> (qmckl_context_check(context) != QMCKL_NULL_CONTEXT) {
|
||||
<span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #a0522d;">rc</span>;
|
||||
rc = qmckl_context_append_memory(context, pointer, size);
|
||||
assert (rc == QMCKL_SUCCESS);
|
||||
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a020f0;">const</span>) context;
|
||||
|
||||
/* <span style="color: #b22222;">Allocate memory and zero it </span>*/
|
||||
<span style="color: #228b22;">void</span> * <span style="color: #a0522d;">pointer</span> = malloc(info.size);
|
||||
<span style="color: #a020f0;">if</span> (pointer == <span style="color: #008b8b;">NULL</span>) {
|
||||
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
||||
}
|
||||
memset(pointer, 0, info.size);
|
||||
|
||||
qmckl_lock(context);
|
||||
{
|
||||
/* <span style="color: #b22222;">If qmckl_memory_struct is full, reallocate a larger one </span>*/
|
||||
<span style="color: #a020f0;">if</span> (ctx->memory.n_allocated == ctx->memory.array_size) {
|
||||
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">size_t</span> <span style="color: #a0522d;">old_size</span> = ctx->memory.array_size;
|
||||
<span style="color: #228b22;">qmckl_memory_info_struct</span> * <span style="color: #a0522d;">new_array</span> = reallocarray(ctx->memory.element,
|
||||
2L * old_size,
|
||||
<span style="color: #a020f0;">sizeof</span>(qmckl_memory_info_struct));
|
||||
<span style="color: #a020f0;">if</span> (new_array == <span style="color: #008b8b;">NULL</span>) {
|
||||
qmckl_unlock(context);
|
||||
free(pointer);
|
||||
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
||||
}
|
||||
|
||||
memset( &(new_array[old_size]), 0, <span style="color: #228b22;">old_size</span> * <span style="color: #a020f0;">sizeof</span>(qmckl_memory_info_struct) );
|
||||
ctx->memory.element = new_array;
|
||||
ctx->memory.array_size = 2L * old_size;
|
||||
}
|
||||
|
||||
/* <span style="color: #b22222;">Find first NULL entry </span>*/
|
||||
<span style="color: #228b22;">size_t</span> <span style="color: #a0522d;">pos</span> = (<span style="color: #228b22;">size_t</span>) 0;
|
||||
<span style="color: #a020f0;">while</span> ( pos < ctx->memory.array_size && ctx->memory.element[pos].size > (<span style="color: #228b22;">size_t</span>) 0) {
|
||||
pos += (<span style="color: #228b22;">size_t</span>) 1;
|
||||
}
|
||||
assert (ctx->memory.element[pos].size == (<span style="color: #228b22;">size_t</span>) 0);
|
||||
|
||||
/* <span style="color: #b22222;">Copy info at the new location </span>*/
|
||||
ctx->memory.element[pos].size = info.size;
|
||||
ctx->memory.element[pos].pointer = pointer;
|
||||
ctx->memory.n_allocated += (<span style="color: #228b22;">size_t</span>) 1;
|
||||
}
|
||||
qmckl_unlock(context);
|
||||
|
||||
<span style="color: #a020f0;">return</span> pointer;
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
||||
<span style="color: #228b22;">type (c_ptr) </span><span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_malloc</span> <span style="color: #000000; background-color: #ffffff;">(context, size) bind(C)</span>
|
||||
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
|
||||
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> context</span>
|
||||
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> size</span>
|
||||
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_malloc</span>
|
||||
<span style="color: #a020f0;">end interface</span>
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-c"><span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span> = qmckl_context_create();
|
||||
<pre class="src src-c">/* <span style="color: #b22222;">Create a context </span>*/
|
||||
<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span> = qmckl_context_create();
|
||||
|
||||
<span style="color: #228b22;">int</span> *<span style="color: #a0522d;">a</span> = (<span style="color: #228b22;">int</span>*) <span style="color: #0000ff;">qmckl_malloc</span>(context, 3*<span style="color: #a020f0;">sizeof</span>(<span style="color: #228b22;">int</span>));
|
||||
<span style="color: #228b22;">qmckl_memory_info_struct</span> <span style="color: #a0522d;">info</span> = qmckl_memory_info_struct_zero;
|
||||
info.size = (<span style="color: #228b22;">size_t</span>) 3;
|
||||
|
||||
/* <span style="color: #b22222;">Allocate an array of ints </span>*/
|
||||
<span style="color: #228b22;">int</span> *<span style="color: #a0522d;">a</span> = (<span style="color: #228b22;">int</span>*) <span style="color: #0000ff;">qmckl_malloc</span>(context, info);
|
||||
|
||||
/* <span style="color: #b22222;">Check that array of ints is OK </span>*/
|
||||
<span style="color: #0000ff;">munit_assert</span>(a != <span style="color: #008b8b;">NULL</span>);
|
||||
|
||||
<span style="color: #228b22;">a</span>[0] = 1; <span style="color: #0000ff;">munit_assert_int</span>(<span style="color: #228b22;">a</span>[0], ==, 1);
|
||||
<span style="color: #228b22;">a</span>[1] = 2; <span style="color: #0000ff;">munit_assert_int</span>(<span style="color: #228b22;">a</span>[1], ==, 2);
|
||||
<span style="color: #228b22;">a</span>[2] = 3; <span style="color: #0000ff;">munit_assert_int</span>(<span style="color: #228b22;">a</span>[2], ==, 3);
|
||||
|
||||
/* <span style="color: #b22222;">Allocate another array of ints </span>*/
|
||||
<span style="color: #228b22;">int</span> *<span style="color: #a0522d;">b</span> = (<span style="color: #228b22;">int</span>*) <span style="color: #0000ff;">qmckl_malloc</span>(context, info);
|
||||
|
||||
/* <span style="color: #b22222;">Check that array of ints is OK </span>*/
|
||||
<span style="color: #0000ff;">munit_assert</span>(b != <span style="color: #008b8b;">NULL</span>);
|
||||
<span style="color: #228b22;">b</span>[0] = 1; <span style="color: #0000ff;">munit_assert_int</span>(<span style="color: #228b22;">b</span>[0], ==, 1);
|
||||
<span style="color: #228b22;">b</span>[1] = 2; <span style="color: #0000ff;">munit_assert_int</span>(<span style="color: #228b22;">b</span>[1], ==, 2);
|
||||
<span style="color: #228b22;">b</span>[2] = 3; <span style="color: #0000ff;">munit_assert_int</span>(<span style="color: #228b22;">b</span>[2], ==, 3);
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
@ -393,38 +479,53 @@ allocation and needs to be updated.
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-c"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_free</span>(<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>,
|
||||
<span style="color: #228b22;">void</span> *<span style="color: #a0522d;">ptr</span>);
|
||||
<span style="color: #228b22;">void</span> * <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">ptr</span>);
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
||||
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int32_t</span>) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_free</span> (context, ptr) <span style="color: #a020f0;">bind</span>(C)
|
||||
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
|
||||
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> context</span>
|
||||
<span style="color: #228b22;">type (c_ptr)</span>, <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> :: <span style="color: #a0522d;">ptr</span>
|
||||
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_free</span>
|
||||
<span style="color: #a020f0;">end interface</span>
|
||||
</pre>
|
||||
</div>
|
||||
<pre class="src src-c"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_free</span>(<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>, <span style="color: #228b22;">void</span> * <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">ptr</span>) {
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-c"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_free</span>(<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>, <span style="color: #228b22;">void</span> *<span style="color: #a0522d;">ptr</span>) {
|
||||
<span style="color: #a020f0;">if</span> (qmckl_context_check(context) != QMCKL_NULL_CONTEXT) {
|
||||
|
||||
<span style="color: #a020f0;">if</span> (ptr == <span style="color: #008b8b;">NULL</span>) {
|
||||
<span style="color: #a020f0;">if</span> (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
|
||||
<span style="color: #a020f0;">return</span> qmckl_failwith(context,
|
||||
QMCKL_INVALID_ARG_2,
|
||||
QMCKL_INVALID_CONTEXT,
|
||||
<span style="color: #8b2252;">"qmckl_free"</span>,
|
||||
<span style="color: #8b2252;">"NULL pointer"</span>);
|
||||
<span style="color: #008b8b;">NULL</span>);
|
||||
}
|
||||
|
||||
<span style="color: #a020f0;">if</span> (ptr == <span style="color: #008b8b;">NULL</span>) {
|
||||
<span style="color: #a020f0;">return</span> qmckl_failwith(context,
|
||||
QMCKL_INVALID_ARG_2,
|
||||
<span style="color: #8b2252;">"qmckl_free"</span>,
|
||||
<span style="color: #8b2252;">"NULL pointer"</span>);
|
||||
}
|
||||
|
||||
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a020f0;">const</span>) context;
|
||||
|
||||
qmckl_lock(context);
|
||||
{
|
||||
/* <span style="color: #b22222;">Find pointer in array of saved pointers </span>*/
|
||||
<span style="color: #228b22;">size_t</span> <span style="color: #a0522d;">pos</span> = (<span style="color: #228b22;">size_t</span>) 0;
|
||||
<span style="color: #a020f0;">while</span> ( pos < ctx->memory.array_size && ctx->memory.element[pos].pointer != ptr) {
|
||||
pos += (<span style="color: #228b22;">size_t</span>) 1;
|
||||
}
|
||||
|
||||
<span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #a0522d;">rc</span>;
|
||||
rc = qmckl_context_remove_memory(context, ptr);
|
||||
<span style="color: #a020f0;">if</span> (pos >= ctx->memory.array_size) {
|
||||
/* <span style="color: #b22222;">Not found </span>*/
|
||||
qmckl_unlock(context);
|
||||
<span style="color: #a020f0;">return</span> qmckl_failwith(context,
|
||||
QMCKL_FAILURE,
|
||||
<span style="color: #8b2252;">"qmckl_free"</span>,
|
||||
<span style="color: #8b2252;">"Pointer not found in context"</span>);
|
||||
}
|
||||
|
||||
assert (rc == QMCKL_SUCCESS);
|
||||
free(ptr);
|
||||
|
||||
memset( &(ctx->memory.element[pos]), 0, <span style="color: #a020f0;">sizeof</span>(qmckl_memory_info_struct) );
|
||||
ctx->memory.n_allocated -= (<span style="color: #228b22;">size_t</span>) 1;
|
||||
}
|
||||
free(ptr);
|
||||
qmckl_unlock(context);
|
||||
|
||||
<span style="color: #a020f0;">return</span> QMCKL_SUCCESS;
|
||||
}
|
||||
</pre>
|
||||
@ -434,7 +535,7 @@ allocation and needs to be updated.
|
||||
</div>
|
||||
<div id="postamble" class="status">
|
||||
<p class="author">Author: TREX CoE</p>
|
||||
<p class="date">Created: 2021-03-28 Sun 23:40</p>
|
||||
<p class="date">Created: 2021-04-20 Tue 22:01</p>
|
||||
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
||||
</div>
|
||||
</body>
|
||||
|
588
qmckl_numprec.html
Normal file
588
qmckl_numprec.html
Normal file
@ -0,0 +1,588 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<!-- 2021-04-20 Tue 22:01 -->
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Numerical precision</title>
|
||||
<meta name="generator" content="Org mode" />
|
||||
<meta name="author" content="TREX CoE" />
|
||||
<style type="text/css">
|
||||
<!--/*--><![CDATA[/*><!--*/
|
||||
.title { text-align: center;
|
||||
margin-bottom: .2em; }
|
||||
.subtitle { text-align: center;
|
||||
font-size: medium;
|
||||
font-weight: bold;
|
||||
margin-top:0; }
|
||||
.todo { font-family: monospace; color: red; }
|
||||
.done { font-family: monospace; color: green; }
|
||||
.priority { font-family: monospace; color: orange; }
|
||||
.tag { background-color: #eee; font-family: monospace;
|
||||
padding: 2px; font-size: 80%; font-weight: normal; }
|
||||
.timestamp { color: #bebebe; }
|
||||
.timestamp-kwd { color: #5f9ea0; }
|
||||
.org-right { margin-left: auto; margin-right: 0px; text-align: right; }
|
||||
.org-left { margin-left: 0px; margin-right: auto; text-align: left; }
|
||||
.org-center { margin-left: auto; margin-right: auto; text-align: center; }
|
||||
.underline { text-decoration: underline; }
|
||||
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
|
||||
p.verse { margin-left: 3%; }
|
||||
pre {
|
||||
border: 1px solid #ccc;
|
||||
box-shadow: 3px 3px 3px #eee;
|
||||
padding: 8pt;
|
||||
font-family: monospace;
|
||||
overflow: auto;
|
||||
margin: 1.2em;
|
||||
}
|
||||
pre.src {
|
||||
position: relative;
|
||||
overflow: visible;
|
||||
padding-top: 1.2em;
|
||||
}
|
||||
pre.src:before {
|
||||
display: none;
|
||||
position: absolute;
|
||||
background-color: white;
|
||||
top: -10px;
|
||||
right: 10px;
|
||||
padding: 3px;
|
||||
border: 1px solid black;
|
||||
}
|
||||
pre.src:hover:before { display: inline;}
|
||||
/* Languages per Org manual */
|
||||
pre.src-asymptote:before { content: 'Asymptote'; }
|
||||
pre.src-awk:before { content: 'Awk'; }
|
||||
pre.src-C:before { content: 'C'; }
|
||||
/* pre.src-C++ doesn't work in CSS */
|
||||
pre.src-clojure:before { content: 'Clojure'; }
|
||||
pre.src-css:before { content: 'CSS'; }
|
||||
pre.src-D:before { content: 'D'; }
|
||||
pre.src-ditaa:before { content: 'ditaa'; }
|
||||
pre.src-dot:before { content: 'Graphviz'; }
|
||||
pre.src-calc:before { content: 'Emacs Calc'; }
|
||||
pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
|
||||
pre.src-fortran:before { content: 'Fortran'; }
|
||||
pre.src-gnuplot:before { content: 'gnuplot'; }
|
||||
pre.src-haskell:before { content: 'Haskell'; }
|
||||
pre.src-hledger:before { content: 'hledger'; }
|
||||
pre.src-java:before { content: 'Java'; }
|
||||
pre.src-js:before { content: 'Javascript'; }
|
||||
pre.src-latex:before { content: 'LaTeX'; }
|
||||
pre.src-ledger:before { content: 'Ledger'; }
|
||||
pre.src-lisp:before { content: 'Lisp'; }
|
||||
pre.src-lilypond:before { content: 'Lilypond'; }
|
||||
pre.src-lua:before { content: 'Lua'; }
|
||||
pre.src-matlab:before { content: 'MATLAB'; }
|
||||
pre.src-mscgen:before { content: 'Mscgen'; }
|
||||
pre.src-ocaml:before { content: 'Objective Caml'; }
|
||||
pre.src-octave:before { content: 'Octave'; }
|
||||
pre.src-org:before { content: 'Org mode'; }
|
||||
pre.src-oz:before { content: 'OZ'; }
|
||||
pre.src-plantuml:before { content: 'Plantuml'; }
|
||||
pre.src-processing:before { content: 'Processing.js'; }
|
||||
pre.src-python:before { content: 'Python'; }
|
||||
pre.src-R:before { content: 'R'; }
|
||||
pre.src-ruby:before { content: 'Ruby'; }
|
||||
pre.src-sass:before { content: 'Sass'; }
|
||||
pre.src-scheme:before { content: 'Scheme'; }
|
||||
pre.src-screen:before { content: 'Gnu Screen'; }
|
||||
pre.src-sed:before { content: 'Sed'; }
|
||||
pre.src-sh:before { content: 'shell'; }
|
||||
pre.src-sql:before { content: 'SQL'; }
|
||||
pre.src-sqlite:before { content: 'SQLite'; }
|
||||
/* additional languages in org.el's org-babel-load-languages alist */
|
||||
pre.src-forth:before { content: 'Forth'; }
|
||||
pre.src-io:before { content: 'IO'; }
|
||||
pre.src-J:before { content: 'J'; }
|
||||
pre.src-makefile:before { content: 'Makefile'; }
|
||||
pre.src-maxima:before { content: 'Maxima'; }
|
||||
pre.src-perl:before { content: 'Perl'; }
|
||||
pre.src-picolisp:before { content: 'Pico Lisp'; }
|
||||
pre.src-scala:before { content: 'Scala'; }
|
||||
pre.src-shell:before { content: 'Shell Script'; }
|
||||
pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
|
||||
/* additional language identifiers per "defun org-babel-execute"
|
||||
in ob-*.el */
|
||||
pre.src-cpp:before { content: 'C++'; }
|
||||
pre.src-abc:before { content: 'ABC'; }
|
||||
pre.src-coq:before { content: 'Coq'; }
|
||||
pre.src-groovy:before { content: 'Groovy'; }
|
||||
/* additional language identifiers from org-babel-shell-names in
|
||||
ob-shell.el: ob-shell is the only babel language using a lambda to put
|
||||
the execution function name together. */
|
||||
pre.src-bash:before { content: 'bash'; }
|
||||
pre.src-csh:before { content: 'csh'; }
|
||||
pre.src-ash:before { content: 'ash'; }
|
||||
pre.src-dash:before { content: 'dash'; }
|
||||
pre.src-ksh:before { content: 'ksh'; }
|
||||
pre.src-mksh:before { content: 'mksh'; }
|
||||
pre.src-posh:before { content: 'posh'; }
|
||||
/* Additional Emacs modes also supported by the LaTeX listings package */
|
||||
pre.src-ada:before { content: 'Ada'; }
|
||||
pre.src-asm:before { content: 'Assembler'; }
|
||||
pre.src-caml:before { content: 'Caml'; }
|
||||
pre.src-delphi:before { content: 'Delphi'; }
|
||||
pre.src-html:before { content: 'HTML'; }
|
||||
pre.src-idl:before { content: 'IDL'; }
|
||||
pre.src-mercury:before { content: 'Mercury'; }
|
||||
pre.src-metapost:before { content: 'MetaPost'; }
|
||||
pre.src-modula-2:before { content: 'Modula-2'; }
|
||||
pre.src-pascal:before { content: 'Pascal'; }
|
||||
pre.src-ps:before { content: 'PostScript'; }
|
||||
pre.src-prolog:before { content: 'Prolog'; }
|
||||
pre.src-simula:before { content: 'Simula'; }
|
||||
pre.src-tcl:before { content: 'tcl'; }
|
||||
pre.src-tex:before { content: 'TeX'; }
|
||||
pre.src-plain-tex:before { content: 'Plain TeX'; }
|
||||
pre.src-verilog:before { content: 'Verilog'; }
|
||||
pre.src-vhdl:before { content: 'VHDL'; }
|
||||
pre.src-xml:before { content: 'XML'; }
|
||||
pre.src-nxml:before { content: 'XML'; }
|
||||
/* add a generic configuration mode; LaTeX export needs an additional
|
||||
(add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
|
||||
pre.src-conf:before { content: 'Configuration File'; }
|
||||
|
||||
table { border-collapse:collapse; }
|
||||
caption.t-above { caption-side: top; }
|
||||
caption.t-bottom { caption-side: bottom; }
|
||||
td, th { vertical-align:top; }
|
||||
th.org-right { text-align: center; }
|
||||
th.org-left { text-align: center; }
|
||||
th.org-center { text-align: center; }
|
||||
td.org-right { text-align: right; }
|
||||
td.org-left { text-align: left; }
|
||||
td.org-center { text-align: center; }
|
||||
dt { font-weight: bold; }
|
||||
.footpara { display: inline; }
|
||||
.footdef { margin-bottom: 1em; }
|
||||
.figure { padding: 1em; }
|
||||
.figure p { text-align: center; }
|
||||
.inlinetask {
|
||||
padding: 10px;
|
||||
border: 2px solid gray;
|
||||
margin: 10px;
|
||||
background: #ffffcc;
|
||||
}
|
||||
#org-div-home-and-up
|
||||
{ text-align: right; font-size: 70%; white-space: nowrap; }
|
||||
textarea { overflow-x: auto; }
|
||||
.linenr { font-size: smaller }
|
||||
.code-highlighted { background-color: #ffff00; }
|
||||
.org-info-js_info-navigation { border-style: none; }
|
||||
#org-info-js_console-label
|
||||
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
|
||||
.org-info-js_search-highlight
|
||||
{ background-color: #ffff00; color: #000000; font-weight: bold; }
|
||||
.org-svg { width: 90%; }
|
||||
/*]]>*/-->
|
||||
</style>
|
||||
<link rel="stylesheet" title="Standard" href="qmckl.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript" src="org-info.js">
|
||||
/**
|
||||
*
|
||||
* @source: org-info.js
|
||||
*
|
||||
* @licstart The following is the entire license notice for the
|
||||
* JavaScript code in org-info.js.
|
||||
*
|
||||
* Copyright (C) 2012-2019 Free Software Foundation, Inc.
|
||||
*
|
||||
*
|
||||
* The JavaScript code in this tag is free software: you can
|
||||
* redistribute it and/or modify it under the terms of the GNU
|
||||
* General Public License (GNU GPL) as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option)
|
||||
* any later version. The code is distributed WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
|
||||
*
|
||||
* As additional permission under GNU GPL version 3 section 7, you
|
||||
* may distribute non-source (e.g., minimized or compacted) forms of
|
||||
* that code without the copy of the GNU GPL normally required by
|
||||
* section 4, provided you include this license notice and a URL
|
||||
* through which recipients can access the Corresponding Source.
|
||||
*
|
||||
* @licend The above is the entire license notice
|
||||
* for the JavaScript code in org-info.js.
|
||||
*
|
||||
*/
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
/*
|
||||
@licstart The following is the entire license notice for the
|
||||
JavaScript code in this tag.
|
||||
|
||||
Copyright (C) 2012-2019 Free Software Foundation, Inc.
|
||||
|
||||
The JavaScript code in this tag is free software: you can
|
||||
redistribute it and/or modify it under the terms of the GNU
|
||||
General Public License (GNU GPL) as published by the Free Software
|
||||
Foundation, either version 3 of the License, or (at your option)
|
||||
any later version. The code is distributed WITHOUT ANY WARRANTY;
|
||||
without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
|
||||
|
||||
As additional permission under GNU GPL version 3 section 7, you
|
||||
may distribute non-source (e.g., minimized or compacted) forms of
|
||||
that code without the copy of the GNU GPL normally required by
|
||||
section 4, provided you include this license notice and a URL
|
||||
through which recipients can access the Corresponding Source.
|
||||
|
||||
|
||||
@licend The above is the entire license notice
|
||||
for the JavaScript code in this tag.
|
||||
*/
|
||||
|
||||
<!--/*--><![CDATA[/*><!--*/
|
||||
org_html_manager.set("TOC_DEPTH", "4");
|
||||
org_html_manager.set("LINK_HOME", "index.html");
|
||||
org_html_manager.set("LINK_UP", "");
|
||||
org_html_manager.set("LOCAL_TOC", "1");
|
||||
org_html_manager.set("VIEW_BUTTONS", "0");
|
||||
org_html_manager.set("MOUSE_HINT", "underline");
|
||||
org_html_manager.set("FIXED_TOC", "0");
|
||||
org_html_manager.set("TOC", "1");
|
||||
org_html_manager.set("VIEW", "info");
|
||||
org_html_manager.setup(); // activate after the parameters are set
|
||||
/*]]>*///-->
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
/*
|
||||
@licstart The following is the entire license notice for the
|
||||
JavaScript code in this tag.
|
||||
|
||||
Copyright (C) 2012-2019 Free Software Foundation, Inc.
|
||||
|
||||
The JavaScript code in this tag is free software: you can
|
||||
redistribute it and/or modify it under the terms of the GNU
|
||||
General Public License (GNU GPL) as published by the Free Software
|
||||
Foundation, either version 3 of the License, or (at your option)
|
||||
any later version. The code is distributed WITHOUT ANY WARRANTY;
|
||||
without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
|
||||
|
||||
As additional permission under GNU GPL version 3 section 7, you
|
||||
may distribute non-source (e.g., minimized or compacted) forms of
|
||||
that code without the copy of the GNU GPL normally required by
|
||||
section 4, provided you include this license notice and a URL
|
||||
through which recipients can access the Corresponding Source.
|
||||
|
||||
|
||||
@licend The above is the entire license notice
|
||||
for the JavaScript code in this tag.
|
||||
*/
|
||||
<!--/*--><![CDATA[/*><!--*/
|
||||
function CodeHighlightOn(elem, id)
|
||||
{
|
||||
var target = document.getElementById(id);
|
||||
if(null != target) {
|
||||
elem.cacheClassElem = elem.className;
|
||||
elem.cacheClassTarget = target.className;
|
||||
target.className = "code-highlighted";
|
||||
elem.className = "code-highlighted";
|
||||
}
|
||||
}
|
||||
function CodeHighlightOff(elem, id)
|
||||
{
|
||||
var target = document.getElementById(id);
|
||||
if(elem.cacheClassElem)
|
||||
elem.className = elem.cacheClassElem;
|
||||
if(elem.cacheClassTarget)
|
||||
target.className = elem.cacheClassTarget;
|
||||
}
|
||||
/*]]>*///-->
|
||||
</script>
|
||||
<script type="text/x-mathjax-config">
|
||||
MathJax.Hub.Config({
|
||||
displayAlign: "center",
|
||||
displayIndent: "0em",
|
||||
|
||||
"HTML-CSS": { scale: 100,
|
||||
linebreaks: { automatic: "false" },
|
||||
webFont: "TeX"
|
||||
},
|
||||
SVG: {scale: 100,
|
||||
linebreaks: { automatic: "false" },
|
||||
font: "TeX"},
|
||||
NativeMML: {scale: 100},
|
||||
TeX: { equationNumbers: {autoNumber: "AMS"},
|
||||
MultLineWidth: "85%",
|
||||
TagSide: "right",
|
||||
TagIndent: ".8em"
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<script type="text/javascript"
|
||||
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="org-div-home-and-up">
|
||||
<a accesskey="h" href=""> UP </a>
|
||||
|
|
||||
<a accesskey="H" href="index.html"> HOME </a>
|
||||
</div><div id="content">
|
||||
<h1 class="title">Numerical precision</h1>
|
||||
<div id="table-of-contents">
|
||||
<h2>Table of Contents</h2>
|
||||
<div id="text-table-of-contents">
|
||||
<ul>
|
||||
<li><a href="#org648ec29">1. Control of the numerical precision</a></li>
|
||||
<li><a href="#org278a6b5">2. Precision</a></li>
|
||||
<li><a href="#orgade5a74">3. Range</a></li>
|
||||
<li><a href="#orgb04ac39">4. Helper functions</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org648ec29" class="outline-2">
|
||||
<h2 id="org648ec29"><span class="section-number-2">1</span> Control of the numerical precision</h2>
|
||||
<div class="outline-text-2" id="text-1">
|
||||
<p>
|
||||
Controlling numerical precision enables optimizations. Here, the
|
||||
default parameters determining the target numerical precision and
|
||||
range are defined. Following the IEEE Standard for Floating-Point
|
||||
Arithmetic (IEEE 754),
|
||||
<i>precision</i> refers to the number of significand bits and <i>range</i>
|
||||
refers to the number of exponent bits.
|
||||
</p>
|
||||
|
||||
<table id="org92a550e" border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
|
||||
|
||||
|
||||
<colgroup>
|
||||
<col class="org-left" />
|
||||
|
||||
<col class="org-right" />
|
||||
</colgroup>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="org-left"><code>QMCKL_DEFAULT_PRECISION</code></td>
|
||||
<td class="org-right">53</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="org-left"><code>QMCKL_DEFAULT_RANGE</code></td>
|
||||
<td class="org-right">11</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-c"><span style="color: #a020f0;">typedef</span> <span style="color: #a020f0;">struct</span> <span style="color: #228b22;">qmckl_numprec_struct</span> {
|
||||
<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">precision</span>;
|
||||
<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">range</span>;
|
||||
} <span style="color: #228b22;">qmckl_numprec_struct</span>;
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
The following functions set and get the required precision and
|
||||
range. <code>precision</code> is an integer between 2 and 53, and <code>range</code> is an
|
||||
integer between 2 and 11.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The setter functions functions return a new context as a 64-bit
|
||||
integer. The getter functions return the value, as a 32-bit
|
||||
integer. The update functions return <code>QMCKL_SUCCESS</code> or
|
||||
<code>QMCKL_FAILURE</code>.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org278a6b5" class="outline-2">
|
||||
<h2 id="org278a6b5"><span class="section-number-2">2</span> Precision</h2>
|
||||
<div class="outline-text-2" id="text-2">
|
||||
<p>
|
||||
<code>qmckl_context_set_numprec_precision</code> modifies the parameter for the
|
||||
numerical precision in the context.
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-c"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_set_numprec_precision</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int</span> <span style="color: #a0522d;">precision</span>) {
|
||||
|
||||
<span style="color: #a020f0;">if</span> (qmckl_context_check(context) == QMCKL_NULL_CONTEXT)
|
||||
<span style="color: #a020f0;">return</span> QMCKL_INVALID_CONTEXT;
|
||||
|
||||
<span style="color: #a020f0;">if</span> (precision < 2) {
|
||||
<span style="color: #a020f0;">return</span> qmckl_failwith(context,
|
||||
QMCKL_INVALID_ARG_2,
|
||||
<span style="color: #8b2252;">"qmckl_update_numprec_precision"</span>,
|
||||
<span style="color: #8b2252;">"precision < 2"</span>);
|
||||
}
|
||||
|
||||
<span style="color: #a020f0;">if</span> (precision > 53) {
|
||||
<span style="color: #a020f0;">return</span> qmckl_failwith(context,
|
||||
QMCKL_INVALID_ARG_2,
|
||||
<span style="color: #8b2252;">"qmckl_update_numprec_precision"</span>,
|
||||
<span style="color: #8b2252;">"precision > 53"</span>);
|
||||
}
|
||||
|
||||
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a020f0;">const</span>) context;
|
||||
|
||||
/* <span style="color: #b22222;">This should be always true because the context is valid </span>*/
|
||||
assert (ctx != <span style="color: #008b8b;">NULL</span>);
|
||||
|
||||
qmckl_lock(context);
|
||||
{
|
||||
ctx->numprec.precision = (<span style="color: #228b22;">uint32_t</span>) precision;
|
||||
}
|
||||
qmckl_unlock(context);
|
||||
|
||||
<span style="color: #a020f0;">return</span> QMCKL_SUCCESS;
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
||||
<span style="color: #228b22;">integer</span> (qmckl_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_set_numprec_precision</span>(context, precision) <span style="color: #a020f0;">bind</span>(C)
|
||||
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
|
||||
<span style="color: #a020f0;">import</span>
|
||||
<span style="color: #228b22;">integer</span> (qmckl_context), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> context</span>
|
||||
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> precision</span>
|
||||
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_set_numprec_precision</span>
|
||||
<span style="color: #a020f0;">end interface</span>
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<code>qmckl_get_numprec_precision</code> returns the value of the numerical precision in the context.
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-c"><span style="color: #228b22;">int</span> <span style="color: #0000ff;">qmckl_get_numprec_precision</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>) {
|
||||
<span style="color: #a020f0;">if</span> (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
|
||||
<span style="color: #a020f0;">return</span> qmckl_failwith(context,
|
||||
QMCKL_INVALID_CONTEXT,
|
||||
<span style="color: #8b2252;">"qmckl_get_numprec_precision"</span>,
|
||||
<span style="color: #8b2252;">""</span>);
|
||||
}
|
||||
|
||||
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a020f0;">const</span>) context;
|
||||
<span style="color: #a020f0;">return</span> ctx->numprec.precision;
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
||||
<span style="color: #228b22;">integer</span> (qmckl_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_get_numprec_precision</span>(context) <span style="color: #a020f0;">bind</span>(C)
|
||||
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
|
||||
<span style="color: #a020f0;">import</span>
|
||||
<span style="color: #228b22;">integer</span> (qmckl_context), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> context</span>
|
||||
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_get_numprec_precision</span>
|
||||
<span style="color: #a020f0;">end interface</span>
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-orgade5a74" class="outline-2">
|
||||
<h2 id="orgade5a74"><span class="section-number-2">3</span> Range</h2>
|
||||
<div class="outline-text-2" id="text-3">
|
||||
<p>
|
||||
<code>qmckl_set_numprec_range</code> modifies the parameter for the numerical
|
||||
range in a given context.
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-c"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_set_numprec_range</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int</span> <span style="color: #a0522d;">range</span>) {
|
||||
|
||||
<span style="color: #a020f0;">if</span> (qmckl_context_check(context) == QMCKL_NULL_CONTEXT)
|
||||
<span style="color: #a020f0;">return</span> QMCKL_INVALID_CONTEXT;
|
||||
|
||||
<span style="color: #a020f0;">if</span> (range < 2) {
|
||||
<span style="color: #a020f0;">return</span> qmckl_failwith(context,
|
||||
QMCKL_INVALID_ARG_2,
|
||||
<span style="color: #8b2252;">"qmckl_set_numprec_range"</span>,
|
||||
<span style="color: #8b2252;">"range < 2"</span>);
|
||||
}
|
||||
|
||||
<span style="color: #a020f0;">if</span> (range > 11) {
|
||||
<span style="color: #a020f0;">return</span> qmckl_failwith(context,
|
||||
QMCKL_INVALID_ARG_2,
|
||||
<span style="color: #8b2252;">"qmckl_set_numprec_range"</span>,
|
||||
<span style="color: #8b2252;">"range > 11"</span>);
|
||||
}
|
||||
|
||||
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a020f0;">const</span>) context;
|
||||
|
||||
/* <span style="color: #b22222;">This should be always true because the context is valid </span>*/
|
||||
assert (ctx != <span style="color: #008b8b;">NULL</span>);
|
||||
|
||||
qmckl_lock(context);
|
||||
{
|
||||
ctx->numprec.range = (<span style="color: #228b22;">uint32_t</span>) range;
|
||||
}
|
||||
qmckl_unlock(context);
|
||||
|
||||
<span style="color: #a020f0;">return</span> QMCKL_SUCCESS;
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
||||
<span style="color: #228b22;">integer</span> (qmckl_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_numprec_set_range</span>(context, range) <span style="color: #a020f0;">bind</span>(C)
|
||||
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
|
||||
<span style="color: #a020f0;">import</span>
|
||||
<span style="color: #228b22;">integer</span> (qmckl_context), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> context</span>
|
||||
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> range</span>
|
||||
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_numprec_set_range</span>
|
||||
<span style="color: #a020f0;">end interface</span>
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<code>qmckl_get_numprec_range</code> returns the value of the numerical range in the context.
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-c"><span style="color: #228b22;">int</span> <span style="color: #0000ff;">qmckl_get_numprec_range</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>) {
|
||||
<span style="color: #a020f0;">if</span> (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
|
||||
<span style="color: #a020f0;">return</span> qmckl_failwith(context,
|
||||
QMCKL_INVALID_CONTEXT,
|
||||
<span style="color: #8b2252;">"qmckl_get_numprec_range"</span>,
|
||||
<span style="color: #8b2252;">""</span>);
|
||||
}
|
||||
|
||||
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a020f0;">const</span>) context;
|
||||
<span style="color: #a020f0;">return</span> ctx->numprec.range;
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="outline-container-orgb04ac39" class="outline-2">
|
||||
<h2 id="orgb04ac39"><span class="section-number-2">4</span> Helper functions</h2>
|
||||
<div class="outline-text-2" id="text-4">
|
||||
<p>
|
||||
<code>qmckl_get_numprec_epsilon</code> returns \(\epsilon = 2^{1-n}\) where <code>n</code> is the precision.
|
||||
We need to remove the sign bit from the precision.
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-c"><span style="color: #228b22;">double</span> <span style="color: #0000ff;">qmckl_get_numprec_epsilon</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>) {
|
||||
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int</span> <span style="color: #a0522d;">precision</span> = qmckl_get_numprec_precision(context);
|
||||
<span style="color: #a020f0;">return</span> 1. / (<span style="color: #228b22;">double</span>) (1L << (precision-2));
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="postamble" class="status">
|
||||
<p class="author">Author: TREX CoE</p>
|
||||
<p class="date">Created: 2021-04-20 Tue 22:01</p>
|
||||
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -3,7 +3,7 @@
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<!-- 2021-03-28 Sun 23:40 -->
|
||||
<!-- 2021-04-20 Tue 22:01 -->
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Testing</title>
|
||||
@ -311,7 +311,7 @@ for the JavaScript code in this tag.
|
||||
</div>
|
||||
<div id="postamble" class="status">
|
||||
<p class="author">Author: TREX CoE</p>
|
||||
<p class="date">Created: 2021-03-28 Sun 23:40</p>
|
||||
<p class="date">Created: 2021-04-20 Tue 22:01</p>
|
||||
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
||||
</div>
|
||||
</body>
|
||||
|
@ -13,3 +13,4 @@
|
||||
#+LANGUAGE: en
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user