Tuesday, August 9, 2011

LAMMPS, FFTW, JPEGLIB and MPICH2 Installation on MAC OS X

This post shows how to install LAMMPS on MAC. To have parallel build one needs to install some MPI wrapper like OpenMPI or MPICH2. For some type of simulations with LAMMPS you need FFTW too. I wanted to have Jpeg libraries too with LAMMPS. Of course, you need the most important piece, C, C++ and Fortran compilers. If you just need LAMMPS, I mean with out optional packages, then you don't need Fortran compiler. I recommend Intel compilers. Yesterday, I built LAMMPS with all these and thought it might be helpful for someone if I posted it here.

Oho, by the way make sure you download XCODE and install it before you install Intel compilers. Otherwise, you won't be able to create c executables. You can download it from Apple website. It is also there on the CDs that come with your mac. Xcode is not installed by default.

Here is how it goes ...

Jpeg Libraries

You can download the source at http://www.ijg.org/
$ cd Desktop
$ tar xzvf jpegsrc.v8c.tar.gz
$ cd jpeg-8c/
$ mkdir ~/libjpeg
$ ./configure --prefix=/Users/sm4082/libjpeg/ CC=icc \
CFLAGS='-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip' \
LDFLAGS='-L/Developer/opt/intel/Compiler/11.1/084/lib/' \
CPPFLAGS='-I/Developer/opt/intel/Compiler/11.1/084/include'
$ make
$ make install
$ make test

MPICH2 Installation

MPICH2 can be downloaded from http://www.mcs.anl.gov/research/projects/mpich2/.
$ cd ~/Desktop
$ tar xzvf mpich2-1.4.tar.gz
$ cd mpich2-1.4
$ mkdir ~/mpich2
$ ./configure --prefix=/Users/sm4082/mpich2 CC=icc \
CFLAGS='-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip' \
F77=ifort FFLAGS='-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip' FC=ifort \
FCFLAGS='-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip' CXX=icpc \
CXXFLAGS='-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip' --enable-f77 \
--enable-fc --enable-cxx --enable-totalview --enable-mpe \
--enable-fast=O2 --with-device=ch3:nemesis \
--with-pm=hydra:mpd:gforker --enable-error-checking=all \
--enable-error-messages=all --enable-smpcoll --enable-nmpi-as-mpi \
--enable-timing=all --enable-timer-type=gettimeofday \
--enable-romio --enable-threads=default --enable-debuginfo --enable-g=dbg,log --disable-rpath 2>&1 | tee c.txt
$ make 2>&1 | tee m.txt
$ make install 2>&1 | tee mi.txt

FFTW Installation

LAMMPS doesn't work with FFTW version 3.X version. We need to install version 2.X.X. FFTW can be downloaded from http://www.fftw.org/
$ cd ~/Desktop
$ tar xzvf fftw-2.1.5.tar.gz
$ cd fftw-2.1.5
$ mkdir ~/fftw-2.1.5
$ ./configure CC='icc' CFLAGS='-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip' \
LDFLAGS='-L/Developer/opt/intel/Compiler/11.1/084/lib' \
CPPFLAGS='-I/Developer/opt/intel/Compiler/11.1/084/include' --enable-shared  \
--enable-mpi MPICC=/Users/sm4082/mpich2/bin/mpicc \
LDFLAGS='-L/Users/sm4082/mpich2/lib' \
CPPFLAGS='-I/Users/sm4082/mpich2/include' --with-openmp \
--enable-debug --disable-fortran --prefix=/Users/sm4082/fftw-2.1.5/
$ make
$ make install
$ make check

Finally, LAMMPS Installation

LAMMPS can be downloaded from http://lammps.sandia.gov/
To install packages like MEAM, REAX you need Fortran compiler. I have used Intel Fortran compiler.
$ cd ~/Desktop
$ tar xzvf lammps.tar.gz
$ cd lammps-5Aug11/lib/meam/
$ make -f Makefile.ifort
$ cd ../poems/
$ make -f Makefile.icc
$ cd ../reax/
$ make -f Makefile.ifort
$ cd ../../src/
Next, edit the makefile Makefile.linux in MAKE folder in src directory.
$ more MAKE/Makefile.linux
# linux = RedHat Linux box, Intel icc, Intel ifort, MPICH2, FFTW

SHELL = /bin/sh

# ---------------------------------------------------------------------
# compiler/linker settings
# specify flags and libraries needed for your compiler

CC =            /Users/sm4082/mpich2/bin/mpic++
CCFLAGS =       -O3 -fPIC -align -Zp8 -axP -unroll -xP -ip
DEPFLAGS =      -M
LINK =          /Users/sm4082/mpich2/bin/mpic++
LINKFLAGS =     -O
LIB =           -lstdc++
ARCHIVE =       ar
ARFLAGS =       -rc
SIZE =          size

# ---------------------------------------------------------------------
# LAMMPS-specific settings
# specify settings for LAMMPS features you will use

# LAMMPS ifdef options, see doc/Section_start.html

LMP_INC =       -DLAMMPS_GZIP -DLAMMPS_JPEG

# MPI library, can be src/STUBS dummy lib
# INC = path for mpi.h, MPI compiler settings
# PATH = path for MPI library
# LIB = name of MPI library

MPI_INC =       -DMPICH_SKIP_MPICXX -I/Users/sm4082/mpich2/include
MPI_PATH = -L/Users/sm4082/mpich2/lib
MPI_LIB =       -lmpich -lpthread

# FFT library, can be -DFFT_NONE if not using PPPM from KSPACE package
# INC = -DFFT_FFTW, -DFFT_INTEL, -DFFT_NONE, etc, FFT compiler settings
# PATH = path for FFT library
# LIB = name of FFT library

FFT_INC =       -DFFT_FFTW -I/Users/sm4082/fftw-2.1.5/include
FFT_PATH = -L/Users/sm4082/fftw-2.1.5/lib
FFT_LIB =       -lfftw

# JPEG library, only needed if -DLAMMPS_JPEG listed with LMP_INC
# INC = path for jpeglib.h
# PATH = path for JPEG library
# LIB = name of JPEG library

JPG_INC =      -I/Users/sm4082/libjpeg/include 
JPG_PATH =      -L/Users/sm4082/libjpeg/lib
JPG_LIB =       -ljpeg

# additional system libraries needed by LAMMPS package libraries
# these settings are IGNORED if the corresponding LAMMPS package
#   (e.g. gpu, meam) is NOT included in the LAMMPS build
# SYSINC = settings to compile with
# SYSLIB = libraries to link with
# SYSPATH = paths to libraries

gpu_SYSINC =
meam_SYSINC =
reax_SYSINC =
user-atc_SYSINC =
user-awpmd_SYSINC =

gpu_SYSLIB =       -lcudart -lcuda
meam_SYSLIB =      -lifcore -lsvml -lompstub -limf
poems_SYSLIB =     -lifcore -lsvml -lompstub -limf
reax_SYSLIB =      -lifcore -lsvml -lompstub -limf
user-atc_SYSLIB =  -lblas -llapack
user-awpmd_SYSLIB =  -lblas -llapack

gpu_SYSPATH =      -L/usr/local/cuda/lib64
meam_SYSPATH =     -L/Developer/opt/intel/Compiler/11.1/084/lib
poems_SYSPATH =     -L/Developer/opt/intel/Compiler/11.1/084/lib
reax_SYSPATH =     -L/Developer/opt/intel/Compiler/11.1/084/lib
user-atc_SYSPATH =
user-awpmd_SYSPATH =

# ---------------------------------------------------------------------
# build rules and dependencies
# no need to edit this section

include Makefile.package

EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC)
EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH)
EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB)

# Link target

$(EXE): $(OBJ)
        $(LINK) $(LINKFLAGS) $(EXTRA_PATH) $(OBJ) $(EXTRA_LIB) $(LIB) -o $(EXE)
        $(SIZE) $(EXE)

# Library target

lib:    $(OBJ)
        $(ARCHIVE) $(ARFLAGS) $(EXE) $(OBJ)

# Compilation rules

%.o:%.cpp
        $(CC) $(CCFLAGS) $(EXTRA_INC) -c $<

%.d:%.cpp
        $(CC) $(CCFLAGS) $(EXTRA_INC) $(DEPFLAGS) $< > $@

# Individual dependencies

DEPENDS = $(OBJ:.o=.d)
include $(DEPENDS)
Edit the Makefile.linux following the above makefile. You need Fortran libraries for compiling packages Meam and Reax. The library needed is libifcore. So, I have created a link to this in intel C/C++ lib folder. The advantage of doing this is that you just need to add just intel C/C++ lib to DYLD_LIBRARY_PATH, but not Fortran libraries location. If you want you can include Fortran libraries location for meam_SYSPATH and reax_SYSPATH variables in makefile. But like I said, you need to add both C/C++ and Fortran library locations to DYLD_LIBRARY_PATH.
$ sudo -s
$ ln -s /Developer/opt/intel/composerxe-2011.0.085/compiler/lib/libifcore.a /Developer/opt/intel/Compiler/11.1/084/lib/libifcore.a
$ ln -s /Developer/opt/intel/composerxe-2011.0.085/compiler/lib/libifcore.dylib /Developer/opt/intel/Compiler/11.1/084/lib/libifcore.dylib
$ exit
$ make yes-granular
$ make yes-meam
$ make yes-poems
$ make yes-reax
$ make linux
You should see the lammps executable lmp_linux at the end of the installation.

Running examples with LAMMPS executable

First, we need to make sure the path of Intel libraries, /Developer/opt/intel/Compiler/11.1/084/lib, is added to DYLD_LIBRARY_PATH. You can either do it temporarily for a session or permanently by adding to your ~.bashrc.
Temporary
$ export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/Developer/opt/intel/Compiler/11.1/084/lib
Permanent
$ cd
$ echo "export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/Developer/opt/intel/Compiler/11.1/084/lib" >> .bashrc
$ source .bashrc
If you still see library problems while trying to run examples, I suggest add the location of MPICH2, Jpeg and FFTW libraries also to DYLD_LIBRARY_PATH varaible.

LAMMPS Examples

$ cd lammps-5Aug11/examples/meam/
$ ../../src/lmp_linux < in.meam
$ cd ../peptide
$ ../../src/lmp_linux < in.peptide 
$ cd ../micelle/
$ ../../src/lmp_linux < in.micelle 
$ cd ../flow/
$ ../../src/lmp_linux < in.flow.couette 
$ ../../src/lmp_linux < in.flow.pois
For all these runs you should see lammps running successfully outputting details on the screen just like the ones shown in the log files in those respective example directories. Most of the time, the errors come from the library problems like library not found. Which means library location is not added to DYLD_LIBRARY_PATH variable. You can run the same examples with mpi wrapper in parallel.
$ ~/mpich2/bin/mpiexec -n 4 ../../src/lmp_linux < in.flow.couette
or
$ ~/mpich2/bin/mpirun -np 4 ../../src/lmp_linux < in.flow.couette
You should see something like "Loop time of 0.523332 on 4 procs for 10000 steps with 420 atoms" instead of "Loop time of 0.468267 on 1 procs for 10000 steps with 420 atoms".

Sometimes, you need to go to Security pane in the System Preferences and add lmp_linux to allowed incoming connections. Otherwise, it won't let you run any parallel runs. By the way, you need to go to advanced tab on the security pane to do this.

If everything goes well you're done. You got LAMMPS executable to run whole lot of simulations in the days ahead of you. Good luck. If you get problems don't hesitate to drop me a comment and I'll try my best to help you out.

Monday, July 11, 2011

BASH Shell Scripting to generate confluence code that gets you bar and pie charts on your wiki

At my work I often use confluence to update our wiki. Just last week I wanted to change the way bar charts look on our wiki. Confluence has simple mechanism of obtaining bar and pie charts. These charts indicate how our clusters are being used by the user community in our university. To generate the numbers, first need to run some script which creates some files with all the required numbers from some database. For example, to create a bar chart shown below I need to put in this code in my confluence. If you go to this page, you can see how these charts look on wiki: https://wikis.nyu.edu/display/NYUHPC/Historical+Usage+Reports

