<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Scientific Computing on shocksolution.com</title><link>https://shocksolution.com/tags/scientific-computing/</link><description>Recent content in Scientific Computing on shocksolution.com</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Wed, 20 Nov 2013 13:27:41 +0000</lastBuildDate><atom:link href="https://shocksolution.com/tags/scientific-computing/index.xml" rel="self" type="application/rss+xml"/><item><title>Preventing "soft" failures due to memory fragmentation in Linux</title><link>https://shocksolution.com/posts/preventing-soft-failures-due-to-memory-fragmentation-in-linux/</link><pubDate>Wed, 20 Nov 2013 13:27:41 +0000</pubDate><guid>https://shocksolution.com/posts/preventing-soft-failures-due-to-memory-fragmentation-in-linux/</guid><description>&lt;p&gt;A previous post documented that a Linux server running a pre-2.6.24 kernel can fail to allocate large chunks of memory after its memory has been fragmented by a &amp;ldquo;thrashing&amp;rdquo; incident. In this post, I will point out some ways to prevent this problem.&lt;/p&gt;&#10;&lt;h2 id="use-a-newer-kernel"&gt;Use a Newer Kernel&lt;/h2&gt;&#10;&lt;p&gt;We have some servers running RHEL 5.9 with the kernel updated to 2.6.34.14. After a thrashing incident, these servers do not experience the same problem with allocating large blocks of memory. I think the fix is &lt;a href="http://kernelnewbies.org/Linux_2_6_24#head-eacf0c267f25660d4fe1bbeb3216d0d1d7400d1b" title="Kernel%202.6.24%20release%20notes"&gt;documented in the release notes for kernel 2.6.24&lt;/a&gt;. Section 2.4 talks about &amp;ldquo;anti-fragmentation patches&amp;rdquo; and includes a link to &lt;a href="http://lwn.net/Articles/224829/" title="Linux%20memory%20management"&gt;this article about Linux memory management&lt;/a&gt;, which links to this &lt;a href="http://lwn.net/Articles/224835/" title="The%20performance%20and%20behaviour%20of%20the%20anti-fragmentation%20related%20patches"&gt;thorough documentation of the anti-fragmentation patches&lt;/a&gt;.(BTW, here is &lt;a href="https://%3Cwww.kernel.org/pub/linux/kernel/v2.6/%3E" title="Linux%20kernel%202.6%20changelogs"&gt;the full list of 2.6 kernel changelogs&lt;/a&gt;) My plan is to deploy RHEL 5.9 with the updated kernel to all the compute nodes in our cluster. However, this still doesn&amp;rsquo;t solve the problem of a user who requests some portion of the RAM on a node and then proceeds to consume more memory than requested. This is unfair to another user whose job is running on the same node.&lt;/p&gt;</description></item><item><title>Memory fragmentation degrades performance in Linux kernels &amp;lt; 2.6.24 (RHEL 5.4)</title><link>https://shocksolution.com/posts/memory-fragmentation-degrades-performance-in-linux-kernels-2-6-24-rhel-5-4/</link><pubDate>Fri, 15 Nov 2013 21:30:38 +0000</pubDate><guid>https://shocksolution.com/posts/memory-fragmentation-degrades-performance-in-linux-kernels-2-6-24-rhel-5-4/</guid><description>&lt;p&gt;I have data from the &lt;a href="http://webstokes.ist.ucf.edu/" title="STOKES%20Advanced%20Research%20Computing%20Center"&gt;STOKES High Performance Compute Cluster&lt;/a&gt; which definitively shows that kernel versions prior to 2.6.24 can suffer significant performance degradation due to memory fragmentation. I noticed the problem on servers running Red Hat Enterprise Linux (RHEL) 5.4 with kernel version 2.6.18-164.el5. This post will document my findings. The graphs were taken from our &lt;a href="http://ganglia.sourceforge.net/" title="Ganglia%20Monitoring%20System"&gt;Ganglia monitoring system&lt;/a&gt;.&lt;/p&gt;&#10;&lt;p&gt;This node has 24GB of RAM. As long as processes do not request more than 23GB of RAM, the node operates normally. Processes can use 23GB of RAM all day long:&lt;/p&gt;</description></item><item><title>Insert an EPS file into an Asymptote Vector Graphics document</title><link>https://shocksolution.com/posts/insert-an-eps-file-into-an-asymptote-vector-graphics-document/</link><pubDate>Wed, 23 Oct 2013 13:08:06 +0000</pubDate><guid>https://shocksolution.com/posts/insert-an-eps-file-into-an-asymptote-vector-graphics-document/</guid><description>&lt;p&gt;It&amp;rsquo;s surprisingly difficult to find out whether it is possible to include an image from an Encapsulated PostScript (EPS) file into an Asymptote vector graphics document. It turns out that it &lt;em&gt;is&lt;/em&gt; easy, but difficult to find in the Asymptote docs (I finally found the answer, via Google, &lt;a href="http://asymptote.sourceforge.net/FAQ/section9.html" title="Asymptote%20FAQ"&gt;in the FAQ&lt;/a&gt;). It turns out that you use the &lt;a href="http://asymptote.sourceforge.net/doc/label.html" title="Asymptote%20label%20function"&gt;label&lt;/a&gt; function to insert an image into an Asymptote document. Here is a snippet of code that I used to assemble a multi-part figure from several EPS documents:&lt;/p&gt;</description></item><item><title>Using the MATLAB Distributed/Parallel Computing Toolbox without modifying your cluster</title><link>https://shocksolution.com/posts/using-the-matlab-distributedparallel-computing-toolbox-without-modifying-your-cluster/</link><pubDate>Wed, 02 Oct 2013 19:44:53 +0000</pubDate><guid>https://shocksolution.com/posts/using-the-matlab-distributedparallel-computing-toolbox-without-modifying-your-cluster/</guid><description>&lt;p&gt;This post shows how I set up MATLAB to perform parallel calculations on a multi-core server which is part of an existing cluster that is managed using Torque and Moab. I did this without making any changes to the cluster submission system. The &lt;a href="http://%3C%3Cwww.mathworks.com/support/product/DM/installation/oldversions.html&amp;amp;gt%3E;" title="MATLAB%20Parallel%20Computing%20Toolbox/Distributed%20Computing%20Server%20"&gt;installation documentation for the MATLAB Parallel Computing Toolbox and Distributed Computing Server&lt;/a&gt; is poor. The instructions make a lot of assumptions that don&amp;rsquo;t fit into an existing &amp;ldquo;production&amp;rdquo; cluster environment. For example, they assume that a GUI is available to configure the cluster (this step is not required for my method!) Further, the instructions give the impression that MATLAB components must be &amp;ldquo;installed&amp;rdquo; on both the head node and compute nodes by an administrator. THIS IS FALSE! Ordinary users can run concurrent (multicore) MATLAB jobs without administrative privileges!&lt;/p&gt;</description></item><item><title>How to plot .xvg files from GROMACS on Windows</title><link>https://shocksolution.com/posts/how-to-plot-xvg-files-from-gromacs-on-windows/</link><pubDate>Tue, 12 Mar 2013 18:00:51 +0000</pubDate><guid>https://shocksolution.com/posts/how-to-plot-xvg-files-from-gromacs-on-windows/</guid><description>&lt;p&gt;&lt;a href="http://%3C%3Cwww.gromacs.org/Documentation/How-tos/Graphing_Data&amp;amp;gt%3E;" title="GROMACS%20xvg%20files"&gt;GROMACS produces graphical output in the form of .xvg files&lt;/a&gt;. These are designed to be viewed with a classic &lt;a href="http://plasma-gate.weizmann.ac.il/Grace/" title="Grace"&gt;UNIX/Linux plotting program called Grace&lt;/a&gt;. If you happen to be using Linux and you have Grace installed, it is very easy to plot the data with the command&lt;/p&gt;&#10;&lt;div class="code-block"&gt;&#10; &lt;button class="code-copy" type="button" hidden aria-label="Copy code to clipboard"&gt;&#10; &lt;span class="code-copy-label" aria-hidden="true"&gt;Copy&lt;/span&gt;&#10; &lt;/button&gt;&#10; &lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;xmgrace my_file.xvg&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#10; &lt;/div&gt;&lt;p&gt;If you aren&amp;rsquo;t using Linux, plotting .xvg files is quite a bit more difficult. &lt;a href="http://%3C%3Cwww.gnuplot.info/&amp;amp;gt%3E;" title="Gnuplot"&gt;Gnuplot&lt;/a&gt; is the only free plotting program that I have found that can handle .xvg files. &lt;a href="http://sourceforge.net/projects/gnuplot/files/" title="Gnuplot%20download%20for%20Windows"&gt;Gnuplot is available for Windows&lt;/a&gt; (there is a direct download link near the top of the download page), but I will caution you that Gnuplot is not easy to learn. It has a command-line interface, and there are no point-and-click options to do basic operations such as labeling the axes of the plot. If you are using Gnuplot, you can plot the contents of an .xvg file with the command:&lt;/p&gt;</description></item><item><title>Opportunity for postdoctoral research associate in high performance computing</title><link>https://shocksolution.com/posts/opportunity-for-postdoctoral-research-associate-in-high-performance-computing/</link><pubDate>Mon, 04 Mar 2013 22:51:12 +0000</pubDate><guid>https://shocksolution.com/posts/opportunity-for-postdoctoral-research-associate-in-high-performance-computing/</guid><description>&lt;p&gt;My current employer, the &lt;a href="http://webstokes.ist.ucf.edu" title="STOKES%20ARCC"&gt;STOKES Advanced Research Computing Center (STOKES ARCC)&lt;/a&gt;, is &lt;a href="https://%3Cwww.jobswithucf.com/postings/34718%3E" title="Hiring%20postdoc%20in%20high%20performance%20computing"&gt;hiring a postdoctoral research associate to conduct research in high performance computing with an emphasis on next-generation networking technologies&lt;/a&gt;. The ARCC has internal funding that will be used to upgrade our research network to the &lt;a href="http://%3Cwww.internet2.edu/%3E" title="Internet2"&gt;Internet2&lt;/a&gt; &lt;a href="http://%3Cwww.internet2.edu/pubs/Internet2-Innovation-Platform-FAQ.pdf%3E" title="Innovation%20Platform"&gt;Innovation Platform&lt;/a&gt; standard. We are also seeking external funding to extend the research network across the &lt;a href="http://%3Cwww.ucf.edu/%3E" title="University%20of%20Central%20Florida"&gt;UCF&lt;/a&gt; campus. We are looking for a candidate with an interest in topics such as defining a &amp;ldquo;Science DMZ,&amp;rdquo; Internet2, GENI, &lt;a href="http://%3Cwww.internet2.edu/performance/pS-PS/%3E" title="perfSONAR-PS"&gt;perfSONAR&lt;/a&gt;, software-defined networks, etc. Please use the link above to apply for the position. Feel free to contact me if you have questions-&lt;a href="https://shocksolution.com/about_craig_finch/" title="Contact%20Craig%20Finch"&gt;my contact information is on the about page&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Updated GROMACS tutorials</title><link>https://shocksolution.com/posts/updated-gromacs-tutorials/</link><pubDate>Thu, 28 Feb 2013 21:40:54 +0000</pubDate><guid>https://shocksolution.com/posts/updated-gromacs-tutorials/</guid><description>&lt;p&gt;I have published &lt;a href="https://github.com/cfinch/GROMACS_Examples" title="GROMACS%20Tutorials"&gt;up-to-date versions of two classic GROMACS tutorials&lt;/a&gt; on GitHub. The &lt;a href="http://manual.gromacs.org/online/getting_started.html" title="GROMACS%20Getting%20Started"&gt;Getting Started section of the GROMACS online documentation&lt;/a&gt; contains some helpful tutorials.  Unfortunately, these tutorials have not been updated in a while. They also don&amp;rsquo;t explain how to set up an efficient workflow to run large molecular dynamics simulations on a shared cluster using a resource manager such at &lt;a href="http://%3Cwww.adaptivecomputing.com/products/open-source/torque/%3E" title="Torque%20resource%20manager"&gt;Torque&lt;/a&gt;. I have created a set of files that implement the &lt;a href="http://manual.gromacs.org/online/speptide.html" title="speptide%20molecular%20dynamics%20tutorial"&gt;speptide tutorial&lt;/a&gt; from the GROMACS documentation.You can use my files and follow along with the explanations in the GROMACS manual. The speptide directory has two subdirectories: one for MDP files (which control the simulations) and one for simulation files. I have found this to be an efficient setup because many MD experiments involve simulating multiple variants of a molecule (such as mutants of a protein) and comparing the results. All variants should be run with the same parameters, so the same MDP files are used for each simulation. Keeping the MDP files in their own directory and creating symbolic links from the run directory to the MDP files ensures that all simulations are run with identical parameters. In the &lt;strong&gt;run&lt;/strong&gt; directory, there is a Bash script called setup_GROMACS_job.sh. At the top of the script, the user sets variables to set simulation parameters such as the box size. The script can be run with the command&lt;/p&gt;</description></item><item><title>Installing Lumerical FDTD on a linux cluster</title><link>https://shocksolution.com/posts/installing-lumerical-fdtd-on-a-linux-cluster/</link><pubDate>Mon, 25 Feb 2013 20:25:43 +0000</pubDate><guid>https://shocksolution.com/posts/installing-lumerical-fdtd-on-a-linux-cluster/</guid><description>&lt;p&gt;Most of the time, RPM (especially in conjunction with yum) is a decent package management solution. However, I can think of two common circumstances when you don&amp;rsquo;t want to let RPM install a package:&lt;/p&gt;&#10;&lt;p&gt;&lt;em&gt;You don&amp;rsquo;t have root permissions on a system such as a shared cluster&lt;/em&gt; You are an administrator on a shared cluster and you can&amp;rsquo;t risk having a package over-write system-critical files&lt;/p&gt;&#10;&lt;p&gt;One approach is to &lt;a href="http://%3Cwww.cyberciti.biz/tips/how-to-extract-an-rpm-package-without-installing-it.html%3E" title="Extract%20files%20from%20RPM%20package"&gt;extract the files from the RPM package&lt;/a&gt; and install them manually. I used this method to install &lt;a href="http://%3Cwww.lumerical.com/tcad-products/fdtd/%3E" title="FDTD%20Solutions"&gt;FDTD Solutions&lt;/a&gt; from &lt;a href="http://%3Cwww.lumerical.com/%3E" title="Lumerical"&gt;Lumerical&lt;/a&gt; on the &lt;a href="http://webstokes.ist.ucf.edu/" title="STOKES%20ARCC"&gt;STOKES Linux cluster&lt;/a&gt;. The application is distributed as an RPM package. I &lt;em&gt;never&lt;/em&gt; install a third-party RPM as root, because a badly constructed package might over-write a system-critical file that some user is depending on. I downloaded the appropriate TAR file from Lumerical, uncompressed it, and looked at the contents. There is a simple script called install.sh which checks to make sure the user is root and then tries to install a hardware key driver and an RPM that contains the FDTD software. Here are my recommendations for installing Lumerical products on a cluster:&lt;/p&gt;</description></item><item><title>OpenMPI, Intel Compilers and RedHat 5: cannot find -lnuma</title><link>https://shocksolution.com/posts/openmpi-on-redhat-5-cannot-find-lnuma/</link><pubDate>Wed, 20 Feb 2013 23:21:42 +0000</pubDate><guid>https://shocksolution.com/posts/openmpi-on-redhat-5-cannot-find-lnuma/</guid><description>&lt;p&gt;I found an interesting quirk when trying to build an OpenMPI application on a visualization node with a &amp;ldquo;stock&amp;rdquo; version of Red Hat Enterprise Linux 5.8.  I used mpicc to compile the application and got the following error:&lt;/p&gt;&#10;&lt;div class="code-block"&gt;&#10; &lt;button class="code-copy" type="button" hidden aria-label="Copy code to clipboard"&gt;&#10; &lt;span class="code-copy-label" aria-hidden="true"&gt;Copy&lt;/span&gt;&#10; &lt;/button&gt;&#10; &lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ mpicc hello_world_mpi.c -o hello_world&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;/usr/bin/ld: cannot find -lnuma&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#10; &lt;/div&gt;&lt;p&gt;This was rather surprising, since this node mounts a directory via NFS that contains OpenMPI and Intel Composer 2013, and these applications are known to work on other nodes. To find the source of the problem, I used the &lt;strong&gt;showme&lt;/strong&gt; option to see the command that is actually run by mpicc:&lt;/p&gt;</description></item><item><title>Building NumPy and SciPy with Intel Composer 2013 and the MKL</title><link>https://shocksolution.com/posts/building-numpy-and-scipy-with-intel-composer-2013-and-the-mkl/</link><pubDate>Wed, 16 Jan 2013 22:29:19 +0000</pubDate><guid>https://shocksolution.com/posts/building-numpy-and-scipy-with-intel-composer-2013-and-the-mkl/</guid><description>&lt;p&gt;Since Python is widely used as a high-productivity language for scientific computing, &lt;a href="http://software.intel.com/en-us/articles/numpy-scipy-with-mkl" title="Intel:%20building%20NumPy%20with%20Intel%20compilers%20and%20MKL"&gt;Intel has created a page showing how to build NumPy with Intel compilers and the Math Kernel Library (MKL)&lt;/a&gt;. I would like to clarify a few items regarding building NumPy on a 64-bit Red Hat Enterprise Linux 5.4 system. Since this is a production system, I don&amp;rsquo;t want to replace the Python 2.4 binary -2.7.3-intel-composer-2013that ships with RHEL 5.4. Instead, I created a directory called&lt;/p&gt;</description></item><item><title>Installing and configuring Infiniband on a Red Hat system</title><link>https://shocksolution.com/posts/installing-and-configuring-infiniband-on-a-red-hat-system/</link><pubDate>Wed, 12 Dec 2012 23:15:54 +0000</pubDate><guid>https://shocksolution.com/posts/installing-and-configuring-infiniband-on-a-red-hat-system/</guid><description>&lt;p&gt;This post will take you through the installation and configuration of an Infiniband card on a server running Red Hat Enterprise Linux 5.4.  These steps are applicable to any version of Red Hat 5, and will probably work with version 6 as well.  It has been surprisingly hard to find all of these steps in one document.&lt;/p&gt;&#10;&lt;h2 id="required-packages"&gt;Required packages&lt;/h2&gt;&#10;&lt;p&gt;openib-1.4.1-6.el5.noarch libibverbs-1.1.3-2.el5.x86_64 libnes-0.9.0-2.el5.x86_64 libibumad-1.3.3-1.el5.x86_64 opensm-libs-3.3.3-2.el5.x86_64 swig-1.3.29-2.el5.x86_64 ibutils-libs-1.2-11.1.el5.x86_64 ibutils-1.2-11.1.el5.x86_64 (provides ibdiagnet and others) opensm-3.3.3-2.el5.x86_64 libibmad-1.3.3-1.el5.x86_64 infiniband-diags-1.5.3-1.el5.x86_64 (provides handy tools like ibstat and ibstatus) libibverbs-utils-1.1.3-2.el5.x86_64 (provides handy tools ibv_devinfo and ibv_devices) libibverbs-devel-1.1.3-2.el5.x86_64&lt;/p&gt;</description></item><item><title>Managing an HPC cluster or cloud infrastructure: alternatives to xCAT</title><link>https://shocksolution.com/posts/managing-an-hpc-cluster-or-cloud-infrastructure-alternatives-to-xcat/</link><pubDate>Sun, 04 Nov 2012 19:01:15 +0000</pubDate><guid>https://shocksolution.com/posts/managing-an-hpc-cluster-or-cloud-infrastructure-alternatives-to-xcat/</guid><description>&lt;p&gt;&lt;a href="http://sourceforge.net/apps/mediawiki/xcat/index.php?title=Main_Page" title="xCAT%20home%20page"&gt;xCAT is the eXtreme Cloud Administration Toolkit from IBM&lt;/a&gt;.  It&amp;rsquo;s a suite of tools that IBM has developed to manage large groups of servers, such as a cloud infrastructure or a high-performance computing cluster (HPCC).  I have only used xCAT to administer a mid-sized compute cluster (about 140 compute nodes totaling about 1400 cores running &lt;a href="https://access.redhat.com/knowledge/docs/Red_Hat_Enterprise_Linux/" title="Red%20Hat%20Enterprise%20Linux%20Documentation"&gt;RHEL 5&lt;/a&gt;).  Overall, I have not found xCAT to be particularly effective for managing a mid-sized cluster.  In many ways, xCAT is a brilliant piece of software, but like many &amp;ldquo;brilliant&amp;rdquo; solutions, it&amp;rsquo;s just too complex for its own good.  There might be a cluster that is so large and complex that only a tool like xCAT can effectively manage it (especially if you have an administrative staff and you can pay someone to be a full-time xCAT guru).  If you have a smaller cluster with limited administrative resources, you&amp;rsquo;re better off finding a simpler management solution. In contrast, I will briefly outline the administrative tools provided by &lt;a href="http://%3Cwww.aspsys.com/%3E" title="Aspen%20Systems,%20Inc."&gt;Aspen Systems&lt;/a&gt;.  We are in the process of expanding our IBM x1350 cluster with about 1000 compute cores from Aspen. Aspen has developed their own suite of cluster administration tools that take a very different approach.  For a system such as ours (2400 cores total), the Aspen approach makes a lot more sense.  &lt;a href="http://%3Cwww.aspsys.com/clients%3E" title="Aspen%20Systems%20customers"&gt;The Aspen tools have also been used to manage much larger clusters for customers such as NOAA, NREL and NIST&lt;/a&gt;, so I&amp;rsquo;m not sure if there is a cluster that is &amp;ldquo;too big&amp;rdquo; for Aspen&amp;rsquo;s tools.  I&amp;rsquo;ll list some of the key differences between the IBM and Aspen systems:&lt;/p&gt;</description></item><item><title>An Improved Ebuild for OpenFOAM on Gentoo Linux</title><link>https://shocksolution.com/posts/an-improved-ebuild-for-openfoam-on-gentoo-linux/</link><pubDate>Mon, 22 Oct 2012 09:38:00 +0000</pubDate><guid>https://shocksolution.com/posts/an-improved-ebuild-for-openfoam-on-gentoo-linux/</guid><description>&lt;p&gt;&lt;a href="http://%3C%3Cwww.openfoam.org/&amp;amp;gt%3E;" title="OpenFOAM"&gt;OpenFOAM&lt;/a&gt; is a notoriously difficult piece of software to compile, install and run. OpenCFD (the authors of OpenFOAM) have chosen to require the use of recent versions of gcc that are not available on most stable enterprise-class systems (ie Red Hat Enterprise Linux). To make things worse, until recently, OpenCFD also bundled a large number of libraries and helper applications (like VTK and ParaView) with the OpenFOAM source instead of using libraries and tools that are already on the system. Fortunately, OpenCFD has now moved the extra tools to a separate tarball, and the wizards at Gentoo have managed to create an ebuild for OpenFOAM. This is why I run Gentoo on my desktop workstation!&lt;/p&gt;</description></item><item><title>Hack of the Day: running CFD-ACE+ on Gentoo Linux</title><link>https://shocksolution.com/posts/hack-of-the-day-running-cfd-ace-on-gentoo-linux/</link><pubDate>Tue, 24 Jul 2012 18:50:49 +0000</pubDate><guid>https://shocksolution.com/posts/hack-of-the-day-running-cfd-ace-on-gentoo-linux/</guid><description>&lt;p&gt;&lt;a href="http://%3C%3Cwww.esi-cfd.com/&amp;amp;gt%3E;" title="CFD-ACE+"&gt;CFD-ACE+&lt;/a&gt; is a multiphysics and computational fluid dynamics (CFD) simulation tool that was originally developed by &lt;a href="http://%3C%3Cwww.cfdrc.com/&amp;amp;gt%3E;" title="CFDRC"&gt;CFD Research Corp.&lt;/a&gt; and is now distributed by ESI Software. The only platforms officially supported by CFD-ACE+ are Red Hat Enterprise Linux, SUSE Linux and Windows. Fortunately, it seems that ACE+ runs on other Linux distributions with only a little hacking. I just installed and tested CFD-ACE+ successfully (albeit not very thoroughly) on an up-to-date Gentoo Linux system.  The process will require hacking some config files to build an external library from source. I started by downloading the files intended for Red Hat 6. Each package is a strange self-extracting executable file that unpacks itself when run. They also provide a C-shell script called install.com that automates the install process. The install script is very well behaved in that it doesn&amp;rsquo;t try to spew libraries and binaries throughout your filesystem, and you can run it as an ordinary user and install the file in your home directory.  The tricky part about the installation is that the unpacking software (which is bundled into the self-extracting executable) needs the library selinux.so.1 in order to run. That library isn&amp;rsquo;t normally installed on a Gentoo system unless you&amp;rsquo;ve specifically set up SELinux.  In order to avoid the potential problems of installing this library in my system paths,  I  created &lt;strong&gt;src&lt;/strong&gt;and&lt;strong&gt;include&lt;/strong&gt;directories in my home directory.  I downloaded source tarballs for libsepol and libselinux from the &lt;a href="http://userspace.selinuxproject.org/releases/" title="SELinux%20Source%20Downloads"&gt;download page of the selinux project&lt;/a&gt;.  First, build libsepol using&lt;strong&gt;make&lt;/strong&gt;.  Then, copy the libsepol.so.1 binary from the src directory to the lib directory you just created in your home directory. Copy the include/sepol directory with all of its contents to the include directory in your home directory.  When you are done, you should have:&lt;/p&gt;</description></item><item><title>Building SciPy with Intel compilers and MKL on 64bit RHEL 5</title><link>https://shocksolution.com/posts/building-scipy-with-intel-compilers-and-mkl-on-64bit-rhel-5/</link><pubDate>Mon, 02 Jul 2012 17:14:54 +0000</pubDate><guid>https://shocksolution.com/posts/building-scipy-with-intel-compilers-and-mkl-on-64bit-rhel-5/</guid><description>&lt;p&gt;This is a follow-up to my earlier &lt;a href="https://shocksolution.com/2012/04/building-numpy-on-a-red-hat-cluster-with-intel-mkl/" title="NumPy%20on%2064%20bit%20RHEL%205%20with%20Intel%20Compilers%20and%20MKL"&gt;post about building NumPy with Intel compilers and the Intel MKL on CentOS 5&lt;/a&gt;. I will now explain how to build SciPy (which requires NumPy). First, download and unpack the SciPy source tarball. The following command can be used to build SciPy:&lt;/p&gt;&#10;&lt;div class="code-block"&gt;&#10; &lt;button class="code-copy" type="button" hidden aria-label="Copy code to clipboard"&gt;&#10; &lt;span class="code-copy-label" aria-hidden="true"&gt;Copy&lt;/span&gt;&#10; &lt;/button&gt;&#10; &lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;LDFLAGS=&amp;#34;&amp;#34; FFLAGS=&amp;#34;-fPIC -openmp&amp;#34; python2.7 setup.py build --fcompiler=intelem &amp;amp;&amp;gt; build.out&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#10; &lt;/div&gt;&lt;p&gt;I set the LDFLAGS variable to an empty string to avoid using any LDFLAGS which are defined in my .bashrc. The &lt;strong&gt;-fPIC&lt;/strong&gt;tells the compiler to create position-independent code, although this flag may not be required for newer compilers (ours are quote old: ifort (IFORT) 10.1 20070913 and icc (ICC) 10.1 20070913). I used the**-openmp&lt;strong&gt;flag to be consistent with the flags I used for building NumPy. The option&lt;/strong&gt;--fcompiler=intelem** forces the Intel Fortran compiler to be used instead of g77. I redirected all output to a file called build.out, which is helpful for finding errors and warnings in the build output. Once you have built SciPy successfully, install it with the following command:&lt;/p&gt;</description></item><item><title>Benchmarking BLAS Part 1: Building BLASbench with gcc</title><link>https://shocksolution.com/posts/benchmarking-blas-part-1-building-blasbench-with-gcc/</link><pubDate>Fri, 25 May 2012 22:37:22 +0000</pubDate><guid>https://shocksolution.com/posts/benchmarking-blas-part-1-building-blasbench-with-gcc/</guid><description>&lt;p&gt;I recently installed &lt;a href="http://math-atlas.sourceforge.net/" title="ATLAS"&gt;ATLAS&lt;/a&gt; on my new workstation and I&amp;rsquo;ve been wondering what kind of performance gain I would get compared to the &lt;a href="http://%3Cwww.netlib.org/blas/%3E" title="BLAS"&gt;reference BLAS&lt;/a&gt;. After some searching, I finally found a BLAS benchmarking tool called &lt;a href="http://icl.cs.utk.edu/projects/llcbench/blasbench.html" title="BLASbench"&gt;BLASbench&lt;/a&gt;, which is part of the &lt;a href="http://icl.cs.utk.edu/projects/llcbench/index.htm" title="LLCbench"&gt;LLCbench&lt;/a&gt; suite. This tool has a rather strange build process, so follow the instructions on the web page.  You have to create a file called sys.def which contains build instructions for your system.  Here&amp;rsquo;s the sys.def file I used for my Gentoo system:&lt;/p&gt;</description></item><item><title>Building NumPy on a 64-bit Red Hat Cluster with Intel MKL</title><link>https://shocksolution.com/posts/building-numpy-on-a-red-hat-cluster-with-intel-mkl/</link><pubDate>Tue, 24 Apr 2012 16:40:40 +0000</pubDate><guid>https://shocksolution.com/posts/building-numpy-on-a-red-hat-cluster-with-intel-mkl/</guid><description>&lt;p&gt;In a previous post I described &lt;a href="https://shocksolution.com/2008/12/update-2-building-64-bit-numpy-with-intel-compilers-and-mkl/" title="Build%20NumPy%20with%20Intel%20Compilers%20and%20MKL"&gt;how to build an optimized version of NumPy using the Intel compilers and Math Kernel Library (MKL)&lt;/a&gt;.  This post will update those instructions, since it has been a few years and I am now using NumPy 1.6.1, MKL 10.0.1.014 and Red Hat 4.1.1 (kernel 2.6.18-8.el5). First, copy the file &lt;strong&gt;site.cfg.example&lt;/strong&gt;to&lt;strong&gt;site.cfg&lt;/strong&gt; and open it in an editor like vim. The commented lines in the file give some explanation of how it works. You only need to add the following lines:&lt;/p&gt;</description></item><item><title>Installing PETSc and libMesh on CentOS 5</title><link>https://shocksolution.com/posts/installing-petsc-and-libmesh-on-centos-5/</link><pubDate>Fri, 20 Jan 2012 20:06:18 +0000</pubDate><guid>https://shocksolution.com/posts/installing-petsc-and-libmesh-on-centos-5/</guid><description>&lt;p&gt;&lt;strong&gt;Prerequisites:&lt;/strong&gt; boost-devel, openmpi-devel, valgrind-devel I installed PETSc and libMesh in my user directory, since I have a single-user workstation.&lt;/p&gt;&#10;&lt;h2 id="installing-petsc-for-use-with-libmesh"&gt;Installing PETSc for use with libMesh&lt;/h2&gt;&#10;&lt;p&gt;First, ensure that OpenMPI is installed and the system paths have been configured correctly.  You will need to add the directory containing OpenMPI binaries to your $PATH, and the directory containing OpenMPI libraries to $LD_LIBRARY_PATH.  CentOS does &lt;em&gt;not&lt;/em&gt; do this automatically!  Type &lt;strong&gt;mpicc&lt;/strong&gt; on the command line to make sure the shell can find the binary.  If mpicc and mpif77 run, then you &lt;a href="http://%3Cwww.open-mpi.org/faq/?category=mpi-apps#petsc%3E" title="OpenMPI%20docs%20on%20PETSc"&gt;should &lt;em&gt;not&lt;/em&gt; need to use the comnand-line flags to the configure script for PETSc&lt;/a&gt;. If you are going to use libMesh with PETSc, you need to enable C++ with a command-line option to the configure script.  Here is the process I used (it might be a good idea to set PETSC_ARCH and PETSC_DIR in your .bashrc so they are consistent for all builds).&lt;/p&gt;</description></item><item><title>Paraview 3.12 on 64-bit CentOS 5.7</title><link>https://shocksolution.com/posts/paraview-3-12-on-64-bit-centos-5-7/</link><pubDate>Thu, 19 Jan 2012 19:23:15 +0000</pubDate><guid>https://shocksolution.com/posts/paraview-3-12-on-64-bit-centos-5-7/</guid><description>&lt;p&gt;I finally got around to installing Paraview on my CentOS 5 box.  There are no official RPMS for CentOS 5, so I was expecting a painful build process. To my great surprise, I was able to &lt;a href="http://%3C%3Cwww.paraview.org/paraview/resources/software.php&amp;amp;gt%3E;" title="Download%20Paraview"&gt;download the Paraview binary&lt;/a&gt; for Linux (64-bit) from Kitware, unpack the archive, and run it!  As root, I placed the entire ParaView-3.12.0 directory under /opt/Paraview.  You could also keep it in your home directory if you are running a single-user system.  I added /opt/Paraview/ParaView-3.12.0/bin to the $PATH in the .bashrc file in my home directory.  Now I can type &lt;strong&gt;paraview&lt;/strong&gt; at the command line and it runs! What if you want Paraview to appear in the Applications menu in your desktop environment?  Most modern desktops (I use XFCE4) construct the Applications menu &amp;ldquo;on the fly&amp;rdquo; based upon the files in a standard directory (/usr/share/applications on CentOS).  The &lt;a href="http://%3C%3Cwww.freedesktop.org/wiki/Home&amp;amp;gt%3E;" title="Free%20Desktop%20Project"&gt;Free Desktop Project&lt;/a&gt; has created a &lt;a href="http://standards.freedesktop.org/desktop-entry-spec/latest/" title="Desktop%20Entry%20File%20Format"&gt;standard for desktop entry files&lt;/a&gt;.  You may also find this &lt;a href="http://linuxcritic.wordpress.com/2010/04/07/anatomy-of-a-desktop-file/" title="Summary%20of%20.desktop%20standard"&gt;summary of the standard&lt;/a&gt; to be helpful.  To add Paraview to the menu, you simply need to create a new file in the standard location.  If you installed Paraview in your user directory, you may want to place the desktop file in $HOME/.local/applications.  Here are the contents of a file I called paraview.desktop:&lt;/p&gt;</description></item><item><title>Installing Sage 4.7 on CentOS 5</title><link>https://shocksolution.com/posts/installing-sage-4-7-on-centos-5/</link><pubDate>Mon, 07 Nov 2011 23:07:59 +0000</pubDate><guid>https://shocksolution.com/posts/installing-sage-4-7-on-centos-5/</guid><description>&lt;p&gt;I recently upgraded my desktop workstation from an old 32-bit version of Gentoo to 64-bit CentOS 5.  I downloaded and installed the latest version of &lt;a href="http://%3Cwww.sagemath.org/%3E" title="Sage%20home%20page"&gt;Sage&lt;/a&gt;, and the process went smoothly. If you find this post helpful, please check out the &lt;a href="http://%3Cwww.packtpub.com/sage-beginners-guide/book%3E" title="Sage%20Beginner's%20Guide"&gt;Sage Beginner&amp;rsquo;s Guide at Packt Publishing&lt;/a&gt;.  Since I don&amp;rsquo;t use Sage every day, I actually refer to my own book on a regular basis!&lt;/p&gt;&#10;&lt;h2 id="download"&gt;Download&lt;/h2&gt;&#10;&lt;p&gt;Since CentOS is designed to be binary compatible with Red Hat Enterprise Linux, the correct binary to download is &lt;strong&gt;sage-4.7.2-linux-64bit-red_hat_enterprise_linux_server_release_5.6_tikanga-x86_64-Linux.tar.gz&lt;/strong&gt;&lt;/p&gt;</description></item><item><title>Python string format examples</title><link>https://shocksolution.com/posts/python-string-format-examples/</link><pubDate>Thu, 03 Nov 2011 22:38:10 +0000</pubDate><guid>https://shocksolution.com/posts/python-string-format-examples/</guid><description>&lt;p&gt;The &lt;a href="http://docs.python.org/library/string.html#format-string-syntax" title="Python%20strings%20format%20method"&gt;format method for Python strings&lt;/a&gt; (introduced in 2.6) is very flexible and powerful.  It&amp;rsquo;s also easy to use, but the documentation is not very clear.  It all makes sense with a few examples.  I&amp;rsquo;ll add more as I have time: &lt;a href="https://%3C%3Cwww.amazon.com/gp/product/0132269937/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0132269937&amp;amp;linkCode=as2&amp;amp;tag=rootwork0f-20&amp;amp;linkId=44971fe03f445ae25fecb2cc2702d3aa&amp;amp;gt%3E;"&gt;&lt;img src="//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;MarketPlace=US&amp;amp;ASIN=0132269937&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL160_&amp;amp;tag=rootwork0f-20" alt="image"&gt;&lt;/a&gt;&lt;img src="//ir-na.amazon-adsystem.com/e/ir?t=rootwork0f-20&amp;amp;l=am2&amp;amp;o=1&amp;amp;a=0132269937" alt="image"&gt;&lt;/p&gt;&#10;&lt;h2 id="formatting-numbers-in-python-strings"&gt;Formatting Numbers in Python Strings&lt;/h2&gt;&#10;&lt;h3 id="formatting-a-floating-point-number"&gt;Formatting a floating-point number&lt;/h3&gt;&#10;&lt;p&gt;[code language=&amp;ldquo;python&amp;rdquo;] &amp;ldquo;{0:.4f}&amp;quot;.format(0.1234567890) &amp;ldquo;{0:.4f}&amp;quot;.format(10.1234567890) [/code] The result is the following string:&lt;/p&gt;&#10;&lt;div class="code-block"&gt;&#10; &lt;button class="code-copy" type="button" hidden aria-label="Copy code to clipboard"&gt;&#10; &lt;span class="code-copy-label" aria-hidden="true"&gt;Copy&lt;/span&gt;&#10; &lt;/button&gt;&#10; &lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&amp;#39;0.1235&amp;#39;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&amp;#39;10.1235&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#10; &lt;/div&gt;&lt;p&gt;Braces { } are used to enclose the &amp;ldquo;replacement field&amp;rdquo; 0 indicates the first argument to method &lt;strong&gt;format&lt;/strong&gt; : indicates the start of the format specifier .4 indicates four decimal places f indicates a floating-point number&lt;/p&gt;</description></item><item><title>How to build ScipPy with Python 2.7.2 on CentOS5</title><link>https://shocksolution.com/posts/how-to-build-scippy-with-python-2-7-2-on-centos5/</link><pubDate>Thu, 25 Aug 2011 00:17:57 +0000</pubDate><guid>https://shocksolution.com/posts/how-to-build-scippy-with-python-2-7-2-on-centos5/</guid><description>&lt;p&gt;EDIT: added &amp;ndash;enable-shared to configure script for building Python, and added /home/yourname/lib to shared library path.  This is necessary for building some packages such as pycairo (which you may need to build pygtk and matplotlib). EDIT 2: you should use the &amp;ndash;prefix=/home/yourusername instead of &amp;ndash;user.  The prefix option places packages in the standard location: /home/yourusername/lib/python2.7/site-packages.  The &amp;ndash;user option places the packages in /home/yourusername/.local/lib/python2.7/site-packages which I think is screwed up!   I use CentoOS5 because I want enterprise-class stability, as well as binary compatibility with a commercial application that is built for RHEL5.  I need to use some &amp;ldquo;bleeding edge&amp;rdquo; packages, such as the latest version of SciPy, but I don&amp;rsquo;t want to affect the base stability of the system.  Here is how I did it.  First, with superuser privileges, use yum to install the following packages.  You may need to set up epel as an alternate repository:&lt;/p&gt;</description></item><item><title>Removing an axis or both axes from a matplotlib plot</title><link>https://shocksolution.com/posts/removing-an-axis-or-both-axes-from-a-matplotlib-plot/</link><pubDate>Wed, 17 Aug 2011 22:40:14 +0000</pubDate><guid>https://shocksolution.com/posts/removing-an-axis-or-both-axes-from-a-matplotlib-plot/</guid><description>&lt;p&gt;Sometimes, the frame around a &lt;a href="http://matplotlib.sourceforge.net/" title="matplotlib"&gt;matplotlib&lt;/a&gt; plot can detract from the information you are trying to convey.  How do you remove the frame, ticks, or axes from a matplotlib plot? &lt;figure class="ma0 w-75"&gt;&lt;img src="https://shocksolution.com/images/plot_without_y_axis.png"&#10;&#9;&#9;&#9;alt="matplotlib plot without a y axis"&gt;&lt;figcaption&gt;&#10;&#9;&#9;&#9;&lt;p&gt;matplotlib plot without a y axis&lt;/p&gt;&#10;&#9;&#9;&lt;/figcaption&gt;&#10;&lt;/figure&gt;&#10;&lt;/p&gt;&#10;&lt;p&gt;Some books you may find useful when working with matplotlib: &lt;a href="https://%3C%3Cwww.amazon.com/gp/product/0132269937/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0132269937&amp;amp;linkCode=as2&amp;amp;tag=rootwork0f-20&amp;amp;linkId=44971fe03f445ae25fecb2cc2702d3aa&amp;amp;gt%3E;"&gt;&lt;img src="//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;MarketPlace=US&amp;amp;ASIN=0132269937&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL160_&amp;amp;tag=rootwork0f-20" alt="image"&gt;&lt;/a&gt;&lt;img src="//ir-na.amazon-adsystem.com/e/ir?t=rootwork0f-20&amp;amp;l=am2&amp;amp;o=1&amp;amp;a=0132269937" alt="image"&gt;&lt;a href="https://%3C%3Cwww.amazon.com/Python-Data-Analysis-Wrangling-IPython/dp/1491957662/ref=as_li_ss_il?keywords=matplotlib&amp;amp;qid=1537646489&amp;amp;sr=8-12&amp;amp;ref=sr_1_12&amp;amp;linkCode=li2&amp;amp;tag=rootwork0f-20&amp;amp;linkId=545b965f9a5ae1055ae778fca7628568&amp;amp;language=en_US&amp;amp;gt%3E;"&gt;&lt;img src="//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;ASIN=1491957662&amp;amp;Format=_SL160_&amp;amp;ID=AsinImage&amp;amp;MarketPlace=US&amp;amp;ServiceVersion=20070822&amp;amp;WS=1&amp;amp;tag=rootwork0f-20&amp;amp;language=en_US" alt="image"&gt;&lt;/a&gt;&lt;img src="https://ir-na.amazon-adsystem.com/e/ir?t=rootwork0f-20&amp;amp;language=en_US&amp;amp;l=li2&amp;amp;o=1&amp;amp;a=1491957662" alt="image"&gt;&lt;a href="https://%3C%3Cwww.amazon.com/Mastering-matplotlib-Duncan-M-McGreggor/dp/1783987545/ref=as_li_ss_il?keywords=matplotlib&amp;amp;qid=1537646489&amp;amp;sr=8-1&amp;amp;ref=sr_1_1&amp;amp;linkCode=li2&amp;amp;tag=rootwork0f-20&amp;amp;linkId=ec917748d4c441f93e36024379f32b58&amp;amp;language=en_US&amp;amp;gt%3E;"&gt;&lt;img src="//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;ASIN=1783987545&amp;amp;Format=_SL160_&amp;amp;ID=AsinImage&amp;amp;MarketPlace=US&amp;amp;ServiceVersion=20070822&amp;amp;WS=1&amp;amp;tag=rootwork0f-20&amp;amp;language=en_US" alt="image"&gt;&lt;/a&gt;&lt;img src="https://ir-na.amazon-adsystem.com/e/ir?t=rootwork0f-20&amp;amp;language=en_US&amp;amp;l=li2&amp;amp;o=1&amp;amp;a=1783987545" alt="image"&gt;&lt;a href="https://%3C%3Cwww.amazon.com/Matplotlib-Plotting-Cookbook-Alexandre-Devert/dp/1849513260/ref=as_li_ss_il?keywords=matplotlib&amp;amp;qid=1537646489&amp;amp;sr=8-2&amp;amp;ref=sr_1_2&amp;amp;linkCode=li2&amp;amp;tag=rootwork0f-20&amp;amp;linkId=6b7d2e5dacde0fa357c7d0316befb29b&amp;amp;language=en_US&amp;amp;gt%3E;"&gt;&lt;img src="//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;ASIN=1849513260&amp;amp;Format=_SL160_&amp;amp;ID=AsinImage&amp;amp;MarketPlace=US&amp;amp;ServiceVersion=20070822&amp;amp;WS=1&amp;amp;tag=rootwork0f-20&amp;amp;language=en_US" alt="image"&gt;&lt;/a&gt;&lt;img src="https://ir-na.amazon-adsystem.com/e/ir?t=rootwork0f-20&amp;amp;language=en_US&amp;amp;l=li2&amp;amp;o=1&amp;amp;a=1849513260" alt="image"&gt;&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://github.com/cfinch/Shocksolution_Examples/tree/master/Plotting/matplotlib" title="Removing%20an%20axis%20from%20a%20Matplotlib%20plot"&gt;The full example is available on github&lt;/a&gt;.&lt;/p&gt;&#10;&lt;p&gt;First, we construct a figure and an axes object:&lt;/p&gt;&#10;&lt;div class="code-block"&gt;&#10; &lt;button class="code-copy" type="button" hidden aria-label="Copy code to clipboard"&gt;&#10; &lt;span class="code-copy-label" aria-hidden="true"&gt;Copy&lt;/span&gt;&#10; &lt;/button&gt;&#10; &lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;fig1 = plt.figure(facecolor=&amp;#39;white&amp;#39;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax1 = plt.axes(frameon=False)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#10; &lt;/div&gt;&lt;p&gt;The Axes object is a container that holds the axes, the ticks, the labels, the plot, the legend, etc.  You will always have an Axes object, even if the axes are not visible! The keyword argument &lt;strong&gt;frameon=False&lt;/strong&gt; turns the frame off. An alternative method is:&lt;/p&gt;</description></item><item><title>Finding dimensions of a bounding box in Jmol</title><link>https://shocksolution.com/posts/finding-dimensions-of-a-bounding-box-in-jmol/</link><pubDate>Mon, 13 Jun 2011 20:22:35 +0000</pubDate><guid>https://shocksolution.com/posts/finding-dimensions-of-a-bounding-box-in-jmol/</guid><description>&lt;p&gt;The &lt;a href="http://jmol.sourceforge.net/" title="Jmol%20homepage"&gt;Jmol&lt;/a&gt; applet (or Java application) is widely used to visualize the structure of molecules.  It is very powerful, but not that well documented. If you don&amp;rsquo;t have Jmol running, open the page for &lt;a href="http://%3Cwww.pdb.org/pdb/explore/jmol.do?structureId=1CF3&amp;amp;opt=3&amp;amp;bionumber=1%3E" title="PDB%201CF3"&gt;Glucose Oxidase (1CF3) from the Protein Databank&lt;/a&gt; so you can follow the instructions for finding the size of the bounding box. Right-click on the applet to get a pop-up menu with lots of options.  Under the &lt;strong&gt;Style&lt;/strong&gt;submenu, click on&lt;strong&gt;Boundbox&lt;/strong&gt;to show a bounding box around the molecule: &lt;figure class="ma0 w-75"&gt;&lt;img src="https://shocksolution.com/images/show_boundbox_menu.png"&#10;&#9;&#9;&#9;alt="Show bounding box"&gt;&lt;figcaption&gt;&#10;&#9;&#9;&#9;&lt;p&gt;Show bounding box&lt;/p&gt;</description></item><item><title>A self-contained Fortran linear equation solver</title><link>https://shocksolution.com/posts/a-self-contained-fortran-linear-equation-solver/</link><pubDate>Wed, 16 Mar 2011 21:33:27 +0000</pubDate><guid>https://shocksolution.com/posts/a-self-contained-fortran-linear-equation-solver/</guid><description>&lt;p&gt;I&amp;rsquo;ve just released a self-contained Fortran module that solves a system of linear equations using the LU decomposition. &lt;a href="https://github.com/cfinch/Shocksolution_Examples/tree/master/FORTRAN/LinearEquationSolver" title="Fortran%20linear%20system%20solver"&gt;Download the Fortran linear solver from github&lt;/a&gt; This module is based on code that was implemented and released on the Web by &lt;a href="http://jean-pierre.moreau.pagesperso-orange.fr/f_matrices.html"&gt;Jean-Pierre Moreau&lt;/a&gt;.  His implementation was based on one of the &lt;a href="http://%3Cwww.nr.com/%3E"&gt;Numerical Recipes&lt;/a&gt; books.  I updated his code to a more strict Fortran 90 standard and added the necessary comments so that it can be built as a Python module using &lt;a href="http://%3Cwww.scipy.org/F2py%3E" title="f2py"&gt;f2py&lt;/a&gt;.  I replaced Jean-Pierre&amp;rsquo;s Fortran test program with a simpler, self-contained program.  I also included a Python script that implements the same test case. I created this module because sometimes a self-contained routine is more appropriate than a full library.  I am compiling a library that implements a custom boundary condition for a proprietary computational fluid dynamics solver (CFD-ACE+).  The library has to be written in Fortran, and it has to be built using a proprietary set of build scripts.  I could either try to reverse-engineer the build process and to modify it to link to a shared library like &lt;a href="http://%3Cwww.netlib.org/lapack/%3E" title="LAPACK"&gt;LAPACK&lt;/a&gt;, or I could implement a self-contained solver.  Since Pierre had already implemented the solver, I was able to slightly modify his code and get it working relatively quickly.&lt;/p&gt;</description></item><item><title>Finding a value in an unordered Fortran array</title><link>https://shocksolution.com/posts/finding-value-in-unordered-fortran-array/</link><pubDate>Fri, 11 Mar 2011 16:27:51 +0000</pubDate><guid>https://shocksolution.com/posts/finding-value-in-unordered-fortran-array/</guid><description>&lt;p&gt;I have been optimizing some Fortran code that involved searching for an integer value in an unordered array (we know the value occurs only once).  Since there is no intrinsic procedure to accomplish this, I thought I&amp;rsquo;d try a couple of approaches to see which was fastest.  The simple answer is that, in this case, brute force beats elegance, even when the target value is near the end of the array. &lt;a href="https://github.com/cfinch/Shocksolution_Examples/tree/master/FORTRAN/FindElementInArray" title="Example%20code"&gt;Download the full example from GitHub&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Sage: open-source mathematical software</title><link>https://shocksolution.com/posts/sage-open-source-mathematical-software/</link><pubDate>Mon, 07 Mar 2011 14:07:19 +0000</pubDate><guid>https://shocksolution.com/posts/sage-open-source-mathematical-software/</guid><description>&lt;p&gt;I&amp;rsquo;ve recently gained a lot of experience with &lt;a href="http://%3Cwww.sagemath.org/%3E" title="Sage"&gt;Sage&lt;/a&gt;, an open-source alternative to MATLAB, Mathematica, Maple, MuPAD, and Magma.  Here are a couple of links to check out:&lt;/p&gt;&#10;&lt;p&gt;&lt;em&gt;&lt;a href="http://%3Cwww.sagenb.org/%3E" title="Sage%20public%20notebook%20servers"&gt;Public notebook servers&lt;/a&gt;--try it online right now!&lt;/em&gt; &lt;a href="http://wiki.sagemath.org/interact" title="Interactive%20Sage%20examples"&gt;Interactive examples with Sage&lt;/a&gt;&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;a href="http://sagemath.org/library-publications.html" title="Publications%20citing%20Sage"&gt;Mathematical publications citing Sage&lt;/a&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h2 id="sage-vs-mathematica"&gt;Sage vs. Mathematica&lt;/h2&gt;&#10;&lt;p&gt;My experience with mathematical software started my freshman year at the University of Illinois when I signed up for a calculus class that was taught almost entirely with Mathematica.  I grew to love Mathematica&amp;rsquo;s symbolic computation and plotting capabilities, although I found its programming language to be cumbersome.  Once I was no longer a student, Mathematica was no longer an option due to the hefty licensing fees.  With the caveat that I haven&amp;rsquo;t used Mathematica in many years,  I will say that Sage compares very favorably to my experience with Mathematica.  Sage has a notebook interface that allows you to integrate code, results, text, typeset equations, and graphics in an interactive document that can be viewed with any standards-compliant web browser.  I don&amp;rsquo;t know how Sage stacks up against Mathematica in areas of advanced mathematics.  I have heard that Sage is far ahead of Mathematica in number theory, because the lead developer of Sage is a number theorist.&lt;/p&gt;</description></item><item><title>Linear system simulation with Python</title><link>https://shocksolution.com/posts/linear-system-simulation-with-python/</link><pubDate>Fri, 17 Dec 2010 21:33:16 +0000</pubDate><guid>https://shocksolution.com/posts/linear-system-simulation-with-python/</guid><description>&lt;p&gt;Linear time-invariant (LTI) systems are widely used in the field of signal processing.  &lt;a href="http://scipy.org/" title="Scipy"&gt;Scipy&lt;/a&gt; contains powerful tools for simulating LTI systems in the &lt;a href="http://docs.scipy.org/doc/scipy/reference/signal.html" title="scipy.signal%20docs"&gt;scipy.signal&lt;/a&gt; package, but they are not well documented.  I will provide a simple example that demonstrates how to use a few of the core classes and functions in scipy.signal for simulating LTI systems with Python.&lt;/p&gt;&#10;&lt;h2 id="define-an-lti-system"&gt;Define an LTI system&lt;/h2&gt;&#10;&lt;p&gt;You will need to have Scipy installed, and you will need to have &lt;a href="http://matplotlib.sourceforge.net/" title="Matplotlib"&gt;Matplotlib&lt;/a&gt; as well to make plots. We will start with an example of a &lt;a href="http://en.wikipedia.org/wiki/Time_constant" title="Time%20constant"&gt;first-order LTI system&lt;/a&gt;, which is characterized by a single parameter known as the time constant.  scipy.signal defines the class &lt;strong&gt;lti&lt;/strong&gt; to represent a linear system in Python.&lt;/p&gt;</description></item><item><title>Using Microsoft Word for Technical Documents</title><link>https://shocksolution.com/posts/using-microsoft-word-for-technical-documents/</link><pubDate>Wed, 18 Aug 2010 23:30:34 +0000</pubDate><guid>https://shocksolution.com/posts/using-microsoft-word-for-technical-documents/</guid><description>&lt;p&gt;Microsoft Word is not the best tool for doing technical writing.  However, sometimes we are required to use Word because we need to collaborate with others who want to use Word.  Right now, I am using Word 2007  on Windows XP to write several mathematical papers.  In general, it is a big improvement from previous versions.  The new integrated equation editor is outstanding&amp;ndash;except for the major bug I&amp;rsquo;ll discuss below.  Here is a brief &amp;ldquo;FAQ&amp;rdquo; you will want to read if you are using Word for technical writing. **Q:**How do I enter multi-line equations in Word 2007?**A:&lt;strong&gt;Press Shift-Enter where you want a line break to appear&lt;/strong&gt;Q:**How do I prevent a page break from splitting a table into two parts?**A:**Select the table.  On the Home tab, click the little box in the lower-right corner of the Paragraph box.  On the paragraph dialog, choose the &amp;ldquo;Lines and Page Breaks&amp;rdquo; tab.  Check the box for &amp;ldquo;Keep Lines Together.&amp;rdquo;**Q:**How do I automatically number headings in Word 2007?  For example: Section 1, Subsection 1.1, 1.2, 1.3, Section 2, etc.**A:**It&amp;rsquo;s not obvious.  &lt;a href="http://%3Cwww.dummies.com/how-to/content/numbering-headings-in-word-2007-multilevel-lists0.html%3E" title="Numbering%20headings%20in%20Word%202007"&gt;See this page from dummies.com about number headings&lt;/a&gt;.**Q:**In Word 2007, why do equations sometimes appear as blank spaces or question marks when I print or save my document as a PDF file?**A.**This occurs when Word is installed on Windows XP Pro.  See the following Microsoft tech support item to find out how to install missing scripts: &lt;a href="http://support.microsoft.com/kb/960985" title="Microsoft%20Support%20Item%20960985"&gt;The characters in an equation are not printed&lt;/a&gt;&amp;hellip; You may also have an outdated printer driver: &lt;a href="http://support.microsoft.com/kb/920228" title="Microsoft%20Support%20Item%20920228"&gt;Microsoft Support Item 920228&lt;/a&gt;**Q:**Why do equations created in Word 2007 disappear when I open the document in Word 2008 for Mac?&lt;strong&gt;A.&lt;/strong&gt; &lt;a href="http://tinyurl.com/2knb6l" title="Word%20for%20Mac%20does%20not%20support%20Word%202007%20equations"&gt;Word for Mac does not support equations written in the new Word 2007 equation editor&lt;/a&gt;. Unfortunately, neither does PowerPoint 2007 on the PC.  You can work around this by inserting equations into Word the old-fashioned way: go to the Insert tab, click on Object (found in the &amp;ldquo;Text&amp;rdquo; box towards the right side of the tab), and choose &amp;ldquo;Microsoft Equation 3.0&amp;rdquo; from the list in the dialog box.&lt;/p&gt;</description></item><item><title>Constrained least-squares fitting with Python</title><link>https://shocksolution.com/posts/constrained-least-squares-fitting-with-python/</link><pubDate>Fri, 05 Mar 2010 19:27:25 +0000</pubDate><guid>https://shocksolution.com/posts/constrained-least-squares-fitting-with-python/</guid><description>&lt;p&gt;&lt;a href="https://%3C%3Cwww.amazon.com/Elegant-SciPy-Art-Scientific-Python/dp/1491922877/ref=as_li_ss_il?keywords=scipy&amp;amp;qid=1537721480&amp;amp;sr=8-2&amp;amp;ref=sr_1_2&amp;amp;linkCode=li2&amp;amp;tag=rootwork0f-20&amp;amp;linkId=b82af06689ab1a386116469d41f270d6&amp;amp;language=en_US&amp;amp;gt%3E;"&gt;&lt;img src="//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;ASIN=1491922877&amp;amp;Format=_SL160_&amp;amp;ID=AsinImage&amp;amp;MarketPlace=US&amp;amp;ServiceVersion=20070822&amp;amp;WS=1&amp;amp;tag=rootwork0f-20&amp;amp;language=en_US" alt="image"&gt;&lt;/a&gt;&lt;img src="https://ir-na.amazon-adsystem.com/e/ir?t=rootwork0f-20&amp;amp;language=en_US&amp;amp;l=li2&amp;amp;o=1&amp;amp;a=1491922877" alt="image"&gt;&lt;a href="https://%3C%3Cwww.amazon.com/Learning-Numerical-Scientific-Computing-Second/dp/1783987707/ref=as_li_ss_il?keywords=scipy&amp;amp;qid=1537721480&amp;amp;sr=8-3&amp;amp;ref=sr_1_3&amp;amp;linkCode=li2&amp;amp;tag=rootwork0f-20&amp;amp;linkId=4f28164dbe2c853ec36f6f35b052e71a&amp;amp;language=en_US&amp;amp;gt%3E;"&gt;&lt;img src="//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;ASIN=1783987707&amp;amp;Format=_SL160_&amp;amp;ID=AsinImage&amp;amp;MarketPlace=US&amp;amp;ServiceVersion=20070822&amp;amp;WS=1&amp;amp;tag=rootwork0f-20&amp;amp;language=en_US" alt="image"&gt;&lt;/a&gt;&lt;img src="https://ir-na.amazon-adsystem.com/e/ir?t=rootwork0f-20&amp;amp;language=en_US&amp;amp;l=li2&amp;amp;o=1&amp;amp;a=1783987707" alt="image"&gt;&lt;a href="https://%3C%3Cwww.amazon.com/SciPy-Recipes-performing-mathematical-computations/dp/1788291468/ref=as_li_ss_il?keywords=scipy&amp;amp;qid=1537721480&amp;amp;sr=8-6&amp;amp;ref=sr_1_6&amp;amp;linkCode=li2&amp;amp;tag=rootwork0f-20&amp;amp;linkId=0f24d2d9680bc94c36ebe6665e04c5e3&amp;amp;language=en_US&amp;amp;gt%3E;"&gt;&lt;img src="//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;ASIN=1788291468&amp;amp;Format=_SL160_&amp;amp;ID=AsinImage&amp;amp;MarketPlace=US&amp;amp;ServiceVersion=20070822&amp;amp;WS=1&amp;amp;tag=rootwork0f-20&amp;amp;language=en_US" alt="image"&gt;&lt;/a&gt;&lt;img src="https://ir-na.amazon-adsystem.com/e/ir?t=rootwork0f-20&amp;amp;language=en_US&amp;amp;l=li2&amp;amp;o=1&amp;amp;a=1788291468" alt="image"&gt;&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="http://scipy.org" title="SciPy%20home"&gt;Scipy&lt;/a&gt; contains a good least-squares fitting routine, &lt;a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.leastsq.html#scipy-optimize-leastsq"&gt;&lt;strong&gt;leastsq()&lt;/strong&gt;&lt;/a&gt;, which implements a modified Levenberg-Marquardt algorithm.  I just learned that it also has a constrained least-squared routine called &lt;a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.fmin_slsqp.html#scipy.optimize.fmin_slsqp" title="scipy.optimize.fmin_slsqp"&gt;&lt;strong&gt;fmin_slsqp()&lt;/strong&gt;&lt;/a&gt;.   I am using simple upper and lower bound constraints, but it&amp;rsquo;s also possible to specify more complex functional constraints. What I did not realize, at first, is that &lt;strong&gt;fmin_slsqp&lt;/strong&gt;requires a different type of objective function than&lt;strong&gt;leastsq&lt;/strong&gt;.   &lt;strong&gt;leastsq&lt;/strong&gt;requires you to write a function that returns a vector of residuals, and&lt;strong&gt;leastsq&lt;/strong&gt;automatically squares and sums the residuals.&lt;strong&gt;fmin_slsqp&lt;/strong&gt; is actually more flexible, in that it can use any objective function that returns a single scalar value.  To implement least-squares curve fitting, your objective function will need to find the residual at each data point, square the values, and sum them up.  Hopefully this tip will save you some time. Check out the &lt;a href="http://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html" title="scipy%20optimization%20tutorial"&gt;scipy optimization tutorial&lt;/a&gt; for more examples.  Here is the original &lt;a href="http://abs-5.me.washington.edu/dynOpt/p262-kraft.pdf" title="SLSQP%20reference"&gt;paper by Dieter Kraft&lt;/a&gt; which introduces the algorithm used by fmin_slsqp.&lt;/p&gt;</description></item><item><title>Storing large Numpy arrays on disk: Python Pickle vs. HDF5</title><link>https://shocksolution.com/posts/storing-large-numpy-arrays-on-disk-python-pickle-vs-hdf5adsf/</link><pubDate>Sun, 10 Jan 2010 23:00:20 +0000</pubDate><guid>https://shocksolution.com/posts/storing-large-numpy-arrays-on-disk-python-pickle-vs-hdf5adsf/</guid><description>&lt;p&gt;&lt;a href="https://shocksolution.com/2008/09/15/python-pickle-painless-binary-storage-for-python-objects/" title="Python%20data%20storage%20with%20Pickle"&gt;In a previous post, I described how Python&amp;rsquo;s Pickle module is fast and convenient&lt;/a&gt; for storing all sorts of data on disk. More recently, I showed &lt;a href="https://shocksolution.com/2009/04/17/profiling-memory-usage-of-python-code/" title="Profiling%20Python%20code"&gt;how to profile the memory usage of Python code&lt;/a&gt;.  In recent weeks, I&amp;rsquo;ve uncovered a serious limitation in the Pickle module when storing large amounts of data: Pickle requires a large amount of memory to save a data structure to disk. Fortunately, there is an open standard called HDF, which defines a binary file format that is designed to efficiently store large scientific data sets. I will demonstrate both approaches, and profile them to see how much memory is required. I am writing the HDF file using the PyTables interface. Here&amp;rsquo;s the little test program I&amp;rsquo;ve been using: [code language=&amp;ldquo;Python&amp;rdquo;]#!/usr/bin/env python from numpy import array&lt;/p&gt;</description></item><item><title>Building and linking to a shared Fortran library</title><link>https://shocksolution.com/posts/building-and-linking-to-a-shared-fortran-library/</link><pubDate>Mon, 26 Oct 2009 22:34:02 +0000</pubDate><guid>https://shocksolution.com/posts/building-and-linking-to-a-shared-fortran-library/</guid><description>&lt;p&gt;I&amp;rsquo;m using GNU Fortran (&lt;a href="http://gcc.gnu.org/onlinedocs/gfortran/index.html" title="gFortran"&gt;gfortran&lt;/a&gt;) to build several shared libraries, and then dynamically linking to them from a Fortran program.  The process is a little different than what I&amp;rsquo;m used to for C libraries, so I thought I&amp;rsquo;d explain it.  Unlike C, there is no need to #include header files when compiling code that relies on functions defined in an external library.  Likewise, there is no need to use -l or -L linking flags to tell the linker about s hared libraries (at least when they&amp;rsquo;re in the same directory).  In fact, the whole process requires a lot less command-line options than I had expected.&lt;/p&gt;</description></item><item><title>Profiling memory usage of Python code</title><link>https://shocksolution.com/posts/profiling-memory-usage-of-python-code/</link><pubDate>Fri, 17 Apr 2009 22:08:52 +0000</pubDate><guid>https://shocksolution.com/posts/profiling-memory-usage-of-python-code/</guid><description>&lt;p&gt;In a previous post, I explained how to use the Python profiler.  The profile is great for finding out which parts of the code run the slowest, or are called most often.  However, the profiler doesn&amp;rsquo;t give any information about how much RAM is being consumed, or where it&amp;rsquo;s being consumed.  If your program needs so much memory that it starts swapping to disk, its speed can be reduced by orders of magnitude.  On the positive side, your code may run much faster if it fits entirely in the processor cache.  In this post, I will introduce two tools that can help you understand the RAM usage of your Python code.&lt;/p&gt;</description></item><item><title>Lookup tables and spline fitting in Python</title><link>https://shocksolution.com/posts/lookup-tables-and-spline-fitting-in-python/</link><pubDate>Wed, 08 Apr 2009 23:36:09 +0000</pubDate><guid>https://shocksolution.com/posts/lookup-tables-and-spline-fitting-in-python/</guid><description>&lt;p&gt;Lookup tables and spline fitting are widely used by scientific programmers.  A particular function may not have an analytic solution&amp;ndash;in other words, it can&amp;rsquo;t be expressed as an equation of elementary functions.  This might happen if the function were empirically determined from experimental data, or if the equation can&amp;rsquo;t be algebraically solved for one variable.  If the analytical function is available, but takes a long time to evaluate, a lookup table or spline approximation can be considerably faster.  In a previous post, I showed how to use the function &lt;a href="https://shocksolution.com/2008/12/11/a-lookup-table-for-fast-python-math/" title="scipy.interpolate.interp1d%20as%20a%20lookup%20table"&gt;interp1d from scipy.interpolate as a lookup table&lt;/a&gt;.  In a later post, I showed that &lt;a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interp1d.html#scipy.interpolate.interp1d" title="interp1d%20docs"&gt;interp1d&lt;/a&gt; is actually rather slow, and &lt;a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.UnivariateSpline.html#scipy.interpolate.UnivariateSpline" title="Scipy.interpolate.UnivariateSpline"&gt;scipy.interpolate.UnivariateSpline&lt;/a&gt; is much faster.  Now, I will show some benchmark results, and explain a potential pitfall when using UnivariateSpline. The two functions I will use for this demonstration are not very complicated.  Each function is a piecewise approximation of a more complex function.  Here is one of the functions.  For small z, the function uses one approximation, and for large z, it uses a far-field approximation.  For intermediate values, a polynomial is used to smoothly match the two solutions. &lt;a href="https://%3Cwww.amazon.com/Elegant-SciPy-Art-Scientific-Python/dp/1491922877/ref=as_li_ss_il?keywords=scipy&amp;amp;qid=1537721480&amp;amp;sr=8-2&amp;amp;ref=sr_1_2&amp;amp;linkCode=li2&amp;amp;tag=rootwork0f-20&amp;amp;linkId=b82af06689ab1a386116469d41f270d6&amp;amp;language=en_US%3E"&gt;&lt;img src="//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;ASIN=1491922877&amp;amp;Format=_SL160_&amp;amp;ID=AsinImage&amp;amp;MarketPlace=US&amp;amp;ServiceVersion=20070822&amp;amp;WS=1&amp;amp;tag=rootwork0f-20&amp;amp;language=en_US" alt="image"&gt;&lt;/a&gt;&lt;img src="https://ir-na.amazon-adsystem.com/e/ir?t=rootwork0f-20&amp;amp;language=en_US&amp;amp;l=li2&amp;amp;o=1&amp;amp;a=1491922877" alt="image"&gt;&lt;a href="https://%3Cwww.amazon.com/Learning-Numerical-Scientific-Computing-Second/dp/1783987707/ref=as_li_ss_il?keywords=scipy&amp;amp;qid=1537721480&amp;amp;sr=8-3&amp;amp;ref=sr_1_3&amp;amp;linkCode=li2&amp;amp;tag=rootwork0f-20&amp;amp;linkId=4f28164dbe2c853ec36f6f35b052e71a&amp;amp;language=en_US%3E"&gt;&lt;img src="//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;ASIN=1783987707&amp;amp;Format=_SL160_&amp;amp;ID=AsinImage&amp;amp;MarketPlace=US&amp;amp;ServiceVersion=20070822&amp;amp;WS=1&amp;amp;tag=rootwork0f-20&amp;amp;language=en_US" alt="image"&gt;&lt;/a&gt;&lt;img src="https://ir-na.amazon-adsystem.com/e/ir?t=rootwork0f-20&amp;amp;language=en_US&amp;amp;l=li2&amp;amp;o=1&amp;amp;a=1783987707" alt="image"&gt;&lt;a href="https://%3Cwww.amazon.com/SciPy-Recipes-performing-mathematical-computations/dp/1788291468/ref=as_li_ss_il?keywords=scipy&amp;amp;qid=1537721480&amp;amp;sr=8-6&amp;amp;ref=sr_1_6&amp;amp;linkCode=li2&amp;amp;tag=rootwork0f-20&amp;amp;linkId=0f24d2d9680bc94c36ebe6665e04c5e3&amp;amp;language=en_US%3E"&gt;&lt;img src="//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;ASIN=1788291468&amp;amp;Format=_SL160_&amp;amp;ID=AsinImage&amp;amp;MarketPlace=US&amp;amp;ServiceVersion=20070822&amp;amp;WS=1&amp;amp;tag=rootwork0f-20&amp;amp;language=en_US" alt="image"&gt;&lt;/a&gt;&lt;img src="https://ir-na.amazon-adsystem.com/e/ir?t=rootwork0f-20&amp;amp;language=en_US&amp;amp;l=li2&amp;amp;o=1&amp;amp;a=1788291468" alt="image"&gt;&lt;/p&gt;</description></item><item><title>3D Plotting Software for Python::Part 1::PyX</title><link>https://shocksolution.com/posts/3d-plotting-software-for-python-pyx/</link><pubDate>Fri, 20 Mar 2009 23:08:55 +0000</pubDate><guid>https://shocksolution.com/posts/3d-plotting-software-for-python-pyx/</guid><description>&lt;p&gt;There are lots of good open-source tools that you can use to make high-resolution, publication-quality 2D plots.  Personally, I like to use &lt;a href="http://python.org/" title="Python%20homepage"&gt;Python&lt;/a&gt;, &lt;a href="http://numpy.scipy.org/" title="Numpy%20home%20page"&gt;numpy&lt;/a&gt;, and &lt;a href="http://matplotlib.sourceforge.net/" title="Matplotlib%20home%20page"&gt;matplotlib&lt;/a&gt;.  Unfortunately, it is much harder to find a good tools to make 3D plots.  Older versions of matplotlib had rudimentary 3D support, but this was removed in version 0.98.  In this post, I will review a Python 3D plotting library called &lt;a href="http://pyx.sourceforge.net/" title="PyX%20homepage"&gt;PyX&lt;/a&gt;.&lt;/p&gt;&#10;&lt;h2 id="preparing-the-data"&gt;Preparing the data&lt;/h2&gt;&#10;&lt;p&gt;Figuring out how to store the data to be plotted was actually the hardest part of learning to use PyX.  The data format for 3D plots is not well documented.  PyX requires a list of (x,y,z) lists like this:&lt;/p&gt;</description></item><item><title>Updated Python class for writing Paraview (VTK) (.vtu) files</title><link>https://shocksolution.com/posts/updated-python-class-for-writing-paraview-vtk-vtu-files/</link><pubDate>Fri, 23 Jan 2009 23:28:05 +0000</pubDate><guid>https://shocksolution.com/posts/updated-python-class-for-writing-paraview-vtk-vtu-files/</guid><description>&lt;p&gt;I have released a new version of my &lt;a href="https://shocksolution.com/microfluidics-and-biotechnology/python-vtk-paraview/" title="Python%20class%20for%20generating%20VTK%20.vtu%20files"&gt;Python class that generates VTK data files in the .vtu format&lt;/a&gt;, which is compatible with Paraview and other VTK applications.  If you have downloaded the old one, please get the latest version, which incorporates some bug fixes and has been more thoroughly tested.&lt;/p&gt;</description></item><item><title>Scipy.integrate ODEPACK import error solved!</title><link>https://shocksolution.com/posts/scipyintegrate-odepack-import-error-solved/</link><pubDate>Wed, 14 Jan 2009 16:46:16 +0000</pubDate><guid>https://shocksolution.com/posts/scipyintegrate-odepack-import-error-solved/</guid><description>&lt;p&gt;I recently found a solution to a problem that had been vexing me for about a year. In order to successfully import anything from scipy.integrate, I had edit the file scipy/integrate/__init__.py and comment out the line&lt;/p&gt;&#10;&lt;div class="code-block"&gt;&#10; &lt;button class="code-copy" type="button" hidden aria-label="Copy code to clipboard"&gt;&#10; &lt;span class="code-copy-label" aria-hidden="true"&gt;Copy&lt;/span&gt;&#10; &lt;/button&gt;&#10; &lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;from odepack import *&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#10; &lt;/div&gt;&lt;p&gt;If not, I would get various import errors such as&lt;/p&gt;&#10;&lt;div class="code-block"&gt;&#10; &lt;button class="code-copy" type="button" hidden aria-label="Copy code to clipboard"&gt;&#10; &lt;span class="code-copy-label" aria-hidden="true"&gt;Copy&lt;/span&gt;&#10; &lt;/button&gt;&#10; &lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Traceback (most recent call last):&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; File &amp;#34;&amp;lt;stdin&amp;gt;&amp;#34;, line 1, in &amp;lt;module&amp;gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; File &amp;#34;/usr/lib/python2.5/site-packages/scipy/integrate/__init__.py&amp;#34;, line 10,&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;in &amp;lt;module&amp;gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; from odepack import *&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; File &amp;#34;/usr/lib/python2.5/site-packages/scipy/integrate/odepack.py&amp;#34;, line 7,&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;in &amp;lt;module&amp;gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; import _odepack&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ImportError: /usr/lib/python2.5/site-packages/scipy/integrate/_odepack.so:&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;undefined symbol: daxpy_&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#10; &lt;/div&gt;&lt;p&gt;I found the solution in &lt;a href="http://bugs.gentoo.org/show_bug.cgi?id=251165" title="Gentoo%20bug%20251165"&gt;Gentoo bug 251165&lt;/a&gt;. The problem only occurs when Scipy is built with non-reference versions of BLAS and CBLAS. The solution is to install the reference implementation of BLAS and CBLAS, rebuild Scipy, and then use whichever implementation of BLAS or CBLAS you want. I don&amp;rsquo;t know why this happens, and I don&amp;rsquo;t know if it affects distributions other than Gentoo. By the way, Gentoo has a really useful system tool called &lt;a href="http://%3C%3Cwww.gentoo.org/proj/en/eselect/index.xml&amp;amp;gt%3E;" title="Eselect%20home%20page"&gt;eselect&lt;/a&gt;, which has various modules that are used to choose between different versions or implementations of tools on your system (BLAS, Java virtual machine, kernel sources, OpenGL, etc.)&lt;/p&gt;</description></item><item><title>Optimizing Python code for fast math</title><link>https://shocksolution.com/posts/optimizing-python-code-for-fast-math/</link><pubDate>Fri, 09 Jan 2009 21:14:38 +0000</pubDate><guid>https://shocksolution.com/posts/optimizing-python-code-for-fast-math/</guid><description>&lt;p&gt;I spent some time today profiling a Brownian dynamics simulation written in Python to see how I could make it faster before starting some long runs on a Linux cluster. In the sections below, I have attempted to quantify the speed improvements due to various changes. Keep in mind that the actual speed improvement in your code will vary, depending on where the actual bottlenecks occur. See my post about &lt;a href="https://shocksolution.com/2008/10/24/profiling-python-code/" title="Profiling%20Python%20code"&gt;profiling Python code&lt;/a&gt;. Another caveat: I am running Python 2.4.4 because it&amp;rsquo;s installed on our cluster.&lt;/p&gt;</description></item><item><title>A lookup table for fast Python math</title><link>https://shocksolution.com/posts/a-lookup-table-for-fast-python-math/</link><pubDate>Thu, 11 Dec 2008 23:17:06 +0000</pubDate><guid>https://shocksolution.com/posts/a-lookup-table-for-fast-python-math/</guid><description>&lt;p&gt;Numerical programming frequently requires the use of look-up tables. A look-up table is a collection of pre-computed values. When given an &amp;ldquo;x&amp;rdquo; value, the table returns a pre-computed &amp;ldquo;y&amp;rdquo; value. Look-up tables can be used to speed up numerical codes, when it is faster to look up a value in the table than it is to compute the value. They are also used when the data in the table cannot be computed&amp;ndash;for example, experimental data or averaged results from an ensemble of Monte Carlo simulations. Another application is to compute a value when a function cannot be solved algebraically. Assume that you have a formula for a function q(h). You need the value of h for a given value of q, but the formula cannot be algebraically solved to get h(q). Instead, choose a range of h values, compute the function q(h), and store each value in a look-up table. Now you can get h(q) for any value stored in the table. The major limitation of a look-up table is that it cannot return valid results for any value of q which is outside the range of those stored in the table. Depending on its implementation, the table may be able to interpolate to return values between known points.&lt;/p&gt;</description></item><item><title>Update 2: building 64-bit Numpy with Intel compilers and MKL</title><link>https://shocksolution.com/posts/update-2-building-64-bit-numpy-with-intel-compilers-and-mkl/</link><pubDate>Tue, 09 Dec 2008 19:33:12 +0000</pubDate><guid>https://shocksolution.com/posts/update-2-building-64-bit-numpy-with-intel-compilers-and-mkl/</guid><description>&lt;p&gt;NOTE: these instructions are obsolete.  Please see &lt;a href="../../2012/04/building-numpy-on-a-red-hat-cluster-with-intel-mkl/" title="Permanent Link: Building NumPy on a 64-bit Red Hat Cluster with Intel MKL"&gt;Building NumPy on a 64-bit Red Hat Cluster with Intel MKL&lt;/a&gt;. In a previous post I described &lt;a href="https://shocksolution.com/2008/10/17/updated-building-64-bit-numpy-with-intel-compilers-icc/" title="Previous%20update"&gt;how I built Numpy with Intel compilers and the Math Kernel Library on a 64-bit cluster&lt;/a&gt;. Today I upgraded to Numpy-1.2.1 and I made a few improvements to my install process. Please read the previous post, since I will not duplicate some important information, and then read on. This time, I made use of a site.cfg file. Copy the file &lt;strong&gt;site.cfg.example&lt;/strong&gt;to&lt;strong&gt;site.cfg&lt;/strong&gt; and edit. At the end of the file, uncomment the [mkl] section and set the path to your library. Mine looks like:&lt;/p&gt;</description></item><item><title>Even faster collision detection in Python using Numpy</title><link>https://shocksolution.com/posts/even-faster-collision-detection-in-python-using-numpy/</link><pubDate>Thu, 16 Oct 2008 19:44:15 +0000</pubDate><guid>https://shocksolution.com/posts/even-faster-collision-detection-in-python-using-numpy/</guid><description>&lt;p&gt;Last night, in the shower, I realized that my collision detection routine could be even faster. Here is a representative snippet of code from my previous post:&lt;/p&gt;&#10;&lt;div class="code-block"&gt;&#10; &lt;button class="code-copy" type="button" hidden aria-label="Copy code to clipboard"&gt;&#10; &lt;span class="code-copy-label" aria-hidden="true"&gt;Copy&lt;/span&gt;&#10; &lt;/button&gt;&#10; &lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; d2 = (x-self.x[0:i])*(x-self.x[0:i]) + (y-self.y[0:i])*(y-self.y[0:i]) + (z-self.z[0:i])*(z-self.z[0:i])&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#10; &lt;/div&gt;&lt;p&gt;For some reason, I used the code (x-self.x)*(x-self.x) instead of (x-self.x)**2. Upon further reflection, I realized that (x-self.x)*(x-self.x) computes the difference between array elements twice, and then multiplies the results. Using a &amp;ldquo;power function&amp;rdquo; should enable the interpreter to compute the difference only once, and then multiply each element times itself. Here is the updated code, using Python&amp;rsquo;s power operator:&lt;/p&gt;</description></item><item><title>Installing numpy with the Intel Math Kernel Library (mkl)</title><link>https://shocksolution.com/posts/installing-numpy-with-the-intel-math-kernel-library-mkl/</link><pubDate>Fri, 19 Sep 2008 21:24:58 +0000</pubDate><guid>https://shocksolution.com/posts/installing-numpy-with-the-intel-math-kernel-library-mkl/</guid><description>&lt;p&gt;Today I installed numpy on a cluster. Normally, as a Gentoo admin, I just install things with emerge, and all the details are taken care of automagically. However, this cluster runs Red Hat Enterprise, and I don&amp;rsquo;t have admin privileges, so I had to install numpy in my home directory. I installed 1.0.4, to match the version used on another system. You may not need to do this for more recent versions of numpy, which may have an improved setup script. The overall process is:&lt;/p&gt;</description></item><item><title>Reading Labview binary files with Python</title><link>https://shocksolution.com/posts/reading-labview-binary-files-with-python/</link><pubDate>Wed, 25 Jun 2008 16:04:46 +0000</pubDate><guid>https://shocksolution.com/posts/reading-labview-binary-files-with-python/</guid><description>&lt;p&gt;My research group uses Labview 7.1 to write custom data acquisition (DAQ) software. I code everything else in Python, so I need to get data from Labview into Python for processing. Our DAQ program produces Labview binary files, so I had to find a way to read them with Python. Binary files are nice because they are a compact way to store numerical data as compared to ASCI or (heaven forbid) XML, but they are much harder to read. The binary format used by Labview is documented only indirectly, so I had to hack a little. The first thing to realize is that the Labview binary file is a direct dump of the data that was stored in RAM. &lt;a href="http://zone.ni.com/reference/en-XX/help/371361A-01/lvconcepts/how_labview_stores_data_in_memory/" title="How%20Labview%20stores%20data%20in%20RAM"&gt;How Labview stores data in memory is documented here.&lt;/a&gt; Indirectly, this documents how binary files are stored on disk. Our DAQ program writes a rather complex &amp;ldquo;cluster&amp;rdquo; (Labview&amp;rsquo;s version of a C structure) to disk. The elements of the cluster are stored contiguously as a sequence of bytes, and there&amp;rsquo;s no way to know which byte goes with which element, unless you know the size of each element and the order in which they are stored in the cluster. So, the first step is to document the cluster that&amp;rsquo;s being written to disk. You can use the context help in Labview to view the data type of the wire that leads to the VI that writes the file. With this in hand, you are ready to write Python code. First, make sure you open the file in binary mode:&lt;/p&gt;</description></item></channel></rss>