<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated on Fri, 25 May 2012 06:23:39 -0700 -->
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <atom:link href="http://software.intel.com/en-us/articles/open-source/type/tutorials/feed/" rel="self" type="application/rss+xml" />
    <title>Intel Software Network articles Feed</title>
    <link>http://software.intel.com/en-us/articles/open-source/type/tutorials/</link>
    <description></description>
    <language>en-us</language>
    <item>
      <title>How to build GCC* cilkplus branch in 64bit Ubuntu* 12.04</title>
      <description><![CDATA[ <div id="art_pre_template"><b>Introduction</b>:</div>
<div id="art_pre_template">Intel® Cilk™ Plus is an open source project now. It is supported in GCC* 4.7 but still not merged into the released GCC* 4.7.0 version. We can build the 'cilkplus' branch of GCC* to make it support the Intel® Cilk™ Plus extensions. The steps are exact same with building GCC* upstream code, so this article is targeted for those who are not familiar with building GCC and want to use Cilk Plus with GCC.<br /></div>
<div id="art_pre_template"><br /></div>
<div id="art_pre_template">(1) <b>Preparation</b></div>
<div id="art_pre_template">OS: Ubuntu* 12.04 LTS beta2 64bit.</div>
<div id="art_pre_template">Install following packages before building GCC Cilk Plus:</div>
<div id="art_pre_template">sudo apt-get install binutils<br />sudo apt-get install build-essential<br />sudo apt-get install m4<br />sudo apt-get install autogen<br />sudo apt-get install bison</div>
<div id="art_pre_template"><br /></div>
<div id="art_pre_template">(2) <b>Install gmp</b></div>
<div id="art_pre_template">1. download gmp (gmp-4.3.2.tar.bz2) from: <a href="ftp://gcc.gnu.org/pub/gcc/infrastructure/">ftp://gcc.gnu.org/pub/gcc/infrastructure/</a></div>
<div id="art_pre_template">2. compile and install gmp:</div>
<div id="art_pre_template">
<pre name="code" class="shell">sudo mkdir -p /opt/gmp-4.3.2
tar -jxvf gmp-4.3.2.tar.bz2
cd gmp-4.3.2
./configure --prefix=/opt/gmp-4.3.2
make &amp;&amp; make check &amp;&amp; sudo make install</pre>
Notes: It is recommended to run 'make check'.</div>
<div id="art_pre_template"><br /></div>
<div id="art_pre_template">(3) <b>Install mpfr</b></div>
<div id="art_pre_template">1. download mpfr (mpfr-2.4.2.tar.bz2) from same link as above.</div>
<div id="art_pre_template">2. compile and install mpfr:</div>
<div id="art_pre_template">
<pre name="code" class="shell">sudo mkdir -p /opt/mpfr-2.4.2
tar -jxvf mpfr-2.4.2.tar.bz2
cd mpfr-2.4.2
./configure --prefix=/opt/mpfr-2.4.2 --with-gmp=/opt/gmp-4.3.2
make &amp;&amp; make check &amp;&amp; sudo make install</pre>
Notes: You must install gmp before installing 'mpfr' as 'mpfr' depends on 'gmp'.</div>
<div id="art_pre_template"><br /></div>
<div id="art_pre_template">(4) <b>install mpc</b></div>
<div id="art_pre_template">1. download mpc (mpc-0.8.1.tar.gz) from same link as above.</div>
<div id="art_pre_template">2. compile and install mpc:</div>
<div id="art_pre_template">
<pre name="code" class="shell">sudo mkdir -p /opt/mpc-0.8.1
tar -zxvf mpc-0.8.1.tar.gz
cd mpc-0.8.1
./configure --prefix=/opt/mpc-0.8.1 --with-gmp=/opt/gmp-4.3.2 --with-mpfr=/opt/mpfr-2.4.2
make &amp;&amp; make check &amp;&amp; sudo make install</pre>
Notes: 'mpc' depends on 'gmp' and 'mpfr'.</div>
<div id="art_pre_template"><br /></div>
<div id="art_pre_template">(5) <b>build and install GCC with Cilk Plus</b></div>
<div id="art_pre_template">1. download the source code of 'cilkplus' branch. There are various ways to download it.</div>
<div id="art_pre_template">SVN:</div>
<div id="art_pre_template">The cilkplus-4_7-branch: <a href="http://gcc.gnu.org/svn/gcc/branches/cilkplus-4_7-branch/">http://gcc.gnu.org/svn/gcc/branches/cilkplus-4_7-branch/</a><br /></div>
<div id="art_pre_template">The cilkplus branch: <a href="http://gcc.gnu.org/svn/gcc/branches/cilkplus/">http://gcc.gnu.org/svn/gcc/branches/cilkplus/</a></div>
<div id="art_pre_template">GIT:</div>
<div id="art_pre_template">The GIT mirror: <a href="http://gcc.gnu.org/git/?p=gcc.git;a=shortlog;h=refs/heads/cilkplus">http://gcc.gnu.org/git/?p=gcc.git;a=shortlog;h=refs/heads/cilkplus</a></div>
<div id="art_pre_template">Here, I download the git mirror for cilkplus branch through browser directly. (The snapshot is 'gcc-0dfa790.tar.gz')</div>
<div id="art_pre_template"><br /></div>
<div id="art_pre_template">2. compile and install gcc cilkplus branch:</div>
<div id="art_pre_template">
<pre name="code" class="shell">export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/gmp-4.3.2/lib:/opt/mpfr-2.4.2/lib:/opt/mpc-0.8.1/lib
export C_INCLUDE_PATH=/usr/include/x86_64-linux-gnu &amp;&amp; export CPLUS_INCLUDE_PATH=$C_INCLUDE_PATH &amp;&amp; export OBJC_INCLUDE_PATH=$C_INCLUDE_PATH
export LIBRARY_PATH=/usr/lib/x86_64-linux-gnu

tar -zxvf gcc-0dfa790.tar.gz
sudo mkdir -p /opt/gcc-4.7-cilkplus
mkdir gcc_cilkplu_build &amp;&amp; cd gcc_cilkplu_build
../gcc-0dfa790/configure --prefix=/opt/gcc-4.7-cilkplus --with-gmp=/opt/gmp-4.3.2 --with-mpfr=/opt/mpfr-2.4.2 --with-mpc=/opt/mpc-0.8.1 --disable-multilib --enable-languages=c,c++
make -j8
sudo make install</pre>
Notes:</div>
<div id="art_pre_template">(1) It is suggested to run 'configure' in a standalone foler instead of running it in the source tree of gcc cilkplus.</div>
<div id="art_pre_template">(2) 'make -j8', this step will build the source code, it will take quite a long time, you may change the argument of '-j' according to your system.</div>
<div id="art_pre_template"><br /></div>
<div id="art_pre_template"><br /></div>
<div id="art_pre_template">(6) <b>Create the 'gccvars.sh' script</b></div>
<div id="art_pre_template">This is optional, you may create a script to help to set the environment of the built gcc. Following is a reference for 'gccvars.sh':</div>
<div id="art_pre_template">
<pre name="code" class="shell"># filename: gccvars.sh
# 'source gccvars.sh' to set the environment of gcc
export C_INCLUDE_PATH=/usr/include/x86_64-linux-gnu:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=$C_INCLUDE_PATH
export OBJC_INCLUDE_PATH=$C_INCLUDE_PATH
export LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LIBRARY_PATH

export GCCDIR=/opt/gcc-4.7-cilkplus
export PATH=$GCCDIR/bin:$PATH
export LD_LIBRARY_PATH=$GCCDIR/lib:$GCCDIR/lib64:/opt/gmp-4.3.2/lib:/opt/mpfr-2.4.2/lib:/opt/mpc-0.8.1/lib:$LD_LIBRARY_PATH
export MANPATH=$GCCDIR/share/man:$MANPATH</pre>
Notes: GCCDIR is the installed path of the built gcc.</div>
<div id="art_pre_template"><br /></div>
<div id="art_pre_template"><br /></div>
<div id="art_pre_template">(7) <b>Test Cilk Plus with GCC</b></div>
<div id="art_pre_template">To use cilk plus with gcc, you need to add '-lcilkrts' flag to the command line. See below test case for more details (it contains how to compile and the results):</div>
<div id="art_pre_template">
<pre name="code" class="cpp">// filename: test_cilkplus.cpp
// compile: g++ test_cilkplus.cpp -lcilkrts

#include &lt;stdio.h&gt;
#include &lt;unistd.h&gt;

#include &lt;cilk/cilk.h&gt;
#include &lt;cilk/cilk_api.h&gt;

void task(int i) {
    printf("task: %d, workder id: %d\n", i, __cilkrts_get_worker_number());
    sleep(1);
}

int main() {
    for(int i=0;i&lt;10;i++)
	    cilk_spawn task(i);
    cilk_spawn task(-1);
    cilk_sync;
    return 0;
}

/* compile and result:
#g++ test_cilkplus.cpp -lcilkrts
#./a.out 
task: 0, workder id: 0
task: 1, workder id: 1
task: 2, workder id: 2
task: 3, workder id: 0
task: 4, workder id: 1
task: 5, workder id: 2
task: 6, workder id: 0
task: 7, workder id: 1
task: 8, workder id: 2
task: 9, workder id: 0
task: -1, workder id: 1
#
notes: you can use 'export CILK_NWORKERS=N' to set the max workders of cilk plus runtime.
*/</pre>
</div>
<div id="art_pre_template">(8) <b>Resources for the Cilk Plus Open Source Project</b></div>
<div id="art_pre_template"><a href="http://software.intel.com/en-us/articles/intel-cilk-plus/">http://software.intel.com/en-us/articles/intel-cilk-plus/</a><br /><a href="http://software.intel.com/en-us/articles/intel-cilk-plus-open-source/">http://software.intel.com/en-us/articles/intel-cilk-plus-open-source/</a><br /></div> ]]></description>
      <link>http://software.intel.com/en-us/articles/how-to-build-gcc-cilkplus-brance-in-64bit-ubuntu-1204/</link>
      <pubDate>Sat, 14 Apr 2012 09:00:00 -0700</pubDate>
      <comments>http://software.intel.com/en-us/articles/how-to-build-gcc-cilkplus-brance-in-64bit-ubuntu-1204/#comments</comments>
      <guid isPermaLink="true">http://software.intel.com/en-us/articles/how-to-build-gcc-cilkplus-brance-in-64bit-ubuntu-1204/</guid>
      <category>Parallel Programming</category>
      <category>Open Source</category>
      <category>Intel® C++ Compiler for Linux* Knowledge Base</category>
    </item>
  </channel></rss>
