<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://e6.ijs.si/medusa/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mkolman</id>
		<title>Medusa: Coordinate Free Mehless Method implementation - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="http://e6.ijs.si/medusa/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mkolman"/>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php/Special:Contributions/Mkolman"/>
		<updated>2026-04-05T23:42:53Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.27.1</generator>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Quantum_Mechanics&amp;diff=1785</id>
		<title>Quantum Mechanics</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Quantum_Mechanics&amp;diff=1785"/>
				<updated>2018-01-11T13:55:40Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Particle in a box */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The quantum world is governed by the [https://en.wikipedia.org/wiki/Schr%C3%B6dinger_equation Schrödinger equation]&lt;br /&gt;
&lt;br /&gt;
\[{\displaystyle {\hat {H}}|\psi (t)\rangle =i\hbar {\frac {\partial }{\partial t}}|\psi (t)\rangle } \]&lt;br /&gt;
&lt;br /&gt;
where $\hat H$ is the [https://en.wikipedia.org/wiki/Hamiltonian_(quantum_mechanics) Hamiltonian], $|\psi (t)\rangle$ is the [https://en.wikipedia.org/wiki/Wave_function quantum state function] and $\hbar$ is the reduced [https://en.wikipedia.org/wiki/Planck_constant Planck constant].&lt;br /&gt;
&lt;br /&gt;
The Hamiltonian consists of kinetic energy $\hat T$ and potential energy $\hat V$. As in classical mechanics, potential energy is a function of time and space, whereas the kinetic energy differs from the classical world and is calculated as&lt;br /&gt;
&lt;br /&gt;
\[\hat T = - \frac{\hbar^2}{2m} \nabla^2 .\]&lt;br /&gt;
&lt;br /&gt;
The final version of the single particle Schrödinger equation can be written as&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
\[\left(- \frac{\hbar^2}{2m} \nabla^2 + V(t, \mathbf r)\right) \psi(t, \mathbf r) = i\hbar {\frac {\partial }{\partial t}}\psi(t, \mathbf r) \]&lt;br /&gt;
&lt;br /&gt;
Quantum state function is a complex function, so it is usually split into the real part and imaginary part&lt;br /&gt;
&lt;br /&gt;
\[ u, v \in C(\mathbb R)\colon \psi = u + i v , \]&lt;br /&gt;
&lt;br /&gt;
which for a real $V$ yields a system of two real equations&lt;br /&gt;
&lt;br /&gt;
\[\left(- \frac{\hbar^2}{2m} \nabla^2 + V(t, \mathbf r)\right) u(t, \mathbf r) = -\hbar {\frac {\partial }{\partial t}} v(t, \mathbf r) , \]&lt;br /&gt;
\[\left(- \frac{\hbar^2}{2m} \nabla^2 + V(t, \mathbf r)\right) v(t, \mathbf r) = \hbar {\frac {\partial }{\partial t}} u(t, \mathbf r) , \]&lt;br /&gt;
&lt;br /&gt;
which may be easier to handle.&lt;br /&gt;
&lt;br /&gt;
= Harmonic oscilator =&lt;br /&gt;
&lt;br /&gt;
By selecting the potential $V(t, \mathbf r)$ and the initial state $\psi(0, \mathbf r)$ we get a unique solution for time propagation of the quantum state function. Probably the most used and well known example is the quantum harmonic oscilator, where we select a quadratic potential&lt;br /&gt;
&lt;br /&gt;
\[V(t, \mathbf r) = V(\mathbf r) = \frac{1}{2} m \omega^2 r^2 , \]&lt;br /&gt;
&lt;br /&gt;
where $m$ is the mass of the particle and $\omega$ is the angular frequency of the oscilator.&lt;br /&gt;
&lt;br /&gt;
The 1D harmonic oscilator has known eigenstate solutions&lt;br /&gt;
&lt;br /&gt;
\[\psi _{n}(x)={\frac {1}{\sqrt {2^{n}\,n!}}}\cdot \left({\frac {m\omega }{\pi \hbar }}\right)^{1/4}\cdot e^{-{\frac {m\omega x^{2}}{2\hbar }}}\cdot H_{n}\left({\sqrt {\frac {m\omega }{\hbar }}}x\right),\qquad n=0,1,2,\ldots .\]&lt;br /&gt;
&lt;br /&gt;
where the functions $H_n$ are the physicists' [https://en.wikipedia.org/wiki/Hermite_polynomials Hermite polynomials]. Time propagation of eigenstates is described with&lt;br /&gt;
&lt;br /&gt;
\[\psi_n(t, x) = \mathrm e ^ {-i (n+0.5)  \omega t} \psi_n(x)\]&lt;br /&gt;
&lt;br /&gt;
= Particle in a box =&lt;br /&gt;
&lt;br /&gt;
A theoretical one dimensional potential&lt;br /&gt;
&lt;br /&gt;
\[\displaystyle V(x)={\begin{cases}0,&amp;amp;0&amp;lt;x&amp;lt;L,\\\infty ,&amp;amp;{\text{otherwise,}}\end{cases}}\]&lt;br /&gt;
&lt;br /&gt;
is known as an infinite potential well. Its time independent eigenfunctions are&lt;br /&gt;
&lt;br /&gt;
\[\sqrt{\frac{2}{L}}\psi_n(x) = \sin\left(k_n x \right), \qquad n = 1,2,3,...\]&lt;br /&gt;
&lt;br /&gt;
where $k_n = \frac{\pi n}{L}$. With a time dependency similar to Harmonic oscilator&lt;br /&gt;
&lt;br /&gt;
\[\psi_n(t, x) = \mathrm e ^ {-i \omega_n t} \psi_n(x),\]&lt;br /&gt;
&lt;br /&gt;
where $\omega_n$ and $k_n$ are connected through dispersion relation through energy $E_n$&lt;br /&gt;
&lt;br /&gt;
\[{\displaystyle E_{n}=\hbar \omega _{n}={\frac {n^{2}\pi ^{2}\hbar ^{2}}{2mL^{2}}}={\frac {\hbar ^{2} k_n^2}{2m}}}.\]&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Quantum_Mechanics&amp;diff=1784</id>
		<title>Quantum Mechanics</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Quantum_Mechanics&amp;diff=1784"/>
				<updated>2018-01-11T13:39:27Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The quantum world is governed by the [https://en.wikipedia.org/wiki/Schr%C3%B6dinger_equation Schrödinger equation]&lt;br /&gt;
&lt;br /&gt;
\[{\displaystyle {\hat {H}}|\psi (t)\rangle =i\hbar {\frac {\partial }{\partial t}}|\psi (t)\rangle } \]&lt;br /&gt;
&lt;br /&gt;
where $\hat H$ is the [https://en.wikipedia.org/wiki/Hamiltonian_(quantum_mechanics) Hamiltonian], $|\psi (t)\rangle$ is the [https://en.wikipedia.org/wiki/Wave_function quantum state function] and $\hbar$ is the reduced [https://en.wikipedia.org/wiki/Planck_constant Planck constant].&lt;br /&gt;
&lt;br /&gt;
The Hamiltonian consists of kinetic energy $\hat T$ and potential energy $\hat V$. As in classical mechanics, potential energy is a function of time and space, whereas the kinetic energy differs from the classical world and is calculated as&lt;br /&gt;
&lt;br /&gt;
\[\hat T = - \frac{\hbar^2}{2m} \nabla^2 .\]&lt;br /&gt;
&lt;br /&gt;
The final version of the single particle Schrödinger equation can be written as&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
\[\left(- \frac{\hbar^2}{2m} \nabla^2 + V(t, \mathbf r)\right) \psi(t, \mathbf r) = i\hbar {\frac {\partial }{\partial t}}\psi(t, \mathbf r) \]&lt;br /&gt;
&lt;br /&gt;
Quantum state function is a complex function, so it is usually split into the real part and imaginary part&lt;br /&gt;
&lt;br /&gt;
\[ u, v \in C(\mathbb R)\colon \psi = u + i v , \]&lt;br /&gt;
&lt;br /&gt;
which for a real $V$ yields a system of two real equations&lt;br /&gt;
&lt;br /&gt;
\[\left(- \frac{\hbar^2}{2m} \nabla^2 + V(t, \mathbf r)\right) u(t, \mathbf r) = -\hbar {\frac {\partial }{\partial t}} v(t, \mathbf r) , \]&lt;br /&gt;
\[\left(- \frac{\hbar^2}{2m} \nabla^2 + V(t, \mathbf r)\right) v(t, \mathbf r) = \hbar {\frac {\partial }{\partial t}} u(t, \mathbf r) , \]&lt;br /&gt;
&lt;br /&gt;
which may be easier to handle.&lt;br /&gt;
&lt;br /&gt;
= Harmonic oscilator =&lt;br /&gt;
&lt;br /&gt;
By selecting the potential $V(t, \mathbf r)$ and the initial state $\psi(0, \mathbf r)$ we get a unique solution for time propagation of the quantum state function. Probably the most used and well known example is the quantum harmonic oscilator, where we select a quadratic potential&lt;br /&gt;
&lt;br /&gt;
\[V(t, \mathbf r) = V(\mathbf r) = \frac{1}{2} m \omega^2 r^2 , \]&lt;br /&gt;
&lt;br /&gt;
where $m$ is the mass of the particle and $\omega$ is the angular frequency of the oscilator.&lt;br /&gt;
&lt;br /&gt;
The 1D harmonic oscilator has known eigenstate solutions&lt;br /&gt;
&lt;br /&gt;
\[\psi _{n}(x)={\frac {1}{\sqrt {2^{n}\,n!}}}\cdot \left({\frac {m\omega }{\pi \hbar }}\right)^{1/4}\cdot e^{-{\frac {m\omega x^{2}}{2\hbar }}}\cdot H_{n}\left({\sqrt {\frac {m\omega }{\hbar }}}x\right),\qquad n=0,1,2,\ldots .\]&lt;br /&gt;
&lt;br /&gt;
where the functions $H_n$ are the physicists' [https://en.wikipedia.org/wiki/Hermite_polynomials Hermite polynomials]. Time propagation of eigenstates is described with&lt;br /&gt;
&lt;br /&gt;
\[\psi_n(t, x) = \mathrm e ^ {-i (n+0.5)  \omega t} \psi_n(x)\]&lt;br /&gt;
&lt;br /&gt;
= Particle in a box =&lt;br /&gt;
&lt;br /&gt;
A theoretical one dimensional potential&lt;br /&gt;
&lt;br /&gt;
\[\displaystyle V(x)={\begin{cases}0,&amp;amp;0&amp;lt;x&amp;lt;L,\\\infty ,&amp;amp;{\text{otherwise,}}\end{cases}}\]&lt;br /&gt;
&lt;br /&gt;
is known as an infinite potential well. Its time independent eigenfunctions are&lt;br /&gt;
&lt;br /&gt;
\[\sqrt{\frac{2}{L}}\psi_n(x) = \sin\left(k_n x \right), \qquad n = 1,2,3,...\]&lt;br /&gt;
&lt;br /&gt;
where $k_n = \frac{\pi n}{L}$. With a time dependency similar to Harmonic oscilator&lt;br /&gt;
&lt;br /&gt;
\[\psi_n(t, x) = \mathrm e ^ {-i \omega_n t} \psi_n(x),\]&lt;br /&gt;
&lt;br /&gt;
where $\omega_n$ and $k_n$ are connected through dispersion relation through energy $E_n$&lt;br /&gt;
&lt;br /&gt;
\[{\displaystyle E_{n}=\hbar \omega _{n}={\frac {n^{2}\pi ^{2}\hbar ^{2}}{2mL^{2}}}={\frac {\hbar ^{2} k_n^2}{2m}}}\]&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Quantum_Mechanics&amp;diff=1783</id>
		<title>Quantum Mechanics</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Quantum_Mechanics&amp;diff=1783"/>
				<updated>2018-01-11T12:38:27Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The quantum world is governed by the [https://en.wikipedia.org/wiki/Schr%C3%B6dinger_equation Schrödinger equation]&lt;br /&gt;
&lt;br /&gt;
\[{\displaystyle {\hat {H}}|\psi (t)\rangle =i\hbar {\frac {\partial }{\partial t}}|\psi (t)\rangle } \]&lt;br /&gt;
&lt;br /&gt;
where $\hat H$ is the [https://en.wikipedia.org/wiki/Hamiltonian_(quantum_mechanics) Hamiltonian], $|\psi (t)\rangle$ is the [https://en.wikipedia.org/wiki/Wave_function quantum state function] and $\hbar$ is the reduced [https://en.wikipedia.org/wiki/Planck_constant Planck constant].&lt;br /&gt;
&lt;br /&gt;
The Hamiltonian consists of kinetic energy $\hat T$ and potential energy $\hat V$. As in classical mechanics, potential energy is a function of time and space, whereas the kinetic energy differs from the classical world and is calculated as&lt;br /&gt;
&lt;br /&gt;
\[\hat T = - \frac{\hbar^2}{2m} \nabla^2 .\]&lt;br /&gt;
&lt;br /&gt;
The final version of the single particle Schrödinger equation can be written as&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
\[\left(- \frac{\hbar^2}{2m} \nabla^2 + V(t, \mathbf r)\right) \psi(t, \mathbf r) = i\hbar {\frac {\partial }{\partial t}}\psi(t, \mathbf r) \]&lt;br /&gt;
&lt;br /&gt;
Quantum state function is a complex function, so it is usually split into the real part and imaginary part&lt;br /&gt;
&lt;br /&gt;
\[ u, v \in C(\mathbb R)\colon \psi = u + i v , \]&lt;br /&gt;
&lt;br /&gt;
which for a real $V$ yields a system of two real equations&lt;br /&gt;
&lt;br /&gt;
\[\left(- \frac{\hbar^2}{2m} \nabla^2 + V(t, \mathbf r)\right) u(t, \mathbf r) = -\hbar {\frac {\partial }{\partial t}} v(t, \mathbf r) , \]&lt;br /&gt;
\[\left(- \frac{\hbar^2}{2m} \nabla^2 + V(t, \mathbf r)\right) v(t, \mathbf r) = \hbar {\frac {\partial }{\partial t}} u(t, \mathbf r) , \]&lt;br /&gt;
&lt;br /&gt;
which may be easier to handle.&lt;br /&gt;
&lt;br /&gt;
= Harmonic oscilator =&lt;br /&gt;
&lt;br /&gt;
By selecting the potential $V(t, \mathbf r)$ and the initial state $\psi(0, \mathbf r)$ we get a unique solution for time propagation of the quantum state function. Probably the most used and well known example is the quantum harmonic oscilator, where we select a quadratic potential&lt;br /&gt;
&lt;br /&gt;
\[V(t, \mathbf r) = V(\mathbf r) = \frac{1}{2} m \omega^2 r^2 , \]&lt;br /&gt;
&lt;br /&gt;
where $m$ is the mass of the particle and $\omega$ is the angular frequency of the oscilator.&lt;br /&gt;
&lt;br /&gt;
The 1D harmonic oscilator has known eigenstate solutions&lt;br /&gt;
&lt;br /&gt;
\[\psi _{n}(x)={\frac {1}{\sqrt {2^{n}\,n!}}}\cdot \left({\frac {m\omega }{\pi \hbar }}\right)^{1/4}\cdot e^{-{\frac {m\omega x^{2}}{2\hbar }}}\cdot H_{n}\left({\sqrt {\frac {m\omega }{\hbar }}}x\right),\qquad n=0,1,2,\ldots .\]&lt;br /&gt;
&lt;br /&gt;
where the functions $H_n$ are the physicists' [https://en.wikipedia.org/wiki/Hermite_polynomials Hermite polynomials]. Time propagation of eigenstates is described with&lt;br /&gt;
&lt;br /&gt;
\[\psi_n(t, x) = \mathrm e ^ {-i (n+0.5)  \omega t} \psi_n(x)\]&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Quantum_Mechanics&amp;diff=1782</id>
		<title>Quantum Mechanics</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Quantum_Mechanics&amp;diff=1782"/>
				<updated>2017-12-21T15:45:30Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Harmonic oscilator */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The quantum world is governed by the [https://en.wikipedia.org/wiki/Schr%C3%B6dinger_equation Schrödinger equation]&lt;br /&gt;
&lt;br /&gt;
\[{\displaystyle {\hat {H}}|\psi (t)\rangle =i\hbar {\frac {\partial }{\partial t}}|\psi (t)\rangle } \]&lt;br /&gt;
&lt;br /&gt;
where $\hat H$ is the [https://en.wikipedia.org/wiki/Hamiltonian_(quantum_mechanics) Hamiltonian], $|\psi (t)\rangle$ is the [https://en.wikipedia.org/wiki/Wave_function quantum state function] and $\hbar$ is the reduced [https://en.wikipedia.org/wiki/Planck_constant Planck constant].&lt;br /&gt;
&lt;br /&gt;
The Hamiltonian consists of kinetic energy $\hat T$ and potential energy $\hat V$. As in classical mechanics, potential energy is a function of time and space, whereas the kinetic energy differs from the classical world and is calculated as&lt;br /&gt;
&lt;br /&gt;
\[\hat T = - \frac{\hbar^2}{2m} \nabla^2 .\]&lt;br /&gt;
&lt;br /&gt;
The final version of the single particle Schrödinger equation can be written as&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
\[\left(- \frac{\hbar^2}{2m} \nabla^2 + V(t, \mathbf r)\right) \psi(t, \mathbf r) = i\hbar {\frac {\partial }{\partial t}}\psi(t, \mathbf r) \]&lt;br /&gt;
&lt;br /&gt;
Quantum state function is a complex function, so it is usually split into the real part and imaginary part&lt;br /&gt;
&lt;br /&gt;
\[ u, v \in C(\mathbb R)\colon \psi = u + i v , \]&lt;br /&gt;
&lt;br /&gt;
which for a real $V$ yields a system of two real equations&lt;br /&gt;
&lt;br /&gt;
\[\left(- \frac{\hbar^2}{2m} \nabla^2 + V(t, \mathbf r)\right) u(t, \mathbf r) = -\hbar {\frac {\partial }{\partial t}} v(t, \mathbf r) , \]&lt;br /&gt;
\[\left(- \frac{\hbar^2}{2m} \nabla^2 + V(t, \mathbf r)\right) v(t, \mathbf r) = \hbar {\frac {\partial }{\partial t}} u(t, \mathbf r) , \]&lt;br /&gt;
&lt;br /&gt;
which may be easier to handle.&lt;br /&gt;
&lt;br /&gt;
= Harmonic oscilator =&lt;br /&gt;
&lt;br /&gt;
By selecting the potential $V(t, \mathbf r)$ and the initial state $\psi(0, \mathbf r)$ we get a unique solution for time propagation of the quantum state function. Probably the most used and well known example is the quantum harmonic oscilator, where we select a quadratic potential&lt;br /&gt;
&lt;br /&gt;
\[V(t, \mathbf r) = V(\mathbf r) = \frac{1}{2} m \omega^2 r^2 , \]&lt;br /&gt;
&lt;br /&gt;
where $m$ is the mass of the particle and $\omega$ is the angular frequency of the oscilator.&lt;br /&gt;
&lt;br /&gt;
The 1D harmonic oscilator has known eigenstate solutions&lt;br /&gt;
&lt;br /&gt;
\[\psi _{n}(x)={\frac {1}{\sqrt {2^{n}\,n!}}}\cdot \left({\frac {m\omega }{\pi \hbar }}\right)^{1/4}\cdot e^{-{\frac {m\omega x^{2}}{2\hbar }}}\cdot H_{n}\left({\sqrt {\frac {m\omega }{\hbar }}}x\right),\qquad n=0,1,2,\ldots .\]&lt;br /&gt;
&lt;br /&gt;
where the functions Hn are the physicists' [https://en.wikipedia.org/wiki/Hermite_polynomials Hermite polynomials].Time propagation of eigenstates is described with&lt;br /&gt;
&lt;br /&gt;
\[\psi(t, x) = \mathrm e ^ {-i\omega t} \psi(x)\]&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Quantum_Mechanics&amp;diff=1781</id>
		<title>Quantum Mechanics</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Quantum_Mechanics&amp;diff=1781"/>
				<updated>2017-12-21T15:45:14Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The quantum world is governed by the [https://en.wikipedia.org/wiki/Schr%C3%B6dinger_equation Schrödinger equation]&lt;br /&gt;
&lt;br /&gt;
\[{\displaystyle {\hat {H}}|\psi (t)\rangle =i\hbar {\frac {\partial }{\partial t}}|\psi (t)\rangle } \]&lt;br /&gt;
&lt;br /&gt;
where $\hat H$ is the [https://en.wikipedia.org/wiki/Hamiltonian_(quantum_mechanics) Hamiltonian], $|\psi (t)\rangle$ is the [https://en.wikipedia.org/wiki/Wave_function quantum state function] and $\hbar$ is the reduced [https://en.wikipedia.org/wiki/Planck_constant Planck constant].&lt;br /&gt;
&lt;br /&gt;
The Hamiltonian consists of kinetic energy $\hat T$ and potential energy $\hat V$. As in classical mechanics, potential energy is a function of time and space, whereas the kinetic energy differs from the classical world and is calculated as&lt;br /&gt;
&lt;br /&gt;
\[\hat T = - \frac{\hbar^2}{2m} \nabla^2 .\]&lt;br /&gt;
&lt;br /&gt;
The final version of the single particle Schrödinger equation can be written as&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
\[\left(- \frac{\hbar^2}{2m} \nabla^2 + V(t, \mathbf r)\right) \psi(t, \mathbf r) = i\hbar {\frac {\partial }{\partial t}}\psi(t, \mathbf r) \]&lt;br /&gt;
&lt;br /&gt;
Quantum state function is a complex function, so it is usually split into the real part and imaginary part&lt;br /&gt;
&lt;br /&gt;
\[ u, v \in C(\mathbb R)\colon \psi = u + i v , \]&lt;br /&gt;
&lt;br /&gt;
which for a real $V$ yields a system of two real equations&lt;br /&gt;
&lt;br /&gt;
\[\left(- \frac{\hbar^2}{2m} \nabla^2 + V(t, \mathbf r)\right) u(t, \mathbf r) = -\hbar {\frac {\partial }{\partial t}} v(t, \mathbf r) , \]&lt;br /&gt;
\[\left(- \frac{\hbar^2}{2m} \nabla^2 + V(t, \mathbf r)\right) v(t, \mathbf r) = \hbar {\frac {\partial }{\partial t}} u(t, \mathbf r) , \]&lt;br /&gt;
&lt;br /&gt;
which may be easier to handle.&lt;br /&gt;
&lt;br /&gt;
= Harmonic oscilator =&lt;br /&gt;
&lt;br /&gt;
By selecting the potential $V(t, \mathbf r)$ and the initial state $\psi(0, \mathbf r)$ we get a unique solution for time propagation of the quantum state function. Probably the most used and well known example is the quantum harmonic oscilator, where we select a quadratic potential&lt;br /&gt;
&lt;br /&gt;
\[V(t, \mathbf r) = V(\mathbf r) = \frac{1}{2} m \omega^2 r^2 \],&lt;br /&gt;
&lt;br /&gt;
where $m$ is the mass of the particle and $\omega$ is the angular frequency of the oscilator.&lt;br /&gt;
&lt;br /&gt;
The 1D harmonic oscilator has known eigenstate solutions&lt;br /&gt;
&lt;br /&gt;
\[\psi _{n}(x)={\frac {1}{\sqrt {2^{n}\,n!}}}\cdot \left({\frac {m\omega }{\pi \hbar }}\right)^{1/4}\cdot e^{-{\frac {m\omega x^{2}}{2\hbar }}}\cdot H_{n}\left({\sqrt {\frac {m\omega }{\hbar }}}x\right),\qquad n=0,1,2,\ldots .\],&lt;br /&gt;
&lt;br /&gt;
where the functions Hn are the physicists' [https://en.wikipedia.org/wiki/Hermite_polynomials Hermite polynomials].Time propagation of eigenstates is described with&lt;br /&gt;
&lt;br /&gt;
\[\psi(t, x) = \mathrm e ^ {-i\omega t} \psi(x)\]&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Quantum_Mechanics&amp;diff=1780</id>
		<title>Quantum Mechanics</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Quantum_Mechanics&amp;diff=1780"/>
				<updated>2017-12-21T15:44:42Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The quantum world is governed by the [https://en.wikipedia.org/wiki/Schr%C3%B6dinger_equation Schrödinger equation]&lt;br /&gt;
&lt;br /&gt;
\[{\displaystyle {\hat {H}}|\psi (t)\rangle =i\hbar {\frac {\partial }{\partial t}}|\psi (t)\rangle } \]&lt;br /&gt;
&lt;br /&gt;
where $\hat H$ is the [https://en.wikipedia.org/wiki/Hamiltonian_(quantum_mechanics) Hamiltonian], $|\psi (t)\rangle$ is the [https://en.wikipedia.org/wiki/Wave_function quantum state function] and $\hbar$ is the reduced [https://en.wikipedia.org/wiki/Planck_constant Planck constant].&lt;br /&gt;
&lt;br /&gt;
The Hamiltonian consists of kinetic energy $\hat T$ and potential energy $\hat V$. As in classical mechanics, potential energy is a function of time and space, whereas the kinetic energy differs from the classical world and is calculated as&lt;br /&gt;
&lt;br /&gt;
\[\hat T = - \frac{\hbar^2}{2m} \nabla^2 .\]&lt;br /&gt;
&lt;br /&gt;
The final version of the single particle Schrödinger equation can be written as&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
\[\left(- \frac{\hbar^2}{2m} \nabla^2 + V(t, \mathbf r)\right) \psi(t, \mathbf r) = i\hbar {\frac {\partial }{\partial t}}\psi(t, \mathbf r) \]&lt;br /&gt;
&lt;br /&gt;
Quantum state function is a complex function, so it is usually split into the real part and imaginary part&lt;br /&gt;
&lt;br /&gt;
\[ u, v \in C(\mathbb R)\colon \psi = u + i v \],&lt;br /&gt;
&lt;br /&gt;
which for a real $V$ yields a system of two real equations&lt;br /&gt;
&lt;br /&gt;
\[\left(- \frac{\hbar^2}{2m} \nabla^2 + V(t, \mathbf r)\right) u(t, \mathbf r) = -\hbar {\frac {\partial }{\partial t}} v(t, \mathbf r) \],&lt;br /&gt;
\[\left(- \frac{\hbar^2}{2m} \nabla^2 + V(t, \mathbf r)\right) v(t, \mathbf r) = \hbar {\frac {\partial }{\partial t}} u(t, \mathbf r) \],&lt;br /&gt;
&lt;br /&gt;
which may be easier to handle.&lt;br /&gt;
&lt;br /&gt;
= Harmonic oscilator =&lt;br /&gt;
&lt;br /&gt;
By selecting the potential $V(t, \mathbf r)$ and the initial state $\psi(0, \mathbf r)$ we get a unique solution for time propagation of the quantum state function. Probably the most used and well known example is the quantum harmonic oscilator, where we select a quadratic potential&lt;br /&gt;
&lt;br /&gt;
\[V(t, \mathbf r) = V(\mathbf r) = \frac{1}{2} m \omega^2 r^2 \],&lt;br /&gt;
&lt;br /&gt;
where $m$ is the mass of the particle and $\omega$ is the angular frequency of the oscilator.&lt;br /&gt;
&lt;br /&gt;
The 1D harmonic oscilator has known eigenstate solutions&lt;br /&gt;
&lt;br /&gt;
\[\psi _{n}(x)={\frac {1}{\sqrt {2^{n}\,n!}}}\cdot \left({\frac {m\omega }{\pi \hbar }}\right)^{1/4}\cdot e^{-{\frac {m\omega x^{2}}{2\hbar }}}\cdot H_{n}\left({\sqrt {\frac {m\omega }{\hbar }}}x\right),\qquad n=0,1,2,\ldots .\],&lt;br /&gt;
&lt;br /&gt;
where the functions Hn are the physicists' [https://en.wikipedia.org/wiki/Hermite_polynomials Hermite polynomials].Time propagation of eigenstates is described with&lt;br /&gt;
&lt;br /&gt;
\[\psi(t, x) = \mathrm e ^ {-i\omega t} \psi(x)\]&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Quantum_Mechanics&amp;diff=1778</id>
		<title>Quantum Mechanics</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Quantum_Mechanics&amp;diff=1778"/>
				<updated>2017-12-15T10:47:48Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: Created page with &amp;quot;= Introduction = The quantum world is governed by the [https://en.wikipedia.org/wiki/Schr%C3%B6dinger_equation Schrödinger equation]  \[{\displaystyle {\hat {H}}|\psi (t)\ran...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
The quantum world is governed by the [https://en.wikipedia.org/wiki/Schr%C3%B6dinger_equation Schrödinger equation]&lt;br /&gt;
&lt;br /&gt;
\[{\displaystyle {\hat {H}}|\psi (t)\rangle =i\hbar {\frac {\partial }{\partial t}}|\psi (t)\rangle } \]&lt;br /&gt;
&lt;br /&gt;
where $\hat H$ is the [https://en.wikipedia.org/wiki/Hamiltonian_(quantum_mechanics) Hamiltonian], $|\psi (t)\rangle$ is the [https://en.wikipedia.org/wiki/Wave_function quantum state function] and $\hbar$ is the reduced [https://en.wikipedia.org/wiki/Planck_constant Planck constant].&lt;br /&gt;
&lt;br /&gt;
The Hamiltonian consists of kinetic energy $\hat T$ and potential energy $\hat V$. As in classical mechanics, potential energy is a function of time and space, whereas the kinetic energy differs from the classical world and is calculated as&lt;br /&gt;
&lt;br /&gt;
\[\hat T = - \frac{\hbar^2}{2m} \nabla^2 .\]&lt;br /&gt;
&lt;br /&gt;
The final version of the single particle Schrödinger equation can be written as&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
\[\left(- \frac{\hbar^2}{2m} \nabla^2 + V(t, \mathbf r)\right) \psi(t, \mathbf r) = i\hbar {\frac {\partial }{\partial t}}\psi(t, \mathbf r) \]&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Fluid_Mechanics&amp;diff=1603</id>
		<title>Fluid Mechanics</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Fluid_Mechanics&amp;diff=1603"/>
				<updated>2017-11-23T11:05:48Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Artificial compressibility method */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
Computational fluid dynamics (CFD) is a field of a great interest among researchers in many fields of science, e.g. studying mathematical fundaments of numerical methods, developing novel physical models, improving computer implementations, and many others. Pushing the limits of all involved fields of science helps community to deepen the understanding of several natural and technological phenomena. Weather forecast, ocean dynamics, water transport, casting, various energetic studies, etc., are just few examples where fluid dynamics plays a crucial role. The core problem of the CFD is solving the Navier-Stokes Equation or its variants, e.g. Darcy or Brinkman equation for flow in porous media. Here, we discuss basic algorithms for solving CFD problems. Check reference list on the [[Main Page]] for more details about related work.&lt;br /&gt;
&lt;br /&gt;
Long story short, we want to solve&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\frac{\partial \b{v}}{\partial t}+\nabla \cdot \left( \rho \b{vv}\right)=-\frac{1}{\rho }\nabla p+\nu {{\nabla }^{2}}\b{v}+\b{f}&lt;br /&gt;
\label{NavierStokes}&lt;br /&gt;
\end{equation}&lt;br /&gt;
also known as a Navier-Stokes equation. In many cases we are interested in the incompressible fluids (Ma&amp;lt;0.3), reducing the continuity equation to&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\nabla \cdot \b{v}=0&lt;br /&gt;
\label{contuinity}&lt;br /&gt;
\end{equation}&lt;br /&gt;
which implies a simplification&lt;br /&gt;
&lt;br /&gt;
\[\frac{\partial \left( \rho \b{v} \right)}{\partial t}+\nabla \cdot \left( \rho \b{vv} \right)=\frac{\partial \left( \rho \b{v} \right)}{\partial t}+(\rho \b{v}\cdot \nabla )\cdot \b{v}. \]&lt;br /&gt;
&lt;br /&gt;
Note that the $\b{v}\b{v}$ stands for the tensor or dyadic product \[ \b{v}\b{v} = \b{v}\otimes\b{v} = \b{v}\b{v}^\T = \left[ \begin{matrix}&lt;br /&gt;
   {{v}_{1}}{{v}_{1}} &amp;amp; \cdots &amp;amp; {{v}_{1}}{{v}_{n}}  \\&lt;br /&gt;
   \vdots &amp;amp; \ddots &amp;amp; \vdots  \\&lt;br /&gt;
   {{v}_{n}}{{v}_{1}} &amp;amp; \cdots &amp;amp; {{v}_{n}}{{v}_{n}}  \\&lt;br /&gt;
\end{matrix} \right]\]&lt;br /&gt;
An example of incompressible variant of advection term in 2D would therefore be&lt;br /&gt;
\[\left( \b{v}\cdot \nabla  \right)\b{v}=\left( \left( \begin{matrix}&lt;br /&gt;
   u  \\&lt;br /&gt;
   v  \\&lt;br /&gt;
\end{matrix} \right) \cdot \left( \begin{matrix}&lt;br /&gt;
   \frac{\partial }{\partial x}  \\&lt;br /&gt;
   \frac{\partial }{\partial y}  \\&lt;br /&gt;
\end{matrix} \right) \right)\left( \begin{matrix}&lt;br /&gt;
   u  \\&lt;br /&gt;
   v  \\&lt;br /&gt;
\end{matrix} \right)=\left( \begin{matrix}&lt;br /&gt;
   u\frac{\partial u}{\partial x}+v\frac{\partial u}{\partial y}  \\&lt;br /&gt;
   u\frac{\partial v}{\partial x}+v\frac{\partial v}{\partial y}  \\&lt;br /&gt;
\end{matrix} \right)\]&lt;br /&gt;
&lt;br /&gt;
The goal of CFD is to solve system \ref{NavierStokes} and \ref{contuinity}. It is obvious that a special treatment will be needed to couple both equations. In following discussion we cover some basic approaches, how this can be accomplished.&lt;br /&gt;
&lt;br /&gt;
= Solutions algorithms =&lt;br /&gt;
== Artificial compressibility method ==&lt;br /&gt;
The simplest, completely explicit approach, is an artificial compressibility method (ACM), where a compressibility term is included in the mass continuity&lt;br /&gt;
\[\frac{\partial \b{v}}{\partial t}+(\b{v}\cdot\nabla )\b{v}=-\frac{1}{\rho }\nabla p+\nu {{\nabla }^{2}}\b{v}+\b{f}\]&lt;br /&gt;
\[\frac{ 1 }{ \rho } \frac{\partial \rho }{\partial t}+\nabla \cdot \b{v}=0\]&lt;br /&gt;
\[\frac{ 1 }{ \rho } \frac{\partial \rho }{\partial p}\frac{\partial p}{\partial t}+\nabla \cdot \b{v}=0\]&lt;br /&gt;
Now, the above system can be solved directly.&lt;br /&gt;
&lt;br /&gt;
The addition of the time derivative of the pressure term physically means that waves of finite speed (the propagation of which depends on the magnitude of the ACM)&lt;br /&gt;
are introduced into the flow field as a mean to distribute the pressure within the domain. In a true&lt;br /&gt;
incompressible flow, the pressure field is affected instantaneously throughout the whole domain. In ACM there is a time delay between the flow disturbance and its effect on the&lt;br /&gt;
pressure field. Upon rearranging the equation yields&lt;br /&gt;
\[\frac{\partial p}{\partial t}+\rho {{C}^{2}}\nabla \cdot \b{v}=0\]&lt;br /&gt;
where the continuity equation is perturbed by the quantity $\frac{\partial p}{\partial t}$ denominated herein&lt;br /&gt;
as the AC parameter/artificial sound speed recognized by&lt;br /&gt;
$C$ [m/s] - speed of sound&lt;br /&gt;
\[\frac{1}{C^2}=\frac{\partial \rho }{\partial p}\]&lt;br /&gt;
Or in another words&lt;br /&gt;
\[C^2=\left( \frac{\partial p}{\partial \rho}\right)_S\]&lt;br /&gt;
where $\rho$ is the density of the material. It follows, by replacing partial derivatives, that the isentropic compressibility can be expressed as:&lt;br /&gt;
\[\beta =\frac{1}{\rho {{C}^{2}}}\]&lt;br /&gt;
The evaluation of the local ACM parameter in incompressible flows is inspired by the&lt;br /&gt;
speed of sound computations in compressible flows (for instance, from the perfect gas law).&lt;br /&gt;
However, in the incompressible flow situation, employing such a relation is difficult, but an artificial&lt;br /&gt;
relation can be developed from the convective and diffusive velocities.&lt;br /&gt;
Reverting to the justification of continuity modification, it can be immediately seen that the&lt;br /&gt;
artificial sound speed must be sufficiently large to have a significant regularizing effect and at&lt;br /&gt;
the same time must be as small as possible to minimizing perturbations on the incompressibility&lt;br /&gt;
equation.  Therefore, $C$ influences the convergence rate and stability of the solution method. In other words,&lt;br /&gt;
assists in reducing large disparity in the eigenvalues, leading to a well-conditioned system. &lt;br /&gt;
The $C$ can be '''estimated''' with&lt;br /&gt;
&lt;br /&gt;
\[ C = \beta \max \left( \left|\b{v}\right|_2, \left|\b{v}_{ref}\right|_2 \right),\]&lt;br /&gt;
where $\b{v}_{ref}$ stands for a reference velocity. &lt;br /&gt;
Values for $\beta$ in the range of 1–10 are recommended for better convergence to the steady state at which the&lt;br /&gt;
mass conservation is enforced. In addition, Equation ensures that $C$ does not reach zero at stagnation points&lt;br /&gt;
that cause instabilities in pseudo-time, effecting convergence&lt;br /&gt;
&lt;br /&gt;
== Explicit/Implicit pressure calculation ==&lt;br /&gt;
&lt;br /&gt;
Applying divergence on \ref{NavierStokes} yields&lt;br /&gt;
\[\nabla \cdot \frac{\partial \b{v}}{\partial t}+\nabla \cdot (\b{v}\cdot \nabla )\b{v}=-\frac{1}{\rho }{{\nabla }^{2}}p+\nabla \cdot \nu {{\nabla }^{2}}\b{v}+\nabla \cdot \b{f}\]&lt;br /&gt;
&lt;br /&gt;
And since $\nabla \cdot \b{v}=0$ and we can change order in $\nabla \cdot \nabla^2$ and $ \nabla^2 \cdot \nabla$ equation simplifies to&lt;br /&gt;
\[\frac{1}{\rho }{{\nabla }^{2}}p=\nabla \cdot \b{f}-\nabla \cdot (\b{v}\cdot \nabla )\b{v}\]&lt;br /&gt;
Now, we need boundary conditions that can be obtained by multiplying the equation  with a boundary normal vector&lt;br /&gt;
\[\b{\hat{n}}\cdot \left( \frac{\partial \b{v}}{\partial t}+(\b{v}\cdot \nabla )\b{v} \right)=\b{\hat{n}}\cdot \left( -\frac{1}{\rho }\nabla p+\nu {{\nabla }^{2}}\b{v}+\b{f} \right)\cdot \b{\hat{n}}\]&lt;br /&gt;
\[\frac{\partial p}{\partial \b{\hat{n}}}=\left( \nu {{\nabla }^{2}}\b{v}+\b{f}-\frac{\partial \b{v}}{\partial t}-(\b{v}\cdot\nabla ) \b{v} \right)\cdot \b{\hat{n}}\]&lt;br /&gt;
&lt;br /&gt;
Note that using tangential boundary vector gives equivalent BCs&lt;br /&gt;
\[\frac{\partial p}{\partial \b{\hat{t}}}=\left( \nu {{\nabla }^{2}}\b{v}+\b{f}-\frac{\partial \b{v}}{\partial t}-(\b{v}\cdot\nabla ) \b{v} \right)\cdot \b{\hat{t}}\]&lt;br /&gt;
For no-slip boundaries BCs simplify to&lt;br /&gt;
\[\frac{\partial p}{\partial \b{\hat{n}}}=\left( \nu {{\nabla }^{2}}\b{v}+\b{f} \right)\cdot \b{\hat{n}}\]&lt;br /&gt;
Otherwise an appropriate expression regarding the velocity can be written, i.e. write full  and taken in account velocity BCs. For example, Neumann velocity $\frac{\partial u}{\partial x}=0$ in 2D&lt;br /&gt;
\[\frac{\partial p}{\partial x}=\left( \nu {{\nabla }^{2}}u + {{f}_{x}}-\frac{\partial u}{\partial t}+v\frac{\partial u}{\partial y} \right)\]&lt;br /&gt;
Note that you allready know everything about the velocity and thus you can compute all the terms explicitely.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So the procedure is:&lt;br /&gt;
&lt;br /&gt;
* Compute Navier Stokes either explicitly or implicitly&lt;br /&gt;
* Solve pressure equations with  computed velocities&lt;br /&gt;
* March in time&lt;br /&gt;
&lt;br /&gt;
Basic boundary conditions&lt;br /&gt;
Wall:   $\b{v}=0$, \[\frac{\partial p}{\partial \hat{n}}=\left( \nabla \cdot \left( \nu \nabla \b{v} \right)+\b{f} \right)\cdot \hat{n}\]&lt;br /&gt;
Inlet:  $\b{v}=\b{a}$, \[\frac{\partial p}{\partial \hat{n}}=\left( \nabla \cdot \left( \nu \nabla \b{v} \right)+\b{f}-\nabla \cdot (\rho \b{v}\b{v})-\rho \frac{\partial \b{v}}{\partial t} \right)\cdot \hat{n}\]&lt;br /&gt;
&lt;br /&gt;
Above system can be linearized (advection term) and solved either explicitly or implicitly.&lt;br /&gt;
&lt;br /&gt;
Further reading:&lt;br /&gt;
&lt;br /&gt;
W. D. Henshaw, A fourth-order accurate method for the incompressible Navier–Stokes equations on overlapping grids, J. Comput. Phys. 113, 13 (1994)&lt;br /&gt;
&lt;br /&gt;
J. C. Strikwerda, Finite difference methods for the Stokes and Navier–Stokes equations, SIAM J. Sci. Stat.&lt;br /&gt;
Comput. 5(1), 56 (1984)&lt;br /&gt;
&lt;br /&gt;
== Explicit Pressure correction ==&lt;br /&gt;
Another possibility is to solve pressure correction equation. Again Consider the momentum equation and mass continuity and discretize it explicitly&lt;br /&gt;
\[\frac{{{\b{v}}_{2}}-{{\b{v}}_{1}}}{\Delta t}=-\frac{1}{\rho }\nabla {{p}_{1}}-({{\b{v}}_{1}}\nabla )\cdot {{\b{v}}_{1}}+\nu {{\nabla }^{2}}{{\b{v}}_{1}}+\b{f}\]&lt;br /&gt;
Computed velocity obviously does not satisfy the mass contunity and therefore let’s call it intermediate velocity. Intermediate velocity is calculated from guessed pressure and old velocity values.&lt;br /&gt;
\[{{\b{v}}^{inter}}=\b{v}_1 + \Delta t\left( -\frac{1}{\rho }\nabla {{p}_{1}}-({{\b{v}}_{1}}\nabla )\cdot {{\b{v}}_{1}}+\nu {{\nabla }^{2}}{{\b{v}}_{1}}+\b{f} \right)\]&lt;br /&gt;
A correction term is added that drives velocity to divergence free field&lt;br /&gt;
\[\nabla \cdot ({{\b{v}}^{inter}}+{{\b{v}}^{corr}})=0 \qquad \to \qquad \nabla \cdot {{\b{v}}^{inter}}=-\nabla \cdot {{\b{v}}^{corr}}\]&lt;br /&gt;
&lt;br /&gt;
Velocity correction is affected only by effect of pressure correction. This fact is obvious due to all terms except gradient of pressure on the right side of equation  are constant.&lt;br /&gt;
\[{{\b{v}}^{corr}}=-\frac{\Delta t}{\rho }\nabla {{p}^{corr}} \]&lt;br /&gt;
&lt;br /&gt;
Note that corrected velocity also satisfies boundary conditions&lt;br /&gt;
\[\b{v}^{iter}+\b{v}^{corr}=\b{v}^{BC}\]&lt;br /&gt;
Applying divergence  and  we get '''pressure correction poisson equation'''.&lt;br /&gt;
\[\,{{\nabla }^{2}}{{p}^{corr}}\,=\frac{\rho }{\Delta t}\nabla \cdot {{\mathbf{v}}^{iter}}\,\]&lt;br /&gt;
&lt;br /&gt;
Boundary conditions can be obtained by mulitplying the equation with a unit normal vector $\b{\hat{n}}$&lt;br /&gt;
\[\frac{\Delta t}{\rho }\frac{\partial {p}^{corr}}{\partial \b{\hat{n}}} = \b{\hat{n}} \cdot \left(\b{v}^{iter} - \b{v}^{BC} \right) \]&lt;br /&gt;
The most straightforward approach, for dirichlet BCs, is to take into account velocity boundary condition in computation of intermediate velocity, and clearly in such cases, pressure boundary condition simplifies to &lt;br /&gt;
\[\frac{\partial p^{corr}}{\partial \b{\hat{n}}} = 0 \]&lt;br /&gt;
As ${{\b{v}}^{\operatorname{int}er}}={{\b{v}}^{BC}}$ . Another option is to explicitely compute intermediate velocity also on boundaries and then correct it through pressure correction.&lt;br /&gt;
&lt;br /&gt;
The pressure poisson equation is, at given boundary conditions, defined only up to a constant. One solution is to select a node and set it to a constant, e.g. p(0, 0) = 0, however much more stable approach is to enforce solution with additional condition, also referred to as a regularization&lt;br /&gt;
	\[\int_{\Omega }^{{}}{pd}\Omega =0\]&lt;br /&gt;
\[\,{{\nabla }^{2}}{{p}^{corr}}\,-\alpha =\frac{\rho }{\Delta t}\nabla \cdot {{\b{v}}^{iter}}\,\]&lt;br /&gt;
Where $\alpha $ stands for Lagrange multiplier. Or in discrete form&lt;br /&gt;
	\[\sum\limits_{i}{p\left( {{x}_{i}} \right)=0}\]&lt;br /&gt;
	\[\b{Mp}-\alpha \b{1}=\frac{\rho }{\Delta t}\nabla \cdot {{\b{v}}^{iter}}\]&lt;br /&gt;
&lt;br /&gt;
where $\b{M}$ holds Laplace shape functions, i.e. the discrete version of Laplace differential operator. &lt;br /&gt;
&lt;br /&gt;
Solution of a system&lt;br /&gt;
&lt;br /&gt;
	\[\left[ \begin{matrix}&lt;br /&gt;
   {{M}_{11}} &amp;amp; .. &amp;amp; {{M}_{1n}} &amp;amp; 1  \\&lt;br /&gt;
   .. &amp;amp; .. &amp;amp; .. &amp;amp; 1  \\&lt;br /&gt;
   {{M}_{n1}} &amp;amp; ... &amp;amp; {{M}_{nn}} &amp;amp; 1  \\&lt;br /&gt;
   1 &amp;amp; 1 &amp;amp; 1 &amp;amp; 0  \\&lt;br /&gt;
\end{matrix} \right]\left[ \begin{matrix}&lt;br /&gt;
   {{p}_{1}}  \\&lt;br /&gt;
   ...  \\&lt;br /&gt;
   {{p}_{n}}  \\&lt;br /&gt;
   \alpha   \\&lt;br /&gt;
\end{matrix} \right]=\frac{\rho }{\Delta t}\left[ \begin{matrix}&lt;br /&gt;
   \nabla \cdot \b{v}_{_{1}}^{\text{iter}}  \\&lt;br /&gt;
   ...  \\&lt;br /&gt;
   \nabla \cdot \b{v}_{n}^{\text{iter}}  \\&lt;br /&gt;
   0  \\&lt;br /&gt;
\end{matrix} \right]\]&lt;br /&gt;
Gives us a solution of pressure correction.&lt;br /&gt;
&lt;br /&gt;
== CBS Algorithm ==&lt;br /&gt;
With explicit temporal discretization problem is formulated as&lt;br /&gt;
\[\b{\hat{v}}={{\b{v}}_{0}}+\Delta t\left( -\nabla {{p}_{0}}+\frac{1}{Re}{{\nabla }^{2}}{{\b{v}}_{0}}-\nabla \cdot ({{\b{v}}_{0}}{{\b{v}}_{0}}) \right)\]&lt;br /&gt;
\[p={{p}_{0}}-\xi \Delta {{t}_{F}}\nabla \b{\hat{v}}+\xi \Delta {{t}_{F}}\Delta t{{\nabla }^{2}}{{\overset{\scriptscriptstyle\frown}{P}}_{0}},\]&lt;br /&gt;
where $\b{\hat{v}}$, $\Delta t$, $\xi$ and $\Delta t_F$ stand for intermediate velocity, time step, relaxation parameter, and artificial time step, respectively, and index 0 stands for previous time / iteration step. First, the intermediate velocity is computed from previous time step. Second, the velocity is driven towards solenoidal field by correcting the pressure. Note that no special boundary conditions for pressure are used, i.e., the pressure on boundaries is computed with the same approach as in the interior of the domain. In general, the internal iteration with an artificial time step is required until the divergence of the velocity field is not below required criteria. However, if one is interested only in a steady-state solution, the internal iteration can be skipped and $\Delta t$ equals $\Delta {{t}_{F}}$. Without internal stepping the transient of the solution is distorted by artificial compressibility effect. This approach is also known as ACM with Characteristics-based discretization of continuity equation, where the relaxation parameter relates to the artificial speed of sound [35].&lt;br /&gt;
&lt;br /&gt;
The relaxation parameter should be set between 1-10, lower number more stable solution.&lt;br /&gt;
&lt;br /&gt;
And also dimensional form&lt;br /&gt;
&lt;br /&gt;
\[p={{p}_{0}}-{{C}^{2}}\Delta {{t}_{F}}\rho \nabla \b{\hat{v}}+{{C}^{2}}\Delta {{t}_{F}}\Delta t{{\nabla }^{2}}{{p}_{0}},\]&lt;br /&gt;
&lt;br /&gt;
Where C is speed of sound [m/s]&lt;br /&gt;
&lt;br /&gt;
== Numerical examples==&lt;br /&gt;
* [[Lid driven cavity]]&lt;br /&gt;
* [[de Vahl Davis natural convection test]]&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Fluid_Mechanics&amp;diff=1594</id>
		<title>Fluid Mechanics</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Fluid_Mechanics&amp;diff=1594"/>
				<updated>2017-11-17T11:32:21Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: Fix typo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
Computational fluid dynamics (CFD) is a field of a great interest among researchers in many fields of science, e.g. studying mathematical fundaments of numerical methods, developing novel physical models, improving computer implementations, and many others. Pushing the limits of all involved fields of science helps community to deepen the understanding of several natural and technological phenomena. Weather forecast, ocean dynamics, water transport, casting, various energetic studies, etc., are just few examples where fluid dynamics plays a crucial role. The core problem of the CFD is solving the Navier-Stokes Equation or its variants, e.g. Darcy or Brinkman equation for flow in porous media. Here, we discuss basic algorithms for solving CFD problems. Check reference list on the [[Main Page]] for more details about related work.&lt;br /&gt;
&lt;br /&gt;
Long story short, we want to solve&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\frac{\partial \b{v}}{\partial t}+(\b{v}\cdot\nabla )\cdot \b{v}=-\frac{1}{\rho }\nabla p+\nu {{\nabla }^{2}}\b{v}+\b{f}&lt;br /&gt;
\label{NavierStokes}&lt;br /&gt;
\end{equation}&lt;br /&gt;
also known as a Navier-Stokes equation. In many cases we are interested in the incompressible fluids (Ma&amp;lt;0.3), reducing the continuity equation to&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\nabla \cdot \b{v}=0&lt;br /&gt;
\label{contuinity}&lt;br /&gt;
\end{equation}&lt;br /&gt;
which implies a simplification&lt;br /&gt;
&lt;br /&gt;
\[\frac{\partial \left( \rho \b{v} \right)}{\partial t}+\nabla \cdot \left( \rho \b{vv} \right)=\frac{\partial \left( \rho \b{v} \right)}{\partial t}+(\rho \b{v}\cdot \nabla )\cdot \b{v}. \]&lt;br /&gt;
&lt;br /&gt;
Note that the $\b{v}\b{v}$ stands for the tensor or dyadic product \[ \b{v}\b{v} = \b{v}\otimes\b{v} = \b{v}\b{v}^\T = \left[ \begin{matrix}&lt;br /&gt;
   {{v}_{1}}{{v}_{1}} &amp;amp; \cdots &amp;amp; {{v}_{1}}{{v}_{n}}  \\&lt;br /&gt;
   \vdots &amp;amp; \ddots &amp;amp; \vdots  \\&lt;br /&gt;
   {{v}_{n}}{{v}_{1}} &amp;amp; \cdots &amp;amp; {{v}_{n}}{{v}_{n}}  \\&lt;br /&gt;
\end{matrix} \right]\]&lt;br /&gt;
An example of incompressible variant of advection term in 2D would therefore be&lt;br /&gt;
\[\left( \b{v}\cdot \nabla  \right)\b{v}=\left( \left( \begin{matrix}&lt;br /&gt;
   u  \\&lt;br /&gt;
   v  \\&lt;br /&gt;
\end{matrix} \right) \cdot \left( \begin{matrix}&lt;br /&gt;
   \frac{\partial }{\partial x}  \\&lt;br /&gt;
   \frac{\partial }{\partial y}  \\&lt;br /&gt;
\end{matrix} \right) \right)\left( \begin{matrix}&lt;br /&gt;
   u  \\&lt;br /&gt;
   v  \\&lt;br /&gt;
\end{matrix} \right)=\left( \begin{matrix}&lt;br /&gt;
   u\frac{\partial u}{\partial x}+v\frac{\partial u}{\partial y}  \\&lt;br /&gt;
   u\frac{\partial v}{\partial x}+v\frac{\partial v}{\partial y}  \\&lt;br /&gt;
\end{matrix} \right)\]&lt;br /&gt;
&lt;br /&gt;
The goal of CFD is to solve system \ref{NavierStokes} and \ref{contuinity}. It is obvious that a special treatment will be needed to couple both equations. In following discussion we cover some basic approaches, how this can be accomplished.&lt;br /&gt;
&lt;br /&gt;
= Solutions algorithms =&lt;br /&gt;
== Artificial compressibility method ==&lt;br /&gt;
The simplest, completely explicit approach, is an artificial compressibility method (ACM), where a compressibility term is included in the mass continuity&lt;br /&gt;
\[\frac{\partial \b{v}}{\partial t}+(\b{v}\cdot\nabla )\b{v}=-\frac{1}{\rho }\nabla p+\nu {{\nabla }^{2}}\b{v}+\b{f}\]&lt;br /&gt;
\[\frac{\partial \rho }{\partial t}+\nabla \cdot \b{v}=0\]&lt;br /&gt;
\[\frac{\partial \rho }{\partial p}\frac{\partial p}{\partial t}+\nabla \cdot \b{v}=0\]&lt;br /&gt;
Now, the above system can be solved directly.&lt;br /&gt;
&lt;br /&gt;
The addition of the time derivative of the pressure term physically means that waves of finite speed (the propagation of which depends on the magnitude of the ACM)&lt;br /&gt;
are introduced into the flow field as a mean to distribute the pressure within the domain. In a true&lt;br /&gt;
incompressible flow, the pressure field is affected instantaneously throughout the whole domain. In ACM there is a time delay between the flow disturbance and its effect on the&lt;br /&gt;
pressure field. Upon rearranging the equation yields&lt;br /&gt;
\[\frac{\partial p}{\partial t}+\rho {{C}^{2}}\nabla \cdot \b{v}=0\]&lt;br /&gt;
where the continuity equation is perturbed by the quantity $\frac{\partial p}{\partial t}$ denominated herein&lt;br /&gt;
as the AC parameter/artificial sound speed recognized by&lt;br /&gt;
$C$ [m/s] - speed of sound&lt;br /&gt;
\[\frac{1}{C^2}=\frac{\partial \rho }{\partial p}\]&lt;br /&gt;
Or in another words&lt;br /&gt;
\[C^2=\left( \frac{\partial p}{\partial \rho}\right)_S\]&lt;br /&gt;
where $\rho$ is the density of the material. It follows, by replacing partial derivatives, that the isentropic compressibility can be expressed as:&lt;br /&gt;
\[\beta =\frac{1}{\rho {{C}^{2}}}\]&lt;br /&gt;
The evaluation of the local ACM parameter in incompressible flows is inspired by the&lt;br /&gt;
speed of sound computations in compressible flows (for instance, from the perfect gas law).&lt;br /&gt;
However, in the incompressible flow situation, employing such a relation is difficult, but an artificial&lt;br /&gt;
relation can be developed from the convective and diffusive velocities.&lt;br /&gt;
Reverting to the justification of continuity modification, it can be immediately seen that the&lt;br /&gt;
artificial sound speed must be sufficiently large to have a significant regularizing effect and at&lt;br /&gt;
the same time must be as small as possible to minimizing perturbations on the incompressibility&lt;br /&gt;
equation.  Therefore, $C$ influences the convergence rate and stability of the solution method. In other words,&lt;br /&gt;
assists in reducing large disparity in the eigenvalues, leading to a well-conditioned system. Values&lt;br /&gt;
of in the range of 1–10 are recommended for better convergence to the steady state at which the&lt;br /&gt;
mass conservation is enforced. In addition, Equation ensures that $C$ does not reach zero at stagnation points&lt;br /&gt;
that cause instabilities in pseudo-time, effecting convergence&lt;br /&gt;
&lt;br /&gt;
== Explicit/Implicit pressure calculation ==&lt;br /&gt;
&lt;br /&gt;
Applying divergence on \ref{NavierStokes} yields&lt;br /&gt;
\[\nabla \cdot \frac{\partial \b{v}}{\partial t}+\nabla \cdot (\b{v}\cdot \nabla )\b{v}=-\frac{1}{\rho }{{\nabla }^{2}}p+\nabla \cdot \nu {{\nabla }^{2}}\b{v}+\nabla \cdot \b{f}\]&lt;br /&gt;
&lt;br /&gt;
And since $\nabla \cdot \b{v}=0$ and we can change order in $\nabla \cdot \nabla^2$ and $ \nabla^2 \cdot \nabla$ equation simplifies to&lt;br /&gt;
\[\frac{1}{\rho }{{\nabla }^{2}}p=\nabla \cdot \b{f}-\nabla \cdot (\b{v}\cdot \nabla )\b{v}\]&lt;br /&gt;
Now, we need boundary conditions that can be obtained by multiplying the equation  with a boundary normal vector&lt;br /&gt;
\[\b{\hat{n}}\cdot \left( \frac{\partial \b{v}}{\partial t}+(\b{v}\cdot \nabla )\b{v} \right)=\b{\hat{n}}\cdot \left( -\frac{1}{\rho }\nabla p+\nu {{\nabla }^{2}}\b{v}+\b{f} \right)\cdot \b{\hat{n}}\]&lt;br /&gt;
\[\frac{\partial p}{\partial \b{\hat{n}}}=\left( \nu {{\nabla }^{2}}\b{v}+\b{f}-\frac{\partial \b{v}}{\partial t}-(\b{v}\cdot\nabla ) \b{v} \right)\cdot \b{\hat{n}}\]&lt;br /&gt;
&lt;br /&gt;
Note that using tangential boundary vector gives equivalent BCs&lt;br /&gt;
\[\frac{\partial p}{\partial \b{\hat{t}}}=\left( \nu {{\nabla }^{2}}\b{v}+\b{f}-\frac{\partial \b{v}}{\partial t}-(\b{v}\cdot\nabla ) \b{v} \right)\cdot \b{\hat{t}}\]&lt;br /&gt;
For no-slip boundaries BCs simplify to&lt;br /&gt;
\[\frac{\partial p}{\partial \b{\hat{n}}}=\left( \nu {{\nabla }^{2}}\b{v}+\b{f} \right)\cdot \b{\hat{n}}\]&lt;br /&gt;
Otherwise an appropriate expression regarding the velocity can be written, i.e. write full  and taken in account velocity BCs. For example, Neumann velocity $\frac{\partial u}{\partial x}=0$ in 2D&lt;br /&gt;
\[\frac{\partial p}{\partial x}=\left( \nu {{\nabla }^{2}}u + {{f}_{x}}-\frac{\partial u}{\partial t}+v\frac{\partial u}{\partial y} \right)\]&lt;br /&gt;
Note that you allready know everything about the velocity and thus you can compute all the terms explicitely.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So the procedure is:&lt;br /&gt;
&lt;br /&gt;
* Compute Navier Stokes either explicitly or implicitly&lt;br /&gt;
* Solve pressure equations with  computed velocities&lt;br /&gt;
* March in time&lt;br /&gt;
&lt;br /&gt;
Basic boundary conditions&lt;br /&gt;
Wall:   $\b{v}=0$, \[\frac{\partial p}{\partial \hat{n}}=\left( \nabla \cdot \left( \nu \nabla \b{v} \right)+\b{f} \right)\cdot \hat{n}\]&lt;br /&gt;
Inlet:  $\b{v}=\b{a}$, \[\frac{\partial p}{\partial \hat{n}}=\left( \nabla \cdot \left( \nu \nabla \b{v} \right)+\b{f}-\nabla \cdot (\rho \b{v}\b{v})-\rho \frac{\partial \b{v}}{\partial t} \right)\cdot \hat{n}\]&lt;br /&gt;
&lt;br /&gt;
Above system can be linearized (advection term) and solved either explicitly or implicitly.&lt;br /&gt;
&lt;br /&gt;
Further reading:&lt;br /&gt;
&lt;br /&gt;
W. D. Henshaw, A fourth-order accurate method for the incompressible Navier–Stokes equations on overlapping grids, J. Comput. Phys. 113, 13 (1994)&lt;br /&gt;
&lt;br /&gt;
J. C. Strikwerda, Finite difference methods for the Stokes and Navier–Stokes equations, SIAM J. Sci. Stat.&lt;br /&gt;
Comput. 5(1), 56 (1984)&lt;br /&gt;
&lt;br /&gt;
== Explicit Pressure correction ==&lt;br /&gt;
Another possibility is to solve pressure correction equation. Again Consider the momentum equation and mass continuity and discretize it explicitly&lt;br /&gt;
\[\frac{{{\b{v}}_{2}}-{{\b{v}}_{1}}}{\Delta t}=-\frac{1}{\rho }\nabla {{p}_{1}}-({{\b{v}}_{1}}\nabla )\cdot {{\b{v}}_{1}}+\nu {{\nabla }^{2}}{{\b{v}}_{1}}+\b{f}\]&lt;br /&gt;
Computed velocity obviously does not satisfy the mass contunity and therefore let’s call it intermediate velocity. Intermediate velocity is calculated from guessed pressure and old velocity values.&lt;br /&gt;
\[{{\b{v}}^{inter}}=\b{v}_1 + \Delta t\left( -\frac{1}{\rho }\nabla {{p}_{1}}-({{\b{v}}_{1}}\nabla )\cdot {{\b{v}}_{1}}+\nu {{\nabla }^{2}}{{\b{v}}_{1}}+\b{f} \right)\]&lt;br /&gt;
A correction term is added that drives velocity to divergence free field&lt;br /&gt;
\[\nabla \cdot ({{\b{v}}^{inter}}+{{\b{v}}^{corr}})=0 \qquad \to \qquad \nabla \cdot {{\b{v}}^{inter}}=-\nabla \cdot {{\b{v}}^{corr}}\]&lt;br /&gt;
&lt;br /&gt;
Velocity correction is affected only by effect of pressure correction. This fact is obvious due to all terms except gradient of pressure on the right side of equation  are constant.&lt;br /&gt;
\[{{\b{v}}^{corr}}=-\frac{\Delta t}{\rho }\nabla {{p}^{corr}} \]&lt;br /&gt;
&lt;br /&gt;
Note that corrected velocity also satisfies boundary conditions&lt;br /&gt;
\[\b{v}^{iter}+\b{v}^{corr}=\b{v}^{BC}\]&lt;br /&gt;
Applying divergence  and  we get '''pressure correction poisson equation'''.&lt;br /&gt;
\[\,{{\nabla }^{2}}{{p}^{corr}}\,=\frac{\rho }{\Delta t}\nabla \cdot {{\mathbf{v}}^{iter}}\,\]&lt;br /&gt;
&lt;br /&gt;
Boundary conditions can be obtained by mulitplying the equation with a unit normal vector $\b{\hat{n}}$&lt;br /&gt;
\[\frac{\Delta t}{\rho }\frac{\partial {p}^{corr}}{\partial \b{\hat{n}}} = \b{\hat{n}} \cdot \left(\b{v}^{iter} - \b{v}^{BC} \right) \]&lt;br /&gt;
The most straightforward approach, for dirichlet BCs, is to take into account velocity boundary condition in computation of intermediate velocity, and clearly in such cases, pressure boundary condition simplifies to &lt;br /&gt;
\[\frac{\partial p^{corr}}{\partial \b{\hat{n}}} = 0 \]&lt;br /&gt;
As ${{\b{v}}^{\operatorname{int}er}}={{\b{v}}^{BC}}$ . Another option is to explicitely compute intermediate velocity also on boundaries and then correct it through pressure correction.&lt;br /&gt;
&lt;br /&gt;
The pressure poisson equation is, at given boundary conditions, defined only up to a constant. One solution is to select a node and set it to a constant, e.g. p(0, 0) = 0, however much more stable approach is to enforce solution with additional condition, also referred to as a regularization&lt;br /&gt;
	\[\int_{\Omega }^{{}}{pd}\Omega =0\]&lt;br /&gt;
\[\,{{\nabla }^{2}}{{p}^{corr}}\,-\alpha =\frac{\rho }{\Delta t}\nabla \cdot {{\b{v}}^{iter}}\,\]&lt;br /&gt;
Where $\alpha $ stands for Lagrange multiplier. Or in discrete form&lt;br /&gt;
	\[\sum\limits_{i}{p\left( {{x}_{i}} \right)=0}\]&lt;br /&gt;
	\[\b{Mp}-\alpha \b{1}=\frac{\rho }{\Delta t}\nabla \cdot {{\b{v}}^{iter}}\]&lt;br /&gt;
&lt;br /&gt;
where $\b{M}$ holds Laplace shape functions, i.e. the discrete version of Laplace differential operator. &lt;br /&gt;
&lt;br /&gt;
Solution of a system&lt;br /&gt;
&lt;br /&gt;
	\[\left[ \begin{matrix}&lt;br /&gt;
   {{M}_{11}} &amp;amp; .. &amp;amp; {{M}_{1n}} &amp;amp; 1  \\&lt;br /&gt;
   .. &amp;amp; .. &amp;amp; .. &amp;amp; 1  \\&lt;br /&gt;
   {{M}_{n1}} &amp;amp; ... &amp;amp; {{M}_{nn}} &amp;amp; 1  \\&lt;br /&gt;
   1 &amp;amp; 1 &amp;amp; 1 &amp;amp; 0  \\&lt;br /&gt;
\end{matrix} \right]\left[ \begin{matrix}&lt;br /&gt;
   {{p}_{1}}  \\&lt;br /&gt;
   ...  \\&lt;br /&gt;
   {{p}_{n}}  \\&lt;br /&gt;
   \alpha   \\&lt;br /&gt;
\end{matrix} \right]=\frac{\rho }{\Delta t}\left[ \begin{matrix}&lt;br /&gt;
   \nabla \cdot \b{v}_{_{1}}^{\text{iter}}  \\&lt;br /&gt;
   ...  \\&lt;br /&gt;
   \nabla \cdot \b{v}_{n}^{\text{iter}}  \\&lt;br /&gt;
   0  \\&lt;br /&gt;
\end{matrix} \right]\]&lt;br /&gt;
Gives us a solution of pressure correction.&lt;br /&gt;
&lt;br /&gt;
== CBS Algorithm ==&lt;br /&gt;
With explicit temporal discretization problem is formulated as&lt;br /&gt;
\[\b{\hat{v}}={{\b{v}}_{0}}+\Delta t\left( -\nabla {{p}_{0}}+\frac{1}{Re}{{\nabla }^{2}}{{\b{v}}_{0}}-\nabla \cdot ({{\b{v}}_{0}}{{\b{v}}_{0}}) \right)\]&lt;br /&gt;
\[p={{p}_{0}}-\xi \Delta {{t}_{F}}\nabla \b{\hat{v}}+\xi \Delta {{t}_{F}}\Delta t{{\nabla }^{2}}{{\overset{\scriptscriptstyle\frown}{P}}_{0}},\]&lt;br /&gt;
where $\b{\hat{v}}$, $\Delta t$, $\xi$ and $\Delta t_F$ stand for intermediate velocity, time step, relaxation parameter, and artificial time step, respectively, and index 0 stands for previous time / iteration step. First, the intermediate velocity is computed from previous time step. Second, the velocity is driven towards solenoidal field by correcting the pressure. Note that no special boundary conditions for pressure are used, i.e., the pressure on boundaries is computed with the same approach as in the interior of the domain. In general, the internal iteration with an artificial time step is required until the divergence of the velocity field is not below required criteria. However, if one is interested only in a steady-state solution, the internal iteration can be skipped and $\Delta t$ equals $\Delta {{t}_{F}}$. Without internal stepping the transient of the solution is distorted by artificial compressibility effect. This approach is also known as ACM with Characteristics-based discretization of continuity equation, where the relaxation parameter relates to the artificial speed of sound [35].&lt;br /&gt;
&lt;br /&gt;
The relaxation parameter should be set between 1-10, lower number more stable solution.&lt;br /&gt;
&lt;br /&gt;
And also dimensional form&lt;br /&gt;
&lt;br /&gt;
\[p={{p}_{0}}-{{C}^{2}}\Delta {{t}_{F}}\rho \nabla \b{\hat{v}}+{{C}^{2}}\Delta {{t}_{F}}\Delta t{{\nabla }^{2}}{{p}_{0}},\]&lt;br /&gt;
&lt;br /&gt;
Where C is speed of sound [m/s]&lt;br /&gt;
&lt;br /&gt;
== Numerical examples==&lt;br /&gt;
* [[Lid driven cavity]]&lt;br /&gt;
* [[de Vahl Davis natural convection test]]&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Fluid_Mechanics&amp;diff=1593</id>
		<title>Fluid Mechanics</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Fluid_Mechanics&amp;diff=1593"/>
				<updated>2017-11-17T10:40:02Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: Removed extra the&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
Computational fluid dynamics (CFD) is a field of a great interest among researchers in many fields of science, e.g. studying mathematical fundaments of numerical methods, developing novel physical models, improving computer implementations, and many others. Pushing the limits of all involved fields of science helps community to deepen the understanding of several natural and technological phenomena. Weather forecast, ocean dynamics, water transport, casting, various energetic studies, etc., are just few examples where fluid dynamics plays a crucial role. The core problem of the CFD is solving the Navier-Stokes Equation or its variants, e.g. Darcy or Brinkman equation for flow in porous media. Here, we discuss basic algorithms for solving CFD problems. Check reference list on the [[Main Page]] for more details about related work.&lt;br /&gt;
&lt;br /&gt;
Long story short, we want to solve&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\frac{\partial \b{v}}{\partial t}+(\b{v}\cdot\nabla )\cdot \b{v}=-\frac{1}{\rho }\nabla p+\nu {{\nabla }^{2}}\b{v}+\b{f}&lt;br /&gt;
\label{NavierStokes}&lt;br /&gt;
\end{equation}&lt;br /&gt;
also known as a Navier-Stokes equation. In many cases we are interested in the incompressible fluids (Ma&amp;lt;0.3), reducing the continuity equation to&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\nabla \cdot \b{v}=0&lt;br /&gt;
\label{contuinity}&lt;br /&gt;
\end{equation}&lt;br /&gt;
which implies a simplification&lt;br /&gt;
&lt;br /&gt;
\[\frac{\partial \left( \rho \b{v} \right)}{\partial t}+\nabla \cdot \left( \rho \b{vv} \right)=\frac{\partial \left( \rho \b{v} \right)}{\partial t}+(\rho \b{v}\cdot \nabla )\cdot \b{v}. \]&lt;br /&gt;
&lt;br /&gt;
Note that the $\b{v}\b{v}$ stands for the tensor or dyadic product \[ \b{v}\b{v} = \b{v}\otimes\b{v} = \b{v}\b{v}^\T = \left[ \begin{matrix}&lt;br /&gt;
   {{v}_{1}}{{v}_{1}} &amp;amp; \cdots &amp;amp; {{v}_{1}}{{v}_{n}}  \\&lt;br /&gt;
   \vdots &amp;amp; \ddots &amp;amp; \vdots  \\&lt;br /&gt;
   {{v}_{n}}{{v}_{1}} &amp;amp; \cdots &amp;amp; {{v}_{n}}{{v}_{n}}  \\&lt;br /&gt;
\end{matrix} \right]\]&lt;br /&gt;
An example of incompressible variant of advection term in 2D would therefore be&lt;br /&gt;
\[\left( \b{v}\cdot \nabla  \right)\b{v}=\left( \left( \begin{matrix}&lt;br /&gt;
   u  \\&lt;br /&gt;
   v  \\&lt;br /&gt;
\end{matrix} \right) \cdot \left( \begin{matrix}&lt;br /&gt;
   \frac{\partial }{\partial x}  \\&lt;br /&gt;
   \frac{\partial }{\partial y}  \\&lt;br /&gt;
\end{matrix} \right) \right)\left( \begin{matrix}&lt;br /&gt;
   u  \\&lt;br /&gt;
   v  \\&lt;br /&gt;
\end{matrix} \right)=\left( \begin{matrix}&lt;br /&gt;
   u\frac{\partial u}{\partial x}+v\frac{\partial u}{\partial y}  \\&lt;br /&gt;
   u\frac{\partial v}{\partial x}+v\frac{\partial v}{\partial y}  \\&lt;br /&gt;
\end{matrix} \right)\]&lt;br /&gt;
&lt;br /&gt;
The goal of CFD is to solve system \ref{NavierStokes} and \ref{contuinity}. It is obvious that a special treatment will be needed to couple both equations. In following discussion we cover some basic approaches, how this can be accomplished.&lt;br /&gt;
&lt;br /&gt;
= Solutions algorithms =&lt;br /&gt;
== Artificial compressibility method ==&lt;br /&gt;
The simplest, completely explicit approach, is an artificial compressibility method (ACM), where a compressibility term is included in the mass continuity&lt;br /&gt;
\[\frac{\partial \b{v}}{\partial t}+(\b{v}\cdot\nabla )\b{v}=-\frac{1}{\rho }\nabla p+\nu {{\nabla }^{2}}\b{v}+\b{f}\]&lt;br /&gt;
\[\frac{\partial \rho }{\partial t}+\nabla \cdot \b{v}=0\]&lt;br /&gt;
\[\frac{\partial \rho }{\partial p}\frac{\partial p}{\partial t}+\nabla \cdot \b{v}=0\]&lt;br /&gt;
Now, the above system can be solved directly.&lt;br /&gt;
&lt;br /&gt;
The addition of the time derivative of the pressure term physically means that waves of finite speed (the propagation of which depends on the magnitude of the ACM)&lt;br /&gt;
are introduced into the flow field as a mean to distribute the pressure within the domain. In a true&lt;br /&gt;
incompressible flow, the pressure field is affected instantaneously throughout the whole domain. In ACM there is a time delay between the flow disturbance and its effect on the&lt;br /&gt;
pressure field. Upon rearranging the equation yields&lt;br /&gt;
\[\frac{\partial p}{\partial t}+\rho {{C}^{2}}\nabla \cdot \b{v}=0\]&lt;br /&gt;
where the continuity equation is perturbed by the quantity $\frac{\partial p}{\partial t}$ denominated herein&lt;br /&gt;
as the AC parameter/artificial sound speed recognized by&lt;br /&gt;
$C$ [m/s] - speed of sound&lt;br /&gt;
\[\frac{1}{C^2}=\frac{\partial \rho }{\partial p}\]&lt;br /&gt;
Or in another words&lt;br /&gt;
\[C^2=\left( \frac{\partial p}{\partial \rho}\right)_S\]&lt;br /&gt;
where $\rho$ is the density of the material. It follows, by replacing partial derivatives, that the isentropic compressibility can be expressed as:&lt;br /&gt;
\[\beta =\frac{1}{\rho {{C}^{2}}}\]&lt;br /&gt;
The evaluation of the local ACM parameter in incompressible flows is inspired by the&lt;br /&gt;
speed of sound computations in compressible flows (for instance, from the perfect gas law).&lt;br /&gt;
However, in the incompressible flow situation, employing such a relation is difficult, but an artificial&lt;br /&gt;
relation can be developed from the convective and diffusive velocities.&lt;br /&gt;
Reverting to the justification of continuity modification, it can be immediately seen that the&lt;br /&gt;
artificial sound speed must be sufficiently large to have a significant regularizing effect and at&lt;br /&gt;
the same time must be as small as possible to minimizing perturbations on the incompressibility&lt;br /&gt;
equation.  Therefore, $C$ influences the convergence rate and stability of the solution method. In other words,&lt;br /&gt;
assists in reducing large disparity in the eigenvalues, leading to a well-conditioned system. Values&lt;br /&gt;
of in the range of 1–10 are recommended for better convergence to the steady state at which the&lt;br /&gt;
mass conservation is enforced. In addition, Equation ensures that $C$ does not reach zero at stagnation points&lt;br /&gt;
that cause instabilities in pseudo-time, effecting convergence&lt;br /&gt;
&lt;br /&gt;
== Explicit/Implicit pressure calculation ==&lt;br /&gt;
&lt;br /&gt;
Applying divergence on \ref{NavierStokes} yields&lt;br /&gt;
\[\nabla \cdot \frac{\partial \b{v}}{\partial t}+\nabla \cdot (\b{v}\cdot \nabla )\b{v}=-\frac{1}{\rho }{{\nabla }^{2}}p+\nabla \cdot \nu {{\nabla }^{2}}\b{v}+\nabla \cdot \b{f}\]&lt;br /&gt;
&lt;br /&gt;
And since $\nabla \cdot \b{v}=0$ and we can change order in $\nabla \cdot \nabla^2$ and $ \nabla^2 \cdot \nabla$ quation simplifies to&lt;br /&gt;
\[\frac{1}{\rho }{{\nabla }^{2}}p=\nabla \cdot \b{f}-\nabla \cdot (\b{v}\cdot \nabla )\b{v}\]&lt;br /&gt;
Now, we need boundary conditions that can be obtained by multiplying the equation  with a boundary normal vector&lt;br /&gt;
\[\b{\hat{n}}\cdot \left( \frac{\partial \b{v}}{\partial t}+(\b{v}\cdot \nabla )\b{v} \right)=\b{\hat{n}}\cdot \left( -\frac{1}{\rho }\nabla p+\nu {{\nabla }^{2}}\b{v}+\b{f} \right)\cdot \b{\hat{n}}\]&lt;br /&gt;
\[\frac{\partial p}{\partial \b{\hat{n}}}=\left( \nu {{\nabla }^{2}}\b{v}+\b{f}-\frac{\partial \b{v}}{\partial t}-(\b{v}\cdot\nabla ) \b{v} \right)\cdot \b{\hat{n}}\]&lt;br /&gt;
&lt;br /&gt;
Note that using tangential boundary vector gives equivalent BCs&lt;br /&gt;
\[\frac{\partial p}{\partial \b{\hat{t}}}=\left( \nu {{\nabla }^{2}}\b{v}+\b{f}-\frac{\partial \b{v}}{\partial t}-(\b{v}\cdot\nabla ) \b{v} \right)\cdot \b{\hat{t}}\]&lt;br /&gt;
For no-slip boundaries BCs simplify to&lt;br /&gt;
\[\frac{\partial p}{\partial \b{\hat{n}}}=\left( \nu {{\nabla }^{2}}\b{v}+\b{f} \right)\cdot \b{\hat{n}}\]&lt;br /&gt;
Otherwise an appropriate expression regarding the velocity can be written, i.e. write full  and taken in account velocity BCs. For example, Neumann velocity $\frac{\partial u}{\partial x}=0$ in 2D&lt;br /&gt;
\[\frac{\partial p}{\partial x}=\left( \nu {{\nabla }^{2}}u + {{f}_{x}}-\frac{\partial u}{\partial t}+v\frac{\partial u}{\partial y} \right)\]&lt;br /&gt;
Note that you allready know everything about the velocity and thus you can compute all the terms explicitely.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So the procedure is:&lt;br /&gt;
&lt;br /&gt;
* Compute Navier Stokes either explicitly or implicitly&lt;br /&gt;
* Solve pressure equations with  computed velocities&lt;br /&gt;
* March in time&lt;br /&gt;
&lt;br /&gt;
Basic boundary conditions&lt;br /&gt;
Wall:   $\b{v}=0$, \[\frac{\partial p}{\partial \hat{n}}=\left( \nabla \cdot \left( \nu \nabla \b{v} \right)+\b{f} \right)\cdot \hat{n}\]&lt;br /&gt;
Inlet:  $\b{v}=\b{a}$, \[\frac{\partial p}{\partial \hat{n}}=\left( \nabla \cdot \left( \nu \nabla \b{v} \right)+\b{f}-\nabla \cdot (\rho \b{v}\b{v})-\rho \frac{\partial \b{v}}{\partial t} \right)\cdot \hat{n}\]&lt;br /&gt;
&lt;br /&gt;
Above system can be linearized (advection term) and solved either explicitly or implicitly.&lt;br /&gt;
&lt;br /&gt;
Further reading:&lt;br /&gt;
&lt;br /&gt;
W. D. Henshaw, A fourth-order accurate method for the incompressible Navier–Stokes equations on overlapping grids, J. Comput. Phys. 113, 13 (1994)&lt;br /&gt;
&lt;br /&gt;
J. C. Strikwerda, Finite difference methods for the Stokes and Navier–Stokes equations, SIAM J. Sci. Stat.&lt;br /&gt;
Comput. 5(1), 56 (1984)&lt;br /&gt;
&lt;br /&gt;
== Explicit Pressure correction ==&lt;br /&gt;
Another possibility is to solve pressure correction equation. Again Consider the momentum equation and mass continuity and discretize it explicitly&lt;br /&gt;
\[\frac{{{\b{v}}_{2}}-{{\b{v}}_{1}}}{\Delta t}=-\frac{1}{\rho }\nabla {{p}_{1}}-({{\b{v}}_{1}}\nabla )\cdot {{\b{v}}_{1}}+\nu {{\nabla }^{2}}{{\b{v}}_{1}}+\b{f}\]&lt;br /&gt;
Computed velocity obviously does not satisfy the mass contunity and therefore let’s call it intermediate velocity. Intermediate velocity is calculated from guessed pressure and old velocity values.&lt;br /&gt;
\[{{\b{v}}^{inter}}=\b{v}_1 + \Delta t\left( -\frac{1}{\rho }\nabla {{p}_{1}}-({{\b{v}}_{1}}\nabla )\cdot {{\b{v}}_{1}}+\nu {{\nabla }^{2}}{{\b{v}}_{1}}+\b{f} \right)\]&lt;br /&gt;
A correction term is added that drives velocity to divergence free field&lt;br /&gt;
\[\nabla \cdot ({{\b{v}}^{inter}}+{{\b{v}}^{corr}})=0 \qquad \to \qquad \nabla \cdot {{\b{v}}^{inter}}=-\nabla \cdot {{\b{v}}^{corr}}\]&lt;br /&gt;
&lt;br /&gt;
Velocity correction is affected only by effect of pressure correction. This fact is obvious due to all terms except gradient of pressure on the right side of equation  are constant.&lt;br /&gt;
\[{{\b{v}}^{corr}}=-\frac{\Delta t}{\rho }\nabla {{p}^{corr}} \]&lt;br /&gt;
&lt;br /&gt;
Note that corrected velocity also satisfies boundary conditions&lt;br /&gt;
\[\b{v}^{iter}+\b{v}^{corr}=\b{v}^{BC}\]&lt;br /&gt;
Applying divergence  and  we get '''pressure correction poisson equation'''.&lt;br /&gt;
\[\,{{\nabla }^{2}}{{p}^{corr}}\,=\frac{\rho }{\Delta t}\nabla \cdot {{\mathbf{v}}^{iter}}\,\]&lt;br /&gt;
&lt;br /&gt;
Boundary conditions can be obtained by mulitplying the equation with a unit normal vector $\b{\hat{n}}$&lt;br /&gt;
\[\frac{\Delta t}{\rho }\frac{\partial {p}^{corr}}{\partial \b{\hat{n}}} = \b{\hat{n}} \cdot \left(\b{v}^{iter} - \b{v}^{BC} \right) \]&lt;br /&gt;
The most straightforward approach, for dirichlet BCs, is to take into account velocity boundary condition in computation of intermediate velocity, and clearly in such cases, pressure boundary condition simplifies to &lt;br /&gt;
\[\frac{\partial p^{corr}}{\partial \b{\hat{n}}} = 0 \]&lt;br /&gt;
As ${{\b{v}}^{\operatorname{int}er}}={{\b{v}}^{BC}}$ . Another option is to explicitely compute intermediate velocity also on boundaries and then correct it through pressure correction.&lt;br /&gt;
&lt;br /&gt;
The pressure poisson equation is, at given boundary conditions, defined only up to a constant. One solution is to select a node and set it to a constant, e.g. p(0, 0) = 0, however much more stable approach is to enforce solution with additional condition, also referred to as a regularization&lt;br /&gt;
	\[\int_{\Omega }^{{}}{pd}\Omega =0\]&lt;br /&gt;
\[\,{{\nabla }^{2}}{{p}^{corr}}\,-\alpha =\frac{\rho }{\Delta t}\nabla \cdot {{\b{v}}^{iter}}\,\]&lt;br /&gt;
Where $\alpha $ stands for Lagrange multiplier. Or in discrete form&lt;br /&gt;
	\[\sum\limits_{i}{p\left( {{x}_{i}} \right)=0}\]&lt;br /&gt;
	\[\b{Mp}-\alpha \b{1}=\frac{\rho }{\Delta t}\nabla \cdot {{\b{v}}^{iter}}\]&lt;br /&gt;
&lt;br /&gt;
where $\b{M}$ holds Laplace shape functions, i.e. the discrete version of Laplace differential operator. &lt;br /&gt;
&lt;br /&gt;
Solution of a system&lt;br /&gt;
&lt;br /&gt;
	\[\left[ \begin{matrix}&lt;br /&gt;
   {{M}_{11}} &amp;amp; .. &amp;amp; {{M}_{1n}} &amp;amp; 1  \\&lt;br /&gt;
   .. &amp;amp; .. &amp;amp; .. &amp;amp; 1  \\&lt;br /&gt;
   {{M}_{n1}} &amp;amp; ... &amp;amp; {{M}_{nn}} &amp;amp; 1  \\&lt;br /&gt;
   1 &amp;amp; 1 &amp;amp; 1 &amp;amp; 0  \\&lt;br /&gt;
\end{matrix} \right]\left[ \begin{matrix}&lt;br /&gt;
   {{p}_{1}}  \\&lt;br /&gt;
   ...  \\&lt;br /&gt;
   {{p}_{n}}  \\&lt;br /&gt;
   \alpha   \\&lt;br /&gt;
\end{matrix} \right]=\frac{\rho }{\Delta t}\left[ \begin{matrix}&lt;br /&gt;
   \nabla \cdot \b{v}_{_{1}}^{\text{iter}}  \\&lt;br /&gt;
   ...  \\&lt;br /&gt;
   \nabla \cdot \b{v}_{n}^{\text{iter}}  \\&lt;br /&gt;
   0  \\&lt;br /&gt;
\end{matrix} \right]\]&lt;br /&gt;
Gives us a solution of pressure correction.&lt;br /&gt;
&lt;br /&gt;
== CBS Algorithm ==&lt;br /&gt;
With explicit temporal discretization problem is formulated as&lt;br /&gt;
\[\b{\hat{v}}={{\b{v}}_{0}}+\Delta t\left( -\nabla {{p}_{0}}+\frac{1}{Re}{{\nabla }^{2}}{{\b{v}}_{0}}-\nabla \cdot ({{\b{v}}_{0}}{{\b{v}}_{0}}) \right)\]&lt;br /&gt;
\[p={{p}_{0}}-\xi \Delta {{t}_{F}}\nabla \b{\hat{v}}+\xi \Delta {{t}_{F}}\Delta t{{\nabla }^{2}}{{\overset{\scriptscriptstyle\frown}{P}}_{0}},\]&lt;br /&gt;
where $\b{\hat{v}}$, $\Delta t$, $\xi$ and $\Delta t_F$ stand for intermediate velocity, time step, relaxation parameter, and artificial time step, respectively, and index 0 stands for previous time / iteration step. First, the intermediate velocity is computed from previous time step. Second, the velocity is driven towards solenoidal field by correcting the pressure. Note that no special boundary conditions for pressure are used, i.e., the pressure on boundaries is computed with the same approach as in the interior of the domain. In general, the internal iteration with an artificial time step is required until the divergence of the velocity field is not below required criteria. However, if one is interested only in a steady-state solution, the internal iteration can be skipped and $\Delta t$ equals $\Delta {{t}_{F}}$. Without internal stepping the transient of the solution is distorted by artificial compressibility effect. This approach is also known as ACM with Characteristics-based discretization of continuity equation, where the relaxation parameter relates to the artificial speed of sound [35].&lt;br /&gt;
&lt;br /&gt;
The relaxation parameter should be set between 1-10, lower number more stable solution.&lt;br /&gt;
&lt;br /&gt;
And also dimensional form&lt;br /&gt;
&lt;br /&gt;
\[p={{p}_{0}}-{{C}^{2}}\Delta {{t}_{F}}\rho \nabla \b{\hat{v}}+{{C}^{2}}\Delta {{t}_{F}}\Delta t{{\nabla }^{2}}{{p}_{0}},\]&lt;br /&gt;
&lt;br /&gt;
Where C is speed of sound [m/s]&lt;br /&gt;
&lt;br /&gt;
== Numerical examples==&lt;br /&gt;
* [[Lid driven cavity]]&lt;br /&gt;
* [[de Vahl Davis natural convection test]]&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Weighted_Least_Squares_(WLS)&amp;diff=1215</id>
		<title>Weighted Least Squares (WLS)</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Weighted_Least_Squares_(WLS)&amp;diff=1215"/>
				<updated>2017-07-06T12:49:29Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Numerical calculation of the shape functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;One of the most important building blocks of the meshless methods is the Moving Least Squares (MLS) approximation , which is implemented in the [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/technical_docs/html/classEngineMLS.html EngineMLS class]. Check [https://gitlab.com/e62Lab/e62numcodes/blob/master/test/mls_test.cpp EngineMLS unit tests] for examples.&lt;br /&gt;
&lt;br /&gt;
= Notation Cheat sheet =&lt;br /&gt;
\begin{align*}&lt;br /&gt;
  m \in \N                  &amp;amp; \dots \text{number of basis functions} \\&lt;br /&gt;
  n \geq m \in \N           &amp;amp; \dots \text{number of points in support domain} \\&lt;br /&gt;
  k \in \mathbb{N}          &amp;amp; \dots \text{dimensionality of vector space} \\&lt;br /&gt;
  \vec s_j \in \R^k         &amp;amp; \dots \text{point in support domain } \quad j=1,\dots,n \\&lt;br /&gt;
  u_j \in \R                &amp;amp; \dots \text{value of function to approximate in }\vec{s}_j \quad j=1,\dots,n \\&lt;br /&gt;
  \vec p \in \R^k           &amp;amp; \dots \text{center point of approximation} \\&lt;br /&gt;
  b_i\colon \R^k \to \R     &amp;amp; \dots \text{basis functions } \quad i=1,\dots,m \\&lt;br /&gt;
  B_{j, i} \in \R           &amp;amp; \dots \text{value of basis functions in support points } b_i(s_j-p) \quad j=1,\dots,n, \quad i=1,\dots,m\\&lt;br /&gt;
  \omega \colon \R^k \to \R &amp;amp; \dots \text{weight function} \\&lt;br /&gt;
  w_j \in \R                &amp;amp; \dots \text{weights } \omega(\vec{s}_j-\vec{p})  \quad j=1,\dots,n \\&lt;br /&gt;
  \alpha_i \in \R           &amp;amp; \dots \text{expansion coefficients around point } \vec{p} \quad i=1,\dots,m \\&lt;br /&gt;
  \hat u\colon \R^k \to \R  &amp;amp; \dots \text{approximation function (best fit)} \\&lt;br /&gt;
  \chi_j \in \R          &amp;amp; \dots \text{shape coefficient for point }\vec{p} \quad j=1,\dots,n \\&lt;br /&gt;
\end{align*}&lt;br /&gt;
&lt;br /&gt;
We will also use \(\b{s}, \b{u}, \b{b}, \b{\alpha}, \b{\chi} \) to annotate a column of corresponding values,&lt;br /&gt;
$W$ as a $n\times n$ diagonal matrix filled with $w_j$ on the diagonal and $B$ as a $n\times m$ matrix filled with $B_{j, i}$.&lt;br /&gt;
&lt;br /&gt;
= Definition of local approximation =&lt;br /&gt;
&amp;lt;figure id=&amp;quot;fig:1DWLS&amp;quot;&amp;gt;&lt;br /&gt;
[[File:image_1avhdsfej1b9cao01029m1e13o69.png|600px|thumb|upright=2|alt=1D MLS example|&amp;lt;caption&amp;gt;Example of 1D WLS approximation &amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
Our wish is to approximate an unknown function $u\colon \R^k \to \R$ while knowing $n$ values $u(\vec{s}_j) := u_j$.&lt;br /&gt;
The vector of known values will be denoted by $\b{u}$ and the vector of coordinates where those values were achieved by $\b{s}$.&lt;br /&gt;
Note that $\b{s}$ is not a vector in the usual sense since its components $\vec{s}_j$ are elements of $\R^k$, but we will call it vector anyway.&lt;br /&gt;
The values of $\b{s}$ are called ''nodes'' or ''support nodes'' or ''support''. The known values $\b{u}$ are also called ''support values''.&lt;br /&gt;
&lt;br /&gt;
In general, an approximation function around point $\vec{p}\in\R^k$ can be&lt;br /&gt;
written as \[\hat{u} (\vec{x}) = \sum_{i=1}^m \alpha_i b_i(\vec{x}) = \b{b}(\vec{x})^\T \b{\alpha} \]&lt;br /&gt;
where $\b{b} = (b_i)_{i=1}^m$ is a set of ''basis functions'', $b_i\colon \R^k \to\R$, and $\b{\alpha} = (\alpha_i)_{i=1}^m$ are the unknown coefficients.&lt;br /&gt;
&lt;br /&gt;
In MLS the goal is to minimize the error of approximation in given values, $\b{e} = \hat u(\b{s}) - \b{u}$&lt;br /&gt;
between the approximation function and target function in the known points $\b{x}$. The error can also be written as $B\b{\alpha} - \b{u}$,&lt;br /&gt;
where $B$ is rectangular matrix of dimensions $n \times m$ with rows containing basis function evaluated in points $\vec{s}_j$.&lt;br /&gt;
\[ B =&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
b_1(\vec{s}_1) &amp;amp; \ldots &amp;amp; b_m(\vec{s}_1) \\&lt;br /&gt;
\vdots &amp;amp; \ddots &amp;amp; \vdots \\&lt;br /&gt;
b_1(\vec{s}_n) &amp;amp; \ldots &amp;amp; b_m(\vec{s}_n)&lt;br /&gt;
\end{bmatrix} =&lt;br /&gt;
 [b_i(\vec{s}_j)]_{j=1,i=1}^{n,m} = [\b{b}(\vec{s}_j)^\T]_{j=1}^n. \]&lt;br /&gt;
&lt;br /&gt;
We can choose to minimize any norm of the error vector $e$&lt;br /&gt;
and usually choose to minimize the $2$-norm or square norm \[ \|\b{e}\| = \|\b{e}\|_2 = \sqrt{\sum_{j=1}^n e_j^2}. \]&lt;br /&gt;
Commonly, we also choose to minimize a weighted norm&lt;br /&gt;
&amp;lt;ref&amp;gt;Note that our definition is a bit unusual, usually weights are not&lt;br /&gt;
 squared with the values. However, we do this to avoid computing square&lt;br /&gt;
 roots when doing MLS. If you are used to the usual definition,&lt;br /&gt;
consider the weight to be $\omega^2$.&amp;lt;/ref&amp;gt;&lt;br /&gt;
instead \[ \|\b{e}\|_{2,w} = \|\b{e}\|_w = \sqrt{\sum_{j=1}^n (w_j e_j)^2}. \]&lt;br /&gt;
The ''weights'' $w_i$ are assumed to be non negative and are assembled in a vector $\b{w}$ or a matrix $W = \operatorname{diag}(\b{w})$ and usually obtained from a weight function.&lt;br /&gt;
A ''weight function'' is a function $\omega\colon \R^k \to[0,\infty)$. We calculate $w_j$ as $w_i := \omega(\vec{p}-\vec{s}_j)$, so&lt;br /&gt;
good choices for $\omega$ are function which have higher values close to $0$ (making closer nodes more important), like the normal distribution.&lt;br /&gt;
If we choose $\omega \equiv 1$, we get the unweighted version.&lt;br /&gt;
&lt;br /&gt;
A choice of minimizing the square norm gave this method its name - Least Squares approximation. If we use the weighted version, we get the Weighted Least Squares or WLS.&lt;br /&gt;
In the most general case we wish to minimize&lt;br /&gt;
\[ \|\b{e}\|_{2,w}^2 = \b{e}^\T W^2 \b{e} = (B\b{\alpha} - \b{u})^\T W^2(B\b{\alpha} - \b{u}) =  \sum_j^n w_j^2 (\hat{u}(\vec{s}_j) - u_j)^2  \]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The problem of finding the coefficients $\b{\alpha}$ that minimize the error $\b{e}$ can be solved with at least three approaches:&lt;br /&gt;
* Normal equations (fastest, less accurate) - using Cholesky decomposition of $B$ (requires full rank and $m \leq n$)&lt;br /&gt;
* QR decomposition of $B$ (requires full rank and $m \leq n$, more precise)&lt;br /&gt;
* SVD decomposition of $B$ (more expensive, even more reliable, no rank demand)&lt;br /&gt;
&lt;br /&gt;
In our Meshless Machine MLS engine we use SVD with regularization described below.&lt;br /&gt;
&lt;br /&gt;
= Computing approximation coefficients =&lt;br /&gt;
&lt;br /&gt;
== [http://mathworld.wolfram.com/NormalEquation.html Normal equations] ==&lt;br /&gt;
We seek the minimum of&lt;br /&gt;
\[ \|\b{e}\|_2^2 = (B\b{\alpha} - \b{u})^\T(B\b{\alpha} - \b{u}) \]&lt;br /&gt;
By seeking the zero gradient in terms of coefficients $\alpha_i$&lt;br /&gt;
\[\frac{\partial}{\partial \alpha_i} (B\b{\alpha} - \b{u})^\T(B\b{\alpha} - \b{u})  = 0\]&lt;br /&gt;
resulting in&lt;br /&gt;
\[ B^\T B\b{\alpha} = B^\T \b{u}. \]&lt;br /&gt;
The coefficient matrix $B^\T B$ is symmetric and positive definite. However, solving above problem directly is&lt;br /&gt;
poorly behaved with respect to round-off errors since the condition number $\kappa(B^\T B)$ is the square&lt;br /&gt;
of $\kappa(B)$.&lt;br /&gt;
&lt;br /&gt;
In case of WLS the equations become&lt;br /&gt;
\[ (WB)^\T WB \b{\alpha} = WB^\T \b{u}. \]&lt;br /&gt;
&lt;br /&gt;
Complexity of Cholesky decomposition is $\frac{n^3}{3}$ and complexity of matrix multiplication $nm^2$. To preform the Cholesky decomposition the rank of $WB$ must be full.&lt;br /&gt;
&lt;br /&gt;
'''Pros:'''&lt;br /&gt;
* simple to implement&lt;br /&gt;
* low computational complexity&lt;br /&gt;
&lt;br /&gt;
'''Cons:'''&lt;br /&gt;
* numerically unstable&lt;br /&gt;
* full rank requirement&lt;br /&gt;
&lt;br /&gt;
== [https://en.wikipedia.org/wiki/QR_decomposition $QR$ Decomposition] ==&lt;br /&gt;
\[{\bf{B}} = {\bf{QR}} = \left[ {{{\bf{Q}}_1},{{\bf{Q}}_2}} \right]\left[ {\begin{array}{*{20}{c}}&lt;br /&gt;
{{{\bf{R}}_1}}\\&lt;br /&gt;
0&lt;br /&gt;
\end{array}} \right]\]&lt;br /&gt;
\[{\bf{B}} = {{\bf{Q}}_1}{{\bf{R}}_1}\]&lt;br /&gt;
$\bf{Q}$ is unitary matrix ($\bf{Q}^{-1}=\bf{Q}^T$). Useful property of a unitary matrices is that multiplying with them does not alter the (Euclidean) norm of a vector, i.e.,&lt;br /&gt;
\[\left\| {{\bf{Qx}}} \right\|{\bf{ = }}\left\| {\bf{x}} \right\|\]&lt;br /&gt;
And $\bf{R}$ is upper diagonal matrix&lt;br /&gt;
\[{\bf{R = (}}{{\bf{R}}_{\bf{1}}}{\bf{,}}0{\bf{)}}\]&lt;br /&gt;
therefore we can say&lt;br /&gt;
\[\begin{array}{l}&lt;br /&gt;
\left\| {{\bf{B\alpha }} - {\bf{u}}} \right\| = \left\| {{{\bf{Q}}^{\rm{T}}}\left( {{\bf{B\alpha }} - {\bf{u}}} \right)} \right\| = \left\| {{{\bf{Q}}^{\rm{T}}}{\bf{B\alpha }} - {{\bf{Q}}^{\rm{T}}}{\bf{u}}} \right\|\\&lt;br /&gt;
 = \left\| {{{\bf{Q}}^{\rm{T}}}\left( {{\bf{QR}}} \right){\bf{\alpha }} - {{\bf{Q}}^{\rm{T}}}{\bf{u}}} \right\| = \left\| {\left( {{{\bf{R}}_1},0} \right){\bf{\alpha }} - {{\left( {{{\bf{Q}}_1},{{\bf{Q}}_{\bf{2}}}} \right)}^{\rm{T}}}{\bf{u}}} \right\|\\&lt;br /&gt;
 = \left\| {{{\bf{R}}_{\bf{1}}}{\bf{\alpha }} - {{\bf{Q}}_{\bf{1}}}{\bf{u}}} \right\| + \left\| {{\bf{Q}}_2^{\rm{T}}{\bf{u}}} \right\|&lt;br /&gt;
\end{array}\]&lt;br /&gt;
Of the two terms on the right we have no control over the second, and we can render the first one&lt;br /&gt;
zero by solving&lt;br /&gt;
\[{{\bf{R}}_{\bf{1}}}{\bf{\alpha }} = {\bf{Q}}_{_{\bf{1}}}^{\rm{T}}{\bf{u}}\]&lt;br /&gt;
Which results in a minimum. We could also compute it with pseudo inverse&lt;br /&gt;
	\[\mathbf{\alpha }={{\mathbf{B}}^{-1}}\mathbf{u}\]&lt;br /&gt;
Where pseudo inverse is simply \[{{\mathbf{B}}^{-1}}=\mathbf{R}_{\text{1}}^{\text{-1}}{{\mathbf{Q}}^{\text{T}}}\] (once again, $R$ is upper diagonal matrix, and $Q$ is unitary matrix).&lt;br /&gt;
And for weighted case&lt;br /&gt;
	\[\mathbf{\alpha }={{\left( {{\mathbf{W}}^{0.5}}\mathbf{B} \right)}^{-1}}\left( {{\mathbf{W}}^{0.5}}\mathbf{u} \right)\]&lt;br /&gt;
&lt;br /&gt;
Complexity of $QR$ decomposition \[\frac{2}{3}m{{n}^{2}}+{{n}^{2}}+\frac{1}{3}n-2=O({{n}^{3}})\]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;Pros:&amp;lt;/strong&amp;gt; better stability in comparison with normal equations &amp;lt;strong&amp;gt; cons: &amp;lt;/strong&amp;gt;higher complexity&lt;br /&gt;
&lt;br /&gt;
== [https://en.wikipedia.org/wiki/Singular_value_decomposition SVD decomposition] ==&lt;br /&gt;
In linear algebra, the [https://en.wikipedia.org/wiki/Singular_value_decomposition singular value decomposition (SVD)]&lt;br /&gt;
is a factorization of a real or complex matrix. It has many useful&lt;br /&gt;
applications in signal processing and statistics.&lt;br /&gt;
&lt;br /&gt;
Formally, the singular value decomposition of an $m \times n$ real or complex&lt;br /&gt;
matrix $\bf{B}$ is a factorization of the form $\bf{B}= \bf{U\Sigma V^\T}$, where&lt;br /&gt;
$\bf{U}$ is an $m \times m$ real or complex unitary matrix, $\bf{\Sigma}$ is an $m \times n$&lt;br /&gt;
rectangular diagonal matrix with non-negative real numbers on the diagonal, and&lt;br /&gt;
$\bf{V}^\T$  is an $n \times n$ real or complex unitary matrix. The diagonal entries&lt;br /&gt;
$\Sigma_{ii}$ are known as the singular values of $\bf{B}$. The $m$ columns of&lt;br /&gt;
$\bf{U}$ and the $n$ columns of $\bf{V}$ are called the left-singular vectors and&lt;br /&gt;
right-singular vectors of $\bf{B}$, respectively.&lt;br /&gt;
&lt;br /&gt;
The singular value decomposition and the eigen decomposition are closely&lt;br /&gt;
related. Namely:&lt;br /&gt;
&lt;br /&gt;
* The left-singular vectors of $\bf{B}$ are eigen vectors of $\bf{BB}^\T$.&lt;br /&gt;
* The right-singular vectors of $\bf{B}$ are eigen vectors of $\bf{B}^\T{B}$.&lt;br /&gt;
* The non-zero singular values of $\bf{B}$ (found on the diagonal entries of $\bf{\Sigma}$) are the square roots of the non-zero eigenvalues of both $\bf{B}^\T\bf{B}$ and $\bf{B}^\T \bf{B}$.&lt;br /&gt;
&lt;br /&gt;
with SVD we can write $\bf{B}$ as \[\bf{B}=\bf{U\Sigma{{V}^{\T}}}\] where are $\bf{U}$ and $\bf{V}$ again unitary matrices and $\bf{\Sigma}$&lt;br /&gt;
stands for diagonal matrix of singular values.&lt;br /&gt;
&lt;br /&gt;
Again we can solve either the system or compute pseudo inverse as&lt;br /&gt;
&lt;br /&gt;
\[ \bf{B}^{-1} = \left( \bf{U\Sigma V}^\T\right)^{-1} = \bf{V}\bf{\Sigma^{-1}U}^\T \]&lt;br /&gt;
where $\bf{\Sigma}^{-1}$ is trivial, just replace every non-zero diagonal entry by&lt;br /&gt;
its reciprocal and transpose the resulting matrix. The stability gain is&lt;br /&gt;
exactly here, one can now set threshold below which the singular value is&lt;br /&gt;
considered as $0$, basically truncate all singular values below some value and&lt;br /&gt;
thus stabilize the inverse.&lt;br /&gt;
&lt;br /&gt;
SVD decomposition complexity \[ 2mn^2+2n^3 = O(n^3) \]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;Pros:&amp;lt;/strong&amp;gt; stable &amp;lt;strong&amp;gt; cons: &amp;lt;/strong&amp;gt;high complexity&lt;br /&gt;
&lt;br /&gt;
Method used in MLSM is SVD with regularization.&lt;br /&gt;
&lt;br /&gt;
= Weighted Least Squares =&lt;br /&gt;
Weighted least squares approximation is the simplest version of the procedure described above. Given support $\b{s}$, values $\b{u}$&lt;br /&gt;
and an anchor point $\vec{p}$, we calculate the coefficients $\b{\alpha}$ using one of the above methods.&lt;br /&gt;
Then, to approximate a function in the neighbourhood of $\vec p$ we use the formula&lt;br /&gt;
\[&lt;br /&gt;
\hat{u}(\vec x) = \b{b}(\vec x)^\T \b{\alpha} = \sum_{i=1}^m \alpha_i b_i(\vec x).&lt;br /&gt;
\]&lt;br /&gt;
&lt;br /&gt;
To approximate the derivative $\frac{\partial u}{\partial x_i}$, or any linear partial differential operator $\mathcal L$ on $u$, we&lt;br /&gt;
simply take the same linear combination of transformed basis functions $\mathcal L b_i$. We have considered coefficients $\alpha_i$ to be&lt;br /&gt;
constant and applied the linearity.&lt;br /&gt;
\[&lt;br /&gt;
 \widehat{\mathcal L u}(\vec x) = \sum_{i=1}^m \alpha_i (\mathcal L b_i)(\vec x).&lt;br /&gt;
\]&lt;br /&gt;
&lt;br /&gt;
= WLS at fixed point with fixed support and unknown function values :: Shape functions =&lt;br /&gt;
Suppose now we are given support $\b{s}$ and a point $\b{p}$ and want to construct the function approximation from values $\b{u}$.&lt;br /&gt;
We proceed as usual, solving the overdetermined system $WB \b{\alpha} = W\b{u}$ for coefficients $\b{\alpha}$ using the pseudoinverse&lt;br /&gt;
\[ \b{\alpha} = (WB)^+W\b{u}, \]&lt;br /&gt;
where $A^+$ denotes the Moore-Penrose pseudoinverse that can be calculated using SVD.&lt;br /&gt;
&lt;br /&gt;
Writing down the approximation function $\hat{u}$ we get&lt;br /&gt;
\[&lt;br /&gt;
\hat u (\vec{p}) = \b{b}(\vec{p})^\T \b{\alpha} = \b{b}(\vec{p})^\T (WB)^+W\b{u} = \b{\chi}(\vec{p}) \b{u}.&lt;br /&gt;
\]&lt;br /&gt;
&lt;br /&gt;
We have defined $\b{\chi}$ to be&lt;br /&gt;
\[ \b{\chi}(\vec{p}) = \b{b}(\vec{p})^\T (WB)^+W. \]&lt;br /&gt;
Vector $\b{\chi}$  is a row vector, also called a ''shape function''. The name comes from being able to take all the information&lt;br /&gt;
about shape of the domain and choice of approximation and store it in a single row vector, being able to approximate&lt;br /&gt;
a function value from given support values $\b{u}$ with a single dot product. For any values $\b{u}$, value $\b{\chi}(p) \b{u}$&lt;br /&gt;
gives us the approximation $\hat{u}(\vec{p})$ of $u$ in point $\vec{p}$.&lt;br /&gt;
Mathematically speaking, $\b{\chi}(\vec{p})$ is a functional, $\b{\chi}(\vec{p})\colon \R^n \to \R$, mapping $n$-tuples of known function values to&lt;br /&gt;
their approximations in point $\vec{p}$.&lt;br /&gt;
&lt;br /&gt;
The same approach works for any linear operator $\mathcal L$ applied to $u$, just replace every $b_i$ in definition of $\b{\chi}$ with $\mathcal Lb_i$.&lt;br /&gt;
For example, take a $1$-dimensional case for approximation of derivatives with weight equal to $1$ and $n=m=3$, with equally spaced support values at distances $h$.&lt;br /&gt;
We wish to approximate $u''$ in the middle support point, just by making a weighted sum of the values, something like the finite difference&lt;br /&gt;
\[ u'' \approx \frac{u_1 - 2u_2 + u_3}{h^2}. \]&lt;br /&gt;
This is exactly the same formula as we would have come to by computing $\b{\chi}$, except that our approach is a lot more general. But one should think about&lt;br /&gt;
$\b{\chi}$ as one would about the finite difference scheme, it is a rule, telling us how to compute the derivative.&lt;br /&gt;
\[ u''(s_2) \approx \underbrace{\begin{bmatrix} \frac{1}{h^2} &amp;amp; \frac{-2}{h^2} &amp;amp; \frac{1}{h^2} \end{bmatrix}}_{\b{\chi}} \begin{bmatrix}u_1 \\ u_2 \\ u_3 \end{bmatrix}  \]&lt;br /&gt;
&lt;br /&gt;
The fact that $\b{\chi}$ is independent of the function values $\b{u}$ but depend only on domain geometry means that&lt;br /&gt;
'''we can just compute the shape functions $\b{\chi}$ for points of interest and then approximate any linear operator&lt;br /&gt;
of any function, given its values, very fast, using only a single dot product.'''&lt;br /&gt;
&lt;br /&gt;
== Numerical calculation of the shape functions ==&lt;br /&gt;
The expression&lt;br /&gt;
\[ \b{\chi}(\vec{p}) = \b{b}(\vec{p})^\T (WB)^+W \]&lt;br /&gt;
can be evaluated directly, but this is not the most optimal approach. A numerically cheaper and more stable way is to translate the problem of inverting the matrix to solving a linear system of equations.&lt;br /&gt;
&lt;br /&gt;
'''Invertible $B$ case:'''&lt;br /&gt;
If $B$ is invertible, then $\b{\chi}(\vec{p}) = \b{b}(\vec{p})^\T B^{-1}$, transposing the equation then multiplying it from the left by $B$, &lt;br /&gt;
$\b{\chi}$ can be thought as a solution of a system $B^\T\chi(\vec{p})^\T = \b{b}(\vec{p})$, which can be solved using LU or Cholesky decomposition for example.&lt;br /&gt;
&lt;br /&gt;
'''General case:''' &lt;br /&gt;
For a system written as $Ax = b$, where $A$ is a $n\times m$ matrix, $x$ is a vector of length $m$ and $b$ a vector of length $n$, a generalized solution&lt;br /&gt;
is defined as $x$ that minimizes $\|A x - b\|_2^2$. If more $x$ attain the minimal value, $x$ with the minimal $\|x\|$ is chosen. Note that this generalizes the solution &lt;br /&gt;
a general system ($A$ is invertible) and over-determined system ($n &amp;gt; m$ and $A$ has full rank). Such an $x$ can be computed using the pseudoinverse $x = A^{+} b$. &lt;br /&gt;
&lt;br /&gt;
In our case, let us denote a part of the solution containing the pseudoinverse by $\tilde{\b{\chi}}$. &lt;br /&gt;
\[ \b{\chi}(\vec{p}) = \underbrace{\b{b}(\vec{p})^\T (WB)^+}_{\tilde{\b{\chi}}} W \]&lt;br /&gt;
We have an expression $\tilde{\b{\chi}} = \b{b}(\vec{p})^\T (WB)^+$ which after transposition takes the form $\tilde{\b{\chi}}^\T = ((WB)^\T)^+\b{b}(\vec{p})$, the same as $x = A^+b$ above.&lt;br /&gt;
Therefore, $\tilde{\b{\chi}}^\T$ is the solution of an (indeterminate) system $(WB)^\T \tilde{\b{\chi}}^\T = \b{b}(\vec{p})$. &lt;br /&gt;
After solving that, we can get the shape function $\b\chi(\vec{p}) = \tilde{\b{\chi}} W$ by multiplying by matrix $W$. &lt;br /&gt;
The system before can be solved using any decomposition of matrix $(WB)^\T = B^\T W$ necessary, mosr generally the SVD decompostion, but depending on our knowledge of the &lt;br /&gt;
problem, we can use Cholesky ($B^\T W$ is positive definite), $LDL^\T$ if it is symmetric, $LU$ for a general square matrix, $QR$ for full rank overdetermined system and SVD for a general system.&lt;br /&gt;
Is more shapes need to be calculated using the same matrix $B^\T W$ and only different right hand sides, it can be done efficiently by storing the decomposition of $B^\T W$.&lt;br /&gt;
&lt;br /&gt;
= MLS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;figure id=&amp;quot;fig:comparisonMLSandWLS&amp;quot;&amp;gt;&lt;br /&gt;
[[File:mlswls.svg|thumb|upright=2|&amp;lt;caption&amp;gt;Comparison of WLS and MLS approximation&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When using WLS the approximation gets worse as we move away from the central point $\vec{p}$.&lt;br /&gt;
This is partially due to not being in the center of the support any more and partially due to weight&lt;br /&gt;
being distributed in such a way to assign more importance to nodes closer to $\vec{p}$.&lt;br /&gt;
&lt;br /&gt;
We can battle this problem in two ways: when we wish to approximate in a new point that is sufficiently far&lt;br /&gt;
away from $\vec{p}$ we can compute new support, recompute the new coefficients $\b{\alpha}$ and approximate again.&lt;br /&gt;
This is very costly and we would like to avoid that. A partial fix is to keep support the same, but only&lt;br /&gt;
recompute the weight vector $\b{w}$, that will now assign weight values to nodes close to the new point.&lt;br /&gt;
We still need to recompute the coefficients $\b{\alpha}$, however we avoid the cost of setting up new support&lt;br /&gt;
and function values and recomputing $B$. This approach is called Moving Least Squares due to recomputing&lt;br /&gt;
the weighted least squares problem whenever we move the point of approximation.&lt;br /&gt;
&lt;br /&gt;
Note that if out weight is constant or if $n = m$, when approximation reduces to interpolation, the weights do not play&lt;br /&gt;
any role and this method is redundant. In fact, its benefits arise when supports are rather large.&lt;br /&gt;
&lt;br /&gt;
See &amp;lt;xr id=&amp;quot;fig:comparisonMLSandWLS&amp;quot;/&amp;gt; for comparison between MLS and WLS approximations. MLS approximation remains close to&lt;br /&gt;
actual function while still inside the support domain, while WLS approximation becomes bad when&lt;br /&gt;
we come out of the reach of the weight function.&lt;br /&gt;
&lt;br /&gt;
{{reflist}}&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Weighted_Least_Squares_(WLS)&amp;diff=1214</id>
		<title>Weighted Least Squares (WLS)</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Weighted_Least_Squares_(WLS)&amp;diff=1214"/>
				<updated>2017-07-06T12:24:04Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Numerical calculation of the shape functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;One of the most important building blocks of the meshless methods is the Moving Least Squares (MLS) approximation , which is implemented in the [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/technical_docs/html/classEngineMLS.html EngineMLS class]. Check [https://gitlab.com/e62Lab/e62numcodes/blob/master/test/mls_test.cpp EngineMLS unit tests] for examples.&lt;br /&gt;
&lt;br /&gt;
= Notation Cheat sheet =&lt;br /&gt;
\begin{align*}&lt;br /&gt;
  m \in \N                  &amp;amp; \dots \text{number of basis functions} \\&lt;br /&gt;
  n \geq m \in \N           &amp;amp; \dots \text{number of points in support domain} \\&lt;br /&gt;
  k \in \mathbb{N}          &amp;amp; \dots \text{dimensionality of vector space} \\&lt;br /&gt;
  \vec s_j \in \R^k         &amp;amp; \dots \text{point in support domain } \quad j=1,\dots,n \\&lt;br /&gt;
  u_j \in \R                &amp;amp; \dots \text{value of function to approximate in }\vec{s}_j \quad j=1,\dots,n \\&lt;br /&gt;
  \vec p \in \R^k           &amp;amp; \dots \text{center point of approximation} \\&lt;br /&gt;
  b_i\colon \R^k \to \R     &amp;amp; \dots \text{basis functions } \quad i=1,\dots,m \\&lt;br /&gt;
  B_{j, i} \in \R           &amp;amp; \dots \text{value of basis functions in support points } b_i(s_j-p) \quad j=1,\dots,n, \quad i=1,\dots,m\\&lt;br /&gt;
  \omega \colon \R^k \to \R &amp;amp; \dots \text{weight function} \\&lt;br /&gt;
  w_j \in \R                &amp;amp; \dots \text{weights } \omega(\vec{s}_j-\vec{p})  \quad j=1,\dots,n \\&lt;br /&gt;
  \alpha_i \in \R           &amp;amp; \dots \text{expansion coefficients around point } \vec{p} \quad i=1,\dots,m \\&lt;br /&gt;
  \hat u\colon \R^k \to \R  &amp;amp; \dots \text{approximation function (best fit)} \\&lt;br /&gt;
  \chi_j \in \R          &amp;amp; \dots \text{shape coefficient for point }\vec{p} \quad j=1,\dots,n \\&lt;br /&gt;
\end{align*}&lt;br /&gt;
&lt;br /&gt;
We will also use \(\b{s}, \b{u}, \b{b}, \b{\alpha}, \b{\chi} \) to annotate a column of corresponding values,&lt;br /&gt;
$W$ as a $n\times n$ diagonal matrix filled with $w_j$ on the diagonal and $B$ as a $n\times m$ matrix filled with $B_{j, i}$.&lt;br /&gt;
&lt;br /&gt;
= Definition of local approximation =&lt;br /&gt;
&amp;lt;figure id=&amp;quot;fig:1DWLS&amp;quot;&amp;gt;&lt;br /&gt;
[[File:image_1avhdsfej1b9cao01029m1e13o69.png|600px|thumb|upright=2|alt=1D MLS example|&amp;lt;caption&amp;gt;Example of 1D WLS approximation &amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
Our wish is to approximate an unknown function $u\colon \R^k \to \R$ while knowing $n$ values $u(\vec{s}_j) := u_j$.&lt;br /&gt;
The vector of known values will be denoted by $\b{u}$ and the vector of coordinates where those values were achieved by $\b{s}$.&lt;br /&gt;
Note that $\b{s}$ is not a vector in the usual sense since its components $\vec{s}_j$ are elements of $\R^k$, but we will call it vector anyway.&lt;br /&gt;
The values of $\b{s}$ are called ''nodes'' or ''support nodes'' or ''support''. The known values $\b{u}$ are also called ''support values''.&lt;br /&gt;
&lt;br /&gt;
In general, an approximation function around point $\vec{p}\in\R^k$ can be&lt;br /&gt;
written as \[\hat{u} (\vec{x}) = \sum_{i=1}^m \alpha_i b_i(\vec{x}) = \b{b}(\vec{x})^\T \b{\alpha} \]&lt;br /&gt;
where $\b{b} = (b_i)_{i=1}^m$ is a set of ''basis functions'', $b_i\colon \R^k \to\R$, and $\b{\alpha} = (\alpha_i)_{i=1}^m$ are the unknown coefficients.&lt;br /&gt;
&lt;br /&gt;
In MLS the goal is to minimize the error of approximation in given values, $\b{e} = \hat u(\b{s}) - \b{u}$&lt;br /&gt;
between the approximation function and target function in the known points $\b{x}$. The error can also be written as $B\b{\alpha} - \b{u}$,&lt;br /&gt;
where $B$ is rectangular matrix of dimensions $n \times m$ with rows containing basis function evaluated in points $\vec{s}_j$.&lt;br /&gt;
\[ B =&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
b_1(\vec{s}_1) &amp;amp; \ldots &amp;amp; b_m(\vec{s}_1) \\&lt;br /&gt;
\vdots &amp;amp; \ddots &amp;amp; \vdots \\&lt;br /&gt;
b_1(\vec{s}_n) &amp;amp; \ldots &amp;amp; b_m(\vec{s}_n)&lt;br /&gt;
\end{bmatrix} =&lt;br /&gt;
 [b_i(\vec{s}_j)]_{j=1,i=1}^{n,m} = [\b{b}(\vec{s}_j)^\T]_{j=1}^n. \]&lt;br /&gt;
&lt;br /&gt;
We can choose to minimize any norm of the error vector $e$&lt;br /&gt;
and usually choose to minimize the $2$-norm or square norm \[ \|\b{e}\| = \|\b{e}\|_2 = \sqrt{\sum_{j=1}^n e_j^2}. \]&lt;br /&gt;
Commonly, we also choose to minimize a weighted norm&lt;br /&gt;
&amp;lt;ref&amp;gt;Note that our definition is a bit unusual, usually weights are not&lt;br /&gt;
 squared with the values. However, we do this to avoid computing square&lt;br /&gt;
 roots when doing MLS. If you are used to the usual definition,&lt;br /&gt;
consider the weight to be $\omega^2$.&amp;lt;/ref&amp;gt;&lt;br /&gt;
instead \[ \|\b{e}\|_{2,w} = \|\b{e}\|_w = \sqrt{\sum_{j=1}^n (w_j e_j)^2}. \]&lt;br /&gt;
The ''weights'' $w_i$ are assumed to be non negative and are assembled in a vector $\b{w}$ or a matrix $W = \operatorname{diag}(\b{w})$ and usually obtained from a weight function.&lt;br /&gt;
A ''weight function'' is a function $\omega\colon \R^k \to[0,\infty)$. We calculate $w_j$ as $w_i := \omega(\vec{p}-\vec{s}_j)$, so&lt;br /&gt;
good choices for $\omega$ are function which have higher values close to $0$ (making closer nodes more important), like the normal distribution.&lt;br /&gt;
If we choose $\omega \equiv 1$, we get the unweighted version.&lt;br /&gt;
&lt;br /&gt;
A choice of minimizing the square norm gave this method its name - Least Squares approximation. If we use the weighted version, we get the Weighted Least Squares or WLS.&lt;br /&gt;
In the most general case we wish to minimize&lt;br /&gt;
\[ \|\b{e}\|_{2,w}^2 = \b{e}^\T W^2 \b{e} = (B\b{\alpha} - \b{u})^\T W^2(B\b{\alpha} - \b{u}) =  \sum_j^n w_j^2 (\hat{u}(\vec{s}_j) - u_j)^2  \]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The problem of finding the coefficients $\b{\alpha}$ that minimize the error $\b{e}$ can be solved with at least three approaches:&lt;br /&gt;
* Normal equations (fastest, less accurate) - using Cholesky decomposition of $B$ (requires full rank and $m \leq n$)&lt;br /&gt;
* QR decomposition of $B$ (requires full rank and $m \leq n$, more precise)&lt;br /&gt;
* SVD decomposition of $B$ (more expensive, even more reliable, no rank demand)&lt;br /&gt;
&lt;br /&gt;
In our Meshless Machine MLS engine we use SVD with regularization described below.&lt;br /&gt;
&lt;br /&gt;
= Computing approximation coefficients =&lt;br /&gt;
&lt;br /&gt;
== [http://mathworld.wolfram.com/NormalEquation.html Normal equations] ==&lt;br /&gt;
We seek the minimum of&lt;br /&gt;
\[ \|\b{e}\|_2^2 = (B\b{\alpha} - \b{u})^\T(B\b{\alpha} - \b{u}) \]&lt;br /&gt;
By seeking the zero gradient in terms of coefficients $\alpha_i$&lt;br /&gt;
\[\frac{\partial}{\partial \alpha_i} (B\b{\alpha} - \b{u})^\T(B\b{\alpha} - \b{u})  = 0\]&lt;br /&gt;
resulting in&lt;br /&gt;
\[ B^\T B\b{\alpha} = B^\T \b{u}. \]&lt;br /&gt;
The coefficient matrix $B^\T B$ is symmetric and positive definite. However, solving above problem directly is&lt;br /&gt;
poorly behaved with respect to round-off errors since the condition number $\kappa(B^\T B)$ is the square&lt;br /&gt;
of $\kappa(B)$.&lt;br /&gt;
&lt;br /&gt;
In case of WLS the equations become&lt;br /&gt;
\[ (WB)^\T WB \b{\alpha} = WB^\T \b{u}. \]&lt;br /&gt;
&lt;br /&gt;
Complexity of Cholesky decomposition is $\frac{n^3}{3}$ and complexity of matrix multiplication $nm^2$. To preform the Cholesky decomposition the rank of $WB$ must be full.&lt;br /&gt;
&lt;br /&gt;
'''Pros:'''&lt;br /&gt;
* simple to implement&lt;br /&gt;
* low computational complexity&lt;br /&gt;
&lt;br /&gt;
'''Cons:'''&lt;br /&gt;
* numerically unstable&lt;br /&gt;
* full rank requirement&lt;br /&gt;
&lt;br /&gt;
== [https://en.wikipedia.org/wiki/QR_decomposition $QR$ Decomposition] ==&lt;br /&gt;
\[{\bf{B}} = {\bf{QR}} = \left[ {{{\bf{Q}}_1},{{\bf{Q}}_2}} \right]\left[ {\begin{array}{*{20}{c}}&lt;br /&gt;
{{{\bf{R}}_1}}\\&lt;br /&gt;
0&lt;br /&gt;
\end{array}} \right]\]&lt;br /&gt;
\[{\bf{B}} = {{\bf{Q}}_1}{{\bf{R}}_1}\]&lt;br /&gt;
$\bf{Q}$ is unitary matrix ($\bf{Q}^{-1}=\bf{Q}^T$). Useful property of a unitary matrices is that multiplying with them does not alter the (Euclidean) norm of a vector, i.e.,&lt;br /&gt;
\[\left\| {{\bf{Qx}}} \right\|{\bf{ = }}\left\| {\bf{x}} \right\|\]&lt;br /&gt;
And $\bf{R}$ is upper diagonal matrix&lt;br /&gt;
\[{\bf{R = (}}{{\bf{R}}_{\bf{1}}}{\bf{,}}0{\bf{)}}\]&lt;br /&gt;
therefore we can say&lt;br /&gt;
\[\begin{array}{l}&lt;br /&gt;
\left\| {{\bf{B\alpha }} - {\bf{u}}} \right\| = \left\| {{{\bf{Q}}^{\rm{T}}}\left( {{\bf{B\alpha }} - {\bf{u}}} \right)} \right\| = \left\| {{{\bf{Q}}^{\rm{T}}}{\bf{B\alpha }} - {{\bf{Q}}^{\rm{T}}}{\bf{u}}} \right\|\\&lt;br /&gt;
 = \left\| {{{\bf{Q}}^{\rm{T}}}\left( {{\bf{QR}}} \right){\bf{\alpha }} - {{\bf{Q}}^{\rm{T}}}{\bf{u}}} \right\| = \left\| {\left( {{{\bf{R}}_1},0} \right){\bf{\alpha }} - {{\left( {{{\bf{Q}}_1},{{\bf{Q}}_{\bf{2}}}} \right)}^{\rm{T}}}{\bf{u}}} \right\|\\&lt;br /&gt;
 = \left\| {{{\bf{R}}_{\bf{1}}}{\bf{\alpha }} - {{\bf{Q}}_{\bf{1}}}{\bf{u}}} \right\| + \left\| {{\bf{Q}}_2^{\rm{T}}{\bf{u}}} \right\|&lt;br /&gt;
\end{array}\]&lt;br /&gt;
Of the two terms on the right we have no control over the second, and we can render the first one&lt;br /&gt;
zero by solving&lt;br /&gt;
\[{{\bf{R}}_{\bf{1}}}{\bf{\alpha }} = {\bf{Q}}_{_{\bf{1}}}^{\rm{T}}{\bf{u}}\]&lt;br /&gt;
Which results in a minimum. We could also compute it with pseudo inverse&lt;br /&gt;
	\[\mathbf{\alpha }={{\mathbf{B}}^{-1}}\mathbf{u}\]&lt;br /&gt;
Where pseudo inverse is simply \[{{\mathbf{B}}^{-1}}=\mathbf{R}_{\text{1}}^{\text{-1}}{{\mathbf{Q}}^{\text{T}}}\] (once again, $R$ is upper diagonal matrix, and $Q$ is unitary matrix).&lt;br /&gt;
And for weighted case&lt;br /&gt;
	\[\mathbf{\alpha }={{\left( {{\mathbf{W}}^{0.5}}\mathbf{B} \right)}^{-1}}\left( {{\mathbf{W}}^{0.5}}\mathbf{u} \right)\]&lt;br /&gt;
&lt;br /&gt;
Complexity of $QR$ decomposition \[\frac{2}{3}m{{n}^{2}}+{{n}^{2}}+\frac{1}{3}n-2=O({{n}^{3}})\]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;Pros:&amp;lt;/strong&amp;gt; better stability in comparison with normal equations &amp;lt;strong&amp;gt; cons: &amp;lt;/strong&amp;gt;higher complexity&lt;br /&gt;
&lt;br /&gt;
== [https://en.wikipedia.org/wiki/Singular_value_decomposition SVD decomposition] ==&lt;br /&gt;
In linear algebra, the [https://en.wikipedia.org/wiki/Singular_value_decomposition singular value decomposition (SVD)]&lt;br /&gt;
is a factorization of a real or complex matrix. It has many useful&lt;br /&gt;
applications in signal processing and statistics.&lt;br /&gt;
&lt;br /&gt;
Formally, the singular value decomposition of an $m \times n$ real or complex&lt;br /&gt;
matrix $\bf{B}$ is a factorization of the form $\bf{B}= \bf{U\Sigma V^\T}$, where&lt;br /&gt;
$\bf{U}$ is an $m \times m$ real or complex unitary matrix, $\bf{\Sigma}$ is an $m \times n$&lt;br /&gt;
rectangular diagonal matrix with non-negative real numbers on the diagonal, and&lt;br /&gt;
$\bf{V}^\T$  is an $n \times n$ real or complex unitary matrix. The diagonal entries&lt;br /&gt;
$\Sigma_{ii}$ are known as the singular values of $\bf{B}$. The $m$ columns of&lt;br /&gt;
$\bf{U}$ and the $n$ columns of $\bf{V}$ are called the left-singular vectors and&lt;br /&gt;
right-singular vectors of $\bf{B}$, respectively.&lt;br /&gt;
&lt;br /&gt;
The singular value decomposition and the eigen decomposition are closely&lt;br /&gt;
related. Namely:&lt;br /&gt;
&lt;br /&gt;
* The left-singular vectors of $\bf{B}$ are eigen vectors of $\bf{BB}^\T$.&lt;br /&gt;
* The right-singular vectors of $\bf{B}$ are eigen vectors of $\bf{B}^\T{B}$.&lt;br /&gt;
* The non-zero singular values of $\bf{B}$ (found on the diagonal entries of $\bf{\Sigma}$) are the square roots of the non-zero eigenvalues of both $\bf{B}^\T\bf{B}$ and $\bf{B}^\T \bf{B}$.&lt;br /&gt;
&lt;br /&gt;
with SVD we can write $\bf{B}$ as \[\bf{B}=\bf{U\Sigma{{V}^{\T}}}\] where are $\bf{U}$ and $\bf{V}$ again unitary matrices and $\bf{\Sigma}$&lt;br /&gt;
stands for diagonal matrix of singular values.&lt;br /&gt;
&lt;br /&gt;
Again we can solve either the system or compute pseudo inverse as&lt;br /&gt;
&lt;br /&gt;
\[ \bf{B}^{-1} = \left( \bf{U\Sigma V}^\T\right)^{-1} = \bf{V}\bf{\Sigma^{-1}U}^\T \]&lt;br /&gt;
where $\bf{\Sigma}^{-1}$ is trivial, just replace every non-zero diagonal entry by&lt;br /&gt;
its reciprocal and transpose the resulting matrix. The stability gain is&lt;br /&gt;
exactly here, one can now set threshold below which the singular value is&lt;br /&gt;
considered as $0$, basically truncate all singular values below some value and&lt;br /&gt;
thus stabilize the inverse.&lt;br /&gt;
&lt;br /&gt;
SVD decomposition complexity \[ 2mn^2+2n^3 = O(n^3) \]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;Pros:&amp;lt;/strong&amp;gt; stable &amp;lt;strong&amp;gt; cons: &amp;lt;/strong&amp;gt;high complexity&lt;br /&gt;
&lt;br /&gt;
Method used in MLSM is SVD with regularization.&lt;br /&gt;
&lt;br /&gt;
= Weighted Least Squares =&lt;br /&gt;
Weighted least squares approximation is the simplest version of the procedure described above. Given support $\b{s}$, values $\b{u}$&lt;br /&gt;
and an anchor point $\vec{p}$, we calculate the coefficients $\b{\alpha}$ using one of the above methods.&lt;br /&gt;
Then, to approximate a function in the neighbourhood of $\vec p$ we use the formula&lt;br /&gt;
\[&lt;br /&gt;
\hat{u}(\vec x) = \b{b}(\vec x)^\T \b{\alpha} = \sum_{i=1}^m \alpha_i b_i(\vec x).&lt;br /&gt;
\]&lt;br /&gt;
&lt;br /&gt;
To approximate the derivative $\frac{\partial u}{\partial x_i}$, or any linear partial differential operator $\mathcal L$ on $u$, we&lt;br /&gt;
simply take the same linear combination of transformed basis functions $\mathcal L b_i$. We have considered coefficients $\alpha_i$ to be&lt;br /&gt;
constant and applied the linearity.&lt;br /&gt;
\[&lt;br /&gt;
 \widehat{\mathcal L u}(\vec x) = \sum_{i=1}^m \alpha_i (\mathcal L b_i)(\vec x).&lt;br /&gt;
\]&lt;br /&gt;
&lt;br /&gt;
= WLS at fixed point with fixed support and unknown function values :: Shape functions =&lt;br /&gt;
Suppose now we are given support $\b{s}$ and a point $\b{p}$ and want to construct the function approximation from values $\b{u}$.&lt;br /&gt;
We proceed as usual, solving the overdetermined system $WB \b{\alpha} = W\b{u}$ for coefficients $\b{\alpha}$ using the pseudoinverse&lt;br /&gt;
\[ \b{\alpha} = (WB)^+W\b{u}, \]&lt;br /&gt;
where $A^+$ denotes the Moore-Penrose pseudoinverse that can be calculated using SVD.&lt;br /&gt;
&lt;br /&gt;
Writing down the approximation function $\hat{u}$ we get&lt;br /&gt;
\[&lt;br /&gt;
\hat u (\vec{p}) = \b{b}(\vec{p})^\T \b{\alpha} = \b{b}(\vec{p})^\T (WB)^+W\b{u} = \b{\chi}(\vec{p}) \b{u}.&lt;br /&gt;
\]&lt;br /&gt;
&lt;br /&gt;
We have defined $\b{\chi}$ to be&lt;br /&gt;
\[ \b{\chi}(\vec{p}) = \b{b}(\vec{p})^\T (WB)^+W. \]&lt;br /&gt;
Vector $\b{\chi}$  is a row vector, also called a ''shape function''. The name comes from being able to take all the information&lt;br /&gt;
about shape of the domain and choice of approximation and store it in a single row vector, being able to approximate&lt;br /&gt;
a function value from given support values $\b{u}$ with a single dot product. For any values $\b{u}$, value $\b{\chi}(p) \b{u}$&lt;br /&gt;
gives us the approximation $\hat{u}(\vec{p})$ of $u$ in point $\vec{p}$.&lt;br /&gt;
Mathematically speaking, $\b{\chi}(\vec{p})$ is a functional, $\b{\chi}(\vec{p})\colon \R^n \to \R$, mapping $n$-tuples of known function values to&lt;br /&gt;
their approximations in point $\vec{p}$.&lt;br /&gt;
&lt;br /&gt;
The same approach works for any linear operator $\mathcal L$ applied to $u$, just replace every $b_i$ in definition of $\b{\chi}$ with $\mathcal Lb_i$.&lt;br /&gt;
For example, take a $1$-dimensional case for approximation of derivatives with weight equal to $1$ and $n=m=3$, with equally spaced support values at distances $h$.&lt;br /&gt;
We wish to approximate $u''$ in the middle support point, just by making a weighted sum of the values, something like the finite difference&lt;br /&gt;
\[ u'' \approx \frac{u_1 - 2u_2 + u_3}{h^2}. \]&lt;br /&gt;
This is exactly the same formula as we would have come to by computing $\b{\chi}$, except that our approach is a lot more general. But one should think about&lt;br /&gt;
$\b{\chi}$ as one would about the finite difference scheme, it is a rule, telling us how to compute the derivative.&lt;br /&gt;
\[ u''(s_2) \approx \underbrace{\begin{bmatrix} \frac{1}{h^2} &amp;amp; \frac{-2}{h^2} &amp;amp; \frac{1}{h^2} \end{bmatrix}}_{\b{\chi}} \begin{bmatrix}u_1 \\ u_2 \\ u_3 \end{bmatrix}  \]&lt;br /&gt;
&lt;br /&gt;
The fact that $\b{\chi}$ is independent of the function values $\b{u}$ but depend only on domain geometry means that&lt;br /&gt;
'''we can just compute the shape functions $\b{\chi}$ for points of interest and then approximate any linear operator&lt;br /&gt;
of any function, given its values, very fast, using only a single dot product.'''&lt;br /&gt;
&lt;br /&gt;
== Numerical calculation of the shape functions ==&lt;br /&gt;
The expression&lt;br /&gt;
\[ \b{\chi}(\vec{p}) = \b{b}(\vec{p})^\T (WB)^+W \]&lt;br /&gt;
can be evaluated directly, but this is not the most optimal approach. A numerically cheaper and more stable way is to translate the problem of inverting the matrix to solving a linear system of equations.&lt;br /&gt;
&lt;br /&gt;
'''Invertible $B$ case:'''&lt;br /&gt;
If $B$ is invertible, then $\b{\chi}(\vec{p}) = \b{b}(\vec{p})^\T B^{-1}$, transposing the equation then multiplying it from the left by $B$, &lt;br /&gt;
$\b{\chi}$ can be thought as a solution of a system $B^\T\chi(\vec{p})^\T = \b{b}(\vec{p})$, which can be solved using LU or Cholesky decomposition for example.&lt;br /&gt;
&lt;br /&gt;
'''General case:''' &lt;br /&gt;
For a system written as $Ax = b$, where $A$ is a $n\times m$ matrix, $x$ is a vector of length $m$ and $b$ a vector of length $m$, a generalized solution&lt;br /&gt;
$x$ is defined as such an $x$ that minimizes $\|A x - b\|_2^2$. If more $x$ attain the minimal value, $x$ with the minimal $\|x\|$ is chosen. Note that this generalizes the solution &lt;br /&gt;
a general sistem ($A$ is invertible) and over-determined system ($n &amp;gt; m$ and $A$ has full rank). Such an $x$ can be computed using the pseudoinverse $x = A^{+} b$. &lt;br /&gt;
&lt;br /&gt;
In our case, let us denote a part of the solution containing the pseudoinverse by $\tilde{\b{\chi}}$. &lt;br /&gt;
\[ \b{\chi}(\vec{p}) = \underbrace{\b{b}(\vec{p})^\T (WB)^+}_{\tilde{\b{\chi}}} W \]&lt;br /&gt;
We have an expression $\tilde{\b{\chi}} = \b{b}(\vec{p})^\T (WB)^+$ which after transposition takes the form $\tilde{\b{\chi}}^\T = ((WB)^\T)^+\b{b}(\vec{p})$, the same as $x = A^+b$ above.&lt;br /&gt;
Therefore, $\tilde{\b{\chi}}^\T$ is the solution of an (indeterminate) system $(WB)^\T \tilde{\b{\chi}}^\T = \b{b}(\vec{p})$. &lt;br /&gt;
After solving that, we can get the shape function $\b\chi(\vec{p}) = \tilde{\b{\chi}} W$ by multiplying by matrix $W$. &lt;br /&gt;
The system before can be solved using any decomposition of matrix $(WB)^\T = B^\T W$ necessary, mosr generally the SVD decompostion, but depending on our knowledge of the &lt;br /&gt;
problem, we can use Cholesky ($B^\T W$ is positive definite), $LDL^\T$ if it is symmetric, $LU$ for a general square matrix, $QR$ for full rank overdetermined system and SVD for a general system.&lt;br /&gt;
Is more shapes need to be calculated using the same matrix $B^\T W$ and only different right hand sides, it can be done efficiently by storing the decomposition of $B^\T W$.&lt;br /&gt;
&lt;br /&gt;
= MLS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;figure id=&amp;quot;fig:comparisonMLSandWLS&amp;quot;&amp;gt;&lt;br /&gt;
[[File:mlswls.svg|thumb|upright=2|&amp;lt;caption&amp;gt;Comparison of WLS and MLS approximation&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When using WLS the approximation gets worse as we move away from the central point $\vec{p}$.&lt;br /&gt;
This is partially due to not being in the center of the support any more and partially due to weight&lt;br /&gt;
being distributed in such a way to assign more importance to nodes closer to $\vec{p}$.&lt;br /&gt;
&lt;br /&gt;
We can battle this problem in two ways: when we wish to approximate in a new point that is sufficiently far&lt;br /&gt;
away from $\vec{p}$ we can compute new support, recompute the new coefficients $\b{\alpha}$ and approximate again.&lt;br /&gt;
This is very costly and we would like to avoid that. A partial fix is to keep support the same, but only&lt;br /&gt;
recompute the weight vector $\b{w}$, that will now assign weight values to nodes close to the new point.&lt;br /&gt;
We still need to recompute the coefficients $\b{\alpha}$, however we avoid the cost of setting up new support&lt;br /&gt;
and function values and recomputing $B$. This approach is called Moving Least Squares due to recomputing&lt;br /&gt;
the weighted least squares problem whenever we move the point of approximation.&lt;br /&gt;
&lt;br /&gt;
Note that if out weight is constant or if $n = m$, when approximation reduces to interpolation, the weights do not play&lt;br /&gt;
any role and this method is redundant. In fact, its benefits arise when supports are rather large.&lt;br /&gt;
&lt;br /&gt;
See &amp;lt;xr id=&amp;quot;fig:comparisonMLSandWLS&amp;quot;/&amp;gt; for comparison between MLS and WLS approximations. MLS approximation remains close to&lt;br /&gt;
actual function while still inside the support domain, while WLS approximation becomes bad when&lt;br /&gt;
we come out of the reach of the weight function.&lt;br /&gt;
&lt;br /&gt;
{{reflist}}&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Weighted_Least_Squares_(WLS)&amp;diff=1213</id>
		<title>Weighted Least Squares (WLS)</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Weighted_Least_Squares_(WLS)&amp;diff=1213"/>
				<updated>2017-07-06T12:23:12Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Numerical calculation of the shape functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;One of the most important building blocks of the meshless methods is the Moving Least Squares (MLS) approximation , which is implemented in the [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/technical_docs/html/classEngineMLS.html EngineMLS class]. Check [https://gitlab.com/e62Lab/e62numcodes/blob/master/test/mls_test.cpp EngineMLS unit tests] for examples.&lt;br /&gt;
&lt;br /&gt;
= Notation Cheat sheet =&lt;br /&gt;
\begin{align*}&lt;br /&gt;
  m \in \N                  &amp;amp; \dots \text{number of basis functions} \\&lt;br /&gt;
  n \geq m \in \N           &amp;amp; \dots \text{number of points in support domain} \\&lt;br /&gt;
  k \in \mathbb{N}          &amp;amp; \dots \text{dimensionality of vector space} \\&lt;br /&gt;
  \vec s_j \in \R^k         &amp;amp; \dots \text{point in support domain } \quad j=1,\dots,n \\&lt;br /&gt;
  u_j \in \R                &amp;amp; \dots \text{value of function to approximate in }\vec{s}_j \quad j=1,\dots,n \\&lt;br /&gt;
  \vec p \in \R^k           &amp;amp; \dots \text{center point of approximation} \\&lt;br /&gt;
  b_i\colon \R^k \to \R     &amp;amp; \dots \text{basis functions } \quad i=1,\dots,m \\&lt;br /&gt;
  B_{j, i} \in \R           &amp;amp; \dots \text{value of basis functions in support points } b_i(s_j-p) \quad j=1,\dots,n, \quad i=1,\dots,m\\&lt;br /&gt;
  \omega \colon \R^k \to \R &amp;amp; \dots \text{weight function} \\&lt;br /&gt;
  w_j \in \R                &amp;amp; \dots \text{weights } \omega(\vec{s}_j-\vec{p})  \quad j=1,\dots,n \\&lt;br /&gt;
  \alpha_i \in \R           &amp;amp; \dots \text{expansion coefficients around point } \vec{p} \quad i=1,\dots,m \\&lt;br /&gt;
  \hat u\colon \R^k \to \R  &amp;amp; \dots \text{approximation function (best fit)} \\&lt;br /&gt;
  \chi_j \in \R          &amp;amp; \dots \text{shape coefficient for point }\vec{p} \quad j=1,\dots,n \\&lt;br /&gt;
\end{align*}&lt;br /&gt;
&lt;br /&gt;
We will also use \(\b{s}, \b{u}, \b{b}, \b{\alpha}, \b{\chi} \) to annotate a column of corresponding values,&lt;br /&gt;
$W$ as a $n\times n$ diagonal matrix filled with $w_j$ on the diagonal and $B$ as a $n\times m$ matrix filled with $B_{j, i}$.&lt;br /&gt;
&lt;br /&gt;
= Definition of local approximation =&lt;br /&gt;
&amp;lt;figure id=&amp;quot;fig:1DWLS&amp;quot;&amp;gt;&lt;br /&gt;
[[File:image_1avhdsfej1b9cao01029m1e13o69.png|600px|thumb|upright=2|alt=1D MLS example|&amp;lt;caption&amp;gt;Example of 1D WLS approximation &amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
Our wish is to approximate an unknown function $u\colon \R^k \to \R$ while knowing $n$ values $u(\vec{s}_j) := u_j$.&lt;br /&gt;
The vector of known values will be denoted by $\b{u}$ and the vector of coordinates where those values were achieved by $\b{s}$.&lt;br /&gt;
Note that $\b{s}$ is not a vector in the usual sense since its components $\vec{s}_j$ are elements of $\R^k$, but we will call it vector anyway.&lt;br /&gt;
The values of $\b{s}$ are called ''nodes'' or ''support nodes'' or ''support''. The known values $\b{u}$ are also called ''support values''.&lt;br /&gt;
&lt;br /&gt;
In general, an approximation function around point $\vec{p}\in\R^k$ can be&lt;br /&gt;
written as \[\hat{u} (\vec{x}) = \sum_{i=1}^m \alpha_i b_i(\vec{x}) = \b{b}(\vec{x})^\T \b{\alpha} \]&lt;br /&gt;
where $\b{b} = (b_i)_{i=1}^m$ is a set of ''basis functions'', $b_i\colon \R^k \to\R$, and $\b{\alpha} = (\alpha_i)_{i=1}^m$ are the unknown coefficients.&lt;br /&gt;
&lt;br /&gt;
In MLS the goal is to minimize the error of approximation in given values, $\b{e} = \hat u(\b{s}) - \b{u}$&lt;br /&gt;
between the approximation function and target function in the known points $\b{x}$. The error can also be written as $B\b{\alpha} - \b{u}$,&lt;br /&gt;
where $B$ is rectangular matrix of dimensions $n \times m$ with rows containing basis function evaluated in points $\vec{s}_j$.&lt;br /&gt;
\[ B =&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
b_1(\vec{s}_1) &amp;amp; \ldots &amp;amp; b_m(\vec{s}_1) \\&lt;br /&gt;
\vdots &amp;amp; \ddots &amp;amp; \vdots \\&lt;br /&gt;
b_1(\vec{s}_n) &amp;amp; \ldots &amp;amp; b_m(\vec{s}_n)&lt;br /&gt;
\end{bmatrix} =&lt;br /&gt;
 [b_i(\vec{s}_j)]_{j=1,i=1}^{n,m} = [\b{b}(\vec{s}_j)^\T]_{j=1}^n. \]&lt;br /&gt;
&lt;br /&gt;
We can choose to minimize any norm of the error vector $e$&lt;br /&gt;
and usually choose to minimize the $2$-norm or square norm \[ \|\b{e}\| = \|\b{e}\|_2 = \sqrt{\sum_{j=1}^n e_j^2}. \]&lt;br /&gt;
Commonly, we also choose to minimize a weighted norm&lt;br /&gt;
&amp;lt;ref&amp;gt;Note that our definition is a bit unusual, usually weights are not&lt;br /&gt;
 squared with the values. However, we do this to avoid computing square&lt;br /&gt;
 roots when doing MLS. If you are used to the usual definition,&lt;br /&gt;
consider the weight to be $\omega^2$.&amp;lt;/ref&amp;gt;&lt;br /&gt;
instead \[ \|\b{e}\|_{2,w} = \|\b{e}\|_w = \sqrt{\sum_{j=1}^n (w_j e_j)^2}. \]&lt;br /&gt;
The ''weights'' $w_i$ are assumed to be non negative and are assembled in a vector $\b{w}$ or a matrix $W = \operatorname{diag}(\b{w})$ and usually obtained from a weight function.&lt;br /&gt;
A ''weight function'' is a function $\omega\colon \R^k \to[0,\infty)$. We calculate $w_j$ as $w_i := \omega(\vec{p}-\vec{s}_j)$, so&lt;br /&gt;
good choices for $\omega$ are function which have higher values close to $0$ (making closer nodes more important), like the normal distribution.&lt;br /&gt;
If we choose $\omega \equiv 1$, we get the unweighted version.&lt;br /&gt;
&lt;br /&gt;
A choice of minimizing the square norm gave this method its name - Least Squares approximation. If we use the weighted version, we get the Weighted Least Squares or WLS.&lt;br /&gt;
In the most general case we wish to minimize&lt;br /&gt;
\[ \|\b{e}\|_{2,w}^2 = \b{e}^\T W^2 \b{e} = (B\b{\alpha} - \b{u})^\T W^2(B\b{\alpha} - \b{u}) =  \sum_j^n w_j^2 (\hat{u}(\vec{s}_j) - u_j)^2  \]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The problem of finding the coefficients $\b{\alpha}$ that minimize the error $\b{e}$ can be solved with at least three approaches:&lt;br /&gt;
* Normal equations (fastest, less accurate) - using Cholesky decomposition of $B$ (requires full rank and $m \leq n$)&lt;br /&gt;
* QR decomposition of $B$ (requires full rank and $m \leq n$, more precise)&lt;br /&gt;
* SVD decomposition of $B$ (more expensive, even more reliable, no rank demand)&lt;br /&gt;
&lt;br /&gt;
In our Meshless Machine MLS engine we use SVD with regularization described below.&lt;br /&gt;
&lt;br /&gt;
= Computing approximation coefficients =&lt;br /&gt;
&lt;br /&gt;
== [http://mathworld.wolfram.com/NormalEquation.html Normal equations] ==&lt;br /&gt;
We seek the minimum of&lt;br /&gt;
\[ \|\b{e}\|_2^2 = (B\b{\alpha} - \b{u})^\T(B\b{\alpha} - \b{u}) \]&lt;br /&gt;
By seeking the zero gradient in terms of coefficients $\alpha_i$&lt;br /&gt;
\[\frac{\partial}{\partial \alpha_i} (B\b{\alpha} - \b{u})^\T(B\b{\alpha} - \b{u})  = 0\]&lt;br /&gt;
resulting in&lt;br /&gt;
\[ B^\T B\b{\alpha} = B^\T \b{u}. \]&lt;br /&gt;
The coefficient matrix $B^\T B$ is symmetric and positive definite. However, solving above problem directly is&lt;br /&gt;
poorly behaved with respect to round-off errors since the condition number $\kappa(B^\T B)$ is the square&lt;br /&gt;
of $\kappa(B)$.&lt;br /&gt;
&lt;br /&gt;
In case of WLS the equations become&lt;br /&gt;
\[ (WB)^\T WB \b{\alpha} = WB^\T \b{u}. \]&lt;br /&gt;
&lt;br /&gt;
Complexity of Cholesky decomposition is $\frac{n^3}{3}$ and complexity of matrix multiplication $nm^2$. To preform the Cholesky decomposition the rank of $WB$ must be full.&lt;br /&gt;
&lt;br /&gt;
'''Pros:'''&lt;br /&gt;
* simple to implement&lt;br /&gt;
* low computational complexity&lt;br /&gt;
&lt;br /&gt;
'''Cons:'''&lt;br /&gt;
* numerically unstable&lt;br /&gt;
* full rank requirement&lt;br /&gt;
&lt;br /&gt;
== [https://en.wikipedia.org/wiki/QR_decomposition $QR$ Decomposition] ==&lt;br /&gt;
\[{\bf{B}} = {\bf{QR}} = \left[ {{{\bf{Q}}_1},{{\bf{Q}}_2}} \right]\left[ {\begin{array}{*{20}{c}}&lt;br /&gt;
{{{\bf{R}}_1}}\\&lt;br /&gt;
0&lt;br /&gt;
\end{array}} \right]\]&lt;br /&gt;
\[{\bf{B}} = {{\bf{Q}}_1}{{\bf{R}}_1}\]&lt;br /&gt;
$\bf{Q}$ is unitary matrix ($\bf{Q}^{-1}=\bf{Q}^T$). Useful property of a unitary matrices is that multiplying with them does not alter the (Euclidean) norm of a vector, i.e.,&lt;br /&gt;
\[\left\| {{\bf{Qx}}} \right\|{\bf{ = }}\left\| {\bf{x}} \right\|\]&lt;br /&gt;
And $\bf{R}$ is upper diagonal matrix&lt;br /&gt;
\[{\bf{R = (}}{{\bf{R}}_{\bf{1}}}{\bf{,}}0{\bf{)}}\]&lt;br /&gt;
therefore we can say&lt;br /&gt;
\[\begin{array}{l}&lt;br /&gt;
\left\| {{\bf{B\alpha }} - {\bf{u}}} \right\| = \left\| {{{\bf{Q}}^{\rm{T}}}\left( {{\bf{B\alpha }} - {\bf{u}}} \right)} \right\| = \left\| {{{\bf{Q}}^{\rm{T}}}{\bf{B\alpha }} - {{\bf{Q}}^{\rm{T}}}{\bf{u}}} \right\|\\&lt;br /&gt;
 = \left\| {{{\bf{Q}}^{\rm{T}}}\left( {{\bf{QR}}} \right){\bf{\alpha }} - {{\bf{Q}}^{\rm{T}}}{\bf{u}}} \right\| = \left\| {\left( {{{\bf{R}}_1},0} \right){\bf{\alpha }} - {{\left( {{{\bf{Q}}_1},{{\bf{Q}}_{\bf{2}}}} \right)}^{\rm{T}}}{\bf{u}}} \right\|\\&lt;br /&gt;
 = \left\| {{{\bf{R}}_{\bf{1}}}{\bf{\alpha }} - {{\bf{Q}}_{\bf{1}}}{\bf{u}}} \right\| + \left\| {{\bf{Q}}_2^{\rm{T}}{\bf{u}}} \right\|&lt;br /&gt;
\end{array}\]&lt;br /&gt;
Of the two terms on the right we have no control over the second, and we can render the first one&lt;br /&gt;
zero by solving&lt;br /&gt;
\[{{\bf{R}}_{\bf{1}}}{\bf{\alpha }} = {\bf{Q}}_{_{\bf{1}}}^{\rm{T}}{\bf{u}}\]&lt;br /&gt;
Which results in a minimum. We could also compute it with pseudo inverse&lt;br /&gt;
	\[\mathbf{\alpha }={{\mathbf{B}}^{-1}}\mathbf{u}\]&lt;br /&gt;
Where pseudo inverse is simply \[{{\mathbf{B}}^{-1}}=\mathbf{R}_{\text{1}}^{\text{-1}}{{\mathbf{Q}}^{\text{T}}}\] (once again, $R$ is upper diagonal matrix, and $Q$ is unitary matrix).&lt;br /&gt;
And for weighted case&lt;br /&gt;
	\[\mathbf{\alpha }={{\left( {{\mathbf{W}}^{0.5}}\mathbf{B} \right)}^{-1}}\left( {{\mathbf{W}}^{0.5}}\mathbf{u} \right)\]&lt;br /&gt;
&lt;br /&gt;
Complexity of $QR$ decomposition \[\frac{2}{3}m{{n}^{2}}+{{n}^{2}}+\frac{1}{3}n-2=O({{n}^{3}})\]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;Pros:&amp;lt;/strong&amp;gt; better stability in comparison with normal equations &amp;lt;strong&amp;gt; cons: &amp;lt;/strong&amp;gt;higher complexity&lt;br /&gt;
&lt;br /&gt;
== [https://en.wikipedia.org/wiki/Singular_value_decomposition SVD decomposition] ==&lt;br /&gt;
In linear algebra, the [https://en.wikipedia.org/wiki/Singular_value_decomposition singular value decomposition (SVD)]&lt;br /&gt;
is a factorization of a real or complex matrix. It has many useful&lt;br /&gt;
applications in signal processing and statistics.&lt;br /&gt;
&lt;br /&gt;
Formally, the singular value decomposition of an $m \times n$ real or complex&lt;br /&gt;
matrix $\bf{B}$ is a factorization of the form $\bf{B}= \bf{U\Sigma V^\T}$, where&lt;br /&gt;
$\bf{U}$ is an $m \times m$ real or complex unitary matrix, $\bf{\Sigma}$ is an $m \times n$&lt;br /&gt;
rectangular diagonal matrix with non-negative real numbers on the diagonal, and&lt;br /&gt;
$\bf{V}^\T$  is an $n \times n$ real or complex unitary matrix. The diagonal entries&lt;br /&gt;
$\Sigma_{ii}$ are known as the singular values of $\bf{B}$. The $m$ columns of&lt;br /&gt;
$\bf{U}$ and the $n$ columns of $\bf{V}$ are called the left-singular vectors and&lt;br /&gt;
right-singular vectors of $\bf{B}$, respectively.&lt;br /&gt;
&lt;br /&gt;
The singular value decomposition and the eigen decomposition are closely&lt;br /&gt;
related. Namely:&lt;br /&gt;
&lt;br /&gt;
* The left-singular vectors of $\bf{B}$ are eigen vectors of $\bf{BB}^\T$.&lt;br /&gt;
* The right-singular vectors of $\bf{B}$ are eigen vectors of $\bf{B}^\T{B}$.&lt;br /&gt;
* The non-zero singular values of $\bf{B}$ (found on the diagonal entries of $\bf{\Sigma}$) are the square roots of the non-zero eigenvalues of both $\bf{B}^\T\bf{B}$ and $\bf{B}^\T \bf{B}$.&lt;br /&gt;
&lt;br /&gt;
with SVD we can write $\bf{B}$ as \[\bf{B}=\bf{U\Sigma{{V}^{\T}}}\] where are $\bf{U}$ and $\bf{V}$ again unitary matrices and $\bf{\Sigma}$&lt;br /&gt;
stands for diagonal matrix of singular values.&lt;br /&gt;
&lt;br /&gt;
Again we can solve either the system or compute pseudo inverse as&lt;br /&gt;
&lt;br /&gt;
\[ \bf{B}^{-1} = \left( \bf{U\Sigma V}^\T\right)^{-1} = \bf{V}\bf{\Sigma^{-1}U}^\T \]&lt;br /&gt;
where $\bf{\Sigma}^{-1}$ is trivial, just replace every non-zero diagonal entry by&lt;br /&gt;
its reciprocal and transpose the resulting matrix. The stability gain is&lt;br /&gt;
exactly here, one can now set threshold below which the singular value is&lt;br /&gt;
considered as $0$, basically truncate all singular values below some value and&lt;br /&gt;
thus stabilize the inverse.&lt;br /&gt;
&lt;br /&gt;
SVD decomposition complexity \[ 2mn^2+2n^3 = O(n^3) \]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;Pros:&amp;lt;/strong&amp;gt; stable &amp;lt;strong&amp;gt; cons: &amp;lt;/strong&amp;gt;high complexity&lt;br /&gt;
&lt;br /&gt;
Method used in MLSM is SVD with regularization.&lt;br /&gt;
&lt;br /&gt;
= Weighted Least Squares =&lt;br /&gt;
Weighted least squares approximation is the simplest version of the procedure described above. Given support $\b{s}$, values $\b{u}$&lt;br /&gt;
and an anchor point $\vec{p}$, we calculate the coefficients $\b{\alpha}$ using one of the above methods.&lt;br /&gt;
Then, to approximate a function in the neighbourhood of $\vec p$ we use the formula&lt;br /&gt;
\[&lt;br /&gt;
\hat{u}(\vec x) = \b{b}(\vec x)^\T \b{\alpha} = \sum_{i=1}^m \alpha_i b_i(\vec x).&lt;br /&gt;
\]&lt;br /&gt;
&lt;br /&gt;
To approximate the derivative $\frac{\partial u}{\partial x_i}$, or any linear partial differential operator $\mathcal L$ on $u$, we&lt;br /&gt;
simply take the same linear combination of transformed basis functions $\mathcal L b_i$. We have considered coefficients $\alpha_i$ to be&lt;br /&gt;
constant and applied the linearity.&lt;br /&gt;
\[&lt;br /&gt;
 \widehat{\mathcal L u}(\vec x) = \sum_{i=1}^m \alpha_i (\mathcal L b_i)(\vec x).&lt;br /&gt;
\]&lt;br /&gt;
&lt;br /&gt;
= WLS at fixed point with fixed support and unknown function values :: Shape functions =&lt;br /&gt;
Suppose now we are given support $\b{s}$ and a point $\b{p}$ and want to construct the function approximation from values $\b{u}$.&lt;br /&gt;
We proceed as usual, solving the overdetermined system $WB \b{\alpha} = W\b{u}$ for coefficients $\b{\alpha}$ using the pseudoinverse&lt;br /&gt;
\[ \b{\alpha} = (WB)^+W\b{u}, \]&lt;br /&gt;
where $A^+$ denotes the Moore-Penrose pseudoinverse that can be calculated using SVD.&lt;br /&gt;
&lt;br /&gt;
Writing down the approximation function $\hat{u}$ we get&lt;br /&gt;
\[&lt;br /&gt;
\hat u (\vec{p}) = \b{b}(\vec{p})^\T \b{\alpha} = \b{b}(\vec{p})^\T (WB)^+W\b{u} = \b{\chi}(\vec{p}) \b{u}.&lt;br /&gt;
\]&lt;br /&gt;
&lt;br /&gt;
We have defined $\b{\chi}$ to be&lt;br /&gt;
\[ \b{\chi}(\vec{p}) = \b{b}(\vec{p})^\T (WB)^+W. \]&lt;br /&gt;
Vector $\b{\chi}$  is a row vector, also called a ''shape function''. The name comes from being able to take all the information&lt;br /&gt;
about shape of the domain and choice of approximation and store it in a single row vector, being able to approximate&lt;br /&gt;
a function value from given support values $\b{u}$ with a single dot product. For any values $\b{u}$, value $\b{\chi}(p) \b{u}$&lt;br /&gt;
gives us the approximation $\hat{u}(\vec{p})$ of $u$ in point $\vec{p}$.&lt;br /&gt;
Mathematically speaking, $\b{\chi}(\vec{p})$ is a functional, $\b{\chi}(\vec{p})\colon \R^n \to \R$, mapping $n$-tuples of known function values to&lt;br /&gt;
their approximations in point $\vec{p}$.&lt;br /&gt;
&lt;br /&gt;
The same approach works for any linear operator $\mathcal L$ applied to $u$, just replace every $b_i$ in definition of $\b{\chi}$ with $\mathcal Lb_i$.&lt;br /&gt;
For example, take a $1$-dimensional case for approximation of derivatives with weight equal to $1$ and $n=m=3$, with equally spaced support values at distances $h$.&lt;br /&gt;
We wish to approximate $u''$ in the middle support point, just by making a weighted sum of the values, something like the finite difference&lt;br /&gt;
\[ u'' \approx \frac{u_1 - 2u_2 + u_3}{h^2}. \]&lt;br /&gt;
This is exactly the same formula as we would have come to by computing $\b{\chi}$, except that our approach is a lot more general. But one should think about&lt;br /&gt;
$\b{\chi}$ as one would about the finite difference scheme, it is a rule, telling us how to compute the derivative.&lt;br /&gt;
\[ u''(s_2) \approx \underbrace{\begin{bmatrix} \frac{1}{h^2} &amp;amp; \frac{-2}{h^2} &amp;amp; \frac{1}{h^2} \end{bmatrix}}_{\b{\chi}} \begin{bmatrix}u_1 \\ u_2 \\ u_3 \end{bmatrix}  \]&lt;br /&gt;
&lt;br /&gt;
The fact that $\b{\chi}$ is independent of the function values $\b{u}$ but depend only on domain geometry means that&lt;br /&gt;
'''we can just compute the shape functions $\b{\chi}$ for points of interest and then approximate any linear operator&lt;br /&gt;
of any function, given its values, very fast, using only a single dot product.'''&lt;br /&gt;
&lt;br /&gt;
== Numerical calculation of the shape functions ==&lt;br /&gt;
The expression&lt;br /&gt;
\[ \b{\chi}(\vec{p}) = \b{b}(\vec{p})^\T (WB)^+W \]&lt;br /&gt;
can be evaluated directly, but this is not the most optimal approach. A numerically cheaper and more stable way is to translate the problem of inverting the matrix to solving a linear system of equations.&lt;br /&gt;
&lt;br /&gt;
'''Invertible $B$ case:'''&lt;br /&gt;
If $B$ is invertible, then $\b{\chi}(\vec{p}) = \b{b}(\vec{p})^\T B^{-1}$, transposing the equation then multiplying it from the left by $B$, &lt;br /&gt;
$\b{\chi}$ can be thought as a solution of a system $B^\T\chi(\vec{p})^\T = \b{b}(\vec{p})$, which can be solved using LU or Cholesky decomposition for example.&lt;br /&gt;
&lt;br /&gt;
'''General case:''' &lt;br /&gt;
For a system written as $Ax = b$, where a is a $n\times m$ matrix, $x$ is a vector of length $m$ and $b$ a vector of length $m$, a generalized solution&lt;br /&gt;
$x$ is defined as such an $x$ that minimizes $\|A x - b\|_2^2$. If more $x$ attain the minimal value, $x$ with the minimal $\|x\|$ is chosen. Note that this generalizes the solution &lt;br /&gt;
a general sistem ($A$ is invertible) and over-determined system ($n &amp;gt; m$ and $A$ has full rank). Such an $x$ can be computed using the pseudoinverse $x = A^{+} b$. &lt;br /&gt;
&lt;br /&gt;
In our case, let us denote a part of the solution containing the pseudoinverse by $\tilde{\b{\chi}}$. &lt;br /&gt;
\[ \b{\chi}(\vec{p}) = \underbrace{\b{b}(\vec{p})^\T (WB)^+}_{\tilde{\b{\chi}}} W \]&lt;br /&gt;
We have an expression $\tilde{\b{\chi}} = \b{b}(\vec{p})^\T (WB)^+$ which after transposition takes the form $\tilde{\b{\chi}}^\T = ((WB)^\T)^+\b{b}(\vec{p})$, the same as $x = A^+b$ above.&lt;br /&gt;
Therefore, $\tilde{\b{\chi}}^\T$ is the solution of an (indeterminate) system $(WB)^\T \tilde{\b{\chi}}^\T = \b{b}(\vec{p})$. &lt;br /&gt;
After solving that, we can get the shape function $\b\chi(\vec{p}) = \tilde{\b{\chi}} W$ by multiplying by matrix $W$. &lt;br /&gt;
The system before can be solved using any decomposition of matrix $(WB)^\T = B^\T W$ necessary, mosr generally the SVD decompostion, but depending on our knowledge of the &lt;br /&gt;
problem, we can use Cholesky ($B^\T W$ is positive definite), $LDL^\T$ if it is symmetric, $LU$ for a general square matrix, $QR$ for full rank overdetermined system and SVD for a general system.&lt;br /&gt;
Is more shapes need to be calculated using the same matrix $B^\T W$ and only different right hand sides, it can be done efficiently by storing the decomposition of $B^\T W$.&lt;br /&gt;
&lt;br /&gt;
= MLS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;figure id=&amp;quot;fig:comparisonMLSandWLS&amp;quot;&amp;gt;&lt;br /&gt;
[[File:mlswls.svg|thumb|upright=2|&amp;lt;caption&amp;gt;Comparison of WLS and MLS approximation&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When using WLS the approximation gets worse as we move away from the central point $\vec{p}$.&lt;br /&gt;
This is partially due to not being in the center of the support any more and partially due to weight&lt;br /&gt;
being distributed in such a way to assign more importance to nodes closer to $\vec{p}$.&lt;br /&gt;
&lt;br /&gt;
We can battle this problem in two ways: when we wish to approximate in a new point that is sufficiently far&lt;br /&gt;
away from $\vec{p}$ we can compute new support, recompute the new coefficients $\b{\alpha}$ and approximate again.&lt;br /&gt;
This is very costly and we would like to avoid that. A partial fix is to keep support the same, but only&lt;br /&gt;
recompute the weight vector $\b{w}$, that will now assign weight values to nodes close to the new point.&lt;br /&gt;
We still need to recompute the coefficients $\b{\alpha}$, however we avoid the cost of setting up new support&lt;br /&gt;
and function values and recomputing $B$. This approach is called Moving Least Squares due to recomputing&lt;br /&gt;
the weighted least squares problem whenever we move the point of approximation.&lt;br /&gt;
&lt;br /&gt;
Note that if out weight is constant or if $n = m$, when approximation reduces to interpolation, the weights do not play&lt;br /&gt;
any role and this method is redundant. In fact, its benefits arise when supports are rather large.&lt;br /&gt;
&lt;br /&gt;
See &amp;lt;xr id=&amp;quot;fig:comparisonMLSandWLS&amp;quot;/&amp;gt; for comparison between MLS and WLS approximations. MLS approximation remains close to&lt;br /&gt;
actual function while still inside the support domain, while WLS approximation becomes bad when&lt;br /&gt;
we come out of the reach of the weight function.&lt;br /&gt;
&lt;br /&gt;
{{reflist}}&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=How_to_build&amp;diff=1197</id>
		<title>How to build</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=How_to_build&amp;diff=1197"/>
				<updated>2017-06-12T09:16:40Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Building on Mac OSX */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Installation=&lt;br /&gt;
To make this work from plain Ubuntu installation, run&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install cmake doxygen graphviz libboost-dev libsfml-dev libhdf5-serial-dev&lt;br /&gt;
git clone https://gitlab.com/e62Lab/e62numcodes.git&lt;br /&gt;
cd e62numcodes&lt;br /&gt;
./run_tests.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
which installs dependancies, clones the repository, goes into the root folder of the repository and runs tests. This will check the configuration, notify you of potentially missing dependencies, build and run all tests, check code style and docs. If this works, you are ready to go! Otherwise install any missing packages and if it still fails, raise an issue!&lt;br /&gt;
&lt;br /&gt;
=Building=&lt;br /&gt;
&lt;br /&gt;
List of dependencies:&lt;br /&gt;
&lt;br /&gt;
* Build tools, like &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;gt;= 2.8.12&amp;lt;/syntaxhighlight&amp;gt;, &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; g++ &amp;gt;= 4.8&amp;lt;/syntaxhighlight&amp;gt;, &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;make&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* [http://www.boost.org/ Boost]&lt;br /&gt;
* &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; doxygen &amp;gt;=  1.8.8 &amp;lt;/syntaxhighlight&amp;gt; and Graphviz&lt;br /&gt;
* for drawing [http://www.sfml-dev.org/ SMFL library version 2]&lt;br /&gt;
* for IO [https://www.hdfgroup.org/ HDF5 library]&lt;br /&gt;
&lt;br /&gt;
Out of source builds are preferred. Run&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir -p build&lt;br /&gt;
cd build&lt;br /&gt;
cmake ..&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Note that you only have to run &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;lt;/syntaxhighlight&amp;gt; once, after that only &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&amp;lt;/syntaxhighlight&amp;gt; is sufficient.&lt;br /&gt;
&lt;br /&gt;
Binaries are placed into &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; bin &amp;lt;/syntaxhighlight&amp;gt; folder. Test can be run all at once via &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&lt;br /&gt;
run_all_tests &amp;lt;/syntaxhighlight&amp;gt; or individually via eg. &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;make basisfunc_run_tests &amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Linear Algebra==&lt;br /&gt;
We use [http://eigen.tuxfamily.org/ Eigen] as our matrix library. See&lt;br /&gt;
[http://eigen.tuxfamily.org/dox-devel/group__QuickRefPage.html here] for use&lt;br /&gt;
reference and documentation. For a quick transition from Matlab see&lt;br /&gt;
[http://eigen.tuxfamily.org/dox/AsciiQuickReference.txt here].&lt;br /&gt;
&lt;br /&gt;
==Drawing==&lt;br /&gt;
Some tests include drawing. We are using [http://www.sfml-dev.org/ SMFL library], which can be installed on most linux systems easly&lt;br /&gt;
as &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo apt-get install libsfml-dev &amp;lt;/syntaxhighlight&amp;gt; or &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo pacman -S sfml &amp;lt;/syntaxhighlight&amp;gt;.  After the&lt;br /&gt;
installation uncomment a test case in &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; domain_draw_test.cpp &amp;lt;/syntaxhighlight&amp;gt; and run &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&lt;br /&gt;
test_domain_draw &amp;lt;/syntaxhighlight&amp;gt; to see the visual effect.&lt;br /&gt;
&lt;br /&gt;
Binaries using SFML require additional linker flags &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; -lsfml-graphics&lt;br /&gt;
-lsfml-window -lsfml-system &amp;lt;/syntaxhighlight&amp;gt;, but the makefile should take care of that for you.&lt;br /&gt;
&lt;br /&gt;
==HDF5==&lt;br /&gt;
&lt;br /&gt;
In order to use IO you need [https://www.hdfgroup.org/ hdf5 library].&lt;br /&gt;
You can install it easily using the command &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo apt-get install libhdf5-&lt;br /&gt;
dev &amp;lt;/syntaxhighlight&amp;gt; or &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo pacman -S hdf5-cpp-fortran &amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Ubuntu places hdf5 libs in a werid folder &amp;lt;code&amp;gt;/usr/lib/x86_64-linux-gnu/hdf5/serial/&amp;lt;/code&amp;gt;. &lt;br /&gt;
If you get error similar to &amp;lt;code&amp;gt;-lhdf5 not found&amp;lt;/code&amp;gt; and you have hdf5 installed, you might have to link the libraries into&lt;br /&gt;
a discoverable place, like &amp;lt;code&amp;gt;/usr/lib/&amp;lt;/code&amp;gt; or add the above directory to the linker path.&lt;br /&gt;
If using cmake, you can add the following line to your CMakeLists.txt&lt;br /&gt;
  link_directories(/usr/lib/x86_64-linux-gnu/hdf5/serial/)&lt;br /&gt;
&lt;br /&gt;
== Using Intel Math Kernel Library (MKL) ==&lt;br /&gt;
Eigen has great support for MKL all you have to do is define a EIGEN_USE_MKL_ALL macro before any includes.&lt;br /&gt;
You can see further instructions [https://eigen.tuxfamily.org/dox/TopicUsingIntelMKL.html on their website].&lt;br /&gt;
&lt;br /&gt;
Besides setting &amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; inline&amp;gt;#define EIGEN_USE_MKL_ALL&amp;lt;/syntaxhighlight&amp;gt; in your code,&lt;br /&gt;
some linker and compilation fixes are needed. You have to set MKL and MKLROOT variables in cmake. You can define&lt;br /&gt;
the variable MKLROOT as a system variable (using export) which is enough. You can also define it manually when calling&lt;br /&gt;
cmake. If it is not set in either way it will default to &amp;quot;/opt/intel/compilers_and_libraries_2017.2.174/linux/mkl&amp;quot;.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cmake .. -DMKL=ON -DMKLROOT=/opt/intel/compilers_and_libraries_2016.1.150/linux/mkl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Your target has to be linked with some MKL libraries so make sure to add the following link to your cmake file.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cmake&amp;quot;&amp;gt;&lt;br /&gt;
target_link_libraries(target ${LMKL})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Building on Mac OSX ==&lt;br /&gt;
This method was tested on El Capitan. Linking the OpenMP library is still not functioning as intended.&lt;br /&gt;
&lt;br /&gt;
First install all dependencies from homebrew&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
brew install llvm cmake homebrew/science/hdf5 SFML&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Now you can clone and build the project with CLang using the following commands&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://gitlab.com/e62Lab/e62numcodes.git&lt;br /&gt;
cd e62numcodes&lt;br /&gt;
mkdir build&lt;br /&gt;
cd build&lt;br /&gt;
cmake .. -DCMAKE_C_COMPILER=/usr/local/opt/llvm/bin/clang -DCMAKE_CXX_COMPILER=/usr/local/opt/llvm/bin/clang++&lt;br /&gt;
make domain_run_tests&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Intel C/C++ Compiler ==&lt;br /&gt;
&lt;br /&gt;
In order to use Intel's compiler you have to first set the &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;CXX&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;CC&amp;lt;/syntaxhighlight&amp;gt; bash variables. Before calling&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;lt;/syntaxhighlight&amp;gt; for the first time you have to export the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export CXX=&amp;quot;icpc&amp;quot;&lt;br /&gt;
export CC=&amp;quot;icc&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or you can define the compiler when first calling cmake like so:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cmake .. -DCMAKE_C_COMPILER=$(which icc) -DCMAKE_CXX_COMPILER=$(which icpc) &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also compile it directly for Intel® Xeon Phi™ Coprocessor. You do this by adding &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;-Dmmic=ON&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
flag to the &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;cmake&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cmake .. -Dmmic=ON -DCMAKE_C_COMPILER=$(which icc) -DCMAKE_CXX_COMPILER=$(which icpc) &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note:&amp;lt;/b&amp;gt; All features that depend on system third-party libraries are not available on MIC (Many Integrated Core).&lt;br /&gt;
This includes:&lt;br /&gt;
&lt;br /&gt;
* [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/technical_docs/html/classmm_1_1HDF5IO.html HDF5IO] class in &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;io.hpp&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/technical_docs/html/classmm_1_1Monitor.html Monitor] class in &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;util.hpp&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* all of [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/technical_docs/html/util_8hpp_source.html  &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;draw.hpp&amp;lt;/syntaxhighlight&amp;gt;]&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=How_to_build&amp;diff=1196</id>
		<title>How to build</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=How_to_build&amp;diff=1196"/>
				<updated>2017-06-12T09:15:10Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Installation=&lt;br /&gt;
To make this work from plain Ubuntu installation, run&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install cmake doxygen graphviz libboost-dev libsfml-dev libhdf5-serial-dev&lt;br /&gt;
git clone https://gitlab.com/e62Lab/e62numcodes.git&lt;br /&gt;
cd e62numcodes&lt;br /&gt;
./run_tests.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
which installs dependancies, clones the repository, goes into the root folder of the repository and runs tests. This will check the configuration, notify you of potentially missing dependencies, build and run all tests, check code style and docs. If this works, you are ready to go! Otherwise install any missing packages and if it still fails, raise an issue!&lt;br /&gt;
&lt;br /&gt;
=Building=&lt;br /&gt;
&lt;br /&gt;
List of dependencies:&lt;br /&gt;
&lt;br /&gt;
* Build tools, like &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;gt;= 2.8.12&amp;lt;/syntaxhighlight&amp;gt;, &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; g++ &amp;gt;= 4.8&amp;lt;/syntaxhighlight&amp;gt;, &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;make&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* [http://www.boost.org/ Boost]&lt;br /&gt;
* &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; doxygen &amp;gt;=  1.8.8 &amp;lt;/syntaxhighlight&amp;gt; and Graphviz&lt;br /&gt;
* for drawing [http://www.sfml-dev.org/ SMFL library version 2]&lt;br /&gt;
* for IO [https://www.hdfgroup.org/ HDF5 library]&lt;br /&gt;
&lt;br /&gt;
Out of source builds are preferred. Run&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir -p build&lt;br /&gt;
cd build&lt;br /&gt;
cmake ..&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Note that you only have to run &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;lt;/syntaxhighlight&amp;gt; once, after that only &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&amp;lt;/syntaxhighlight&amp;gt; is sufficient.&lt;br /&gt;
&lt;br /&gt;
Binaries are placed into &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; bin &amp;lt;/syntaxhighlight&amp;gt; folder. Test can be run all at once via &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&lt;br /&gt;
run_all_tests &amp;lt;/syntaxhighlight&amp;gt; or individually via eg. &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;make basisfunc_run_tests &amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Linear Algebra==&lt;br /&gt;
We use [http://eigen.tuxfamily.org/ Eigen] as our matrix library. See&lt;br /&gt;
[http://eigen.tuxfamily.org/dox-devel/group__QuickRefPage.html here] for use&lt;br /&gt;
reference and documentation. For a quick transition from Matlab see&lt;br /&gt;
[http://eigen.tuxfamily.org/dox/AsciiQuickReference.txt here].&lt;br /&gt;
&lt;br /&gt;
==Drawing==&lt;br /&gt;
Some tests include drawing. We are using [http://www.sfml-dev.org/ SMFL library], which can be installed on most linux systems easly&lt;br /&gt;
as &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo apt-get install libsfml-dev &amp;lt;/syntaxhighlight&amp;gt; or &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo pacman -S sfml &amp;lt;/syntaxhighlight&amp;gt;.  After the&lt;br /&gt;
installation uncomment a test case in &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; domain_draw_test.cpp &amp;lt;/syntaxhighlight&amp;gt; and run &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&lt;br /&gt;
test_domain_draw &amp;lt;/syntaxhighlight&amp;gt; to see the visual effect.&lt;br /&gt;
&lt;br /&gt;
Binaries using SFML require additional linker flags &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; -lsfml-graphics&lt;br /&gt;
-lsfml-window -lsfml-system &amp;lt;/syntaxhighlight&amp;gt;, but the makefile should take care of that for you.&lt;br /&gt;
&lt;br /&gt;
==HDF5==&lt;br /&gt;
&lt;br /&gt;
In order to use IO you need [https://www.hdfgroup.org/ hdf5 library].&lt;br /&gt;
You can install it easily using the command &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo apt-get install libhdf5-&lt;br /&gt;
dev &amp;lt;/syntaxhighlight&amp;gt; or &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo pacman -S hdf5-cpp-fortran &amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Ubuntu places hdf5 libs in a werid folder &amp;lt;code&amp;gt;/usr/lib/x86_64-linux-gnu/hdf5/serial/&amp;lt;/code&amp;gt;. &lt;br /&gt;
If you get error similar to &amp;lt;code&amp;gt;-lhdf5 not found&amp;lt;/code&amp;gt; and you have hdf5 installed, you might have to link the libraries into&lt;br /&gt;
a discoverable place, like &amp;lt;code&amp;gt;/usr/lib/&amp;lt;/code&amp;gt; or add the above directory to the linker path.&lt;br /&gt;
If using cmake, you can add the following line to your CMakeLists.txt&lt;br /&gt;
  link_directories(/usr/lib/x86_64-linux-gnu/hdf5/serial/)&lt;br /&gt;
&lt;br /&gt;
== Using Intel Math Kernel Library (MKL) ==&lt;br /&gt;
Eigen has great support for MKL all you have to do is define a EIGEN_USE_MKL_ALL macro before any includes.&lt;br /&gt;
You can see further instructions [https://eigen.tuxfamily.org/dox/TopicUsingIntelMKL.html on their website].&lt;br /&gt;
&lt;br /&gt;
Besides setting &amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; inline&amp;gt;#define EIGEN_USE_MKL_ALL&amp;lt;/syntaxhighlight&amp;gt; in your code,&lt;br /&gt;
some linker and compilation fixes are needed. You have to set MKL and MKLROOT variables in cmake. You can define&lt;br /&gt;
the variable MKLROOT as a system variable (using export) which is enough. You can also define it manually when calling&lt;br /&gt;
cmake. If it is not set in either way it will default to &amp;quot;/opt/intel/compilers_and_libraries_2017.2.174/linux/mkl&amp;quot;.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cmake .. -DMKL=ON -DMKLROOT=/opt/intel/compilers_and_libraries_2016.1.150/linux/mkl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Your target has to be linked with some MKL libraries so make sure to add the following link to your cmake file.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cmake&amp;quot;&amp;gt;&lt;br /&gt;
target_link_libraries(target ${LMKL})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Building on Mac OSX ==&lt;br /&gt;
This method was tested on El Capitan. Linking the OpenMP library is still not functioning as intended.&lt;br /&gt;
&lt;br /&gt;
First install all dependencies from homebrew&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
brew install llvm cmake homebrew/science/hdf5 SFML&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Now you can clone and build the project with CLang using the following commands&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://gitlab.com/e62Lab/e62numcodes.git&lt;br /&gt;
cd e62numcodes&lt;br /&gt;
mkdir build&lt;br /&gt;
cd build&lt;br /&gt;
cmake .. -DCMAKE_C_COMPILER=//clang -DCMAKE_CXX_COMPILER=/clang++&lt;br /&gt;
make domain_run_tests&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Using Intel C/C++ Compiler ==&lt;br /&gt;
&lt;br /&gt;
In order to use Intel's compiler you have to first set the &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;CXX&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;CC&amp;lt;/syntaxhighlight&amp;gt; bash variables. Before calling&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;lt;/syntaxhighlight&amp;gt; for the first time you have to export the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export CXX=&amp;quot;icpc&amp;quot;&lt;br /&gt;
export CC=&amp;quot;icc&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or you can define the compiler when first calling cmake like so:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cmake .. -DCMAKE_C_COMPILER=$(which icc) -DCMAKE_CXX_COMPILER=$(which icpc) &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also compile it directly for Intel® Xeon Phi™ Coprocessor. You do this by adding &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;-Dmmic=ON&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
flag to the &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;cmake&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cmake .. -Dmmic=ON -DCMAKE_C_COMPILER=$(which icc) -DCMAKE_CXX_COMPILER=$(which icpc) &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note:&amp;lt;/b&amp;gt; All features that depend on system third-party libraries are not available on MIC (Many Integrated Core).&lt;br /&gt;
This includes:&lt;br /&gt;
&lt;br /&gt;
* [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/technical_docs/html/classmm_1_1HDF5IO.html HDF5IO] class in &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;io.hpp&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/technical_docs/html/classmm_1_1Monitor.html Monitor] class in &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;util.hpp&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* all of [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/technical_docs/html/util_8hpp_source.html  &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;draw.hpp&amp;lt;/syntaxhighlight&amp;gt;]&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=File:Vec_novec_size_timed_log_normed.png&amp;diff=1043</id>
		<title>File:Vec novec size timed log normed.png</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=File:Vec_novec_size_timed_log_normed.png&amp;diff=1043"/>
				<updated>2017-03-30T11:08:18Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: Mkolman uploaded a new version of File:Vec novec size timed log normed.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;File uploaded with MsUpload&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Execution_on_Intel%C2%AE_Xeon_Phi%E2%84%A2_co-processor&amp;diff=1042</id>
		<title>Execution on Intel® Xeon Phi™ co-processor</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Execution_on_Intel%C2%AE_Xeon_Phi%E2%84%A2_co-processor&amp;diff=1042"/>
				<updated>2017-03-30T10:57:47Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Speedup by vectorization and parallelization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Speedup by parallelization ==&lt;br /&gt;
&lt;br /&gt;
We tested the speedups on the Intel® Xeon Phi™ with the following code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;assert.h&amp;gt;&lt;br /&gt;
#include &amp;lt;omp.h&amp;gt;&lt;br /&gt;
#include &amp;lt;math.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]) {&lt;br /&gt;
    int numthreads;&lt;br /&gt;
    int n;&lt;br /&gt;
&lt;br /&gt;
    assert(argc == 3 &amp;amp;&amp;amp; &amp;quot;args: numthreads n&amp;quot;);&lt;br /&gt;
    sscanf(argv[1], &amp;quot;%d&amp;quot;, &amp;amp;numthreads);&lt;br /&gt;
    sscanf(argv[2], &amp;quot;%d&amp;quot;, &amp;amp;n);&lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;Init...\n&amp;quot;);&lt;br /&gt;
    printf(&amp;quot;Start (%d threads)...\n&amp;quot;, numthreads);&lt;br /&gt;
    printf(&amp;quot;%d test cases\n&amp;quot;, n);&lt;br /&gt;
&lt;br /&gt;
    int m = 1000000;&lt;br /&gt;
    double ttime = omp_get_wtime();&lt;br /&gt;
&lt;br /&gt;
    int i;&lt;br /&gt;
    double d = 0;&lt;br /&gt;
#pragma offload target(mic:0)&lt;br /&gt;
    {&lt;br /&gt;
#pragma omp parallel for private (i) schedule(static) num_threads(numthreads)&lt;br /&gt;
        for(i = 0; i &amp;lt; n; ++i) {&lt;br /&gt;
            for(int j = 0; j &amp;lt; m; ++j) {&lt;br /&gt;
                d = sin(d) + 0.1 + j;&lt;br /&gt;
                d = pow(0.2, d)*j;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    double time = omp_get_wtime() - ttime;&lt;br /&gt;
    fprintf(stderr, &amp;quot;%d %d %.6f\n&amp;quot;, n, numthreads, time);&lt;br /&gt;
    printf(&amp;quot;time: %.6f s\n&amp;quot;, time);&lt;br /&gt;
    printf(&amp;quot;Done d = %.6lf.\n&amp;quot;, d);&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code essentially distributes a problem of size $n\cdot m$ among &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;numthreads&amp;lt;/syntaxhighlight&amp;gt; cores,&lt;br /&gt;
We tested the time of execution for $n$ from the set $\{1, 10, 20, 50, 100, 200, 500, 1000\}$&lt;br /&gt;
and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; numthreads &amp;lt;/syntaxhighlight&amp;gt; from $1$ to $350$. The plots of exectuion times and performance speeups are shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;figure id=&amp;quot;times&amp;quot;&amp;gt;&lt;br /&gt;
[[File:times.png|thumb|center|upright=3|alt=A square of nodes coloured according to the solution(with smaller and larger node density)|&amp;lt;caption&amp;gt;A picture of our solution (with smaller and larger node density)&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;figure id=&amp;quot;fig:speedups&amp;quot;&amp;gt;&lt;br /&gt;
[[File:speedups.png|thumb|center|upright=3|alt=A square of nodes coloured according to the solution(with smaller and larger node density)|&amp;lt;caption&amp;gt;A picture of our solution (with smaller and larger node density)&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The code was compiled using: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; icc -openmp -O3 -qopt-report=2 -qopt-report-phase=vec -o test test.cpp&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
without warnings or errors. Then, in order to offload to Intel Phi, user must be logged in as root: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo su &amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
To run correctly, intel compiler and runtime variables must be sourced: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; source /opt/intel/bin/compilervars.sh intel64&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
Finally, the code was tested using the following command, where &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; test &amp;lt;/syntaxhighlight&amp;gt; is the name of the compiled executable: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; for n in 1 10 20 50 100 200 500 1000; do for nt in {1..350}; echo $nt $n; ./test $nt $n 2&amp;gt;&amp;gt; speedups.txt; done; done&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Speedup by vectorization ==&lt;br /&gt;
&lt;br /&gt;
Intel Xeon Phi has a 512 bit of space for simultaneous computation, which means it can calculate 8 double (or 16 single) operations at the same time. This is called vectorization and greatly improves code execution.&lt;br /&gt;
&lt;br /&gt;
Consider the following code of speedtest.cpp:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
    const int N = 104;&lt;br /&gt;
    double a[N];&lt;br /&gt;
    for (int i = 0; i &amp;lt; 1e5; i++)&lt;br /&gt;
        for (int j = 0; j &amp;lt; N; j++)&lt;br /&gt;
            a[j] = std::sin(std::exp(a[j]-j)*3 * i + i*j);&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; a[4] &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Intel's C++ compiler ICPC will successfully vectorize the inner for loop, so that it will run significantly faster than with vectorization disabled.&lt;br /&gt;
&lt;br /&gt;
The code can be compiled with or without vectorization&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ icpc speedtest.cpp -o vectorized_speedtest -O3&lt;br /&gt;
$ icpc speedtest.cpp -o unvectorized_speedtest -O3 -no-vec&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The below table shows execution times of the code displayed before on different machines with different settings. Two times represent execution time with double and float data type, respectively.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Machine&lt;br /&gt;
| ASUS ZenBook Pro UX501VW&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
|-&lt;br /&gt;
! Compiler&lt;br /&gt;
| g++-6.3.1&lt;br /&gt;
| g++-4.8.5&lt;br /&gt;
| icpc-16.0.1&lt;br /&gt;
| icpc-16.0.1 -no-vec&lt;br /&gt;
| icpc-16.0.1 -mmic&lt;br /&gt;
| icpc-16.0.1 -mmic -no-vec&lt;br /&gt;
|-&lt;br /&gt;
! Double time[s]&lt;br /&gt;
| 0.63 - 0.66&lt;br /&gt;
| 0.65 - 0.66&lt;br /&gt;
| 0.155 - 0.160&lt;br /&gt;
| 0.50 - 0.51&lt;br /&gt;
| 0.25 - 0.26&lt;br /&gt;
| 11.1 - 11.2&lt;br /&gt;
|-&lt;br /&gt;
! Float time[s]&lt;br /&gt;
| 0.65 - 0.71&lt;br /&gt;
| 0.53 - 0.55&lt;br /&gt;
| 0.155 - 0.160&lt;br /&gt;
| 0.17 - 0.19&lt;br /&gt;
| 0.37 - 0.38&lt;br /&gt;
| 4.2 - 4.3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
We can see massive 44 fold speedup with and without vectorization.&lt;br /&gt;
&lt;br /&gt;
=== Code incapable of vectorization ===&lt;br /&gt;
&lt;br /&gt;
On the other hand there is a very similar code that can not be vectorized. Now all iterations of the inner loop access the same variable instead of each its own element in a list. ICPC is now unable to vectorize the code resulting in no difference when using -no-vec compile flag.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
    const int N = 104;&lt;br /&gt;
    double a;&lt;br /&gt;
    for (int i = 0; i &amp;lt; 1e5; i++)&lt;br /&gt;
        for (int j = 0; j &amp;lt; N; j++)&lt;br /&gt;
            a = std::sin(std::exp(a-j)*3 * i + i*j);&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Machine&lt;br /&gt;
| ASUS ZenBook Pro UX501VW&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
|-&lt;br /&gt;
! Compiler&lt;br /&gt;
| g++-6.3.1&lt;br /&gt;
| g++-4.8.5&lt;br /&gt;
| icpc-16.0.1&lt;br /&gt;
| icpc-16.0.1 -no-vec&lt;br /&gt;
| icpc-16.0.1 -mmic&lt;br /&gt;
| icpc-16.0.1 -mmic -no-vec&lt;br /&gt;
|-&lt;br /&gt;
! Double time[s]&lt;br /&gt;
| 0.80 - 0.82&lt;br /&gt;
| 0.72 - 0.73&lt;br /&gt;
| 0.58 - 0.59&lt;br /&gt;
| 0.58 - 0.59&lt;br /&gt;
| 10.9 - 11.0&lt;br /&gt;
| 10.9 - 11.0&lt;br /&gt;
|-&lt;br /&gt;
! Float time[s]&lt;br /&gt;
| 0.69 - 0.72&lt;br /&gt;
| 0.66 - 0.67&lt;br /&gt;
| 0.32 - 0.33&lt;br /&gt;
| 0.32 - 0.34&lt;br /&gt;
| 4.1 - 4.2&lt;br /&gt;
| 4.1 - 4.2&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Speedup by vectorization and parallelization ==&lt;br /&gt;
&lt;br /&gt;
Consider the following code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
int main(){&lt;br /&gt;
    double *a, *b, *c;&lt;br /&gt;
    int i,j,k, ok, n=1000;  // or n=10000&lt;br /&gt;
    // allocated memory on the heap aligned to 64 byte boundary&lt;br /&gt;
    ok = posix_memalign((void**)&amp;amp;a, 64, n*n*sizeof(double));&lt;br /&gt;
    ok = posix_memalign((void**)&amp;amp;b, 64, n*n*sizeof(double));&lt;br /&gt;
    ok = posix_memalign((void**)&amp;amp;c, 64, n*n*sizeof(double));&lt;br /&gt;
    // initialize matrices&lt;br /&gt;
    for (i = 0; i &amp;lt; n*n; ++i) {&lt;br /&gt;
        a[i] = 1;&lt;br /&gt;
        b[i] = 1;&lt;br /&gt;
        c[i] = 1;&lt;br /&gt;
    }&lt;br /&gt;
    //parallelize via OpenMP on MIC&lt;br /&gt;
    #pragma omp parallel for&lt;br /&gt;
    for( i = 0; i &amp;lt; n; i++ ) {&lt;br /&gt;
        for( k = 0; k &amp;lt; n; k++ ) {&lt;br /&gt;
            #pragma vector aligned&lt;br /&gt;
            #pragma ivdep&lt;br /&gt;
            for( j = 0; j &amp;lt; n; j++ ) {&lt;br /&gt;
                //c[i][j] = c[i][j] + a[i][k]*b[k][j];&lt;br /&gt;
                c[i*n+j] = c[i*n+j] + a[i*n+k]*b[k*n+j];&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    printf(&amp;quot;%f\n&amp;quot;, c[n]);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is designed to be parallelizable and vectorizable. But with smaller systems (N=1000) we lose the benefits of vectorization with larger number of threads used.&lt;br /&gt;
&lt;br /&gt;
However even the larger test case (N=10000) is barely faster than execution on the host processor. With 61 threads and vectorization it runs for a flat minute,&lt;br /&gt;
where the host with 24 threads needs 1 minute and 15 seconds.&lt;br /&gt;
&lt;br /&gt;
It is interesting to note that so-called &amp;quot;real time&amp;quot;, i.e. the total processor time used, behaves differently for vectorized and nonvectorized code. For $N=10^4$&lt;br /&gt;
nonvectorized code constantly uses 133 minutes for completion regardless of thread number, but vectorized code goes from 33 minutes with one thread to an hour&lt;br /&gt;
of total processing time with 61 threads. Similarly with $N=10^3$ and 61 threads nonvectorized code uses 125% of it beginning processing time, where for vectorized&lt;br /&gt;
that figure is 600%.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;figure id=&amp;quot;times&amp;quot;&amp;gt;&lt;br /&gt;
[[File:vec_novec_timed.png|thumb|center|upright=3|alt=Times used|&amp;lt;caption&amp;gt;Times used for the sample problem with and without vectorization using different number threads for two different N.&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below is a scan over different sizes $N$. Two parallelization regimes were used; Number of threads equal to the physical number of cores, and twice as many threads&lt;br /&gt;
to take advantage of hyperthreading. All modes of execution show the same basic shape. All are inefficient for small $N$ but approach the complexity $N^3$ for large $N$.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;figure id=&amp;quot;times&amp;quot;&amp;gt;&lt;br /&gt;
[[File:vec_novec_size_timed_log.png|thumb|center|upright=3|alt=Times used|&amp;lt;caption&amp;gt;Times used for a single operation with and without vectorization for different N.&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below we take a closer look at the time used for a single operation for larger $N$.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;figure id=&amp;quot;times&amp;quot;&amp;gt;&lt;br /&gt;
[[File:vec_novec_size_timed_log_normed.png|thumb|center|upright=3|alt=Times used|&amp;lt;caption&amp;gt;Times used for the sample problem with and without vectorization for different N.&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=File:Vec_novec_size_timed_log_normed.png&amp;diff=1041</id>
		<title>File:Vec novec size timed log normed.png</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=File:Vec_novec_size_timed_log_normed.png&amp;diff=1041"/>
				<updated>2017-03-30T10:49:27Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: File uploaded with MsUpload&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;File uploaded with MsUpload&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=File:Vec_novec_timed.png&amp;diff=1040</id>
		<title>File:Vec novec timed.png</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=File:Vec_novec_timed.png&amp;diff=1040"/>
				<updated>2017-03-30T10:44:39Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: Mkolman uploaded a new version of File:Vec novec timed.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;File uploaded with MsUpload&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=File:Vec_novec_size_timed_log.png&amp;diff=1039</id>
		<title>File:Vec novec size timed log.png</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=File:Vec_novec_size_timed_log.png&amp;diff=1039"/>
				<updated>2017-03-30T10:41:33Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: File uploaded with MsUpload&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;File uploaded with MsUpload&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=File:Vec_novec_timed.png&amp;diff=1038</id>
		<title>File:Vec novec timed.png</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=File:Vec_novec_timed.png&amp;diff=1038"/>
				<updated>2017-03-28T18:47:23Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: Mkolman uploaded a new version of File:Vec novec timed.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;File uploaded with MsUpload&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Execution_on_Intel%C2%AE_Xeon_Phi%E2%84%A2_co-processor&amp;diff=1037</id>
		<title>Execution on Intel® Xeon Phi™ co-processor</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Execution_on_Intel%C2%AE_Xeon_Phi%E2%84%A2_co-processor&amp;diff=1037"/>
				<updated>2017-03-28T13:56:57Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Speedup by vectorization and parallelization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Speedup by parallelization ==&lt;br /&gt;
&lt;br /&gt;
We tested the speedups on the Intel® Xeon Phi™ with the following code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;assert.h&amp;gt;&lt;br /&gt;
#include &amp;lt;omp.h&amp;gt;&lt;br /&gt;
#include &amp;lt;math.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]) {&lt;br /&gt;
    int numthreads;&lt;br /&gt;
    int n;&lt;br /&gt;
&lt;br /&gt;
    assert(argc == 3 &amp;amp;&amp;amp; &amp;quot;args: numthreads n&amp;quot;);&lt;br /&gt;
    sscanf(argv[1], &amp;quot;%d&amp;quot;, &amp;amp;numthreads);&lt;br /&gt;
    sscanf(argv[2], &amp;quot;%d&amp;quot;, &amp;amp;n);&lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;Init...\n&amp;quot;);&lt;br /&gt;
    printf(&amp;quot;Start (%d threads)...\n&amp;quot;, numthreads);&lt;br /&gt;
    printf(&amp;quot;%d test cases\n&amp;quot;, n);&lt;br /&gt;
&lt;br /&gt;
    int m = 1000000;&lt;br /&gt;
    double ttime = omp_get_wtime();&lt;br /&gt;
&lt;br /&gt;
    int i;&lt;br /&gt;
    double d = 0;&lt;br /&gt;
#pragma offload target(mic:0)&lt;br /&gt;
    {&lt;br /&gt;
#pragma omp parallel for private (i) schedule(static) num_threads(numthreads)&lt;br /&gt;
        for(i = 0; i &amp;lt; n; ++i) {&lt;br /&gt;
            for(int j = 0; j &amp;lt; m; ++j) {&lt;br /&gt;
                d = sin(d) + 0.1 + j;&lt;br /&gt;
                d = pow(0.2, d)*j;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    double time = omp_get_wtime() - ttime;&lt;br /&gt;
    fprintf(stderr, &amp;quot;%d %d %.6f\n&amp;quot;, n, numthreads, time);&lt;br /&gt;
    printf(&amp;quot;time: %.6f s\n&amp;quot;, time);&lt;br /&gt;
    printf(&amp;quot;Done d = %.6lf.\n&amp;quot;, d);&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code essentially distributes a problem of size $n\cdot m$ among &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;numthreads&amp;lt;/syntaxhighlight&amp;gt; cores,&lt;br /&gt;
We tested the time of execution for $n$ from the set $\{1, 10, 20, 50, 100, 200, 500, 1000\}$&lt;br /&gt;
and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; numthreads &amp;lt;/syntaxhighlight&amp;gt; from $1$ to $350$. The plots of exectuion times and performance speeups are shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;figure id=&amp;quot;times&amp;quot;&amp;gt;&lt;br /&gt;
[[File:times.png|thumb|center|upright=3|alt=A square of nodes coloured according to the solution(with smaller and larger node density)|&amp;lt;caption&amp;gt;A picture of our solution (with smaller and larger node density)&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;figure id=&amp;quot;fig:speedups&amp;quot;&amp;gt;&lt;br /&gt;
[[File:speedups.png|thumb|center|upright=3|alt=A square of nodes coloured according to the solution(with smaller and larger node density)|&amp;lt;caption&amp;gt;A picture of our solution (with smaller and larger node density)&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The code was compiled using: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; icc -openmp -O3 -qopt-report=2 -qopt-report-phase=vec -o test test.cpp&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
without warnings or errors. Then, in order to offload to Intel Phi, user must be logged in as root: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo su &amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
To run correctly, intel compiler and runtime variables must be sourced: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; source /opt/intel/bin/compilervars.sh intel64&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
Finally, the code was tested using the following command, where &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; test &amp;lt;/syntaxhighlight&amp;gt; is the name of the compiled executable: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; for n in 1 10 20 50 100 200 500 1000; do for nt in {1..350}; echo $nt $n; ./test $nt $n 2&amp;gt;&amp;gt; speedups.txt; done; done&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Speedup by vectorization ==&lt;br /&gt;
&lt;br /&gt;
Intel Xeon Phi has a 512 bit of space for simultaneous computation, which means it can calculate 8 double (or 16 single) operations at the same time. This is called vectorization and greatly improves code execution.&lt;br /&gt;
&lt;br /&gt;
Consider the following code of speedtest.cpp:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
    const int N = 104;&lt;br /&gt;
    double a[N];&lt;br /&gt;
    for (int i = 0; i &amp;lt; 1e5; i++)&lt;br /&gt;
        for (int j = 0; j &amp;lt; N; j++)&lt;br /&gt;
            a[j] = std::sin(std::exp(a[j]-j)*3 * i + i*j);&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; a[4] &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Intel's C++ compiler ICPC will successfully vectorize the inner for loop, so that it will run significantly faster than with vectorization disabled.&lt;br /&gt;
&lt;br /&gt;
The code can be compiled with or without vectorization&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ icpc speedtest.cpp -o vectorized_speedtest -O3&lt;br /&gt;
$ icpc speedtest.cpp -o unvectorized_speedtest -O3 -no-vec&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The below table shows execution times of the code displayed before on different machines with different settings. Two times represent execution time with double and float data type, respectively.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Machine&lt;br /&gt;
| ASUS ZenBook Pro UX501VW&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
|-&lt;br /&gt;
! Compiler&lt;br /&gt;
| g++-6.3.1&lt;br /&gt;
| g++-4.8.5&lt;br /&gt;
| icpc-16.0.1&lt;br /&gt;
| icpc-16.0.1 -no-vec&lt;br /&gt;
| icpc-16.0.1 -mmic&lt;br /&gt;
| icpc-16.0.1 -mmic -no-vec&lt;br /&gt;
|-&lt;br /&gt;
! Double time[s]&lt;br /&gt;
| 0.63 - 0.66&lt;br /&gt;
| 0.65 - 0.66&lt;br /&gt;
| 0.155 - 0.160&lt;br /&gt;
| 0.50 - 0.51&lt;br /&gt;
| 0.25 - 0.26&lt;br /&gt;
| 11.1 - 11.2&lt;br /&gt;
|-&lt;br /&gt;
! Float time[s]&lt;br /&gt;
| 0.65 - 0.71&lt;br /&gt;
| 0.53 - 0.55&lt;br /&gt;
| 0.155 - 0.160&lt;br /&gt;
| 0.17 - 0.19&lt;br /&gt;
| 0.37 - 0.38&lt;br /&gt;
| 4.2 - 4.3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
We can see massive 44 fold speedup with and without vectorization.&lt;br /&gt;
&lt;br /&gt;
=== Code incapable of vectorization ===&lt;br /&gt;
&lt;br /&gt;
On the other hand there is a very similar code that can not be vectorized. Now all iterations of the inner loop access the same variable instead of each its own element in a list. ICPC is now unable to vectorize the code resulting in no difference when using -no-vec compile flag.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
    const int N = 104;&lt;br /&gt;
    double a;&lt;br /&gt;
    for (int i = 0; i &amp;lt; 1e5; i++)&lt;br /&gt;
        for (int j = 0; j &amp;lt; N; j++)&lt;br /&gt;
            a = std::sin(std::exp(a-j)*3 * i + i*j);&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Machine&lt;br /&gt;
| ASUS ZenBook Pro UX501VW&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
|-&lt;br /&gt;
! Compiler&lt;br /&gt;
| g++-6.3.1&lt;br /&gt;
| g++-4.8.5&lt;br /&gt;
| icpc-16.0.1&lt;br /&gt;
| icpc-16.0.1 -no-vec&lt;br /&gt;
| icpc-16.0.1 -mmic&lt;br /&gt;
| icpc-16.0.1 -mmic -no-vec&lt;br /&gt;
|-&lt;br /&gt;
! Double time[s]&lt;br /&gt;
| 0.80 - 0.82&lt;br /&gt;
| 0.72 - 0.73&lt;br /&gt;
| 0.58 - 0.59&lt;br /&gt;
| 0.58 - 0.59&lt;br /&gt;
| 10.9 - 11.0&lt;br /&gt;
| 10.9 - 11.0&lt;br /&gt;
|-&lt;br /&gt;
! Float time[s]&lt;br /&gt;
| 0.69 - 0.72&lt;br /&gt;
| 0.66 - 0.67&lt;br /&gt;
| 0.32 - 0.33&lt;br /&gt;
| 0.32 - 0.34&lt;br /&gt;
| 4.1 - 4.2&lt;br /&gt;
| 4.1 - 4.2&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Speedup by vectorization and parallelization ==&lt;br /&gt;
&lt;br /&gt;
Consider the following code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
int main(){&lt;br /&gt;
    double *a, *b, *c;&lt;br /&gt;
    int i,j,k, ok, n=1000;  // or n=10000&lt;br /&gt;
    // allocated memory on the heap aligned to 64 byte boundary&lt;br /&gt;
    ok = posix_memalign((void**)&amp;amp;a, 64, n*n*sizeof(double));&lt;br /&gt;
    ok = posix_memalign((void**)&amp;amp;b, 64, n*n*sizeof(double));&lt;br /&gt;
    ok = posix_memalign((void**)&amp;amp;c, 64, n*n*sizeof(double));&lt;br /&gt;
    // initialize matrices&lt;br /&gt;
    for (i = 0; i &amp;lt; n*n; ++i) {&lt;br /&gt;
        a[i] = 1;&lt;br /&gt;
        b[i] = 1;&lt;br /&gt;
        c[i] = 1;&lt;br /&gt;
    }&lt;br /&gt;
    //parallelize via OpenMP on MIC&lt;br /&gt;
    #pragma omp parallel for&lt;br /&gt;
    for( i = 0; i &amp;lt; n; i++ ) {&lt;br /&gt;
        for( k = 0; k &amp;lt; n; k++ ) {&lt;br /&gt;
            #pragma vector aligned&lt;br /&gt;
            #pragma ivdep&lt;br /&gt;
            for( j = 0; j &amp;lt; n; j++ ) {&lt;br /&gt;
                //c[i][j] = c[i][j] + a[i][k]*b[k][j];&lt;br /&gt;
                c[i*n+j] = c[i*n+j] + a[i*n+k]*b[k*n+j];&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    printf(&amp;quot;%f\n&amp;quot;, c[n]);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is designed to be parallelizable and vectorizable. But with smaller systems (N=1000) we lose the benefits of vectorization with larger number of threads used.&lt;br /&gt;
&lt;br /&gt;
However even the larger test case (N=10000) is barely faster than execution on the host processor. With 61 threads and vectorization it runs for a flat minute,&lt;br /&gt;
where the host with 24 threads needs 1 minute and 15 seconds.&lt;br /&gt;
&lt;br /&gt;
It is interesting to note that so-called &amp;quot;real time&amp;quot;, i.e. the total processor time used, behaves differently for vectorized and nonvectorized code. For $N=10^4$&lt;br /&gt;
nonvectorized code constantly uses 133 minutes for completion regardless of thread number, but vectorized code goes from 33 minutes with one thread to an hour&lt;br /&gt;
of total processing time with 61 threads. Similarly with $N=10^3$ and 61 threads nonvectorized code uses 125% of it beginning processing time, where for vectorized&lt;br /&gt;
that figure is 600%.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;figure id=&amp;quot;times&amp;quot;&amp;gt;&lt;br /&gt;
[[File:vec_novec_timed.png|thumb|center|upright=3|alt=Times used|&amp;lt;caption&amp;gt;Times used for the sample problem with and without vectorization for two different N.&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Execution_on_Intel%C2%AE_Xeon_Phi%E2%84%A2_co-processor&amp;diff=1033</id>
		<title>Execution on Intel® Xeon Phi™ co-processor</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Execution_on_Intel%C2%AE_Xeon_Phi%E2%84%A2_co-processor&amp;diff=1033"/>
				<updated>2017-03-28T09:40:46Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Speedup by vectorization and parallelization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Speedup by parallelization ==&lt;br /&gt;
&lt;br /&gt;
We tested the speedups on the Intel® Xeon Phi™ with the following code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;assert.h&amp;gt;&lt;br /&gt;
#include &amp;lt;omp.h&amp;gt;&lt;br /&gt;
#include &amp;lt;math.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]) {&lt;br /&gt;
    int numthreads;&lt;br /&gt;
    int n;&lt;br /&gt;
&lt;br /&gt;
    assert(argc == 3 &amp;amp;&amp;amp; &amp;quot;args: numthreads n&amp;quot;);&lt;br /&gt;
    sscanf(argv[1], &amp;quot;%d&amp;quot;, &amp;amp;numthreads);&lt;br /&gt;
    sscanf(argv[2], &amp;quot;%d&amp;quot;, &amp;amp;n);&lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;Init...\n&amp;quot;);&lt;br /&gt;
    printf(&amp;quot;Start (%d threads)...\n&amp;quot;, numthreads);&lt;br /&gt;
    printf(&amp;quot;%d test cases\n&amp;quot;, n);&lt;br /&gt;
&lt;br /&gt;
    int m = 1000000;&lt;br /&gt;
    double ttime = omp_get_wtime();&lt;br /&gt;
&lt;br /&gt;
    int i;&lt;br /&gt;
    double d = 0;&lt;br /&gt;
#pragma offload target(mic:0)&lt;br /&gt;
    {&lt;br /&gt;
#pragma omp parallel for private (i) schedule(static) num_threads(numthreads)&lt;br /&gt;
        for(i = 0; i &amp;lt; n; ++i) {&lt;br /&gt;
            for(int j = 0; j &amp;lt; m; ++j) {&lt;br /&gt;
                d = sin(d) + 0.1 + j;&lt;br /&gt;
                d = pow(0.2, d)*j;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    double time = omp_get_wtime() - ttime;&lt;br /&gt;
    fprintf(stderr, &amp;quot;%d %d %.6f\n&amp;quot;, n, numthreads, time);&lt;br /&gt;
    printf(&amp;quot;time: %.6f s\n&amp;quot;, time);&lt;br /&gt;
    printf(&amp;quot;Done d = %.6lf.\n&amp;quot;, d);&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code essentially distributes a problem of size $n\cdot m$ among &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;numthreads&amp;lt;/syntaxhighlight&amp;gt; cores,&lt;br /&gt;
We tested the time of execution for $n$ from the set $\{1, 10, 20, 50, 100, 200, 500, 1000\}$&lt;br /&gt;
and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; numthreads &amp;lt;/syntaxhighlight&amp;gt; from $1$ to $350$. The plots of exectuion times and performance speeups are shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;figure id=&amp;quot;times&amp;quot;&amp;gt;&lt;br /&gt;
[[File:times.png|thumb|center|upright=3|alt=A square of nodes coloured according to the solution(with smaller and larger node density)|&amp;lt;caption&amp;gt;A picture of our solution (with smaller and larger node density)&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;figure id=&amp;quot;fig:speedups&amp;quot;&amp;gt;&lt;br /&gt;
[[File:speedups.png|thumb|center|upright=3|alt=A square of nodes coloured according to the solution(with smaller and larger node density)|&amp;lt;caption&amp;gt;A picture of our solution (with smaller and larger node density)&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The code was compiled using: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; icc -openmp -O3 -qopt-report=2 -qopt-report-phase=vec -o test test.cpp&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
without warnings or errors. Then, in order to offload to Intel Phi, user must be logged in as root: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo su &amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
To run correctly, intel compiler and runtime variables must be sourced: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; source /opt/intel/bin/compilervars.sh intel64&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
Finally, the code was tested using the following command, where &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; test &amp;lt;/syntaxhighlight&amp;gt; is the name of the compiled executable: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; for n in 1 10 20 50 100 200 500 1000; do for nt in {1..350}; echo $nt $n; ./test $nt $n 2&amp;gt;&amp;gt; speedups.txt; done; done&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Speedup by vectorization ==&lt;br /&gt;
&lt;br /&gt;
Intel Xeon Phi has a 512 bit of space for simultaneous computation, which means it can calculate 8 double (or 16 single) operations at the same time. This is called vectorization and greatly improves code execution.&lt;br /&gt;
&lt;br /&gt;
Consider the following code of speedtest.cpp:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
    const int N = 104;&lt;br /&gt;
    double a[N];&lt;br /&gt;
    for (int i = 0; i &amp;lt; 1e5; i++)&lt;br /&gt;
        for (int j = 0; j &amp;lt; N; j++)&lt;br /&gt;
            a[j] = std::sin(std::exp(a[j]-j)*3 * i + i*j);&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; a[4] &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Intel's C++ compiler ICPC will successfully vectorize the inner for loop, so that it will run significantly faster than with vectorization disabled.&lt;br /&gt;
&lt;br /&gt;
The code can be compiled with or without vectorization&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ icpc speedtest.cpp -o vectorized_speedtest -O3&lt;br /&gt;
$ icpc speedtest.cpp -o unvectorized_speedtest -O3 -no-vec&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The below table shows execution times of the code displayed before on different machines with different settings. Two times represent execution time with double and float data type, respectively.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Machine&lt;br /&gt;
| ASUS ZenBook Pro UX501VW&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
|-&lt;br /&gt;
! Compiler&lt;br /&gt;
| g++-6.3.1&lt;br /&gt;
| g++-4.8.5&lt;br /&gt;
| icpc-16.0.1&lt;br /&gt;
| icpc-16.0.1 -no-vec&lt;br /&gt;
| icpc-16.0.1 -mmic&lt;br /&gt;
| icpc-16.0.1 -mmic -no-vec&lt;br /&gt;
|-&lt;br /&gt;
! Double time[s]&lt;br /&gt;
| 0.63 - 0.66&lt;br /&gt;
| 0.65 - 0.66&lt;br /&gt;
| 0.155 - 0.160&lt;br /&gt;
| 0.50 - 0.51&lt;br /&gt;
| 0.25 - 0.26&lt;br /&gt;
| 11.1 - 11.2&lt;br /&gt;
|-&lt;br /&gt;
! Float time[s]&lt;br /&gt;
| 0.65 - 0.71&lt;br /&gt;
| 0.53 - 0.55&lt;br /&gt;
| 0.155 - 0.160&lt;br /&gt;
| 0.17 - 0.19&lt;br /&gt;
| 0.37 - 0.38&lt;br /&gt;
| 4.2 - 4.3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
We can see massive 44 fold speedup with and without vectorization.&lt;br /&gt;
&lt;br /&gt;
=== Code incapable of vectorization ===&lt;br /&gt;
&lt;br /&gt;
On the other hand there is a very similar code that can not be vectorized. Now all iterations of the inner loop access the same variable instead of each its own element in a list. ICPC is now unable to vectorize the code resulting in no difference when using -no-vec compile flag.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
    const int N = 104;&lt;br /&gt;
    double a;&lt;br /&gt;
    for (int i = 0; i &amp;lt; 1e5; i++)&lt;br /&gt;
        for (int j = 0; j &amp;lt; N; j++)&lt;br /&gt;
            a = std::sin(std::exp(a-j)*3 * i + i*j);&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Machine&lt;br /&gt;
| ASUS ZenBook Pro UX501VW&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
|-&lt;br /&gt;
! Compiler&lt;br /&gt;
| g++-6.3.1&lt;br /&gt;
| g++-4.8.5&lt;br /&gt;
| icpc-16.0.1&lt;br /&gt;
| icpc-16.0.1 -no-vec&lt;br /&gt;
| icpc-16.0.1 -mmic&lt;br /&gt;
| icpc-16.0.1 -mmic -no-vec&lt;br /&gt;
|-&lt;br /&gt;
! Double time[s]&lt;br /&gt;
| 0.80 - 0.82&lt;br /&gt;
| 0.72 - 0.73&lt;br /&gt;
| 0.58 - 0.59&lt;br /&gt;
| 0.58 - 0.59&lt;br /&gt;
| 10.9 - 11.0&lt;br /&gt;
| 10.9 - 11.0&lt;br /&gt;
|-&lt;br /&gt;
! Float time[s]&lt;br /&gt;
| 0.69 - 0.72&lt;br /&gt;
| 0.66 - 0.67&lt;br /&gt;
| 0.32 - 0.33&lt;br /&gt;
| 0.32 - 0.34&lt;br /&gt;
| 4.1 - 4.2&lt;br /&gt;
| 4.1 - 4.2&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Speedup by vectorization and parallelization ==&lt;br /&gt;
&lt;br /&gt;
Consider the following code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
int main(){&lt;br /&gt;
    double *a, *b, *c;&lt;br /&gt;
    int i,j,k, ok, n=1000;  // or n=10000&lt;br /&gt;
    // allocated memory on the heap aligned to 64 byte boundary&lt;br /&gt;
    ok = posix_memalign((void**)&amp;amp;a, 64, n*n*sizeof(double));&lt;br /&gt;
    ok = posix_memalign((void**)&amp;amp;b, 64, n*n*sizeof(double));&lt;br /&gt;
    ok = posix_memalign((void**)&amp;amp;c, 64, n*n*sizeof(double));&lt;br /&gt;
    // initialize matrices&lt;br /&gt;
    for (i = 0; i &amp;lt; n*n; ++i) {&lt;br /&gt;
        a[i] = 1;&lt;br /&gt;
        b[i] = 1;&lt;br /&gt;
        c[i] = 1;&lt;br /&gt;
    }&lt;br /&gt;
    //parallelize via OpenMP on MIC&lt;br /&gt;
    #pragma omp parallel for&lt;br /&gt;
    for( i = 0; i &amp;lt; n; i++ ) {&lt;br /&gt;
        for( k = 0; k &amp;lt; n; k++ ) {&lt;br /&gt;
            #pragma vector aligned&lt;br /&gt;
            #pragma ivdep&lt;br /&gt;
            for( j = 0; j &amp;lt; n; j++ ) {&lt;br /&gt;
                //c[i][j] = c[i][j] + a[i][k]*b[k][j];&lt;br /&gt;
                c[i*n+j] = c[i*n+j] + a[i*n+k]*b[k*n+j];&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    printf(&amp;quot;%f\n&amp;quot;, c[n]);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;figure id=&amp;quot;times&amp;quot;&amp;gt;&lt;br /&gt;
[[File:vec_novec_timed.png|thumb|center|upright=3|alt=Times used|&amp;lt;caption&amp;gt;Times used for the sample problem with and without vectorization for two different N.&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Execution_on_Intel%C2%AE_Xeon_Phi%E2%84%A2_co-processor&amp;diff=1032</id>
		<title>Execution on Intel® Xeon Phi™ co-processor</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Execution_on_Intel%C2%AE_Xeon_Phi%E2%84%A2_co-processor&amp;diff=1032"/>
				<updated>2017-03-28T09:38:53Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Speedup by vectorization and parallelization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Speedup by parallelization ==&lt;br /&gt;
&lt;br /&gt;
We tested the speedups on the Intel® Xeon Phi™ with the following code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;assert.h&amp;gt;&lt;br /&gt;
#include &amp;lt;omp.h&amp;gt;&lt;br /&gt;
#include &amp;lt;math.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]) {&lt;br /&gt;
    int numthreads;&lt;br /&gt;
    int n;&lt;br /&gt;
&lt;br /&gt;
    assert(argc == 3 &amp;amp;&amp;amp; &amp;quot;args: numthreads n&amp;quot;);&lt;br /&gt;
    sscanf(argv[1], &amp;quot;%d&amp;quot;, &amp;amp;numthreads);&lt;br /&gt;
    sscanf(argv[2], &amp;quot;%d&amp;quot;, &amp;amp;n);&lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;Init...\n&amp;quot;);&lt;br /&gt;
    printf(&amp;quot;Start (%d threads)...\n&amp;quot;, numthreads);&lt;br /&gt;
    printf(&amp;quot;%d test cases\n&amp;quot;, n);&lt;br /&gt;
&lt;br /&gt;
    int m = 1000000;&lt;br /&gt;
    double ttime = omp_get_wtime();&lt;br /&gt;
&lt;br /&gt;
    int i;&lt;br /&gt;
    double d = 0;&lt;br /&gt;
#pragma offload target(mic:0)&lt;br /&gt;
    {&lt;br /&gt;
#pragma omp parallel for private (i) schedule(static) num_threads(numthreads)&lt;br /&gt;
        for(i = 0; i &amp;lt; n; ++i) {&lt;br /&gt;
            for(int j = 0; j &amp;lt; m; ++j) {&lt;br /&gt;
                d = sin(d) + 0.1 + j;&lt;br /&gt;
                d = pow(0.2, d)*j;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    double time = omp_get_wtime() - ttime;&lt;br /&gt;
    fprintf(stderr, &amp;quot;%d %d %.6f\n&amp;quot;, n, numthreads, time);&lt;br /&gt;
    printf(&amp;quot;time: %.6f s\n&amp;quot;, time);&lt;br /&gt;
    printf(&amp;quot;Done d = %.6lf.\n&amp;quot;, d);&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code essentially distributes a problem of size $n\cdot m$ among &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;numthreads&amp;lt;/syntaxhighlight&amp;gt; cores,&lt;br /&gt;
We tested the time of execution for $n$ from the set $\{1, 10, 20, 50, 100, 200, 500, 1000\}$&lt;br /&gt;
and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; numthreads &amp;lt;/syntaxhighlight&amp;gt; from $1$ to $350$. The plots of exectuion times and performance speeups are shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;figure id=&amp;quot;times&amp;quot;&amp;gt;&lt;br /&gt;
[[File:times.png|thumb|center|upright=3|alt=A square of nodes coloured according to the solution(with smaller and larger node density)|&amp;lt;caption&amp;gt;A picture of our solution (with smaller and larger node density)&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;figure id=&amp;quot;fig:speedups&amp;quot;&amp;gt;&lt;br /&gt;
[[File:speedups.png|thumb|center|upright=3|alt=A square of nodes coloured according to the solution(with smaller and larger node density)|&amp;lt;caption&amp;gt;A picture of our solution (with smaller and larger node density)&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The code was compiled using: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; icc -openmp -O3 -qopt-report=2 -qopt-report-phase=vec -o test test.cpp&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
without warnings or errors. Then, in order to offload to Intel Phi, user must be logged in as root: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo su &amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
To run correctly, intel compiler and runtime variables must be sourced: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; source /opt/intel/bin/compilervars.sh intel64&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
Finally, the code was tested using the following command, where &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; test &amp;lt;/syntaxhighlight&amp;gt; is the name of the compiled executable: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; for n in 1 10 20 50 100 200 500 1000; do for nt in {1..350}; echo $nt $n; ./test $nt $n 2&amp;gt;&amp;gt; speedups.txt; done; done&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Speedup by vectorization ==&lt;br /&gt;
&lt;br /&gt;
Intel Xeon Phi has a 512 bit of space for simultaneous computation, which means it can calculate 8 double (or 16 single) operations at the same time. This is called vectorization and greatly improves code execution.&lt;br /&gt;
&lt;br /&gt;
Consider the following code of speedtest.cpp:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
    const int N = 104;&lt;br /&gt;
    double a[N];&lt;br /&gt;
    for (int i = 0; i &amp;lt; 1e5; i++)&lt;br /&gt;
        for (int j = 0; j &amp;lt; N; j++)&lt;br /&gt;
            a[j] = std::sin(std::exp(a[j]-j)*3 * i + i*j);&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; a[4] &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Intel's C++ compiler ICPC will successfully vectorize the inner for loop, so that it will run significantly faster than with vectorization disabled.&lt;br /&gt;
&lt;br /&gt;
The code can be compiled with or without vectorization&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ icpc speedtest.cpp -o vectorized_speedtest -O3&lt;br /&gt;
$ icpc speedtest.cpp -o unvectorized_speedtest -O3 -no-vec&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The below table shows execution times of the code displayed before on different machines with different settings. Two times represent execution time with double and float data type, respectively.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Machine&lt;br /&gt;
| ASUS ZenBook Pro UX501VW&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
|-&lt;br /&gt;
! Compiler&lt;br /&gt;
| g++-6.3.1&lt;br /&gt;
| g++-4.8.5&lt;br /&gt;
| icpc-16.0.1&lt;br /&gt;
| icpc-16.0.1 -no-vec&lt;br /&gt;
| icpc-16.0.1 -mmic&lt;br /&gt;
| icpc-16.0.1 -mmic -no-vec&lt;br /&gt;
|-&lt;br /&gt;
! Double time[s]&lt;br /&gt;
| 0.63 - 0.66&lt;br /&gt;
| 0.65 - 0.66&lt;br /&gt;
| 0.155 - 0.160&lt;br /&gt;
| 0.50 - 0.51&lt;br /&gt;
| 0.25 - 0.26&lt;br /&gt;
| 11.1 - 11.2&lt;br /&gt;
|-&lt;br /&gt;
! Float time[s]&lt;br /&gt;
| 0.65 - 0.71&lt;br /&gt;
| 0.53 - 0.55&lt;br /&gt;
| 0.155 - 0.160&lt;br /&gt;
| 0.17 - 0.19&lt;br /&gt;
| 0.37 - 0.38&lt;br /&gt;
| 4.2 - 4.3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
We can see massive 44 fold speedup with and without vectorization.&lt;br /&gt;
&lt;br /&gt;
=== Code incapable of vectorization ===&lt;br /&gt;
&lt;br /&gt;
On the other hand there is a very similar code that can not be vectorized. Now all iterations of the inner loop access the same variable instead of each its own element in a list. ICPC is now unable to vectorize the code resulting in no difference when using -no-vec compile flag.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
    const int N = 104;&lt;br /&gt;
    double a;&lt;br /&gt;
    for (int i = 0; i &amp;lt; 1e5; i++)&lt;br /&gt;
        for (int j = 0; j &amp;lt; N; j++)&lt;br /&gt;
            a = std::sin(std::exp(a-j)*3 * i + i*j);&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Machine&lt;br /&gt;
| ASUS ZenBook Pro UX501VW&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
|-&lt;br /&gt;
! Compiler&lt;br /&gt;
| g++-6.3.1&lt;br /&gt;
| g++-4.8.5&lt;br /&gt;
| icpc-16.0.1&lt;br /&gt;
| icpc-16.0.1 -no-vec&lt;br /&gt;
| icpc-16.0.1 -mmic&lt;br /&gt;
| icpc-16.0.1 -mmic -no-vec&lt;br /&gt;
|-&lt;br /&gt;
! Double time[s]&lt;br /&gt;
| 0.80 - 0.82&lt;br /&gt;
| 0.72 - 0.73&lt;br /&gt;
| 0.58 - 0.59&lt;br /&gt;
| 0.58 - 0.59&lt;br /&gt;
| 10.9 - 11.0&lt;br /&gt;
| 10.9 - 11.0&lt;br /&gt;
|-&lt;br /&gt;
! Float time[s]&lt;br /&gt;
| 0.69 - 0.72&lt;br /&gt;
| 0.66 - 0.67&lt;br /&gt;
| 0.32 - 0.33&lt;br /&gt;
| 0.32 - 0.34&lt;br /&gt;
| 4.1 - 4.2&lt;br /&gt;
| 4.1 - 4.2&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Speedup by vectorization and parallelization ==&lt;br /&gt;
&lt;br /&gt;
Consider the following code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
int main(){&lt;br /&gt;
    double *a, *b, *c;&lt;br /&gt;
    int i,j,k, ok, n=1000;  // or n=10000&lt;br /&gt;
    // allocated memory on the heap aligned to 64 byte boundary&lt;br /&gt;
    ok = posix_memalign((void**)&amp;amp;a, 64, n*n*sizeof(double));&lt;br /&gt;
    ok = posix_memalign((void**)&amp;amp;b, 64, n*n*sizeof(double));&lt;br /&gt;
    ok = posix_memalign((void**)&amp;amp;c, 64, n*n*sizeof(double));&lt;br /&gt;
    // initialize matrices&lt;br /&gt;
    for (i = 0; i &amp;lt; n*n; ++i) {&lt;br /&gt;
        a[i] = 1;&lt;br /&gt;
        b[i] = 1;&lt;br /&gt;
        c[i] = 1;&lt;br /&gt;
    }&lt;br /&gt;
    //parallelize via OpenMP on MIC&lt;br /&gt;
    #pragma omp parallel for&lt;br /&gt;
    for( i = 0; i &amp;lt; n; i++ ) {&lt;br /&gt;
        for( k = 0; k &amp;lt; n; k++ ) {&lt;br /&gt;
            #pragma vector aligned&lt;br /&gt;
            #pragma ivdep&lt;br /&gt;
            for( j = 0; j &amp;lt; n; j++ ) {&lt;br /&gt;
                //c[i][j] = c[i][j] + a[i][k]*b[k][j];&lt;br /&gt;
                c[i*n+j] = c[i*n+j] + a[i*n+k]*b[k*n+j];&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    printf(&amp;quot;%f\n&amp;quot;, c[n]);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;figure id=&amp;quot;times&amp;quot;&amp;gt;&lt;br /&gt;
[[File:vec_novec_timed.png|thumb|center|upright=3|alt=Times used for the sample problem with and without vectorization for two different N.&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Execution_on_Intel%C2%AE_Xeon_Phi%E2%84%A2_co-processor&amp;diff=1031</id>
		<title>Execution on Intel® Xeon Phi™ co-processor</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Execution_on_Intel%C2%AE_Xeon_Phi%E2%84%A2_co-processor&amp;diff=1031"/>
				<updated>2017-03-28T09:35:35Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Speedup by vectorization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Speedup by parallelization ==&lt;br /&gt;
&lt;br /&gt;
We tested the speedups on the Intel® Xeon Phi™ with the following code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;assert.h&amp;gt;&lt;br /&gt;
#include &amp;lt;omp.h&amp;gt;&lt;br /&gt;
#include &amp;lt;math.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]) {&lt;br /&gt;
    int numthreads;&lt;br /&gt;
    int n;&lt;br /&gt;
&lt;br /&gt;
    assert(argc == 3 &amp;amp;&amp;amp; &amp;quot;args: numthreads n&amp;quot;);&lt;br /&gt;
    sscanf(argv[1], &amp;quot;%d&amp;quot;, &amp;amp;numthreads);&lt;br /&gt;
    sscanf(argv[2], &amp;quot;%d&amp;quot;, &amp;amp;n);&lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;Init...\n&amp;quot;);&lt;br /&gt;
    printf(&amp;quot;Start (%d threads)...\n&amp;quot;, numthreads);&lt;br /&gt;
    printf(&amp;quot;%d test cases\n&amp;quot;, n);&lt;br /&gt;
&lt;br /&gt;
    int m = 1000000;&lt;br /&gt;
    double ttime = omp_get_wtime();&lt;br /&gt;
&lt;br /&gt;
    int i;&lt;br /&gt;
    double d = 0;&lt;br /&gt;
#pragma offload target(mic:0)&lt;br /&gt;
    {&lt;br /&gt;
#pragma omp parallel for private (i) schedule(static) num_threads(numthreads)&lt;br /&gt;
        for(i = 0; i &amp;lt; n; ++i) {&lt;br /&gt;
            for(int j = 0; j &amp;lt; m; ++j) {&lt;br /&gt;
                d = sin(d) + 0.1 + j;&lt;br /&gt;
                d = pow(0.2, d)*j;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    double time = omp_get_wtime() - ttime;&lt;br /&gt;
    fprintf(stderr, &amp;quot;%d %d %.6f\n&amp;quot;, n, numthreads, time);&lt;br /&gt;
    printf(&amp;quot;time: %.6f s\n&amp;quot;, time);&lt;br /&gt;
    printf(&amp;quot;Done d = %.6lf.\n&amp;quot;, d);&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code essentially distributes a problem of size $n\cdot m$ among &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;numthreads&amp;lt;/syntaxhighlight&amp;gt; cores,&lt;br /&gt;
We tested the time of execution for $n$ from the set $\{1, 10, 20, 50, 100, 200, 500, 1000\}$&lt;br /&gt;
and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; numthreads &amp;lt;/syntaxhighlight&amp;gt; from $1$ to $350$. The plots of exectuion times and performance speeups are shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;figure id=&amp;quot;times&amp;quot;&amp;gt;&lt;br /&gt;
[[File:times.png|thumb|center|upright=3|alt=A square of nodes coloured according to the solution(with smaller and larger node density)|&amp;lt;caption&amp;gt;A picture of our solution (with smaller and larger node density)&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;figure id=&amp;quot;fig:speedups&amp;quot;&amp;gt;&lt;br /&gt;
[[File:speedups.png|thumb|center|upright=3|alt=A square of nodes coloured according to the solution(with smaller and larger node density)|&amp;lt;caption&amp;gt;A picture of our solution (with smaller and larger node density)&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The code was compiled using: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; icc -openmp -O3 -qopt-report=2 -qopt-report-phase=vec -o test test.cpp&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
without warnings or errors. Then, in order to offload to Intel Phi, user must be logged in as root: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo su &amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
To run correctly, intel compiler and runtime variables must be sourced: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; source /opt/intel/bin/compilervars.sh intel64&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
Finally, the code was tested using the following command, where &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; test &amp;lt;/syntaxhighlight&amp;gt; is the name of the compiled executable: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; for n in 1 10 20 50 100 200 500 1000; do for nt in {1..350}; echo $nt $n; ./test $nt $n 2&amp;gt;&amp;gt; speedups.txt; done; done&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Speedup by vectorization ==&lt;br /&gt;
&lt;br /&gt;
Intel Xeon Phi has a 512 bit of space for simultaneous computation, which means it can calculate 8 double (or 16 single) operations at the same time. This is called vectorization and greatly improves code execution.&lt;br /&gt;
&lt;br /&gt;
Consider the following code of speedtest.cpp:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
    const int N = 104;&lt;br /&gt;
    double a[N];&lt;br /&gt;
    for (int i = 0; i &amp;lt; 1e5; i++)&lt;br /&gt;
        for (int j = 0; j &amp;lt; N; j++)&lt;br /&gt;
            a[j] = std::sin(std::exp(a[j]-j)*3 * i + i*j);&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; a[4] &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Intel's C++ compiler ICPC will successfully vectorize the inner for loop, so that it will run significantly faster than with vectorization disabled.&lt;br /&gt;
&lt;br /&gt;
The code can be compiled with or without vectorization&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ icpc speedtest.cpp -o vectorized_speedtest -O3&lt;br /&gt;
$ icpc speedtest.cpp -o unvectorized_speedtest -O3 -no-vec&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The below table shows execution times of the code displayed before on different machines with different settings. Two times represent execution time with double and float data type, respectively.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Machine&lt;br /&gt;
| ASUS ZenBook Pro UX501VW&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
|-&lt;br /&gt;
! Compiler&lt;br /&gt;
| g++-6.3.1&lt;br /&gt;
| g++-4.8.5&lt;br /&gt;
| icpc-16.0.1&lt;br /&gt;
| icpc-16.0.1 -no-vec&lt;br /&gt;
| icpc-16.0.1 -mmic&lt;br /&gt;
| icpc-16.0.1 -mmic -no-vec&lt;br /&gt;
|-&lt;br /&gt;
! Double time[s]&lt;br /&gt;
| 0.63 - 0.66&lt;br /&gt;
| 0.65 - 0.66&lt;br /&gt;
| 0.155 - 0.160&lt;br /&gt;
| 0.50 - 0.51&lt;br /&gt;
| 0.25 - 0.26&lt;br /&gt;
| 11.1 - 11.2&lt;br /&gt;
|-&lt;br /&gt;
! Float time[s]&lt;br /&gt;
| 0.65 - 0.71&lt;br /&gt;
| 0.53 - 0.55&lt;br /&gt;
| 0.155 - 0.160&lt;br /&gt;
| 0.17 - 0.19&lt;br /&gt;
| 0.37 - 0.38&lt;br /&gt;
| 4.2 - 4.3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
We can see massive 44 fold speedup with and without vectorization.&lt;br /&gt;
&lt;br /&gt;
=== Code incapable of vectorization ===&lt;br /&gt;
&lt;br /&gt;
On the other hand there is a very similar code that can not be vectorized. Now all iterations of the inner loop access the same variable instead of each its own element in a list. ICPC is now unable to vectorize the code resulting in no difference when using -no-vec compile flag.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
    const int N = 104;&lt;br /&gt;
    double a;&lt;br /&gt;
    for (int i = 0; i &amp;lt; 1e5; i++)&lt;br /&gt;
        for (int j = 0; j &amp;lt; N; j++)&lt;br /&gt;
            a = std::sin(std::exp(a-j)*3 * i + i*j);&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Machine&lt;br /&gt;
| ASUS ZenBook Pro UX501VW&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
|-&lt;br /&gt;
! Compiler&lt;br /&gt;
| g++-6.3.1&lt;br /&gt;
| g++-4.8.5&lt;br /&gt;
| icpc-16.0.1&lt;br /&gt;
| icpc-16.0.1 -no-vec&lt;br /&gt;
| icpc-16.0.1 -mmic&lt;br /&gt;
| icpc-16.0.1 -mmic -no-vec&lt;br /&gt;
|-&lt;br /&gt;
! Double time[s]&lt;br /&gt;
| 0.80 - 0.82&lt;br /&gt;
| 0.72 - 0.73&lt;br /&gt;
| 0.58 - 0.59&lt;br /&gt;
| 0.58 - 0.59&lt;br /&gt;
| 10.9 - 11.0&lt;br /&gt;
| 10.9 - 11.0&lt;br /&gt;
|-&lt;br /&gt;
! Float time[s]&lt;br /&gt;
| 0.69 - 0.72&lt;br /&gt;
| 0.66 - 0.67&lt;br /&gt;
| 0.32 - 0.33&lt;br /&gt;
| 0.32 - 0.34&lt;br /&gt;
| 4.1 - 4.2&lt;br /&gt;
| 4.1 - 4.2&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Speedup by vectorization and parallelization ==&lt;br /&gt;
&lt;br /&gt;
Consider the following code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
int main(){&lt;br /&gt;
    double *a, *b, *c;&lt;br /&gt;
    int i,j,k, ok, n=1000;  // or n=10000&lt;br /&gt;
    // allocated memory on the heap aligned to 64 byte boundary&lt;br /&gt;
    ok = posix_memalign((void**)&amp;amp;a, 64, n*n*sizeof(double));&lt;br /&gt;
    ok = posix_memalign((void**)&amp;amp;b, 64, n*n*sizeof(double));&lt;br /&gt;
    ok = posix_memalign((void**)&amp;amp;c, 64, n*n*sizeof(double));&lt;br /&gt;
    // initialize matrices&lt;br /&gt;
    for (i = 0; i &amp;lt; n*n; ++i) {&lt;br /&gt;
        a[i] = 1;&lt;br /&gt;
        b[i] = 1;&lt;br /&gt;
        c[i] = 1;&lt;br /&gt;
    }&lt;br /&gt;
    //parallelize via OpenMP on MIC&lt;br /&gt;
    #pragma omp parallel for&lt;br /&gt;
    for( i = 0; i &amp;lt; n; i++ ) {&lt;br /&gt;
        for( k = 0; k &amp;lt; n; k++ ) {&lt;br /&gt;
            #pragma vector aligned&lt;br /&gt;
            #pragma ivdep&lt;br /&gt;
            for( j = 0; j &amp;lt; n; j++ ) {&lt;br /&gt;
                //c[i][j] = c[i][j] + a[i][k]*b[k][j];&lt;br /&gt;
                c[i*n+j] = c[i*n+j] + a[i*n+k]*b[k*n+j];&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    printf(&amp;quot;%f\n&amp;quot;, c[n]);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:vec_novec_timed.png|800px]]&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=File:Vec_novec_timed.png&amp;diff=1030</id>
		<title>File:Vec novec timed.png</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=File:Vec_novec_timed.png&amp;diff=1030"/>
				<updated>2017-03-28T09:35:13Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: File uploaded with MsUpload&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;File uploaded with MsUpload&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=How_to_build&amp;diff=892</id>
		<title>How to build</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=How_to_build&amp;diff=892"/>
				<updated>2017-03-09T12:16:08Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Intel C/C++ Compiler */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Installation=&lt;br /&gt;
To make this work from plain Ubuntu installation, run&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install cmake doxygen graphviz libboost-dev libsfml-dev libhdf5-serial-dev&lt;br /&gt;
git clone https://gitlab.com/e62Lab/e62numcodes.git&lt;br /&gt;
cd e62numcodes&lt;br /&gt;
./run_tests.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
which installs dependancies, clones the repository, goes into the root folder of the repository and runs tests. This will check the configuration, notify you of potentially missing dependencies, build and run all tests, check code style and docs. If this works, you are ready to go! Otherwise install any missing packages and if it still fails, raise an issue!&lt;br /&gt;
&lt;br /&gt;
=Building=&lt;br /&gt;
&lt;br /&gt;
List of dependencies:&lt;br /&gt;
&lt;br /&gt;
* Build tools, like &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;gt;= 2.8.12&amp;lt;/syntaxhighlight&amp;gt;, &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; g++ &amp;gt;= 4.8&amp;lt;/syntaxhighlight&amp;gt;, &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;make&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* [http://www.boost.org/ Boost]&lt;br /&gt;
* &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; doxygen &amp;gt;=  1.8.8 &amp;lt;/syntaxhighlight&amp;gt; and Graphviz&lt;br /&gt;
* for drawing [http://www.sfml-dev.org/ SMFL library version 2]&lt;br /&gt;
* for IO [https://www.hdfgroup.org/ HDF5 library]&lt;br /&gt;
&lt;br /&gt;
Out of source builds are preferred. Run&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir -p build&lt;br /&gt;
cd build&lt;br /&gt;
cmake ..&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Note that you only have to run &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;lt;/syntaxhighlight&amp;gt; once, after that only &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&amp;lt;/syntaxhighlight&amp;gt; is sufficient.&lt;br /&gt;
&lt;br /&gt;
Binaries are placed into &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; bin &amp;lt;/syntaxhighlight&amp;gt; folder. Test can be run all at once via &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&lt;br /&gt;
run_all_tests &amp;lt;/syntaxhighlight&amp;gt; or individually via eg. &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;make basisfunc_run_tests &amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Linear Algebra==&lt;br /&gt;
We use [http://eigen.tuxfamily.org/ Eigen] as our matrix library. See&lt;br /&gt;
[http://eigen.tuxfamily.org/dox-devel/group__QuickRefPage.html here] for use&lt;br /&gt;
reference and documentation. For a quick transition from Matlab see&lt;br /&gt;
[http://eigen.tuxfamily.org/dox/AsciiQuickReference.txt here].&lt;br /&gt;
&lt;br /&gt;
==Drawing==&lt;br /&gt;
Some tests include drawing. We are using [http://www.sfml-dev.org/ SMFL library], which can be installed on most linux systems easly&lt;br /&gt;
as &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo apt-get install libsfml-dev &amp;lt;/syntaxhighlight&amp;gt; or &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo pacman -S sfml &amp;lt;/syntaxhighlight&amp;gt;.  After the&lt;br /&gt;
installation uncomment a test case in &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; domain_draw_test.cpp &amp;lt;/syntaxhighlight&amp;gt; and run &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&lt;br /&gt;
test_domain_draw &amp;lt;/syntaxhighlight&amp;gt; to see the visual effect.&lt;br /&gt;
&lt;br /&gt;
Binaries using SFML require additional linker flags &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; -lsfml-graphics&lt;br /&gt;
-lsfml-window -lsfml-system &amp;lt;/syntaxhighlight&amp;gt;, but the makefile should take care of that for you.&lt;br /&gt;
&lt;br /&gt;
==HDF5==&lt;br /&gt;
&lt;br /&gt;
In order to use IO you need [https://www.hdfgroup.org/ hdf5 library].&lt;br /&gt;
You can install it easily using the command &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo apt-get install libhdf5-&lt;br /&gt;
dev &amp;lt;/syntaxhighlight&amp;gt; or &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo pacman -S hdf5-cpp-fortran &amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Ubuntu places hdf5 libs in a werid folder &amp;lt;code&amp;gt;/usr/lib/x86_64-linux-gnu/hdf5/serial/&amp;lt;/code&amp;gt;. &lt;br /&gt;
If you get error similar to &amp;lt;code&amp;gt;-lhdf5 not found&amp;lt;/code&amp;gt; and you have hdf5 installed, you might have to link the libraries into&lt;br /&gt;
a discoverable place, like &amp;lt;code&amp;gt;/usr/lib/&amp;lt;/code&amp;gt; or add the above directory to the linker path.&lt;br /&gt;
If using cmake, you can add the following line to your CMakeLists.txt&lt;br /&gt;
  link_directories(/usr/lib/x86_64-linux-gnu/hdf5/serial/)&lt;br /&gt;
&lt;br /&gt;
== Using Intel Math Kernel Library (MKL) ==&lt;br /&gt;
Eigen has great support for MKL all you have to do is define a EIGEN_USE_MKL_ALL macro before any includes.&lt;br /&gt;
You can see further instructions [https://eigen.tuxfamily.org/dox/TopicUsingIntelMKL.html on their website].&lt;br /&gt;
&lt;br /&gt;
Besides setting &amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; inline&amp;gt;#define EIGEN_USE_MKL_ALL&amp;lt;/syntaxhighlight&amp;gt; in your code,&lt;br /&gt;
some linker and compilation fixes are needed. You have to set MKL and MKLROOT variables in cmake. You can define&lt;br /&gt;
the variable MKLROOT as a system variable (using export) which is enough. You can also define it manually when calling&lt;br /&gt;
cmake. If it is not set in either way it will default to &amp;quot;/opt/intel/compilers_and_libraries_2017.2.174/linux/mkl&amp;quot;.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cmake .. -DMKL=ON -DMKLROOT=/opt/intel/compilers_and_libraries_2016.1.150/linux/mkl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Your target has to be linked with some MKL libraries so make sure to add the following link to your cmake file.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cmake&amp;quot;&amp;gt;&lt;br /&gt;
target_link_libraries(target ${LMKL})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Intel C/C++ Compiler ==&lt;br /&gt;
&lt;br /&gt;
In order to use Intel's compiler you have to first set the &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;CXX&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;CC&amp;lt;/syntaxhighlight&amp;gt; bash variables. Before calling&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;lt;/syntaxhighlight&amp;gt; for the first time you have to export the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export CXX=&amp;quot;icpc&amp;quot;&lt;br /&gt;
export CC=&amp;quot;icc&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or you can define the compiler when first calling cmake like so:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cmake .. -DCMAKE_C_COMPILER=$(which icc) -DCMAKE_CXX_COMPILER=$(which icpc) &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also compile it directly for Intel® Xeon Phi™ Coprocessor. You do this by adding &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;-Dmmic=ON&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
flag to the &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;cmake&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cmake .. -Dmmic=ON -DCMAKE_C_COMPILER=$(which icc) -DCMAKE_CXX_COMPILER=$(which icpc) &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note:&amp;lt;/b&amp;gt; All features that depend on system third-party libraries are not available on MIC (Many Integrated Core).&lt;br /&gt;
This includes:&lt;br /&gt;
&lt;br /&gt;
* [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/technical_docs/html/classmm_1_1HDF5IO.html HDF5IO] class in &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;io.hpp&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/technical_docs/html/classmm_1_1Monitor.html Monitor] class in &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;util.hpp&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* all of [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/technical_docs/html/util_8hpp_source.html  &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;draw.hpp&amp;lt;/syntaxhighlight&amp;gt;]&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=How_to_build&amp;diff=891</id>
		<title>How to build</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=How_to_build&amp;diff=891"/>
				<updated>2017-03-09T12:15:41Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Intel Math Kernel Library (MKL) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Installation=&lt;br /&gt;
To make this work from plain Ubuntu installation, run&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install cmake doxygen graphviz libboost-dev libsfml-dev libhdf5-serial-dev&lt;br /&gt;
git clone https://gitlab.com/e62Lab/e62numcodes.git&lt;br /&gt;
cd e62numcodes&lt;br /&gt;
./run_tests.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
which installs dependancies, clones the repository, goes into the root folder of the repository and runs tests. This will check the configuration, notify you of potentially missing dependencies, build and run all tests, check code style and docs. If this works, you are ready to go! Otherwise install any missing packages and if it still fails, raise an issue!&lt;br /&gt;
&lt;br /&gt;
=Building=&lt;br /&gt;
&lt;br /&gt;
List of dependencies:&lt;br /&gt;
&lt;br /&gt;
* Build tools, like &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;gt;= 2.8.12&amp;lt;/syntaxhighlight&amp;gt;, &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; g++ &amp;gt;= 4.8&amp;lt;/syntaxhighlight&amp;gt;, &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;make&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* [http://www.boost.org/ Boost]&lt;br /&gt;
* &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; doxygen &amp;gt;=  1.8.8 &amp;lt;/syntaxhighlight&amp;gt; and Graphviz&lt;br /&gt;
* for drawing [http://www.sfml-dev.org/ SMFL library version 2]&lt;br /&gt;
* for IO [https://www.hdfgroup.org/ HDF5 library]&lt;br /&gt;
&lt;br /&gt;
Out of source builds are preferred. Run&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir -p build&lt;br /&gt;
cd build&lt;br /&gt;
cmake ..&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Note that you only have to run &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;lt;/syntaxhighlight&amp;gt; once, after that only &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&amp;lt;/syntaxhighlight&amp;gt; is sufficient.&lt;br /&gt;
&lt;br /&gt;
Binaries are placed into &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; bin &amp;lt;/syntaxhighlight&amp;gt; folder. Test can be run all at once via &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&lt;br /&gt;
run_all_tests &amp;lt;/syntaxhighlight&amp;gt; or individually via eg. &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;make basisfunc_run_tests &amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Linear Algebra==&lt;br /&gt;
We use [http://eigen.tuxfamily.org/ Eigen] as our matrix library. See&lt;br /&gt;
[http://eigen.tuxfamily.org/dox-devel/group__QuickRefPage.html here] for use&lt;br /&gt;
reference and documentation. For a quick transition from Matlab see&lt;br /&gt;
[http://eigen.tuxfamily.org/dox/AsciiQuickReference.txt here].&lt;br /&gt;
&lt;br /&gt;
==Drawing==&lt;br /&gt;
Some tests include drawing. We are using [http://www.sfml-dev.org/ SMFL library], which can be installed on most linux systems easly&lt;br /&gt;
as &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo apt-get install libsfml-dev &amp;lt;/syntaxhighlight&amp;gt; or &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo pacman -S sfml &amp;lt;/syntaxhighlight&amp;gt;.  After the&lt;br /&gt;
installation uncomment a test case in &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; domain_draw_test.cpp &amp;lt;/syntaxhighlight&amp;gt; and run &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&lt;br /&gt;
test_domain_draw &amp;lt;/syntaxhighlight&amp;gt; to see the visual effect.&lt;br /&gt;
&lt;br /&gt;
Binaries using SFML require additional linker flags &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; -lsfml-graphics&lt;br /&gt;
-lsfml-window -lsfml-system &amp;lt;/syntaxhighlight&amp;gt;, but the makefile should take care of that for you.&lt;br /&gt;
&lt;br /&gt;
==HDF5==&lt;br /&gt;
&lt;br /&gt;
In order to use IO you need [https://www.hdfgroup.org/ hdf5 library].&lt;br /&gt;
You can install it easily using the command &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo apt-get install libhdf5-&lt;br /&gt;
dev &amp;lt;/syntaxhighlight&amp;gt; or &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo pacman -S hdf5-cpp-fortran &amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Ubuntu places hdf5 libs in a werid folder &amp;lt;code&amp;gt;/usr/lib/x86_64-linux-gnu/hdf5/serial/&amp;lt;/code&amp;gt;. &lt;br /&gt;
If you get error similar to &amp;lt;code&amp;gt;-lhdf5 not found&amp;lt;/code&amp;gt; and you have hdf5 installed, you might have to link the libraries into&lt;br /&gt;
a discoverable place, like &amp;lt;code&amp;gt;/usr/lib/&amp;lt;/code&amp;gt; or add the above directory to the linker path.&lt;br /&gt;
If using cmake, you can add the following line to your CMakeLists.txt&lt;br /&gt;
  link_directories(/usr/lib/x86_64-linux-gnu/hdf5/serial/)&lt;br /&gt;
&lt;br /&gt;
== Using Intel Math Kernel Library (MKL) ==&lt;br /&gt;
Eigen has great support for MKL all you have to do is define a EIGEN_USE_MKL_ALL macro before any includes.&lt;br /&gt;
You can see further instructions [https://eigen.tuxfamily.org/dox/TopicUsingIntelMKL.html on their website].&lt;br /&gt;
&lt;br /&gt;
Besides setting &amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; inline&amp;gt;#define EIGEN_USE_MKL_ALL&amp;lt;/syntaxhighlight&amp;gt; in your code,&lt;br /&gt;
some linker and compilation fixes are needed. You have to set MKL and MKLROOT variables in cmake. You can define&lt;br /&gt;
the variable MKLROOT as a system variable (using export) which is enough. You can also define it manually when calling&lt;br /&gt;
cmake. If it is not set in either way it will default to &amp;quot;/opt/intel/compilers_and_libraries_2017.2.174/linux/mkl&amp;quot;.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cmake .. -DMKL=ON -DMKLROOT=/opt/intel/compilers_and_libraries_2016.1.150/linux/mkl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Your target has to be linked with some MKL libraries so make sure to add the following link to your cmake file.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cmake&amp;quot;&amp;gt;&lt;br /&gt;
target_link_libraries(target ${LMKL})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Intel C/C++ Compiler==&lt;br /&gt;
&lt;br /&gt;
In order to use Intel's compiler you have to first set the &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;CXX&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;CC&amp;lt;/syntaxhighlight&amp;gt; bash variables. Before calling&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;lt;/syntaxhighlight&amp;gt; for the first time you have to export the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export CXX=&amp;quot;icpc&amp;quot;&lt;br /&gt;
export CC=&amp;quot;icc&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or you can define the compiler when first calling cmake like so:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cmake .. -DCMAKE_C_COMPILER=$(which icc) -DCMAKE_CXX_COMPILER=$(which icpc) &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also compile it directly for Intel® Xeon Phi™ Coprocessor. You do this by adding &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;-Dmmic=ON&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
flag to the &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;cmake&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cmake .. -Dmmic=ON -DCMAKE_C_COMPILER=$(which icc) -DCMAKE_CXX_COMPILER=$(which icpc) &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note:&amp;lt;/b&amp;gt; All features that depend on system third-party libraries are not available on MIC (Many Integrated Core).&lt;br /&gt;
This includes:&lt;br /&gt;
&lt;br /&gt;
* [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/technical_docs/html/classmm_1_1HDF5IO.html HDF5IO] class in &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;io.hpp&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/technical_docs/html/classmm_1_1Monitor.html Monitor] class in &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;util.hpp&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* all of [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/technical_docs/html/util_8hpp_source.html  &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;draw.hpp&amp;lt;/syntaxhighlight&amp;gt;]&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=How_to_build&amp;diff=890</id>
		<title>How to build</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=How_to_build&amp;diff=890"/>
				<updated>2017-03-09T12:13:06Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Intel */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Installation=&lt;br /&gt;
To make this work from plain Ubuntu installation, run&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install cmake doxygen graphviz libboost-dev libsfml-dev libhdf5-serial-dev&lt;br /&gt;
git clone https://gitlab.com/e62Lab/e62numcodes.git&lt;br /&gt;
cd e62numcodes&lt;br /&gt;
./run_tests.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
which installs dependancies, clones the repository, goes into the root folder of the repository and runs tests. This will check the configuration, notify you of potentially missing dependencies, build and run all tests, check code style and docs. If this works, you are ready to go! Otherwise install any missing packages and if it still fails, raise an issue!&lt;br /&gt;
&lt;br /&gt;
=Building=&lt;br /&gt;
&lt;br /&gt;
List of dependencies:&lt;br /&gt;
&lt;br /&gt;
* Build tools, like &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;gt;= 2.8.12&amp;lt;/syntaxhighlight&amp;gt;, &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; g++ &amp;gt;= 4.8&amp;lt;/syntaxhighlight&amp;gt;, &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;make&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* [http://www.boost.org/ Boost]&lt;br /&gt;
* &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; doxygen &amp;gt;=  1.8.8 &amp;lt;/syntaxhighlight&amp;gt; and Graphviz&lt;br /&gt;
* for drawing [http://www.sfml-dev.org/ SMFL library version 2]&lt;br /&gt;
* for IO [https://www.hdfgroup.org/ HDF5 library]&lt;br /&gt;
&lt;br /&gt;
Out of source builds are preferred. Run&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir -p build&lt;br /&gt;
cd build&lt;br /&gt;
cmake ..&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Note that you only have to run &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;lt;/syntaxhighlight&amp;gt; once, after that only &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&amp;lt;/syntaxhighlight&amp;gt; is sufficient.&lt;br /&gt;
&lt;br /&gt;
Binaries are placed into &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; bin &amp;lt;/syntaxhighlight&amp;gt; folder. Test can be run all at once via &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&lt;br /&gt;
run_all_tests &amp;lt;/syntaxhighlight&amp;gt; or individually via eg. &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;make basisfunc_run_tests &amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Linear Algebra==&lt;br /&gt;
We use [http://eigen.tuxfamily.org/ Eigen] as our matrix library. See&lt;br /&gt;
[http://eigen.tuxfamily.org/dox-devel/group__QuickRefPage.html here] for use&lt;br /&gt;
reference and documentation. For a quick transition from Matlab see&lt;br /&gt;
[http://eigen.tuxfamily.org/dox/AsciiQuickReference.txt here].&lt;br /&gt;
&lt;br /&gt;
==Drawing==&lt;br /&gt;
Some tests include drawing. We are using [http://www.sfml-dev.org/ SMFL library], which can be installed on most linux systems easly&lt;br /&gt;
as &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo apt-get install libsfml-dev &amp;lt;/syntaxhighlight&amp;gt; or &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo pacman -S sfml &amp;lt;/syntaxhighlight&amp;gt;.  After the&lt;br /&gt;
installation uncomment a test case in &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; domain_draw_test.cpp &amp;lt;/syntaxhighlight&amp;gt; and run &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&lt;br /&gt;
test_domain_draw &amp;lt;/syntaxhighlight&amp;gt; to see the visual effect.&lt;br /&gt;
&lt;br /&gt;
Binaries using SFML require additional linker flags &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; -lsfml-graphics&lt;br /&gt;
-lsfml-window -lsfml-system &amp;lt;/syntaxhighlight&amp;gt;, but the makefile should take care of that for you.&lt;br /&gt;
&lt;br /&gt;
==HDF5==&lt;br /&gt;
&lt;br /&gt;
In order to use IO you need [https://www.hdfgroup.org/ hdf5 library].&lt;br /&gt;
You can install it easily using the command &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo apt-get install libhdf5-&lt;br /&gt;
dev &amp;lt;/syntaxhighlight&amp;gt; or &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo pacman -S hdf5-cpp-fortran &amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Ubuntu places hdf5 libs in a werid folder &amp;lt;code&amp;gt;/usr/lib/x86_64-linux-gnu/hdf5/serial/&amp;lt;/code&amp;gt;. &lt;br /&gt;
If you get error similar to &amp;lt;code&amp;gt;-lhdf5 not found&amp;lt;/code&amp;gt; and you have hdf5 installed, you might have to link the libraries into&lt;br /&gt;
a discoverable place, like &amp;lt;code&amp;gt;/usr/lib/&amp;lt;/code&amp;gt; or add the above directory to the linker path.&lt;br /&gt;
If using cmake, you can add the following line to your CMakeLists.txt&lt;br /&gt;
  link_directories(/usr/lib/x86_64-linux-gnu/hdf5/serial/)&lt;br /&gt;
&lt;br /&gt;
== Intel Math Kernel Library (MKL) ==&lt;br /&gt;
Eigen has great support for MKL all you have to do is define a EIGEN_USE_MKL_ALL macro before any includes.&lt;br /&gt;
You can see further instructions [https://eigen.tuxfamily.org/dox/TopicUsingIntelMKL.html on their website].&lt;br /&gt;
&lt;br /&gt;
Besides setting &amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; inline&amp;gt;#define EIGEN_USE_MKL_ALL&amp;lt;/syntaxhighlight&amp;gt; in your code,&lt;br /&gt;
some linker and compilation fixes are needed. You have to set MKL and MKLROOT variables in cmake. You can define&lt;br /&gt;
the variable MKLROOT as a system variable (using export) which is enough. You can also define it manually when calling&lt;br /&gt;
cmake. If it is not set in either way it will default to &amp;quot;/opt/intel/compilers_and_libraries_2017.2.174/linux/mkl&amp;quot;.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cmake .. -DMKL=ON -DMKLROOT=/opt/intel/compilers_and_libraries_2016.1.150/linux/mkl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Your target has to be linked with some MKL libraries so make sure to add the following link to your cmake file.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cmake&amp;quot;&amp;gt;&lt;br /&gt;
target_link_libraries(target ${LMKL})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Intel C/C++ Compiler==&lt;br /&gt;
&lt;br /&gt;
In order to use Intel's compiler you have to first set the &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;CXX&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;CC&amp;lt;/syntaxhighlight&amp;gt; bash variables. Before calling&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;lt;/syntaxhighlight&amp;gt; for the first time you have to export the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export CXX=&amp;quot;icpc&amp;quot;&lt;br /&gt;
export CC=&amp;quot;icc&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or you can define the compiler when first calling cmake like so:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cmake .. -DCMAKE_C_COMPILER=$(which icc) -DCMAKE_CXX_COMPILER=$(which icpc) &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also compile it directly for Intel® Xeon Phi™ Coprocessor. You do this by adding &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;-Dmmic=ON&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
flag to the &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;cmake&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cmake .. -Dmmic=ON -DCMAKE_C_COMPILER=$(which icc) -DCMAKE_CXX_COMPILER=$(which icpc) &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note:&amp;lt;/b&amp;gt; All features that depend on system third-party libraries are not available on MIC (Many Integrated Core).&lt;br /&gt;
This includes:&lt;br /&gt;
&lt;br /&gt;
* [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/technical_docs/html/classmm_1_1HDF5IO.html HDF5IO] class in &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;io.hpp&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/technical_docs/html/classmm_1_1Monitor.html Monitor] class in &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;util.hpp&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* all of [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/technical_docs/html/util_8hpp_source.html  &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;draw.hpp&amp;lt;/syntaxhighlight&amp;gt;]&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=How_to_build&amp;diff=889</id>
		<title>How to build</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=How_to_build&amp;diff=889"/>
				<updated>2017-03-09T10:27:19Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Intel */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Installation=&lt;br /&gt;
To make this work from plain Ubuntu installation, run&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install cmake doxygen graphviz libboost-dev libsfml-dev libhdf5-serial-dev&lt;br /&gt;
git clone https://gitlab.com/e62Lab/e62numcodes.git&lt;br /&gt;
cd e62numcodes&lt;br /&gt;
./run_tests.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
which installs dependancies, clones the repository, goes into the root folder of the repository and runs tests. This will check the configuration, notify you of potentially missing dependencies, build and run all tests, check code style and docs. If this works, you are ready to go! Otherwise install any missing packages and if it still fails, raise an issue!&lt;br /&gt;
&lt;br /&gt;
=Building=&lt;br /&gt;
&lt;br /&gt;
List of dependencies:&lt;br /&gt;
&lt;br /&gt;
* Build tools, like &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;gt;= 2.8.12&amp;lt;/syntaxhighlight&amp;gt;, &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; g++ &amp;gt;= 4.8&amp;lt;/syntaxhighlight&amp;gt;, &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;make&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* [http://www.boost.org/ Boost]&lt;br /&gt;
* &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; doxygen &amp;gt;=  1.8.8 &amp;lt;/syntaxhighlight&amp;gt; and Graphviz&lt;br /&gt;
* for drawing [http://www.sfml-dev.org/ SMFL library version 2]&lt;br /&gt;
* for IO [https://www.hdfgroup.org/ HDF5 library]&lt;br /&gt;
&lt;br /&gt;
Out of source builds are preferred. Run&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir -p build&lt;br /&gt;
cd build&lt;br /&gt;
cmake ..&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Note that you only have to run &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;lt;/syntaxhighlight&amp;gt; once, after that only &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&amp;lt;/syntaxhighlight&amp;gt; is sufficient.&lt;br /&gt;
&lt;br /&gt;
Binaries are placed into &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; bin &amp;lt;/syntaxhighlight&amp;gt; folder. Test can be run all at once via &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&lt;br /&gt;
run_all_tests &amp;lt;/syntaxhighlight&amp;gt; or individually via eg. &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;make basisfunc_run_tests &amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Linear Algebra==&lt;br /&gt;
We use [http://eigen.tuxfamily.org/ Eigen] as our matrix library. See&lt;br /&gt;
[http://eigen.tuxfamily.org/dox-devel/group__QuickRefPage.html here] for use&lt;br /&gt;
reference and documentation. For a quick transition from Matlab see&lt;br /&gt;
[http://eigen.tuxfamily.org/dox/AsciiQuickReference.txt here].&lt;br /&gt;
&lt;br /&gt;
==Drawing==&lt;br /&gt;
Some tests include drawing. We are using [http://www.sfml-dev.org/ SMFL library], which can be installed on most linux systems easly&lt;br /&gt;
as &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo apt-get install libsfml-dev &amp;lt;/syntaxhighlight&amp;gt; or &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo pacman -S sfml &amp;lt;/syntaxhighlight&amp;gt;.  After the&lt;br /&gt;
installation uncomment a test case in &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; domain_draw_test.cpp &amp;lt;/syntaxhighlight&amp;gt; and run &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&lt;br /&gt;
test_domain_draw &amp;lt;/syntaxhighlight&amp;gt; to see the visual effect.&lt;br /&gt;
&lt;br /&gt;
Binaries using SFML require additional linker flags &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; -lsfml-graphics&lt;br /&gt;
-lsfml-window -lsfml-system &amp;lt;/syntaxhighlight&amp;gt;, but the makefile should take care of that for you.&lt;br /&gt;
&lt;br /&gt;
==HDF5==&lt;br /&gt;
&lt;br /&gt;
In order to use IO you need [https://www.hdfgroup.org/ hdf5 library].&lt;br /&gt;
You can install it easily using the command &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo apt-get install libhdf5-&lt;br /&gt;
dev &amp;lt;/syntaxhighlight&amp;gt; or &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo pacman -S hdf5-cpp-fortran &amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Ubuntu places hdf5 libs in a werid folder &amp;lt;code&amp;gt;/usr/lib/x86_64-linux-gnu/hdf5/serial/&amp;lt;/code&amp;gt;. &lt;br /&gt;
If you get error similar to &amp;lt;code&amp;gt;-lhdf5 not found&amp;lt;/code&amp;gt; and you have hdf5 installed, you might have to link the libraries into&lt;br /&gt;
a discoverable place, like &amp;lt;code&amp;gt;/usr/lib/&amp;lt;/code&amp;gt; or add the above directory to the linker path.&lt;br /&gt;
If using cmake, you can add the following line to your CMakeLists.txt&lt;br /&gt;
  link_directories(/usr/lib/x86_64-linux-gnu/hdf5/serial/)&lt;br /&gt;
&lt;br /&gt;
==Intel==&lt;br /&gt;
&lt;br /&gt;
In order to use Intel's compiler you have to first set the &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;CXX&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;CC&amp;lt;/syntaxhighlight&amp;gt; bash variables. Before calling&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;lt;/syntaxhighlight&amp;gt; for the first time you have to export the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export CXX=&amp;quot;icpc&amp;quot;&lt;br /&gt;
export CC=&amp;quot;icc&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or you can define the compiler when first calling cmake like so:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cmake .. -DCMAKE_C_COMPILER=$(which icc) -DCMAKE_CXX_COMPILER=$(which icpc) &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also compile it directly for Intel® Xeon Phi™ Coprocessor. You do this by adding &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;-Dmmic=ON&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
flag to the &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;cmake&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cmake .. -Dmmic=ON -DCMAKE_C_COMPILER=$(which icc) -DCMAKE_CXX_COMPILER=$(which icpc) &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note:&amp;lt;/b&amp;gt; All features that depend on system third-party libraries are not available on MIC (Many Integrated Core).&lt;br /&gt;
This includes:&lt;br /&gt;
&lt;br /&gt;
* [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/technical_docs/html/classmm_1_1HDF5IO.html HDF5IO] class in &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;io.hpp&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/technical_docs/html/classmm_1_1Monitor.html Monitor] class in &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;util.hpp&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* all of [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/technical_docs/html/util_8hpp_source.html  &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;draw.hpp&amp;lt;/syntaxhighlight&amp;gt;]&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Execution_on_Intel%C2%AE_Xeon_Phi%E2%84%A2_co-processor&amp;diff=880</id>
		<title>Execution on Intel® Xeon Phi™ co-processor</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Execution_on_Intel%C2%AE_Xeon_Phi%E2%84%A2_co-processor&amp;diff=880"/>
				<updated>2017-03-01T17:41:24Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Speedup by vectorization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Speedup by parallelization ==&lt;br /&gt;
&lt;br /&gt;
We tested the speedups on the Intel® Xeon Phi™ with the following code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;assert.h&amp;gt;&lt;br /&gt;
#include &amp;lt;omp.h&amp;gt;&lt;br /&gt;
#include &amp;lt;math.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]) {&lt;br /&gt;
    int numthreads;&lt;br /&gt;
    int n;&lt;br /&gt;
&lt;br /&gt;
    assert(argc == 3 &amp;amp;&amp;amp; &amp;quot;args: numthreads n&amp;quot;);&lt;br /&gt;
    sscanf(argv[1], &amp;quot;%d&amp;quot;, &amp;amp;numthreads);&lt;br /&gt;
    sscanf(argv[2], &amp;quot;%d&amp;quot;, &amp;amp;n);&lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;Init...\n&amp;quot;);&lt;br /&gt;
    printf(&amp;quot;Start (%d threads)...\n&amp;quot;, numthreads);&lt;br /&gt;
    printf(&amp;quot;%d test cases\n&amp;quot;, n);&lt;br /&gt;
&lt;br /&gt;
    int m = 1000000;&lt;br /&gt;
    double ttime = omp_get_wtime();&lt;br /&gt;
&lt;br /&gt;
    int i;&lt;br /&gt;
    double d = 0;&lt;br /&gt;
#pragma offload target(mic:0)&lt;br /&gt;
    {&lt;br /&gt;
#pragma omp parallel for private (i) schedule(static) num_threads(numthreads)&lt;br /&gt;
        for(i = 0; i &amp;lt; n; ++i) {&lt;br /&gt;
            for(int j = 0; j &amp;lt; m; ++j) {&lt;br /&gt;
                d = sin(d) + 0.1 + j;&lt;br /&gt;
                d = pow(0.2, d)*j;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    double time = omp_get_wtime() - ttime;&lt;br /&gt;
    fprintf(stderr, &amp;quot;%d %d %.6f\n&amp;quot;, n, numthreads, time);&lt;br /&gt;
    printf(&amp;quot;time: %.6f s\n&amp;quot;, time);&lt;br /&gt;
    printf(&amp;quot;Done d = %.6lf.\n&amp;quot;, d);&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code essentially distributes a problem of size $n\cdot m$ among &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;numthreads&amp;lt;/syntaxhighlight&amp;gt; cores,&lt;br /&gt;
We tested the time of execution for $n$ from the set $\{1, 10, 20, 50, 100, 200, 500, 1000\}$&lt;br /&gt;
and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; numthreads &amp;lt;/syntaxhighlight&amp;gt; from $1$ to $350$. The plots of exectuion times and performance speeups are shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;figure id=&amp;quot;times&amp;quot;&amp;gt;&lt;br /&gt;
[[File:times.png|thumb|center|upright=3|alt=A square of nodes coloured according to the solution(with smaller and larger node density)|&amp;lt;caption&amp;gt;A picture of our solution (with smaller and larger node density)&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;figure id=&amp;quot;fig:speedups&amp;quot;&amp;gt;&lt;br /&gt;
[[File:speedups.png|thumb|center|upright=3|alt=A square of nodes coloured according to the solution(with smaller and larger node density)|&amp;lt;caption&amp;gt;A picture of our solution (with smaller and larger node density)&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The code was compiled using: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; icc -openmp -O3 -qopt-report=2 -qopt-report-phase=vec -o test test.cpp&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
without warnings or errors. Then, in order to offload to Intel Phi, user must be logged in as root: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo su &amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
To run correctly, intel compiler and runtime variables must be sourced: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; source /opt/intel/bin/compilervars.sh intel64&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
Finally, the code was tested using the following command, where &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; test &amp;lt;/syntaxhighlight&amp;gt; is the name of the compiled executable: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; for n in 1 10 20 50 100 200 500 1000; do for nt in {1..350}; echo $nt $n; ./test $nt $n 2&amp;gt;&amp;gt; speedups.txt; done; done&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Speedup by vectorization ==&lt;br /&gt;
&lt;br /&gt;
Intel Xeon Phi has a 512 bit of space for simultaneous computation, which means it can calculate 8 double (or 16 single) operations at the same time. This is called vectorization and greatly improves code execution.&lt;br /&gt;
&lt;br /&gt;
Consider the following code of speedtest.cpp:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
    const int N = 104;&lt;br /&gt;
    double a[N];&lt;br /&gt;
    for (int i = 0; i &amp;lt; 1e5; i++)&lt;br /&gt;
        for (int j = 0; j &amp;lt; N; j++)&lt;br /&gt;
            a[j] = std::sin(std::exp(a[j]-j)*3 * i + i*j);&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; a[4] &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Intel's C++ compiler ICPC will successfully vectorize the inner for loop, so that it will run significantly faster than with vectorization disabled.&lt;br /&gt;
&lt;br /&gt;
The code can be compiled with or without vectorization&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ icpc speedtest.cpp -o vectorized_speedtest -O3&lt;br /&gt;
$ icpc speedtest.cpp -o unvectorized_speedtest -O3 -no-vec&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The below table shows execution times of the code displayed before on different machines with different settings. Two times represent execution time with double and float data type, respectively.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Machine&lt;br /&gt;
| ASUS ZenBook Pro UX501VW&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
|-&lt;br /&gt;
! Compiler&lt;br /&gt;
| g++-6.3.1&lt;br /&gt;
| g++-4.8.5&lt;br /&gt;
| icpc-16.0.1&lt;br /&gt;
| icpc-16.0.1 -no-vec&lt;br /&gt;
| icpc-16.0.1 -mmic&lt;br /&gt;
| icpc-16.0.1 -mmic -no-vec&lt;br /&gt;
|-&lt;br /&gt;
! Double time[s]&lt;br /&gt;
| 0.63 - 0.66&lt;br /&gt;
| 0.65 - 0.66&lt;br /&gt;
| 0.155 - 0.160&lt;br /&gt;
| 0.50 - 0.51&lt;br /&gt;
| 0.25 - 0.26&lt;br /&gt;
| 11.1 - 11.2&lt;br /&gt;
|-&lt;br /&gt;
! Float time[s]&lt;br /&gt;
| 0.65 - 0.71&lt;br /&gt;
| 0.53 - 0.55&lt;br /&gt;
| 0.155 - 0.160&lt;br /&gt;
| 0.17 - 0.19&lt;br /&gt;
| 0.37 - 0.38&lt;br /&gt;
| 4.2 - 4.3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
We can see massive 44 fold speedup with and without vectorization.&lt;br /&gt;
&lt;br /&gt;
=== Code incapable of vectorization ===&lt;br /&gt;
&lt;br /&gt;
On the other hand there is a very similar code that can not be vectorized. Now all iterations of the inner loop access the same variable instead of each its own element in a list. ICPC is now unable to vectorize the code resulting in no difference when using -no-vec compile flag.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
    const int N = 104;&lt;br /&gt;
    double a;&lt;br /&gt;
    for (int i = 0; i &amp;lt; 1e5; i++)&lt;br /&gt;
        for (int j = 0; j &amp;lt; N; j++)&lt;br /&gt;
            a = std::sin(std::exp(a-j)*3 * i + i*j);&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Machine&lt;br /&gt;
| ASUS ZenBook Pro UX501VW&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
|-&lt;br /&gt;
! Compiler&lt;br /&gt;
| g++-6.3.1&lt;br /&gt;
| g++-4.8.5&lt;br /&gt;
| icpc-16.0.1&lt;br /&gt;
| icpc-16.0.1 -no-vec&lt;br /&gt;
| icpc-16.0.1 -mmic&lt;br /&gt;
| icpc-16.0.1 -mmic -no-vec&lt;br /&gt;
|-&lt;br /&gt;
! Double time[s]&lt;br /&gt;
| 0.80 - 0.82&lt;br /&gt;
| 0.72 - 0.73&lt;br /&gt;
| 0.58 - 0.59&lt;br /&gt;
| 0.58 - 0.59&lt;br /&gt;
| 10.9 - 11.0&lt;br /&gt;
| 10.9 - 11.0&lt;br /&gt;
|-&lt;br /&gt;
! Float time[s]&lt;br /&gt;
| 0.69 - 0.72&lt;br /&gt;
| 0.66 - 0.67&lt;br /&gt;
| 0.32 - 0.33&lt;br /&gt;
| 0.32 - 0.34&lt;br /&gt;
| 4.1 - 4.2&lt;br /&gt;
| 4.1 - 4.2&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Execution_on_Intel%C2%AE_Xeon_Phi%E2%84%A2_co-processor&amp;diff=879</id>
		<title>Execution on Intel® Xeon Phi™ co-processor</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Execution_on_Intel%C2%AE_Xeon_Phi%E2%84%A2_co-processor&amp;diff=879"/>
				<updated>2017-03-01T17:38:44Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Speedup by vectorization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Speedup by parallelization ==&lt;br /&gt;
&lt;br /&gt;
We tested the speedups on the Intel® Xeon Phi™ with the following code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;assert.h&amp;gt;&lt;br /&gt;
#include &amp;lt;omp.h&amp;gt;&lt;br /&gt;
#include &amp;lt;math.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]) {&lt;br /&gt;
    int numthreads;&lt;br /&gt;
    int n;&lt;br /&gt;
&lt;br /&gt;
    assert(argc == 3 &amp;amp;&amp;amp; &amp;quot;args: numthreads n&amp;quot;);&lt;br /&gt;
    sscanf(argv[1], &amp;quot;%d&amp;quot;, &amp;amp;numthreads);&lt;br /&gt;
    sscanf(argv[2], &amp;quot;%d&amp;quot;, &amp;amp;n);&lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;Init...\n&amp;quot;);&lt;br /&gt;
    printf(&amp;quot;Start (%d threads)...\n&amp;quot;, numthreads);&lt;br /&gt;
    printf(&amp;quot;%d test cases\n&amp;quot;, n);&lt;br /&gt;
&lt;br /&gt;
    int m = 1000000;&lt;br /&gt;
    double ttime = omp_get_wtime();&lt;br /&gt;
&lt;br /&gt;
    int i;&lt;br /&gt;
    double d = 0;&lt;br /&gt;
#pragma offload target(mic:0)&lt;br /&gt;
    {&lt;br /&gt;
#pragma omp parallel for private (i) schedule(static) num_threads(numthreads)&lt;br /&gt;
        for(i = 0; i &amp;lt; n; ++i) {&lt;br /&gt;
            for(int j = 0; j &amp;lt; m; ++j) {&lt;br /&gt;
                d = sin(d) + 0.1 + j;&lt;br /&gt;
                d = pow(0.2, d)*j;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    double time = omp_get_wtime() - ttime;&lt;br /&gt;
    fprintf(stderr, &amp;quot;%d %d %.6f\n&amp;quot;, n, numthreads, time);&lt;br /&gt;
    printf(&amp;quot;time: %.6f s\n&amp;quot;, time);&lt;br /&gt;
    printf(&amp;quot;Done d = %.6lf.\n&amp;quot;, d);&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code essentially distributes a problem of size $n\cdot m$ among &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;numthreads&amp;lt;/syntaxhighlight&amp;gt; cores,&lt;br /&gt;
We tested the time of execution for $n$ from the set $\{1, 10, 20, 50, 100, 200, 500, 1000\}$&lt;br /&gt;
and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; numthreads &amp;lt;/syntaxhighlight&amp;gt; from $1$ to $350$. The plots of exectuion times and performance speeups are shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;figure id=&amp;quot;times&amp;quot;&amp;gt;&lt;br /&gt;
[[File:times.png|thumb|center|upright=3|alt=A square of nodes coloured according to the solution(with smaller and larger node density)|&amp;lt;caption&amp;gt;A picture of our solution (with smaller and larger node density)&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;figure id=&amp;quot;fig:speedups&amp;quot;&amp;gt;&lt;br /&gt;
[[File:speedups.png|thumb|center|upright=3|alt=A square of nodes coloured according to the solution(with smaller and larger node density)|&amp;lt;caption&amp;gt;A picture of our solution (with smaller and larger node density)&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The code was compiled using: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; icc -openmp -O3 -qopt-report=2 -qopt-report-phase=vec -o test test.cpp&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
without warnings or errors. Then, in order to offload to Intel Phi, user must be logged in as root: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo su &amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
To run correctly, intel compiler and runtime variables must be sourced: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; source /opt/intel/bin/compilervars.sh intel64&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
Finally, the code was tested using the following command, where &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; test &amp;lt;/syntaxhighlight&amp;gt; is the name of the compiled executable: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; for n in 1 10 20 50 100 200 500 1000; do for nt in {1..350}; echo $nt $n; ./test $nt $n 2&amp;gt;&amp;gt; speedups.txt; done; done&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Speedup by vectorization ==&lt;br /&gt;
&lt;br /&gt;
Intel Xeon Phi has a 512 bit of space for simultaneous computation, which means it can calculate 8 double (or 16 single) operations at the same time. This is called vectorization and greatly improves code execution.&lt;br /&gt;
&lt;br /&gt;
Consider the following code of speedtest.cpp:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
    const int N = 104;&lt;br /&gt;
    double a[N];&lt;br /&gt;
    for (int i = 0; i &amp;lt; 1e5; i++)&lt;br /&gt;
        for (int j = 0; j &amp;lt; N; j++)&lt;br /&gt;
            a[j] = std::sin(std::exp(a[j]-j)*3 * i + i*j);&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; a[4] &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Intel's C++ compiler ICPC will successfully vectorize the inner for loop, so that it will run significantly faster than with vectorization disabled.&lt;br /&gt;
&lt;br /&gt;
The code can be compiled with or without vectorization&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ icpc speedtest.cpp -o vectorized_speedtest -O3&lt;br /&gt;
$ icpc speedtest.cpp -o unvectorized_speedtest -O3 -no-vec&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Machine&lt;br /&gt;
| ASUS ZenBook Pro UX501VW&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
|-&lt;br /&gt;
! Compiler&lt;br /&gt;
| g++-6.3.1&lt;br /&gt;
| g++-4.8.5&lt;br /&gt;
| icpc-16.0.1&lt;br /&gt;
| icpc-16.0.1 -no-vec&lt;br /&gt;
| icpc-16.0.1 -mmic&lt;br /&gt;
| icpc-16.0.1 -mmic -no-vec&lt;br /&gt;
|-&lt;br /&gt;
! Double time[s]&lt;br /&gt;
| 0.63 - 0.66&lt;br /&gt;
| 0.65 - 0.66&lt;br /&gt;
| 0.155 - 0.160&lt;br /&gt;
| 0.50 - 0.51&lt;br /&gt;
| 0.25 - 0.26&lt;br /&gt;
| 11.1 - 11.2&lt;br /&gt;
|-&lt;br /&gt;
! Float time[s]&lt;br /&gt;
| 0.65 - 0.71&lt;br /&gt;
| 0.53 - 0.55&lt;br /&gt;
| 0.155 - 0.160&lt;br /&gt;
| 0.17 - 0.19&lt;br /&gt;
| 0.37 - 0.38&lt;br /&gt;
| 4.2 - 4.3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
We can see massive 44 fold speedup with and without vectorization.&lt;br /&gt;
&lt;br /&gt;
=== Code incapable of vectorization ===&lt;br /&gt;
&lt;br /&gt;
On the other hand there is a very similar code that can not be vectorized. Now all iterations of the inner loop access the same variable instead of each its own element in a list. ICPC is now unable to vectorize the code resulting in no difference when using -no-vec compile flag.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
    const int N = 104;&lt;br /&gt;
    double a;&lt;br /&gt;
    for (int i = 0; i &amp;lt; 1e5; i++)&lt;br /&gt;
        for (int j = 0; j &amp;lt; N; j++)&lt;br /&gt;
            a = std::sin(std::exp(a-j)*3 * i + i*j);&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Machine&lt;br /&gt;
| ASUS ZenBook Pro UX501VW&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
|-&lt;br /&gt;
! Compiler&lt;br /&gt;
| g++-6.3.1&lt;br /&gt;
| g++-4.8.5&lt;br /&gt;
| icpc-16.0.1&lt;br /&gt;
| icpc-16.0.1 -no-vec&lt;br /&gt;
| icpc-16.0.1 -mmic&lt;br /&gt;
| icpc-16.0.1 -mmic -no-vec&lt;br /&gt;
|-&lt;br /&gt;
! Double time[s]&lt;br /&gt;
| 0.80 - 0.82&lt;br /&gt;
| 0.72 - 0.73&lt;br /&gt;
| 0.58 - 0.59&lt;br /&gt;
| 0.58 - 0.59&lt;br /&gt;
| 10.9 - 11.0&lt;br /&gt;
| 10.9 - 11.0&lt;br /&gt;
|-&lt;br /&gt;
! Float time[s]&lt;br /&gt;
| 0.69 - 0.72&lt;br /&gt;
| 0.66 - 0.67&lt;br /&gt;
| 0.32 - 0.33&lt;br /&gt;
| 0.32 - 0.34&lt;br /&gt;
| 4.1 - 4.2&lt;br /&gt;
| 4.1 - 4.2&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Execution_on_Intel%C2%AE_Xeon_Phi%E2%84%A2_co-processor&amp;diff=878</id>
		<title>Execution on Intel® Xeon Phi™ co-processor</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Execution_on_Intel%C2%AE_Xeon_Phi%E2%84%A2_co-processor&amp;diff=878"/>
				<updated>2017-03-01T17:37:58Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Speedup by vectorization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Speedup by parallelization ==&lt;br /&gt;
&lt;br /&gt;
We tested the speedups on the Intel® Xeon Phi™ with the following code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;assert.h&amp;gt;&lt;br /&gt;
#include &amp;lt;omp.h&amp;gt;&lt;br /&gt;
#include &amp;lt;math.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]) {&lt;br /&gt;
    int numthreads;&lt;br /&gt;
    int n;&lt;br /&gt;
&lt;br /&gt;
    assert(argc == 3 &amp;amp;&amp;amp; &amp;quot;args: numthreads n&amp;quot;);&lt;br /&gt;
    sscanf(argv[1], &amp;quot;%d&amp;quot;, &amp;amp;numthreads);&lt;br /&gt;
    sscanf(argv[2], &amp;quot;%d&amp;quot;, &amp;amp;n);&lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;Init...\n&amp;quot;);&lt;br /&gt;
    printf(&amp;quot;Start (%d threads)...\n&amp;quot;, numthreads);&lt;br /&gt;
    printf(&amp;quot;%d test cases\n&amp;quot;, n);&lt;br /&gt;
&lt;br /&gt;
    int m = 1000000;&lt;br /&gt;
    double ttime = omp_get_wtime();&lt;br /&gt;
&lt;br /&gt;
    int i;&lt;br /&gt;
    double d = 0;&lt;br /&gt;
#pragma offload target(mic:0)&lt;br /&gt;
    {&lt;br /&gt;
#pragma omp parallel for private (i) schedule(static) num_threads(numthreads)&lt;br /&gt;
        for(i = 0; i &amp;lt; n; ++i) {&lt;br /&gt;
            for(int j = 0; j &amp;lt; m; ++j) {&lt;br /&gt;
                d = sin(d) + 0.1 + j;&lt;br /&gt;
                d = pow(0.2, d)*j;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    double time = omp_get_wtime() - ttime;&lt;br /&gt;
    fprintf(stderr, &amp;quot;%d %d %.6f\n&amp;quot;, n, numthreads, time);&lt;br /&gt;
    printf(&amp;quot;time: %.6f s\n&amp;quot;, time);&lt;br /&gt;
    printf(&amp;quot;Done d = %.6lf.\n&amp;quot;, d);&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code essentially distributes a problem of size $n\cdot m$ among &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;numthreads&amp;lt;/syntaxhighlight&amp;gt; cores,&lt;br /&gt;
We tested the time of execution for $n$ from the set $\{1, 10, 20, 50, 100, 200, 500, 1000\}$&lt;br /&gt;
and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; numthreads &amp;lt;/syntaxhighlight&amp;gt; from $1$ to $350$. The plots of exectuion times and performance speeups are shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;figure id=&amp;quot;times&amp;quot;&amp;gt;&lt;br /&gt;
[[File:times.png|thumb|center|upright=3|alt=A square of nodes coloured according to the solution(with smaller and larger node density)|&amp;lt;caption&amp;gt;A picture of our solution (with smaller and larger node density)&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;figure id=&amp;quot;fig:speedups&amp;quot;&amp;gt;&lt;br /&gt;
[[File:speedups.png|thumb|center|upright=3|alt=A square of nodes coloured according to the solution(with smaller and larger node density)|&amp;lt;caption&amp;gt;A picture of our solution (with smaller and larger node density)&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The code was compiled using: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; icc -openmp -O3 -qopt-report=2 -qopt-report-phase=vec -o test test.cpp&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
without warnings or errors. Then, in order to offload to Intel Phi, user must be logged in as root: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo su &amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
To run correctly, intel compiler and runtime variables must be sourced: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; source /opt/intel/bin/compilervars.sh intel64&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
Finally, the code was tested using the following command, where &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; test &amp;lt;/syntaxhighlight&amp;gt; is the name of the compiled executable: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; for n in 1 10 20 50 100 200 500 1000; do for nt in {1..350}; echo $nt $n; ./test $nt $n 2&amp;gt;&amp;gt; speedups.txt; done; done&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Speedup by vectorization ==&lt;br /&gt;
&lt;br /&gt;
Intel Xeon Phi has a 512 bit of space for simultaneous computation, which means it can calculate 8 double (or 16 single) operations at the same time. This is called vectorization and greatly improves code execution.&lt;br /&gt;
&lt;br /&gt;
Consider the following code of speedtest.cpp:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
    const int N = 104;&lt;br /&gt;
    double a[N];&lt;br /&gt;
    for (int i = 0; i &amp;lt; 1e5; i++)&lt;br /&gt;
        for (int j = 0; j &amp;lt; N; j++)&lt;br /&gt;
            a[j] = std::sin(std::exp(a[j]-j)*3 * i + i*j);&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; a[4] &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Intel's C++ compiler ICPC will successfully vectorize the inner for loop, so that it will run significantly faster than with vectorization disabled.&lt;br /&gt;
&lt;br /&gt;
The code can be compiled with or without vectorization&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ icpc speedtest.cpp -o vectorized_speedtest -O3&lt;br /&gt;
$ icpc speedtest.cpp -o unvectorized_speedtest -O3 -no-vec&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Machine&lt;br /&gt;
| ASUS ZenBook Pro UX501VW&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
|-&lt;br /&gt;
! Compiler&lt;br /&gt;
| g++-6.3.1&lt;br /&gt;
| g++-4.8.5&lt;br /&gt;
| icpc-16.0.1&lt;br /&gt;
| icpc-16.0.1 -no-vec&lt;br /&gt;
| icpc-16.0.1 -mmic&lt;br /&gt;
| icpc-16.0.1 -mmic -no-vec&lt;br /&gt;
|-&lt;br /&gt;
! Double time[s]&lt;br /&gt;
| 0.63 - 0.66&lt;br /&gt;
| 0.65 - 0.66&lt;br /&gt;
| 0.155 - 0.160&lt;br /&gt;
| 0.50 - 0.51&lt;br /&gt;
| 0.25 - 0.26&lt;br /&gt;
| 11.1 - 11.2&lt;br /&gt;
! Float time[s]&lt;br /&gt;
| 0.65 - 0.71&lt;br /&gt;
| 0.53 - 0.55&lt;br /&gt;
| 0.155 - 0.160&lt;br /&gt;
| 0.17 - 0.19&lt;br /&gt;
| 0.37 - 0.38&lt;br /&gt;
| 4.2 - 4.3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
We can see massive 44 fold speedup with and without vectorization.&lt;br /&gt;
&lt;br /&gt;
=== Code incapable of vectorization ===&lt;br /&gt;
&lt;br /&gt;
On the other hand there is a very similar code that can not be vectorized. Now all iterations of the inner loop access the same variable instead of each its own element in a list. ICPC is now unable to vectorize the code resulting in no difference when using -no-vec compile flag.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
    const int N = 104;&lt;br /&gt;
    double a;&lt;br /&gt;
    for (int i = 0; i &amp;lt; 1e5; i++)&lt;br /&gt;
        for (int j = 0; j &amp;lt; N; j++)&lt;br /&gt;
            a = std::sin(std::exp(a-j)*3 * i + i*j);&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Machine&lt;br /&gt;
| ASUS ZenBook Pro UX501VW&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
|-&lt;br /&gt;
! Compiler&lt;br /&gt;
| g++-6.3.1&lt;br /&gt;
| g++-4.8.5&lt;br /&gt;
| icpc-16.0.1&lt;br /&gt;
| icpc-16.0.1 -no-vec&lt;br /&gt;
| icpc-16.0.1 -mmic&lt;br /&gt;
| icpc-16.0.1 -mmic -no-vec&lt;br /&gt;
|-&lt;br /&gt;
! Double time[s]&lt;br /&gt;
| 0.80 - 0.82&lt;br /&gt;
| 0.72 - 0.73&lt;br /&gt;
| 0.58 - 0.59&lt;br /&gt;
| 0.58 - 0.59&lt;br /&gt;
| 10.9 - 11.0&lt;br /&gt;
| 10.9 - 11.0&lt;br /&gt;
|}&lt;br /&gt;
! Float time[s]&lt;br /&gt;
| 0.69 - 0.72&lt;br /&gt;
| 0.66 - 0.67&lt;br /&gt;
| 0.32 - 0.33&lt;br /&gt;
| 0.32 - 0.34&lt;br /&gt;
| 4.1 - 4.2&lt;br /&gt;
| 4.1 - 4.2&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Execution_on_Intel%C2%AE_Xeon_Phi%E2%84%A2_co-processor&amp;diff=877</id>
		<title>Execution on Intel® Xeon Phi™ co-processor</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Execution_on_Intel%C2%AE_Xeon_Phi%E2%84%A2_co-processor&amp;diff=877"/>
				<updated>2017-03-01T17:21:11Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Speedup by vectorization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Speedup by parallelization ==&lt;br /&gt;
&lt;br /&gt;
We tested the speedups on the Intel® Xeon Phi™ with the following code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;assert.h&amp;gt;&lt;br /&gt;
#include &amp;lt;omp.h&amp;gt;&lt;br /&gt;
#include &amp;lt;math.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]) {&lt;br /&gt;
    int numthreads;&lt;br /&gt;
    int n;&lt;br /&gt;
&lt;br /&gt;
    assert(argc == 3 &amp;amp;&amp;amp; &amp;quot;args: numthreads n&amp;quot;);&lt;br /&gt;
    sscanf(argv[1], &amp;quot;%d&amp;quot;, &amp;amp;numthreads);&lt;br /&gt;
    sscanf(argv[2], &amp;quot;%d&amp;quot;, &amp;amp;n);&lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;Init...\n&amp;quot;);&lt;br /&gt;
    printf(&amp;quot;Start (%d threads)...\n&amp;quot;, numthreads);&lt;br /&gt;
    printf(&amp;quot;%d test cases\n&amp;quot;, n);&lt;br /&gt;
&lt;br /&gt;
    int m = 1000000;&lt;br /&gt;
    double ttime = omp_get_wtime();&lt;br /&gt;
&lt;br /&gt;
    int i;&lt;br /&gt;
    double d = 0;&lt;br /&gt;
#pragma offload target(mic:0)&lt;br /&gt;
    {&lt;br /&gt;
#pragma omp parallel for private (i) schedule(static) num_threads(numthreads)&lt;br /&gt;
        for(i = 0; i &amp;lt; n; ++i) {&lt;br /&gt;
            for(int j = 0; j &amp;lt; m; ++j) {&lt;br /&gt;
                d = sin(d) + 0.1 + j;&lt;br /&gt;
                d = pow(0.2, d)*j;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    double time = omp_get_wtime() - ttime;&lt;br /&gt;
    fprintf(stderr, &amp;quot;%d %d %.6f\n&amp;quot;, n, numthreads, time);&lt;br /&gt;
    printf(&amp;quot;time: %.6f s\n&amp;quot;, time);&lt;br /&gt;
    printf(&amp;quot;Done d = %.6lf.\n&amp;quot;, d);&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code essentially distributes a problem of size $n\cdot m$ among &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;numthreads&amp;lt;/syntaxhighlight&amp;gt; cores,&lt;br /&gt;
We tested the time of execution for $n$ from the set $\{1, 10, 20, 50, 100, 200, 500, 1000\}$&lt;br /&gt;
and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; numthreads &amp;lt;/syntaxhighlight&amp;gt; from $1$ to $350$. The plots of exectuion times and performance speeups are shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;figure id=&amp;quot;times&amp;quot;&amp;gt;&lt;br /&gt;
[[File:times.png|thumb|center|upright=3|alt=A square of nodes coloured according to the solution(with smaller and larger node density)|&amp;lt;caption&amp;gt;A picture of our solution (with smaller and larger node density)&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;figure id=&amp;quot;fig:speedups&amp;quot;&amp;gt;&lt;br /&gt;
[[File:speedups.png|thumb|center|upright=3|alt=A square of nodes coloured according to the solution(with smaller and larger node density)|&amp;lt;caption&amp;gt;A picture of our solution (with smaller and larger node density)&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The code was compiled using: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; icc -openmp -O3 -qopt-report=2 -qopt-report-phase=vec -o test test.cpp&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
without warnings or errors. Then, in order to offload to Intel Phi, user must be logged in as root: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo su &amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
To run correctly, intel compiler and runtime variables must be sourced: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; source /opt/intel/bin/compilervars.sh intel64&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
Finally, the code was tested using the following command, where &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; test &amp;lt;/syntaxhighlight&amp;gt; is the name of the compiled executable: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; for n in 1 10 20 50 100 200 500 1000; do for nt in {1..350}; echo $nt $n; ./test $nt $n 2&amp;gt;&amp;gt; speedups.txt; done; done&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Speedup by vectorization ==&lt;br /&gt;
&lt;br /&gt;
Intel Xeon Phi has a 512 bit of space for simultaneous computation, which means it can calculate 8 double (or 16 single) operations at the same time. This is called vectorization and greatly improves code execution.&lt;br /&gt;
&lt;br /&gt;
Consider the following code of speedtest.cpp:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
    const int N = 104;&lt;br /&gt;
    double a[N];&lt;br /&gt;
    for (int i = 0; i &amp;lt; 1e5; i++)&lt;br /&gt;
        for (int j = 0; j &amp;lt; N; j++)&lt;br /&gt;
            a[j] = std::sin(std::exp(a[j]-j)*3 * i + i*j);&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; a[4] &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Intel's C++ compiler ICPC will successfully vectorize the inner for loop, so that it will run significantly faster than with vectorization disabled.&lt;br /&gt;
&lt;br /&gt;
The code can be compiled with or without vectorization&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ icpc speedtest.cpp -o vectorized_speedtest -O3&lt;br /&gt;
$ icpc speedtest.cpp -o unvectorized_speedtest -O3 -no-vec&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Machine&lt;br /&gt;
| ASUS ZenBook Pro UX501VW&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
|-&lt;br /&gt;
! Compiler&lt;br /&gt;
| g++-6.3.1&lt;br /&gt;
| g++-4.8.5&lt;br /&gt;
| icpc-16.0.1&lt;br /&gt;
| icpc-16.0.1 -no-vec&lt;br /&gt;
| icpc-16.0.1&lt;br /&gt;
| icpc-16.0.1 -no-vec&lt;br /&gt;
|-&lt;br /&gt;
! Execution time[s]&lt;br /&gt;
| 0.63 - 0.66&lt;br /&gt;
| 0.65 - 0.66&lt;br /&gt;
| 0.155 - 0.160&lt;br /&gt;
| 0.50 - 0.51&lt;br /&gt;
| 0.25 - 0.26&lt;br /&gt;
| 11.1 - 11.2&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
''' Code incapable of vectorization '''&lt;br /&gt;
&lt;br /&gt;
On the other hand there is a very similar code that can not be vectorized.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
    const int N = 104;&lt;br /&gt;
    double a;&lt;br /&gt;
    for (int i = 0; i &amp;lt; 1e5; i++)&lt;br /&gt;
        for (int j = 0; j &amp;lt; N; j++)&lt;br /&gt;
            a = std::sin(std::exp(a-j)*3 * i + i*j);&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Machine&lt;br /&gt;
| ASUS ZenBook Pro UX501VW&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon® CPU E5-2620 v3&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
| Intel® Xeon Phi™ Coprocessor SE10/7120&lt;br /&gt;
|-&lt;br /&gt;
! Compiler&lt;br /&gt;
| g++-6.3.1&lt;br /&gt;
| g++-4.8.5&lt;br /&gt;
| icpc-16.0.1&lt;br /&gt;
| icpc-16.0.1 -no-vec&lt;br /&gt;
| icpc-16.0.1&lt;br /&gt;
| icpc-16.0.1 -no-vec&lt;br /&gt;
|-&lt;br /&gt;
! Execution time[s]&lt;br /&gt;
| 0.80 - 0.82&lt;br /&gt;
| 0.72 - 0.73&lt;br /&gt;
| 0.58 - 0.59&lt;br /&gt;
| 0.58 - 0.59&lt;br /&gt;
| 10.9 - 11.0&lt;br /&gt;
| 10.9 - 11.0&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Execution_on_Intel%C2%AE_Xeon_Phi%E2%84%A2_co-processor&amp;diff=876</id>
		<title>Execution on Intel® Xeon Phi™ co-processor</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Execution_on_Intel%C2%AE_Xeon_Phi%E2%84%A2_co-processor&amp;diff=876"/>
				<updated>2017-03-01T16:45:45Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Speedup by vectorization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Speedup by parallelization ==&lt;br /&gt;
&lt;br /&gt;
We tested the speedups on the Intel® Xeon Phi™ with the following code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;assert.h&amp;gt;&lt;br /&gt;
#include &amp;lt;omp.h&amp;gt;&lt;br /&gt;
#include &amp;lt;math.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]) {&lt;br /&gt;
    int numthreads;&lt;br /&gt;
    int n;&lt;br /&gt;
&lt;br /&gt;
    assert(argc == 3 &amp;amp;&amp;amp; &amp;quot;args: numthreads n&amp;quot;);&lt;br /&gt;
    sscanf(argv[1], &amp;quot;%d&amp;quot;, &amp;amp;numthreads);&lt;br /&gt;
    sscanf(argv[2], &amp;quot;%d&amp;quot;, &amp;amp;n);&lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;Init...\n&amp;quot;);&lt;br /&gt;
    printf(&amp;quot;Start (%d threads)...\n&amp;quot;, numthreads);&lt;br /&gt;
    printf(&amp;quot;%d test cases\n&amp;quot;, n);&lt;br /&gt;
&lt;br /&gt;
    int m = 1000000;&lt;br /&gt;
    double ttime = omp_get_wtime();&lt;br /&gt;
&lt;br /&gt;
    int i;&lt;br /&gt;
    double d = 0;&lt;br /&gt;
#pragma offload target(mic:0)&lt;br /&gt;
    {&lt;br /&gt;
#pragma omp parallel for private (i) schedule(static) num_threads(numthreads)&lt;br /&gt;
        for(i = 0; i &amp;lt; n; ++i) {&lt;br /&gt;
            for(int j = 0; j &amp;lt; m; ++j) {&lt;br /&gt;
                d = sin(d) + 0.1 + j;&lt;br /&gt;
                d = pow(0.2, d)*j;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    double time = omp_get_wtime() - ttime;&lt;br /&gt;
    fprintf(stderr, &amp;quot;%d %d %.6f\n&amp;quot;, n, numthreads, time);&lt;br /&gt;
    printf(&amp;quot;time: %.6f s\n&amp;quot;, time);&lt;br /&gt;
    printf(&amp;quot;Done d = %.6lf.\n&amp;quot;, d);&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code essentially distributes a problem of size $n\cdot m$ among &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;numthreads&amp;lt;/syntaxhighlight&amp;gt; cores,&lt;br /&gt;
We tested the time of execution for $n$ from the set $\{1, 10, 20, 50, 100, 200, 500, 1000\}$&lt;br /&gt;
and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; numthreads &amp;lt;/syntaxhighlight&amp;gt; from $1$ to $350$. The plots of exectuion times and performance speeups are shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;figure id=&amp;quot;times&amp;quot;&amp;gt;&lt;br /&gt;
[[File:times.png|thumb|center|upright=3|alt=A square of nodes coloured according to the solution(with smaller and larger node density)|&amp;lt;caption&amp;gt;A picture of our solution (with smaller and larger node density)&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;figure id=&amp;quot;fig:speedups&amp;quot;&amp;gt;&lt;br /&gt;
[[File:speedups.png|thumb|center|upright=3|alt=A square of nodes coloured according to the solution(with smaller and larger node density)|&amp;lt;caption&amp;gt;A picture of our solution (with smaller and larger node density)&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The code was compiled using: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; icc -openmp -O3 -qopt-report=2 -qopt-report-phase=vec -o test test.cpp&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
without warnings or errors. Then, in order to offload to Intel Phi, user must be logged in as root: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo su &amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
To run correctly, intel compiler and runtime variables must be sourced: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; source /opt/intel/bin/compilervars.sh intel64&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
Finally, the code was tested using the following command, where &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; test &amp;lt;/syntaxhighlight&amp;gt; is the name of the compiled executable: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; for n in 1 10 20 50 100 200 500 1000; do for nt in {1..350}; echo $nt $n; ./test $nt $n 2&amp;gt;&amp;gt; speedups.txt; done; done&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Speedup by vectorization ==&lt;br /&gt;
&lt;br /&gt;
Intel Xeon Phi has a 512 bit of space for simultaneous computation, which means it can calculate 8 double (or 16 single) operations at the same time. This is called vectorization and greatly improves code execution.&lt;br /&gt;
&lt;br /&gt;
Consider the following code:&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Execution_on_Intel%C2%AE_Xeon_Phi%E2%84%A2_co-processor&amp;diff=875</id>
		<title>Execution on Intel® Xeon Phi™ co-processor</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Execution_on_Intel%C2%AE_Xeon_Phi%E2%84%A2_co-processor&amp;diff=875"/>
				<updated>2017-03-01T16:45:14Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Speedup by parallelization ==&lt;br /&gt;
&lt;br /&gt;
We tested the speedups on the Intel® Xeon Phi™ with the following code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;assert.h&amp;gt;&lt;br /&gt;
#include &amp;lt;omp.h&amp;gt;&lt;br /&gt;
#include &amp;lt;math.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]) {&lt;br /&gt;
    int numthreads;&lt;br /&gt;
    int n;&lt;br /&gt;
&lt;br /&gt;
    assert(argc == 3 &amp;amp;&amp;amp; &amp;quot;args: numthreads n&amp;quot;);&lt;br /&gt;
    sscanf(argv[1], &amp;quot;%d&amp;quot;, &amp;amp;numthreads);&lt;br /&gt;
    sscanf(argv[2], &amp;quot;%d&amp;quot;, &amp;amp;n);&lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;Init...\n&amp;quot;);&lt;br /&gt;
    printf(&amp;quot;Start (%d threads)...\n&amp;quot;, numthreads);&lt;br /&gt;
    printf(&amp;quot;%d test cases\n&amp;quot;, n);&lt;br /&gt;
&lt;br /&gt;
    int m = 1000000;&lt;br /&gt;
    double ttime = omp_get_wtime();&lt;br /&gt;
&lt;br /&gt;
    int i;&lt;br /&gt;
    double d = 0;&lt;br /&gt;
#pragma offload target(mic:0)&lt;br /&gt;
    {&lt;br /&gt;
#pragma omp parallel for private (i) schedule(static) num_threads(numthreads)&lt;br /&gt;
        for(i = 0; i &amp;lt; n; ++i) {&lt;br /&gt;
            for(int j = 0; j &amp;lt; m; ++j) {&lt;br /&gt;
                d = sin(d) + 0.1 + j;&lt;br /&gt;
                d = pow(0.2, d)*j;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    double time = omp_get_wtime() - ttime;&lt;br /&gt;
    fprintf(stderr, &amp;quot;%d %d %.6f\n&amp;quot;, n, numthreads, time);&lt;br /&gt;
    printf(&amp;quot;time: %.6f s\n&amp;quot;, time);&lt;br /&gt;
    printf(&amp;quot;Done d = %.6lf.\n&amp;quot;, d);&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code essentially distributes a problem of size $n\cdot m$ among &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;numthreads&amp;lt;/syntaxhighlight&amp;gt; cores,&lt;br /&gt;
We tested the time of execution for $n$ from the set $\{1, 10, 20, 50, 100, 200, 500, 1000\}$&lt;br /&gt;
and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; numthreads &amp;lt;/syntaxhighlight&amp;gt; from $1$ to $350$. The plots of exectuion times and performance speeups are shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;figure id=&amp;quot;times&amp;quot;&amp;gt;&lt;br /&gt;
[[File:times.png|thumb|center|upright=3|alt=A square of nodes coloured according to the solution(with smaller and larger node density)|&amp;lt;caption&amp;gt;A picture of our solution (with smaller and larger node density)&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;figure id=&amp;quot;fig:speedups&amp;quot;&amp;gt;&lt;br /&gt;
[[File:speedups.png|thumb|center|upright=3|alt=A square of nodes coloured according to the solution(with smaller and larger node density)|&amp;lt;caption&amp;gt;A picture of our solution (with smaller and larger node density)&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The code was compiled using: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; icc -openmp -O3 -qopt-report=2 -qopt-report-phase=vec -o test test.cpp&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
without warnings or errors. Then, in order to offload to Intel Phi, user must be logged in as root: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo su &amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
To run correctly, intel compiler and runtime variables must be sourced: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; source /opt/intel/bin/compilervars.sh intel64&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
Finally, the code was tested using the following command, where &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; test &amp;lt;/syntaxhighlight&amp;gt; is the name of the compiled executable: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; for n in 1 10 20 50 100 200 500 1000; do for nt in {1..350}; echo $nt $n; ./test $nt $n 2&amp;gt;&amp;gt; speedups.txt; done; done&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Speedup by vectorization ==&lt;br /&gt;
&lt;br /&gt;
Intel Xeon Phi has a 512 bit of space for simultaneous computation, which means it can calculate 8 double (or 16 single) operations at the same time. This is called vectorization and greatly increases code execution.&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=How_to_build&amp;diff=795</id>
		<title>How to build</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=How_to_build&amp;diff=795"/>
				<updated>2016-12-28T11:27:22Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Intel */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Installation=&lt;br /&gt;
To make this work from plain Ubuntu installation, run&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install cmake doxygen graphviz libboost-dev libsfml-dev libhdf5-serial-dev&lt;br /&gt;
git clone https://gitlab.com/e62Lab/e62numcodes.git&lt;br /&gt;
cd e62numcodes&lt;br /&gt;
./run_tests.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
which installs dependancies, clones the repository, goes into the root folder of the repository and runs tests. This will check the configuration, notify you of potentially missing dependencies, build and run all tests, check code style and docs. If this works, you are ready to go! Otherwise install any missing packages and if it still fails, raise an issue!&lt;br /&gt;
&lt;br /&gt;
=Building=&lt;br /&gt;
&lt;br /&gt;
List of dependencies:&lt;br /&gt;
&lt;br /&gt;
* Build tools, like &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;gt;= 2.8.12&amp;lt;/syntaxhighlight&amp;gt;, &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; g++ &amp;gt;= 4.8&amp;lt;/syntaxhighlight&amp;gt;, &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;make&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* [http://www.boost.org/ Boost]&lt;br /&gt;
* &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; doxygen &amp;gt;=  1.8.8 &amp;lt;/syntaxhighlight&amp;gt; and Graphviz&lt;br /&gt;
* for drawing [http://www.sfml-dev.org/ SMFL library version 2]&lt;br /&gt;
* for IO [https://www.hdfgroup.org/ HDF5 library]&lt;br /&gt;
&lt;br /&gt;
Out of source builds are preferred. Run&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir -p build&lt;br /&gt;
cd build&lt;br /&gt;
cmake ..&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Note that you only have to run &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;lt;/syntaxhighlight&amp;gt; once, after that only &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&amp;lt;/syntaxhighlight&amp;gt; is sufficient.&lt;br /&gt;
&lt;br /&gt;
Binaries are placed into &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; bin &amp;lt;/syntaxhighlight&amp;gt; folder. Test can be run all at once via &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&lt;br /&gt;
run_all_tests &amp;lt;/syntaxhighlight&amp;gt; or individually via eg. &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;make basisfunc_run_tests &amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Linear Algebra==&lt;br /&gt;
We use [http://eigen.tuxfamily.org/ Eigen] as our matrix library. See&lt;br /&gt;
[http://eigen.tuxfamily.org/dox-devel/group__QuickRefPage.html here] for use&lt;br /&gt;
reference and documentation. For a quick transition from Matlab see&lt;br /&gt;
[http://eigen.tuxfamily.org/dox/AsciiQuickReference.txt here].&lt;br /&gt;
&lt;br /&gt;
==Drawing==&lt;br /&gt;
Some tests include drawing. We are using [http://www.sfml-dev.org/ SMFL library], which can be installed on most linux systems easly&lt;br /&gt;
as &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo apt-get install libsfml-dev &amp;lt;/syntaxhighlight&amp;gt; or &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo pacman -S sfml &amp;lt;/syntaxhighlight&amp;gt;.  After the&lt;br /&gt;
installation uncomment a test case in &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; domain_draw_test.cpp &amp;lt;/syntaxhighlight&amp;gt; and run &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&lt;br /&gt;
test_domain_draw &amp;lt;/syntaxhighlight&amp;gt; to see the visual effect.&lt;br /&gt;
&lt;br /&gt;
Binaries using SFML require additional linker flags &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; -lsfml-graphics&lt;br /&gt;
-lsfml-window -lsfml-system &amp;lt;/syntaxhighlight&amp;gt;, but the makefile should take care of that for you.&lt;br /&gt;
&lt;br /&gt;
==HDF5==&lt;br /&gt;
&lt;br /&gt;
In order to use IO you need [https://www.hdfgroup.org/ hdf5 library].&lt;br /&gt;
You can install it easily using the command &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo apt-get install libhdf5-&lt;br /&gt;
dev &amp;lt;/syntaxhighlight&amp;gt; or &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo pacman -S hdf5-cpp-fortran &amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Ubuntu places hdf5 libs in a werid folder &amp;lt;code&amp;gt;/usr/lib/x86_64-linux-gnu/hdf5/serial/&amp;lt;/code&amp;gt;. &lt;br /&gt;
If you get error similar to &amp;lt;code&amp;gt;-lhdf5 not found&amp;lt;/code&amp;gt; and you have hdf5 installed, you might have to link the libraries into&lt;br /&gt;
a discoverable place, like &amp;lt;code&amp;gt;/usr/lib/&amp;lt;/code&amp;gt; or add the above directory to the linker path.&lt;br /&gt;
If using cmake, you can add the following line to your CMakeLists.txt&lt;br /&gt;
  link_directories(/usr/lib/x86_64-linux-gnu/hdf5/serial/)&lt;br /&gt;
&lt;br /&gt;
==Intel==&lt;br /&gt;
&lt;br /&gt;
In order to use Intel's compiler you have to first set the &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;CXX&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;CC&amp;lt;/syntaxhighlight&amp;gt; bash variables. Before calling&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;lt;/syntaxhighlight&amp;gt; for the first time you have to export the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export CXX=&amp;quot;icpc&amp;quot;&lt;br /&gt;
export CC=&amp;quot;icc&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also compile it directly for Intel® Xeon Phi™ Coprocessor. You do this by adding &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;-Dmmic=ON&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
flag to the &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;cmake&amp;lt;/syntaxhighlight&amp;gt; command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cmake .. -Dmmic=ON&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note:&amp;lt;/b&amp;gt; All features that depend on system third-party libraries are not available on MIC (Many Integrated Core).&lt;br /&gt;
This includes:&lt;br /&gt;
&lt;br /&gt;
* [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/technical_docs/html/classmm_1_1HDF5IO.html HDF5IO] class in &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;io.hpp&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/technical_docs/html/classmm_1_1Monitor.html Monitor] class in &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;util.hpp&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* all of [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/technical_docs/html/util_8hpp_source.html  &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;draw.hpp&amp;lt;/syntaxhighlight&amp;gt;]&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=How_to_build&amp;diff=794</id>
		<title>How to build</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=How_to_build&amp;diff=794"/>
				<updated>2016-12-22T16:12:22Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Intel */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Installation=&lt;br /&gt;
To make this work from plain Ubuntu installation, run&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install cmake doxygen graphviz libboost-dev libsfml-dev libhdf5-serial-dev&lt;br /&gt;
git clone https://gitlab.com/e62Lab/e62numcodes.git&lt;br /&gt;
cd e62numcodes&lt;br /&gt;
./run_tests.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
which installs dependancies, clones the repository, goes into the root folder of the repository and runs tests. This will check the configuration, notify you of potentially missing dependencies, build and run all tests, check code style and docs. If this works, you are ready to go! Otherwise install any missing packages and if it still fails, raise an issue!&lt;br /&gt;
&lt;br /&gt;
=Building=&lt;br /&gt;
&lt;br /&gt;
List of dependencies:&lt;br /&gt;
&lt;br /&gt;
* Build tools, like &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;gt;= 2.8.12&amp;lt;/syntaxhighlight&amp;gt;, &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; g++ &amp;gt;= 4.8&amp;lt;/syntaxhighlight&amp;gt;, &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;make&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* [http://www.boost.org/ Boost]&lt;br /&gt;
* &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; doxygen &amp;gt;=  1.8.8 &amp;lt;/syntaxhighlight&amp;gt; and Graphviz&lt;br /&gt;
* for drawing [http://www.sfml-dev.org/ SMFL library version 2]&lt;br /&gt;
* for IO [https://www.hdfgroup.org/ HDF5 library]&lt;br /&gt;
&lt;br /&gt;
Out of source builds are preferred. Run&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir -p build&lt;br /&gt;
cd build&lt;br /&gt;
cmake ..&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Note that you only have to run &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;lt;/syntaxhighlight&amp;gt; once, after that only &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&amp;lt;/syntaxhighlight&amp;gt; is sufficient.&lt;br /&gt;
&lt;br /&gt;
Binaries are placed into &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; bin &amp;lt;/syntaxhighlight&amp;gt; folder. Test can be run all at once via &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&lt;br /&gt;
run_all_tests &amp;lt;/syntaxhighlight&amp;gt; or individually via eg. &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;make basisfunc_run_tests &amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Linear Algebra==&lt;br /&gt;
We use [http://eigen.tuxfamily.org/ Eigen] as our matrix library. See&lt;br /&gt;
[http://eigen.tuxfamily.org/dox-devel/group__QuickRefPage.html here] for use&lt;br /&gt;
reference and documentation. For a quick transition from Matlab see&lt;br /&gt;
[http://eigen.tuxfamily.org/dox/AsciiQuickReference.txt here].&lt;br /&gt;
&lt;br /&gt;
==Drawing==&lt;br /&gt;
Some tests include drawing. We are using [http://www.sfml-dev.org/ SMFL library], which can be installed on most linux systems easly&lt;br /&gt;
as &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo apt-get install libsfml-dev &amp;lt;/syntaxhighlight&amp;gt; or &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo pacman -S sfml &amp;lt;/syntaxhighlight&amp;gt;.  After the&lt;br /&gt;
installation uncomment a test case in &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; domain_draw_test.cpp &amp;lt;/syntaxhighlight&amp;gt; and run &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&lt;br /&gt;
test_domain_draw &amp;lt;/syntaxhighlight&amp;gt; to see the visual effect.&lt;br /&gt;
&lt;br /&gt;
Binaries using SFML require additional linker flags &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; -lsfml-graphics&lt;br /&gt;
-lsfml-window -lsfml-system &amp;lt;/syntaxhighlight&amp;gt;, but the makefile should take care of that for you.&lt;br /&gt;
&lt;br /&gt;
==HDF5==&lt;br /&gt;
&lt;br /&gt;
In order to use IO you need [https://www.hdfgroup.org/ hdf5 library].&lt;br /&gt;
You can install it easily using the command &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo apt-get install libhdf5-&lt;br /&gt;
dev &amp;lt;/syntaxhighlight&amp;gt; or &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo pacman -S hdf5-cpp-fortran &amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Ubuntu places hdf5 libs in a werid folder &amp;lt;code&amp;gt;/usr/lib/x86_64-linux-gnu/hdf5/serial/&amp;lt;/code&amp;gt;. &lt;br /&gt;
If you get error similar to &amp;lt;code&amp;gt;-lhdf5 not found&amp;lt;/code&amp;gt; and you have hdf5 installed, you might have to link the libraries into&lt;br /&gt;
a discoverable place, like &amp;lt;code&amp;gt;/usr/lib/&amp;lt;/code&amp;gt; or add the above directory to the linker path.&lt;br /&gt;
If using cmake, you can add the following line to your CMakeLists.txt&lt;br /&gt;
  link_directories(/usr/lib/x86_64-linux-gnu/hdf5/serial/)&lt;br /&gt;
&lt;br /&gt;
==Intel==&lt;br /&gt;
&lt;br /&gt;
In order to use Intel's compiler you have to first set the &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;CXX&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;CC&amp;lt;/syntaxhighlight&amp;gt; bash variables. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export CXX=&amp;quot;icpc&amp;quot;&lt;br /&gt;
export CC=&amp;quot;icc&amp;quot;&lt;br /&gt;
mkdir -p build&lt;br /&gt;
cd build&lt;br /&gt;
cmake ..&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To compile code for Intel Phi architecture you have to enable -mmic compile flag, which you can do with &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cmake .. -Dmmic=ON&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=How_to_build&amp;diff=793</id>
		<title>How to build</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=How_to_build&amp;diff=793"/>
				<updated>2016-12-22T15:10:08Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Building */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Installation=&lt;br /&gt;
To make this work from plain Ubuntu installation, run&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install cmake doxygen graphviz libboost-dev libsfml-dev libhdf5-serial-dev&lt;br /&gt;
git clone https://gitlab.com/e62Lab/e62numcodes.git&lt;br /&gt;
cd e62numcodes&lt;br /&gt;
./run_tests.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
which installs dependancies, clones the repository, goes into the root folder of the repository and runs tests. This will check the configuration, notify you of potentially missing dependencies, build and run all tests, check code style and docs. If this works, you are ready to go! Otherwise install any missing packages and if it still fails, raise an issue!&lt;br /&gt;
&lt;br /&gt;
=Building=&lt;br /&gt;
&lt;br /&gt;
List of dependencies:&lt;br /&gt;
&lt;br /&gt;
* Build tools, like &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;gt;= 2.8.12&amp;lt;/syntaxhighlight&amp;gt;, &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; g++ &amp;gt;= 4.8&amp;lt;/syntaxhighlight&amp;gt;, &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;make&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* [http://www.boost.org/ Boost]&lt;br /&gt;
* &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; doxygen &amp;gt;=  1.8.8 &amp;lt;/syntaxhighlight&amp;gt; and Graphviz&lt;br /&gt;
* for drawing [http://www.sfml-dev.org/ SMFL library version 2]&lt;br /&gt;
* for IO [https://www.hdfgroup.org/ HDF5 library]&lt;br /&gt;
&lt;br /&gt;
Out of source builds are preferred. Run&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir -p build&lt;br /&gt;
cd build&lt;br /&gt;
cmake ..&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Note that you only have to run &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; cmake &amp;lt;/syntaxhighlight&amp;gt; once, after that only &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&amp;lt;/syntaxhighlight&amp;gt; is sufficient.&lt;br /&gt;
&lt;br /&gt;
Binaries are placed into &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; bin &amp;lt;/syntaxhighlight&amp;gt; folder. Test can be run all at once via &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&lt;br /&gt;
run_all_tests &amp;lt;/syntaxhighlight&amp;gt; or individually via eg. &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;make basisfunc_run_tests &amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Linear Algebra==&lt;br /&gt;
We use [http://eigen.tuxfamily.org/ Eigen] as our matrix library. See&lt;br /&gt;
[http://eigen.tuxfamily.org/dox-devel/group__QuickRefPage.html here] for use&lt;br /&gt;
reference and documentation. For a quick transition from Matlab see&lt;br /&gt;
[http://eigen.tuxfamily.org/dox/AsciiQuickReference.txt here].&lt;br /&gt;
&lt;br /&gt;
==Drawing==&lt;br /&gt;
Some tests include drawing. We are using [http://www.sfml-dev.org/ SMFL library], which can be installed on most linux systems easly&lt;br /&gt;
as &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo apt-get install libsfml-dev &amp;lt;/syntaxhighlight&amp;gt; or &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo pacman -S sfml &amp;lt;/syntaxhighlight&amp;gt;.  After the&lt;br /&gt;
installation uncomment a test case in &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; domain_draw_test.cpp &amp;lt;/syntaxhighlight&amp;gt; and run &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; make&lt;br /&gt;
test_domain_draw &amp;lt;/syntaxhighlight&amp;gt; to see the visual effect.&lt;br /&gt;
&lt;br /&gt;
Binaries using SFML require additional linker flags &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; -lsfml-graphics&lt;br /&gt;
-lsfml-window -lsfml-system &amp;lt;/syntaxhighlight&amp;gt;, but the makefile should take care of that for you.&lt;br /&gt;
&lt;br /&gt;
==HDF5==&lt;br /&gt;
&lt;br /&gt;
In order to use IO you need [https://www.hdfgroup.org/ hdf5 library].&lt;br /&gt;
You can install it easily using the command &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo apt-get install libhdf5-&lt;br /&gt;
dev &amp;lt;/syntaxhighlight&amp;gt; or &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt; sudo pacman -S hdf5-cpp-fortran &amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Ubuntu places hdf5 libs in a werid folder &amp;lt;code&amp;gt;/usr/lib/x86_64-linux-gnu/hdf5/serial/&amp;lt;/code&amp;gt;. &lt;br /&gt;
If you get error similar to &amp;lt;code&amp;gt;-lhdf5 not found&amp;lt;/code&amp;gt; and you have hdf5 installed, you might have to link the libraries into&lt;br /&gt;
a discoverable place, like &amp;lt;code&amp;gt;/usr/lib/&amp;lt;/code&amp;gt; or add the above directory to the linker path.&lt;br /&gt;
If using cmake, you can add the following line to your CMakeLists.txt&lt;br /&gt;
  link_directories(/usr/lib/x86_64-linux-gnu/hdf5/serial/)&lt;br /&gt;
&lt;br /&gt;
==Intel==&lt;br /&gt;
&lt;br /&gt;
In order to use Intel's compiler you have to first set the &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;CXX&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;CC&amp;lt;/syntaxhighlight&amp;gt; bash variables. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export CXX=&amp;quot;icpc&amp;quot;&lt;br /&gt;
export CC=&amp;quot;icc&amp;quot;&lt;br /&gt;
mkdir -p build&lt;br /&gt;
cd build&lt;br /&gt;
cmake ..&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To compile code for Intel Phi architecture you have to enable -mmic compile flag, which you can do with &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cmake .. -Dmmic=1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Solid_Mechanics&amp;diff=515</id>
		<title>Solid Mechanics</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Solid_Mechanics&amp;diff=515"/>
				<updated>2016-11-07T13:50:55Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Point contact on a 2D half-plane */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Basic equations of elasticity=&lt;br /&gt;
&lt;br /&gt;
To determine the distribution of static stresses and displacements in a solid body we must obtain a solution (either analytically or numerically) to the basic equations of the theory of elasticity, satisfying the boundary conditions on forces and/or displacements. The equations thus form a boundary value problem. For a general three dimensional solid object the equations governing its behavior are:&lt;br /&gt;
* equations of equilibrium (3)&lt;br /&gt;
* strain-displacement equations (6)&lt;br /&gt;
* stress-strain equations (6)&lt;br /&gt;
where the number in brackets indicates the number of equations. The equations of equilibrium are three tensor partial differential equations for the balance of linear momentum, the strain-displacement equations are relations that stem from infinitesimal strain theory and the stress-strain equations are a set of linear algebraic constitutive relations (3D Hooke's law). In two dimensions these equations simplify to 8 equations (2 equilibrium, 3 strain-displacement, and 3 stress-strain).&lt;br /&gt;
&lt;br /&gt;
A large amount of confusion regarding linear elasticity originates from the many different notations used in this field. For this reason we first provide an overview of the different notations that are used.&lt;br /&gt;
&lt;br /&gt;
=== Direct tensor form ===&lt;br /&gt;
In direct tensor form (independent of coordinate system) the governing equations are:&lt;br /&gt;
*Equation of motion (an expression of Newton's second law):&lt;br /&gt;
\[&lt;br /&gt;
\boldsymbol{\nabla} \cdot \boldsymbol{\sigma} + \boldsymbol{F} = \rho \ddot{\boldsymbol{u}}&lt;br /&gt;
\]&lt;br /&gt;
*Strain-displacement equations:&lt;br /&gt;
\[&lt;br /&gt;
\boldsymbol{\varepsilon} = \frac{1}{2}\left[ \boldsymbol{\nabla} \boldsymbol{u} + (\boldsymbol{\nabla} \boldsymbol{u})^T  \right]&lt;br /&gt;
\]&lt;br /&gt;
*Stress-displacement equations (constitutive equations). For a linear elastic material this is Hooke's law:&lt;br /&gt;
\[&lt;br /&gt;
\boldsymbol{\sigma} = \boldsymbol{C} : \boldsymbol{\varepsilon}&lt;br /&gt;
\]&lt;br /&gt;
&lt;br /&gt;
where $\boldsymbol{\sigma}$ is the Cauchy stress tensor, $\boldsymbol{\varepsilon}$ is the infinitesimal strain tensor, $\boldsymbol{u}$ is the displacement vector, $\boldsymbol{C}$ is the fourth order stiffness tensor, $\boldsymbol{F}$ is the body force per unit volume (a vector quantity), $\rho$ is the mass density, $\boldsymbol{\nabla}(\bullet)$ is the gradient operator, $\boldsymbol{\nabla}\cdot(\bullet)$ is the divergence operator, $(\bullet)^T$ represents a transpose, $\ddot{(\bullet)}$ is the second derivative with respect to time, and $\boldsymbol{A}:\boldsymbol{B}$ is the inner product of two second order tensors (a tensor contraction).&lt;br /&gt;
&lt;br /&gt;
=== Cartesian coordinate form ===&lt;br /&gt;
&lt;br /&gt;
Using the Einstein summation convention (implied summations over repeated indexes) the equations are:&lt;br /&gt;
*Equation of motion (an expression of Newton's second law):&lt;br /&gt;
\[&lt;br /&gt;
\sigma_{ji,j} + F_i = \rho \partial_{tt} u_i&lt;br /&gt;
\]&lt;br /&gt;
*Strain-displacement equations:&lt;br /&gt;
\[&lt;br /&gt;
\varepsilon_{ij} = \frac{1}{2}\left(u_{j,i}+u_{i,j}\right)&lt;br /&gt;
\]&lt;br /&gt;
*Stress-displacement equations (constitutive equations). For a linear elastic material this is Hooke's law:&lt;br /&gt;
\[&lt;br /&gt;
\sigma_{i,j} = C_{ijkl} \varepsilon_{kl},&lt;br /&gt;
\]&lt;br /&gt;
where $i,j = 1,2,3$ represent, respectively, $x$, $y$ and $z$, the $(\bullet),j$ subscript is a shorthand for partial derivative $\partial(\bullet)/\partial x_j$ and $\partial_{tt}$ is shorthand notation for $\partial^2/\partial t^2$, $\sigma_{ij}=\sigma_{ji}$ is the Cauchy stress tensor (with 6 independent components), $F_i$ are the body forces, $\rho$ is the mass density, $u_i$ is the displacement, $\varepsilon_{ij} = \varepsilon_{ji}$ is the strain tensor (also with 6 independent components), and, finally $C_{ijkl}$ is the fourth-order stiffness tensor that due to symmetry requirements $C_{ijkl} = C_{klij} = C_{jikl} =C_{ijkl}$ can be reduced to 21 different elements.&lt;br /&gt;
&lt;br /&gt;
=== Matrix-vector (FEM) notation ===&lt;br /&gt;
&lt;br /&gt;
*Equation of motion:&lt;br /&gt;
\[&lt;br /&gt;
\boldsymbol{L}^T\boldsymbol{\sigma} + \boldsymbol{F} = \rho\ddot{\boldsymbol{u}}&lt;br /&gt;
\]&lt;br /&gt;
*Strain-displacement equations:&lt;br /&gt;
\[&lt;br /&gt;
\boldsymbol{\varepsilon} = \boldsymbol{L}\boldsymbol{u}&lt;br /&gt;
\]&lt;br /&gt;
*Stress-displacement equations (constitutive equations). For a linear elastic material this is Hooke's law:&lt;br /&gt;
\[&lt;br /&gt;
\boldsymbol{\sigma} = \boldsymbol{C}\boldsymbol{\varepsilon}&lt;br /&gt;
\]&lt;br /&gt;
where $\boldsymbol{\sigma}$ is the Cauchy stress tensor represented in vector form (6 components), $\boldsymbol{L}$ is a differential operator matrix (size $3 \times 6$), $\bullet^T$ is transpose of a matrix $\bullet$, $\boldsymbol{F}$ is the body force vector, $\rho$ is the mass density, $\boldsymbol{u}$ is the displacement vector, $\boldsymbol{\varepsilon}$ is the strain tensor represented in vector form (6 components), and $\boldsymbol{C}$ is the symmetric stress-strain matrix (size $6 \times 6$ with 21 material constants $C_{ij} = C_{ji}$). Certain literature prefers using the symbol $\boldsymbol{D}$ instead of $\boldsymbol{C}$ for the stress-strain matrix. The symbol $C$ is then used as the &amp;quot;compliance tensor&amp;quot; that relates the strains to the stresses, e.g. $\boldsymbol{\varepsilon} = \boldsymbol{C}\boldsymbol{\sigma}$.&lt;br /&gt;
&lt;br /&gt;
To solve the basic equations of elasticity two approaches exist according to the boundary conditions of the boundary value problem. In the '''displacement formulation''' the displacements are prescribed everywhere at the boundaries and the stresses and strains are eliminated from the formulation. The other possible option is that the surface tractions are prescribed everywhere on the surface boundary. The equations of elasticity are then manipulated to leave the stresses as the unknown to be solved for. This approach is known as the '''stress formulation'''.&lt;br /&gt;
&lt;br /&gt;
== Displacement formulation ==&lt;br /&gt;
&lt;br /&gt;
In this approach our goal is to eliminate the strains and stresses from the equations and leave only the displacements as the unknown to be solved for. The first step is to substitute&lt;br /&gt;
&lt;br /&gt;
=== Navier equations ===&lt;br /&gt;
The Navier or Navier-Cauchy equations describe the dynamic of a solid through the displacement vector field $\b{u}$. The equation is as follows&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\rho \frac{\partial^2 \b{u}}{\partial t^2} = \mu \nabla^2 \b{u} + (\lambda + \mu) \nabla(\nabla \cdot \b{u}) + \b{F}\ ,&lt;br /&gt;
\end{equation}&lt;br /&gt;
where $\mu$ and $\lambda$ are Lamé constants, $\rho$ is the object density and $\b{F}$ are the external forces.&lt;br /&gt;
&lt;br /&gt;
== Stress formulation ==&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Linear_elasticity#Stress_formulation Stress formulation at Wikipedia]&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Stress_functions Stress functions at Wikipedia]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- ==Strain-displacement equations==&lt;br /&gt;
&lt;br /&gt;
Under the action of applied forces, a point in the solid originally at $\boldsymbol{x} = (x,y,z)$ moves to position $\boldsymbol{X} = (X,Y,Z)$. This movement can be described completely by the displacement vector &lt;br /&gt;
\begin{equation*}&lt;br /&gt;
\boldsymbol{u}(\boldsymbol{x}) = \boldsymbol{X} - \boldsymbol{x},&lt;br /&gt;
\end{equation*}&lt;br /&gt;
consisting of three components&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\boldsymbol{u} = \{u_x \quad u_y \quad u_z\}.&lt;br /&gt;
\end{equation}&lt;br /&gt;
The brackets $\{\}$ indicate that this is a column vector. The components of this vector are mutually orthogonal and their positive directions correspond to the positive directions of the coordinate axes. To prevent confusion with the shorthand notation for partial derivatives, the components of $\boldsymbol{u}$ are sometimes represented with the letter $u, v, w$, e.g. $\boldsymbol{u} = \{u \quad v \quad w\}$.&lt;br /&gt;
&lt;br /&gt;
The strains in the deformed structure can be expressed as partial derivatives of the displacements as follows: --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Two-dimensional stress distributions ==&lt;br /&gt;
Many problems in elasticity can be simplified as two-dimensional problems described by ''plane theory of elasticity''. In general there are two types of problems we may encounter in plane analysis: '''plane stress''' and '''plane strain'''. The first problem arises in analysis of thin plates loaded in the plane of the plate, while the second is used for elongated bodies of constant cross section subject to uniform loading.&lt;br /&gt;
&lt;br /&gt;
=== Plane stress ===&lt;br /&gt;
&lt;br /&gt;
Plane stress distributions build on the assumption that the normal stress and shear stresses directed perpendicular to the $x$-$y$ plane are assumed zero:&lt;br /&gt;
\begin{equation}\label{eq:pstress_assump}&lt;br /&gt;
\sigma_{zz} = \sigma_{zx} = \sigma_{zy} = 0.&lt;br /&gt;
\end{equation}&lt;br /&gt;
It is also assumed that the stress components do not vary through the thickness of the plate (the assumptions do violate some compatibility conditions, but are still sufficiently accurate for practical applications if the plate is thin).&lt;br /&gt;
&lt;br /&gt;
Using (\ref{eq:pstress_assump}) the three-dimensional Hooke's law can be reduced to:&lt;br /&gt;
\begin{equation}\label{eq:planestress}&lt;br /&gt;
\boldsymbol{\sigma} = \boldsymbol{C}\boldsymbol{\varepsilon}&lt;br /&gt;
\end{equation}&lt;br /&gt;
in matrix form where for isotropic materials, we have&lt;br /&gt;
\begin{equation}\label{eq:planestressmatrix}&lt;br /&gt;
\boldsymbol{C}&lt;br /&gt;
= \frac{E}{1-\nu^2}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
1 &amp;amp; \nu &amp;amp; 0 \\&lt;br /&gt;
\nu &amp;amp; 1 &amp;amp; 0 \\&lt;br /&gt;
0 &amp;amp; 0 &amp;amp; \frac{1-\nu}{2}&lt;br /&gt;
\end{bmatrix} \qquad \text{(Plane stress)}&lt;br /&gt;
\end{equation}&lt;br /&gt;
and \[\boldsymbol{\sigma} = \{\sigma_{xx} \quad \sigma_{yy} \quad \sigma_{xy}\},\] \[\boldsymbol{\varepsilon} = \{\varepsilon_{xx} \quad \varepsilon_{yy} \quad \varepsilon_{xy}\},\]  where the brackets $\{\,\}$ indicate that these are column vectors.&lt;br /&gt;
&lt;br /&gt;
=== Plane strain ===&lt;br /&gt;
&lt;br /&gt;
The plane strain problem arises in analysis of walls, dams, tunnels where one dimension of the structure is very large in comparison to the other two dimensions ($x$- and $y$- coordinates). It is also appropriate for small-scale problems such as bars and rollers compressed by forces normal to their cross section. In all such problems the body may be imagined as a prismatic cylinder with one dimension much larger that the other two. The applied forces act in the $x$-$y$ plane and do not vary in the $z$ direction, leading to the assumption&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\frac{\partial}{\partial z} = u_z = 0.&lt;br /&gt;
\end{equation} &lt;br /&gt;
&lt;br /&gt;
With the above assumption it follows immediately that&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\varepsilon_{zz} = \varepsilon_{zx} = \varepsilon_{zy} = 0.&lt;br /&gt;
\end{equation}&lt;br /&gt;
The three dimensional Hooke's law can now be reduced to&lt;br /&gt;
\begin{equation}\label{eq:planestrain}&lt;br /&gt;
\boldsymbol{\sigma} = \boldsymbol{C}\boldsymbol{\varepsilon}&lt;br /&gt;
\end{equation}&lt;br /&gt;
where the matrix $C$ is given by&lt;br /&gt;
\begin{equation}\label{eq:matrixplanestrain}&lt;br /&gt;
\boldsymbol{C}&lt;br /&gt;
= \frac{E}{(1+\nu)(1-2\nu)}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
1-\nu &amp;amp; \nu &amp;amp; 0 \\&lt;br /&gt;
\nu &amp;amp; 1-\nu &amp;amp; 0 \\&lt;br /&gt;
0 &amp;amp; 0 &amp;amp; \frac{1-2\nu}{2}&lt;br /&gt;
\end{bmatrix} \qquad \text{(Plane strain)}&lt;br /&gt;
\end{equation}&lt;br /&gt;
The vectors $\boldsymbol{\sigma}$ and $\boldsymbol{\varepsilon}$ are the same as above for plane stress. In the case of plane strain we have additonal non-zero components of the stress tensor:&lt;br /&gt;
\begin{equation}\label{eq:sigmazz}&lt;br /&gt;
\sigma_{zz} = \nu(\sigma_{xx}+\sigma_{yy})&lt;br /&gt;
\end{equation}&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\sigma_{yz} = \sigma_{zx} = 0&lt;br /&gt;
\end{equation}&lt;br /&gt;
The reason $\sigma_{zz}$ is not included in the matrix stress-strain equation (\ref{eq:planestrain}) is because it is linearly dependent on the normal stresses $\sigma_{xx}$ and $\sigma_{zz}$.&lt;br /&gt;
&lt;br /&gt;
=== Connection between plane stress and plane strain ===&lt;br /&gt;
&lt;br /&gt;
For '''isotropic''' materials with elastic modulus $E$ and Poisson's ratio $\nu$ it is possible to go from plane stress to plane strain, or vice-versa, by replacing $E$ and $\nu$ in the stress-strain matrix with a fictitious modulus $E^*$ and fictitious Poisson ratio $\nu^*$. This allows us to &amp;quot;reuse&amp;quot; a plane stress program to solve plane strain or again vice-versa (as long as the material is isotropic). A few exercises on this topic are given [http://www.colorado.edu/engineering/cas/courses.d/IFEM.d/IFEM.Ch14.d/IFEM.Ch14.pdf at this link (page 13)].&lt;br /&gt;
&lt;br /&gt;
To go from plane stres'''s''' ($s$) to plane strai'''n''' ($n$) insert the fictitious quantities&lt;br /&gt;
\begin{equation}\label{eq:ston1}&lt;br /&gt;
E_n^* = \frac{E_s}{1-\nu_s^2},&lt;br /&gt;
\end{equation}&lt;br /&gt;
\begin{equation}\label{eq:ston2}&lt;br /&gt;
\nu_n^* = \frac{\nu_s}{1-\nu_s}.&lt;br /&gt;
\end{equation}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
'''Substitution from plane stress to plane strain'''&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;Note: this derivation is shown just to confirm the above formulas. In a numerical program, we keep the stress-strain matrix and just use the above formulas (\ref{eq:ston1}) and (\ref{eq:ston2}) to update the values of $E$ and $\nu$. Also note we have omitted the indexes ($s$) and ($n$) in the following derivations.&lt;br /&gt;
&lt;br /&gt;
We start with the plane stress matrix with the inserted fictitious values $E^*$ and $\nu^*$&lt;br /&gt;
\[&lt;br /&gt;
\frac{E^*}{1-{\nu^*}^2}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
1 &amp;amp; \nu^* &amp;amp; 0 \\&lt;br /&gt;
\nu^* &amp;amp; 1 &amp;amp; 0 \\&lt;br /&gt;
0 &amp;amp; 0 &amp;amp; \frac{1}{2}(1-\nu^*)&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
\] &lt;br /&gt;
and make the above substitutions (\ref{eq:ston1}) and (\ref{eq:ston2}) leading to:&lt;br /&gt;
\[&lt;br /&gt;
\frac{E}{\left(1-\nu^2\right)\left(1-\left(\frac{\nu}{1-\nu}\right)^2\right)}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
1 &amp;amp; \frac{\nu}{1-\nu} &amp;amp; 0 \\&lt;br /&gt;
\frac{\nu}{1-\nu} &amp;amp; 1 &amp;amp; 0 \\&lt;br /&gt;
0 &amp;amp; 0 &amp;amp; \frac{1}{2}(1-\frac{\nu}{1-\nu})&lt;br /&gt;
\end{bmatrix}.&lt;br /&gt;
\]&lt;br /&gt;
We can then use the rule to convert sums of squares into products as well as bring the factor $1/(1-v)$ out of the matrix:&lt;br /&gt;
\[&lt;br /&gt;
\frac{E}{\left(1-\nu\right)\left(1+\nu\right)\left(1-\frac{\nu}{1-\nu}\right)\left(1+\frac{\nu}{1-\nu}\right)\left(1-\nu\right)}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
1-\nu &amp;amp; \nu &amp;amp; 0 \\&lt;br /&gt;
\nu &amp;amp; 1-\nu &amp;amp; 0 \\&lt;br /&gt;
0 &amp;amp; 0 &amp;amp; \frac{1}{2}(1-2\nu)&lt;br /&gt;
\end{bmatrix}.&lt;br /&gt;
\]&lt;br /&gt;
By joining some of the factors to a common denominator and rearranging leads to&lt;br /&gt;
\[&lt;br /&gt;
\frac{E\left(1-\nu\right)\left(1-\nu\right)}{\left(1-\nu\right)\left(1+\nu\right)\left(1-2\nu\right)1\left(1-\nu\right)}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
1-\nu &amp;amp; \nu &amp;amp; 0 \\&lt;br /&gt;
\nu &amp;amp; 1-\nu &amp;amp; 0 \\&lt;br /&gt;
0 &amp;amp; 0 &amp;amp; \frac{1}{2}(1-2\nu)&lt;br /&gt;
\end{bmatrix}.&lt;br /&gt;
\]&lt;br /&gt;
The final step is canceling the factors that occur in both the numerator and denominator &lt;br /&gt;
\[&lt;br /&gt;
\frac{E}{\left(1+\nu\right)\left(1-2\nu\right)}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
1-\nu &amp;amp; \nu &amp;amp; 0 \\&lt;br /&gt;
\nu &amp;amp; 1-\nu &amp;amp; 0 \\&lt;br /&gt;
0 &amp;amp; 0 &amp;amp; \frac{1}{2}(1-2\nu)&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
\]&lt;br /&gt;
which leads exactly to the relationship for plane strain given in (\ref{eq:planestrain}).&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the opposite case we want to go from plane strai'''n''' ($n$) to plane stres'''s''' ($s$) we can use:&lt;br /&gt;
\begin{equation}\label{eq:ntos1}&lt;br /&gt;
E_s^* = \frac{E_n(1+2\nu_n)}{(1+\nu_n)^2},&lt;br /&gt;
\end{equation}&lt;br /&gt;
\begin{equation}\label{eq:ntos2}&lt;br /&gt;
\nu_s^* = \frac{\nu_n}{1+\nu_n}.&lt;br /&gt;
\end{equation}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
'''Substitution from plane strain to plane stress'''&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Note that we have again omitted the indexes ($s$) and ($n$) since our wish is expressed by the bold title.&lt;br /&gt;
&lt;br /&gt;
We start with the plane strain matrix with the inserted fictitious values $E^*$ and $\nu^*$&lt;br /&gt;
\[&lt;br /&gt;
\frac{E^*}{\left(1+\nu^*\right)\left(1-2\nu^*\right)}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
1-\nu^* &amp;amp; \nu^* &amp;amp; 0 \\&lt;br /&gt;
\nu^* &amp;amp; 1-\nu^* &amp;amp; 0 \\&lt;br /&gt;
0 &amp;amp; 0 &amp;amp; \frac{1}{2}(1-2\nu^*)&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
\] &lt;br /&gt;
and make the above substitutions (\ref{eq:ntos1}) and (\ref{eq:ntos2}) leading to:&lt;br /&gt;
\[&lt;br /&gt;
\frac{E(1+2\nu)}{\left(1+\nu\right)^2\left(1+\frac{\nu}{1+\nu}\right)\left(1-2\frac{\nu}{1+\nu}\right)}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
1-\frac{\nu}{1+\nu} &amp;amp; \frac{\nu}{1+\nu} &amp;amp; 0 \\&lt;br /&gt;
\frac{\nu}{1+\nu} &amp;amp; 1-\frac{\nu}{1+\nu} &amp;amp; 0 \\&lt;br /&gt;
0 &amp;amp; 0 &amp;amp; \frac{1}{2}(1-2\frac{\nu}{1+\nu})&lt;br /&gt;
\end{bmatrix}.&lt;br /&gt;
\]&lt;br /&gt;
Writing some of the sums with common denominators and rearranging leads to&lt;br /&gt;
\[&lt;br /&gt;
\frac{E(1+2\nu)(1+\nu)(1+\nu)}{\left(1+\nu\right)^2\left(1+2\nu\right)\left(1-\nu\right)}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
\frac{1}{1+\nu} &amp;amp; \frac{\nu}{1+\nu} &amp;amp; 0 \\&lt;br /&gt;
\frac{\nu}{1+\nu} &amp;amp; \frac{1}{1+\nu} &amp;amp; 0 \\&lt;br /&gt;
0 &amp;amp; 0 &amp;amp; \frac{1}{2}\left(\frac{1-\nu}{1+\nu}\right)&lt;br /&gt;
\end{bmatrix}.&lt;br /&gt;
\]&lt;br /&gt;
We can also bring the factor $1/(1+\nu)$ out from the matrix components. After canceling all factors that occur in both denominator and numerator we are left with&lt;br /&gt;
\[&lt;br /&gt;
\frac{E}{\left(1+\nu\right)\left(1-\nu\right)}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
1 &amp;amp; \nu &amp;amp; 0 \\&lt;br /&gt;
\nu &amp;amp; 1 &amp;amp; 0 \\&lt;br /&gt;
0 &amp;amp; 0 &amp;amp; \frac{1}{2}(1-\nu)&lt;br /&gt;
\end{bmatrix}.&lt;br /&gt;
\]&lt;br /&gt;
Rewriting the product of sums as a sum of squares gives us the matrix for plane stress in (\ref{eq:planestress}).&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Point contact on a 2D half-plane=&lt;br /&gt;
&lt;br /&gt;
A starting point to solve problems in contact mechanics is to understand the effect of a point-load applied to a homogeneous, linear elastic, isotropic half-plane. This problem may be defined either as plane stress or plain strain (for solution with FreeFem++ we have choosen the latter). The traction boundary conditions for this problem are:&lt;br /&gt;
\begin{equation}\label{eq:bc}&lt;br /&gt;
\sigma_{xy}(x,0) = 0, \quad \sigma_{yy}(x,y) = -P\delta(x,y)&lt;br /&gt;
\end{equation}&lt;br /&gt;
where $\delta(x,y)$ is the Dirac delta function. Together these boundary conditions state that there is a singular normal force $P$ applied at $(x,y) = (0,0)$ and there are no shear stresses on the surface of the elastic half-plane.&lt;br /&gt;
&lt;br /&gt;
The analytical relations for the stresses can be found from the [https://en.wikipedia.org/wiki/Flamant_solution Flamant solution] (stress distributions in a linear elastic wedge loaded by point forces a the tip. When the &amp;quot;wedge&amp;quot; is flat we get a half-plane. The derivation uses polar coordinates.) and are given as:&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\sigma_{xx} = -\frac{2P}{\pi} \frac{x^2y}{\left(x^2+y^2\right)^2},&lt;br /&gt;
\end{equation}&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\sigma_{yy} = -\frac{2P}{\pi} \frac{y^3}{\left(x^2+y^2\right)^2},&lt;br /&gt;
\end{equation}&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\sigma_{xy} = -\frac{2P}{\pi} \frac{xy^2}{\left(x^2+y^2\right)^2},&lt;br /&gt;
\end{equation}&lt;br /&gt;
for some point $(x,y)$ in the half-plane. From this stress field the strain components and thus the displacements $(u_x,u_y)$ can be determined. The displacements are given by&lt;br /&gt;
\begin{align}&lt;br /&gt;
u_x &amp;amp;= -\frac{P}{4\pi\mu}\left((\kappa-1)\theta - \frac{2xy}{r^2}\right), \label{eq:dispx}\\&lt;br /&gt;
u_y &amp;amp;= -\frac{P}{4\pi\mu}\left((\kappa+1)\log r + \frac{2x^2}{r^2}\right), \label{eq:dispy}&lt;br /&gt;
\end{align}&lt;br /&gt;
where $$r = \sqrt{x^2+y^2}$$ and $$\tan \theta = \frac{x}{y}.$$ The symbol $\kappa$ is known as Dundars constant and is defined as&lt;br /&gt;
\[&lt;br /&gt;
\kappa = \begin{cases} 3 - 4\nu &amp;amp; \quad \text{(Plane strain)}, \\&lt;br /&gt;
                       \cfrac{3 - \nu}{1+\nu} &amp;amp; \quad \text{(Plane stress)}. \end{cases}&lt;br /&gt;
\]&lt;br /&gt;
The last remaining symbol is $\mu$ which represents the shear modulus (sometimes also denoted with $G$).&lt;br /&gt;
&lt;br /&gt;
==Numerical solution with [http://www.freefem.org/ FreeFem++]==&lt;br /&gt;
Due to the known analytical solution the point-contact problem can be used for benchmarking numerical PDE solvers in terms of accuracy (as well as computational efficiency). The purpose of this section is to compare the numerical solution obtained by FreeFem++ with the analytical solution, as well as provide a reference numerical solution for the [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/wiki/index.php/Main_Page C++ library] developed in our laboratory.&lt;br /&gt;
&lt;br /&gt;
For purposes of simplicity we limit ourselves to the domain $(x,y) \in \Omega = [-1,1] \times[-1,-0.1]$ and prescribe Dirichlet displacement on the boundaries $\Gamma_D$ from the known analytical solution (\ref{eq:dispx}, \ref{eq:dispy}). This way we avoid having to deal with the Dirac delta traction boundary condition (\ref{eq:bc}). The problem can be described as find $\boldsymbol{u(\boldsymbol{x})}$ that satisfies&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\boldsymbol{\nabla}\cdot\boldsymbol{\sigma}= 0 \qquad \text{on }\Omega&lt;br /&gt;
\end{equation}&lt;br /&gt;
and&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\boldsymbol{u} = \boldsymbol{u}_{\text{analytical}} \qquad \text{on }\Gamma_D&lt;br /&gt;
\end{equation}&lt;br /&gt;
where $\boldsymbol{u}_\text{analytical}$ is given in equations (\ref{eq:dispx}) and (\ref{eq:dispy}).&lt;br /&gt;
&lt;br /&gt;
To solve the point-contact problem in FreeFem++ we must first provide the weak form of the balance equation:&lt;br /&gt;
\begin{equation*}&lt;br /&gt;
\boldsymbol{\nabla}\cdot\boldsymbol{\sigma} + \boldsymbol{b} = 0.&lt;br /&gt;
\end{equation*}&lt;br /&gt;
The corresponding weak formulation is&lt;br /&gt;
\begin{equation}\label{eq:weak}&lt;br /&gt;
\int_\Omega \boldsymbol{\sigma} : \boldsymbol{\varepsilon}(\boldsymbol{v}) \, d\Omega - \int_\Omega \boldsymbol{b}\cdot\boldsymbol{v}\,d\Omega = 0&lt;br /&gt;
\end{equation}&lt;br /&gt;
where $:$ denotes the tensor scalar product (tensor contraction), i.e. $\boldsymbol{A}:\boldsymbol{B} =\sum_{i,j} A_{ij}B_{ij}$. The vector $\boldsymbol{v}$ is the test function or so-called &amp;quot;virtual displacement&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Equation (\ref{eq:weak}) can be handed to FreeFem++ with the help of [https://en.wikipedia.org/wiki/Voigt_notation#Mandel_notation Voigt or Mandel notation], that reduces the symmetric tensors $\boldsymbol{\sigma}$ and $\boldsymbol{\varepsilon}$ to vectors. The benefit of [https://en.wikipedia.org/wiki/Voigt_notation#Mandel_notation Mandel notation] is that it allows the tensor scalar product to be performed as a scalar product of two vectors.&lt;br /&gt;
For this reason we create the following macros:&lt;br /&gt;
 macro u [ux,uy] // displacements&lt;br /&gt;
 macro v [vx,vy] // test function&lt;br /&gt;
 macro b [bx,by] // body forces&lt;br /&gt;
 macro e(u) [dx(u[0]),dy(u[1]),(dx(u[1])+dy(u[0]))/2] // strain (for post-processing)&lt;br /&gt;
 macro em(u) [dx(u[0]),dy(u[1]),sqrt(2)*(dx(u[1])+dy(u[0]))/2] // strain in Mandel notation&lt;br /&gt;
 macro A [[2*mu+lambda,mu,0],[mu,2*mu+lambda,0],[0,0,2*mu]] // stress-strain matrix&lt;br /&gt;
&lt;br /&gt;
The weak form (\ref{eq:weak}) can then be expressed naturally in FreeFem++ syntax as&lt;br /&gt;
 int2d(Th)((A*em(u))'*em(v)) - int2d(Th)(b'*v)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Stress and displacement fields===&lt;br /&gt;
&lt;br /&gt;
===Convergence studies===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;figure id=&amp;quot;fig:point_contact_convergence&amp;quot;&amp;gt;&lt;br /&gt;
[[File:Convergence.png|thumb|upright=2|&amp;lt;caption&amp;gt;Convergence results for the point contact problem. The colours blue, red and green represent linear, quadratic and cubic finite elements, respectively.&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the convergence between analytical and numerical solution we vary the number of nodes by increasing the grid size in both $x$- and $y$- directions simultaneously by powers of two from $2^2$ (16 nodes all together) to $2^7$ (16384 nodes all together).&lt;br /&gt;
The $L^2$ error norm is used to measure the &amp;quot;difference&amp;quot; between solutions. Since the displacements are the variable that obtain from FreeFem++, we use the displacement magnitude $|\boldsymbol{u}| = \sqrt{u_x^2+u_y^2}$ to define our $L^2$-error norm. The exact equation we have used is&lt;br /&gt;
\begin{equation}&lt;br /&gt;
L^2\text{-norm} = \sqrt{\frac{\int_\Omega (|\boldsymbol{u_{\text{numerical}}}|-|\boldsymbol{u_{\text{analytical}}}|)^2d\Omega}{\int_\Omega|\boldsymbol{u_{\text{analytical}}}|^2d\Omega}}.  &lt;br /&gt;
\end{equation}&lt;br /&gt;
Results are shown in &amp;lt;xr id=&amp;quot;fig:point_contact_convergence&amp;quot;/&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=Contact between parallel cylinders=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
* Theory of matrix structural analysis&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Solid_Mechanics&amp;diff=430</id>
		<title>Solid Mechanics</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Solid_Mechanics&amp;diff=430"/>
				<updated>2016-10-27T13:29:25Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Strain-displacement equations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Basic equations of elasticity=&lt;br /&gt;
&lt;br /&gt;
To determine the distribution of static stresses and displacements in a solid body we must obtain a solution (either analytically or numerically) to the basic equations of the theory of elasticity, satisfying the boundary conditions on forces and/or displacements. For a general three dimensional solid object these equations are:&lt;br /&gt;
* strain-displacement equations ($6$)&lt;br /&gt;
* stress-strain equations ($6$)&lt;br /&gt;
* equations of equilibrium ($3$)&lt;br /&gt;
where the number in brackets indicates the number of equations. We see there are $15$ equations for $15$ unknown variables ($6$ strains, $6$ stresses and $3$ displacements). In two dimensions this simplifies to $8$ equations with $2$ displacements, $3$ stresses, and $3$ strains.&lt;br /&gt;
&lt;br /&gt;
====Stress formulation====&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Linear_elasticity#Stress_formulation Stress formulation at Wikipedia]&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Stress_functions Stress functions at Wikipedia]&lt;br /&gt;
==Strain-displacement equations==&lt;br /&gt;
&lt;br /&gt;
Under the action of applied forces, a point in the solid originally at $(x,y,z)$ moves to position $(X,Y,Z)$. This movement can be described completely by the displacement vector&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\boldsymbol{u}(\boldsymbol{x}) = \{u_x(x,y,z) \quad u_y(x,y,z) \quad u_z(x,y,z)\},&lt;br /&gt;
\end{equation}&lt;br /&gt;
the brackets $\{\}$ indicating that this is a column vector.&lt;br /&gt;
&lt;br /&gt;
===Navier equation===&lt;br /&gt;
Navier equation describes the dynamic of a solid through the displacement vector field $\b{u}$. The equation is as follows&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\rho \frac{\partial^2 \b{u}}{\partial t^2} = \mu \nabla^2 \b{u} + (\lambda + \mu) \nabla(\nabla \cdot \b{u}) + \b{F}\ ,&lt;br /&gt;
\end{equation}&lt;br /&gt;
where $\mu$ and $\lambda$ are Lamé constants, $\rho$ is the object density and $\b{F}$ are the outside forces.&lt;br /&gt;
&lt;br /&gt;
==Stress-strain equations==&lt;br /&gt;
&lt;br /&gt;
===Two-dimensional stress distributions===&lt;br /&gt;
Many problems in elasticity can be simplified as two-dimensional problems described by ''plane theory of elasticity''. In general there are two types of problems we may encounter in plane analysis: '''plane stress''' and '''plane strain'''. The first problem arises in analysis of thin plates loaded in the plane of the plate, while the second is used for elongated bodies of constant cross section subject to uniform loading.&lt;br /&gt;
&lt;br /&gt;
====Plane stress====&lt;br /&gt;
&lt;br /&gt;
Plane stress distributions build on the assumption that the normal stress and shear stresses directed perpendicular to the $x$-$y$ plane are assumed zero:&lt;br /&gt;
\begin{equation}\label{eq:pstress_assump}&lt;br /&gt;
\sigma_{zz} = \sigma_{zx} = \sigma_{zy} = 0.&lt;br /&gt;
\end{equation}&lt;br /&gt;
It is also assumed that the stress components do not vary through the thickness of the plate (the assumptions do violate some compatibility conditions, but are still sufficiently accurate for practical applications if the plate is thin).&lt;br /&gt;
&lt;br /&gt;
Using (\ref{eq:pstress_assump}) the three-dimensional Hooke's law can be reduced to:&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
\sigma_{xx} \\&lt;br /&gt;
\sigma_{yy} \\&lt;br /&gt;
\sigma_{xy}&lt;br /&gt;
\end{bmatrix} &lt;br /&gt;
= \frac{E}{1-\nu^2}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
1 &amp;amp; \nu &amp;amp; 0 \\&lt;br /&gt;
\nu &amp;amp; 1 &amp;amp; 0 \\&lt;br /&gt;
0 &amp;amp; 0 &amp;amp; \frac{1-\nu}{2}&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
\varepsilon_{xx} \\&lt;br /&gt;
\varepsilon_{yy} \\&lt;br /&gt;
\varepsilon_{xy}&lt;br /&gt;
\end{bmatrix}  &lt;br /&gt;
\end{equation}&lt;br /&gt;
&lt;br /&gt;
====Plane strain====&lt;br /&gt;
&lt;br /&gt;
The plane strain problem arises in analysis of walls, dams, tunnels where one dimension of the structure is very large in comparison to the other two dimensions ($x$- and $y$- coordinates). It is also appropriate for small-scale problems such as bars and rollers compressed by forces normal to their cross section. In all such problems the body may be imagined as a prismatic cylinder with one dimension much larger that the other two. The applied forces act in the $x$-$y$ plane and do not vary in the $z$ direction, leading to the assumption&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\frac{\partial}{\partial z} = u_z = 0.&lt;br /&gt;
\end{equation} &lt;br /&gt;
&lt;br /&gt;
With the above assumption it follows immediately that&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\varepsilon_{zz} = \varepsilon_{zx} = \varepsilon_{zy} = 0.&lt;br /&gt;
\end{equation}&lt;br /&gt;
The three dimensional Hooke's law can now be reduced to&lt;br /&gt;
\begin{equation}\label{eq:planestrain}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
\sigma_{xx} \\&lt;br /&gt;
\sigma_{yy} \\&lt;br /&gt;
\sigma_{xy}&lt;br /&gt;
\end{bmatrix} &lt;br /&gt;
= \frac{E}{(1+\nu)(1-2\nu)}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
1-\nu &amp;amp; \nu &amp;amp; 0 \\&lt;br /&gt;
\nu &amp;amp; 1-\nu &amp;amp; 0 \\&lt;br /&gt;
0 &amp;amp; 0 &amp;amp; \frac{1-2\nu}{2}&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
\varepsilon_{xx} \\&lt;br /&gt;
\varepsilon_{yy} \\&lt;br /&gt;
\varepsilon_{xy}&lt;br /&gt;
\end{bmatrix}  &lt;br /&gt;
\end{equation}&lt;br /&gt;
\begin{equation}\label{eq:sigmazz}&lt;br /&gt;
\sigma_{zz} = \nu(\sigma_{xx}+\sigma_{yy})&lt;br /&gt;
\end{equation}&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\sigma_{yz} = \sigma_{zx} = 0&lt;br /&gt;
\end{equation}&lt;br /&gt;
The reason $\sigma_{zz}$ is not included in the matrix stress-strain equation (\ref{eq:planestrain}) is because it is linearly dependent on the normal stresses $\sigma_{xx}$ and $\sigma_{zz}$ as shown in (\ref{eq:sigmazz}).&lt;br /&gt;
&lt;br /&gt;
====Connection between plane stress and plane strain====&lt;br /&gt;
&lt;br /&gt;
For '''isotropic''' materials with elastic modulus $E$ and Poisson's ratio $\nu$ it is possible to go from plane stress to plane strain, or vice-versa, by replacing $E$ and $\nu$ in the stress-strain matrix with a fictitious modulus $E^*$ and fictitious Poisson ratio $\nu^*$. This allows us to &amp;quot;reuse&amp;quot; plane stress program to solve plane strain or again vice-versa (as long as the material is isotropic).&lt;br /&gt;
&lt;br /&gt;
To go from plane stres'''s''' (s) to plane strai'''n''' (n) the fictitious quantities $E^*$ and $\nu^*$ are&lt;br /&gt;
\begin{equation}&lt;br /&gt;
E_n^* = \frac{E_s}{1-\nu_s^2},&lt;br /&gt;
\end{equation}&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\nu_n^* = \frac{\nu_s}{1-\nu_s}.&lt;br /&gt;
\end{equation}&lt;br /&gt;
In the opposite case we want to go from plane strai'''n''' (n) to plane stres'''s''' (s) we can use:&lt;br /&gt;
\begin{equation}&lt;br /&gt;
E_s^* = E_n(1-\nu_n^2),&lt;br /&gt;
\end{equation}&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\nu_s^* = \frac{\nu_n}{1+\nu_n}.&lt;br /&gt;
\end{equation}&lt;br /&gt;
&lt;br /&gt;
Once the type of problem has been defined it is convenient to work in terms of ''Lamé constants'' $\lambda$ and $\mu$ which are expressed in terms of $E$ and $\nu$ by&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\lambda = \frac{E\nu}{(1+\nu)(1-2\nu)}, \qquad \mu = G = \frac{E}{2(1+\nu)}.&lt;br /&gt;
\end{equation}&lt;br /&gt;
&lt;br /&gt;
==Equations of equilibrium==&lt;br /&gt;
&lt;br /&gt;
==Tonti diagram==&lt;br /&gt;
&lt;br /&gt;
=Point contact on a 2D half-plane=&lt;br /&gt;
&lt;br /&gt;
A starting point to solve problems in contact mechanics is to understand the effect of a point-load applied to a homogeneous, linear elastic, isotropic half-plane. This problem may be defined either as plane stress or plain strain (for solution with FreeFem++ we have choosen the latter). The traction boundary conditions for this problem are:&lt;br /&gt;
\begin{equation}\label{eq:bc}&lt;br /&gt;
\sigma_{xy}(x,0) = 0, \quad \sigma_{yy}(x,y) = -P\delta(x,y)&lt;br /&gt;
\end{equation}&lt;br /&gt;
where $\delta(x,y)$ is the Dirac delta function. Together these boundary conditions state that there is a singular normal force $P$ applied at $(x,y) = (0,0)$ and there are no shear stresses on the surface of the elastic half-plane.&lt;br /&gt;
&lt;br /&gt;
The analytical relations for the stresses can be found from the [https://en.wikipedia.org/wiki/Flamant_solution Flamant solution] (stress distributions in a linear elastic wedge loaded by point forces a the tip. When the &amp;quot;wedge&amp;quot; is flat we get a half-plane. The derivation uses polar coordinates.) and are given as:&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\sigma_{xx} = -\frac{2P}{\pi} \frac{x^2y}{\left(x^2+y^2\right)^2},&lt;br /&gt;
\end{equation}&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\sigma_{xy} = -\frac{2P}{\pi} \frac{y^3}{\left(x^2+y^2\right)^2},&lt;br /&gt;
\end{equation}&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\sigma_{yy} = -\frac{2P}{\pi} \frac{xy^2}{\left(x^2+y^2\right)^2},&lt;br /&gt;
\end{equation}&lt;br /&gt;
for some point $(x,y)$ in the half-plane. From this stress field the strain components and thus the displacements $(u,v)$ can be determined. The displacements are given by&lt;br /&gt;
\begin{align}&lt;br /&gt;
u_x &amp;amp;= -\frac{P}{4\pi\mu}\left((\kappa-1)\theta - \frac{2xy}{r^2}\right), \label{eq:dispx}\\&lt;br /&gt;
u_y &amp;amp;= -\frac{P}{4\pi\mu}\left((\kappa+1)\log r - \frac{2y^2}{r^2}\right), \label{eq:dispy}&lt;br /&gt;
\end{align}&lt;br /&gt;
where $$r = \sqrt{x^2+y^2}$$ and $$\tan \theta = \frac{x}{y}.$$ The symbol $\kappa$ is known as Dundars constant and is defined as&lt;br /&gt;
\[&lt;br /&gt;
\kappa = \begin{cases} 3 - 4\nu &amp;amp; \qquad \text{plane strain}, \\&lt;br /&gt;
                       \cfrac{3 - \nu}{1+\nu} &amp;amp; \qquad \text{plane stress}. \end{cases}&lt;br /&gt;
\]&lt;br /&gt;
The last remaining symbol is $\mu$ which represents the shear modulus (sometimes also denoted with $G$).&lt;br /&gt;
&lt;br /&gt;
==Numerical solution with [http://www.freefem.org/ FreeFem++]==&lt;br /&gt;
Due to the known analytical solution the point-contact problem can be used for benchmarking numerical PDE solvers in terms of accuracy (as well as computational efficiency). The purpose of this section is to compare the numerical solution obtained by FreeFem++ with the analytical solution, as well as provide a reference numerical solution for the [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/wiki/index.php/Main_Page C++ library] developed in our laboratory.&lt;br /&gt;
&lt;br /&gt;
For purposes of simplicity we limit ourselves to the domain $(x,y) \in \Omega = [-1,1] \times[-1,-0.1]$ and prescribe Dirichlet displacement on the boundaries $\Gamma_D$ from the known analytical solution (\ref{eq:dispx}, \ref{eq:dispy}). This way we avoid having to deal with the Dirac delta traction boundary condition (\ref{eq:bc}). The problem can be describes as find $\boldsymbol{u(\boldsymbol{x})}$ that satisfies&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\boldsymbol{\nabla}\cdot\boldsymbol{\sigma}= 0 \qquad \text{on }\Omega&lt;br /&gt;
\end{equation}&lt;br /&gt;
and&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\boldsymbol{u} = \boldsymbol{u}_{\text{analytical}} \qquad \text{on }\Gamma_D&lt;br /&gt;
\end{equation}&lt;br /&gt;
where $\boldsymbol{u}_\text{analytical}$ is given in equations (\ref{eq:dispx}) and (\ref{eq:dispy}).&lt;br /&gt;
&lt;br /&gt;
To solve the point-contact problem in FreeFem++ we must first provide the weak form of the balance equation:&lt;br /&gt;
\begin{equation*}&lt;br /&gt;
\boldsymbol{\nabla}\cdot\boldsymbol{\sigma} + \boldsymbol{b} = 0.&lt;br /&gt;
\end{equation*}&lt;br /&gt;
The corresponding weak formulation is&lt;br /&gt;
\begin{equation}\label{eq:weak}&lt;br /&gt;
\int_\Omega \boldsymbol{\sigma} : \boldsymbol{\varepsilon}(\boldsymbol{v}) \, d\Omega - \int_\Omega \boldsymbol{b}\cdot\boldsymbol{v}\,d\Omega = 0&lt;br /&gt;
\end{equation}&lt;br /&gt;
where $:$ denotes the tensor scalar product (tensor contraction), i.e. $\boldsymbol{A}:\boldsymbol{B} =\sum_{i,j} A_{ij}B_{ij}$. The vector $\boldsymbol{v}$ is the test function or so-called &amp;quot;virtual displacement&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Equation (\ref{eq:weak}) can be handed to FreeFem++ with the help of Voigt or Mandel notation, that reduces the symmetric tensors $\boldsymbol{\sigma}$ and $\boldsymbol{\varepsilon}$ to vectors. The benefit of Mandel notation is that it allows the tensor scalar product to be performed as a scalar product of two vectors.&lt;br /&gt;
For this reason we create the following macros:&lt;br /&gt;
 macro u [ux,uy] // displacements&lt;br /&gt;
 macro v [vx,vy] // test function&lt;br /&gt;
 macro b [bx,by] // body forces&lt;br /&gt;
 macro e(u) [dx(u[0]),dy(u[1]),(dx(u[1])+dy(u[0]))/2] // strain (for post-processing)&lt;br /&gt;
 macro em(u) [dx(u[0]),dy(u[1]),sqrt(2)*(dx(u[1])+dy(u[0]))/2] // strain in Mandel notation&lt;br /&gt;
 macro A [[2*mu+lambda,mu,0],[mu,2*mu+lambda,0],[0,0,2*mu]] // stress-strain matrix&lt;br /&gt;
&lt;br /&gt;
The weak form (\ref{eq:weak}) can then be expressed naturally in FreeFem++ syntax as&lt;br /&gt;
 int2d(Th)((A*em(u))'*em(v)) - int2d(Th)(b'*v)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Stress and displacement fields===&lt;br /&gt;
&lt;br /&gt;
===Convergence studies===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;figure id=&amp;quot;fig:point_contact_convergence&amp;quot;&amp;gt;&lt;br /&gt;
[[File:Convergence.png|thumb|upright=2|&amp;lt;caption&amp;gt;Convergence results for the point contact problem. The colours blue, red and green represent linear, quadratic and cubic finite elements, respectively.&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the convergence between analytical and numerical solution we vary the number of nodes by increasing the grid size in both $x$- and $y$- directions simultaneously by powers of two from $2^2$ (16 nodes all together) to $2^7$ (16384 nodes all together).&lt;br /&gt;
The $L^2$ error norm is used to measure the &amp;quot;difference&amp;quot; between solutions. Since the displacements are the variable that obtain from FreeFem++, we use the displacement magnitude $|\boldsymbol{u}| = \sqrt{u_x^2+u_y^2}$ to define our $L^2$-error norm. The exact equation we have used is&lt;br /&gt;
\begin{equation}&lt;br /&gt;
L^2\text{-norm} = \sqrt{\frac{\int_\Omega (|\boldsymbol{u_{\text{numerical}}}|-|\boldsymbol{u_{\text{analytical}}}|)^2d\Omega}{\int_\Omega|\boldsymbol{u_{\text{analytical}}}|^2d\Omega}}.  &lt;br /&gt;
\end{equation}&lt;br /&gt;
Results are shown in &amp;lt;xr id=&amp;quot;fig:point_contact_convergence&amp;quot;/&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=Contact between parallel cylinders=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
* Theory of matrix structural analysis&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	<entry>
		<id>http://e6.ijs.si/medusa/wiki/index.php?title=Solid_Mechanics&amp;diff=423</id>
		<title>Solid Mechanics</title>
		<link rel="alternate" type="text/html" href="http://e6.ijs.si/medusa/wiki/index.php?title=Solid_Mechanics&amp;diff=423"/>
				<updated>2016-10-27T13:07:21Z</updated>
		
		<summary type="html">&lt;p&gt;Mkolman: /* Connection between plane stress and plane strain */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Basic equations of elasticity=&lt;br /&gt;
&lt;br /&gt;
To determine the distribution of static stresses and displacements in a solid body we must obtain a solution (either analytically or numerically) to the basic equations of the theory of elasticity, satisfying the boundary conditions on forces and/or displacements. For a general three dimensional solid object these equations are:&lt;br /&gt;
* strain-displacement equations ($6$)&lt;br /&gt;
* stress-strain equations ($6$)&lt;br /&gt;
* equations of equilibrium ($3$)&lt;br /&gt;
where the number in brackets indicates the number of equations. We see there are $15$ equations for $15$ unknown variables ($6$ strains, $6$ stresses and $3$ displacements). In two dimensions this simplifies to $8$ equations with $2$ displacements, $3$ stresses, and $3$ strains.&lt;br /&gt;
&lt;br /&gt;
====Stress formulation====&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Linear_elasticity#Stress_formulation Stress formulation at Wikipedia]&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Stress_functions Stress functions at Wikipedia]&lt;br /&gt;
==Strain-displacement equations==&lt;br /&gt;
&lt;br /&gt;
Under the action of applied forces, a point in the solid originally at $(x,y,z)$ moves to position $(X,Y,Z)$. This movement can be described completely by the displacement vector&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\boldsymbol{u(\boldsymbol{x})} = \{u_x(x,y,z) \quad u_y(x,y,z) \quad u_z(x,y,z)\},&lt;br /&gt;
\end{equation}&lt;br /&gt;
the brackets $\{\}$ indicating that this is a column vector.&lt;br /&gt;
&lt;br /&gt;
==Stress-strain equations==&lt;br /&gt;
&lt;br /&gt;
===Two-dimensional stress distributions===&lt;br /&gt;
Many problems in elasticity can be simplified as two-dimensional problems described by ''plane theory of elasticity''. In general there are two types of problems we may encounter in plane analysis: '''plane stress''' and '''plane strain'''. The first problem arises in analysis of thin plates loaded in the plane of the plate, while the second is used for elongated bodies of constant cross section subject to uniform loading.&lt;br /&gt;
&lt;br /&gt;
====Plane stress====&lt;br /&gt;
&lt;br /&gt;
Plane stress distributions build on the assumption that the normal stress and shear stresses directed perpendicular to the $x$-$y$ plane are assumed zero:&lt;br /&gt;
\begin{equation}\label{eq:pstress_assump}&lt;br /&gt;
\sigma_{zz} = \sigma_{zx} = \sigma_{zy} = 0.&lt;br /&gt;
\end{equation}&lt;br /&gt;
It is also assumed that the stress components do not vary through the thickness of the plate (the assumptions do violate some compatibility conditions, but are still sufficiently accurate for practical applications if the plate is thin).&lt;br /&gt;
&lt;br /&gt;
Using (\ref{eq:pstress_assump}) the three-dimensional Hooke's law can be reduced to:&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
\sigma_{xx} \\&lt;br /&gt;
\sigma_{yy} \\&lt;br /&gt;
\sigma_{xy}&lt;br /&gt;
\end{bmatrix} &lt;br /&gt;
= \frac{E}{1-\nu^2}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
1 &amp;amp; \nu &amp;amp; 0 \\&lt;br /&gt;
\nu &amp;amp; 1 &amp;amp; 0 \\&lt;br /&gt;
0 &amp;amp; 0 &amp;amp; \frac{1-\nu}{2}&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
\varepsilon_{xx} \\&lt;br /&gt;
\varepsilon_{yy} \\&lt;br /&gt;
\varepsilon_{xy}&lt;br /&gt;
\end{bmatrix}  &lt;br /&gt;
\end{equation}&lt;br /&gt;
&lt;br /&gt;
====Plane strain====&lt;br /&gt;
&lt;br /&gt;
The plane strain problem arises in analysis of walls, dams, tunnels where one dimension of the structure is very large in comparison to the other two dimensions ($x$- and $y$- coordinates). It is also appropriate for small-scale problems such as bars and rollers compressed by forces normal to their cross section. In all such problems the body may be imagined as a prismatic cylinder with one dimension much larger that the other two. The applied forces act in the $x$-$y$ plane and do not vary in the $z$ direction, leading to the assumption&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\frac{\partial}{\partial z} = u_z = 0.&lt;br /&gt;
\end{equation} &lt;br /&gt;
&lt;br /&gt;
With the above assumption it follows immediately that&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\varepsilon_{zz} = \varepsilon_{zx} = \varepsilon_{zy} = 0.&lt;br /&gt;
\end{equation}&lt;br /&gt;
The three dimensional Hooke's law can now be reduced to&lt;br /&gt;
\begin{equation}\label{eq:planestrain}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
\sigma_{xx} \\&lt;br /&gt;
\sigma_{yy} \\&lt;br /&gt;
\sigma_{xy}&lt;br /&gt;
\end{bmatrix} &lt;br /&gt;
= \frac{E}{(1+\nu)(1-2\nu)}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
1-\nu &amp;amp; \nu &amp;amp; 0 \\&lt;br /&gt;
\nu &amp;amp; 1-\nu &amp;amp; 0 \\&lt;br /&gt;
0 &amp;amp; 0 &amp;amp; \frac{1-2\nu}{2}&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
\varepsilon_{xx} \\&lt;br /&gt;
\varepsilon_{yy} \\&lt;br /&gt;
\varepsilon_{xy}&lt;br /&gt;
\end{bmatrix}  &lt;br /&gt;
\end{equation}&lt;br /&gt;
\begin{equation}\label{eq:sigmazz}&lt;br /&gt;
\sigma_{zz} = \nu(\sigma_{xx}+\sigma_{yy})&lt;br /&gt;
\end{equation}&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\sigma_{yz} = \sigma_{zx} = 0&lt;br /&gt;
\end{equation}&lt;br /&gt;
The reason $\sigma_{zz}$ is not included in the matrix stress-strain equation (\ref{eq:planestrain}) is because it is linearly dependent on the normal stresses $\sigma_{xx}$ and $\sigma_{zz}$ as shown in (\ref{eq:sigmazz}).&lt;br /&gt;
&lt;br /&gt;
====Connection between plane stress and plane strain====&lt;br /&gt;
&lt;br /&gt;
For '''isotropic''' materials with elastic modulus $E$ and Poisson's ratio $\nu$ it is possible to go from plane stress to plane strain, or vice-versa, by replacing $E$ and $\nu$ in the stress-strain matrix with a fictitious modulus $E^*$ and fictitious Poisson ratio $\nu^*$. This allows us to &amp;quot;reuse&amp;quot; plane stress program to solve plane strain or again vice-versa (as long as the material is isotropic).&lt;br /&gt;
&lt;br /&gt;
To go from plane stres'''s''' (s) to plane strai'''n''' (n) the fictitious quantities $E^*$ and $\nu^*$ are&lt;br /&gt;
\begin{equation}&lt;br /&gt;
E_n^* = \frac{E_s}{1-\nu_s^2},&lt;br /&gt;
\end{equation}&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\nu_n^* = \frac{\nu_s}{1-\nu_s}.&lt;br /&gt;
\end{equation}&lt;br /&gt;
In the opposite case we want to go from plane strai'''n''' (n) to plane stres'''s''' (s) we can use:&lt;br /&gt;
\begin{equation}&lt;br /&gt;
E_s^* = E_n(1-\nu_n^2),&lt;br /&gt;
\end{equation}&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\nu_s^* = \frac{\nu_n}{1+\nu_n}.&lt;br /&gt;
\end{equation}&lt;br /&gt;
&lt;br /&gt;
Once the type of problem has been defined it is convenient to work in terms of ''Lamé constants'' $\lambda$ and $\mu$ which are expressed in terms of $E$ and $\nu$ by&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\lambda = \frac{E\nu}{(1+\nu)(1-2\nu)}, \qquad \mu = G = \frac{E}{2(1+\nu)}.&lt;br /&gt;
\end{equation}&lt;br /&gt;
&lt;br /&gt;
==Equations of equilibrium==&lt;br /&gt;
&lt;br /&gt;
==Tonti diagram==&lt;br /&gt;
&lt;br /&gt;
=Point contact on a 2D half-plane=&lt;br /&gt;
&lt;br /&gt;
A starting point to solve problems in contact mechanics is to understand the effect of a point-load applied to a homogeneous, linear elastic, isotropic half-plane. This problem may be defined either as plane stress or plain strain (for solution with FreeFem++ we have choosen the latter). The traction boundary conditions for this problem are:&lt;br /&gt;
\begin{equation}\label{eq:bc}&lt;br /&gt;
\sigma_{xy}(x,0) = 0, \quad \sigma_{yy}(x,y) = -P\delta(x,y)&lt;br /&gt;
\end{equation}&lt;br /&gt;
where $\delta(x,y)$ is the Dirac delta function. Together these boundary conditions state that there is a singular normal force $P$ applied at $(x,y) = (0,0)$ and there are no shear stresses on the surface of the elastic half-plane.&lt;br /&gt;
&lt;br /&gt;
The analytical relations for the stresses can be found from the [https://en.wikipedia.org/wiki/Flamant_solution Flamant solution] (stress distributions in a linear elastic wedge loaded by point forces a the tip. When the &amp;quot;wedge&amp;quot; is flat we get a half-plane. The derivation uses polar coordinates.) and are given as:&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\sigma_{xx} = -\frac{2P}{\pi} \frac{x^2y}{\left(x^2+y^2\right)^2},&lt;br /&gt;
\end{equation}&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\sigma_{xy} = -\frac{2P}{\pi} \frac{y^3}{\left(x^2+y^2\right)^2},&lt;br /&gt;
\end{equation}&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\sigma_{yy} = -\frac{2P}{\pi} \frac{xy^2}{\left(x^2+y^2\right)^2},&lt;br /&gt;
\end{equation}&lt;br /&gt;
for some point $(x,y)$ in the half-plane. From this stress field the strain components and thus the displacements $(u,v)$ can be determined. The displacements are given by&lt;br /&gt;
\begin{align}&lt;br /&gt;
u_x &amp;amp;= -\frac{P}{4\pi\mu}\left((\kappa-1)\theta - \frac{2xy}{r^2}\right), \label{eq:dispx}\\&lt;br /&gt;
u_y &amp;amp;= -\frac{P}{4\pi\mu}\left((\kappa+1)\log r - \frac{2y^2}{r^2}\right), \label{eq:dispy}&lt;br /&gt;
\end{align}&lt;br /&gt;
where $$r = \sqrt{x^2+y^2}$$ and $$\tan \theta = \frac{x}{y}.$$ The symbol $\kappa$ is known as Dundars constant and is defined as&lt;br /&gt;
\[&lt;br /&gt;
\kappa = \begin{cases} 3 - 4\nu &amp;amp; \qquad \text{plane strain}, \\&lt;br /&gt;
                       \cfrac{3 - \nu}{1+\nu} &amp;amp; \qquad \text{plane stress}. \end{cases}&lt;br /&gt;
\]&lt;br /&gt;
The last remaining symbol is $\mu$ which represents the shear modulus (sometimes also denoted with $G$).&lt;br /&gt;
&lt;br /&gt;
==Numerical solution with [http://www.freefem.org/ FreeFem++]==&lt;br /&gt;
Due to the known analytical solution the point-contact problem can be used for benchmarking numerical PDE solvers in terms of accuracy (as well as computational efficiency). The purpose of this section is to compare the numerical solution obtained by FreeFem++ with the analytical solution, as well as provide a reference numerical solution for the [http://www-e6.ijs.si/ParallelAndDistributedSystems/MeshlessMachine/wiki/index.php/Main_Page C++ library] developed in our laboratory.&lt;br /&gt;
&lt;br /&gt;
For purposes of simplicity we limit ourselves to the domain $(x,y) \in \Omega = [-1,1] \times[-1,-0.1]$ and prescribe Dirichlet displacement on the boundaries $\Gamma_D$ from the known analytical solution (\ref{eq:dispx}, \ref{eq:dispy}). This way we avoid having to deal with the Dirac delta traction boundary condition (\ref{eq:bc}). The problem can be describes as find $\boldsymbol{u(\boldsymbol{x})}$ that satisfies&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\boldsymbol{\nabla}\cdot\boldsymbol{\sigma}= 0 \qquad \text{on }\Omega&lt;br /&gt;
\end{equation}&lt;br /&gt;
and&lt;br /&gt;
\begin{equation}&lt;br /&gt;
\boldsymbol{u} = \boldsymbol{u}_{\text{analytical}} \qquad \text{on }\Gamma_D&lt;br /&gt;
\end{equation}&lt;br /&gt;
where $\boldsymbol{u}_\text{analytical}$ is given in equations (\ref{eq:dispx}) and (\ref{eq:dispy}).&lt;br /&gt;
&lt;br /&gt;
To solve the point-contact problem in FreeFem++ we must first provide the weak form of the balance equation:&lt;br /&gt;
\begin{equation*}&lt;br /&gt;
\boldsymbol{\nabla}\cdot\boldsymbol{\sigma} + \boldsymbol{b} = 0.&lt;br /&gt;
\end{equation*}&lt;br /&gt;
The corresponding weak formulation is&lt;br /&gt;
\begin{equation}\label{eq:weak}&lt;br /&gt;
\int_\Omega \boldsymbol{\sigma} : \boldsymbol{\varepsilon}(\boldsymbol{v}) \, d\Omega - \int_\Omega \boldsymbol{b}\cdot\boldsymbol{v}\,d\Omega = 0&lt;br /&gt;
\end{equation}&lt;br /&gt;
where $:$ denotes the tensor scalar product (tensor contraction), i.e. $\boldsymbol{A}:\boldsymbol{B} =\sum_{i,j} A_{ij}B_{ij}$. The vector $\boldsymbol{v}$ is the test function or so-called &amp;quot;virtual displacement&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Equation (\ref{eq:weak}) can be handed to FreeFem++ with the help of Voigt or Mandel notation, that reduces the symmetric tensors $\boldsymbol{\sigma}$ and $\boldsymbol{\varepsilon}$ to vectors. The benefit of Mandel notation is that it allows the tensor scalar product to be performed as a scalar product of two vectors.&lt;br /&gt;
For this reason we create the following macros:&lt;br /&gt;
 macro u [ux,uy] // displacements&lt;br /&gt;
 macro v [vx,vy] // test function&lt;br /&gt;
 macro b [bx,by] // body forces&lt;br /&gt;
 macro e(u) [dx(u[0]),dy(u[1]),(dx(u[1])+dy(u[0]))/2] // strain (for post-processing)&lt;br /&gt;
 macro em(u) [dx(u[0]),dy(u[1]),sqrt(2)*(dx(u[1])+dy(u[0]))/2] // strain in Mandel notation&lt;br /&gt;
 macro A [[2*mu+lambda,mu,0],[mu,2*mu+lambda,0],[0,0,2*mu]] // stress-strain matrix&lt;br /&gt;
&lt;br /&gt;
The weak form (\ref{eq:weak}) can then be expressed naturally in FreeFem++ syntax as&lt;br /&gt;
 int2d(Th)((A*em(u))'*em(v)) - int2d(Th)(b'*v)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Stress and displacement fields===&lt;br /&gt;
&lt;br /&gt;
===Convergence studies===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;figure id=&amp;quot;fig:point_contact_convergence&amp;quot;&amp;gt;&lt;br /&gt;
[[File:Convergence.png|thumb|upright=2|&amp;lt;caption&amp;gt;Convergence results for the point contact problem. The colours blue, red and green represent linear, quadratic and cubic finite elements, respectively.&amp;lt;/caption&amp;gt;]]&lt;br /&gt;
&amp;lt;/figure&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the convergence between analytical and numerical solution we vary the number of nodes by increasing the grid size in both $x$- and $y$- directions simultaneously by powers of two from $2^2$ (16 nodes all together) to $2^7$ (16384 nodes all together).&lt;br /&gt;
The $L^2$ error norm is used to measure the &amp;quot;difference&amp;quot; between solutions. Since the displacements are the variable that obtain from FreeFem++, we use the displacement magnitude $|\boldsymbol{u}| = \sqrt{u_x^2+u_y^2}$ to define our $L^2$-error norm. The exact equation we have used is&lt;br /&gt;
\begin{equation}&lt;br /&gt;
L^2\text{-norm} = \sqrt{\frac{\int_\Omega (|\boldsymbol{u_{\text{numerical}}}|-|\boldsymbol{u_{\text{analytical}}}|)^2d\Omega}{\int_\Omega|\boldsymbol{u_{\text{analytical}}}|^2d\Omega}}.  &lt;br /&gt;
\end{equation}&lt;br /&gt;
Results are shown in &amp;lt;xr id=&amp;quot;fig:point_contact_convergence&amp;quot;/&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=Contact between parallel cylinders=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
* Theory of matrix structural analysis&lt;/div&gt;</summary>
		<author><name>Mkolman</name></author>	</entry>

	</feed>