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.
sudo apt-get update
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
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
./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.
/usr, but since we
installed it at /usr/local, we need to inform the Makefiles about
this:
export SWARMHOME=/usr/localIn 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.
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
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*.debNOTE: 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.applto
include /usr/share/libswarm/etc/Makefile.applIf 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
id. Use pointers to your classes:
instead of declaring something like id agent, declare
AgentSwarm *agent. If gcc knowns the class of bug object it
will be able to warn you when you do some mistakes. When examining your
program within gdb, you be able to fully explore the variable and methods of
the agent object.
OBJCFLAGS += -W -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings \
-Wswitch -Wshadow -Wcast-align -Wuninitialized \
-Wbad-function-cast -Wchar-subscripts -Winline \
-Wnested-externs -Wimport -Wprotocol -Wlong-long
OBJCFLAGS += -g -O0Almost always I prefer to use cgdb instead of plain gdb:

distclean. Don't simply fix the problem and type "make" again
to continue the compilation because it probably would not work well. It seems
that the swarm's configure script improved a lot in the last years, but it is
still incomplete. Not all programs required to compile swarm are checked, and
we only discover this fact at compile time, after some error message that might
be hard to understand:
installation problem, cannot exec 'cc1obj': No such file or directory missing -batch --eval '(setq *disable-gui* nil)' -l .../src/defobj/modulemap.elc -f generate-module-map cp -f ../etc/common.el .../_common.el ... missing -batch -f batch-byte-compile .../_common.el /bin/sh: missing: command not foundThe first message means that the GNU Objective-C compiler isn't installed; the other two mean that emacs isn't installed (but emacs should be required to build swarm only if you want java support). If you are using the official 2.2 version of swarm, you might get the following error:
mframe.m:1728: internal compiler error: in assign_stack_temp_for_type, at function.c:605 Please submit a full bug report, with preprocessed source if appropriate.Then, it will be necessary to comment the line 1728 of libobjc/mframe.m:
1726: #ifndef __CHECKER__ 1727: /* Checker-equipped compiler barfs on this on sparc-sun-solaris2.7. */ 1728: // *(block *) buffer = retframe_block (retframe); 1729: #else 1730: #warning Disabling code in mframe for Checker 1731: #endifIf you have tried to install a Debian package of swarm-2.1, it might be necessary to upgrade some of the listed packages before proceeding, as reported by Jerry Li: Problems installing swarm-2.2 on Ubuntu 5.1. As you can see, we ran the
configure script with some parameters.
When the script is unable to find a library that you know is already
installed, you can use "dpkg -S" and "dpkg -L" to discover the correct path to
the library or its headers. Example:
configure: error: Please specify Tcl header path using --with-tcldir or --with-tclincludedir $ dpkg -S tcl.h tcl8.4-dev: /usr/include/tcl8.4/tcl-private/generic/tcl.h perl-tk: /usr/lib/perl5/Tk/pTk/tcl.h tcl8.4-dev: /usr/include/tcl8.4/tcl.h $ dpkg -L tcl8.4-dev | grep libFor versions of Ubuntu before 8.04, the configure parameters were:
./configure --disable-jar --without-jdkdir --enable-onefile --with-pic \
--with-gnu-ld --with-tclincludedir=/usr/include/tcl8.4/ \
--with-tclscriptdir=/usr/lib/tcl8.4/ --with-tkscriptdir=/usr/lib/tk8.4/ \
--with-tcl=/usr/lib/tcl8.4/ --with-tk=/usr/lib/tk8.4/
On amd64, I got the following error:
/usr/bin/ld: ../../avcall/.libs/libavcall.a(structcpy.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC ../../avcall/.libs/libavcall.a(structcpy.o): could not read symbols: Bad value collect2: ld returned 1 exit statusAnd the solution was to pass the parameter "--with-pic" to the configure script. On other architectures, swarm might become slower when built with this parameter. On some architectures, swarm might run faster if you set some compiler flags before running the "configure" script:
export CFLAGS='-O3 -ffast-math -funroll-all-loops -ftree-vectorize' export OBJCFLAGS='-O3 -ffast-math -funroll-all-loops -ftree-vectorize' ./configureand, then, add following line to the Makefiles of your models:
OBJCFLAGS+=-gThe use of ffast-math flag is controversial. At some webpages we find the information that it may reduce accuracy of float point calculations. Others tell that it actually increases the accuracy. You have to test it yourself to see what happens in your architecture.