Objective-C SWARM at Ubuntu 8.04

Jakson Aquino

Contents

Building swarm: a quick guide
Debian package
Debugging
    Writing ease to debug code
    CGDB
    Valgrind
Some explanations on the process of building swarm

 

I used the Objective-C version of swarm in my doctorate thesis because it was free software and was not an interpreted language, like java. The model that I was developing was quite complex and I thought that running it through an interpreted language would be slower than running a compiled binary. I thought Swarm was a good choice. However, after finishing my doctorate, I translated my model into C++ and it became about 2-3 times faster than the one written in Objective-C with swarm. Thus, now I plan to continue the development of my virtual anthropoids in C++, without any agent based model toolkit. I still have to compare C++ with java, since java has many performance optimizations that might make the model run faster than when written in C++. Anyway, I still keep here the quick guide to build Objective-C Swarm and the packages for Debian and Ubuntu.

 

Building swarm: a quick guide

The steps below were tested in Ubuntu 8.04.
  1. Enable the 'universe' repository if it isn't enabled yet. Click here to know how to do it under Ubuntu. If you prefer, you can manually edit the file /etc/apt/sources.list and uncomment the line that allows the installation of software from the 'universe' repository.

  2. Then, update your list of available software. That is, open a terminal and type (or copy and paste):
       sudo apt-get update
    
  3. Install the software necessary to download and compile swarm:
       sudo apt-get install gobjc gperf libxpm-dev libpng12-dev automake \
            emacs21-nox libhdf5-serial-dev blt-dev autoconf libtool make \
            xfonts-75dpi xfonts-100dpi
    
  4. Now, you can download the swarm source code from Paul Johnson's web site:

       wget http://pj.freefaculty.org/Swarm/swarm-2.2.4.tar.gz
       tar -xzf swarm-2.2.4.tar.gz
       cd swarm-2.2.4
    
  5. Then, you can compile swarm:
       ./autogen.sh
       ./configure --with-pic --enable-onelib --with-gnu-ld --disable-jar \
          --without-jdkdir --with-tcl=/usr/lib/tcl8.4/ --with-tk=/usr/lib/tk8.4/
       make
       sudo make install
    
    Note: If you are using a version of Ubuntu older than 8.04 you will have to pass different parameters to the configure script.

  6. Swarm is already installed. You should now put this line at the end of your ~/.bashrc, because, by default, the Makefiles that come with swarm applications are configured to look for swarm at /usr, but since we installed it at /usr/local, we need to inform the Makefiles about this:
    export SWARMHOME=/usr/local
    
    In addition to putting the above line in your ~/.bashrc, copy and paste it in your terminal too. When you logoff and login again the .bashrc will be re-read and the SWARMHOME environment variable automatically will be active.

  7. Finally, you can download, compile and run some examples:
       wget http://ftp.swarm.org/pub/swarm/apps/objc/sdg/swarmapps-objc-2.2-3.tar.gz
       tar -xvzf swarmapps-objc-2.2-3.tar.gz
       cd swarmapps-objc-2.2-3/heatbugs/
       make
       ./heatbugs
    

 

HeatBugs model running

 

Debian package

To build and install a Debian package of swarm using Ubuntu, install all build dependencies (see the Quick Guide above) and, then, do the following commands in a terminal:
   sudo apt-get install build-essential dpkg-dev debhelper fakeroot
   wget http://pj.freefaculty.org/Swarm/swarm-2.2.4.tar.gz -O swarm_2.2.4.orig.tar.gz
   wget http://jalvesaq.googlepages.com/swarm_2.2.4-1.diff.gz
   wget http://jalvesaq.googlepages.com/swarm_2.2.4-1.dsc
   dpkg-source -x swarm_2.2.4-1.dsc
   cd swarm-2.2.4
   dpkg-buildpackage -rfakeroot -uc -us
   cd ..
   sudo dpkg -i libswarm_2.2.4-1*.deb libswarm-dev_2.2.4-1*.deb
NOTE: Debian/Ubuntu and Red Hat/Fedora use different file system hierarchies. If you are using the Debian package, you'll have to change one line of the Makefiles of your swarm applications from:
include $(SWARMHOME)/etc/swarm/Makefile.appl
to
include /usr/share/libswarm/etc/Makefile.appl
If you just want to run a precompiled model, you don't need neither libswarm-dev nor libswarm-dbg, and if you don't want to build swarm yourself, you can use the binaries I've built for:

Ubuntu 8.04 (Hardy Heron) i386: md5sum
 26fa93a5393c463c8924458bc8f3da30
67a9bf87dcd8bf013839e703fa5bdf11
4a84cf4ae5ff654c40bee2665aa52151
  
Ubuntu 8.04 (Hardy Heron) amd64: md5sum
 5284702387314276e13b15cf08dd309e
42c9f0d16c4dc70c1e50fefb653d9fc3
d4a087f42429cae666c5baac60872a0e
  
Ubuntu 7.10 (Gutsy Gibbon) i386: md5sum
 7e379bb2b957160e88cff0048bcf2e40
3ea083ac153bb1d3cde6b79523a1b83d
20eed6b0bd205c9898b6166bfc81d63f
  
Ubuntu 7.10 (Gutsy Gibbon) amd64: md5sum
 72d48de8ddf6354cb1afc32009e18480
25f1c4c53aea98d0a543ce46d381bcbc
7e3c20f236ec7daa86ca629de57493ca
  
Ubuntu 6.06 (Dapper Drake) md5sum
 26035f76b859068f850ba660f77c07d8
01b2959f9e1e67a738b88cbd3320ba0d
69e737bbc2d6b4b47bba21eec6c4e068
  
Debian Etch (4.0) md5sum
 22001507e06d8880df53379e7d5e9e61
33958c3f836cc4b3854e66f617df4341
9349bc381b5e6a51643439614d238d3c

 

When debugging a swarm model, I prefer a version of libswarm stripped from debugging symbols to avoid gdb stepping inside swarm code, which is distracting to me. But sometimes it's useful to have the debugging symbols. When the application crashes inside swarm libraries, the library with debugging symbols might be necessary to do a useful backtrace, that is, one that shows what line of your code caused the crash into swarm library. So, if you prefer a version of libswarm with debugging symbols, you can install libswarm-dbg. This might me enough to do a backtrace, but, in order to actually see swarm code inside gdb, you should unpack swarm source code at /usr/src:

   sudo tar -xzf swarm-2.2.4.tar.gz -C /usr/src

 

Debugging swarm models

Writing ease to debug code