2009年1月14日星期三

Make it Inline

When compiling source code using g++, the -O3 flags turns on -finline-functions, which tells g++ to integrate all simple functions int to their callers. If no optimization flags are specified, the default one is -O0, which does no optimization.
The default in g++ seems to be to ignore "inline"
unless one gives the options -finline-functions

references:
http://gcc.gnu.org/onlinedocs/gcc-3.4.2/gcc/Optimize-Options.html#Optimize-Options

Using gprof with NS2

gprof is a powerful tool to measure the running time of each function in a program, which is widely used to analyze and speed up programs.

To use gprof, a program should be BOTH compiled and linked with -pg, -g is also needed for compilation. For example, given a source file hello.c, it should be compiled using gcc -g -pg hello.c -o hello

In NS2, since the compilation process is done using Makefile, which specifies compilation options and link options in a separate form, two modifications should be done to the Makefile as follows:

CCOPT = -Wall -g -pg
LDFLAGS = -Wl,-export-dynamic -pg


Type "make clean & make" to regenerate executable file. Then run your simulation as usual. When ns2 exits, a new file "gmon.out is created. You can use gprof NS_BIN_DIR/ns gmon.out to see the results, where NS_BIN_DIR denotes the directory that the executable file "ns" is located.

2009年1月13日星期二

How to compile NS2 on 64-bit System

When compiling NS-2.33 on a 64-bit CPU system, I got following error message from linker:
"skipping incompatible libXext.so when searching for -lXext"
cannot found libXext

The reason is the default directory in ns2 to look for libXext is /usr/X11R6/lib, where the 32-bit libXext is located. On a 63-bit system, we should change the directory to /usr/X11R6/lib64/. This can be done with a single command:

grep -rl "/usr/X11R6/lib" * | xargs sed -i -e 's/\/usr\/X11R6\/lib/\/usr\/X11R6\/lib64/'

Change current dir to ns-all-in-one-2.33 and execute the aboe command and run ./install. Then ns2 will be successfully compiled.

NOTE: the command should be run only once, otherwise there would be errors.