Posted by: sureshamrita | December 12, 2010

Simulation – some lessons

Recently I had to write a Recognition system simulator.  It was a medium sized code with around 4000 lines of C++. This is the first time I was writing a simulator and at the end of it, I felt I could have done it better.

Basically my code was monolithic. Just one executable at the end. I realized that this approach has the following difficulties:

  • When an error comes it is very difficult to know form which part of the code it came. We get an exception but which part of the code triggered the error in the first place?
  • We may later realize that some portion of the code is better written in another language, for example like matlab or python. But that would be impossible if we write a monolithic C++ code.

A simulation system has the following logical components:

  • The data generating unit.
  • Data processing unit.
  • Result display unit –  usually in the form of plots.

My experience is that each of these units should be written as different executables – in a language most suited to the job at hand. Finally all the binaries could be bundled by a shell script or python script.

It is also better that each of the above components output is stored in  a file. It may be a good idea to create filenames which  reflect the parameter values used for generating data. This approach has the advantage that it is easy to fix a bug. Ourself or a code segment can look at the output file and quickly find out if the file is in order.

I have more comment to add regarding presentation of the final result. When I first wrote the code, all the data processing was done using C++ and the plots were generated using gnuplot. But it is much easier to do some kind of data manipulation using matlab and also generate plots using matlab or excel. Such an approach is possible only if we make our code hybrid instead of monolithic.

I would like to acknowledge the inputs given by my lab mate, Dr Ninad Thakoor


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: