Simulation vs Emulation

Many times I can see these two different terms being used the other way around in articles. Simulation (προσομοίωση) is the process of modelling an event or process in a virtual environment. The model is aware that is being simulated and is different that the real one. It is used to represent the actual model/object. Emulation (εξομοίωση) on the other hand, is the process of creating the desired environment for an application, or an object in general, to act like being in the expected environment. For instance, a standard i386 Linux OS can be emulated on a i386 virtual machine that runs on PPC hardware. Emulation mimics what is excepted by the targeted object. The LHC can be simulated in a computer model. The first moments of the big bang will be emulated within the physical accelerator. Particles are not aware where they are physically.

Simple and very basic PBS/Torque emulator

PBS (Portable Batch System) is one of the common batch systems used across clusters. Unfortunately, proprietary piece of software. There used to be an open source version, OpenPBS which has been forked to Torque. Torque can be installed and configured to perform the basic operations within 15-20 minutes. Although, for evaluation purposes, I have wrote a *very simple* emulator for PBS/Torque. All it provides is three scripts:

qsub -> submitting a job
qstat -> displaying job list
qdel -> removing job(s)

A virtual job can be submitted, without need of proper PBS or Torque-like submission script and other parameters. The parameters each script is accepting are:

qsub – single virtual job: qsub test
– qstat – either username to list jobs of a user or none to list all jobs: qstat foobar
– qdel – single or list of job IDs to remove: qdel 1234 5678

Download: pbs-emu-0.1.tar.gz

Speedup and efficiency shell calculator

The following script can be used to calculate the speedup and efficiency of a parallel code when compared to its serial version. Pretty much straight forward process. This script can be used either individually or as part of another script to automate the process of generating the required results. It accepts three arguments: 1) serial execution time 2) parallel execution time 3) number of processors.

./SEcalc.sh <serial> <parallel> <procs>

Script:

############################################################################
# Copyright (C) 2011  Panagiotis Kritikakos <panoskrt@gmail.com>           #
#                                                                          #
#    This program is free software: you can redistribute it and/or modify  #
#    it under the terms of the GNU General Public License as published by  #
#    the Free Software Foundation, either version 3 of the License, or     #
#    (at your option) any later version.                                   #
#                                                                          #
#    This program is distributed in the hope that it will be useful,       #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#    GNU General Public License for more details.                          #
#                                                                          #
#    You should have received a copy of the GNU General Public License     #
#    along with this program.  If not, see <http://www.gnu.org/licenses/>. #
############################################################################

#!/bin/bash

if [ "$#" -eq "3" ]; then
   runtime1proc=$1
   runtimeNproc=$2
   totalprocs=$3
   speedup=`echo "${runtime1proc}/${runtimeNproc}" | bc -l`;
   efficiency=`echo "${speedup}/${totalprocs}" | bc -l`;

   printf "\n Total processors: ${totalprocs}\n\n";
   printf " Runtime for serial code: ${runtime1proc}\n Runtime for parallel code: \
   ${runtimeNproc}\n\n";
   printf " Speedup: ${speedup}\n Efficiency: ${efficiency}\n\n";
else
   printf "\n Usage: SEcalc.sh   \n\n";
   printf " SEcalc.sh 0.350 0.494 2\n\n";
fi

OpenNebula DHCP leases – automatic lease discovery

OpenNebula uses a network template file that lists all the available IPs within a specific network that can be given to the Virtual Machines on an OpenNebula deployment. The template can define more details such as gateway, resolves, network class and so on. In our case, we just need a list of available leases for the VMs to pick up. The following script automates the process of getting listed all the available IPs within the network range of the bridged interface of the OpenNebula host machine, starting from checking the first IP after that of the bridged interface.

############################################################################
# Copyright (C) 2011  Panagiotis Kritikakos <pkritika@epcc.ed.ac.uk>       #
#                                                                          #
#    This program is free software: you can redistribute it and/or modify  #
#    it under the terms of the GNU General Public License as published by  #
#    the Free Software Foundation, either version 3 of the License, or     #
#    (at your option) any later version.                                   #
#                                                                          #
#    This program is distributed in the hope that it will be useful,       #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#    GNU General Public License for more details.                          #
#                                                                          #
#    You should have received a copy of the GNU General Public License     #
#    along with this program.  If not, see <http://www.gnu.org/licenses/>. #
############################################################################

#!/bin/bash

if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
 echo
 echo " This script will generate the appropriate leases for the Open Nebula Virtual
         Machines."
 echo " It will generate leases that for unused IPs that map to the bridged interface."
 echo
 echo " The default bridge interface is br0. If you want to change this, pass another
        interface as an argument."
  echo
  exit
fi

if [ "$1" == "" ]; then
  BRIDGE=br0
else
  BRIDGE=$1
fi

