computational science and engineering

Installing PETSc and libMesh on CentOS 5

January 20th, 2012 Posted in Linux, Scientific computing | No Comments »

Prerequisites: boost-devel, openmpi-devel, valgrind-devel

I installed PETSc and libMesh in my user directory, since I have a single-user workstation.

Installing PETSc for use with libMesh

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 not do this automatically!  Type mpicc on the command line to make sure the shell can find the binary.  If mpicc and mpif77 run, then you should not need to use the comnand-line flags to the configure script for PETSc.

Read the rest of this entry »

Paraview 3.12 on 64-bit CentOS 5.7

January 19th, 2012 Posted in Linux, Scientific computing | No Comments »

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 download the Paraview binary 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 paraview 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 “on the fly” based upon the files in a standard directory (/usr/share/applications on CentOS).  The Free Desktop Project has created a standard for desktop entry files.  You may also find this summary of the standard 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:

[Desktop Entry]
Type=Application
Name=Paraview
Categories=Graphics;3DGraphics;Science;Engineering
Comment=3D visualization tool
Exec=paraview
Icon=paraview.svg

I found Paraview menu icons here.  Save the SVG icon to /usr/share/icons (there may be an equivalent location in your user directory but I don’t know what it is).  Now, when you bring up the Applications menu in your desktop environment the entry should appear (no need to restart or anything).

Screenshot of Paraview

Installing Sage 4.7 on CentOS 5

November 7th, 2011 Posted in Linux, Sage, Scientific computing | No Comments »

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 Sage, and the process went smoothly.

If you find this post helpful, please check out the Sage Beginner’s Guide at Packt Publishing.  Since I don’t use Sage every day, I actually refer to my own book on a regular basis!

Download

Since CentOS is designed to be binary compatible with Red Hat Enterprise Linux, the correct binary to download is
sage-4.7.2-linux-64bit-red_hat_enterprise_linux_server_release_5.6_tikanga-x86_64-Linux.tar.gz

Install

Uncompress the file with tar xfz <filename>  The result is a huge directory (3.1Gb) with a self-contained version of Sage that can be run right where you uncompressed it.  As root, I moved the directory to /opt, changed ownership to root, and changed the name to sage-4.7.2.  I then edited the script /opt/sage-4.7.2/sage so that the variable SAGE_ROOT contains the correct path:

SAGE_ROOT="/opt/sage-4.7.2"

Run sage once as root to set the paths correctly.

Read the rest of this entry »

Python string format examples

November 3rd, 2011 Posted in Python, Scientific computing, Software development | No Comments »

The format method for Python strings (introduced in 2.6) is very flexible and powerful.  It’s also easy to use, but the documentation is not very clear.  It all makes sense with a few examples.  I’ll start with one and add more as I have time:

Formatting a floating-point number

"{0:.4f}".format(0.1234567890)

The result is the following string:

'0.1235'

Explanation

Braces { } are used to enclose the “replacement field”
0 indicates the first argument to method format
: indicates the start of the format specifier
.4 indicates four decimal places
f indicates a floating-point number

Scientific Notation

"{0:.4e}".format(0.1234567890)

Output:

'1.2346e-01'

Multiple Arguments

In Python 2.6 you can include multiple arguments like this:

"sin({0:.4f}) = {1:.4e}".format(0.1234567890, sin(0.123456789))
'sin(0.1235) = 1.2314e-01'

In Python 2.7 and later, you may omit the first integer from each replacement field, and the arguments to format will be taken in order:

"sin({:.4f}) = {:.4e}".format(0.1234567890, sin(0.123456789))
'sin(0.1235) = 1.2314e-01'

Linux kernel 3.1 config for Gentoo guest on VMWare Fusion

October 24th, 2011 Posted in Linux, Mac | No Comments »

The following kernel configuration was posted by Alessandro Di Marco as a comment on a previous post in which I provided a Linux kernel config for an earlier version of the kernel. In the interest of sharing his contribution, I’m placing it in its own post. I don’t know the author personally and I have not tried this config.  Like any other free software, you are using it at your own risk and neither Alessandro nor I provide any warranty. Download the file from the link below, change the file extension from .txt. to .config and load the config into one of the standard kernel configuration tools (such as make menuconfig) and look over all the options before using it.

Gentoo Kernel 3.1 Config

TeXLive and Asymptote on CentOS 5

October 3rd, 2011 Posted in Uncategorized | No Comments »

Tex Live

For reasons unknown, a TeX Live package is not available for Red Hat Enterprise Linux/Centos 5 from the major repositories (EPEL or DAG).  I consider this to be a glaring omission, since TeXLive is a great improvement upon teTeX.  Since I don’t have time right now to package it myself, I installed TeX Live manually in my user directory and it’s working fine.  I used the network install process, which starts with downloading a command-line installer and then following the detailed installation instructions with the base path set to $HOME/texlive/2011.

Asymptote