Confluence code for bar chart

{chart:title=CPU Time in Hours|type=bar|width=900}
|| CLUSTER || January || February || March || April || May || June ||
|| USQ | 380033 | 291235 | 356897 | 343902 | 375666 | 445860 ||
|| BOWERY | 572622 | 272514 | 331905 | 355627 | 301544 | 309076 ||
|| CARDIAC | 716065 | 359153 | 329973 | 723314 | 279251 | 617893 ||
|| CUDA | 1 | 0 | 1 | 251 | 54 | 0 ||
{chart}
&nbsp;

Confluence code for pie chart

{chart:title=Number of Jobs on BOWERY|width=450}
|| CLUSTER || January || February || March || April || May || June ||
|| BOWERY | 5,571 | 2,722 | 3,445 | 3,670 | 3,800 | 5,909 ||
{chart}

Simple. Right? Not really. Because, I need to do this on the first of every month. Because of whatever reasons I end up doing this some where in the middle of the month. Which is not cool. So, I thought of setting a cron job. I wanted this cron job to deliver me an email with the stuff I need to put on confluence to generate the charts just like the one shown here.

Generally, I need to log on to a specific machine and then run a command to generate the numbers and a file with the same numbers. Let me show you what I do here:
[manchu@hpc-metrics ~]$ /usr/local/bin/metrics-analysis.py monthly
To retrieve a monthly report for the previous month.
Getting HPC Metrics Statistics.
For the jobs ended on and after 2011-06-01 before 2011-07-01.
Getting the total counts from usq...
Getting the total counts from bowery...
Getting the total counts from cardiac...
Getting the total counts from cuda...
Getting the total counts from usq...
Getting the total counts from bowery...
Getting the total counts from cardiac...
Getting the total counts from cuda...

**************** Starting the sum task 1: grouped by ALL *************
Getting the total sum from usq...
Getting the total sum from bowery...
Getting the total sum from cardiac...
Getting the total sum from cuda...
----------------------
Summary of this period, sorted by ALL
For jobs ended on and after 2011-06-01 and before 2011-07-01
                               Name            usq         bowery        cardiac           cuda            All
                        Jobs number         72,671          5,909         32,444            107        111,131
                        User number             76             36              9              1             94
                        CPU time(h)        445,860        309,076        617,893              0      1,372,829
                       Wall time(h)      4,279,233        115,571        793,340             83      5,188,227
                       Used time(h)        381,261         39,053        177,488              3        597,805
                Requested CPU cores        108,591        115,402        183,247            830        408,070
                Avg. used CPU cores           1.17           7.91           3.48           0.00
Where,
Avg. used CPU cores: the average CPU resource consumed by a job, which is "CPU time/Used time"


The results were also stored in the file of hpc_usage_2011-06-01_2011-06-30.txt


[manchu@hpc-metrics ~]$ vi hpc_usage_2011-06-01_2011-06-30.txt
1 HPC Usage Summary
  2 
  3 **************** Starting the sum task 1: grouped by ALL *************
  4 Summary of this period, sorted by ALL
  5 For jobs ended on and after 2011-06-01 and before 2011-07-01
  6                                Name            usq         bowery        cardiac           cuda            All
  7                         Jobs number         72,671          5,909         32,444            107        111,131
  8                         User number             76             36              9              1             94
  9                         CPU time(h)        445,860        309,076        617,893              0      1,372,829
 10                        Wall time(h)      4,279,233        115,571        793,340             83      5,188,227
 11                        Used time(h)        381,261         39,053        177,488              3        597,805
 12                 Requested CPU cores        108,591        115,402        183,247            830        408,070
 13                 Avg. used CPU cores           1.17           7.91           3.48           0.00
 14 Where,
 15 Avg. used CPU cores: the average CPU resource consumed by a job, which is "CPU time/Used time"
 16 
 17 

I need to get the numbers from line 7 to 13 and put them together in specific format required to generate bar and pie charts on wiki using confluence wiki tool. Like I said, I could do it by cutting and pasting the numbers on to some excel file and then copy and paste them from there to confluence. Believe me it's painful to do that. So I've decided to write a script that would do all this work and then cron job would deliver all the results to me in the email. I just copy the entire things from the email and put them on confluence. That's it. It's just not even a minute job this way. More over cron job would remind me that I need to do this on the first of every month. Cool. Ha!

Crontab

My cron job runs the script at 00:05 on 1st of each month. The line you need to put in your cron tab is:
[manchu@hpc-metrics ~]$ crontab -e
5 0 1 * * /home/manchu/hpc-metrics-cronjob.sh > /dev/null 2>&1
crontab: installing new crontab
[manchu@hpc-metrics ~]$

Cron Job Script

Here is my cron job script:
[manchu@hpc-metrics ~]$ more hpc-metrics-cronjob.sh 
#!/bin/bash

# This is a cron job script for delivering the hpc metrics at the beginning of each month. Written by Sreedhar Manchu.
/home/manchu/metrics.sh | mail -s "HPC Metrics Details for `date -d\"1 month ago\" +%B`" my_email@domain.com
[manchu@hpc-metrics ~]$ 

Shell Script to generate the required code for confluence

Here is the script I wrote to generate the confluence code:
[manchu@hpc-metrics ~]$ more metrics.sh 
#!/bin/bash

/usr/local/bin/metrics-analysis.py monthly
echo "----------------------------------------------------------------------------------------"
echo
echo "###################################### EXCEL VALUES ###################################"
echo
echo "----------------------------------------------------------------------------------------"
echo

filename=hpc_usage_`date -d "last month" "+%F"`_`date -d "yesterday" "+%F"`.txt

for ((i=-5; i<=-2; i++))
do
 echo -n "| *`date -d "last month" "+%b %Y"`* |"
 for j in {7..12}
 do 
  echo -n "`head -$j $filename | tail -1 | perl -lane 'print " $F['$i'] |"'`"
 done
 echo -n "`head -13 $filename | tail -1 | perl -lane 'print " $F['$(($i+1))'] |"'`"
 echo
done


months=`date -d "last month" "+%-m"`
clusters=4
categories=7
for ((i=0; i<$months; i++))
do
filename=hpc_usage_`date -d "$(($months-$i)) months ago" "+%F"`_`date -d "yesterday $(($months-$i-1)) months ago" "+%F"`.txt
 for ((j=0; j<$clusters; j++))
 do
  for ((k=0; k<$categories; k++))
                do
   if [ $k -ne 6 ]
   then
    value[$(($i+$j*$months+$clusters*$months*$k))]="`head -$(($k+7)) $filename | tail -1 | perl -lane 'print "$F['$((
-5+$j))']"' | sed 's/,//g'`" 
   else
    value[$(($i+$j*$months+$clusters*$months*$k))]="`head -13 $filename | tail -1 | perl -lane 'print "$F['$((-4+$j))