IPADDR=`ifconfig $BRIDGE | grep "inet addr" | awk {'print $2'} | sed s/addr:*//g`
BCAST=`ifconfig $BRIDGE | grep "inet addr" | awk {'print $3'} | sed s/Bcast:*//g`
MASK=`ifconfig $BRIDGE | grep "inet addr" | awk {'print $4'} | sed s/Mask:*//g`
if [ -e /etc/debian_version ]; then
  NETWORK=`ipcalc -n $IPADDR $MASK | grep Network | awk {'print $2'} | sed 's/\./ /g' \
| awk {'print $1"."$2"."$3'}`
else
  NETWORK=`ipcalc -n $IPADDR $MASK | sed s/NETWORK=*//g | sed 's/\./ /g' | \
awk {'print $1"."$2"."$3'}`
fi

IPOCT=`ifconfig $BRIDGE | grep "inet addr" | awk {'print $2'} | sed s/addr:*//g | \
sed 's/\./ /g' | awk {'print $4'}`
BCASTOCT=`ifconfig $BRIDGE | grep "inet addr" | awk {'print $3'} | sed s/Bcast:*//g | \
sed 's/\./ /g' | awk {'print $4'}`

hostMin=$(($IPOCT + 1))
hostMax=$(($BCASTOCT - 2))
totalIP=$(($hostMax - $hostMin))

echo
echo " $(($totalIP + 1)) IPs will be checked for availability.
       That might take some time..."
iter=1

ONNET_FILE=hpce2_network.net

printf 'NAME = "HPCE2"\n' > $ONNET_FILE
printf 'TYPE = FIXED\n\n' >> $ONNET_FILE
printf "BRIDGE = ${BRIDGE}\n" >> $ONNET_FILE
echo
for LEASE in `seq $hostMin $hostMax`
do
  echo -n $iter " "
  ping -c 1 ${NETWORK}.$LEASE -W 1 > /dev/null;
  if [ $? -ne 0 ]; then
    printf 'LEASES = [ IP=''"'$NETWORK.$LEASE'"''] \n' >> $ONNET_FILE
  fi
  let iter++
done
echo
echo

Compiling SPEC Benchmarks tools on ARM

Some of the SPEC benchmarks come for a variety of architectures but not for ARM, which is not surprising anyway. The easiest way to execute the benchmarks is by using the provided scripts, which is pretty much straight forward operation. The benchmarks come with pre-compiled tools and libraries that are needed by the benchmarks. Among them is Perl, which will fail to compile on ARM systems because of some invalid object definitions in its makefile. These definitions get in the makefile by the Configure script which is called before calling make. Instead of messing around with Configure, I added a couple of lines in the buildtools file, which is responsible for building the SPEC tools on a new architecture or after having modified the host system, in order to remove the unnecessary lines from the corresponding makefiles.

The buildtools script can be found under tools/src/ in the SPEC benchmarks directoy. What is needed is to go in the Perl building section, line 103, and replace the fist part of the building phase with the following oneliner:

(cd $PERLSRC; LD_LIBRARY_PATH=`pwd`; export LD_LIBRARY_PATH; 
./Configure -dOes $PERLFLAGS -Ddosuid=undef -Dprefix=$INSTALLDIR 
-Dd_bincompat3=undef; cat makefile | grep -v built-in 
| grep -v "command line" > makefile.new; cp makefile.new makefile; 
cat x2p/makefile | grep -v built-in | grep -v "command line" > x2p/makefile.new; 
cp x2p/makefile.new x2p/makefile; make; ./perl installperl ) 
|| die "Can't build perl"

Running Fortran on ARM

Generally and very briefly, there is no official Fortran compiler available for the ARM architecture. The easiest way to get Fortran code (specifically Fortran 77) to run on the ARM architecture, or any other architecture that doesn’t have a Fortran compiler, is to convert the Fortran code to C. In order to do that efficiently, we can use Netlib’s f2c command line tool, available for Linux, Unix and Windows.

The steps that need to be followed are:

1) Compile the library – source at http://www.netlib.org/f2c/libf2c.zip
Rename makefile.u to makefile and do make. Copy the generated libf2c.a to /usr/lib and the f2c.h header under /usr/include.
2) Compile the binary – source at http://www.netlib.org/f2c/src/
Rename makefile.u to makefile and do make. Copy the binary f2c under /usr/local/bin.

Supposing we have the foo.f file we can generate the C version by running f2c foo.f, giving us foo.c. It can now be compiled using ‘gcc foo.c -o foo -lf2c‘.

In order to automate this process a while, the following script can be used. It accepts only one argument, the Fortran source file.

#!/bin/bash
fortranFile=$1
fileName=`echo $1 | sed 's/\(.*\)\..*/\1/'`
echo $fileName
f2c $fortranFile
gcc ${fileName}.c -o $fileName -lf2c

UPDATE: There is GCC Fortran compiler for ARM Fedora and Debian and I presume for other distros as well. The issue now is that these distributions are compiled for ARMv5, while the latest ARM processors (Cortex-A8, A9, A15) are of the ARMv7 architecture. The compilers, and the OS in general is therefore unable to make use of the additional instructions sets and FPU. Other distros, such as Slackware, are compiled on even older architecture, ARMv4.

Monitoring power consumption of an IPMI system for a given application

