Finally, based on the above information, the following module command should be constructed and run from within this module file:
module load compiler/2022.0.2 mkl/2022.0.2 mpi/2021.4.0
Any hints for achieving this aim programmatically with tcl?
Note: The number of components in the toolchain used to compile a package may vary, the only invariant rule is that each part of the components is separated with a hyphen, as represented above.
On 2/20/22 3:19 AM, Hongyi Zhao wrote:
Finally, based on the above information, the following module command should be constructed and run from within this module file:
module load compiler/2022.0.2 mkl/2022.0.2 mpi/2021.4.0
Any hints for achieving this aim programmatically with tcl?
Note: The number of components in the toolchain used to compile a package may vary, the only invariant rule is that each part of the components is separated with a hyphen, as represented above.
Hello,
Not completely certain of what output you want but this piece of code
should get you going:
set mod_file "vasp/6.3.0/intel_omp-compiler.2022.0.2-mkl.2022.0.2-mpi.2021.4.0"
set parts [split $mod_file /]
if {[llength $parts] != 3} { puts "not a module file?"; exit }
set p_name [lindex $parts 0]
set p_vers [lindex $parts 1]
set comp_info [lindex $parts 2]
set comp_parts [list]
foreach part [split $comp_info -] {
set idx [string first . $part]
if {$idx < 0} { continue }
incr idx -1
set compo_name [string range $part 0 $idx]
incr idx +2
set compo_vers [string range $part $idx end]
lappend comp_parts "${compo_name}/${compo_vers}"
}
set final_cmd "module load [join $comp_parts { }]"
puts "MODULE LOAD COMMAND: \n $final_cmd"
In my case, the constructed `module load` command must be run as follows from within the module file itself:
module load [lindex $comp_parts 0] [lindex $comp_parts 1] [lindex $comp_parts 2]
The above command will be converted to the following lmod command before execution:
load("compiler/2022.0.2","mkl/2022.0.2","mpi/2021.4.0")
While your version "module load [join $comp_parts { }]" will be converted into the following one which doesn't work:
load("compiler/2022.0.2 mkl/2022.0.2 mpi/2021.4.0")
The problem appears to be the module list is seen as a single item on the command line
You might try:
module load {*}$comp_parts
It should allow as many modules as are found.
If the TCL version is reasonably recent,
another way to generate the comp_parts list is:
lassign [split $str "/"] pkg pkg_ver other
set comp_parts [lmap comp [lassign [split $other "-"] toolchain] {
set sepi [string first "." $comp]
string replace $comp $sepi $sepi "/"
}]
pkg, pkg_ver and tool chain have values set as well.
In my case, the constructed `module load` command must be run as follows from within the module file itself:
module load [lindex $comp_parts 0] [lindex $comp_parts 1] [lindex $comp_parts 2]
The above command will be converted to the following lmod command before execution:
load("compiler/2022.0.2","mkl/2022.0.2","mpi/2021.4.0")
While your version "module load [join $comp_parts { }]" will be converted into the following one which doesn't work:
load("compiler/2022.0.2 mkl/2022.0.2 mpi/2021.4.0")
On Monday, February 21, 2022 at 2:41:02 PM UTC+8, clt.to...@dfgh.net wrote:
In my case, the constructed `module load` command must be run as follows from within the module file itself:
module load [lindex $comp_parts 0] [lindex $comp_parts 1] [lindex $comp_parts 2]
The above command will be converted to the following lmod command before execution:
load("compiler/2022.0.2","mkl/2022.0.2","mpi/2021.4.0")
While your version "module load [join $comp_parts { }]" will be converted into the following one which doesn't work:
load("compiler/2022.0.2 mkl/2022.0.2 mpi/2021.4.0")
The problem appears to be the module list is seen as a single item on the command line
You might try:
module load {*}$comp_parts
It should allow as many modules as are found.Thank you. It does the trick.
If the TCL version is reasonably recent,My TCL version is shown below:
```
werner@X10DAi-00:~$ tclsh <<< 'puts [info patchlevel]'
8.6.10
werner@X10DAi-00:~$ echo 'puts [info patchlevel];exit 0' | tclsh
8.6.10
```
another way to generate the comp_parts list is:
lassign [split $str "/"] pkg pkg_ver other
set comp_parts [lmap comp [lassign [split $other "-"] toolchain] {
set sepi [string first "." $comp]
string replace $comp $sepi $sepi "/"
}]
pkg, pkg_ver and tool chain have values set as well.Thank you for your enhancement. Based on your suggestion above, I changed to the following code, and it works:
```
set HOME $env(HOME)
set module_fullname [module-info name]
lassign [split $module_fullname "/"] pkg pkg_ver comp_info
set comp_parts [lmap comp [lassign [split $comp_info "-"] toolchain] {
set sepi [string first "." $comp]
string replace $comp $sepi $sepi "/"
}]
# See Public/repo/github.com/TACC/Lmod.git.bash
#$ cd /opt/intel/oneapi && sudo ./modulefiles-setup.sh
#$ module use /opt/intel/oneapi/modulefiles
#module --force purge
module load {*}$comp_parts
prepend-path PATH $HOME/Public/hpc/$pkg/$pkg_ver/bin/$comp_info
module-whatis "$pkg $pkg_ver"
# Help message
proc ModulesHelp { } {
set module_fullname [module-info name]
puts stderr "\tLoads the $module_fullname environment."
}
```
Regards,
HZ
set HOME $env(HOME)
set module_fullname [module-info name]
lassign [split $module_fullname "/"] pkg pkg_ver comp_info
set comp_parts [lmap comp [lassign [split $comp_info "-"] toolchain] {
set sepi [string first "." $comp]
string replace $comp $sepi $sepi "/"
}]
Though it works, this part of your suggested code is rathere obsure to understand. Why the variable "toolchain" only appeared once in this method?
In my case, the constructed `module load` command must be run as follows from within the module file itself:
module load [lindex $comp_parts 0] [lindex $comp_parts 1] [lindex $comp_parts 2]
The above command will be converted to the following lmod command before execution:
load("compiler/2022.0.2","mkl/2022.0.2","mpi/2021.4.0")
While your version "module load [join $comp_parts { }]" will be converted into the following one which doesn't work:
load("compiler/2022.0.2 mkl/2022.0.2 mpi/2021.4.0")
The problem appears to be the module list is seen as a single item on the command line
You might try:
module load {*}$comp_parts
It should allow as many modules as are found.
If the TCL version is reasonably recent, another way to generate the comp_parts list is:
lassign [split $str "/"] pkg pkg_ver other
set comp_parts [lmap comp [lassign [split $other "-"] toolchain] {
set sepi [string first "." $comp]
string replace $comp $sepi $sepi "/"
}]
pkg, pkg_ver and tool chain have values set as well.
Dave B
lassign [split $str "/"] pkg pkg_ver other
set comp_parts [lmap comp [lassign [split $other "-"] toolchain] {
set sepi [string first "." $comp]
string replace $comp $sepi $sepi "/"
}]
I copied and pasted your above code snippet into Komodo as follows:
```
set str "vasp/6.3.0/intel_omp-compiler.2022.0.2-mkl.2022.0.2-mpi.2021.4.0"
lassign [split $str "/"] pkg pkg_ver other
set comp_parts [lmap comp [lassign [split $other "-"] toolchain]
{
set sepi [string first "." $comp]
string replace $comp $sepi $sepi "/"
}
]
```
But Komodo complains that the following line has syntax error:
set comp_parts [lmap comp [lassign [split $other "-"] toolchain]
The error is as follows:
wrong # args
set comp_parts [lmap comp [lassign [split $other "-"] toolchain] --------------------------- this line break is seen as an early end of the lmap command -------------------------------------------------- this line break will cause trouble for the lmap command too -------------------------
{
set sepi [string first "." $comp]
string replace $comp $sepi $sepi "/"
}
]
in the list, which is now on the next line, and is not seen as part of the current command.lassign [split $str "/"] pkg pkg_ver other
set comp_parts [lmap comp [lassign [split $other "-"] toolchain] {
set sepi [string first "." $comp]
string replace $comp $sepi $sepi "/"
}]
I copied and pasted your above code snippet into Komodo as follows:
```
set str "vasp/6.3.0/intel_omp-compiler.2022.0.2-mkl.2022.0.2-mpi.2021.4.0"
lassign [split $str "/"] pkg pkg_ver other
set comp_parts [lmap comp [lassign [split $other "-"] toolchain]
{
set sepi [string first "." $comp]
string replace $comp $sepi $sepi "/"
}
]
```
But Komodo complains that the following line has syntax error:
set comp_parts [lmap comp [lassign [split $other "-"] toolchain]
The error is as follows:
wrong # args
There are changes in the copied code. Unless a line break is within "" or {} or is immediately (no extra white space) preceded by a "\" it ends a command. In this case the lmap command is expecting a block of code to execute once for each set of data
set comp_parts [lmap comp [lassign [split $other "-"] toolchain] --------------------------- this line break is seen as an early end of the lmap command -------------------------------------------------- this line break will cause trouble for the lmap command too -------------------------
{
set sepi [string first "." $comp]
string replace $comp $sepi $sepi "/"
}
]
There are several tutorials on the web, one is on the TCL wiki:
https://wiki.tcl-lang.org/page/Tcl+Tutorial+Lesson+0
There are books as well. I learned TCL about 20 years ago from "Practical Programming in Tcl and Tk". It is available on the web now. There are more recent books on TCL which cover all the latest changes in TCL and Tk.
I suggest you start a new thread asking for tutorials or books.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 498 |
Nodes: | 16 (2 / 14) |
Uptime: | 21:13:13 |
Calls: | 9,827 |
Calls today: | 6 |
Files: | 13,761 |
Messages: | 6,191,558 |