| 1 |
\documentclass{beamer} |
| 2 |
|
| 3 |
% You can also use a 16:9 aspect ratio: |
| 4 |
%\documentclass[aspectratio=169]{beamer} |
| 5 |
\usetheme{TACC16} |
| 6 |
|
| 7 |
% It's possible to move the footer to the right: |
| 8 |
%\usetheme[rightfooter]{TACC16} |
| 9 |
|
| 10 |
% page |
| 11 |
%\begin{frame}{} |
| 12 |
% \begin{itemize} |
| 13 |
% \item |
| 14 |
% \end{itemize} |
| 15 |
%\end{frame} |
| 16 |
% |
| 17 |
%% page |
| 18 |
%\begin{frame}[fragile] |
| 19 |
% \frametitle{} |
| 20 |
% {\tiny |
| 21 |
% \begin{semiverbatim} |
| 22 |
% \end{semiverbatim} |
| 23 |
%} |
| 24 |
% \begin{itemize} |
| 25 |
% \item |
| 26 |
% \end{itemize} |
| 27 |
% |
| 28 |
%\end{frame} |
| 29 |
|
| 30 |
\begin{document} |
| 31 |
\title[Lmod]{How TCL break, puts \& help messages are handled by Lmod} |
| 32 |
\author{Robert McLay} |
| 33 |
\date{January 10, 2023} |
| 34 |
|
| 35 |
% page 1 |
| 36 |
\frame{\titlepage} |
| 37 |
|
| 38 |
|
| 39 |
% page 2 |
| 40 |
\begin{frame}{Outline} |
| 41 |
\center{\includegraphics[width=.9\textwidth]{[email protected]}} |
| 42 |
\begin{itemize} |
| 43 |
\item Review of how TCL modulefiles are evaluated |
| 44 |
\item How .version and .modulerc file are evaluated |
| 45 |
\item Support for bare TCL break (LmodBreak()) |
| 46 |
\item Support for TCL's puts |
| 47 |
\item Capturing help message from TCL modulefiles |
| 48 |
\end{itemize} |
| 49 |
\end{frame} |
| 50 |
|
| 51 |
% page 3 |
| 52 |
\begin{frame}{How Lmod handles TCL modulefiles} |
| 53 |
\begin{itemize} |
| 54 |
\item Use tcl2lua.tcl to read the modulefile. |
| 55 |
\item It evaluates all pure TCL code |
| 56 |
\item It outputs Lua strings for all module commands (setenv, etc) |
| 57 |
\item Lmod evalutes Lua output from tcl2lua.tcl |
| 58 |
\item Means that all TCL if stmts are evaluated by tcl2lua.tcl |
| 59 |
\end{itemize} |
| 60 |
\end{frame} |
| 61 |
|
| 62 |
% page 4 |
| 63 |
\begin{frame}{How Lmod handles TCL modulefiles (II)} |
| 64 |
\begin{itemize} |
| 65 |
\item Remember that tcl2lua.tcl is a separate code written in TCL |
| 66 |
\item It doesn't have access to the internal Lmod structures |
| 67 |
\item There is only a command-line interface between the two programs. |
| 68 |
\end{itemize} |
| 69 |
\end{frame} |
| 70 |
|
| 71 |
% page 5 |
| 72 |
\begin{frame}[fragile] |
| 73 |
\frametitle{When things go awry} |
| 74 |
\begin{itemize} |
| 75 |
\item Suppose you have TCL modules \textbf{Centos} and \textbf{B} |
| 76 |
\end{itemize} |
| 77 |
{\tiny |
| 78 |
\begin{semiverbatim} |
| 79 |
Centos:: |
| 80 |
|
| 81 |
#%Module |
| 82 |
setenv SYSTEM\_NAME Centos |
| 83 |
|
| 84 |
And B:: |
| 85 |
|
| 86 |
#%Module |
| 87 |
module load Centos |
| 88 |
|
| 89 |
if \{ \$env(SYSTEM\_NAME) == "Centos" \} \{ |
| 90 |
# do something |
| 91 |
\} |
| 92 |
|
| 93 |
\end{semiverbatim} |
| 94 |
} |
| 95 |
\end{frame} |
| 96 |
|
| 97 |
% page 6 |
| 98 |
\begin{frame}[fragile] |
| 99 |
\frametitle{Converting the TCL \textbf{B} into Lua} |
| 100 |
{\tiny |
| 101 |
\begin{semiverbatim} |
| 102 |
load("Centos") |
| 103 |
LmodError("can't read \"env(SYSTEM\_NAME)\": no such variable") |
| 104 |
\end{semiverbatim} |
| 105 |
} |
| 106 |
\begin{itemize} |
| 107 |
\item Trouble: the TCL \textbf{load} command $\Rightarrow$ |
| 108 |
\texttt{load("Centos")} |
| 109 |
\item Cannot get the TCL load command to be evaluated before the |
| 110 |
TCL if block |
| 111 |
\end{itemize} |
| 112 |
|
| 113 |
\end{frame} |
| 114 |
|
| 115 |
% page 7 |
| 116 |
\begin{frame}{How .version \& .modulerc are eval'ed} |
| 117 |
\begin{itemize} |
| 118 |
\item Lmod uses the RC2lua.tcl script to convert to Lua |
| 119 |
\item It only knows \texttt{module-version}, |
| 120 |
\texttt{module-alias}, ... |
| 121 |
\item It doesn't know about \texttt{setenv} |
| 122 |
\item I don't know what setenv means here |
| 123 |
\end{itemize} |
| 124 |
\end{frame} |
| 125 |
|
| 126 |
% page 8 |
| 127 |
\begin{frame}[fragile] |
| 128 |
\frametitle{How Lmod implements TCL break} |
| 129 |
{\tiny |
| 130 |
\begin{semiverbatim} |
| 131 |
set a 10 |
| 132 |
while \{\$a < 20 \} \{ |
| 133 |
puts "value of a: \$a" |
| 134 |
incr acl2 |
| 135 |
if \{ \$a > 15\} \{ |
| 136 |
break |
| 137 |
\} |
| 138 |
\} |
| 139 |
\end{semiverbatim} |
| 140 |
} |
| 141 |
\begin{itemize} |
| 142 |
\item Normal use: exit from loop. |
| 143 |
\item A bare TCL break is normally an error |
| 144 |
\item Lmod (and Tmod) stops evaluating current module. |
| 145 |
\item Lmod keeps all previous module evaluations intact |
| 146 |
\item Lmod continues evaluating after break |
| 147 |
\item Not sure what Tmod3 and Tmod do w.r.t. break |
| 148 |
\end{itemize} |
| 149 |
\end{frame} |
| 150 |
|
| 151 |
|
| 152 |
% page 9 |
| 153 |
\begin{frame}{Examples} |
| 154 |
\begin{itemize} |
| 155 |
\item \texttt{module load A B brkModule D} |
| 156 |
\item modules A and B are still loaded |
| 157 |
\item brkModule is essentially ignored |
| 158 |
\item D is loaded. |
| 159 |
\item \texttt{module load A B errModule D} |
| 160 |
\item Lmod internally loads A \& B |
| 161 |
\item Loading errModule fails |
| 162 |
\item No new modules loaded. |
| 163 |
\end{itemize} |
| 164 |
\end{frame} |
| 165 |
|
| 166 |
% page 10 |
| 167 |
\begin{frame}{How Lmod supports break} |
| 168 |
\begin{itemize} |
| 169 |
\item Special code in tcl2lua.tcl to handle a bare break |
| 170 |
\item Lmod has to recover from a rejected modulefile |
| 171 |
\end{itemize} |
| 172 |
\end{frame} |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
% page 11 |
| 177 |
\begin{frame}[fragile] |
| 178 |
\frametitle{How tcl2lua.tcl handles bare break} |
| 179 |
{\tiny |
| 180 |
\begin{semiverbatim} |
| 181 |
set errorVal [interp eval \$child \{ |
| 182 |
set returnVal 0 |
| 183 |
... |
| 184 |
set sourceFailed [catch \{source \$ModulesCurrentModulefile \} errorMsg] |
| 185 |
if \{ \$g\_help ...\} \{ |
| 186 |
... |
| 187 |
\} |
| 188 |
if \{\$sourceFailed\} \{ |
| 189 |
if \{ \$sourceFailed == 3 || \$errorMsg == {invoked "break" outside of a loop}\} \{ |
| 190 |
set returnVal 1 |
| 191 |
myBreak # output "LmodBreak into Global |
| 192 |
showResults # Write output |
| 193 |
return \$returnVal # return with error status |
| 194 |
\} |
| 195 |
reportError \$errorMsg # output error message |
| 196 |
set returnVal 1 # return with error status |
| 197 |
\} |
| 198 |
showResults # Write output for normal translation |
| 199 |
return \$returnVal # return with OK status |
| 200 |
\}] |
| 201 |
\end{semiverbatim} |
| 202 |
} |
| 203 |
\begin{itemize} |
| 204 |
\item A bare break is an error in TCL |
| 205 |
\item tcl2lua.tcl captures that |
| 206 |
\item generates ''LmodBreak()'' |
| 207 |
\end{itemize} |
| 208 |
|
| 209 |
\end{frame} |
| 210 |
|
| 211 |
% page 12 |
| 212 |
\begin{frame}{How Lmod handles LmodBreak()} |
| 213 |
\begin{itemize} |
| 214 |
\item Lmod maintains a stack of module ``states'' |
| 215 |
\item It is called ``FrameStk`` |
| 216 |
\item It contains: |
| 217 |
\begin{enumerate} |
| 218 |
\item VarT: new env vars values |
| 219 |
\item ModuleTable: The currently loaded modules |
| 220 |
\item mname: Current module object to be loaded. |
| 221 |
\end{enumerate} |
| 222 |
\item Support for FrameStk was added with Lmod 7 rewrite |
| 223 |
\item Correct support for Break was added in 8.7+ |
| 224 |
\end{itemize} |
| 225 |
\end{frame} |
| 226 |
|
| 227 |
% page 13 |
| 228 |
\begin{frame}{FrameStk action during module loads} |
| 229 |
\begin{itemize} |
| 230 |
\item Each module load creates a new FrameStk entry |
| 231 |
\item Currently loaded module succeeds $\Rightarrow$ overwrites |
| 232 |
previous entry |
| 233 |
\item Break causes the current entry to be thrown away |
| 234 |
\end{itemize} |
| 235 |
\end{frame} |
| 236 |
|
| 237 |
% page 14 |
| 238 |
\begin{frame}[fragile] |
| 239 |
\frametitle{Another Break example} |
| 240 |
{\tiny |
| 241 |
\begin{semiverbatim} |
| 242 |
\$ cat StdEnv.lua |
| 243 |
load("A") |
| 244 |
load("B") |
| 245 |
load("BRK") |
| 246 |
load("D") |
| 247 |
|
| 248 |
\$ ml StdEnv; ml |
| 249 |
Currently loaded modules: |
| 250 |
1) A 2) B 3) D |
| 251 |
\end{semiverbatim} |
| 252 |
} |
| 253 |
\begin{itemize} |
| 254 |
\item The contents of the \texttt{BRK} module are ignored |
| 255 |
\end{itemize} |
| 256 |
|
| 257 |
\end{frame} |
| 258 |
|
| 259 |
% page 15 |
| 260 |
\begin{frame}{Handling TCL puts} |
| 261 |
\begin{itemize} |
| 262 |
\item TCL \texttt{puts} $\Rightarrow$ calls \texttt{myPuts} thru child interpreter |
| 263 |
\item puts and myPuts takes upto 3 arguments |
| 264 |
\item It took years to get this correct |
| 265 |
\item \texttt{myPuts} write to a global array in tcl2lua.tcl |
| 266 |
\item the \texttt{showResults} sends it to stdout for lua to |
| 267 |
evaluate |
| 268 |
\item Message sent to stderr use LmodMsgRaw() function |
| 269 |
\end{itemize} |
| 270 |
\end{frame} |
| 271 |
|
| 272 |
% page 16 |
| 273 |
\begin{frame}{\texttt{myPuts} arguments} |
| 274 |
\begin{itemize} |
| 275 |
\item puts can only have 1 to 3 arguments |
| 276 |
\item puts <-nonewline> <channel> msg |
| 277 |
\item puts msg $\Rightarrow$ writes to stdout (at end) |
| 278 |
\item puts stdout msg $\Rightarrow$ writes to stdout (at end) |
| 279 |
\item puts stderr msg $\Rightarrow$ writes to stderr |
| 280 |
\item puts prestdout msg $\Rightarrow$ writes to stdout but at the beginning of output |
| 281 |
\end{itemize} |
| 282 |
\end{frame} |
| 283 |
|
| 284 |
|
| 285 |
% page 17 |
| 286 |
\begin{frame}[fragile] |
| 287 |
\frametitle{Handling TCL help messages} |
| 288 |
{\tiny |
| 289 |
\begin{semiverbatim} |
| 290 |
proc ModulesHelp { } { |
| 291 |
puts stderr "The TACC Amber installation ..." |
| 292 |
} |
| 293 |
|
| 294 |
Lmod wants: |
| 295 |
help ([===[The TACC Amber installation ...]===]) |
| 296 |
\end{semiverbatim} |
| 297 |
} |
| 298 |
\begin{itemize} |
| 299 |
\item Converting TCL help message was tricky |
| 300 |
\item tcl2lua.tcl has to capture the output when executing |
| 301 |
ModulesHelp |
| 302 |
\item myPuts has a special mode when running ModulesHelp |
| 303 |
\end{itemize} |
| 304 |
|
| 305 |
\end{frame} |
| 306 |
|
| 307 |
% page 18 |
| 308 |
\begin{frame}[fragile] |
| 309 |
\frametitle{} |
| 310 |
{\tiny |
| 311 |
\begin{semiverbatim} |
| 312 |
if \{ \$g\_help && [info procs "ModulesHelp"] == "ModulesHelp" \} \{ |
| 313 |
set start "help(\textbackslash[===\textbackslash[" |
| 314 |
set end "\textbackslash]===\textbackslash])" |
| 315 |
setPutMode "inHelp" |
| 316 |
myPuts stdout \$start |
| 317 |
catch { ModulesHelp } errMsg |
| 318 |
myPuts stdout \$end |
| 319 |
setPutMode "normal" |
| 320 |
\} |
| 321 |
\end{semiverbatim} |
| 322 |
} |
| 323 |
\begin{itemize} |
| 324 |
\item in ``inHelp'' mode output to stderr is written to stdout |
| 325 |
\end{itemize} |
| 326 |
\end{frame} |
| 327 |
|
| 328 |
|
| 329 |
% page 19 |
| 330 |
\begin{frame}[fragile] |
| 331 |
\frametitle{Help Conversion Example} |
| 332 |
{\tiny |
| 333 |
\begin{semiverbatim} |
| 334 |
help([===[ |
| 335 |
The TACC Amber installation only includes the parallel Sander/pmemd modules. |
| 336 |
The Amber modulefile defines the following environment variables: ... |
| 337 |
|
| 338 |
Version 9 |
| 339 |
]===]) |
| 340 |
\end{semiverbatim} |
| 341 |
} |
| 342 |
\begin{itemize} |
| 343 |
\item This way help message work the same with Lua and TCL modulefiles |
| 344 |
\end{itemize} |
| 345 |
|
| 346 |
\end{frame} |
| 347 |
|
| 348 |
% page 20 |
| 349 |
\begin{frame}{Conclusions} |
| 350 |
\begin{itemize} |
| 351 |
\item TCL to Lua conversion works well |
| 352 |
\item But it is NOT perfect. |
| 353 |
\item TCL Break, puts and help message required special foo |
| 354 |
\end{itemize} |
| 355 |
\end{frame} |
| 356 |
|
| 357 |
% page 21 |
| 358 |
\begin{frame}{Next Time} |
| 359 |
\begin{itemize} |
| 360 |
\item How to use \texttt{check\_module\_tree\_syntax} |
| 361 |
\end{itemize} |
| 362 |
\end{frame} |
| 363 |
|
| 364 |
% page 22 |
| 365 |
\begin{frame}{Future Topics} |
| 366 |
\begin{itemize} |
| 367 |
\item I am on vacation (a.k.a holiday) in early February |
| 368 |
\item Next Meeting will be Feb 14th |
| 369 |
\end{itemize} |
| 370 |
\end{frame} |
| 371 |
|
| 372 |
\end{document} |