Posts Tagged ‘software’

Random Gaussian distribution in libGSL

March 17, 2011

I think the gsl_ran_gaussian function is broken in the GNU Scientific Library.

This function is supposed to return a random value from the Gaussian distribution with a mean = 0.0 and a user-specified standard deviation.  However, consider the C code (below), in which the user-specified standard deviation value seems to have no effect on the random value.


#include "gsl/gsl_rng.h"
int main( int argc, const char* argv[] )
printf( "\nHello World\n\n" );
gsl_rng *rng;
int random_seed = (int)time(NULL);
rng = gsl_rng_alloc(gsl_rng_mt19937);
gsl_rng_set(rng, random_seed);

double rand_gauss;

int reps = 5;
int i = 0;
for (i = 0; i < reps; i++)
rand_gauss = gsl_ran_gaussian(rng, 0.001);
printf("sigma = 0.001, random value = %f\n", rand_gauss);
rand_gauss = gsl_ran_gaussian(rng, 0.01);
printf("sigma = 0.01, random value = %f\n", rand_gauss);
rand_gauss = gsl_ran_gaussian(rng, 0.1);
printf("sigma = 0.1, random value = %f\n", rand_gauss);
rand_gauss = gsl_ran_gaussian(rng, 1.0);
printf("sigma = 1.0, random value = %f\n", rand_gauss);


Hello World

sigma = 0.001, random value = 6304.000000
sigma = 0.01, random value = 3104.000000
sigma = 0.1, random value = 1952.000000
sigma = 1.0, random value = 1536.000000
sigma = 0.001, random value = 3712.000000
sigma = 0.01, random value = 1312.000000
sigma = 0.1, random value = 3424.000000
sigma = 1.0, random value = 6752.000000
sigma = 0.001, random value = 6016.000000
sigma = 0.01, random value = 8000.000000
sigma = 0.1, random value = 6752.000000
sigma = 1.0, random value = 7200.000000
sigma = 0.001, random value = 5408.000000
sigma = 0.01, random value = 7136.000000
sigma = 0.1, random value = 1056.000000
sigma = 1.0, random value = 4160.000000
sigma = 0.001, random value = 7744.000000
sigma = 0.01, random value = 5376.000000
sigma = 0.1, random value = 3072.000000
sigma = 1.0, random value = 4896.000000



Python enforces recursion limitations.

November 15, 2010

Python has limits on recursion depth.  This is a nice language feature because it prevents infinite loops from exploding your runtime, but it can be problematic when dealing with deep data structures and/or graph traversal.

If you see this error. . .

RuntimeError: maximum recursion depth exceeded

. . . don’t freak out.  Instead, try increasing the recursion limit.  First, find the current limit:

>>> import sys

>>> sys.getrecursionlimit()


. . . and then increase the limit:

>>> sys.setrecursionlimit(10000)

In my case, I changed the limit from 1000 to 10000, but obviously the appropriate numbers might be different for your problem.

How-to Configure NFS on OS X 10.6 Server

February 7, 2010

Here are instructions for configuring remotely mounted folders using network file system (NFS) on Apple OSX 10.6 Server. . .

Our lab recently purchased a computational cluster, consisting of eight Apple XServes.  We have one “head” node with RAID storage, and seven “auxiliary” nodes that automount folders on the head node.  The head node is visible to the entire world, but the auxiliary nodes live on a private subnet.  Although most Apple documentation suggests using AFP to share folders across the subnet, I found AFP to be inappropriate for our setup.  To wit, AFP does not allow users simultaneously logged into the same client machine to mount the same folder.  For example, suppose Alice signs into the headnode and then signs into auxiliary node #2 and runs a script.  As a consequence of these actions, Alice automatically mounted the folder /Users and the subfolder /Users/Alice.  If another user, Bob, performs these same steps, he won’t be able to mount his home folder from node #2 until Alice signs-off!  The cause of this problem is that AFP gives Alice an exclusive lock on /Users.  Long story short: AFP seems inappropriate for high-performance computing scenarios.

As an alternative to AFP, I setup remote folder mounting using NFS.

Here are instructions for configuring NFS. . .

1. Configure Domain Name System (DNS) service.  Here are some good instructions from

2. Configure Open Directory service.  Here are more instructions from

3. Define the folders to be exported.  Although you can manually create these definitions by editing the file named /etc/exports, I recommend you instead use the OSX GUI tools in the Server Admin application.  My rationale is that /etc/exports is fragile because Server Admin will freely overwrite the contents of this file.  Do the following:

3a. Enable NFS.  In Server Admin, select the server, then click the icon for settings, then click the menu bar for services.  Ensure the checkbox next to NFS is enabled.

3b. Select your desired sharepoints.  In Server Admin, click on the NFS service.  Select the icon for sharepoints.  Browse to the folders you want to share, and click the share button in the upper-right corner.  In this example, I show how to share the Users folder.

4. Start NFS by clicking on the Start NFS button at the bottom of the Server Admin application.  If NFS is already running, then you will instead see a button for Stop NFS; in this case, don’t stop NFS.

5. Enable your shared folders to be automounted. For each sharepoint, select the sharepoint and then select the Share Point menu bar.  Ensure the checkbox for Enable Automount is checked.   You should see something like this:

6. Click on the Edit… button next to Enable Automount.  Ensure that the sharepoint is being exported using the NFS protocol.  If the sharepoint is intended to be the home directory for users, then ensure the option “Use for user home folders and group folders” is enabled.  You should see something like this:

Click OK when you are done.

7. Back in the Share Points menu, click on the button for Protocol Options…; you should see something like this:

7a. Ensure the sharepoint is not being shared via AFP, and is being shared via NFS.  In the NFS menu, you might use options like what I show below:

Here I’m sharing the Users folder to the subnet with address with mask  This means that addresses with the pattern 10.0.0.? (where ? can be anything) have access to the folder.

8. Finally, let’s test the NFS setup.  Open Terminal and type the following:

> sudo nfsd update

. . . in order to restart NFS.  You also could restart your computer, but it seems easier to use nfsd.

> sudo nfsd checkexports

Enter the password for root access.  If NFS is correctly configured, you should see no output from nfsd.

> showmount -e

. . . should list all your NFS exported sharepoint.  For example, on our server. . .

markov:~ admin$ showmount -e
Exports list on localhost:
/private/var/xgrid/sfs              Everyone

OK.  Good luck!