Using the SUNDIALS ODE package on Lion

The SUNDIALS project from Lawrence Livermore National Lab is a package of tools for solving systems of ordinary differential equations (ODEs) and related problems, including MPI parallelization and GMRES-based step methods. I am testing it for use on large food web models, in the hope that it will be faster and more robust than Matlab’s methods (or, certainly, than implementing fancy methods myself). This entry covers the steps I took to get it built and working on Mac OS X Lion.

  1. If you just upgraded to Lion and haven’t done this yet, install Xcode from the Mac App Store.
  2. Install gfortran prebuilt for Lion: http://r.research.att.com/gfortran-4.2.3.dmg
  3. If you haven’t done this already, install and set up MacPorts.
  4. Install OpenMPI via MacPorts with the command sudo port install openmpi. This can take a long time (hours), since it depends on also doing a separate MacPorts install of GCC 4.4. Starting this install is a good way to end the day.
  5. Download SUNDIALS 2.4.0 (the whole package, sundials-2.4.0.tar.gz) from the SUNDIALS download page. Move it to wherever you like and extract it (double-clicking works fine).
  6. Open a terminal window, cd into the SUNDIALS directory, and run the following (I set my CC to gcc for the sake of safety, even though Lion defaults to LLVM):
./configure CC=gcc F77=gfortran \
--prefix=/usr/local/sundials \
--enable-shared \
--with-mpicc=/opt/local/bin/openmpicc \
--with-mpif77=/opt/local/bin/openmpif77
make
sudo make install

That’s it; SUNDIALS should now be installed in /usr/local/sundials. You can use the prefix /usr/local if you like, but this way it’s conveniently kept separated from everything else.

To use it, it’s a matter of making sure that /usr/local/sundials/include is in your header search path, /usr/local/sundials/lib is in your library search path, and you give the linker -l[library name] (that’s a “hyphen lowercase ell”) for any libraries you need. For example, for the SUNDIALS example file cvsFoodWeb_ASAi_kry.c, I needed -lsundials_nvecserial -lsundials_cvodes

In Xcode, you can do this via the following steps:

  • Make a new Application/Command-Line Tool project.
  • Add your source code, e.g., cvsFoodWeb_ASAi_kry.c
  • In the project settings, add /usr/local/sundials/include to Header Search Paths. Oddly, this causes Header Search Paths to remain empty, but a User Header Search Paths field appears with your desired path.
  • Check Always Search User Paths
  • Add your library flags, e.g., -lsundials_nvecserial -lsundials_cvodes, to Other Linker Flags.

If everything has gone according to plan, the code should now build and run successfully.

So far, these steps only work for serial code: when I get an MPI example compiling and running, I’ll post those steps as well.

Posted in howto | Tagged , | 2 Comments

Pause Processing.js

Processing.js is great. But while working on a network visualization sketch (coming soon), I found I sometimes wanted to pause/restart its execution manually. (Note that there is a built-in pauseOnBlur directive that will only run the animation when the window is in front.)

Turns out this is really easy to do. In fact, they even do it on this tutorial page for JavaScript developers. But since Googling “pause processing.js” came up short and the relevant functions didn’t strike me as relevant in the reference docs, here’s what I came up with before I found the documentation:

<p>
  <button id="toggleBtn" onClick="toggle();">Pause</button>
</p>

<script type="text/javascript">
// If you attached weird "Processing language" code
// to a canvas with id "sketch":
var processing = Processing.getInstanceById("sketch");

// If you're doing everything in raw JavaScript like me,
// you probably did something like this:
var processing = new Processing( ... );
// ...

var looping = true;
function toggle()
{
  if(looping)
  {
    processing.noLoop();
    document.getElementById("toggleBtn").textContent = "Play";
  }
  else
  {
    processing.loop();
    document.getElementById("toggleBtn").textContent = "Pause";
  }
  looping = !looping;
}
</script>
Posted in howto | Leave a comment

First steps with Python

First up, I’m trying to resume my habit, lost when I started grad school, of posting various things to this website, mostly experiences getting computer things to work. This is mostly for my own benefit—easy to find command-line instructions—with the side effect that other people can see it if they want to. If I get ambitious, I might start posting science-related things here too.

This post is about my long-overdue first steps with Python, which, like Spanish, I have been on the verge of starting to learn for about six years.