']"' | sed 's/,//g'`" 
   fi
  done
 done
done

title_string=("Number of Jobs" "Number of Users" "CPU Time in Hours" "Walltime in Hours" "Used Time in Hours" "Total Requested CPU Cores" "Avg. C
PU Cores Used Per Job")
cluster=("USQ" "BOWERY" "CARDIAC" "CUDA")

echo
echo "----------------------------------------------------------------------------------------"
echo
echo "####################################### BAR CHARTS ####################################"
echo
echo "----------------------------------------------------------------------------------------"
echo
echo "&nbsp;"
for ((k=0; k<$categories; k++))
do
 echo "{chart:title=${title_string[$k]}|type=bar|width=900}"
 echo -n "|| CLUSTER ||"
 for ((n=0; n<$months; n++))
 do
  echo -n " `date -d "$(($months-$n)) month ago" "+%B"` ||"
 done
 echo
 for ((j=0; j<$clusters; j++))
 do
  echo -n "|| ${cluster[$j]} |"
  for ((i=0; i<$months; i++))
  do
   echo -n " ${value[$(($k*$clusters*$months+$j*$months+$i))]} |"
  done
  echo "|"
 done
 echo "{chart}"
 echo "&nbsp;"
 echo
done
echo "----------------------------------------------------------------------------------------"
echo

input_start_date=`date -d "$months months ago" "+%F"`
input_end_date="`date "+%F"`"

/usr/local/bin/metrics-analysis.py << EOF
$input_start_date
$input_end_date
EOF

filename="hpc_usage_`date -d "$months months ago" "+%F"`_`date -d "yesterday" "+%F"`.txt"
for ((j=0; j<$clusters; j++))
do
 for ((k=0; k<$categories; k++))
 do
  if [ $k -ne 6 ]
  then
   value[$(($k*$clusters+$j))]="`head -$(($k+7)) $filename | tail -1 | perl -lane 'print "$F['$((-5+$j))']"' | sed 's/,//g'`
" 
  else
   value[$(($k*$clusters+$j))]="`head -13 $filename | tail -1 | perl -lane 'print "$F['$((-4+$j))']"' | sed 's/,//g'`" 
  fi
 done
done
echo "----------------------------------------------------------------------------------------"
echo
echo "####################################### PIE CHARTS ####################################"
echo
echo "----------------------------------------------------------------------------------------"
echo
echo "&nbsp;"
for ((k=0; k<$categories; k++))
do
        echo "{chart:title=${title_string[$k]} over the last `date -d"last month" "+%-m"` months|width=450}" 
        echo -n "|| CLUSTER ||"
        for ((j=0; j<=3; j++))
        do
                echo -n " ${cluster[$j]} ||"
        done
        echo 
        echo -n "|| category |"
        for ((j=0; j<$clusters; j++))
        do
  echo -n " ${value[$(($k*$clusters+$j))]} |"
        done
        echo -n "|"
        echo
        echo "{chart}"
        echo "&nbsp;"
        echo
done
echo "----------------------------------------------------------------------------------------"
echo


[manchu@hpc-metrics ~]$ 

Output I get when I run the script

Here is the output I get when I run this script:
[manchu@hpc-metrics ~]$ ./metrics.sh 
To retrieve a monthly report for the previous month.
Getting HPC Metrics Statistics.
For the jobs ended on and after 2011-06-01 before 2011-07-01.
Getting the total counts from usq...
Getting the total counts from bowery...
Getting the total counts from cardiac...
Getting the total counts from cuda...
Getting the total counts from usq...
Getting the total counts from bowery...
Getting the total counts from cardiac...
Getting the total counts from cuda...

**************** Starting the sum task 1: grouped by ALL *************
Getting the total sum from usq...
Getting the total sum from bowery...
Getting the total sum from cardiac...
Getting the total sum from cuda...
----------------------
Summary of this period, sorted by ALL
For jobs ended on and after 2011-06-01 and before 2011-07-01
                               Name            usq         bowery        cardiac           cuda            All
                        Jobs number         72,671          5,909         32,444            107        111,131
                        User number             76             36              9              1             94
                        CPU time(h)        445,860        309,076        617,893              0      1,372,829
                       Wall time(h)      4,279,233        115,571        793,340             83      5,188,227
                       Used time(h)        381,261         39,053        177,488              3        597,805
                Requested CPU cores        108,591        115,402        183,247            830        408,070
                Avg. used CPU cores           1.17           7.91           3.48           0.00
Where,
Avg. used CPU cores: the average CPU resource consumed by a job, which is "CPU time/Used time"


The results were also stored in the file of hpc_usage_2011-06-01_2011-06-30.txt


----------------------------------------------------------------------------------------

###################################### EXCEL VALUES ###################################

----------------------------------------------------------------------------------------

| *Jun 2011* | 72,671 | 76 | 445,860 | 4,279,233 | 381,261 | 108,591 | 1.17 |
| *Jun 2011* | 5,909 | 36 | 309,076 | 115,571 | 39,053 | 115,402 | 7.91 |
| *Jun 2011* | 32,444 | 9 | 617,893 | 793,340 | 177,488 | 183,247 | 3.48 |
| *Jun 2011* | 107 | 1 | 0 | 83 | 3 | 830 | 0.00 |

----------------------------------------------------------------------------------------

####################################### BAR CHARTS ####################################

----------------------------------------------------------------------------------------

&nbsp;
{chart:title=Number of Jobs|type=bar|width=900}
|| CLUSTER || January || February || March || April || May || June ||
|| USQ | 205227 | 341853 | 433496 | 494724 | 323675 | 72671 ||
|| BOWERY | 5571 | 2722 | 3445 | 3670 | 3800 | 5909 ||
|| CARDIAC | 42578 | 98160 | 27774 | 32225 | 53133 | 32444 ||
|| CUDA | 29 | 1 | 114 | 218 | 131 | 107 ||
{chart}
&nbsp;

{chart:title=Number of Users|type=bar|width=900}
|| CLUSTER || January || February || March || April || May || June ||
|| USQ | 70 | 87 | 96 | 89 | 85 | 76 ||
|| BOWERY | 27 | 32 | 33 | 35 | 38 | 36 ||
|| CARDIAC | 10 | 9 | 10 | 7 | 12 | 9 ||
|| CUDA | 4 | 1 | 4 | 6 | 3 | 1 ||
{chart}
&nbsp;

{chart:title=CPU Time in Hours|type=bar|width=900}
|| CLUSTER || January || February || March || April || May || June ||
|| USQ | 380033 | 291235 | 356897 | 343902 | 375666 | 445860 ||
|| BOWERY | 572622 | 272514 | 331905 | 355627 | 301544 | 309076 ||
|| CARDIAC | 716065 | 359153 | 329973 | 723314 | 279251 | 617893 ||
|| CUDA | 1 | 0 | 1 | 251 | 54 | 0 ||
{chart}
&nbsp;

{chart:title=Walltime in Hours|type=bar|width=900}
|| CLUSTER || January || February || March || April || May || June ||
|| USQ | 5245803 | 13446775 | 20903317 | 20559816 | 40612407 | 4279233 ||
|| BOWERY | 80722 | 43649 | 60817 | 63988 | 67950 | 115571 ||
|| CARDIAC | 284755 | 494757 | 320250 | 78273 | 1067320 | 793340 ||
|| CUDA | 116 | 4 | 224 | 996 | 158 | 83 ||
{chart}
&nbsp;

{chart:title=Used Time in Hours|type=bar|width=900}
|| CLUSTER || January || February || March || April || May || June ||
|| USQ | 291717 | 214256 | 282014 | 295398 | 312894 | 381261 ||
|| BOWERY | 30980 | 21816 | 29132 | 38124 | 36421 | 39053 ||
|| CARDIAC | 153014 | 150655 | 117527 | 23588 | 256442 | 177488 ||
|| CUDA | 71 | 0 | 21 | 300 | 91 | 3 ||
{chart}
&nbsp;

{chart:title=Total Requested CPU Cores|type=bar|width=900}
|| CLUSTER || January || February || March || April || May || June ||
|| USQ | 428382 | 780907 | 838015 | 1357449 | 359100 | 108591 ||
|| BOWERY | 175895 | 103060 | 97843 | 107121 | 96763 | 115402 ||
|| CARDIAC | 151891 | 277135 | 66307 | 87260 | 91421 | 183247 ||
|| CUDA | 92 | 4 | 307 | 1623 | 1019 | 830 ||
{chart}
&nbsp;

{chart:title=Avg. CPU Cores Used Per Job|type=bar|width=900}
|| CLUSTER || January || February || March || April || May || June ||
|| USQ | 1.30 | 1.36 | 1.27 | 1.16 | 1.20 | 1.17 ||
|| BOWERY | 18.48 | 12.49 | 11.39 | 9.33 | 8.28 | 7.91 ||
|| CARDIAC | 4.68 | 2.38 | 2.81 | 30.66 | 1.09 | 3.48 ||
|| CUDA | 0.01 | 0.02 | 0.04 | 0.84 | 0.59 | 0.00 ||
{chart}
&nbsp;

----------------------------------------------------------------------------------------

To analyze the hpc-metrics database
Please input the start date, such as 2010-11-01: Please input the day after the end date, such as 2010-12-01: Getting HPC Metrics Statistics.
For the jobs ended on and after 2011-01-01 before 2011-07-01.
Getting the total counts from usq...
Getting the total counts from bowery...
Getting the total counts from cardiac...
Getting the total counts from cuda...
Getting the total counts from usq...
Getting the total counts from bowery...
Getting the total counts from cardiac...
Getting the total counts from cuda...

**************** Starting the sum task 1: grouped by ALL *************
Getting the total sum from usq...
Getting the total sum from bowery...
Getting the total sum from cardiac...
Getting the total sum from cuda...
----------------------
Summary of this period, sorted by ALL
For jobs ended on and after 2011-01-01 and before 2011-07-01
                               Name            usq         bowery        cardiac           cuda            All
                        Jobs number      1,871,646         25,117        286,314            600      2,183,677
                        User number            153             66             22             11            172
                        CPU time(h)      2,193,594      2,143,289      3,025,648            307      7,362,837
                       Wall time(h)    105,047,351        432,696      3,038,695          1,580    108,520,322
                       Used time(h)      1,777,541        195,527        878,715            486      2,852,269
                Requested CPU cores      3,872,444        696,084        857,261          3,875      5,429,664
                Avg. used CPU cores           1.23          10.96           3.44           0.63
Where,
Avg. used CPU cores: the average CPU resource consumed by a job, which is "CPU time/Used time"


The results were also stored in the file of hpc_usage_2011-01-01_2011-06-30.txt


----------------------------------------------------------------------------------------

####################################### PIE CHARTS ####################################

----------------------------------------------------------------------------------------

&nbsp;
{chart:title=Number of Jobs over the last 6 months|width=450}
|| CLUSTER || USQ || BOWERY || CARDIAC || CUDA ||
|| category | 1871646 | 25117 | 286314 | 600 ||
{chart}
&nbsp;

{chart:title=Number of Users over the last 6 months|width=450}
|| CLUSTER || USQ || BOWERY || CARDIAC || CUDA ||
|| category | 153 | 66 | 22 | 11 ||
{chart}
&nbsp;

{chart:title=CPU Time in Hours over the last 6 months|width=450}
|| CLUSTER || USQ || BOWERY || CARDIAC || CUDA ||
|| category | 2193594 | 2143289 | 3025648 | 307 ||
{chart}
&nbsp;

{chart:title=Walltime in Hours over the last 6 months|width=450}
|| CLUSTER || USQ || BOWERY || CARDIAC || CUDA ||
|| category | 105047351 | 432696 | 3038695 | 1580 ||
{chart}
&nbsp;

{chart:title=Used Time in Hours over the last 6 months|width=450}
|| CLUSTER || USQ || BOWERY || CARDIAC || CUDA ||
|| category | 1777541 | 195527 | 878715 | 486 ||
{chart}
&nbsp;

{chart:title=Total Requested CPU Cores over the last 6 months|width=450}
|| CLUSTER || USQ || BOWERY || CARDIAC || CUDA ||
|| category | 3872444 | 696084 | 857261 | 3875 ||
{chart}
&nbsp;

{chart:title=Avg. CPU Cores Used Per Job over the last 6 months|width=450}
|| CLUSTER || USQ || BOWERY || CARDIAC || CUDA ||
|| category | 1.23 | 10.96 | 3.44 | 0.63 ||
{chart}
&nbsp;

----------------------------------------------------------------------------------------

[manchu@hpc-metrics ~]$

Saturday, July 9, 2011

Berkely Lab Checkpoint/Restart (BLCR) Installation and Run Procedure

What is BLCR?

BLCR (Berkeley Lab Checkpoint/Restart) allows programs running on Linux to be "checkpointed" (written entirely to a file), and then later "restarted". BLCR can be found at http://ftg.lbl.gov/checkpoint.

Web Links

https://ftg.lbl.gov/projects/CheckpointRestart/
https://ftg.lbl.gov/CheckpointRestart/CheckpointDownloads.shtml
https://ftg.lbl.gov/CheckpointRestart/downloads/blcr-0.8.2.tar.gz
https://ftg.lbl.gov/CheckpointRestart/downloads/blcr-0.8.2-1.src.rpm
https://upc-bugs.lbl.gov//blcr/doc/html/BLCR_Admin_Guide.html
https://upc-bugs.lbl.gov//blcr/doc/html/BLCR_Users_Guide.html
https://upc-bugs.lbl.gov//blcr/doc/html/FAQ.html

Installation Procedure

# cd Desktop
# wget https://ftg.lbl.gov/CheckpointRestart/downloads/blcr-0.8.2.tar.gz
# tar xzvf blcr-0.8.2.tar.gz
# cd blcr-0.8.2
# mkdir builddir
# cd builddir/
# ../configure --with-linux=/usr/src/kernels/2.6.18-128.el5-x86_64/ --with-system-map=/boot/System.map-2.6.18-128.1.6.el5_lustre.1.8.0.1smp --with-vmlinux=/boot/vmlinuz-2.6.18-128.1.6.el5_lustre.1.8.0.1smp --enable-multilib --enable-testsuite --enable-init-script

*******************************************************************
***** WARNING WARNING WARNING WARNING WARNING WARNING WARNING *****
*******************************************************************
* The kernel source does not match currently the running kernel.  *
* Compilation will produce modules unsuitable for the currently   *
* running kernel, which may not be what you intended.             *
*******************************************************************
***** WARNING WARNING WARNING WARNING WARNING WARNING WARNING *****
*******************************************************************
======================================================================
Please review the following configuration information:
  Kernel source directory = /usr/src/kernels/2.6.18-128.el5-x86_64/
  Kernel build directory = /usr/src/kernels/2.6.18-128.el5-x86_64/
  Kernel symbol table = /boot/System.map-2.6.18-128.1.6.el5_lustre.1.8.0.1smp/boot/vmlinuz-2.6.18-128.1.6.el5_lustre.1.8.0.1smp
  Kernel version probed from kernel build = 2.6.18-128.el5
  Kernel running currently = 2.6.18-128.1.6.el5_lustre.1.8.0.1smp
======================================================================

Warning: Proceeding with this warning would lead to the installation failure.

This can be fixed with the following procedure. BLCR needs to be able to examine a linux kernel source tree that has been configured, and this configuration must match the kernel that you will run BLCR against. If you do not have a configured linux kernel source tree, you may be able to create one fairly easily. Many distributions provide a 'config' file that is all you need to easily produce a configured kernel source tree.

# uname -r
2.6.18-128.1.6.el5_lustre.1.8.0.1smp
 
# cp -a /usr/src/linux-2.6.18-128.1.6.el5_lustre.1.8.0.1/ /tmp/
# cd /tmp/linux-2.6.18-128.1.6.el5_lustre.1.8.0.1/
# cp configs/kernel-2.6.18-2.6-rhel5-x86_64-smp.config .config
# make prepare-all scripts
# cd /state/partition1/blcr-0.8.2/builddir/
# ../configure --with-linux=/tmp/linux-2.6.18-128.1.6.el5_lustre.1.8.0.1/ --with-system-map=/boot/System.map-2.6.18-128.1.6.el5_lustre.1.8.0.1smp --with-vmlinux=/boot/vmlinuz-2.6.18-128.1.6.el5_lustre.1.8.0.1smp --enable-multilib --enable-testsuite --enable-init-script

*******************************************************************
***** WARNING WARNING WARNING WARNING WARNING WARNING WARNING *****
*******************************************************************
* The kernel source does not match currently the running kernel.  *
* Compilation will produce modules unsuitable for the currently   *
* running kernel, which may not be what you intended.             *
*******************************************************************
***** WARNING WARNING WARNING WARNING WARNING WARNING WARNING *****
*******************************************************************
======================================================================
Please review the following configuration information:
  Kernel source directory = /tmp/linux-2.6.18-128.1.6.el5_lustre.1.8.0.1/
  Kernel build directory = /tmp/linux-2.6.18-128.1.6.el5_lustre.1.8.0.1/
  Kernel symbol table = /boot/System.map-2.6.18-128.1.6.el5_lustre.1.8.0.1smp/boot/vmlinuz-2.6.18-128.1.6.el5_lustre.1.8.0.1smp
  Kernel version probed from kernel build = 2.6.18-128.1.6.el5_lustre.1.8.0.1custom
  Kernel running currently = 2.6.18-128.1.6.el5_lustre.1.8.0.1smp
======================================================================

Warning: Kernel version probed from kernel build = 2.6.18-128.1.6.el5_lustre.1.8.0.1custom doesn't match with Kernel running currently = 2.6.18-128.1.6.el5_lustre.1.8.0.1smp. Proceeding with this warning would lead to installation failure.

This can be fixed with the following procedure. We need to change the Kernel version in the Makefile in the Linux kernel source directory copied to /tmp.
# cd /tmp/linux-2.6.18-128.1.6.el5_lustre.1.8.0.1/
# vi Makefile

Handy Hint: Change the line "EXTRAVERSION = -128.1.6.el5_lustre.1.8.0.1custom" to "EXTRAVERSION = -128.1.6.el5_lustre.1.8.0.1smp". We just have to replace tag "custom" with "smp".

# cp configs/kernel-2.6.18-2.6-rhel5-x86_64-smp.config .config
# make prepare-all scripts
# cd /state/partition1/blcr-0.8.2/builddir/

Configuring BLCR

# ../configure --with-linux=/tmp/linux-2.6.18-128.1.6.el5_lustre.1.8.0.1/ --with-system-map=/boot/System.map-2.6.18-128.1.6.el5_lustre.1.8.0.1smp --with-vmlinux=/boot/vmlinuz-2.6.18-128.1.6.el5_lustre.1.8.0.1smp --enable-multilib --enable-testsuite --enable-init-script
 
======================================================================
Please review the following configuration information:
  Kernel source directory = /tmp/linux-2.6.18-128.1.6.el5_lustre.1.8.0.1/
  Kernel build directory = /tmp/linux-2.6.18-128.1.6.el5_lustre.1.8.0.1/
  Kernel symbol table = /boot/System.map-2.6.18-128.1.6.el5_lustre.1.8.0.1smp/boot/vmlinuz-2.6.18-128.1.6.el5_lustre.1.8.0.1smp
  Kernel version probed from kernel build = 2.6.18-128.1.6.el5_lustre.1.8.0.1smp
  Kernel running currently = 2.6.18-128.1.6.el5_lustre.1.8.0.1smp
====================================================================== 

Compiling BLCR

# make

Testing the Build

# make insmod check
 
======================
All 58 tests passed
(2 tests were not run)
======================
Make sure blcr modules are loaded by grepping for blcr in the lsmod output. There should be two modules "blcr" and "blcr_imports".
# lsmod | grep blcr
blcr                  139268  0
blcr_imports           46208  1 blcr

Note: "make insmod check" loads BLCR kernel modules before doing check. Hence, loading them again with insmod would fail and there is no need for it.
If only "make check" is used in building the package then BLCR kernel modules need to be loaded separately. These module need to be loaded in order as shown below.

# insmod /usr/local/lib64/blcr/2.6.18-128.1.6.el5_lustre.1.8.0.1smp/blcr_imports.ko
# insmod /usr/local/lib64/blcr/2.6.18-128.1.6.el5_lustre.1.8.0.1smp/blcr.ko

Installing BLCR

# make install

Useful Information: By default BLCR will install into /usr/local.

Loading the kernel modules by default at boot time

Useful Information: Adding '--enable-init-script' to the configure flags installs blcr init script in /usr/local/etc/init.d/blcr. We need to copy this script to /etc/init.d/ and then modify the script, chkconfig to make it work as boot up script (service).

# vi /etc/init.d/blcr  
# chkconfig --add blcr
Follow the below procedure to modify the script and then save it.
Copy the blcr kernel modules from /usr/local/lib64/blcr/`uname -r`/ to /lib/modules/`uname -r`/kernel/drivers/misc/
# cp /usr/local/lib64/blcr/`uname -r`/*.ko /lib/modules/`uname -r`/kernel/drivers/misc/
# depmod -a
# vi /etc/init.d/blcr

Modify line 10:  module_dir=
                             to
                 module_dir=/usr/local/lib64/blcr/2.6.18-128.1.6.el5_lustre.1.8.0.1smp

Note: Next to module_dir= add the path of the directory containing blcr kernel modules.

Modify line 38:  modprobe $1 || (do_checkmod $1 || insmod ${module_dir}/${1}.ko)
                             to
                 modprobe $1 > /dev/null 2>&1 || (do_checkmod $1 || insmod ${module_dir}/${1}.ko)

Modify line 43:  modprobe -r $1 || (do_checkmod $1 && rmmod $1)
                             to
                 modprobe -r $1 > /dev/null 2>&1 || (do_checkmod $1 && rmmod $1)

Modify line 88:  if [ "x$rc1$rc2" != "x111" ] ; then
                             to
                 if [ "x$rc1$rc2" != "x11" ] ; then

Note: " > /dev/null 2>&1" next to modprobe is not necessary at all. Even when modprobe doesn't work, insmod works to load blcr modules. But as it tries to use the command modprobe first it gives "FATAL: Module blcr_imports not found" and "FATAL: Module blcr not found" error messages for the command modprobe. Then it runs insmod command successfully to load blcr modules with ok message. Adding " > /dev/null 2>&1" next to modprobe takes off this confusion.

If you don't want to copy the blcr kernel modules to /lib/modules/`uname -r`/kernel/drivers/misc/, then you can also do this as shown below.
# vi /etc/init.d/blcr

Modify line 10:  module_dir=
                             to
                 module_dir=/usr/local/lib64/blcr/2.6.18-128.1.6.el5_lustre.1.8.0.1smp

Note: Next to module_dir= add the path of the directory containing blcr kernel modules.

Modify line 38:  modprobe $1 || (do_checkmod $1 || insmod ${module_dir}/${1}.ko)
                             to
                 modprobe $1 > /dev/null 2>&1 || (do_checkmod $1 || insmod ${module_dir}/${1}.ko)

Modify line 43:  modprobe -r $1 || (do_checkmod $1 && rmmod $1)
                             to
                 modprobe -r $1 > /dev/null 2>&1 || (do_checkmod $1 && rmmod $1)

Modify line 88:  if [ "x$rc1$rc2" != "x111" ] ; then
                             to
                 if [ "x$rc1$rc2" != "x11" ] ; then

Note: " > /dev/null 2>&1" next to modprobe is not necessary at all. Even when modprobe doesn't work, insmod works to load blcr modules. But as it tries to use the command modprobe first it gives "FATAL: Module blcr_imports not found" and "FATAL: Module blcr not found" error messages for the command modprobe. Then it runs insmod command successfully to load blcr modules with ok message. Adding " > /dev/null 2>&1" next to modprobe takes off this confusion.

Note: There is no need to modify lines 38 and 43 as modules are loaded through insmod command as long as you don't care about error messages from command modprobe. No matter what, I believe we need to modify line 88 though.

# chkconfig --add blcr
# chkconfig --list blcr
blcr               0:off    1:off    2:off    3:on    4:on    5:on    6:off
# service blcr status
BLCR subsytem is active
# lsmod | grep blcr
blcr                  139268  0
blcr_imports           46208  1 blcr
# service blcr stop
Unloading BLCR:                                            [  OK  ]
# lsmod | grep blcr
# service blcr start
Loading BLCR:                                              [  OK  ]
# lsmod | grep blcr
blcr                  139268  0
blcr_imports           46208  1 blcr
# service blcr reload
Unloading BLCR:                                            [  OK  ]
Loading BLCR:                                              [  OK  ]
# lsmod | grep blcr
blcr                  139268  0
blcr_imports           46208  1 blcr
#
Useful Information
1) If you haven't used --enable-init-script configure option a template init script, etc/blcr.rc is provided in the BLCR source directory, blcr-0.8.2/etc/. Modify this as shown above to suit your system.

    # cp /state/partition1/blcr-0.8.2/etc/blcr.rc /etc/init.d/blcr
    # chmod 755 blcr
    # vi /etc/init.d/blcr

 2) Line 10 should be like this: module_dir=/usr/local/lib64/blcr/2.6.18-128.1.6.el5_lustre.1.8.0.1smp. Replace the text next to "module_dir=" with the path of blcr kernel modules. In my case it is "/usr/local/lib64/blcr/2.6.18-128.1.6.el5_lustre.1.8.0.1smp".
 3) Modify all other lines just like above.

Updating ld.so.cache

Nearly all Linux distributions use a caching mechanism for resolving dynamic library dependencies. If you have installed BLCR's shared library in a directory that is cached by the mechanism, then you will need to update this cache. To do so, run the ldconfig command as root; no command-line arguments are needed.

Handy Hint: Add the line "/usr/local/lib64" to the file "/etc/ld.so.conf" if configured with --enable-multilib or create a file under /etc/ld.so.conf.d/ with the line "/usr/local/lib64" or /usr/local/lib if configured without --enable-multilib.

# vi /etc/ld.so.conf
# more /etc/ld.so.conf
/lib64
/usr/lib64
/usr/kerberos/lib64
/opt/nmi/lib
/usr/lib64/qt-3.1/lib
/usr/lib64/mysql
/usr/X11R6/lib64
/usr/local/lib64
# ldconfig

Note: If configured without --enable-multilib replace the line /usr/local/lib64 with /usr/local/lib.

Note: If configured with --prefix= or --libdir= options that cause BLCR's shared library (libcr.so) to be installed in other than /lib or /usr/lib or any directory listed in /etc/ld.so.conf or any directory listed in a file under /etc/ld.so.conf.d/ then there is no need to run the ldconfig command. Although, it should always be safe to run the ldconfig command.

Note: Note that if you passed no --prefix= or --libdir= options to BLCR's configure script, then you should check /etc/ld.so.conf and /etc/ld.so.conf.d/ for /usr/local/lib (the default location) to determine if you actually need to run the ldconfig command.

Note: If passed --prefix= or --libdir= options to BLCR's configure script that cause BLCR's shared library (libcr.so) to be installed in other than /lib or /usr/lib or any directory listed in /etc/ld.so.conf or any directory listed in a file under /etc/ld.so.conf.d/, then you need to create a file like blcr.sh in /etc/profile.d/ with permissions 755 (-rwxr-xr-x).

# cd /etc/profile.d/
# more blcr.sh
#!/bin/sh
export LD_LIBRARY_PATH=/usr/local/lib/:/usr/local/lib64/
# chmod 755 blcr.sh
# source /etc/profile.d/blcr.sh
# echo $LD_LIBRARY_PATH
/usr/local/lib/:/usr/local/lib64/

Building a binary RPM from source RPMS

We can build RPMS from a source RPM (with a .src.rpm suffix) rather than the .tar.gz version of the BLCR distribution. Source RPMs are available on BLCR website. These source RPMs are configured to build for the running kernel, with --prefix=/usr and to configure with --enable-multilib on 64-bit platforms. Built RPMs will be placed in a subdirectory of /usr/src/redhat/RPMS.

Warning: To build binary RPMs from the source RPM, we need to do little bit tweaking on our systems as kernel version probed from kernel build = 2.6.18-128.1.6.el5_lustre.1.8.0.1custom doesn't match with Kernel running currently = 2.6.18-128.1.6.el5_lustre.1.8.0.1smp. Proceeding with this mismatch would lead to installation failure.

Handy Hint: Trick is to create links to vmlinuz, system map and kernel build in their respective directories with the tag custom in place of original tag smp.

Follow this procedure to build RPMS.
# cd /lib/modules/
# ln -s 2.6.18-128.1.6.el5_lustre.1.8.0.1smp 2.6.18-128.1.6.el5_lustre.1.8.0.1custom
# cd /boot/
# ln -s System.map-2.6.18-128.1.6.el5_lustre.1.8.0.1smp System.map-2.6.18-128.1.6.el5_lustre.1.8.0.1custom
# ln -s vmlinuz-2.6.18-128.1.6.el5_lustre.1.8.0.1smp vmlinuz-2.6.18-128.1.6.el5_lustre.1.8.0.1custom
# rpmbuild --rebuild --define 'kernel_ver 2.6.18-128.1.6.el5_lustre.1.8.0.1custom' blcr-0.8.2-1.src.rpm --target `uname -p`

Note: If installed from RPMS the path to executables is /usr/bin and to libraries it is /usr/lib64 (64 bit) as well as /usr/lib (32 bit). Most probably, /usr/lib64 would already be there in the file /etc/ld.so.conf. If it is not there make sure to add it as a separate line to this file. No need to add /usr/lib as this is always there in the system path and more over we just need 64 bit libraries as our machines are 64 bit.

Running BLCR

$ vi blcr.c
$ more blcr.c
#include "stdio.h"
int main( int argc, char *argv[] )
{ 
int i;
             for (i=0; i<100; i++)
             { 
                            printf("i = %d\n", i);
                            fflush(stdout);
                            sleep(1);
              } 
} 
$ gcc blcr.c -o blcr
$ cr_run ./blcr > output.txt &
[1] 17830
$ tail -f output.txt       # 'more output.txt' to see different output before checkpointing and after restart.
$ ps | grep blcr | grep -v grep
17830 pts/0 00:00:00 blcr
$ cr_checkpoint --term 17830       # creates a contex.pid file and kills the process
[1]+ Terminated       cr_run ./blcr >output.txt
$ ls context.*
context.17830
$ cr_restart context.17830 &       # viola ! start from where it was checkpointed

Friday, June 24, 2011

PBS Script Generator: Interdependent dropdown/select menus in Javascript

Recently, I made my foray onto Javascript. I wanted to write a script in javascript to generate a pbs script generator for users based on their selection criteria for running batch jobs on compute nodes on clusters. To make it possible I needed to understand how to create interdependent drop-down/select menus. They contain options for selecting number of nodes, memory per each node, processor per node, and walltime, etc. Overall, I loved learning little bit of javascript. Hopefully, I should make more progress and use it for making some good stuff in the future.

This code contains small styling in css, major block of javascript and a block of HTML. I'll explain the code in my next post. By the way, if you scroll all the way down on this page you can see this PBS Script Generator in action as a widget.

For NetID: Start with an alphabet and then end with some number. Eg. xx2000
Job Name: Start with an alphabet. You can end either with an alphabet or number. It can contain either dash or underscore in the middle. Eg. pbs_job

<style type="text/css">
  .div_style
  {
    margin-left:auto;
    margin-right:auto;
    margin-top:1em;
    text-align:left;
    width:290px;
  }
  table {table-collapse:collapse; border-spacing:0; width:450px; margin:auto; margin-top:20px;}
  td {border:2px groove black;padding:7px;background-color:#ccffcc;font-size:small;font-style:italic;}
  th {border:2px groove black; padding:7px; background-color:#ffffcc; text-align:center;}
</style>
<script type="text/javascript">
  // Table data -- an array of objects
  var jsData = new Array();
 
  function setStyle(x) {
   document.getElementById(x).style.background = "yellow";
   document.getElementById(x).select();
   if (document.getElementById(x).value.split(":")[0] == "SRE NetID" 
|| document.getElementById(x).value.split(":")[0] == "Job Name") {
    document.getElementById(x).value = document.getElementById(x).value.split(" ")[2];
    document.getElementById(x).select();
   }
  }
 
  function grab_netid() {
   netid = document.getElementById('netid_input').value;
   if (netid.match(/^[a-z]{1,9}[0-9]{1,4}$/) != netid) {
    alert("Invalid SRE NetID!");
    return false;
   }
   document.getElementById('netid_input').style.color = "black";
   document.getElementById('netid_input').style.fontWeight = "bold";
   document.getElementById('netid_input').value = "SRE NetID: " + netid;
  }
 
  function grab_jobname() {
   jobname = document.getElementById('jobname_input').value;
   //jobname=document.forms["myForm"]["jobname"].value;
   if (jobname.match(/^[a-zA-Z]{1}[a-zA-Z0-9-_.]{0,13}[a-zA-Z0-9]{1}$/) != jobname) {
    alert("Invalid job name! The name specified may be up to and including" + "\n" 
+ "    15 characters in length. First and last characters should be" + "\n" 
+ "         alphabetic and others can be alphanumeric,.,- and _.");
    return false;
   }
   document.getElementById('jobname_input').style.color = "black";
   document.getElementById('jobname_input').style.fontWeight = "bold";
   document.getElementById('jobname_input').value = "Job Name: " + jobname;
  }
 
  function select_shell() {
   if (document.getElementById('sh_shell').checked == true) {
    pbs_shell_top = "#!/bin/bash";
    pbs_shell_bottom = "#PBS -S /bin/bash";
    pbs_module = "source /etc/profile.d/env-modules.sh"
   } else { // if (document.getElementById('csh_shell').checked == true)
    pbs_shell_top = "#!/bin/csh -f";
    pbs_shell_bottom = "#PBS -S /bin/tcsh";
    pbs_module = "source /etc/profile.d/env-modules.csh"
   }
  }
 
  function select_email() {
   pbs_email = "<br>" + "#PBS -M " + netid + "@SRE.edu" 
+ "<br>" + "#PBS -m ";
   var selectedEmail = document.forms["myForm"].elements["email"];
   for (var i = 0; i < selectedEmail.length; i++) {
    if (selectedEmail[i].checked && i == 0) pbs_email += "b";
    else if (selectedEmail[i].checked && i == 1) pbs_email += "e";
    else if (selectedEmail[i].checked && i == 2) pbs_email += "a";
   }
   if (pbs_email == "<br>" + "#PBS -M " + netid + "@SRE.edu" 
+ "<br>" + "#PBS -m ") 
       pbs_email = "";
  }
 
  function loadSelectElement(selObjId, options) {
   var selObj = document.getElementById(selObjId);
   selObj.style.width = "290px";
 
   // clear the target select element apart from the "select your..." option
   selObj.options.length = 1;
 
   // copy options from array of [value, pair] arrays to select box
   // IE doesn't work if you use the DOM-standard method, however...
   if (typeof(window.clientInformation) != 'undefined') {
    // IE doesn't take the second "before" parameter...
    for (var loop = 0; loop < options.length; loop++)
        selObj.add(new Option(options[loop][1], options[loop][0]));
   } else {
    for (var loop = 0; loop < options.length; loop++)
        selObj.add(new Option(options[loop][1], options[loop][0]), null);
   }
  }
 
  function madeSelection(selObj) {
   if (selObj.name != 'selectedshell' && selObj.name != 'email') {
    var selectedValue = selObj.options[selObj.selectedIndex].value;
    var selectedText = selObj.options[selObj.selectedIndex].text;
    if (selectedValue == '--') return;
   }
   select_shell();
   if (selObj.name != 'selectedshell') {
    netid = document.getElementById('netid_input').value;
 
    if (netid.split(":")[0] == "SRE NetID")
        netid = netid.split(" ")[2];
 
    if (netid.match(/^[a-z]{1,9}[0-9]{1,4}$/) != netid) {
     alert("Invalid SRE NetID!");
     return false;
    }
    jobname = document.getElementById('jobname_input').value;
 
    if (jobname.split(":")[0] == "Job Name")
        jobname = jobname.split(" ")[2];
    if (jobname.match(/^[a-zA-Z]{1}[a-zA-Z0-9-_.]{0,13}[a-zA-Z0-9]{1}$/) != jobname) {
     alert("Invalid job name! The name specified may be up to and including" + "\n" 
+ "    15 characters in length. First and last characters should be" + "\n" 
+ "         alphabetic and others can be alphanumeric,.,- and _.");
     return false;
    }
   }
 
   select_email();
 
   if (selObj.name == 'select01') {
    selObj.onclick = toggle_display(document.getElementById('select03Container'));
    selObj.onclick = toggle_display(document.getElementById('select04Container'));
    selObj.onclick = toggle_display(document.getElementById('select05Container'));
    toggle_display(document.getElementById('pbsscript'));
    toggle_display(document.getElementById('pbs_table'));
    document.getElementById('select02Container').style.display = 'block';
    document.getElementById('select02').options[0].text = 'Select Memory';
    selectedJobType = selectedValue;
 
    switch (selectedValue) {
    case 'type_parallel':
     loadSelectElement('select02', [
      ['type_1gb', '1 GB'],
      ['type_2gb', '2 GB'],
      ['type_3gb', '3 GB'],
      ['type_4gb', '4 GB'],
      ['type_5gb', '5 GB'],
      ['type_6gb', '6 GB'],
      ['type_7gb', '7 GB'],
      ['type_8gb', '8 GB'],
      ['type_9gb', '9 GB'],
      ['type_10gb', '10 GB'],
      ['type_11gb', '11 GB'],
      ['type_12gb', '12 GB'],
      ['type_13gb', '13 GB'],
      ['type_14gb', '14 GB'],
      ['type_15gb', '15 GB'],
      ['type_16gb', '16 GB'],
      ['type_17gb', '17 GB'],
      ['type_18gb', '18 GB'],
      ['type_19gb', '19 GB'],
      ['type_20gb', '20 GB'],
      ['type_21gb', '21 GB'],
      ['type_22gb', '22 GB'],
      ['type_23gb', '23 GB'],
      ['type_24gb', '24 GB'],
      ['type_25gb', '25 GB'],
      ['type_26gb', '26 GB'],
      ['type_27gb', '27 GB'],
      ['type_28gb', '28 GB'],
      ['type_29gb', '29 GB'],
      ['type_30gb', '30 GB'],
      ['type_31gb', '31 GB'],
      ['type_32gb', '32 GB'],
      ['type_33gb', '33 GB'],
      ['type_34gb', '34 GB'],
      ['type_35gb', '35 GB'],
      ['type_36gb', '36 GB'],
      ['type_37gb', '37 GB'],
      ['type_38gb', '38 GB'],
      ['type_39gb', '39 GB'],
      ['type_40gb', '40 GB'],
      ['type_41gb', '41 GB'],
      ['type_42gb', '42 GB'],
      ['type_43gb', '43 GB'],
      ['type_44gb', '44 GB'],
      ['type_45gb', '45 GB'],
      ['type_46gb', '46 GB'],
      ['type_47gb', '47 GB'],
      ['type_48gb', '48 GB'],
      ['type_49gb', '49 GB'],
      ['type_50gb', '50 GB'],
      ['type_51gb', '51 GB'],
      ['type_52gb', '52 GB'],
      ['type_53gb', '53 GB'],
      ['type_54gb', '54 GB'],
      ['type_55gb', '55 GB'],
      ['type_56gb', '56 GB'],
      ['type_57gb', '57 GB'],
      ['type_58gb', '58 GB'],
      ['type_59gb', '59 GB'],
      ['type_60gb', '60 GB'],
      ['type_61gb', '61 GB'],
      ['type_62gb', '62 GB'],
      ['type_63gb', '63 GB'],
      ['type_64gb', '64 GB'],
      ['type_65gb', '65 GB'],
      ['type_66gb', '66 GB'],
      ['type_67gb', '67 GB'],
      ['type_68gb', '68 GB'],
      ['type_69gb', '69 GB'],
      ['type_70gb', '70 GB'],
      ['type_71gb', '71 GB'],
      ['type_72gb', '72 GB'],
      ['type_73gb', '73 GB'],
      ['type_74gb', '74 GB'],
      ['type_75gb', '75 GB'],
      ['type_76gb', '76 GB'],
      ['type_77gb', '77 GB'],
      ['type_78gb', '78 GB'],
      ['type_79gb', '79 GB'],
      ['type_80gb', '80 GB'],
      ['type_81gb', '81 GB'],
      ['type_82gb', '82 GB'],
      ['type_83gb', '83 GB'],
      ['type_84gb', '84 GB'],
      ['type_85gb', '85 GB'],
      ['type_86gb', '86 GB'],
      ['type_87gb', '87 GB'],
      ['type_88gb', '88 GB'],
      ['type_89gb', '89 GB'],
      ['type_90gb', '90 GB']
     ]);
     return;
 
    case 'type_serial':
     loadSelectElement('select02', [
      ['type_20gb', '20 GB'],
      ['type_21gb', '21 GB'],
      ['type_22gb', '22 GB'],
      ['type_23gb', '23 GB'],
      ['type_24gb', '24 GB'],
      ['type_25gb', '25 GB'],
      ['type_26gb', '26 GB'],
      ['type_27gb', '27 GB'],
      ['type_28gb', '28 GB'],
      ['type_29gb', '29 GB'],
      ['type_30gb', '30 GB'],
      ['type_31gb', '31 GB'],
      ['type_32gb', '32 GB'],
      ['type_33gb', '33 GB'],
      ['type_34gb', '34 GB'],
      ['type_35gb', '35 GB'],
      ['type_36gb', '36 GB'],
      ['type_37gb', '37 GB'],
      ['type_38gb', '38 GB'],
      ['type_39gb', '39 GB'],
      ['type_40gb', '40 GB'],
      ['type_41gb', '41 GB'],
      ['type_42gb', '42 GB'],
      ['type_43gb', '43 GB'],
      ['type_44gb', '44 GB'],
      ['type_45gb', '45 GB'],
      ['type_46gb', '46 GB'],
      ['type_47gb', '47 GB'],
      ['type_48gb', '48 GB'],
      ['type_49gb', '49 GB'],
      ['type_50gb', '50 GB'],
      ['type_51gb', '51 GB'],
      ['type_52gb', '52 GB'],
      ['type_53gb', '53 GB'],
      ['type_54gb', '54 GB'],
      ['type_55gb', '55 GB'],
      ['type_56gb', '56 GB'],
      ['type_57gb', '57 GB'],
      ['type_58gb', '58 GB'],
      ['type_59gb', '59 GB'],
      ['type_60gb', '60 GB'],
      ['type_61gb', '61 GB'],
      ['type_62gb', '62 GB'],
      ['type_63gb', '63 GB'],
      ['type_64gb', '64 GB'],
      ['type_65gb', '65 GB'],
      ['type_66gb', '66 GB'],
      ['type_67gb', '67 GB'],
      ['type_68gb', '68 GB'],
      ['type_69gb', '69 GB'],
      ['type_70gb', '70 GB'],
      ['type_71gb', '71 GB'],
      ['type_72gb', '72 GB'],
      ['type_73gb', '73 GB'],
      ['type_74gb', '74 GB'],
      ['type_75gb', '75 GB'],
      ['type_76gb', '76 GB'],
      ['type_77gb', '77 GB'],
      ['type_78gb', '78 GB'],
      ['type_79gb', '79 GB'],
      ['type_80gb', '80 GB'],
      ['type_81gb', '81 GB'],
      ['type_82gb', '82 GB'],
      ['type_83gb', '83 GB'],
      ['type_84gb', '84 GB'],
      ['type_85gb', '85 GB'],
      ['type_86gb', '86 GB'],
      ['type_87gb', '87 GB'],
      ['type_88gb', '88 GB'],
      ['type_89gb', '89 GB'],
      ['type_90gb', '90 GB'],
      ['type_91gb', '91 GB'],
      ['type_92gb', '92 GB'],
      ['type_93gb', '93 GB'],
      ['type_94gb', '94 GB'],
      ['type_95gb', '95 GB'],
      ['type_96gb', '96 GB'],
      ['type_97gb', '97 GB'],
      ['type_98gb', '98 GB'],
      ['type_99gb', '99 GB'],
      ['type_100gb', '100 GB'],
      ['type_101gb', '101 GB'],
      ['type_102gb', '102 GB'],
      ['type_103gb', '103 GB'],
      ['type_104gb', '104 GB'],
      ['type_105gb', '105 GB'],
      ['type_106gb', '106 GB'],
      ['type_107gb', '107 GB'],
      ['type_108gb', '108 GB'],
      ['type_109gb', '109 GB'],
      ['type_110gb', '110 GB'],
      ['type_111gb', '111 GB'],
      ['type_112gb', '112 GB'],
      ['type_113gb', '113 GB'],
      ['type_114gb', '114 GB'],
      ['type_115gb', '115 GB'],
      ['type_116gb', '116 GB'],
      ['type_117gb', '117 GB'],
      ['type_118gb', '118 GB'],
      ['type_119gb', '119 GB'],
      ['type_120gb', '120 GB'],
      ['type_121gb', '121 GB'],
      ['type_122gb', '122 GB'],
      ['type_123gb', '123 GB'],
      ['type_124gb', '124 GB'],
      ['type_125gb', '125 GB'],
      ['type_126gb', '126 GB'],
      ['type_127gb', '127 GB'],
      ['type_128gb', '128 GB'],
      ['type_129gb', '129 GB'],
      ['type_130gb', '130 GB'],
      ['type_131gb', '131 GB'],
      ['type_132gb', '132 GB'],
      ['type_133gb', '133 GB'],
      ['type_134gb', '134 GB'],
      ['type_135gb', '135 GB'],
      ['type_136gb', '136 GB'],
      ['type_137gb', '137 GB'],
      ['type_138gb', '138 GB'],
      ['type_139gb', '139 GB'],
      ['type_140gb', '140 GB'],
      ['type_141gb', '141 GB'],
      ['type_142gb', '142 GB'],
      ['type_143gb', '143 GB'],
      ['type_144gb', '144 GB'],
      ['type_145gb', '145 GB'],
      ['type_146gb', '146 GB'],
      ['type_147gb', '147 GB'],
      ['type_148gb', '148 GB'],
      ['type_149gb', '149 GB'],
      ['type_150gb', '150 GB'],
      ['type_151gb', '151 GB'],
      ['type_152gb', '152 GB'],
      ['type_153gb', '153 GB'],
      ['type_154gb', '154 GB'],
      ['type_155gb', '155 GB'],
      ['type_156gb', '156 GB'],
      ['type_157gb', '157 GB'],
      ['type_158gb', '158 GB'],
      ['type_159gb', '159 GB'],
      ['type_160gb', '160 GB'],
      ['type_161gb', '161 GB'],
      ['type_162gb', '162 GB'],
      ['type_163gb', '163 GB'],
      ['type_164gb', '164 GB'],
      ['type_165gb', '165 GB'],
      ['type_166gb', '166 GB'],
      ['type_167gb', '167 GB'],
      ['type_168gb', '168 GB'],
      ['type_169gb', '169 GB'],
      ['type_170gb', '170 GB'],
      ['type_171gb', '171 GB'],
      ['type_172gb', '172 GB'],
      ['type_173gb', '173 GB'],
      ['type_174gb', '174 GB'],
      ['type_175gb', '175 GB'],
      ['type_176gb', '176 GB'],
      ['type_177gb', '177 GB'],
      ['type_178gb', '178 GB'],
      ['type_179gb', '179 GB'],
      ['type_180gb', '180 GB'],
      ['type_181gb', '181 GB'],
      ['type_182gb', '182 GB'],
      ['type_183gb', '183 GB'],
      ['type_184gb', '184 GB'],
      ['type_185gb', '185 GB'],
      ['type_186gb', '186 GB'],
      ['type_187gb', '187 GB'],
      ['type_188gb', '188 GB'],
      ['type_189gb', '189 GB'],
      ['type_190gb', '190 GB'],
      ['type_191gb', '191 GB'],
      ['type_192gb', '192 GB'],
      ['type_193gb', '193 GB'],
      ['type_194gb', '194 GB'],
      ['type_195gb', '195 GB'],
      ['type_196gb', '196 GB'],
      ['type_197gb', '197 GB'],
      ['type_198gb', '198 GB'],
      ['type_199gb', '199 GB'],
      ['type_200gb', '200 GB'],
      ['type_201gb', '201 GB'],
      ['type_202gb', '202 GB'],
      ['type_203gb', '203 GB'],
      ['type_204gb', '204 GB'],
      ['type_205gb', '205 GB'],
      ['type_206gb', '206 GB'],
      ['type_207gb', '207 GB'],
      ['type_208gb', '208 GB'],
      ['type_209gb', '209 GB'],
      ['type_210gb', '210 GB'],
      ['type_211gb', '211 GB'],
      ['type_212gb', '212 GB'],
      ['type_213gb', '213 GB'],
      ['type_214gb', '214 GB'],
      ['type_215gb', '215 GB'],
      ['type_216gb', '216 GB'],
      ['type_217gb', '217 GB'],
      ['type_218gb', '218 GB'],
      ['type_219gb', '219 GB'],
      ['type_220gb', '220 GB'],
      ['type_221gb', '221 GB'],
      ['type_222gb', '222 GB'],
      ['type_223gb', '223 GB'],
      ['type_224gb', '224 GB'],
      ['type_225gb', '225 GB'],
      ['type_226gb', '226 GB'],
      ['type_227gb', '227 GB'],
      ['type_228gb', '228 GB'],
      ['type_229gb', '229 GB'],
      ['type_230gb', '230 GB'],
      ['type_231gb', '231 GB'],
      ['type_232gb', '232 GB'],
      ['type_233gb', '233 GB'],
      ['type_234gb', '234 GB'],
      ['type_235gb', '235 GB'],
      ['type_236gb', '236 GB'],
      ['type_237gb', '237 GB'],
      ['type_238gb', '238 GB'],
      ['type_239gb', '239 GB'],
      ['type_240gb', '240 GB'],
      ['type_241gb', '241 GB'],
      ['type_242gb', '242 GB'],
      ['type_243gb', '243 GB'],
      ['type_244gb', '244 GB']
     ]);
     return;
    }
   } // select01
   if (selObj.name == 'select02') {
    selObj.onclick = toggle_display(document.getElementById('select04Container'));
    selObj.onclick = toggle_display(document.getElementById('select05Container'));
    toggle_display(document.getElementById('pbsscript'));
    toggle_display(document.getElementById('pbs_table'));
    document.getElementById('select03Container').style.display = 'block';
    document.getElementById('select03').options[0].text = 'Select No. of Nodes';
    selectedMemory = selectedText;
 
    if (selectedJobType == 'type_parallel') {
     if (selectedText.split(" ")[0] <= 22) {
      loadSelectElement('select03', [
       ['type_2nodes', '2'],
       ['type_3nodes', '3'],
       ['type_4nodes', '4'],
       ['type_5nodes', '5'],
       ['type_6nodes', '6'],
       ['type_7nodes', '7'],
       ['type_8nodes', '8'],
       ['type_9nodes', '9'],
       ['type_10nodes', '10'],
       ['type_11nodes', '11'],
       ['type_12nodes', '12'],
       ['type_13nodes', '13'],
       ['type_14nodes', '14'],
       ['type_15nodes', '15'],
       ['type_16nodes', '16'],
       ['type_17nodes', '17'],
       ['type_18nodes', '18'],
       ['type_19nodes', '19'],
       ['type_20nodes', '20'],
       ['type_21nodes', '21'],
       ['type_22nodes', '22'],
       ['type_23nodes', '23'],
       ['type_24nodes', '24'],
       ['type_25nodes', '25'],
       ['type_26nodes', '26'],
       ['type_27nodes', '27'],
       ['type_28nodes', '28'],
       ['type_29nodes', '29'],
       ['type_30nodes', '30'],
       ['type_31nodes', '31'],
       ['type_32nodes', '32'],
       ['type_33nodes', '33'],
       ['type_34nodes', '34'],
       ['type_35nodes', '35'],
       ['type_36nodes', '36'],
       ['type_37nodes', '37'],
       ['type_38nodes', '38'],
       ['type_39nodes', '39'],
       ['type_40nodes', '40'],
       ['type_41nodes', '41'],
       ['type_42nodes', '42'],
       ['type_43nodes', '43'],
       ['type_44nodes', '44'],
       ['type_45nodes', '45'],
       ['type_46nodes', '46'],
       ['type_47nodes', '47'],
       ['type_48nodes', '48'],
       ['type_49nodes', '49'],
       ['type_50nodes', '50'],
       ['type_51nodes', '51'],
       ['type_52nodes', '52'],
       ['type_53nodes', '53'],
       ['type_54nodes', '54'],
       ['type_55nodes', '55'],
       ['type_56nodes', '56'],
       ['type_57nodes', '57'],
       ['type_58nodes', '58'],
       ['type_59nodes', '59'],
       ['type_60nodes', '60'],
       ['type_61nodes', '61'],
       ['type_62nodes', '62'],
       ['type_63nodes', '63'],
       ['type_64nodes', '64'],
       ['type_65nodes', '65'],
       ['type_66nodes', '66'],
       ['type_67nodes', '67'],
       ['type_68nodes', '68'],
       ['type_69nodes', '69'],
       ['type_70nodes', '70'],
       ['type_71nodes', '71'],
       ['type_72nodes', '72']
      ]);
      return;
     } else if (selectedText.split(" ")[0] >= 23 && selectedText.split(" ")[0] <= 42) {
      loadSelectElement('select03', [
       ['type_2nodes', '2'],
       ['type_3nodes', '3'],
       ['type_4nodes', '4'],
       ['type_5nodes', '5'],
       ['type_6nodes', '6'],
       ['type_7nodes', '7'],
       ['type_8nodes', '8'],
       ['type_9nodes', '9'],
       ['type_10nodes', '10'],
       ['type_11nodes', '11'],
       ['type_12nodes', '12'],
       ['type_13nodes', '13'],
       ['type_14nodes', '14'],
       ['type_15nodes', '15'],
       ['type_16nodes', '16'],
       ['type_17nodes', '17'],
       ['type_18nodes', '18'],
       ['type_19nodes', '19'],
       ['type_20nodes', '20'],
       ['type_21nodes', '21'],
       ['type_22nodes', '22'],
       ['type_23nodes', '23'],
       ['type_24nodes', '24'],
       ['type_25nodes', '25'],
       ['type_26nodes', '26']
      ]);
      return;
     } else {
      loadSelectElement('select03', [
       ['type_2nodes', '2'],
       ['type_3nodes', '3'],
       ['type_4nodes', '4'],
       ['type_5nodes', '5'],
       ['type_6nodes', '6'],
       ['type_7nodes', '7'],
       ['type_8nodes', '8'],
       ['type_9nodes', '9'],
       ['type_10nodes', '10'],
       ['type_11nodes', '11'],
       ['type_12nodes', '12'],
       ['type_13nodes', '13'],
       ['type_14nodes', '14'],
       ['type_15nodes', '15'],
       ['type_16nodes', '16'],
       ['type_17nodes', '17']
      ]);
      return;
     }
    } else {
     document.getElementById('select03').options[0].text = 'Select No. of Processors Per Node (ppn)';
     loadSelectElement('select03', [
      ['type_1ppn', '1'],
      ['type_2ppn', '2'],
      ['type_3ppn', '3'],
      ['type_4ppn', '4'],
      ['type_5ppn', '5'],
      ['type_6ppn', '6'],
      ['type_7ppn', '7'],
      ['type_8ppn', '8'],
      ['type_9ppn', '9'],
      ['type_10ppn', '10'],
      ['type_11ppn', '11'],
      ['type_12ppn', '12'],
      ['type_13ppn', '13'],
      ['type_14ppn', '14'],
      ['type_15ppn', '15'],
      ['type_16ppn', '16']
     ]);
     return;
    }
   } // select02
   if (selObj.name == 'select03') {
    selObj.onclick = toggle_display(document.getElementById('select05Container'));
    toggle_display(document.getElementById('pbsscript'));
    toggle_display(document.getElementById('pbs_table'));
    document.getElementById('select04Container').style.display = 'block';
    document.getElementById('select04').options[0].text = 'Select Walltime (Hr)';
 
    if (selectedJobType == 'type_parallel') {
     selectedNodes = selectedText;
    } else {
     selectedPPN = selectedText;
    }
 
    if (selectedJobType == 'type_serial' 
|| (selectedJobType == 'type_parallel' && (selectedMemory.split(" ")[0] < 23 
|| selectedMemory.split(" ")[0] > 42))) {
     loadSelectElement('select04', [
      ['type_walltime1', '1:00:00'],
      ['type_walltime2', '2:00:00'],
      ['type_walltime3', '3:00:00'],
      ['type_walltime4', '4:00:00'],
      ['type_walltime5', '5:00:00'],
      ['type_walltime6', '6:00:00'],
      ['type_walltime7', '7:00:00'],
      ['type_walltime8', '8:00:00'],
      ['type_walltime9', '9:00:00'],
      ['type_walltime10', '10:00:00'],
      ['type_walltime11', '11:00:00'],
      ['type_walltime12', '12:00:00'],
      ['type_walltime13', '13:00:00'],
      ['type_walltime14', '14:00:00'],
      ['type_walltime15', '15:00:00'],
      ['type_walltime16', '16:00:00'],
      ['type_walltime17', '17:00:00'],
      ['type_walltime18', '18:00:00'],
      ['type_walltime19', '19:00:00'],
      ['type_walltime20', '20:00:00'],
      ['type_walltime21', '21:00:00'],
      ['type_walltime22', '22:00:00'],
      ['type_walltime23', '23:00:00'],
      ['type_walltime24', '24:00:00'],
      ['type_walltime25', '25:00:00'],
      ['type_walltime26', '26:00:00'],
      ['type_walltime27', '27:00:00'],
      ['type_walltime28', '28:00:00'],
      ['type_walltime29', '29:00:00'],
      ['type_walltime30', '30:00:00'],
      ['type_walltime31', '31:00:00'],
      ['type_walltime32', '32:00:00'],
      ['type_walltime33', '33:00:00'],
      ['type_walltime34', '34:00:00'],
      ['type_walltime35', '35:00:00'],
      ['type_walltime36', '36:00:00'],
      ['type_walltime37', '37:00:00'],
      ['type_walltime38', '38:00:00'],
      ['type_walltime39', '39:00:00'],
      ['type_walltime40', '40:00:00'],
      ['type_walltime41', '41:00:00'],
      ['type_walltime42', '42:00:00'],
      ['type_walltime43', '43:00:00'],
      ['type_walltime44', '44:00:00'],
      ['type_walltime45', '45:00:00'],
      ['type_walltime46', '46:00:00'],
      ['type_walltime47', '47:00:00'],
      ['type_walltime48', '48:00:00']
     ]);
     return;
    } else {
     loadSelectElement('select04', [
      ['type_walltime1', '1:00:00'],
      ['type_walltime2', '2:00:00'],
      ['type_walltime3', '3:00:00'],
      ['type_walltime4', '4:00:00'],
      ['type_walltime5', '5:00:00'],
      ['type_walltime6', '6:00:00'],
      ['type_walltime7', '7:00:00'],
      ['type_walltime8', '8:00:00'],
      ['type_walltime9', '9:00:00'],
      ['type_walltime10', '10:00:00'],
      ['type_walltime11', '11:00:00'],
      ['type_walltime12', '12:00:00']
     ]);
     return;
    }
   } // select03
   if (selObj.name == 'select04') {
    selectedWalltime = selectedText;
    toggle_display(document.getElementById('pbsscript'));
    toggle_display(document.getElementById('pbs_table'));
 
    if (selectedJobType == 'type_parallel') {
     document.getElementById('select05Container').style.display = 'block';
     document.getElementById('select05').options[0].text = 'Select No. of Processors Per Node (ppn)';
 
     if (selectedText.split(":")[0] <= 12 
|| selectedMemory.split(" ")[0] > 42) {
      loadSelectElement('select05', [
       ['type_1ppn', '1'],
       ['type_2ppn', '2'],
       ['type_3ppn', '3'],
       ['type_4ppn', '4'],
       ['type_5ppn', '5'],
       ['type_6ppn', '6'],
       ['type_7ppn', '7'],
       ['type_8ppn', '8'],
       ['type_9ppn', '9'],
       ['type_10ppn', '10'],
       ['type_11ppn', '11'],
       ['type_12ppn', '12']
      ]);
      return;
     } else {
      loadSelectElement('select05', [
       ['type_1ppn', '1'],
       ['type_2ppn', '2'],
       ['type_3ppn', '3'],
       ['type_4ppn', '4'],
       ['type_5ppn', '5'],
       ['type_6ppn', '6'],
       ['type_7ppn', '7'],
       ['type_8ppn', '8']
      ]);
      return;
     }
    }
   } //select04
   if (selObj.name == 'select05') {
    selectedPPN = selectedText;
   } //select05
   document.getElementById('pbsscript').style.display = 'none';
 
   if (selectedJobType == 'type_serial') {
    document.getElementById('pbsscript').innerHTML = pbs_shell_top + "<br><br>" 
+ "#PBS -V" + "<br>" + pbs_shell_bottom + "<br>" 
+ "#PBS -N " + jobname + "<br>" + "#PBS -l nodes=1:ppn=" + selectedPPN 
+ ",walltime=" + selectedWalltime + "<br>" + "#PBS -l mem=" 
+ selectedMemory.split(" ")[0] + "GB" + "<br>" 
+ "#PBS -q bigmem" + pbs_email + "<br>" + "#PBS -e localhost:/scratch/" 
+ netid + "/${PBS_JOBNAME}.e${PBS_JOBID}" + "<br>" 
+ "#PBS -o localhost:/scratch/" + netid + "/${PBS_JOBNAME}.o${PBS_JOBID}" 
+ "<br><br>" + pbs_module + "<br><br>" + "exit 0;";
   } else {
    document.getElementById('pbsscript').innerHTML = pbs_shell_top + "<br><br>" 
+ "#PBS -V" + "<br>" + pbs_shell_bottom + "<br>" 
+ "#PBS -N " + jobname + "<br>" + "#PBS -l nodes=" + selectedNodes 
+ ":ppn=" + selectedPPN + ",walltime=" + selectedWalltime;
    document.getElementById('pbsscript').innerHTML += "<br>" + "#PBS -l mem=" 
+ selectedMemory.split(" ")[0] + "GB";
    if (selectedMemory.split(" ")[0] <= 22) {
     if (selectedWalltime.split(":")[0] <= 12) {
      if (selectedPPN <= 8) {
       document.getElementById('pbsscript').innerHTML += "<br>" + "#PBS -q p48" 
+ pbs_email + "<br>" + "#PBS -e localhost:/scratch/" + netid 
+ "/${PBS_JOBNAME}.e${PBS_JOBID}" + "<br>" + "#PBS -o localhost:/scratch/" 
+ netid + "/${PBS_JOBNAME}.o${PBS_JOBID}" + "<br><br>" + pbs_module 
+ "<br><br>" + "exit 0;";
 
      } else {
       document.getElementById('pbsscript').innerHTML += "<br>" + "#PBS -q p12" 
+ pbs_email + "<br>" + "#PBS -e localhost:/scratch/" + netid 
+ "/${PBS_JOBNAME}.e${PBS_JOBID}" + "<br>" + "#PBS -o localhost:/scratch/" 
+ netid + "/${PBS_JOBNAME}.o${PBS_JOBID}" + "<br><br>" + pbs_module 
+ "<br><br>" + "exit 0;";
      }
     } else {
      document.getElementById('pbsscript').innerHTML += "<br>" + "#PBS -q p48" 
+ pbs_email + "<br>" + "#PBS -e localhost:/scratch/" + netid 
+ "/${PBS_JOBNAME}.e${PBS_JOBID}" + "<br>" + "#PBS -o localhost:/scratch/" 
+ netid + "/${PBS_JOBNAME}.o${PBS_JOBID}" + "<br><br>" + pbs_module 
+ "<br><br>" + "exit 0;";
     }
    } else if (selectedMemory.split(" ")[0] > 22 && selectedMemory.split(" ")[0] <= 42) {
     document.getElementById('pbsscript').innerHTML += "<br>" + "#PBS -q p12" 
+ pbs_email + "<br>" + "#PBS -e localhost:/scratch/" + netid 
+ "/${PBS_JOBNAME}.e${PBS_JOBID}" + "<br>" + "#PBS -o localhost:/scratch/" 
+ netid + "/${PBS_JOBNAME}.o${PBS_JOBID}" + "<br><br>" + pbs_module 
+ "<br><br>" + "exit 0;";
    } else {
     document.getElementById('pbsscript').innerHTML += "<br>" + "#PBS -q bigmem" 
+ pbs_email + "<br>" + "#PBS -e localhost:/scratch/" + netid 
+ "/${PBS_JOBNAME}.e${PBS_JOBID}" + "<br>" + "#PBS -o localhost:/scratch/" 
+ netid + "/${PBS_JOBNAME}.o${PBS_JOBID}" + "<br><br>" + pbs_module 
+ "<br><br>" + "exit 0;";
    }
 
   }
   var pbs_code = document.getElementById('pbsscript').innerHTML;
   jsData[0] = {
    location: pbs_code
   };
   document.getElementById('pbs_table').style.display = '';
   drawTable('matchData');
  }
 
  // Draw table from 'jsData' array of objects
  function drawTable(tbody) {
   var tr, td;
   tbody = document.getElementById(tbody);
   // remove existing rows, if any
   clearTable(tbody);
   // loop through data source
   for (var i = 0; i < jsData.length; i++) {
    tr = tbody.insertRow(tbody.rows.length);
    td = tr.insertCell(tr.cells.length);
    //td.setAttribute("align", "center");
    td.innerHTML = jsData[i].location;
   }
  }
 
  // Remove existing table rows
  function clearTable(tbody) {
   while (tbody.rows.length > 0) {
    tbody.deleteRow(0);
   }
  }
 
  function toggle_display(obj) {
   if (obj.style.display != 'none') {
    obj.style.display = 'none';
   }
   return;
  }
 </script>    
<FORM name="myForm">
  <TABLE style="width: 300px;">
    <THEAD>
      <TR>
        <TH style="font-size:120%; padding:12px;">PBS SCRIPT GENERATOR</TH>
      </TR>
    </THEAD>
  </TABLE>
  <DIV class="div_style" id="shell_container" style="margin-top:20px">
    <LABEL>Select a Shell</LABEL>
    <INPUT checked="checked" id="sh_shell" name="selectedshell" onclick="madeSelection(this)" type="radio" value="sh">
    </INPUT>
    SH/BASH
    <INPUT id="csh_shell" name="selectedshell" onclick="madeSelection(this)" type="radio" value="csh">
    </INPUT>
    TCSH/CSH </DIV>
  <DIV class="div_style" id="netid_container" style="margin-top:20px">
    <INPUT id="netid_input" name="netid" onfocus="setStyle(this.id)" style="width:217px" type="text" value="Enter your SRE NetID!">
    </INPUT>
    <INPUT onclick="grab_netid();" type="button" value="Submit">
    </INPUT>
  </DIV>
  <DIV class="div_style" id="jobname_container" style="margin-top:20px">
    <INPUT id="jobname_input" name="jobname" onfocus="setStyle(this.id)" style="width:217px" type="text" value="Enter your job name!">
    </INPUT>
    <INPUT onclick="grab_jobname();" type="button" value="Submit">
    </INPUT>
  </DIV>
  <DIV class="div_style" id="email_container" style="margin-top:20px; margin-bottom:20px;">
    <LABEL>Receive Email: </LABEL>
    <INPUT checked="checked" name="email" onclick="madeSelection(this)" type="checkbox" value="begin">
    </INPUT>
    Begin
    <INPUT checked="checked" name="email" onclick="madeSelection(this)" type="checkbox" valueSRE="end">
    </INPUT>
    End
    <INPUT checked="checked" name="email" onclick="madeSelection(this)" type="checkbox" value="abort">
    </INPUT>
    Abort </DIV>
  <DIV class="div_style" id="select01Container" style="display:block;">
    <SELECT id="select01" name="select01" onchange="madeSelection(this);" style="width:290px;">
      <OPTION value="--">Select Job Type</OPTION>
      <OPTION value="type_parallel">Parallel (No. of Nodes >= 2)</OPTION>
      <OPTION value="type_serial">Serial (No. of Nodes = 1)</OPTION>
    </SELECT>
  </DIV>
  <DIV class="div_style" id="select02Container" style="display:none;">
    <SELECT id="select02" name="select02" onchange="madeSelection(this);">
      <OPTION value="--">Select Memory</OPTION>
    </SELECT>
  </DIV>
  <DIV class="div_style" id="select03Container" style="display:none;">
    <SELECT id="select03" name="select03" onchange="madeSelection(this);">
      <OPTION value="--">Select No. of Nodes</OPTION>
    </SELECT>
  </DIV>
  <DIV class="div_style" id="select04Container" style="display:none;">
    <SELECT id="select04" name="select04" onchange="madeSelection(this);">
      <OPTION value="--">Select Processors Per Node (ppn) </OPTION>
    </SELECT>
  </DIV>
  <DIV class="div_style" id="select05Container" style="display:none;">
    <SELECT id="select05" name="select05" onchange="madeSelection(this);">
      <OPTION value="--">Select Walltime (Hr) </OPTION>
    </SELECT>
  </DIV>
  <DIV class="div_style" id="pbsscript"> </DIV>
  <TABLE id="pbs_table" style="display: none;">
    <THEAD>
      <TR>
        <TH>PBS SCRIPT</TH>
      </TR>
    </THEAD>
    <TBODY id="matchData">
    </TBODY>
  </TABLE>
</FORM>

Including mathematics on blog using LaTeX notation: MathJax

If you want to display mathematical equations on your blog you can do that using MathJax Content Delivery Network (CDN). Here is the link: MathJax.

The default math delimiters are \(\$\$...\$\$\), \\([...\)\] for displayed mathematics, and \\((...\)\\()\) for inline mathematics. What it means is you need to keep either \(\$\$\) at the beginning and end of LaTeX notation or \\([\) at the beginning and \] at the end of the same LaTeX notation to display the equation on the page. If I do this with this text, \sqrt{3x-1}+(1+x)^2:

\(\$\$\sqrt{3x-1}+(1+x)^2\$\$\)                         on the page shows up as
$$\sqrt{3x-1}+(1+x)^2$$

\\([\)\sqrt{3x-1}+(1+x)^2\]                         also shows up as
\[\sqrt{3x-1}+(1+x)^2\]

As an example of inline equation, \\((\)\sqrt{3x-1}+(1+x)^2\) shows up as an inline equation, \(\sqrt{3x-1}+(1+x)^2\).

To make it possible, you need to link MathJax by including the below lines in your design html code on your blog. After logging onto your blog, click on Design, Edit HTML and then add the lines either in the head section or before head tag. If you want to keep in side the head tag, use browser search for </head> and insert these lines right before that. Or you can simply place them right before <head>.

<script type="text/javascript"
  src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>

Finally, I'd like to say one more great feature of MathJax. If you right click on the equation on the page, you can see the LaTeX source code for the eqation, which is quite useful in case you are looking at some complicated equation on some other page which was in fact put on the page using MathJax. This way you can see the TeX code. Anyway, hope this helps someone.

Highlighting codes on your blog: Syntax Highlighter

Did you ever want to post some code on your blog and highlight it from the plain text? I did. The simple solution I found is Syntax Highlighter developed by Mr. Alex Gorbatchev. Here is the link to his webpage: Syntax Highlighter.

What you need to do is log on to your blog and click on Design, then Edit HTML. Once you see the html code on the page, just paste the code below above head tag.

<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/>
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js' type='text/javascript'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushAppleScript.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js' type='text/javascript'/>
<script language='javascript' type='text/javascript'>
 SyntaxHighlighter.config.bloggerMode = true;
 SyntaxHighlighter.all();
</script>

Now your design html code should look like below. For reference, I have grayed the pasted code out below:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html b:version='2' class='v2' expr:dir='data:blog.languageDirection' xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr'>

<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/>
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js' type='text/javascript'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushAppleScript.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js' type='text/javascript'/>
<script language='javascript' type='text/javascript'>
 SyntaxHighlighter.config.bloggerMode = true;
 SyntaxHighlighter.all();
</script>

  <head>
    <meta content='IE=EmulateIE7' http-equiv='X-UA-Compatible'/>
    <b:if cond='data:blog.isMobile'>
      <meta content='width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0' name='viewport'/>

Now it's time to post some html code on our blog. Whatever we did until now lays behind pages and helps load our posts highlighting code, for example in html. In fact, I used Syntax Highlighter to highlight above html codes. Let me show you here how I did it.

We need to use pre tag like shown below. The problem with the syntax highlighter is that all right angle brackets must be HTML escaped, eg all < must be replaced with &lt; This will ensure correct rendering of our code.

<pre class="brush:xml; toolbar:false;">&lt;link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/&gt;
&lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/&gt;
&lt;link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/&gt;
&lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js' type='text/javascript'/&gt;
&lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'/&gt; 
&lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'/&gt; 
&lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'/&gt; 
&lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js' type='text/javascript'/&gt; 
&lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'/&gt; 
&lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'/&gt; 
&lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/&gt; 
&lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/&gt;
&lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushAppleScript.js' type='text/javascript'/&gt;
&lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js' type='text/javascript'/&gt;
&lt;script language='javascript' type='text/javascript'&gt;
 SyntaxHighlighter.config.bloggerMode = true;
 SyntaxHighlighter.all();
&lt;/script&gt;
</pre>

<pre class="brush:xml; toolbar:false;  highlight:[5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22]">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;
&lt;!DOCTYPE html&gt;
&lt;html b:version='2' class='v2' expr:dir='data:blog.languageDirection' xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr'&gt;

&lt;link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/&gt;
&lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/&gt;
&lt;link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/&gt;
&lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js' type='text/javascript'/&gt;
&lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'/&gt; 
&lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'/&gt; 
&lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'/&gt; 
&lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js' type='text/javascript'/&gt; 
&lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'/&gt; 
&lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'/&gt; 
&lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/&gt; 
&lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/&gt;
&lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushAppleScript.js' type='text/javascript'/&gt;
&lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js' type='text/javascript'/&gt;
&lt;script language='javascript' type='text/javascript'&gt;
 SyntaxHighlighter.config.bloggerMode = true;
 SyntaxHighlighter.all();
&lt;/script&gt;

  &lt;head&gt;
    &lt;meta content='IE=EmulateIE7' http-equiv='X-UA-Compatible'/&gt;
    &lt;b:if cond='data:blog.isMobile'&gt;
      &lt;meta content='width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0' name='viewport'/&gt;
</pre>

After editing html code on your design page if you paste the above two blocks of code on your new post Edit HTML window you can see how your page comes up with the first two blocks on this page. To do this you need to use pre tag like I used above. If you observe I used class attribute with a feature "brush:xml". If you want to post code in C language you need to write "brush:c" or for C++ it should be "brush:cpp", etc. For more languages and language aliases see this page: More Brushes.

Finally, like I mentioned above, you need to escape right angle brackets with &lt;. If you have tonnes of lines in your code, let's say you have big html code, with right chevron, then it's better to look for some tool that automates this job. Otherwise, you might end up hurting your fingers trying to escape all the right chevrons. Just search online for "html encoder" or "html escape", etc. I use this web page: HTML Encoder. Check Alex Gorbatchev web page for more details.

Oho, I forgot to mention one more thing. In my design html page I put javascript pages for Bash, CPP, CSS, Javascript, Perl, PHP, Python, SQL and XML. CPP works for both C++ and C languages. XML works for xml, xhtml, xslt, html, xhtml. If you need more languages check the link I gave above and add the appropriate javascript file link to be loaded. The advantage with these links is that whenever there is new version of syntax highlighter, this page gets that one as the links are always pointed to current version. Hope this helps someone.

PBS Script Generator: Interdependent dropdown/select menus in Javascript

PBS SCRIPT GENERATOR
SH/BASH TCSH/CSH
Begin End Abort

About Me

LA, CA, United States
Here I write about the battles that have been going on in my mind. It's pretty much a scribble.

Sreedhar Manchu

Sreedhar Manchu
Higher Education: Not a simple life anymore