Creating your own ‘modules’ environment

When you’re working with high performance computing cluster which has several compilers, parallel libraries, etc and has modules package for managing user environment it’s handy to make your own environment with all paths you need using this package.

If you’ll try to create simple shell script like:

#!/bin/bash

module unload openmpi-gcc/1.3.2
module load openmpi-sun/1.3.2

It won’t work. It’ll just show you an error like this:

./sun_env_bad.sh: line 3: module: command not found
./sun_env_bad.sh: line 4: module: command not found

The reason why script is complaining hides in children shells environment inheritance. When you start any script from inside your console it inherits all environment variables from it’s parent. But it doesn’t inherit aliases and functions they are not part of the environment. As you no doubt have already guessed modules is a shell function. You see it in your login shell ’cause when you log in to the system it runs /etc/profile which in turn runs /etc/profile.d/*.sh scripts. modules function is in /etc/profile.d/modules.sh.

So you can resolve this problem by sourcing either /etc/profile or /usr/local/Modules/3.2.6/init/bash in the first line of your environment configuration script.

Advertisements

Tags:

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


%d bloggers like this: