<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Mark Lodato's Blog</title>
 <link href="http://marklodato.github.com/atom.xml" rel="self"/>
 <link href="http://marklodato.github.com/"/>
 <updated>2010-02-23T20:56:58-08:00</updated>
 <id>http://marklodato.github.com/</id>
 <author>
   <name>Mark Lodato</name>
   <email>lodatom@gmail.com</email>
 </author>
 
 
 <entry>
   <title>Executable Shared Libraries</title>
   <link href="http://marklodato.github.com/2009/10/03/executable-shared-libraries.html"/>
   <updated>2009-10-03T00:00:00-07:00</updated>
   <id>http://marklodato.github.com/2009/10/03/executable-shared-libraries</id>
   <content type="html">&lt;p&gt;I figured out a way to create a shared library that is also executable. One possible use for this would be to make &lt;a href='http://cython.org'&gt;Cython&lt;/a&gt; modules that can be run by themselves or imported from Python. I found some mailing list discussions from 2003 describing a method, but it does not work on x86 Linux. The method below works, at least, on x86-64 Linux with gcc 4.3.3 on Ubuntu 9.04.&lt;/p&gt;
&lt;del&gt;Unfortunately, I could not get gcc to do this for me - I have to run the
linker myself.  I tried giving `-Wl,-shared`, but gcc put the flag too late in
the command line.  If anyone figures out a way to do this, let me know!&lt;/del&gt;
&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; Thanks to &lt;a href='http://sourceware.org/ml/binutils/2009-10/msg00088.html'&gt;Daniel Jacobowitz&lt;/a&gt;, I found out that &lt;code&gt;-fPIC -fPIE -pie&lt;/code&gt; is sufficient. Easy! I&amp;#8217;ve updated the post bleow to reflect this.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s some example code:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;&lt;span class='nv'&gt;$ &lt;/span&gt;cat &lt;span class='s'&gt;&amp;lt;&amp;lt;EOF &amp;gt;library.c&lt;/span&gt;
&lt;span class='s'&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;
&lt;span class='s'&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;/span&gt;

&lt;span class='s'&gt;void foo(int x) {&lt;/span&gt;
&lt;span class='s'&gt;    printf(&amp;quot;foo(%d)\n&amp;quot;, x);&lt;/span&gt;
&lt;span class='s'&gt;}&lt;/span&gt;

&lt;span class='s'&gt;int main(int argc, char **argv) {&lt;/span&gt;
&lt;span class='s'&gt;    if (argc != 2) {&lt;/span&gt;
&lt;span class='s'&gt;        fprintf(stderr, &amp;quot;USAGE: %s n\n&amp;quot;, argv[0]);&lt;/span&gt;
&lt;span class='s'&gt;        exit(1);&lt;/span&gt;
&lt;span class='s'&gt;    }&lt;/span&gt;
&lt;span class='s'&gt;    foo(atoi(argv[1]));&lt;/span&gt;
&lt;span class='s'&gt;    return 0;&lt;/span&gt;
&lt;span class='s'&gt;}&lt;/span&gt;
&lt;span class='s'&gt;EOF&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Compile &lt;code&gt;-fPIC -fPIE -pie&lt;/code&gt; to make a position-independent executable, which can be loaded like a shared library.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;&lt;span class='nv'&gt;$ &lt;/span&gt;gcc -fPIC -fPIE -pic -o library.so library.c
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now you can both execute and load your shared library.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;&lt;span class='nv'&gt;$ &lt;/span&gt;./library.so 12
foo&lt;span class='o'&gt;(&lt;/span&gt;12&lt;span class='o'&gt;)&lt;/span&gt;

&lt;span class='nv'&gt;$ &lt;/span&gt;python -c &lt;span class='se'&gt;\&lt;/span&gt;
    &lt;span class='s1'&gt;&amp;#39;import ctypes; x = ctypes.cdll.LoadLibrary(&amp;quot;./library.so&amp;quot;); x.foo(13)&amp;#39;&lt;/span&gt;
