<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
<?xml-stylesheet type="text/css" href="http://www.stefan-kroboth.com/styles/feed.css"?>


<title type="html">Stefan Kroboth</title>
<subtitle type="html">fork while fork;</subtitle>
<link rel="alternate" type="text/html" href="http://www.stefan-kroboth.com"/>
<link rel="self" type="application/atom+xml" href="http://www.stefan-kroboth.com/atom.xml"/>
<updated>2011-09-12T16:01:42+02:00</updated>
<author>
<name>Stefan</name>
<uri>http://www.stefan-kroboth.com</uri>
</author>
<id>http://www.stefan-kroboth.com/</id>
<generator uri="http://nanoblogger.sourceforge.net" version="3.4.2">
NanoBlogger
</generator>

<entry>
<title type="html">CUDA, AGILE and gcc version problems</title>
<author>
<name>Stefan</name>
</author>
<link rel="alternate" type="text/html" href="http://www.stefan-kroboth.com/archives/2011/09/12/cuda_agile_and_gcc_version_problems/index.html"/>

<id>http://www.stefan-kroboth.com/archives/2011/09/12/cuda_agile_and_gcc_version_problems/index.html</id>
<published>2011-09-12T15:22:43+02:00</published>
<updated>2011-09-12T15:22:43+02:00</updated>
<category term="gpu_programming" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">

A very annoying error you might stumble upon when compiling CUDA code is this one:<br><br>
<code>
/usr/include/c++/4.5/iomanip(64): error: expected an expression<br>

/usr/include/c++/4.5/iomanip(94): error: expected an expression<br>

/usr/include/c++/4.5/iomanip(125): error: expected an expression<br>

/usr/include/c++/4.5/iomanip(193): error: expected an expression<br>

/usr/include/c++/4.5/iomanip(223): error: expected an expression
</code><br><br>

It took me a while to find out what is causing this error message.<br>

It seems that Nvidias CUDA compiler <code>nvcc</code> keeps lagging behind gcc. Currently it is not possible to run the <code>nvcc</code> with gcc-4.5 although gcc-4.4 works fine.
This means that it is necessary to switch back to gcc-4.4 on your system, preferably using update-alternatives. But in some cases you can't just change the gcc version globally since other
users might be working on the same system and rely on a recent gcc version. Nvidia doesn't provide a convenient way to tell <code>nvcc</code> to just use a different compiler. 
I will now show some ways to solve this problem, depending on different situations.

<br><br>

<b>You can use another version without conflicts: update-alternatives</b>
<br><br>
Just register gcc-4.4 with update-alternatives using the following command (make sure to use the right paths): <br><br>
<code>update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 44 --slave /usr/bin/g++ g++ /usr/bin/g++-4.4</code><br><br>

And change to another gcc version using:<br><br>
<code>update-alternatives --config gcc</code>
<br><br>

You should now be able to use <code>nvcc</code> without problems.<br><br>

<b>Switching to another gcc version is not possible (e.g. working on a shared server)</b><br><br>

This means that you need to tell <code>nvcc</code> to use another gcc compiler instead of changing the gcc version for the whole system. 
Sounds easy, and it is easy, but pretty inconvenient. 
First of all, create a directory where you'll put symlinks to your desired gcc (and g++) compiler(s):
<br><br>
<code>cd /home/username<br>
mkdir .compilers<br>
cd .compilers</code><br><br>

Now create the symlinks mentioned above (the paths might differ on your system):<br><br>

<code>ln -s gcc /usr/bin/gcc-4.4<br>
ln -s g++ /usr/bin/g++-4.4<br>
ln -s c++ /usr/bin/g++-4.4</code><br><br>

To tell nvcc which gcc compilers to use, pass it this option:<br><br> 
<code>--compiler-bindir=/home/username/.compilers</code><br><br>

<b>AGILE</b><br><br>
AGILE uses Cmake, which makes passing the option a bit more <strike>annoying</strike>complicated. Run this in your AGILE build directory:<br><br>
<code>cmake -DCUDA_NVCC_FLAGS_RELEASE:STRING="--compiler-bindir=/home/username/.compilers" ..<br>
make</code><br><br>
</div>
</content>

</entry>
<entry>
<title type="html">Calling a MATLAB Function from the Terminal or Perl</title>
<author>
<name>Stefan</name>
</author>
<link rel="alternate" type="text/html" href="http://www.stefan-kroboth.com/archives/2011/08/16/calling_a_matlab_function_from_the_terminal_or_perl/index.html"/>

<id>http://www.stefan-kroboth.com/archives/2011/08/16/calling_a_matlab_function_from_the_terminal_or_perl/index.html</id>
<published>2011-08-16T16:50:46+02:00</published>
<updated>2011-08-16T16:50:46+02:00</updated>
<category term="perl" />
<category term="matlab" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">

