views:

124

answers:

3

Hi,

in the field of scientific simulations (physics) I am thinking about developing some new simulation package in C/C++. What do you think would be the best practices when starting here from scratch? Can you recommend some bibliography?

Thanks

+1  A: 

Start with Numerical recipes: the art of scientific computing. A pretty comprehensive tome. However, keep in mind two things:

  • It contains both C++ and Fortran 90 code samples.
  • Forget about actually using any of the code samples in your project, though - AFAIK they are copyrighted and must be licensed for reuse separately.

Still, if you need it for educational purposes, this book is a highly recommended reading.

David Parunakian
Well, of course you can use the code from Numerical Recipes if you pay for a licence to do so. Such a licence is not expensive.
High Performance Mark
A: 

Have a look at OpenModelica.

wilhelmmedetz
+2  A: 

Here's something of a reading list. Not sure if it's too basic for you:

Writing Scientific Software: a good follow-on to a basic 'Learn to Program in C++' or whatever.

Parallel Scientific Computing in C++ and MPI: if you are not planning to parallelise your application, you should be.

Engineering and Scientific C++: a good, domain-specific, introduction to programming in C++. A bit dated in language details, but the overall approach hasn't aged.

I suggest that you read through the SO answers to questions such as 'How should I design a large C++ program ?' for advice on other books which may be of interest.

As to best practices, here are some suggestions. Again, I'm not sure of your starting point so some of this may be too basic:

  • As I wrote above, you should be planning from the outset to develop a parallel program. If message-passing on a cluster is not your cup of tea, at least consider shared memory programming for a multi-core desktop. OpenMP is worth investigating.
  • Make yourself familiar with existing work. The BOOST libraries are probably essential. While I applaud your intention to roll-your-own, don't ignore existing well-established numerical libraries such as BLAS and LAPACK which you'll find at Netlib. Depending on your development platform and toolset you may find them already installed.
  • If you are coming from a scientific background, you may want to improve your knowledge of and skills in software engineering. Matters such as: source code control; testing; code profiling and optimisation; deep knowledge of what your compiler(s) can do. In my experience many computational scientists have a weak background in all of this stuff.
  • You should be planning to spend (approximately) as much time on designing and testing your program as on actually coding it. Even working on your own it is essential to have a good plan of action before you start coding. There's no reason why it has to be complete in every detail at the beginning but never enter territory without a map.
  • You are silent on the aspect(s) of the physical world you want to simulate. There is a lot of prior art in all sorts of physical simulations, if you were a bit more specific SO might be able to provide some more specific suggestions.
High Performance Mark
hi. thanks a lot for your helpful and extensive answer. about your last point, the idea is to develop some new molecular dynamics code. some advice here? thanks
Werner
Molecular dynamics is beyond my ken, but I see that the Wikipedia article has some pointers to software. I'll be very surprised if you can't find open source code to inspect, and the literature is extensive.
High Performance Mark