foo&lt;span class='o'&gt;(&lt;/span&gt;13&lt;span class='o'&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The rest is the stupid way I did it before, mainly for historical interest.&lt;/p&gt;

&lt;p&gt;Run &lt;code&gt;gcc &amp;#39;-###&amp;#39;&lt;/code&gt; to find out what command it &lt;em&gt;would&lt;/em&gt; have run.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;&lt;span class='nv'&gt;$ &lt;/span&gt;gcc &lt;span class='s1'&gt;&amp;#39;-###&amp;#39;&lt;/span&gt; -fPIC -fPIE -pie -rdynamic -o library.so library.o
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Look for the &lt;code&gt;collect2&lt;/code&gt; line - this is the linker. Run that exact command, but insert &lt;code&gt;-shared&lt;/code&gt; before the &lt;code&gt;-pie&lt;/code&gt;. On my system, I ran this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;&lt;span class='nv'&gt;$ &lt;/span&gt;/usr/lib/gcc/x86_64-linux-gnu/4.3.3/collect2 &lt;span class='se'&gt;\&lt;/span&gt;
    --eh-frame-hdr &lt;span class='se'&gt;\&lt;/span&gt;
    -m elf_x86_64 &lt;span class='se'&gt;\&lt;/span&gt;
    -shared &lt;span class='se'&gt;\&lt;/span&gt;
    -pie &lt;span class='se'&gt;\&lt;/span&gt;
    --export-dynamic &lt;span class='se'&gt;\&lt;/span&gt;
    -o library.so &lt;span class='se'&gt;\&lt;/span&gt;
    -z relro &lt;span class='se'&gt;\&lt;/span&gt;
    /usr/lib/Scrt1.o &lt;span class='se'&gt;\&lt;/span&gt;
    /usr/lib/crti.o &lt;span class='se'&gt;\&lt;/span&gt;
    /usr/lib/gcc/x86_64-linux-gnu/4.3.3/crtbeginS.o &lt;span class='se'&gt;\&lt;/span&gt;
    -L/usr/lib/gcc/x86_64-linux-gnu/4.3.3 &lt;span class='se'&gt;\&lt;/span&gt;
    -L/usr/lib &lt;span class='se'&gt;\&lt;/span&gt;
    -L/lib &lt;span class='se'&gt;\&lt;/span&gt;
    library.o &lt;span class='se'&gt;\&lt;/span&gt;
    -lgcc &lt;span class='se'&gt;\&lt;/span&gt;
    --as-needed &lt;span class='se'&gt;\&lt;/span&gt;
    -lgcc_s &lt;span class='se'&gt;\&lt;/span&gt;
    --no-as-needed &lt;span class='se'&gt;\&lt;/span&gt;
    -lc &lt;span class='se'&gt;\&lt;/span&gt;
    -lgcc &lt;span class='se'&gt;\&lt;/span&gt;
    --as-needed &lt;span class='se'&gt;\&lt;/span&gt;
    -lgcc_s &lt;span class='se'&gt;\&lt;/span&gt;
    --no-as-needed &lt;span class='se'&gt;\&lt;/span&gt;
    /usr/lib/gcc/x86_64-linux-gnu/4.3.3/crtendS.o &lt;span class='se'&gt;\&lt;/span&gt;
    /usr/lib/crtn.o
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>NumPy, SciPy, and the Intel Compiler Suite</title>
   <link href="http://marklodato.github.com/2009/08/30/numpy-scipy-and-intel.html"/>
   <updated>2009-08-30T00:00:00-07:00</updated>
   <id>http://marklodato.github.com/2009/08/30/numpy-scipy-and-intel</id>
   <content type="html">&lt;p&gt;I spent a &lt;em&gt;lot&lt;/em&gt; of time trying to get &lt;a href='http://numpy.scipy.org'&gt;NumPy&lt;/a&gt; and &lt;a href='http://www.scipy.org'&gt;SciPy&lt;/a&gt; to work with the &lt;a href='http://software.intel.com/en-us/intel-compilers/'&gt;Intel Compiler Suite&lt;/a&gt;, but it finally works. Here is how I did it on Ubuntu 9.04/AMD64 on an Intel Core 2 Duo using the versions specified. It appears that every combination of versions requires a different process, so hopefully this works for you!&lt;/p&gt;

&lt;h3 id='intel_compiler_suite_111046'&gt;Intel Compiler Suite 11.1.046&lt;/h3&gt;

&lt;p&gt;Download both the Intel C++ and Fortran compilers for Linux, which are free for non-commercial use. I used Intel 64 version 11.1.046. The install is very easy; I installed the C++ compiler and then the Fortran one.&lt;/p&gt;

&lt;p&gt;Once they are installed, source the iccvars.sh script.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;&lt;span class='nb'&gt;source&lt;/span&gt; /opt/intel/Compiler/11.1/046/bin/iccvars.sh intel64
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Also, you may want to do the following so that you do not need to have the Intel library directories in your &lt;code&gt;$LD_LIBRARY_PATH&lt;/code&gt;.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;cat &amp;gt; /etc/ld.so.conf.d/intel.conf &lt;span class='s'&gt;&amp;lt;&amp;lt;EOF&lt;/span&gt;
&lt;span class='s'&gt;/opt/intel/Compiler/11.1/046/lib/intel64&lt;/span&gt;
&lt;span class='s'&gt;/opt/intel/Compiler/11.1/046/ipp/em64t/sharedlib&lt;/span&gt;
&lt;span class='s'&gt;/opt/intel/Compiler/11.1/046/mkl/lib/em64t&lt;/span&gt;
&lt;span class='s'&gt;/opt/intel/Compiler/11.1/046/tbb/em64t/cc4.1.0_libc2.4_kernel2.6.16.21/lib&lt;/span&gt;
&lt;span class='s'&gt;EOF&lt;/span&gt;
sudo /sbin/ldconfig
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;h4 id='note_about_xhost'&gt;Note About -xHost&lt;/h4&gt;

&lt;p&gt;In recent Intel compilers, you can give the &lt;code&gt;-xHost&lt;/code&gt; option, which will optimize based on the Intel processor of the current host. This works great if you are compiling with an Intel processor and you will run on the same machine. This was my case, so this is the flag I used. If this is not the case (AMD processor, or compiling to run on other chips), then you will want to set this optimization flag to something more appropriate.&lt;/p&gt;

&lt;h3 id='amd__umfpack_part_of_suitesparse_340'&gt;AMD / UMFPACK, part of SuiteSparse 3.4.0&lt;/h3&gt;

&lt;p&gt;The AMD and UMFPACK libraries (part of &lt;a href='http://www.cise.ufl.edu/research/sparse/SuiteSparse/'&gt;SuiteSparse&lt;/a&gt;) are needed for SciPy, so we&amp;#8217;ll build them first. They are static libraries, so I chose to build them in /opt.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;&lt;span class='nb'&gt;cd&lt;/span&gt; /opt
tar zxvf SuiteSparse-3.4.0.tar.gz
&lt;span class='nb'&gt;cd &lt;/span&gt;SuiteSparse
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;First we need to patch the Makefile to build with the Intel compiler. If you want to compile the whole suite, you also need to set up BLAS and LAPACK to use MKL. But we don&amp;#8217;t need the whole suite for SciPy.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='diff'&gt;patch -p0 &amp;lt;&amp;lt;EOF
&lt;span class='gh'&gt;diff -ur SuiteSparse.orig/UFconfig/UFconfig.mk SuiteSparse/UFconfig/UFconfig.mk&lt;/span&gt;
&lt;span class='gd'&gt;--- SuiteSparse.orig/UFconfig/UFconfig.mk	2009-05-20 14:06:04.000000000 -0400&lt;/span&gt;
&lt;span class='gi'&gt;+++ SuiteSparse/UFconfig/UFconfig.mk	2009-08-07 02:03:19.000000000 -0400&lt;/span&gt;
&lt;span class='gu'&gt;@@ -33,11 +33,11 @@&lt;/span&gt;
 # C compiler and compiler flags:  These will normally not give you optimal
 # performance.  You should select the optimization parameters that are best
 # for your system.  On Linux, use &amp;quot;CFLAGS = -O3 -fexceptions&amp;quot; for example.
&lt;span class='gd'&gt;-CC = cc&lt;/span&gt;
&lt;span class='gi'&gt;+CC = icc&lt;/span&gt;
 # CFLAGS = -O   (for example; see below for details)

 # C++ compiler (also uses CFLAGS)
&lt;span class='gd'&gt;-CPLUSPLUS = g++&lt;/span&gt;
&lt;span class='gi'&gt;+CPLUSPLUS = icpc&lt;/span&gt;

 # ranlib, and ar, for generating libraries
 RANLIB = ranlib
&lt;span class='gu'&gt;@@ -48,8 +48,8 @@&lt;/span&gt;
 MV = mv -f

 # Fortran compiler (not normally required)
&lt;span class='gd'&gt;-F77 = f77&lt;/span&gt;
&lt;span class='gd'&gt;-F77FLAGS = -O&lt;/span&gt;
&lt;span class='gi'&gt;+F77 = ifort&lt;/span&gt;
&lt;span class='gi'&gt;+F77FLAGS = -O3 -xHost&lt;/span&gt;
 F77LIB =

 # C and Fortran libraries
&lt;span class='gu'&gt;@@ -220,7 +224,7 @@&lt;/span&gt;

 # Using default compilers:
 # CC = gcc
&lt;span class='gd'&gt;-CFLAGS = -O3 -fexceptions&lt;/span&gt;
&lt;span class='gi'&gt;+CFLAGS = -O3 -xHost -fPIC -openmp -vec_report=0&lt;/span&gt;

 # alternatives:
 # CFLAGS = -g -fexceptions \
EOF
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Compile both libraries. No install needed after this.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;make -C AMD
make -C UMFPACK
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id='numpy_130'&gt;Numpy 1.3.0&lt;/h3&gt;

&lt;p&gt;Now on to NumPy.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;tar zxvf numpy-1.3.0.tar.gz
&lt;span class='nb'&gt;cd &lt;/span&gt;numpy-1.3.0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Next, set up the site.cfg file for Intel MKL, AMD, and UMFPACK. (Only MKL is needed for NumPy, but if we set this up now, it will work for SciPy later.)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; I used &lt;code&gt;mkl_mc&lt;/code&gt; because I have a Core architecture. Read the &lt;a href='file:///opt/intel/Compiler/11.1/046/Documentation/en_US/mkl/userguide.pdf'&gt;MKL User&amp;#8217;s Guide&lt;/a&gt; to determine which kernel library to use for your architecture. It &lt;em&gt;should&lt;/em&gt; be automatic (from &lt;code&gt;mkl_core&lt;/code&gt;), but for some reason it kept failing with &lt;code&gt;undefined symbol: mkl_dft_commit_descriptor_s_c2c_md_omp&lt;/code&gt;. Adding &lt;code&gt;mkl_mc&lt;/code&gt; fixed it.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;cat &amp;gt; site.cfg &lt;span class='s'&gt;&amp;lt;&amp;lt;EOF&lt;/span&gt;
&lt;span class='s'&gt;[DEFAULT]&lt;/span&gt;
&lt;span class='s'&gt;include_dirs = /opt/SuiteSparse/UFconfig&lt;/span&gt;

&lt;span class='s'&gt;[amd]&lt;/span&gt;
&lt;span class='s'&gt;amd_libs = amd&lt;/span&gt;
&lt;span class='s'&gt;library_dirs = /opt/SuiteSparse/AMD/Lib&lt;/span&gt;
&lt;span class='s'&gt;include_dirs = /opt/SuiteSparse/AMD/Include&lt;/span&gt;

&lt;span class='s'&gt;[umfpack]&lt;/span&gt;
&lt;span class='s'&gt;umfpack_libs = umfpack&lt;/span&gt;
&lt;span class='s'&gt;library_dirs = /opt/SuiteSparse/UMFPACK/Lib&lt;/span&gt;
&lt;span class='s'&gt;include_dirs = /opt/SuiteSparse/UMFPACK/Include&lt;/span&gt;

&lt;span class='s'&gt;[mkl]&lt;/span&gt;
&lt;span class='s'&gt;include_dirs = /opt/intel/Compiler/11.1/046/mkl/include&lt;/span&gt;
&lt;span class='s'&gt;library_dirs = /opt/intel/Compiler/11.1/046/mkl/lib/em64t&lt;/span&gt;
&lt;span class='s'&gt;lapack_libs = mkl_lapack&lt;/span&gt;
&lt;span class='s'&gt;mkl_libs = mkl_intel_lp64, mkl_intel_thread, mkl_core, mkl_mc&lt;/span&gt;
&lt;span class='s'&gt;EOF&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now, turn on optimization, &lt;code&gt;-fPIC&lt;/code&gt;, and OpenMP support for &lt;code&gt;icc&lt;/code&gt;.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='diff'&gt;patch -p0 &amp;lt;&amp;lt;EOF
&lt;span class='gd'&gt;--- numpy/distutils/intelccompiler.py.old       2009-03-29 07:24:21.000000000 -0400&lt;/span&gt;
&lt;span class='gi'&gt;+++ numpy/distutils/intelccompiler.py   2009-08-05 23:58:30.000000000 -0400&lt;/span&gt;
&lt;span class='gu'&gt;@@ -8,7 +8,7 @@&lt;/span&gt;
     &amp;quot;&amp;quot;&amp;quot;

     compiler_type = &amp;#39;intel&amp;#39;
&lt;span class='gd'&gt;-    cc_exe = &amp;#39;icc&amp;#39;&lt;/span&gt;
&lt;span class='gi'&gt;+    cc_exe = &amp;#39;icc -xHost -O3 -fPIC -openmp&amp;#39;&lt;/span&gt;

     def __init__ (self, verbose=0, dry_run=0, force=0):
         UnixCCompiler.__init__ (self, verbose,dry_run, force)
EOF
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Set the appropriate flags for &lt;code&gt;ifort&lt;/code&gt;, skipping Numpy&amp;#8217;s broken autodetection.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='diff'&gt;patch -p0 &amp;lt;&amp;lt;EOF
&lt;span class='gd'&gt;--- numpy/distutils/fcompiler/intel.py.bak      2009-03-29 07:24:21.000000000 -0400&lt;/span&gt;
&lt;span class='gi'&gt;+++ numpy/distutils/fcompiler/intel.py  2009-08-06 23:08:59.000000000 -0400&lt;/span&gt;
&lt;span class='gu'&gt;@@ -47,6 +47,7 @@&lt;/span&gt;
     module_include_switch = &amp;#39;-I&amp;#39;

     def get_flags(self):
&lt;span class='gi'&gt;+        return [&amp;#39;-fPIC&amp;#39;, &amp;#39;-cm&amp;#39;]&lt;/span&gt;
         v = self.get_version()
         if v &amp;gt;= &amp;#39;10.0&amp;#39;:
             # Use -fPIC instead of -KPIC.
&lt;span class='gu'&gt;@@ -63,6 +64,7 @@&lt;/span&gt;
         return [&amp;#39;-O3&amp;#39;,&amp;#39;-unroll&amp;#39;]

     def get_flags_arch(self):
&lt;span class='gi'&gt;+        return [&amp;#39;-xHost&amp;#39;]&lt;/span&gt;
         v = self.get_version()
         opt = []
         if cpu.has_fdiv_bug():
EOF
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Build using icc. You have to add the &lt;code&gt;build_src&lt;/code&gt; to fix a bug in the Numpy 1.3.0 distribution.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;python setup.py build_src config --compiler&lt;span class='o'&gt;=&lt;/span&gt;intel build_clib &lt;span class='se'&gt;\&lt;/span&gt;
    --compiler&lt;span class='o'&gt;=&lt;/span&gt;intel build_ext --compiler&lt;span class='o'&gt;=&lt;/span&gt;intel
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;If you want to install and test without installing to the system,&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;python setup.py install --prefix&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='nv'&gt;$PWD&lt;/span&gt;/d
&lt;span class='nv'&gt;PYTHONPATH&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='nv'&gt;$PWD&lt;/span&gt;/d/lib/python-2.6/site-packages &lt;span class='se'&gt;\&lt;/span&gt;
    &lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='nb'&gt;cd&lt;/span&gt; &lt;span class='nv'&gt;$HOME&lt;/span&gt; &lt;span class='o'&gt;&amp;amp;&amp;amp;&lt;/span&gt; python -c &lt;span class='s1'&gt;&amp;#39;import scipy; scipy.test()&amp;#39;&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Install as root.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;sudo python setup.py install
sudo cp site.cfg /usr/local/lib/python2.6/dist-packages/numpy
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Test (must do this outside the numpy source directory).&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='nb'&gt;cd&lt;/span&gt; &lt;span class='nv'&gt;$HOME&lt;/span&gt; &lt;span class='o'&gt;&amp;amp;&amp;amp;&lt;/span&gt; python -c &lt;span class='s1'&gt;&amp;#39;import numpy; numpy.test()&amp;#39;&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id='scipy_071'&gt;SciPy 0.7.1&lt;/h3&gt;

&lt;p&gt;Now, on to SciPy.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;tar zxvf scipy-0.7.1.tar.gz
&lt;span class='nb'&gt;cd &lt;/span&gt;scipy-0.7.1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Fix compilation with &lt;code&gt;icc&lt;/code&gt;.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='diff'&gt;patch -p0 &amp;lt;&amp;lt;EOF
&lt;span class='gd'&gt;--- scipy/special/cephes/const.c.bak    2009-08-07 01:56:43.000000000 -0400&lt;/span&gt;
&lt;span class='gi'&gt;+++ scipy/special/cephes/const.c        2009-08-07 01:57:08.000000000 -0400&lt;/span&gt;
&lt;span class='gu'&gt;@@ -91,12 +91,12 @@&lt;/span&gt;
 double THPIO4 =  2.35619449019234492885;       /* 3*pi/4 */
 double TWOOPI =  6.36619772367581343075535E-1; /* 2/pi */
 #ifdef INFINITIES
&lt;span class='gd'&gt;-double INFINITY = 1.0/0.0;  /* 99e999; */&lt;/span&gt;
&lt;span class='gi'&gt;+double INFINITY = __builtin_inff();&lt;/span&gt;
 #else
 double INFINITY =  1.79769313486231570815E308;    /* 2**1024*(1-MACHEP) */
 #endif
 #ifdef NANS
&lt;span class='gd'&gt;-double NAN = 1.0/0.0 - 1.0/0.0;&lt;/span&gt;
&lt;span class='gi'&gt;+double NAN = __builtin_nanf(&amp;quot;&amp;quot;);&lt;/span&gt;
 #else
 double NAN = 0.0;
 #endif
EOF
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Build. Note that you have to set &lt;code&gt;fcompiler=intelem&lt;/code&gt; for Intel 64.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;python setup.py config --compiler&lt;span class='o'&gt;=&lt;/span&gt;intel --fcompiler&lt;span class='o'&gt;=&lt;/span&gt;intelem build_clib &lt;span class='se'&gt;\&lt;/span&gt;
    --compiler&lt;span class='o'&gt;=&lt;/span&gt;intel --fcompiler&lt;span class='o'&gt;=&lt;/span&gt;intelem build_ext --compiler&lt;span class='o'&gt;=&lt;/span&gt;intel &lt;span class='se'&gt;\&lt;/span&gt;
    --fcompiler&lt;span class='o'&gt;=&lt;/span&gt;intelem -I/opt/SuiteSparse/UFconfig
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The SWIG code generates C++, but distutils doesn&amp;#8217;t use the C++ compiler to link, so we have to do this ourselves. There may have been a way to fix some setup.py or something, but it&amp;#8217;s easier to just do this by hand.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;&lt;span class='k'&gt;for &lt;/span&gt;x in csr csc coo bsr dia; &lt;span class='k'&gt;do&lt;/span&gt;
&lt;span class='k'&gt;    &lt;/span&gt;icpc -xHost -O3 -fPIC -shared &lt;span class='se'&gt;\&lt;/span&gt;
        build/temp.linux-x86_64-2.6/scipy/sparse/sparsetools/&lt;span class='k'&gt;${&lt;/span&gt;&lt;span class='nv'&gt;x&lt;/span&gt;&lt;span class='k'&gt;}&lt;/span&gt;_wrap.o &lt;span class='se'&gt;\&lt;/span&gt;
        -o build/lib.linux-x86_64-2.6/scipy/sparse/sparsetools/_&lt;span class='k'&gt;${&lt;/span&gt;&lt;span class='nv'&gt;x&lt;/span&gt;&lt;span class='k'&gt;}&lt;/span&gt;.so
&lt;span class='k'&gt;done&lt;/span&gt;
icpc -xHost -O3 -fPIC -openmp -shared &lt;span class='se'&gt;\&lt;/span&gt;
    build/temp.linux-x86_64-2.6/scipy/interpolate/src/_interpolate.o &lt;span class='se'&gt;\&lt;/span&gt;
    -o build/lib.linux-x86_64-2.6/scipy/interpolate/_interpolate.so
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;As with numpy, you may want to install to &lt;code&gt;$PWD/d&lt;/code&gt; and test first.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;python setup.py install --prefix&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='nv'&gt;$PWD&lt;/span&gt;/d
&lt;span class='nv'&gt;PYTHONPATH&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='nv'&gt;$PWD&lt;/span&gt;/d/lib/python-2.6/site-packages &lt;span class='se'&gt;\&lt;/span&gt;
    &lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='nb'&gt;cd&lt;/span&gt; &lt;span class='nv'&gt;$HOME&lt;/span&gt; &lt;span class='o'&gt;&amp;amp;&amp;amp;&lt;/span&gt; python -c &lt;span class='s1'&gt;&amp;#39;import scipy; scipy.test()&amp;#39;&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Install as root.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;sudo python setup.py install
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Test (again, outside source directory.)&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='nb'&gt;cd&lt;/span&gt; &lt;span class='nv'&gt;$HOME&lt;/span&gt; &lt;span class='o'&gt;&amp;amp;&amp;amp;&lt;/span&gt; python -c &lt;span class='s1'&gt;&amp;#39;import scipy; scipy.test()&amp;#39;&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class='highlight'&gt;&lt;pre&gt;
&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
 
</feed>