A simple script to measure power consumption of an IPMI enabled system (using ipmi-sensors) while executing a given application. The script can perform two operations: log the power consumption and read an existing log file and report the average watts consumed. The consumption sample is taken by default every 1 second. That can be easily altered either within the script or by introducing an additional user argument.

For logging consumption:

$ ./watt_log.sh get <logfile> <application in ps>

Once the logging will start, the script will automatically stop when the application will finish executing. For interrupting this, CTRL+C would work as well without affecting the logged entries.

For reporting average:

$ ./watt_log.sh average <logfile>
############################################################################
# Copyright (C) 2011  Panagiotis Kritikakos <panoskrt@gmail.com>           #
#                                                                          #
#    This program is free software: you can redistribute it and/or modify  #
#    it under the terms of the GNU General Public License as published by  #
#    the Free Software Foundation, either version 3 of the License, or     #
#    (at your option) any later version.                                   #
#                                                                          #
#    This program is distributed in the hope that it will be useful,       #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#    GNU General Public License for more details.                          #
#                                                                          #
#    You should have received a copy of the GNU General Public License     #
#    along with this program.  If not, see <http://www.gnu.org/licenses/>. #
############################################################################

#!/bin/bash

option=$1
logfile=$2
code=$3

getAvg(){
  totalwatts=`cat ${logfile} | awk '{total = total + $1}END{print total}'`
  elements=`cat  ${logfile} | wc -l`
  avgwatts=`echo "${totalwatts} / ${elements}" | bc`

  printf "\n\n Average watts: ${avgwatts}\n\n"
}

if [ "${option}" == "average" ]; then
   getAvg
   exit 0
fi

if [ $# -lt 3 ] || [ $# -gt 3 ]; then
  echo " Specify logfile and code"
  exit 1
fi

if [ -e ${logfile} ]; then rm -f ${logfile}; fi

codeis=`ps aux | grep ${code} | grep -v grep | wc -l`

while [ ${codeis} -gt 0 ]; do

  sudo /usr/sbin/ipmi-sensors | grep -w "System Level" | awk {'print $5'} | \
  awk ' sub("\\.*0+$","") ' >> ${logfile}
  sleep 1
  codeis=`ps aux | grep ${code} | grep -v grep | wc -l`

done

getAvg

Virtual Cluster liveDVD milestone 3 released

The Virtual Cluster liveDVD milestone 3, an activity of the HPC-Europa2 project, is available from today for download.

“The “HPC-Europa2 Virtual Cluster Live DVD” is a SliTaz based Live Linux DVD. It boots and runs completely from DVD providing recent tools, compilers and libraries for the development of parallel applications. Further on the DVD includes training material, videos from past virtual surgeries and reports from past HPC-Europa visitors.”

SliTaz kernel modules issues

SliTaz is a minimal, light-weight (30MB) Linux distribution, available in a liveCD (or USB, obviously). We are using it as the base for developing a liveDVD for a project. These minimal distros are quite nice from the aspect that you install the package you need as you go. The great problem, is that they’re missing *lots* of base packages that need to perform standard operations (e.g. ‘make’). Even worse, they don’t include lots of kernel modules (i.e. drivers). In my case the system didn’t have the required network module.

I was trying to deploy SliTaz on a Xen virtual machine on a Dell Poweredge. With Ethernet card seen by the VM as:

$ lspci | grep Ether
00:04.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+

The kernel module required for this card is either “8139cp.ko” or “8139too.ko”. Both missing from my installation. I had another testing installation on a VirtualBox where the ethernet card worked fine but it needed another module, available by the default installation. A quick look on the SliTaz forums shown that the module I was after should be available with the 3.0 release, the one I was trying. I tried the ‘cooking’ (development) version as well but it didn’t really made any difference.

A way I could deal with this was to start downloading packages from the SliTaz repository in order to install the kernel source files for compiling the required module. The process had to be done manually on the Xen host system. Get the packages -> create map device for the image-> mount the VM’s image on Xen host -> copy the packages -> un-mount the image -> remove the mapper -> boot the VM -> install packages -> find out the dependencies not listed on the package information -> go back to step1. A bit ‘painful’ doing this as a repetitive process to solve the problem.

kpartx -a /gust/image.img
mount /dev/mapper/loop0p1 /mnt
(cp cp cp cp...)
umount /mnt
kpartx -d /gyest/image.img

The other way was to use my SliTaz VM instance on VirtualBox that had connection to the Internet. Downloading the kernel source, with all of its dependencies:

$ tazpkg get-install linux-source

Creating a Makefile for the required module:

obj-m += 8139cp.o
KVERSION = $(shell uname -r)
all:
	make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
	make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean

Typing ‘make’ and the module was created. Next step was to copy the module across to the Xen host system and follow the same steps as for copying packages from the local disk over to the VM’s image. Once the module was copied and the VM was booted, the module had to be loaded:

$ insmod 8139cp.ko
$ lsmod
Module                  Size  Used by    Not tainted
8139cp                 17252  0
$ ifconfig eth0 up
$ udhcpc eth0

eth0 was then up, fetching its IP from the DHCP server. Next step, to automate this on every startup by adding these sequential commands in /etc/init.d/local.sh