The binary version of Asymptote installed with TeX Live didn’t run on my system, so I installed the Asymptote vector graphics language manually.  As root, I used yum to install the gc and gc-devel packages to provide the Boehm garbage collector that Asymptote uses.  I also had to install the package texinfo-tex from the CentOS base repo to provide the texindex utility that Asymptote uses to build its documentation.  Once the dependencies were in place, I downloaded the Asymptote source archive and unpacked it.  I used the following commands to build Asymptote in my user directory:

./configure --prefix=$HOME/asymptote
make
make install

Finally, I set up up the path environment variable in my .bashrc so that the copy of Asymptote I just built will run instead of the binary that comes with TeX Live and my locally installed TeX Live will run instead of the system installation of teTeX:

export PATH=~/asymptote/bin:~/texlive/2011/bin/x86_64-linux:$PATH

If you are doing this from scratch, you should check whether there is a away to prevent the TeX Live installer from installing Asymptote.

Technically, I could remove the system installation of teTeX at this point, but the LyX package depends on teTeX and I’ll have to see if there’s a way to tell yum to keep LyX and get rid of teTeX.

How to install Octave video tools on CentOS 5

September 14th, 2011 Posted in Uncategorized | No Comments »

This post describes how to get GNU Octave up and running on a CentOS 5 Linux system for use in reading, processing, and writing video files.  You will need to use the EPEL and DAG/rpmforge repositories, but I won’t explain how to do that here.

NOTE: I had to go through some trial and error to get this working.  I tried to summarize only the necessary steps, but I can’t guarantee I got it completely right until I try a fresh install on another system which does not have any of the dependencies already installed.  Please leave a comment if you encounter any problems.

As a superuser, use yum to install octave.  You need octave-devel and ncurses-devel in order to install any Octave packages.  You will need to have the EPEL repository enabled:

yum install octave octave-devel ncurses-devel

As a superuser, use yum to install ffmpeg and ffmpeg-devel from the rpmforge repo.  The video package for octave uses the ffmpeg libraries (avilib) to perform the actual video processing.  You will need the ffmpeg-devel package, because Octave builds the video package from source.

  1. Since ffmpeg and ffmpeg-devel are only available from DAG/rpmforge, I suggest disabling EPEL before installing these packages.  This will ensure that all the dependencies are installed from rpmforge, instead of mixing packages from EPEL and rpmforge.  Mixing dependencies from different repositories might lead to incompatibilities and bugs that can be hard to trace.
  2. yum install ffmpeg ffmpeg-devel

Install the video package for Octave.  I prefer to do this as an ordinary user (not root) so that the packages will be installed in my home directory (I have a “rule” that only the package manager is allowed to put files into system locations).  You will need to set the CXX flags environment variable to work around a bug in the C++ headers for the ffmpeg libraries.  If you are going to build other packages that link to ffmpeg’s libraries, you should probably set CXXFLAGS in your .bashrc.  I think this bug was fixed in later versions of ffmpeg, but they haven’t made it into EPEL or rpmforge yet.

  1. Download video package
  2. Unpack the archive: tar xfz video-1.0.2.tar.gz
  3. Change to the unpacked directory: cd video-1.0.2
  4. Temporarily set C++ flags and configure: CXXFLAGS=-D__STDC_CONSTANT_MACROS ./configure
  5. Temporarily set C++ flags and build: CXXFLAGS=-D__STDC_CONSTANT_MACROS make
  6. Install: make install

If you don’t set the C++ flags this way, you will get an error like this:

/usr/include/libavutil/common.h: In function ‘int32_t av_clipl_int32(int64_t)’:
/usr/include/libavutil/common.h:154: error: ‘UINT64_C’ was not declared in this scope

How to build ScipPy with Python 2.7.2 on CentOS5

August 25th, 2011 Posted in Linux, Python, Scientific computing | 1 Comment »

EDIT: added –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 –prefix=/home/yourusername instead of –user.  The prefix option places packages in the standard location: /home/yourusername/lib/python2.7/site-packages.  The –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 “bleeding edge” packages, such as the latest version of SciPy, but I don’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:

Read the rest of this entry »

Parsing INI configuration files with FORTRAN

August 23rd, 2011 Posted in Fortran, Software development | 2 Comments »

Fortran would not be my first choice for working with text, in any form! However, sometimes even numerical codes need to read data from configuration files. The easiest way to read a configuration file from a Fortran 90 routine is by using namelist I/O (I really need to add an example of that). If you’re stuck with INI files, I found an INI file parser written in Fortran buried in an index of free Fortran routine.  I don’t even remember how I even found it, since it’s not well labeled and doesn’t come up in the first few pages of Google results, so I thought I’d better write a post about it in case I ever need such a thing in the future.

Removing an axis or both axes from a matplotlib plot

August 17th, 2011 Posted in Python, Scientific computing | 1 Comment »

Sometimes, the frame around a matplotlib plot can detract from the information you are trying to convey.  How do you remove the frame, ticks, or axes from a matplotlib plot?

matplotlib plot without a y axis

The full example is available on github.

Read the rest of this entry »