First impression: my god, I should have done this six years ago. At last I have a go-to scripting language. Today I am (by and large) saying goodbye to bash, R, Matlab, and, when performance doesn’t much, Java/C++/Objective-C.

Continue reading

Posted in python | Leave a comment

Open Access: The Sooner the Better

I was just browsing my Science Magazine RSS feed at home, and encountered this hilarious screen when I clicked to read the full article…

How Do I Get Access?

How Do I Get Access?

Posted in Uncategorized | Leave a comment

svn revert equivalent in git

I keep wanting to type

git revert

to roll back changes to the last committed version of something—that’s how you’d do it in Subversion—but this isn’t right. This works instead:

git reset --hard HEAD

Posted in howto, Uncategorized | Leave a comment

Classical Revolution Ann Arbor kickoff on Cinco de Mayo

I’m getting a first Classical Revolution chamber jam going next Tuesday in Ann Arbor! The first event will be at the Kerrytown Concert House, with other, non-concert house venues to come. If you’re interested in coming, come. If you’re interested in playing, let me know via Facebook or email.

Classical Revolution Ann Arbor
Tuesday, May 5
8 PM
Kerrytown Concert House, 415 N Fourth Ave

Posted in Announcements, Music | Tagged , , | 3 Comments

XgridLite for Leopard

The other day I released XgridLite for Leopard, something which should have happened about a year and a half ago. There are no substantial changes whatsoever, except that version 1.1 works on Leopard. However, it breaks Tiger support, so if you haven’t upgraded yet—I suspect a small minority of the kind of people that use XgridLite—you should still use version 1.0.2.

Posted in Announcements, Software | Tagged | 5 Comments

XgridLite: Dual Tiger/Leopard Functionality?

After confirmation that things seem to work for others on Leopard, I went through and tried to make sure it would work on Tiger again too. I don’t have time to set up a Tiger test box right now, so I’d appreciate it someone who has a Tiger box would test this updated version:

XgridLite.prefPane.zip

Post your success/lack thereof in the comments!

Posted in xgridlite | 1 Comment

XgridLite on Leopard, Test Version

After debugging some weirdness, I have a version of XgridLite that works on Leopard, I think. Brave testers, download this file:

XgridLite.prefPane.zip

Then decompress and drag the prefPane into your /Library/PreferencePanes or ~/Library/PreferencePanes

Let me know how it goes!

FYI, the weirdness I ran into goes something like this (as described in a message I just sent to the xgrid-users mailing list):

Hi everyone (particularly Apple folks),

After being out of the loop for a while, I finally got around to getting XgridLite working on Leopard. (Test version about to be posted at code.edbaskerville.com, official release probably by Monday.)

In doing so, I ran into one weirdness that I thought someone might be able to explain. XgridLite simply calls xgridctl to get and set controller state, which seems simple enough. In Tiger, it was sufficient to do this as root using a setuid tool.

In Leopard, however, I found that status calls always returned that the controller was off:

daemon              state               pid
======              =====               ===
xgridcontrollerd    stopped

This was happening inside the setuid tool even when querying it via sudo as a regular user worked fine:

Agnos:~ ebaskerv$ sudo xgridctl c status
daemon              state               pid
======              =====               ===
xgridcontrollerd    running             12656

To get to the bottom of this, I activated the root user on my system and tried it from a root shell, and, sure enough, I’m being told the controller is stopped:

sh-3.2# xgridctl c status
daemon              state               pid
======              =====               ===
xgridcontrollerd    stopped

Miraculously, though, if you run xgridctl via sudo as root, all is fine:

sh-3.2# sudo xgridctl c status
daemon              state               pid
======              =====               ===
xgridcontrollerd    running             12656

This gave me the workaround I needed: run xgridctl via sudo as root inside XgridLite. But I still have no idea *why* this is happening, so I’m writing purely out of curiosity. Why is it that running xgridctl status via sudo gives the correct status, while running as root directly does not? One more wrinkle: running xgridctl c start/stop seem to work fine inside my setuid tool (WITHOUT running via sudo), but do NOT work via a root shell!

Any wisdom would be appreciated.

Thanks,
Ed

Posted in xgridlite | Leave a comment

Two Million

Posted in Uncategorized | Tagged , | Leave a comment