Whenever I have to deal with Matlab functions from the terminal I run into the same problems. The main problem is that
you can't see what really gets to Matlab after passing the string containing the Matlab code/function. This makes it hard to find the source of the issue. 
Sometimes the terminal keeps complaining and sometimes Matlab itself. <br><br>

Suppose you'd like to run the following command:
<br><br>
<code> 
myfunction('somestring',42)
</code>
<br><br>

In the terminal, you could run it like this:
<br><br>

<code>
matlab -nojvm -nodisplay -r myfunction('somestring',42)
</code>
<br><br>

Never forget to include <code>-nojvm -nodisplay</code>, otherwise the whole GUI stuff pops up.
However, the shell is not so happy with that command:
<br><br>

<code>
zsh: unknown file attribute
</code>
<br><br>

It took me a while to find out what thats supposed to mean: The brackets have to be escaped.
<br><br>

<code>
matlab -nojvm -nodisplay -r myfunction\('somestring',42\)
</code>
<br><br>

The next error message is a lot easier to understand and comes from Matlab itself:
<br><br>

<code>
??? Undefined function or variable 'somestring'
</code>
<br><br>

This just means that the single quotes must be escaped as well.
<br><br>

<code>
matlab -nojvm -nodisplay -r myfunction\(\'somestring\',42\)
</code>
<br><br>

If you need to call the function from Perl it is necessary to escape the backslashes:
<br><br>

<code>
system("matlab -nojvm -nodisplay -r myfunction\\(\\'somestring\\',42\\)")
</code>
<br><br>

Don't forget to include the <code>exit</code> command somewhere at the end of your Matlab script, otherwise Matlab will keep running until you quit it manually.
</div>
</content>

</entry>
<entry>
<title type="html">AGILE: GPU Library for Image Reconstruction</title>
<author>
<name>Stefan</name>
</author>
<link rel="alternate" type="text/html" href="http://www.stefan-kroboth.com/archives/2011/07/04/agile_gpu_library_for_image_reconstruction/index.html"/>

<id>http://www.stefan-kroboth.com/archives/2011/07/04/agile_gpu_library_for_image_reconstruction/index.html</id>
<published>2011-07-04T21:37:13+02:00</published>
<updated>2011-07-04T21:37:13+02:00</updated>
<category term="image_reconstruction" />
<category term="gpu_programming" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">

The open source GPU Library 
<a href="http://www.imt.tugraz.at/index.php/research/agile-gpu-image-reconstruction-library">AGILE</a> 
(Environment for Linear and non-linear Image reconstruction using Gpu Acceleration) accelerates image reconstruction problems in medical imaging using the power of modern GPUs. 
<br><br>
AGILE is based on CUDA (needs a Nvidia graphics card) and provides several features and a sophisticated template design. It also comes with some example code for Magnetic Resonance Imaging and Fluorescence Tomography.
<br><br>
The first version of AGILE was recently released at the ISMRM [1] and can be downloaded at the Website of the <a href="http://www.imt.tugraz.at/">Institute of Medical Engineering</a> (Graz University of Technology). 
<br><br>
I had the chance to work with the library prior to its release as part of a project on fast MRI image reconstruction. 
From the things I've seen while working on this project, I can say it's worth a look if you're interested in image reconstruction on GPUs. 


<br><br>
[1] Knoll, F.; Freiberger, M.; Bredies, K.; Stollberger, R.: AGILE: An open source library for image reconstruction using graphics card hardware acceleration. Proc. Intl. Soc. Mag. Reson. Med. 19:2554 (2011).
</div>
</content>

</entry>
<entry>
<title type="html">Initialize</title>
<author>
<name>Stefan</name>
</author>
<link rel="alternate" type="text/html" href="http://www.stefan-kroboth.com/archives/2011/07/04/initialize/index.html"/>

<id>http://www.stefan-kroboth.com/archives/2011/07/04/initialize/index.html</id>
<published>2011-07-04T21:31:50+02:00</published>
<updated>2011-07-04T21:31:50+02:00</updated>
<category term="general" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">

I've tried writing a blog several times before but failed miserably at every attempt. Hopefully this is going to change now. Nanoblogger makes it possible to write entries in vim, which might be just the motivation I need. <br><br>

I will try to keep this blog mainly about programming and possibly some image reconstruction. <br><br>

Having a comment function just reminds me of how boring my blog is, so I won't go through the hassle of integrating one (feel free to contact me via email). 
You also won't see any annoying social network schmarrn here.
</div>
</content>

</entry>

</feed>

