Installing NEURON, MPI, and Python on OS X Lion

I’ve recently run into the problem of trying to compile the source for NEURON 7.3a that includes support for parallel NEURON (using MPI) and Python on Mac OS X Lion. Using a number of helpful web resources, I wanted to cobble together an “as-of-this-writing” practice to get a kitchen sink working install for all components.

UPDATED 01-Sept-2012: Added instructions for mpi4py

Because I don’t have the resources to test many version combinations, etc., this assumes OS X 10.7.4 on a Retina MacBook Pro 10,1 (Mid 2012), with a working copy of XCode 4.4.1 installed (available for free from the Mac App Store). I suspect but cannot verify that this will work with many different versions of all of these components. Note: MacPorts is particularly sensitive to very new XCode and OS releases, so right after a new one, things don’t always work right away.

Finally this assumes you have admin access to the computer on which you are installing things and that you will use sudo for good and not evil.

And super-finally, this is basically an aggregate of web sources, some of which I had to modify to get it working. Sources are inline, below. Much is duplicated here because of the transience of web links.

0. Install XCode.
1. Install MacPorts
2. This step will take awhile!1 Open a terminal and type at your prompt ($):

$ sudo port install python27
$ sudo port install py27-numpy
$ sudo port install py27-scipy
$ sudo port select python python27

Running:

$ which python

should result in: ‘/opt/local/bin/python’.

3. Now install the message passing interface (MPI) components. On Mountain Lion (10.8.x), I’ve only gotten OpenMPI working, and only from source (and not MacPorts). But on Lion, I’ve gotten MPICH2 working from MacPorts to play nicely with Neuron (sudo port install mpich2). However here are instructions for how to install MPICH2 from source, with these minimal steps:

a. Download MPICH2 from this website. Look for an http link. Do not worry about Hydra unless you know why (and don’t forget to tell me).
b. In the terminal, follow these commands2,3,4:

$ cd ~/Downloads
$ tar xvzf mpich2-X.x.tar.gz
$ cd mpich2-X.x
$ ./configure
$ make
$ sudo make install

It installs in /usr/local/bin, which you can verify by running: “which mpicc”. (MacPorts version installs in /opt/local/bin by default.)

4. Install NEURON from source with support for MPI and Python:

4a. Download the latest NEURON. Get both InterViews (IV) and NEURON (nrn) and issue the following commands in a terminal window3,5:

$ mkdir ~/Downloads/neuron
$ mv ~/Downloads/iv-XX.tar.gz ~/Downloads/neuron/
$ mv ~/Downloads/nrn-X.X.tar.gz ~/Downloads/neuron/
$ cd ~/Downloads/neuron
$ tar xvzf iv-XX.tar.gz
$ tar xvzf nrn-X.X.tar.gz

4b. Compile and install InterViews:

$ IDIR=/Applications/NEURON-X.X
$ cd iv-XX/
$ ./configure --prefix=$IDIR/iv
$ make
$ sudo make install

4c. Compile and install NEURON with python and MPI support:

$ IDIR=/Applications/NEURON-X.X
$ cd ~/Downloads/neuron/
$ tar xvzf nrn-X.X.tar.gz
$ cd nrn-X.X/
$ ./configure --prefix=$IDIR/nrn --with-iv=$IDIR/iv --with-nrnpython=/opt/local/bin/python --with-paranrn
$ make
$ sudo make install
$ sudo make after_install

5. Add the new NEURON directory to your PATH variable. If you are using the bash shell (often default), edit the file ~/.bashrc by adding or modifying a line that looks like:

export PATH=$PATH:/Applications/NEURON-X.X/nrn/ARCH/bin

where ARCH is most often one of i386, i686, or x86_64 and can be found in the terminal by going to /Applications/NEURON-X.X and looking for one of these.

6. You need to build in support to run NEURON as a module:

$ cd ~/Downloads/neuron/nrn-X.X/src/nrnpython/
$ sudo python setup.py install

This can be tested:

$ python
>>> from neuron import h

That last statement should not complain at you. Instructions on how to start NEURON with python and vice versa are found on this website.

7. Now, let’s install mpi4py, which is necessary for letting Python handle MPI. I could not get the MacPorts py27-mpi4py package working, but it works from source. It’s important that the right python is run on this command and that it knows where mpicc lives.

a. Download the mpi4py source from here.

b. Now unzip and compile here:

$ tar xvzf mpi4py-x.x
$ cd mpi4py-x.x
$ python setup.py build --mpicc=/usr/local/bin/mpicc
$ sudo python setup.py install

Per the installation instructions in mpi4py, this can all be tested:

$ cd demo
$ mpiexec -n 5 python helloworld.py

This should also have reasonable output. Please leave comments if certain aspects worked or did not work or if anything here needs clarification!

1 I am not sure if numpy and scipy are required for NEURON, but they may be useful to you, and I’ve found MacPorts to be the most straightforward, clean installation of it.
2 Assumes that the file downloaded to your ~/Downloads/ folder (often defaults here)
3 Please, replace the X’s with the version number that you downloaded, such as ‘1.6’ or ‘1.4.3’
4 You may need to issue the command 'sudo make all' instead of 'make all'
5 The trailing ‘/’ may be important. For safety sake, just include it.
Advertisements

4 thoughts on “Installing NEURON, MPI, and Python on OS X Lion

  1. tzvet

    nice help. thx ! Just one point about the mpich2 package. It can be also installed through the macports.

  2. sc Post author

    Hi tzvet, so did you try to use the MacPorts-installed mpich2 and confirm that neuron likes it okay? MH had told me that for some reason direct from source was the way to go. My initial MacPorts attempts (awhile ago, on OS X 10.7.4) did not work, so I stopped trying in favor of his recommendation. But I’d love for the MacPorts mpich2 to work. Thanks for the suggestion.

  3. Pingback: Compiling NEURON-7.4 from source code with MPI and Python on OSX | Discussion on Computational Neuroscience, and General Lifestyle Ideas.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s