Search code examples
tclopenfoamenvironment-moduleslmod

LMOD TCL execute bash script while loading module


On our new cluster we use LMod as environmental module system.

Creating a Module TCL Script for OpenFOAM, a system-dependent bashrc file need to be loaded.

This is the TCL script which I am using on another module system, it works fine. I am not able to execute the "source" command line in Lmod, what I am missing here?

    #%Module1.0#####################################################################
##
## modules software/openfoam_v1812
##
## /opt/software/openfoam/openfoamv1812/OpenFOAM-v1812

proc ModulesHelp { } {
        global version modroot

        puts stderr "software/OpenFOAM-v1812 - sets the Environment for OpenFOAM-v1812 (openfoam.com)"
}

module-whatis   "Sets the environment for using OpenFOAM-v1812"

# for Tcl script use only

set     VERSION         v1812
set     OpenFOAM_PATH    /opt/software/openfoam/openfoam${VERSION}/OpenFOAM-${VERSION}
set     FOAM_INST_DIR    /opt/software/openfoam/openfoam${VERSION}

puts stdout "source /opt/software/openfoam/openfoam${VERSION}/OpenFOAM-${VERSION}/etc/bashrc;"

Solution

  • I am not an expert, but I have recently come across a similar problem, in my case for activating Anaconda Python in a model. In my case, the solution was to use the 'execute' command in LMod

    https://lmod.readthedocs.io/en/latest/050_lua_modulefiles.html

    which has the documentation:

    execute {cmd=”<any command>”,modeA={“load”}}

    Run any command with a certain mode. For example execute {cmd=”ulimit -s unlimited”,modeA={“load”}} will run the command ulimit -s unlimited as the last thing that the loading the module will do.

    Hope this helps