1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2025-01-08 20:33:40 +01:00
qmckl/index.html

3232 lines
158 KiB
HTML
Raw Normal View History

<?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-03-06 Sat 22:28 -->
<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>
<meta name="generator" content="Org mode" />
<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" type="text/css" href="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/css/htmlize.css"/>
<link rel="stylesheet" type="text/css" href="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/css/readtheorg.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://fniessen.github.io/org-html-themes/src/lib/js/jquery.stickytableheaders.min.js"></script>
<script type="text/javascript" src="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/js/readtheorg.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[/*><!--*/
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="content">
<h1 class="title">QMCkl source code documentation</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#org1220f5c">1. Introduction</a>
<ul>
<li><a href="#orgd8f99ad">1.1. Literate programming</a></li>
<li><a href="#orgb6996e6">1.2. Source code editing</a></li>
<li><a href="#orgf7cafd5">1.3. Choice of the programming language</a></li>
<li><a href="#orgb6f3588">1.4. Design of the library</a>
<ul>
<li><a href="#org7054d10">1.4.1. Naming conventions</a></li>
<li><a href="#org104f21f">1.4.2. Application programming interface</a></li>
<li><a href="#org4004222">1.4.3. Global state</a></li>
<li><a href="#org9d92bb1">1.4.4. Low-level functions</a></li>
<li><a href="#org1b07e02">1.4.5. High-level functions</a></li>
<li><a href="#orgca95c6b">1.4.6. Numerical precision</a></li>
</ul>
</li>
<li><a href="#org9543279">1.5. Algorithms</a></li>
<li><a href="#orgca6c05b">1.6. Rules for the API</a></li>
</ul>
</li>
<li><a href="#orgdbda631">2. Documentation</a>
<ul>
<li><a href="#org1302996">2.1. <code>qmckl.h</code> header file</a></li>
<li><a href="#org4ac8299">2.2. Context</a>
<ul>
<li><a href="#org2372e23">2.2.1. Context</a></li>
</ul>
</li>
<li><a href="#org5976dad">2.3. Error handling</a>
<ul>
<li><a href="#orgdfb3ddb">2.3.1. Error handling</a></li>
<li><a href="#orga418328">2.3.2. Multi-precision related constants</a></li>
</ul>
</li>
<li><a href="#org651e7fe">2.4. Memory management</a>
<ul>
<li><a href="#org18712b6">2.4.1. <code>qmckl_malloc</code></a></li>
<li><a href="#org603dfce">2.4.2. <code>qmckl_free</code></a></li>
</ul>
</li>
<li><a href="#orged2a041">2.5. Computation of distances</a>
<ul>
<li><a href="#org8e03b4f">2.5.1. Squared distance</a></li>
</ul>
</li>
<li><a href="#org4b10b43">2.6. Atomic Orbitals</a>
<ul>
<li><a href="#org4cd630b">2.6.1. Polynomials</a></li>
<li><a href="#orgf9b8419">2.6.2. Gaussian basis functions</a></li>
<li><a href="#org930fc7a">2.6.3. <span class="todo TODO">TODO</span> Slater basis functions</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#org9472ec5">3. Acknowledgments</a></li>
</ul>
</div>
</div>
<div id="outline-container-org1220f5c" class="outline-2">
<h2 id="org1220f5c"><span class="section-number-2">1</span> Introduction</h2>
<div class="outline-text-2" id="text-1">
<p>
The ultimate goal of the QMCkl library is to provide a high-performance
implementation of the main kernels of QMC. In this particular
implementation of the library, we focus on the definition of the API and the tests, and
on a <i>pedagogical</i> presentation of the algorithms. We expect the
HPC experts to use this repository as a reference for re-writing
optimized libraries.
</p>
</div>
<div id="outline-container-orgd8f99ad" class="outline-3">
<h3 id="orgd8f99ad"><span class="section-number-3">1.1</span> Literate programming</h3>
<div class="outline-text-3" id="text-1-1">
<p>
In a traditional source code, most of the lines of source files of a program
are code, scripts, Makefiles, and only a few lines are comments explaining
parts of the code that are non-trivial to understand. The documentation of
the prorgam is usually written in a separate directory, and is often outdated
compared to the code.
</p>
<p>
Literate programming is a different approach to programming,
where the program is considered as a publishable-quality document. Most of
the lines of the source files are text, mathematical formulas, tables,
figures, <i>etc</i>, and the lines of code are just the translation in a computer
language of the ideas and algorithms expressed in the text. More importantly,
the "document" is structured like a text document with sections, subsections,
a bibliography, a table of contents <i>etc</i>, and the place where pieces of code
appear are the places where they should belong for the reader to understand
the logic of the program, not the places where the compiler expects to find
them. Both the publishable-quality document and the binary executable are
produced from the same source files.
</p>
<p>
Literate programming is particularly well adapted in this <a href="#org79dde7e">context</a>, as the
central part of this project is the documentation of an API. The
implementation of the algorithms is just an expression of the algorithms in a
language that can be compiled, so that the correctness of the algorithms can
be tested.
</p>
<p>
We have chosen to write the source files in <a href="https://karl-voit.at/2017/09/23/orgmode-as-markup-only/">org-mode</a> format,
as any text editor can be used to edit org-mode files. To
produce the documentation, there exists multiple possibilities to convert
org-mode files into different formats such as HTML or PDF. The source code is
easily extracted from the org-mode files invoking the Emacs text editor from
the command-line in the <code>Makefile</code>, and then the produced files are compiled.
Moreover, within the Emacs text editor the source code blocks can be executed
interactively, in the same spirit as Jupyter notebooks.
</p>
</div>
</div>
<div id="outline-container-orgb6996e6" class="outline-3">
<h3 id="orgb6996e6"><span class="section-number-3">1.2</span> Source code editing</h3>
<div class="outline-text-3" id="text-1-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>.
</p>
<p>
Any text editor can be used to edit org-mode files. For a better
user experience Emacs is recommended. For users hating Emacs, it
is good to know that Emacs can behave like Vim when switched into
``Evil'' mode.
</p>
<p>
In the <code>tools/init.el</code> file, we provide a minimal Emacs configuration
file for vim users. This file should be copied into <code>.emacs.d/init.el</code>.
</p>
<p>
For users with a preference for Jupyter notebooks, we also provide the
<code>tools/nb_to_org.sh</code> script can convert jupyter notebooks into org-mode
files.
</p>
<p>
Note that pandoc can be used to convert multiple markdown formats into
org-mode.
</p>
</div>
</div>
<div id="outline-container-orgf7cafd5" class="outline-3">
<h3 id="orgf7cafd5"><span class="section-number-3">1.3</span> Choice of the programming language</h3>
<div class="outline-text-3" id="text-1-3">
<p>
Most of the codes of the TREX CoE are written in <a href="#org3c7e28c">Fortran</a> with some scripts in
Bash and Python. Outside of the CoE, <a href="#org3c7e28c">Fortran</a> is also important (Casino, Amolqc),
and other important languages used by the community are <a href="#org1ac3923">C</a> and <a href="#org1ac3923">C</a>++ (QMCPack,
QWalk), and Julia is gaining in popularity. The library we design should be
compatible with all of these languages. The QMCkl API has to be compatible
with the <a href="#org1ac3923">C</a> language since libraries with a <a href="#org1ac3923">C</a>-compatible API can be used in
every other language.
</p>
<p>
High-performance versions of the QMCkl, with the same API, will be rewritten by
the experts in HPC. These optimized libraries will be tuned for specific
architectures, among which we can cite x86 based processors, and GPU
accelerators. Nowadays, the most efficient software tools to take advantage of
low-level features of the processor (intrinsics) and of GPUs are for <a href="#org1ac3923">C</a>++
developers. It is highly probable that the optimized implementations will be
written in <a href="#org1ac3923">C</a>++, and this is agreement with our choice to make the API
<a href="#org1ac3923">C</a>-compatible.
</p>
<p>
<a href="#org3c7e28c">Fortran</a> is one of the most common languages used by the community, and is simple
enough to make the algorithms readable both by experts in QMC, and experts in
HPC. Hence we propose in this pedagogical implementation of QMCkl to use <a href="#org3c7e28c">Fortran</a>
to express the QMC algorithms. As the main languages of the library is <a href="#org1ac3923">C</a>, this
implies that the exposed <a href="#org1ac3923">C</a> functions call the <a href="#org3c7e28c">Fortran</a> routine. However, for
internal functions related to system programming, the <a href="#org1ac3923">C</a> language is more natural
than <a href="#org3c7e28c">Fortran</a>.
</p>
<p>
The <a href="#org3c7e28c">Fortran</a> source files should provide a <a href="#org1ac3923">C</a> interface using the
<code>iso_c_binding</code> module. The name of the <a href="#org3c7e28c">Fortran</a> 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 <a href="#org3c7e28c">Fortran</a> should be the same as those exposed in the API suffixed by
<code>_f</code>. <a href="#org3c7e28c">Fortran</a> interfaces should also be written in the <code>qmckl_f.f90</code> file.
</p>
<p>
For more guidelines on using <a href="#org3c7e28c">Fortran</a> to generate a <a href="#org1ac3923">C</a> interface, see
<a href="http://fortranwiki.org/fortran/show/Generating+C+Interfaces">this link</a>.
</p>
</div>
</div>
<div id="outline-container-orgb6f3588" class="outline-3">
<h3 id="orgb6f3588"><span class="section-number-3">1.4</span> Design of the library</h3>
<div class="outline-text-3" id="text-1-4">
<p>
The proposed API should allow the library to: deal with memory transfers
between CPU and accelerators, and to use different levels of floating-point
precision. We chose a multi-layered design with low-level and high-level
functions (see below).
</p>
</div>
<div id="outline-container-org7054d10" class="outline-4">
<h4 id="org7054d10"><span class="section-number-4">1.4.1</span> Naming conventions</h4>
<div class="outline-text-4" id="text-1-4-1">
<p>
To avoid namespace collisions, we use <code>qmckl_</code> as a prefix for all exported
functions and variables. All exported header files should have a file name
prefixed with <code>qmckl_</code>.
</p>
<p>
If the name of the org-mode file is <code>xxx.org</code>, the name of the
produced <a href="#org1ac3923">C</a> files should be <code>xxx.c</code> and <code>xxx.h</code> and the name of the
produced <a href="#org3c7e28c">Fortran</a> file should be <code>xxx.f90</code>.
</p>
<p>
Arrays are in uppercase and scalars are in lowercase.
</p>
<p>
In the names of the variables and functions, only the singular
form is allowed.
</p>
</div>
</div>
<div id="outline-container-org104f21f" class="outline-4">
<h4 id="org104f21f"><span class="section-number-4">1.4.2</span> Application programming interface</h4>
<div class="outline-text-4" id="text-1-4-2">
<p>
In the <a href="#org1ac3923">C</a> language, the number of bits used by the integer types can change
from one architecture to another one. To circumvent this problem, we choose to
use the integer types defined in <code>&lt;stdint.h&gt;</code> where the number of bits used for
the integers are fixed.
</p>
<p>
To ensure that the library will be easily usable in <i>any</i> other language
than <a href="#org1ac3923">C</a>, we restrict the data types in the interfaces to the following:
</p>
<ul class="org-ul">
<li>32-bit and 64-bit integers, scalars and and arrays (<code>int32_t</code> and <code>int64_t</code>)</li>
<li>32-bit and 64-bit floats, scalars and and arrays (<code>float</code> and <code>double</code>)</li>
<li>Pointers are always casted into 64-bit integers, even on legacy 32-bit architectures</li>
<li>ASCII strings are represented as a pointers to character arrays
and terminated by a <code>'\0'</code> character (<a href="#org1ac3923">C</a> 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>integers used for counting should always be <code>int64_t</code></li>
</ul>
<p>
To facilitate the use in other languages than <a href="#org1ac3923">C</a>, we will provide some
bindings in other languages in other repositories.
</p>
</div>
</div>
<div id="outline-container-org4004222" class="outline-4">
<h4 id="org4004222"><span class="section-number-4">1.4.3</span> Global state</h4>
<div class="outline-text-4" id="text-1-4-3">
<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 <code>context</code> variable, built by the library with the
<code>qmckl_context_create</code> function. The <code>context</code> contains the global
state of the library, and is used as the first argument of many
QMCkl functions.
</p>
<p>
The internal structure of the <a href="#org79dde7e">context</a> 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 <a href="#org79dde7e">context</a>
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 <a href="#org79dde7e">context</a> and its old
versions can be destroyed with <code>qmckl_context_destroy</code>.
</p>
</div>
</div>
<div id="outline-container-org9d92bb1" class="outline-4">
<h4 id="org9d92bb1"><span class="section-number-4">1.4.4</span> Low-level functions</h4>
<div class="outline-text-4" id="text-1-4-4">
<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
<code>context</code>. 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-org1b07e02" class="outline-4">
<h4 id="org1b07e02"><span class="section-number-4">1.4.5</span> High-level functions</h4>
<div class="outline-text-4" id="text-1-4-5">
<p>
High-level functions are at the top of the function call tree.
They are able to choose which lower-level function to call
depending on the required precision, and do the corresponding type
conversions. These functions are also responsible for allocating
temporary storage, to simplify the use of accelerators.
</p>
<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 <code>context</code> variable.
</p>
</div>
</div>
<div id="outline-container-orgca95c6b" class="outline-4">
<h4 id="orgca95c6b"><span class="section-number-4">1.4.6</span> Numerical precision</h4>
<div class="outline-text-4" id="text-1-4-6">
<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 <code>context</code>
variable.
</p>
</div>
</div>
</div>
<div id="outline-container-org9543279" class="outline-3">
<h3 id="org9543279"><span class="section-number-3">1.5</span> Algorithms</h3>
<div class="outline-text-3" id="text-1-5">
<p>
Reducing the scaling of an algorithm usually implies also reducing
its arithmetic complexity (number of flops per byte). Therefore,
for small sizes \(\mathcal{O}(N^3)\) and \(\mathcal{O}(N^2)\)
algorithms are better adapted than linear scaling algorithms. As
QMCkl is a general purpose library, multiple algorithms should be
implemented adapted to different problem sizes.
</p>
</div>
</div>
<div id="outline-container-orgca6c05b" class="outline-3">
<h3 id="orgca6c05b"><span class="section-number-3">1.6</span> Rules for the API</h3>
<div class="outline-text-3" id="text-1-6">
<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 id="outline-container-orgdbda631" class="outline-2">
<h2 id="orgdbda631"><span class="section-number-2">2</span> Documentation</h2>
<div class="outline-text-2" id="text-2">
</div>
<div id="outline-container-org1302996" class="outline-3">
<h3 id="org1302996"><span class="section-number-3">2.1</span> <code>qmckl.h</code> header file</h3>
<div class="outline-text-3" id="text-2-1">
<p>
The <code>qmckl.h</code> header file has to be included in <a id="org1ac3923">C</a> codes when
QMCkl functions are used:
#+BEGIN<sub>SRC</sub> <a href="#org1ac3923">C</a> :tangle none
#include "qmckl.h"
#+END<sub>SRC</sub> f90
</p>
<p>
In <a id="org3c7e28c">Fortran</a> programs, the <code>qmckl_f.f90</code> interface file should be
included in the source code using the library, and the <a href="#org3c7e28c">Fortran</a> codes
should use the <code>qmckl</code> module as
#+BEGIN<sub>SRC</sub> f90 :tangle none
use qmckl
#+END<sub>SRC</sub> f90
</p>
</div>
</div>
<div id="outline-container-org4ac8299" class="outline-3">
<h3 id="org4ac8299"><span class="section-number-3">2.2</span> <a href="#org79dde7e">Context</a></h3>
<div class="outline-text-3" id="text-2-2">
<p>
This file is written in <a href="#org1ac3923">C</a> because it is more natural to express the
<a href="#org79dde7e">context</a> in <a href="#org1ac3923">C</a> than in <a href="#org3c7e28c">Fortran</a>.
</p>
<p>
2 files are produced:
</p>
<ul class="org-ul">
<li>a source file : <code>qmckl_context.c</code></li>
<li>a test file : <code>test_qmckl_context.c</code></li>
</ul>
</div>
<div id="outline-container-org2372e23" class="outline-4">
<h4 id="org2372e23"><span class="section-number-4">2.2.1</span> <a href="#org79dde7e">Context</a></h4>
<div class="outline-text-4" id="text-2-2-1">
<p>
The <a id="org79dde7e">context</a> variable is a handle for the state of the library, and
is stored in the following data structure, which can't be seen
outside of the library. To simplify compatibility with other
languages, the pointer to the internal data structure is converted
into a 64-bit signed integer, defined in the <code>qmckl_context</code> type.
A value of <code>0</code> for the <a href="#org79dde7e">context</a> is equivalent to a <code>NULL</code> pointer.
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #a020f0;">typedef</span> <span style="color: #228b22;">int64_t</span> <span style="color: #228b22;">qmckl_context</span> ;
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="orga497c02"></a>Data for error handling<br />
<div class="outline-text-5" id="text-2-2-1-1">
<p>
We define here the the data structure containing the strings
necessary for error handling.
</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>
</li>
<li><a id="org00ceddb"></a>Basis set data structure<br />
<div class="outline-text-5" id="text-2-2-1-2">
<p>
Data structure for the info related to the atomic orbitals
basis set.
</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_ao_basis_struct</span> {
<span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">shell_num</span>;
<span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">prim_num</span>;
<span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">shell_center</span>;
<span style="color: #228b22;">int32_t</span> * <span style="color: #a0522d;">shell_ang_mom</span>;
<span style="color: #228b22;">double</span> * <span style="color: #a0522d;">shell_factor</span>;
<span style="color: #228b22;">double</span> * <span style="color: #a0522d;">exponent</span> ;
<span style="color: #228b22;">double</span> * <span style="color: #a0522d;">coefficient</span> ;
<span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">shell_prim_num</span>;
<span style="color: #228b22;">char</span> <span style="color: #a0522d;">type</span>;
} <span style="color: #228b22;">qmckl_ao_basis_struct</span>;
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="org18fd9b9"></a>Source<br />
<div class="outline-text-6" id="text-2-2-1-2-1">
<p>
The tag is used internally to check if the memory domain pointed
by a pointer is a valid <a href="#org79dde7e">context</a>.
</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_context_struct</span> {
<span style="color: #a020f0;">struct</span> <span style="color: #228b22;">qmckl_context_struct</span> * <span style="color: #a0522d;">prev</span>;
/* <span style="color: #b22222;">Molecular system </span>*/
// <span style="color: #b22222;">struct qmckl_nucleus_struct * nucleus;</span>
// <span style="color: #b22222;">struct qmckl_electron_struct * electron;</span>
<span style="color: #a020f0;">struct</span> <span style="color: #228b22;">qmckl_ao_basis_struct</span> * <span style="color: #a0522d;">ao_basis</span>;
// <span style="color: #b22222;">struct qmckl_mo_struct * mo;</span>
// <span style="color: #b22222;">struct qmckl_determinant_struct * det;</span>
/* <span style="color: #b22222;">Numerical precision </span>*/
<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">tag</span>;
<span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">precision</span>;
<span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">range</span>;
/* <span style="color: #b22222;">Error handling </span>*/
<span style="color: #a020f0;">struct</span> <span style="color: #228b22;">qmckl_error_struct</span> * <span style="color: #a0522d;">error</span>;
} <span style="color: #228b22;">qmckl_context_struct</span>;
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">VALID_TAG</span> 0xBEEFFACE
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">INVALID_TAG</span> 0xDEADBEEF
</pre>
</div>
</div>
</li>
</ol>
</li>
<li><a id="orgc29255b"></a><code>qmckl_context_update_error</code><br />
<div class="outline-text-5" id="text-2-2-1-3">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span>
<span style="color: #0000ff;">qmckl_context_update_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</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span>* <span style="color: #a0522d;">message</span>);
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="org38988fd"></a>Source<br />
<div class="outline-text-6" id="text-2-2-1-3-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span>
<span style="color: #0000ff;">qmckl_context_update_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</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span>* <span style="color: #a0522d;">message</span>)
{
assert (context != 0);
assert (function != <span style="color: #008b8b;">NULL</span>);
assert (message != <span style="color: #008b8b;">NULL</span>);
assert (exit_code &gt; 0);
assert (exit_code &lt; QMCKL_INVALID_EXIT_CODE);
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
<span style="color: #a020f0;">if</span> (ctx == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">if</span> (ctx-&gt;error != <span style="color: #008b8b;">NULL</span>) {
free(ctx-&gt;error);
ctx-&gt;error = <span style="color: #008b8b;">NULL</span>;
}
<span style="color: #228b22;">qmckl_error_struct</span>* <span style="color: #a0522d;">error</span> = (<span style="color: #228b22;">qmckl_error_struct</span>*) <span style="color: #0000ff;">qmckl_malloc</span> (context, <span style="color: #a020f0;">sizeof</span>(<span style="color: #228b22;">qmckl_error_struct</span>));
error-&gt;exit_code = exit_code;
strcpy(error-&gt;function, function);
strcpy(error-&gt;message, message);
ctx-&gt;error = error;
<span style="color: #a020f0;">return</span> QMCKL_SUCCESS;
}
</pre>
</div>
</div>
</li>
<li><a id="org8c68b7c"></a><span class="todo TODO">TODO</span> Test<br /></li>
</ol>
</li>
<li><a id="orgefc1d3c"></a><code>qmckl_context_set_error</code><br />
<div class="outline-text-5" id="text-2-2-1-4">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span>
<span style="color: #0000ff;">qmckl_context_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</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span>* <span style="color: #a0522d;">message</span>);
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="orgdb64580"></a>Source<br />
<div class="outline-text-6" id="text-2-2-1-4-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span>
<span style="color: #0000ff;">qmckl_context_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</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span>* <span style="color: #a0522d;">message</span>)
{
assert (context != 0);
assert (function != <span style="color: #008b8b;">NULL</span>);
assert (message != <span style="color: #008b8b;">NULL</span>);
assert (exit_code &gt; 0);
assert (exit_code &lt; QMCKL_INVALID_EXIT_CODE);
<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">new_context</span> = qmckl_context_copy(context);
<span style="color: #a020f0;">if</span> (new_context == 0) <span style="color: #a020f0;">return</span> context;
<span style="color: #a020f0;">if</span> (qmckl_context_update_error(new_context, exit_code,
function, message) != QMCKL_SUCCESS) {
<span style="color: #a020f0;">return</span> context;
}
<span style="color: #a020f0;">return</span> new_context;
}
</pre>
</div>
</div>
</li>
<li><a id="orgbc63d2f"></a><span class="todo TODO">TODO</span> Test<br /></li>
</ol>
</li>
<li><a id="org72b6555"></a><code>qmckl_context_check</code><br />
<div class="outline-text-5" id="text-2-2-1-5">
<p>
Checks if the domain pointed by the pointer is a valid <a href="#org79dde7e">context</a>.
Returns the input <code>qmckl_context</code> if the <a href="#org79dde7e">context</a> is valid, 0
otherwise.
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_check</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>) ;
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="org2ec1a3a"></a>Source<br />
<div class="outline-text-6" id="text-2-2-1-5-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_check</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> (context == (<span style="color: #228b22;">qmckl_context</span>) 0) <span style="color: #a020f0;">return</span> (<span style="color: #228b22;">qmckl_context</span>) 0;
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context_struct</span> * <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
<span style="color: #a020f0;">if</span> (ctx-&gt;tag != VALID_TAG) <span style="color: #a020f0;">return</span> (<span style="color: #228b22;">qmckl_context</span>) 0;
<span style="color: #a020f0;">return</span> context;
}
</pre>
</div>
</div>
</li>
</ol>
</li>
<li><a id="orgfed2fb4"></a><code>qmckl_context_create</code><br />
<div class="outline-text-5" id="text-2-2-1-6">
<p>
To create a new <a href="#org79dde7e">context</a>, use <code>qmckl_context_create()</code>.
</p>
<ul class="org-ul">
<li>On success, returns a pointer to a <a href="#org79dde7e">context</a> using the <code>qmckl_context</code> type</li>
<li><p>
Returns <code>0</code> upon failure to allocate the internal data structure
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_create</span>();
</pre>
</div></li>
</ul>
</div>
<ol class="org-ol">
<li><a id="org83e83c5"></a>Source<br />
<div class="outline-text-6" id="text-2-2-1-6-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_create</span>() {
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">context</span> =
(<span style="color: #228b22;">qmckl_context_struct</span>*) qmckl_malloc ((<span style="color: #228b22;">qmckl_context</span>) 0, <span style="color: #a020f0;">sizeof</span>(qmckl_context_struct));
<span style="color: #a020f0;">if</span> (context == <span style="color: #008b8b;">NULL</span>) {
<span style="color: #a020f0;">return</span> (<span style="color: #228b22;">qmckl_context</span>) 0;
}
context-&gt;prev = <span style="color: #008b8b;">NULL</span>;
context-&gt;ao_basis = <span style="color: #008b8b;">NULL</span>;
context-&gt;precision = QMCKL_DEFAULT_PRECISION;
context-&gt;range = QMCKL_DEFAULT_RANGE;
context-&gt;tag = VALID_TAG;
context-&gt;error = <span style="color: #008b8b;">NULL</span>;
<span style="color: #a020f0;">return</span> (<span style="color: #228b22;">qmckl_context</span>) context;
}
</pre>
</div>
</div>
</li>
<li><a id="org512ad99"></a><a href="#org3c7e28c">Fortran</a> interface<br />
<div class="outline-text-6" id="text-2-2-1-6-2">
<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_int64_t</span>) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_context_create</span>() <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;">end function</span> <span style="color: #0000ff;">qmckl_context_create</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
<li><a id="org82dbb6b"></a><code>qmckl_context_copy</code><br />
<div class="outline-text-5" id="text-2-2-1-7">
<p>
This function makes a shallow copy of the current <a href="#org79dde7e">context</a>.
</p>
<ul class="org-ul">
<li>Copying the 0-valued <a href="#org79dde7e">context</a> returns 0</li>
<li>On success, returns a pointer to the new <a href="#org79dde7e">context</a> using the <code>qmckl_context</code> type</li>
<li><p>
Returns 0 upon failure to allocate the internal data structure
for the new <a href="#org79dde7e">context</a>
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_copy</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>);
</pre>
</div></li>
</ul>
</div>
<ol class="org-ol">
<li><a id="org6d2df82"></a>Source<br />
<div class="outline-text-6" id="text-2-2-1-7-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_copy</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;">qmckl_context</span> <span style="color: #a0522d;">checked_context</span> = qmckl_context_check(context);
<span style="color: #a020f0;">if</span> (checked_context == (<span style="color: #228b22;">qmckl_context</span>) 0) {
<span style="color: #a020f0;">return</span> (<span style="color: #228b22;">qmckl_context</span>) 0;
}
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">old_context</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) checked_context;
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">new_context</span> =
(<span style="color: #228b22;">qmckl_context_struct</span>*) <span style="color: #0000ff;">qmckl_malloc</span> (context, <span style="color: #a020f0;">sizeof</span>(<span style="color: #228b22;">qmckl_context_struct</span>));
<span style="color: #a020f0;">if</span> (new_context == <span style="color: #008b8b;">NULL</span>) {
<span style="color: #a020f0;">return</span> (<span style="color: #228b22;">qmckl_context</span>) 0;
}
new_context-&gt;prev = old_context;
new_context-&gt;ao_basis = old_context-&gt;ao_basis;
new_context-&gt;precision = old_context-&gt;precision;
new_context-&gt;range = old_context-&gt;range;
new_context-&gt;tag = VALID_TAG;
new_context-&gt;error = old_context-&gt;error;
<span style="color: #a020f0;">return</span> (<span style="color: #228b22;">qmckl_context</span>) new_context;
}
</pre>
</div>
</div>
</li>
<li><a id="org0596e8d"></a><a href="#org3c7e28c">Fortran</a> interface<br />
<div class="outline-text-6" id="text-2-2-1-7-2">
<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_int64_t</span>) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_context_copy</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: #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: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_copy</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
<li><a id="org7772773"></a><code>qmckl_context_previous</code><br />
<div class="outline-text-5" id="text-2-2-1-8">
<p>
Returns the previous <a href="#org79dde7e">context</a>
</p>
<ul class="org-ul">
<li>On success, returns the ancestor of the current <a href="#org79dde7e">context</a></li>
<li>Returns 0 for the initial <a href="#org79dde7e">context</a></li>
<li><p>
Returns 0 for the 0-valued <a href="#org79dde7e">context</a>
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_previous</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>);
</pre>
</div></li>
</ul>
</div>
<ol class="org-ol">
<li><a id="orgf87f301"></a>Source<br />
<div class="outline-text-6" id="text-2-2-1-8-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_previous</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;">qmckl_context</span> <span style="color: #a0522d;">checked_context</span> = qmckl_context_check(context);
<span style="color: #a020f0;">if</span> (checked_context == (<span style="color: #228b22;">qmckl_context</span>) 0) {
<span style="color: #a020f0;">return</span> (<span style="color: #228b22;">qmckl_context</span>) 0;
}
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) checked_context;
<span style="color: #a020f0;">return</span> qmckl_context_check((<span style="color: #228b22;">qmckl_context</span>) ctx-&gt;prev);
}
</pre>
</div>
</div>
</li>
<li><a id="org6c7d87d"></a><a href="#org3c7e28c">Fortran</a> interface<br />
<div class="outline-text-6" id="text-2-2-1-8-2">
<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_int64_t</span>) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_context_previous</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: #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: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_previous</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
<li><a id="orgde52fe7"></a><code>qmckl_context_destroy</code><br />
<div class="outline-text-5" id="text-2-2-1-9">
<p>
Destroys the current <a href="#org79dde7e">context</a>, leaving the ancestors untouched.
</p>
<ul class="org-ul">
<li>Succeeds if the current <a href="#org79dde7e">context</a> is properly destroyed</li>
<li>Fails otherwise</li>
<li>Fails if the 0-valued <a href="#org79dde7e">context</a> is given in argument</li>
<li>Fails if the the pointer is not a valid <a href="#org79dde7e">context</a></li>
</ul>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_context_destroy</span>(<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>);
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="orgd8849e8"></a>Source<br />
<div class="outline-text-6" id="text-2-2-1-9-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_context_destroy</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;">qmckl_context</span> <span style="color: #a0522d;">checked_context</span> = qmckl_context_check(context);
<span style="color: #a020f0;">if</span> (checked_context == (<span style="color: #228b22;">qmckl_context</span>) 0) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
<span style="color: #a020f0;">if</span> (ctx == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
ctx-&gt;tag = INVALID_TAG;
<span style="color: #a020f0;">return</span> qmckl_free(context,ctx);
}
</pre>
</div>
</div>
</li>
<li><a id="org1403c14"></a><a href="#org3c7e28c">Fortran</a> interface<br />
<div class="outline-text-6" id="text-2-2-1-9-2">
<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_context_destroy</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: #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: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_destroy</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
<li><a id="org8fcaa38"></a>Basis set<br />
<div class="outline-text-5" id="text-2-2-1-10">
<p>
For H<sub>2</sub> with the following basis set,
</p>
<pre class="example">
HYDROGEN
S 5
1 3.387000E+01 6.068000E-03
2 5.095000E+00 4.530800E-02
3 1.159000E+00 2.028220E-01
4 3.258000E-01 5.039030E-01
5 1.027000E-01 3.834210E-01
S 1
1 3.258000E-01 1.000000E+00
S 1
1 1.027000E-01 1.000000E+00
P 1
1 1.407000E+00 1.000000E+00
P 1
1 3.880000E-01 1.000000E+00
D 1
1 1.057000E+00 1.0000000
</pre>
<p>
we have:
</p>
<pre class="example">
type = 'G'
shell_num = 12
prim_num = 20
SHELL_CENTER = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2]
SHELL_ANG_MOM = ['S', 'S', 'S', 'P', 'P', 'D', 'S', 'S', 'S', 'P', 'P', 'D']
SHELL_PRIM_NUM = [5, 1, 1, 1, 1, 1, 5, 1, 1, 1, 1, 1]
prim_index = [1, 6, 7, 8, 9, 10, 11, 16, 17, 18, 19, 20]
EXPONENT = [ 33.87, 5.095, 1.159, 0.3258, 0.1027, 0.3258, 0.1027,
1.407, 0.388, 1.057, 33.87, 5.095, 1.159, 0.3258, 0.1027,
0.3258, 0.1027, 1.407, 0.388, 1.057]
COEFFICIENT = [ 0.006068, 0.045308, 0.202822, 0.503903, 0.383421,
1.0, 1.0, 1.0, 1.0, 1.0, 0.006068, 0.045308, 0.202822,
0.503903, 0.383421, 1.0, 1.0, 1.0, 1.0, 1.0]
</pre>
</div>
</li>
<li><a id="orgbf51c3d"></a><code>qmckl_context_update_ao_basis</code><br />
<div class="outline-text-5" id="text-2-2-1-11">
<p>
Updates the data describing the AO basis set into the <a href="#org79dde7e">context</a>.
</p>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
<col class="org-left" />
</colgroup>
<tbody>
<tr>
<td class="org-left"><code>type</code></td>
<td class="org-left">Gaussian or Slater</td>
</tr>
<tr>
<td class="org-left"><code>shell_num</code></td>
<td class="org-left">Number of shells</td>
</tr>
<tr>
<td class="org-left"><code>prim_num</code></td>
<td class="org-left">Total number of primitives</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_CENTER(shell_num)</code></td>
<td class="org-left">Id of the nucleus on which the shell is centered</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_ANG_MOM(shell_num)</code></td>
<td class="org-left">Id of the nucleus on which the shell is centered</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_FACTOR(shell_num)</code></td>
<td class="org-left">Normalization factor for the shell</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_PRIM_NUM(shell_num)</code></td>
<td class="org-left">Number of primitives in the shell</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_PRIM_INDEX(shell_num)</code></td>
<td class="org-left">Address of the first primitive of the shelll in the <code>EXPONENT</code> array</td>
</tr>
<tr>
<td class="org-left"><code>EXPONENT(prim_num)</code></td>
<td class="org-left">Array of exponents</td>
</tr>
<tr>
<td class="org-left"><code>COEFFICIENT(prim_num)</code></td>
<td class="org-left">Array of coefficients</td>
</tr>
</tbody>
</table>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span>
<span style="color: #0000ff;">qmckl_context_update_ao_basis</span>(<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span> <span style="color: #a0522d;">type</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">shell_num</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">prim_num</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_CENTER</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> * <span style="color: #a0522d;">SHELL_ANG_MOM</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">SHELL_FACTOR</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_PRIM_NUM</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_PRIM_INDEX</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">EXPONENT</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">COEFFICIENT</span>);
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="org39db84f"></a>Source<br />
<div class="outline-text-6" id="text-2-2-1-11-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span>
<span style="color: #0000ff;">qmckl_context_update_ao_basis</span>(<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span> <span style="color: #a0522d;">type</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">shell_num</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">prim_num</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_CENTER</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> * <span style="color: #a0522d;">SHELL_ANG_MOM</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">SHELL_FACTOR</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_PRIM_NUM</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_PRIM_INDEX</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">EXPONENT</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">COEFFICIENT</span>)
{
<span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">i</span>;
/* <span style="color: #b22222;">Check input </span>*/
<span style="color: #a020f0;">if</span> (type != <span style="color: #8b2252;">'G'</span> &amp;&amp; type != <span style="color: #8b2252;">'S'</span>) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">if</span> (shell_num &lt;= 0) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">if</span> (prim_num &lt;= 0) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">if</span> (prim_num &lt; shell_num) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">for</span> (i=0 ; i&lt;shell_num ; i++) {
<span style="color: #a020f0;">if</span> (SHELL_CENTER[i] &lt;= 0) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">if</span> (SHELL_PRIM_NUM[i] &lt;= 0) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">if</span> (SHELL_ANG_MOM[i] &lt; 0) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">if</span> (SHELL_PRIM_INDEX[i] &lt; 0) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
}
<span style="color: #a020f0;">for</span> (i=0 ; i&lt;prim_num ; i++) {
<span style="color: #a020f0;">if</span> (EXPONENT[i] &lt;= 0) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
}
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
<span style="color: #a020f0;">if</span> (ctx == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #228b22;">qmckl_ao_basis_struct</span>* <span style="color: #a0522d;">basis</span> = (<span style="color: #228b22;">qmckl_ao_basis_struct</span>*) malloc (<span style="color: #a020f0;">sizeof</span>(qmckl_ao_basis_struct));
<span style="color: #a020f0;">if</span> (basis == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
/* <span style="color: #b22222;">Memory allocations </span>*/
basis-&gt;shell_center = (<span style="color: #228b22;">int64_t</span>*) malloc (<span style="color: #228b22;">shell_num</span> * <span style="color: #a020f0;">sizeof</span>(int64_t));
<span style="color: #a020f0;">if</span> (basis-&gt;shell_center == <span style="color: #008b8b;">NULL</span>) {
qmckl_free(context, basis);
<span style="color: #a020f0;">return</span> QMCKL_FAILURE;
}
basis-&gt;shell_ang_mom = (<span style="color: #228b22;">int32_t</span>*) malloc (<span style="color: #228b22;">shell_num</span> * <span style="color: #a020f0;">sizeof</span>(int32_t));
<span style="color: #a020f0;">if</span> (basis-&gt;shell_ang_mom == <span style="color: #008b8b;">NULL</span>) {
qmckl_free(context, basis-&gt;shell_center);
qmckl_free(context, basis);
<span style="color: #a020f0;">return</span> QMCKL_FAILURE;
}
basis-&gt;shell_prim_num= (<span style="color: #228b22;">int64_t</span>*) malloc (<span style="color: #228b22;">shell_num</span> * <span style="color: #a020f0;">sizeof</span>(int64_t));
<span style="color: #a020f0;">if</span> (basis-&gt;shell_prim_num == <span style="color: #008b8b;">NULL</span>) {
qmckl_free(context, basis-&gt;shell_ang_mom);
qmckl_free(context, basis-&gt;shell_center);
qmckl_free(context, basis);
<span style="color: #a020f0;">return</span> QMCKL_FAILURE;
}
basis-&gt;shell_factor = (<span style="color: #228b22;">double</span> *) malloc (<span style="color: #228b22;">shell_num</span> * <span style="color: #a020f0;">sizeof</span>(<span style="color: #228b22;">double</span> ));
<span style="color: #a020f0;">if</span> (basis-&gt;shell_factor == <span style="color: #008b8b;">NULL</span>) {
qmckl_free(context, basis-&gt;shell_prim_num);
qmckl_free(context, basis-&gt;shell_ang_mom);
qmckl_free(context, basis-&gt;shell_center);
qmckl_free(context, basis);
<span style="color: #a020f0;">return</span> QMCKL_FAILURE;
}
basis-&gt;exponent = (<span style="color: #228b22;">double</span> *) malloc (<span style="color: #228b22;">prim_num</span> * <span style="color: #a020f0;">sizeof</span>(<span style="color: #228b22;">double</span> ));
<span style="color: #a020f0;">if</span> (basis-&gt;exponent == <span style="color: #008b8b;">NULL</span>) {
qmckl_free(context, basis-&gt;shell_factor);
qmckl_free(context, basis-&gt;shell_prim_num);
qmckl_free(context, basis-&gt;shell_ang_mom);
qmckl_free(context, basis-&gt;shell_center);
qmckl_free(context, basis);
<span style="color: #a020f0;">return</span> QMCKL_FAILURE;
}
basis-&gt;coefficient = (<span style="color: #228b22;">double</span> *) malloc (<span style="color: #228b22;">prim_num</span> * <span style="color: #a020f0;">sizeof</span>(<span style="color: #228b22;">double</span> ));
<span style="color: #a020f0;">if</span> (basis-&gt;coefficient == <span style="color: #008b8b;">NULL</span>) {
qmckl_free(context, basis-&gt;exponent);
qmckl_free(context, basis-&gt;shell_factor);
qmckl_free(context, basis-&gt;shell_prim_num);
qmckl_free(context, basis-&gt;shell_ang_mom);
qmckl_free(context, basis-&gt;shell_center);
qmckl_free(context, basis);
<span style="color: #a020f0;">return</span> QMCKL_FAILURE;
}
/* <span style="color: #b22222;">Assign data </span>*/
basis-&gt;type = type;
basis-&gt;shell_num = shell_num;
basis-&gt;prim_num = prim_num;
<span style="color: #a020f0;">for</span> (i=0 ; i&lt;shell_num ; i++) {
basis-&gt;shell_center [i] = SHELL_CENTER [i];
basis-&gt;shell_ang_mom [i] = SHELL_ANG_MOM [i];
basis-&gt;shell_prim_num[i] = SHELL_PRIM_NUM[i];
basis-&gt;shell_factor [i] = SHELL_FACTOR [i];
}
<span style="color: #a020f0;">for</span> (i=0 ; i&lt;prim_num ; i++) {
basis-&gt;exponent [i] = EXPONENT[i];
basis-&gt;coefficient[i] = COEFFICIENT[i];
}
ctx-&gt;ao_basis = basis;
<span style="color: #a020f0;">return</span> QMCKL_SUCCESS;
}
</pre>
</div>
</div>
</li>
<li><a id="orge3e75ff"></a><a href="#org3c7e28c">Fortran</a> interface<br />
<div class="outline-text-6" id="text-2-2-1-11-2">
<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: #a0522d;"> function qmckl_context_update_ao_basis(context, </span><span style="color: #a020f0;">&amp;</span>
typ, shell_num, prim_num, SHELL_CENTER, SHELL_ANG_MOM, SHELL_FACTOR, <span style="color: #a020f0;">&amp;</span>
SHELL_PRIM_NUM, SHELL_PRIM_INDEX, EXPONENT, COEFFICIENT) <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;">character</span>(<span style="color: #008b8b;">c_char</span>) , <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> typ</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;"> shell_num</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;"> prim_num</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: #a0522d;"> SHELL_CENTER(shell_num)</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: #a0522d;"> SHELL_ANG_MOM(shell_num)</span>
<span style="color: #228b22;">double precision</span> , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> SHELL_FACTOR(shell_num)</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: #a0522d;"> SHELL_PRIM_NUM(shell_num)</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: #a0522d;"> SHELL_PRIM_INDEX(shell_num)</span>
<span style="color: #228b22;">double precision</span> , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> EXPONENT(prim_num)</span>
<span style="color: #228b22;">double precision</span> , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> COEFFICIENT(prim_num)</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_update_ao_basis</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
<li><a id="orge77809c"></a><span class="todo TODO">TODO</span> Test<br /></li>
</ol>
</li>
<li><a id="org3c38762"></a><code>qmckl_context_set_ao_basis</code><br />
<div class="outline-text-5" id="text-2-2-1-12">
<p>
Sets the data describing the AO basis set into the <a href="#org79dde7e">context</a>.
</p>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
<col class="org-left" />
</colgroup>
<tbody>
<tr>
<td class="org-left"><code>type</code></td>
<td class="org-left">Gaussian or Slater</td>
</tr>
<tr>
<td class="org-left"><code>shell_num</code></td>
<td class="org-left">Number of shells</td>
</tr>
<tr>
<td class="org-left"><code>prim_num</code></td>
<td class="org-left">Total number of primitives</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_CENTER(shell_num)</code></td>
<td class="org-left">Id of the nucleus on which the shell is centered</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_ANG_MOM(shell_num)</code></td>
<td class="org-left">Id of the nucleus on which the shell is centered</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_FACTOR(shell_num)</code></td>
<td class="org-left">Normalization factor for the shell</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_PRIM_NUM(shell_num)</code></td>
<td class="org-left">Number of primitives in the shell</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_PRIM_INDEX(shell_num)</code></td>
<td class="org-left">Address of the first primitive of the shelll in the <code>EXPONENT</code> array</td>
</tr>
<tr>
<td class="org-left"><code>EXPONENT(prim_num)</code></td>
<td class="org-left">Array of exponents</td>
</tr>
<tr>
<td class="org-left"><code>COEFFICIENT(prim_num)</code></td>
<td class="org-left">Array of coefficients</td>
</tr>
</tbody>
</table>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span>
<span style="color: #0000ff;">qmckl_context_set_ao_basis</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;">char</span> <span style="color: #a0522d;">type</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">shell_num</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">prim_num</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_CENTER</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> * <span style="color: #a0522d;">SHELL_ANG_MOM</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">SHELL_FACTOR</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_PRIM_NUM</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_PRIM_INDEX</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">EXPONENT</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">COEFFICIENT</span>);
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="org3f72c2f"></a>Source<br />
<div class="outline-text-6" id="text-2-2-1-12-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span>
<span style="color: #0000ff;">qmckl_context_set_ao_basis</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;">char</span> <span style="color: #a0522d;">type</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">shell_num</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">prim_num</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_CENTER</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> * <span style="color: #a0522d;">SHELL_ANG_MOM</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">SHELL_FACTOR</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_PRIM_NUM</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_PRIM_INDEX</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">EXPONENT</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">COEFFICIENT</span>)
{
<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">new_context</span> = qmckl_context_copy(context);
<span style="color: #a020f0;">if</span> (new_context == 0) <span style="color: #a020f0;">return</span> 0;
<span style="color: #a020f0;">if</span> (qmckl_context_update_ao_basis(new_context, type, shell_num, prim_num,
SHELL_CENTER, SHELL_ANG_MOM, SHELL_FACTOR,
SHELL_PRIM_NUM, SHELL_PRIM_INDEX, EXPONENT,
COEFFICIENT
) == QMCKL_FAILURE)
<span style="color: #a020f0;">return</span> 0;
<span style="color: #a020f0;">return</span> new_context;
}
</pre>
</div>
</div>
</li>
<li><a id="orgd707672"></a><a href="#org3c7e28c">Fortran</a> interface<br />
<div class="outline-text-6" id="text-2-2-1-12-2">
<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_int64_t</span>)<span style="color: #a0522d;"> function qmckl_context_set_ao_basis(context, </span><span style="color: #a020f0;">&amp;</span>
typ, shell_num, prim_num, SHELL_CENTER, SHELL_ANG_MOM, SHELL_FACTOR, <span style="color: #a020f0;">&amp;</span>
SHELL_PRIM_NUM, SHELL_PRIM_INDEX, EXPONENT, COEFFICIENT) <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;">character</span>(<span style="color: #008b8b;">c_char</span>) , <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> typ</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;"> shell_num</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;"> prim_num</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: #a0522d;"> SHELL_CENTER(shell_num)</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: #a0522d;"> SHELL_ANG_MOM(shell_num)</span>
<span style="color: #228b22;">double precision</span> , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> SHELL_FACTOR(shell_num)</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: #a0522d;"> SHELL_PRIM_NUM(shell_num)</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: #a0522d;"> SHELL_PRIM_INDEX(shell_num)</span>
<span style="color: #228b22;">double precision</span> , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> EXPONENT(prim_num)</span>
<span style="color: #228b22;">double precision</span> , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> COEFFICIENT(prim_num)</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_set_ao_basis</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
<li><a id="org1d5eff1"></a><span class="todo TODO">TODO</span> Test<br /></li>
</ol>
</li>
<li><a id="org7634683"></a>Precision<br />
<div class="outline-text-5" id="text-2-2-1-13">
<p>
The following functions set and get the expected required
precision and range. <code>precision</code> should be an integer between 2
and 53, and <code>range</code> should be an integer between 2 and 11.
</p>
<p>
The setter functions functions return a new <a href="#org79dde7e">context</a> 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>
</li>
<li><a id="org7a27209"></a><code>qmckl_context_update_precision</code><br />
<div class="outline-text-5" id="text-2-2-1-14">
<p>
Modifies the parameter for the numerical precision in a given <a href="#org79dde7e">context</a>.
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_context_update_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>);
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="org19948f8"></a>Source<br />
<div class="outline-text-6" id="text-2-2-1-14-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_context_update_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> (precision &lt; 2) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">if</span> (precision &gt; 53) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
<span style="color: #a020f0;">if</span> (ctx == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
ctx-&gt;precision = precision;
<span style="color: #a020f0;">return</span> QMCKL_SUCCESS;
}
</pre>
</div>
</div>
</li>
<li><a id="org04c2b70"></a><a href="#org3c7e28c">Fortran</a> interface<br />
<div class="outline-text-6" id="text-2-2-1-14-2">
<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_context_update_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: #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_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_context_update_precision</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
<li><a id="org63ca75e"></a><code>qmckl_context_update_range</code><br />
<div class="outline-text-5" id="text-2-2-1-15">
<p>
Modifies the parameter for the numerical range in a given <a href="#org79dde7e">context</a>.
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_context_update_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>);
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="org9043814"></a>Source<br />
<div class="outline-text-6" id="text-2-2-1-15-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_context_update_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> (range &lt; 2) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">if</span> (range &gt; 11) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
<span style="color: #a020f0;">if</span> (ctx == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
ctx-&gt;range = range;
<span style="color: #a020f0;">return</span> QMCKL_SUCCESS;
}
</pre>
</div>
</div>
</li>
<li><a id="org002f5c2"></a><a href="#org3c7e28c">Fortran</a> interface<br />
<div class="outline-text-6" id="text-2-2-1-15-2">
<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_context_update_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: #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_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_context_update_range</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
<li><a id="org6533380"></a><code>qmckl_context_set_precision</code><br />
<div class="outline-text-5" id="text-2-2-1-16">
<p>
Returns a copy of the <a href="#org79dde7e">context</a> with a different precision parameter.
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_set_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>);
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="orgc867b56"></a>Source<br />
<div class="outline-text-6" id="text-2-2-1-16-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_set_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: #228b22;">qmckl_context</span> <span style="color: #a0522d;">new_context</span> = qmckl_context_copy(context);
<span style="color: #a020f0;">if</span> (new_context == 0) <span style="color: #a020f0;">return</span> 0;
<span style="color: #a020f0;">if</span> (qmckl_context_update_precision(new_context, precision) == QMCKL_FAILURE) <span style="color: #a020f0;">return</span> 0;
<span style="color: #a020f0;">return</span> new_context;
}
</pre>
</div>
</div>
</li>
<li><a id="org7b7d7ec"></a><a href="#org3c7e28c">Fortran</a> interface<br />
<div class="outline-text-6" id="text-2-2-1-16-2">
<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_int64_t</span>) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_context_set_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: #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_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_context_set_precision</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
<li><a id="orge323105"></a><code>qmckl_context_set_range</code><br />
<div class="outline-text-5" id="text-2-2-1-17">
<p>
Returns a copy of the <a href="#org79dde7e">context</a> with a different precision parameter.
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_set_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>);
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="org390433c"></a>Source<br />
<div class="outline-text-6" id="text-2-2-1-17-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_set_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: #228b22;">qmckl_context</span> <span style="color: #a0522d;">new_context</span> = qmckl_context_copy(context);
<span style="color: #a020f0;">if</span> (new_context == 0) <span style="color: #a020f0;">return</span> 0;
<span style="color: #a020f0;">if</span> (qmckl_context_update_range(new_context, range) == QMCKL_FAILURE) <span style="color: #a020f0;">return</span> 0;
<span style="color: #a020f0;">return</span> new_context;
}
</pre>
</div>
</div>
</li>
<li><a id="orgf01c824"></a><a href="#org3c7e28c">Fortran</a> interface<br />
<div class="outline-text-6" id="text-2-2-1-17-2">
<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_int64_t</span>) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_context_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: #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_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_context_set_range</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
<li><a id="orgd246989"></a><code>qmckl_context_get_precision</code><br />
<div class="outline-text-5" id="text-2-2-1-18">
<p>
Returns the value of the numerical precision in the <a href="#org79dde7e">context</a>
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">int32_t</span> <span style="color: #0000ff;">qmckl_context_get_precision</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>);
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="org99d6c21"></a>Source<br />
<div class="outline-text-6" id="text-2-2-1-18-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">int</span> <span style="color: #0000ff;">qmckl_context_get_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;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
<span style="color: #a020f0;">return</span> ctx-&gt;precision;
}
</pre>
</div>
</div>
</li>
<li><a id="org9db4a84"></a><a href="#org3c7e28c">Fortran</a> interface<br />
<div class="outline-text-6" id="text-2-2-1-18-2">
<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_context_get_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: #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: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_get_precision</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
<li><a id="org5eaac0f"></a><code>qmckl_context_get_range</code><br />
<div class="outline-text-5" id="text-2-2-1-19">
<p>
Returns the value of the numerical range in the <a href="#org79dde7e">context</a>
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">int32_t</span> <span style="color: #0000ff;">qmckl_context_get_range</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>);
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="org19c6fe5"></a>Source<br />
<div class="outline-text-6" id="text-2-2-1-19-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">int</span> <span style="color: #0000ff;">qmckl_context_get_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;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
<span style="color: #a020f0;">return</span> ctx-&gt;range;
}
</pre>
</div>
</div>
</li>
<li><a id="orgfcb2cff"></a><a href="#org3c7e28c">Fortran</a> interface<br />
<div class="outline-text-6" id="text-2-2-1-19-2">
<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_context_get_range</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: #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: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_get_range</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
<li><a id="org0775918"></a><code>qmckl_context_get_epsilon</code><br />
<div class="outline-text-5" id="text-2-2-1-20">
<p>
Returns \(\epsilon = 2^{1-n}\) where <code>n</code> is the precision
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">double</span> <span style="color: #0000ff;">qmckl_context_get_epsilon</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>);
</pre>
</div>
</div>
<ol class="org-ol">
<li><a id="orgfec58da"></a>Source<br />
<div class="outline-text-6" id="text-2-2-1-20-1">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">double</span> <span style="color: #0000ff;">qmckl_context_get_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;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
<span style="color: #a020f0;">return</span> pow(2.0,(<span style="color: #228b22;">double</span>) 1-ctx-&gt;precision);
}
</pre>
</div>
</div>
</li>
<li><a id="orgf43ec57"></a><a href="#org3c7e28c">Fortran</a> interface<br />
<div class="outline-text-6" id="text-2-2-1-20-2">
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
<span style="color: #228b22;">real</span> (<span style="color: #008b8b;">c_double</span>) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_context_get_epsilon</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: #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: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_get_epsilon</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
</ol>
</div>
</div>
<div id="outline-container-org5976dad" class="outline-3">
<h3 id="org5976dad"><span class="section-number-3">2.3</span> Error handling</h3>
<div class="outline-text-3" id="text-2-3">
<p>
This file is written in <a href="#org1ac3923">C</a> because it is more natural to express the
error handling in <a href="#org1ac3923">C</a> than in <a href="#org3c7e28c">Fortran</a>.
</p>
<p>
2 files are produced:
</p>
<ul class="org-ul">
<li>a source file : <code>qmckl_error.c</code></li>
<li>a test file : <code>test_qmckl_error.c</code></li>
</ul>
</div>
<div id="outline-container-orgdfb3ddb" class="outline-4">
<h4 id="orgdfb3ddb"><span class="section-number-4">2.3.1</span> Error handling</h4>
<div class="outline-text-4" id="text-2-3-1">
<p>
The library should never make the calling programs abort, nor
perform any input/output operations. This decision has to be taken
by the developer of the code calling the library.
</p>
<p>
All the functions return with an <a id="org5c0df71">exit code</a>, defined as
</p>
<div class="org-src-container">
<pre class="src src-C" id="orgfbf5250"><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 <a href="#org5c0df71">exit code</a> returns the completion status of the function to the
calling program. When a function call completed successfully, the
<code>QMCKL_SUCCESS</code> <a href="#org5c0df71">exit code</a> is returned. If one of the functions of
the library fails to complete the requested task, an appropriate
error code is returned to the program.
</p>
<p>
Here is the complete list of exit codes.
</p>
<table id="org6adf8ee" 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_SUCCESS</code></td>
<td class="org-right">0</td>
</tr>
<tr>
<td class="org-left"><code>QMCKL_INVALID_ARG_1</code></td>
<td class="org-right">1</td>
</tr>
<tr>
<td class="org-left"><code>QMCKL_INVALID_ARG_2</code></td>
<td class="org-right">2</td>
</tr>
<tr>
<td class="org-left"><code>QMCKL_INVALID_ARG_3</code></td>
<td class="org-right">3</td>
</tr>
<tr>
<td class="org-left"><code>QMCKL_INVALID_ARG_4</code></td>
<td class="org-right">4</td>
</tr>
<tr>
<td class="org-left"><code>QMCKL_INVALID_ARG_5</code></td>
<td class="org-right">5</td>
</tr>
<tr>
<td class="org-left"><code>QMCKL_INVALID_ARG_6</code></td>
<td class="org-right">6</td>
</tr>
<tr>
<td class="org-left"><code>QMCKL_INVALID_ARG_7</code></td>
<td class="org-right">7</td>
</tr>
<tr>
<td class="org-left"><code>QMCKL_INVALID_ARG_8</code></td>
<td class="org-right">8</td>
</tr>
<tr>
<td class="org-left"><code>QMCKL_INVALID_ARG_9</code></td>
<td class="org-right">9</td>
</tr>
<tr>
<td class="org-left"><code>QMCKL_INVALID_ARG_10</code></td>
<td class="org-right">10</td>
</tr>
<tr>
<td class="org-left"><code>QMCKL_NULL_CONTEXT</code></td>
<td class="org-right">101</td>
</tr>
<tr>
<td class="org-left"><code>QMCKL_FAILURE</code></td>
<td class="org-right">102</td>
</tr>
<tr>
<td class="org-left"><code>QMCKL_ERRNO</code></td>
<td class="org-right">103</td>
</tr>
<tr>
<td class="org-left"><code>QMCKL_INVALID_EXIT_CODE</code></td>
<td class="org-right">104</td>
</tr>
</tbody>
</table>
<div class="org-src-container">
<pre class="src src-python"><span style="color: #8b2252;">""" This script generates the C and Fortran constants for the error</span>
<span style="color: #8b2252;"> codes from the org-mode table.</span>
<span style="color: #8b2252;">"""</span>
<span style="color: #a0522d;">result</span> = [ <span style="color: #8b2252;">"#+BEGIN_SRC C :comments org :tangle qmckl.h"</span> ]
<span style="color: #a020f0;">for</span> (text, code) <span style="color: #a020f0;">in</span> table:
<span style="color: #a0522d;">text</span>=text.replace(<span style="color: #8b2252;">"~"</span>,<span style="color: #8b2252;">""</span>)
<span style="color: #a0522d;">result</span> += [ f<span style="color: #8b2252;">"#define {text:30s} {code:d}"</span> ]
<span style="color: #a0522d;">result</span> += [ <span style="color: #8b2252;">"#+END_SRC"</span> ]
<span style="color: #a0522d;">result</span> += [ <span style="color: #8b2252;">""</span> ]
<span style="color: #a0522d;">result</span> += [ <span style="color: #8b2252;">"#+BEGIN_SRC f90 :comments org :tangle qmckl_f.f90"</span> ]
<span style="color: #a020f0;">for</span> (text, code) <span style="color: #a020f0;">in</span> table:
<span style="color: #a0522d;">text</span>=text.replace(<span style="color: #8b2252;">"~"</span>,<span style="color: #8b2252;">""</span>)
<span style="color: #a0522d;">result</span> += [ f<span style="color: #8b2252;">" integer, parameter :: {text:30s} = {code:d}"</span> ]
<span style="color: #a0522d;">result</span> += [ <span style="color: #8b2252;">"#+END_SRC"</span> ]
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">'\n'</span>.join(result)
</pre>
</div>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_SUCCESS</span> 0
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_INVALID_ARG_1</span> 1
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_INVALID_ARG_2</span> 2
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_INVALID_ARG_3</span> 3
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_INVALID_ARG_4</span> 4
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_INVALID_ARG_5</span> 5
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_INVALID_ARG_6</span> 6
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_INVALID_ARG_7</span> 7
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_INVALID_ARG_8</span> 8
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_INVALID_ARG_9</span> 9
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_INVALID_ARG_10</span> 10
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_NULL_CONTEXT</span> 101
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_FAILURE</span> 102
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_ERRNO</span> 103
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_INVALID_EXIT_CODE</span> 104
</pre>
</div>
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> QMCKL_SUCCESS = 0</span>
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> QMCKL_INVALID_ARG_1 = 1</span>
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> QMCKL_INVALID_ARG_2 = 2</span>
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> QMCKL_INVALID_ARG_3 = 3</span>
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> QMCKL_INVALID_ARG_4 = 4</span>
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> QMCKL_INVALID_ARG_5 = 5</span>
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> QMCKL_INVALID_ARG_6 = 6</span>
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> QMCKL_INVALID_ARG_7 = 7</span>
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> QMCKL_INVALID_ARG_8 = 8</span>
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> QMCKL_INVALID_ARG_9 = 9</span>
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> QMCKL_INVALID_ARG_10 = 10</span>
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> QMCKL_NULL_CONTEXT = 101</span>
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> QMCKL_FAILURE = 102</span>
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> QMCKL_ERRNO = 103</span>
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> QMCKL_INVALID_EXIT_CODE = 104</span>
</pre>
</div>
<p>
To make a function fail, the <a id="org297d9ce"><code>qmckl_failwith</code></a> function should be
called, such that information about the failure is stored in
the <a href="#org79dde7e">context</a>. The desired <a href="#org5c0df71">exit code</a> is given as an argument, as
well as the name of the function and an error message. The return
code of the function is the desired return 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_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>) ;
</pre>
</div>
<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>) {
<span style="color: #a020f0;">if</span> (context == 0) <span style="color: #a020f0;">return</span> QMCKL_NULL_CONTEXT;
assert (exit_code &gt; 0);
assert (exit_code &lt; QMCKL_INVALID_EXIT_CODE);
assert (function != <span style="color: #008b8b;">NULL</span>);
assert (message != <span style="color: #008b8b;">NULL</span>);
assert (strlen(function) &lt; QMCKL_MAX_FUN_LEN);
assert (strlen(message) &lt; QMCKL_MAX_MSG_LEN);
context = qmckl_context_set_error(context, exit_code, function, message);
<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 &lt; 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 &gt;= 0"</span>);
}
</pre>
</div>
</div>
</div>
<div id="outline-container-orga418328" class="outline-4">
<h4 id="orga418328"><span class="section-number-4">2.3.2</span> Multi-precision related constants</h4>
<div class="outline-text-4" id="text-2-3-2">
<p>
Controlling numerical precision enables optimizations. Here, the
default parameters determining the target numerical precision and
range are defined.
</p>
<div class="org-src-container">
<pre class="src src-C"><span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_DEFAULT_PRECISION</span> 53
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_DEFAULT_RANGE</span> 11
</pre>
</div>
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> QMCKL_DEFAULT_PRECISION = 53</span>
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> QMCKL_DEFAULT_RANGE = 11</span>
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-org651e7fe" class="outline-3">
<h3 id="org651e7fe"><span class="section-number-3">2.4</span> Memory management</h3>
<div class="outline-text-3" id="text-2-4">
<p>
We override the allocation functions to enable the possibility of
optimized libraries to fine-tune the memory allocation.
</p>
<p>
2 files are produced:
</p>
<ul class="org-ul">
<li>a source file : <code>qmckl_memory.c</code></li>
<li>a test file : <code>test_qmckl_memory.c</code></li>
</ul>
</div>
<div id="outline-container-org18712b6" class="outline-4">
<h4 id="org18712b6"><span class="section-number-4">2.4.1</span> <code>qmckl_malloc</code></h4>
<div class="outline-text-4" id="text-2-4-1">
<p>
Memory allocation function, letting the library choose how the
memory will be allocated, and a pointer is returned to the user.
The <a href="#org79dde7e">context</a> is passed to let the library store data related to the
allocation inside the <a href="#org79dde7e">context</a>.
</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: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">ctx</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">size_t</span> <span style="color: #a0522d;">size</span>);
</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>
<ol class="org-ol">
<li><a id="org23ef550"></a>Source<br />
<div class="outline-text-5" id="text-2-4-1-1">
<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: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">ctx</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">size_t</span> <span style="color: #a0522d;">size</span>) {
<span style="color: #a020f0;">if</span> (ctx == (<span style="color: #228b22;">qmckl_context</span>) 0) {}; /* <span style="color: #b22222;">Avoid unused argument warning </span>*/
<span style="color: #228b22;">void</span> * <span style="color: #a0522d;">result</span> = malloc( (<span style="color: #228b22;">size_t</span>) size );
assert (result != <span style="color: #008b8b;">NULL</span>) ;
<span style="color: #a020f0;">return</span> result;
}
</pre>
</div>
</div>
</li>
</ol>
</div>
<div id="outline-container-org603dfce" class="outline-4">
<h4 id="org603dfce"><span class="section-number-4">2.4.2</span> <code>qmckl_free</code></h4>
<div class="outline-text-4" id="text-2-4-2">
<p>
The <a href="#org79dde7e">context</a> is passed, in case some important information has been
stored related to memory allocation and needs to be updated.
</p>
<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>);
</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>
</div>
<ol class="org-ol">
<li><a id="orga22d257"></a>Source<br />
<div class="outline-text-5" id="text-2-4-2-1">
<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> (context == 0) <span style="color: #a020f0;">return</span> QMCKL_INVALID_ARG_1;
<span style="color: #a020f0;">if</span> (ptr == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> QMCKL_INVALID_ARG_2;
free(ptr);
<span style="color: #a020f0;">return</span> QMCKL_SUCCESS;
}
</pre>
</div>
</div>
</li>
</ol>
</div>
</div>
<div id="outline-container-orged2a041" class="outline-3">
<h3 id="orged2a041"><span class="section-number-3">2.5</span> Computation of distances</h3>
<div class="outline-text-3" id="text-2-5">
<p>
Function for the computation of distances between particles.
</p>
<p>
3 files are produced:
</p>
<ul class="org-ul">
<li>a source file : <code>qmckl_distance.f90</code></li>
<li>a <a href="#org1ac3923">C</a> test file : <code>test_qmckl_distance.c</code></li>
<li>a <a href="#org3c7e28c">Fortran</a> test file : <code>test_qmckl_distance_f.f90</code></li>
</ul>
</div>
<div id="outline-container-org8e03b4f" class="outline-4">
<h4 id="org8e03b4f"><span class="section-number-4">2.5.1</span> Squared distance</h4>
<div class="outline-text-4" id="text-2-5-1">
</div>
<ol class="org-ol">
<li><a id="org1145938"></a><code>qmckl_distance_sq</code><br />
<div class="outline-text-5" id="text-2-5-1-1">
<p>
Computes the matrix of the squared distances between all pairs of
points in two sets, one point within each set:
\[
C_{ij} = \sum_{k=1}^3 (A_{k,i}-B_{k,j})^2
\]
</p>
</div>
<ol class="org-ol">
<li><a id="org338f9e5"></a>Arguments<br />
<div class="outline-text-6" id="text-2-5-1-1-1">
<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>
<tbody>
<tr>
<td class="org-left"><code>context</code></td>
<td class="org-left">input</td>
<td class="org-left">Global state</td>
</tr>
<tr>
<td class="org-left"><code>transa</code></td>
<td class="org-left">input</td>
<td class="org-left">Array <code>A</code> is <code>N</code>: Normal, <code>T</code>: Transposed</td>
</tr>
<tr>
<td class="org-left"><code>transb</code></td>
<td class="org-left">input</td>
<td class="org-left">Array <code>B</code> is <code>N</code>: Normal, <code>T</code>: Transposed</td>
</tr>
<tr>
<td class="org-left"><code>m</code></td>
<td class="org-left">input</td>
<td class="org-left">Number of points in the first set</td>
</tr>
<tr>
<td class="org-left"><code>n</code></td>
<td class="org-left">input</td>
<td class="org-left">Number of points in the second set</td>
</tr>
<tr>
<td class="org-left"><code>A(lda,3)</code></td>
<td class="org-left">input</td>
<td class="org-left">Array containing the \(m \times 3\) matrix \(A\)</td>
</tr>
<tr>
<td class="org-left"><code>lda</code></td>
<td class="org-left">input</td>
<td class="org-left">Leading dimension of array <code>A</code></td>
</tr>
<tr>
<td class="org-left"><code>B(ldb,3)</code></td>
<td class="org-left">input</td>
<td class="org-left">Array containing the \(n \times 3\) matrix \(B\)</td>
</tr>
<tr>
<td class="org-left"><code>ldb</code></td>
<td class="org-left">input</td>
<td class="org-left">Leading dimension of array <code>B</code></td>
</tr>
<tr>
<td class="org-left"><code>C(ldc,n)</code></td>
<td class="org-left">output</td>
<td class="org-left">Array containing the \(m \times n\) matrix \(C\)</td>
</tr>
<tr>
<td class="org-left"><code>ldc</code></td>
<td class="org-left">input</td>
<td class="org-left">Leading dimension of array <code>C</code></td>
</tr>
</tbody>
</table>
</div>
</li>
<li><a id="orge60af9d"></a>Requirements<br />
<div class="outline-text-6" id="text-2-5-1-1-2">
<ul class="org-ul">
<li><code>context</code> is not 0</li>
<li><code>m</code> &gt; 0</li>
<li><code>n</code> &gt; 0</li>
<li><code>lda</code> &gt;= 3 if <code>transa</code> is <code>N</code></li>
<li><code>lda</code> &gt;= m if <code>transa</code> is <code>T</code></li>
<li><code>ldb</code> &gt;= 3 if <code>transb</code> is <code>N</code></li>
<li><code>ldb</code> &gt;= n if <code>transb</code> is <code>T</code></li>
<li><code>ldc</code> &gt;= m</li>
<li><code>A</code> is allocated with at least \(3 \times m \times 8\) bytes</li>
<li><code>B</code> is allocated with at least \(3 \times n \times 8\) bytes</li>
<li><code>C</code> is allocated with at least \(m \times n \times 8\) bytes</li>
</ul>
</div>
</li>
<li><a id="org2103904"></a>Performance<br />
<div class="outline-text-6" id="text-2-5-1-1-3">
<p>
This function might be more efficient when <code>A</code> and <code>B</code> are
transposed.
</p>
<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>(<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;">char</span> <span style="color: #a0522d;">transa</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span> <span style="color: #a0522d;">transb</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">m</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">n</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> *<span style="color: #a0522d;">A</span>, <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: #a020f0;">const</span> <span style="color: #228b22;">double</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>
</li>
<li><a id="org0e44fdd"></a>Source<br />
<div class="outline-text-6" id="text-2-5-1-1-4">
<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;">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;">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>
<span style="color: #228b22;">real</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> A(lda,*)</span>
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> ldb</span>
<span style="color: #228b22;">real</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> B(ldb,*)</span>
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> ldc</span>
<span style="color: #228b22;">real</span>*8 , <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> C(ldc,*)</span>
<span style="color: #228b22;">integer</span>*8 ::<span style="color: #a0522d;"> i,j</span>
<span style="color: #228b22;">real</span>*8 ::<span style="color: #a0522d;"> x, y, z</span>
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> transab</span>
info = 0
<span style="color: #a020f0;">if</span> (context == 0_8) <span style="color: #a020f0;">then</span>
info = -1
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (m &lt;= 0_8) <span style="color: #a020f0;">then</span>
info = -2
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (n &lt;= 0_8) <span style="color: #a020f0;">then</span>
info = -3
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (transa == <span style="color: #8b2252;">'N'</span> <span style="color: #a020f0;">.or.</span> transa == <span style="color: #8b2252;">'n'</span>) <span style="color: #a020f0;">then</span>
transab = 0
<span style="color: #a020f0;">else if</span> (transa == <span style="color: #8b2252;">'T'</span> <span style="color: #a020f0;">.or.</span> transa == <span style="color: #8b2252;">'t'</span>) <span style="color: #a020f0;">then</span>
transab = 1
<span style="color: #a020f0;">else</span>
transab = -100
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (transb == <span style="color: #8b2252;">'N'</span> <span style="color: #a020f0;">.or.</span> transb == <span style="color: #8b2252;">'n'</span>) <span style="color: #a020f0;">then</span>
<span style="color: #a020f0;">continue</span>
<span style="color: #a020f0;">else if</span> (transa == <span style="color: #8b2252;">'T'</span> <span style="color: #a020f0;">.or.</span> transa == <span style="color: #8b2252;">'t'</span>) <span style="color: #a020f0;">then</span>
transab = transab + 2
<span style="color: #a020f0;">else</span>
transab = -100
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (transab &lt; 0) <span style="color: #a020f0;">then</span>
info = -4
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (<span style="color: #a020f0;">iand</span>(transab,1) == 0 <span style="color: #a020f0;">.and.</span> LDA &lt; 3) <span style="color: #a020f0;">then</span>
info = -5
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (<span style="color: #a020f0;">iand</span>(transab,1) == 1 <span style="color: #a020f0;">.and.</span> LDA &lt; m) <span style="color: #a020f0;">then</span>
info = -6
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (<span style="color: #a020f0;">iand</span>(transab,2) == 0 <span style="color: #a020f0;">.and.</span> LDA &lt; 3) <span style="color: #a020f0;">then</span>
info = -6
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (<span style="color: #a020f0;">iand</span>(transab,2) == 2 <span style="color: #a020f0;">.and.</span> LDA &lt; m) <span style="color: #a020f0;">then</span>
info = -7
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">select case</span> (transab)
<span style="color: #a020f0;">case</span>(0)
<span style="color: #a020f0;">do</span> j=1,n
<span style="color: #a020f0;">do</span> i=1,m
x = A(1,i) - B(1,j)
y = A(2,i) - B(2,j)
z = A(3,i) - B(3,j)
C(i,j) = x*x + y*y + z*z
<span style="color: #a020f0;">end do</span>
<span style="color: #a020f0;">end do</span>
<span style="color: #a020f0;">case</span>(1)
<span style="color: #a020f0;">do</span> j=1,n
<span style="color: #a020f0;">do</span> i=1,m
x = A(i,1) - B(1,j)
y = A(i,2) - B(2,j)
z = A(i,3) - B(3,j)
C(i,j) = x*x + y*y + z*z
<span style="color: #a020f0;">end do</span>
<span style="color: #a020f0;">end do</span>
<span style="color: #a020f0;">case</span>(2)
<span style="color: #a020f0;">do</span> j=1,n
<span style="color: #a020f0;">do</span> i=1,m
x = A(1,i) - B(j,1)
y = A(2,i) - B(j,2)
z = A(3,i) - B(j,3)
C(i,j) = x*x + y*y + z*z
<span style="color: #a020f0;">end do</span>
<span style="color: #a020f0;">end do</span>
<span style="color: #a020f0;">case</span>(3)
<span style="color: #a020f0;">do</span> j=1,n
<span style="color: #a020f0;">do</span> i=1,m
x = A(i,1) - B(j,1)
y = A(i,2) - B(j,2)
z = A(i,3) - B(j,3)
C(i,j) = x*x + y*y + z*z
<span style="color: #a020f0;">end do</span>
<span style="color: #a020f0;">end do</span>
<span style="color: #a020f0;">end select</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_distance_sq_f</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
</ol>
</div>
</div>
<div id="outline-container-org4b10b43" class="outline-3">
<h3 id="org4b10b43"><span class="section-number-3">2.6</span> Atomic Orbitals</h3>
<div class="outline-text-3" id="text-2-6">
<p>
This files contains all the routines for the computation of the
values, gradients and Laplacian of the atomic basis functions.
</p>
<p>
3 files are produced:
</p>
<ul class="org-ul">
<li>a source file : <code>qmckl_ao.f90</code></li>
<li>a <a href="#org1ac3923">C</a> test file : <code>test_qmckl_ao.c</code></li>
<li>a <a href="#org3c7e28c">Fortran</a> test file : <code>test_qmckl_ao_f.f90</code></li>
</ul>
</div>
<div id="outline-container-org4cd630b" class="outline-4">
<h4 id="org4cd630b"><span class="section-number-4">2.6.1</span> Polynomials</h4>
<div class="outline-text-4" id="text-2-6-1">
<p>
\[
P_l(\mathbf{r},\mathbf{R}_i) = (x-X_i)^a (y-Y_i)^b (z-Z_i)^c
\]
</p>
\begin{eqnarray*}
\frac{\partial }{\partial x} P_l\left(\mathbf{r},\mathbf{R}_i \right) &
= & a (x-X_i)^{a-1} (y-Y_i)^b (z-Z_i)^c \\
\frac{\partial }{\partial y} P_l\left(\mathbf{r},\mathbf{R}_i \right) &
= & b (x-X_i)^a (y-Y_i)^{b-1} (z-Z_i)^c \\
\frac{\partial }{\partial z} P_l\left(\mathbf{r},\mathbf{R}_i \right) &
= & c (x-X_i)^a (y-Y_i)^b (z-Z_i)^{c-1} \\
\end{eqnarray*}
\begin{eqnarray*}
\left( \frac{\partial }{\partial x^2} +
\frac{\partial }{\partial y^2} +
\frac{\partial }{\partial z^2} \right) P_l
\left(\mathbf{r},\mathbf{R}_i \right) & = &
a(a-1) (x-X_i)^{a-2} (y-Y_i)^b (z-Z_i)^c + \\
&& b(b-1) (x-X_i)^a (y-Y_i)^{b-1} (z-Z_i)^c + \\
&& c(c-1) (x-X_i)^a (y-Y_i)^b (z-Z_i)^{c-1}
\end{eqnarray*}
</div>
<ol class="org-ol">
<li><a id="org51a87e1"></a><code>qmckl_ao_power</code><br />
<div class="outline-text-5" id="text-2-6-1-1">
<p>
Computes all the powers of the <code>n</code> input data up to the given
maximum value given in input for each of the \(n\) points:
</p>
<p>
\[ P_{ij} = X_j^i \]
</p>
</div>
<ol class="org-ol">
<li><a id="org5fccb91"></a>Arguments<br />
<div class="outline-text-6" id="text-2-6-1-1-1">
<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>
<tbody>
<tr>
<td class="org-left"><code>context</code></td>
<td class="org-left">input</td>
<td class="org-left">Global state</td>
</tr>
<tr>
<td class="org-left"><code>n</code></td>
<td class="org-left">input</td>
<td class="org-left">Number of values</td>
</tr>
<tr>
<td class="org-left"><code>X(n)</code></td>
<td class="org-left">input</td>
<td class="org-left">Array containing the input values</td>
</tr>
<tr>
<td class="org-left"><code>LMAX(n)</code></td>
<td class="org-left">input</td>
<td class="org-left">Array containing the maximum power for each value</td>
</tr>
<tr>
<td class="org-left"><code>P(LDP,n)</code></td>
<td class="org-left">output</td>
<td class="org-left">Array containing all the powers of <code>X</code></td>
</tr>
<tr>
<td class="org-left"><code>LDP</code></td>
<td class="org-left">input</td>
<td class="org-left">Leading dimension of array <code>P</code></td>
</tr>
</tbody>
</table>
</div>
</li>
<li><a id="org48d7275"></a>Requirements<br />
<div class="outline-text-6" id="text-2-6-1-1-2">
<ul class="org-ul">
<li><code>context</code> is not 0</li>
<li><code>n</code> &gt; 0</li>
<li><code>X</code> is allocated with at least \(n \times 8\) bytes</li>
<li><code>LMAX</code> is allocated with at least \(n \times 4\) bytes</li>
<li><code>P</code> is allocated with at least \(n \times \max_i \text{LMAX}_i \times 8\) bytes</li>
<li><code>LDP</code> &gt;= \(\max_i\) <code>LMAX[i]</code></li>
</ul>
</div>
</li>
<li><a id="orgc9a822f"></a>Header<br />
<div class="outline-text-6" id="text-2-6-1-1-3">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_ao_power</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;">int64_t</span> <span style="color: #a0522d;">n</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> *<span style="color: #a0522d;">X</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> *<span style="color: #a0522d;">LMAX</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> *<span style="color: #a0522d;">P</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">LDP</span>);
</pre>
</div>
</div>
</li>
<li><a id="orgc5e9837"></a>Source<br />
<div class="outline-text-6" id="text-2-6-1-1-4">
<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_ao_power_f</span><span style="color: #000000; background-color: #ffffff;">(context, n, X, LMAX, P, ldp) result(info)</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>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> n</span>
<span style="color: #228b22;">real</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> X(n)</span>
<span style="color: #228b22;">integer</span> , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> LMAX(n)</span>
<span style="color: #228b22;">real</span>*8 , <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> P(ldp,n)</span>
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> ldp</span>
<span style="color: #228b22;">integer</span>*8 ::<span style="color: #a0522d;"> i,j</span>
info = 0
<span style="color: #a020f0;">if</span> (context == 0_8) <span style="color: #a020f0;">then</span>
info = -1
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (LDP &lt; <span style="color: #a020f0;">MAXVAL</span>(LMAX)) <span style="color: #a020f0;">then</span>
info = -2
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">do</span> j=1,n
P(1,j) = X(j)
<span style="color: #a020f0;">do</span> i=2,LMAX(j)
P(i,j) = P(i-1,j) * X(j)
<span style="color: #a020f0;">end do</span>
<span style="color: #a020f0;">end do</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_ao_power_f</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
<li><a id="org5aea68f"></a><code>qmckl_ao_polynomial_vgl</code><br />
<div class="outline-text-5" id="text-2-6-1-2">
<p>
Computes the values, gradients and Laplacians at a given point of
all polynomials with an angular momentum up to <code>lmax</code>.
</p>
</div>
<ol class="org-ol">
<li><a id="org52f18c5"></a>Arguments<br />
<div class="outline-text-6" id="text-2-6-1-2-1">
<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>
<tbody>
<tr>
<td class="org-left"><code>context</code></td>
<td class="org-left">input</td>
<td class="org-left">Global state</td>
</tr>
<tr>
<td class="org-left"><code>X(3)</code></td>
<td class="org-left">input</td>
<td class="org-left">Array containing the coordinates of the points</td>
</tr>
<tr>
<td class="org-left"><code>R(3)</code></td>
<td class="org-left">input</td>
<td class="org-left">Array containing the x,y,z coordinates of the center</td>
</tr>
<tr>
<td class="org-left"><code>lmax</code></td>
<td class="org-left">input</td>
<td class="org-left">Maximum angular momentum</td>
</tr>
<tr>
<td class="org-left"><code>n</code></td>
<td class="org-left">output</td>
<td class="org-left">Number of computed polynomials</td>
</tr>
<tr>
<td class="org-left"><code>L(ldl,n)</code></td>
<td class="org-left">output</td>
<td class="org-left">Contains a,b,<a href="#org1ac3923">c</a> for all <code>n</code> results</td>
</tr>
<tr>
<td class="org-left"><code>ldl</code></td>
<td class="org-left">input</td>
<td class="org-left">Leading dimension of <code>L</code></td>
</tr>
<tr>
<td class="org-left"><code>VGL(ldv,n)</code></td>
<td class="org-left">output</td>
<td class="org-left">Value, gradients and Laplacian of the polynomials</td>
</tr>
<tr>
<td class="org-left"><code>ldv</code></td>
<td class="org-left">input</td>
<td class="org-left">Leading dimension of array <code>VGL</code></td>
</tr>
</tbody>
</table>
</div>
</li>
<li><a id="orga1a20e9"></a>Requirements<br />
<div class="outline-text-6" id="text-2-6-1-2-2">
<ul class="org-ul">
<li><code>context</code> is not 0</li>
<li><code>n</code> &gt; 0</li>
<li><code>lmax</code> &gt;= 0</li>
<li><code>ldl</code> &gt;= 3</li>
<li><code>ldv</code> &gt;= 5</li>
<li><code>X</code> is allocated with at least \(3 \times 8\) bytes</li>
<li><code>R</code> is allocated with at least \(3 \times 8\) bytes</li>
<li><code>n</code> &gt;= <code>(lmax+1)(lmax+2)(lmax+3)/6</code></li>
<li><code>L</code> is allocated with at least \(3 \times n \times 4\) bytes</li>
<li><code>VGL</code> is allocated with at least \(5 \times n \times 8\) bytes</li>
<li>On output, <code>n</code> should be equal to <code>(lmax+1)(lmax+2)(lmax+3)/6</code></li>
<li>On output, the powers are given in the following order (l=a+b+<a href="#org1ac3923">c</a>):
<ul class="org-ul">
<li>Increase values of <code>l</code></li>
<li>Within a given value of <code>l</code>, alphabetical order of the
string made by a*"x" + b*"y" + <a href="#org1ac3923">c</a>*"z" (in Python notation).
For example, with a=0, b=2 and <a href="#org1ac3923">c</a>=1 the string is "yyz"</li>
</ul></li>
</ul>
</div>
</li>
<li><a id="org1907b60"></a>Error codes<br />
<div class="outline-text-6" id="text-2-6-1-2-3">
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-right" />
<col class="org-left" />
</colgroup>
<tbody>
<tr>
<td class="org-right">-1</td>
<td class="org-left">Null <a href="#org79dde7e">context</a></td>
</tr>
<tr>
<td class="org-right">-2</td>
<td class="org-left">Inconsistent <code>ldl</code></td>
</tr>
<tr>
<td class="org-right">-3</td>
<td class="org-left">Inconsistent <code>ldv</code></td>
</tr>
<tr>
<td class="org-right">-4</td>
<td class="org-left">Inconsistent <code>lmax</code></td>
</tr>
</tbody>
</table>
</div>
</li>
<li><a id="org6389692"></a>Header<br />
<div class="outline-text-6" id="text-2-6-1-2-4">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_ao_polynomial_vgl</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;">double</span> *<span style="color: #a0522d;">X</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> *<span style="color: #a0522d;">R</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">lmax</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> *<span style="color: #a0522d;">n</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> *<span style="color: #a0522d;">L</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">ldl</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> *<span style="color: #a0522d;">VGL</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">ldv</span>);
</pre>
</div>
</div>
</li>
<li><a id="org6e66fed"></a>Source<br />
<div class="outline-text-6" id="text-2-6-1-2-5">
<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_ao_polynomial_vgl_f</span><span style="color: #000000; background-color: #ffffff;">(context, X, R, lmax, n, L, ldl, VGL, ldv) result(info)</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;">real</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> X(3), R(3)</span>
<span style="color: #228b22;">integer</span> , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> lmax</span>
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> n</span>
<span style="color: #228b22;">integer</span> , <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> L(ldl,(lmax+1)*(lmax+2)*(lmax+3)/6)</span>
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> ldl</span>
<span style="color: #228b22;">real</span>*8 , <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> VGL(ldv,(lmax+1)*(lmax+2)*(lmax+3)/6)</span>
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> ldv</span>
<span style="color: #228b22;">integer</span>*8 ::<span style="color: #a0522d;"> i,j</span>
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> a,b,c,d</span>
<span style="color: #228b22;">real</span>*8 ::<span style="color: #a0522d;"> Y(3)</span>
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> lmax_array(3)</span>
<span style="color: #228b22;">real</span>*8 ::<span style="color: #a0522d;"> pows(-2:lmax,3)</span>
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">external</span> ::<span style="color: #a0522d;"> qmckl_ao_power_f</span>
<span style="color: #228b22;">double precision</span> ::<span style="color: #a0522d;"> xy, yz, xz</span>
<span style="color: #228b22;">double precision</span> ::<span style="color: #a0522d;"> da, db, dc, dd</span>
info = 0
<span style="color: #a020f0;">if</span> (context == 0_8) <span style="color: #a020f0;">then</span>
info = -1
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (ldl &lt; 3) <span style="color: #a020f0;">then</span>
info = -2
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (ldv &lt; 5) <span style="color: #a020f0;">then</span>
info = -3
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (lmax &lt;= 0) <span style="color: #a020f0;">then</span>
info = -4
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">do</span> i=1,3
Y(i) = X(i) - R(i)
<span style="color: #a020f0;">end do</span>
lmax_array(1:3) = lmax
<span style="color: #a020f0;">if</span> (lmax == 0) <span style="color: #a020f0;">then</span>
VGL(1,1) = 1.d0
vgL(2:5,1) = 0.d0
l(1:3,1) = 0
n=1
<span style="color: #a020f0;">else if</span> (lmax &gt; 0) <span style="color: #a020f0;">then</span>
pows(-2:0,1:3) = 1.d0
<span style="color: #a020f0;">do</span> i=1,lmax
pows(i,1) = pows(i-1,1) * Y(1)
pows(i,2) = pows(i-1,2) * Y(2)
pows(i,3) = pows(i-1,3) * Y(3)
<span style="color: #a020f0;">end do</span>
VGL(1:5,1:4) = 0.d0
l(1:3,1:4) = 0
VGL(1,1) = 1.d0
vgl(1:5,2:4) = 0.d0
l(1,2) = 1
vgl(1,2) = pows(1,1)
vgL(2,2) = 1.d0
l(2,3) = 1
vgl(1,3) = pows(1,2)
vgL(3,3) = 1.d0
l(3,4) = 1
vgl(1,4) = pows(1,3)
vgL(4,4) = 1.d0
n=4
<span style="color: #a020f0;">endif</span>
! <span style="color: #b22222;">l&gt;=2</span>
dd = 2.d0
<span style="color: #a020f0;">do</span> d=2,lmax
da = dd
<span style="color: #a020f0;">do</span> a=d,0,-1
db = dd-da
<span style="color: #a020f0;">do</span> b=d-a,0,-1
c = d - a - b
dc = dd - da - db
n = n+1
l(1,n) = a
l(2,n) = b
l(3,n) = c
xy = pows(a,1) * pows(b,2)
yz = pows(b,2) * pows(c,3)
xz = pows(a,1) * pows(c,3)
vgl(1,n) = xy * pows(c,3)
xy = dc * xy
xz = db * xz
yz = da * yz
vgl(2,n) = pows(a-1,1) * yz
vgl(3,n) = pows(b-1,2) * xz
vgl(4,n) = pows(c-1,3) * xy
vgl(5,n) = <span style="color: #a020f0;">&amp;</span>
(da-1.d0) * pows(a-2,1) * yz + <span style="color: #a020f0;">&amp;</span>
(db-1.d0) * pows(b-2,2) * xz + <span style="color: #a020f0;">&amp;</span>
(dc-1.d0) * pows(c-2,3) * xy
db = db - 1.d0
<span style="color: #a020f0;">end do</span>
da = da - 1.d0
<span style="color: #a020f0;">end do</span>
dd = dd + 1.d0
<span style="color: #a020f0;">end do</span>
info = 0
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_ao_polynomial_vgl_f</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
</ol>
</div>
<div id="outline-container-orgf9b8419" class="outline-4">
<h4 id="orgf9b8419"><span class="section-number-4">2.6.2</span> Gaussian basis functions</h4>
<div class="outline-text-4" id="text-2-6-2">
</div>
<ol class="org-ol">
<li><a id="org3064e25"></a><code>qmckl_ao_gaussian_vgl</code><br />
<div class="outline-text-5" id="text-2-6-2-1">
<p>
Computes the values, gradients and Laplacians at a given point of
<code>n</code> Gaussian functions centered at the same point:
</p>
<p>
\[ v_i = \exp(-a_i |X-R|^2) \]
\[ \nabla_x v_i = -2 a_i (X_x - R_x) v_i \]
\[ \nabla_y v_i = -2 a_i (X_y - R_y) v_i \]
\[ \nabla_z v_i = -2 a_i (X_z - R_z) v_i \]
\[ \Delta v_i = a_i (4 |X-R|^2 a_i - 6) v_i \]
</p>
</div>
<ol class="org-ol">
<li><a id="org90bee7c"></a>Arguments<br />
<div class="outline-text-6" id="text-2-6-2-1-1">
<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>
<tbody>
<tr>
<td class="org-left"><code>context</code></td>
<td class="org-left">input</td>
<td class="org-left">Global state</td>
</tr>
<tr>
<td class="org-left"><code>X(3)</code></td>
<td class="org-left">input</td>
<td class="org-left">Array containing the coordinates of the points</td>
</tr>
<tr>
<td class="org-left"><code>R(3)</code></td>
<td class="org-left">input</td>
<td class="org-left">Array containing the x,y,z coordinates of the center</td>
</tr>
<tr>
<td class="org-left"><code>n</code></td>
<td class="org-left">input</td>
<td class="org-left">Number of computed gaussians</td>
</tr>
<tr>
<td class="org-left"><code>A(n)</code></td>
<td class="org-left">input</td>
<td class="org-left">Exponents of the Gaussians</td>
</tr>
<tr>
<td class="org-left"><code>VGL(ldv,5)</code></td>
<td class="org-left">output</td>
<td class="org-left">Value, gradients and Laplacian of the Gaussians</td>
</tr>
<tr>
<td class="org-left"><code>ldv</code></td>
<td class="org-left">input</td>
<td class="org-left">Leading dimension of array <code>VGL</code></td>
</tr>
</tbody>
</table>
</div>
</li>
<li><a id="org8047a4d"></a>Requirements<br />
<div class="outline-text-6" id="text-2-6-2-1-2">
<ul class="org-ul">
<li><code>context</code> is not 0</li>
<li><code>n</code> &gt; 0</li>
<li><code>ldv</code> &gt;= 5</li>
<li><code>A(i)</code> &gt; 0 for all <code>i</code></li>
<li><code>X</code> is allocated with at least \(3 \times 8\) bytes</li>
<li><code>R</code> is allocated with at least \(3 \times 8\) bytes</li>
<li><code>A</code> is allocated with at least \(n \times 8\) bytes</li>
<li><code>VGL</code> is allocated with at least \(n \times 5 \times 8\) bytes</li>
</ul>
</div>
</li>
<li><a id="org0a3b812"></a>Header<br />
<div class="outline-text-6" id="text-2-6-2-1-3">
<div class="org-src-container">
<pre class="src src-C"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_ao_gaussian_vgl</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;">double</span> *<span style="color: #a0522d;">X</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> *<span style="color: #a0522d;">R</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> *<span style="color: #a0522d;">n</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> *<span style="color: #a0522d;">A</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> *<span style="color: #a0522d;">VGL</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">ldv</span>);
</pre>
</div>
</div>
</li>
<li><a id="orgb4b750d"></a>Source<br />
<div class="outline-text-6" id="text-2-6-2-1-4">
<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_ao_gaussian_vgl_f</span><span style="color: #000000; background-color: #ffffff;">(context, X, R, n, A, VGL, ldv) result(info)</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;">real</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> X(3), R(3)</span>
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> n</span>
<span style="color: #228b22;">real</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> A(n)</span>
<span style="color: #228b22;">real</span>*8 , <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> VGL(ldv,5)</span>
<span style="color: #228b22;">integer</span>*8 , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> ldv</span>
<span style="color: #228b22;">integer</span>*8 ::<span style="color: #a0522d;"> i,j</span>
<span style="color: #228b22;">real</span>*8 ::<span style="color: #a0522d;"> Y(3), r2, t, u, v</span>
info = 0
<span style="color: #a020f0;">if</span> (context == 0_8) <span style="color: #a020f0;">then</span>
info = -1
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (n &lt;= 0) <span style="color: #a020f0;">then</span>
info = -2
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">if</span> (ldv &lt; n) <span style="color: #a020f0;">then</span>
info = -3
<span style="color: #a020f0;">return</span>
<span style="color: #a020f0;">endif</span>
<span style="color: #a020f0;">do</span> i=1,3
Y(i) = X(i) - R(i)
<span style="color: #a020f0;">end do</span>
r2 = Y(1)*Y(1) + Y(2)*Y(2) + Y(3)*Y(3)
<span style="color: #a020f0;">do</span> i=1,n
VGL(i,1) = dexp(-A(i) * r2)
<span style="color: #a020f0;">end do</span>
<span style="color: #a020f0;">do</span> i=1,n
VGL(i,5) = A(i) * VGL(i,1)
<span style="color: #a020f0;">end do</span>
t = -2.d0 * ( X(1) - R(1) )
u = -2.d0 * ( X(2) - R(2) )
v = -2.d0 * ( X(3) - R(3) )
<span style="color: #a020f0;">do</span> i=1,n
VGL(i,2) = t * VGL(i,5)
VGL(i,3) = u * VGL(i,5)
VGL(i,4) = v * VGL(i,5)
<span style="color: #a020f0;">end do</span>
t = 4.d0 * r2
<span style="color: #a020f0;">do</span> i=1,n
VGL(i,5) = (t * A(i) - 6.d0) * VGL(i,5)
<span style="color: #a020f0;">end do</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_ao_gaussian_vgl_f</span>
</pre>
</div>
</div>
</li>
</ol>
</li>
</ol>
</div>
<div id="outline-container-org930fc7a" class="outline-4">
<h4 id="org930fc7a"><span class="section-number-4">2.6.3</span> <span class="todo TODO">TODO</span> Slater basis functions</h4>
</div>
</div>
</div>
<div id="outline-container-org9472ec5" class="outline-2">
<h2 id="org9472ec5"><span class="section-number-2">3</span> Acknowledgments</h2>
<div class="outline-text-2" id="text-3">
<p>
<img src="https://trex-coe.eu/sites/default/files/inline-images/euflag.jpg" alt="euflag.jpg" />
<a href="https://trex-coe.eu">TREX: Targeting Real Chemical Accuracy at the Exascale</a> project has received funding from the European Unions Horizon 2020 - Research and Innovation program - under grant agreement no. 952165. The content of this document does not represent the opinion of the European Union, and the European Union is not responsible for any use that might be made of such content.
</p>
</div>
</div>
</div>
<div id="postamble" class="status">
<p class="date">Created: 2021-03-06 Sat 22:28</p>
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
</body>
</html>