I will try to answer your question considering that you are asking for Python specifically. I will describe my own method of tackling a simulation problem. Strategies for faster simulations are given in this description.
First, I prototype new simulations in Python. Of course, I try to make use of NumPy and SciPy as much as I can. Whereas NumPy provides a suitable array data type for numerical simulations, SciPy offers a wide numerical routines working with NumPy arrays.
Once the prototypes work more or less, I try to learn which parts of the program or script are the bottleneck. There are typical candidates for that:
- Loops in Python are slow. Very slow.
- As Python uses duck typing, calling functions can be slow.
I use a simple profiling strategy to learn where all the run time is spent. Using the IPython shell (which I cannot recommend enough), I run my script with
This "magic command" will do the profiling (using timeit) for you and present you a list with times once your script has terminated. Use this list to find out where your code is too slow.
Once you nailed down the parts that need to be speeded up, you may consider using compiled languages. I will point to two solutions.
First, there is the Cython language. Cython is a programming language very similar to Python (in fact, Python code is often valid Python code, too); however, the Cython compiler converts the Cython files to C code, which then may be compiled into a module usable from Python. Cython understands NumPy arrays. There are two ways in which using Cython can help you: first, you may introduce data types. This will speed up function calls. Also, if you iterate over arrays, your loop will run faster (in fact, if you type both the dummy variable and the array, you get a plain C loop!). Second, in my experiments even the untyped scripts run a bit faster due the fact that they're compiled instead of interpreted.
The other compiled language that will be useful for you is Fortran. There are different ways to use Fortran with Python (f2py, fortwrap, Cython). As to me personally f2py seems to be the easiest way, I'll quickly describe what it does. f2py can compile Fortran code to Python modules. It will allow you to use NumPy arrays as input and output variables from Python space. In Fortran space, these will be ordinary Fortran arrays. You can operate on those at full Fortran speed.
Personally, I tend to use Cython where the number of function calls is the bottleneck. For loop-heavy stuff, I prefer f2py (maybe because I have a strong Fortran background).
On additional note on Fortran: modern Fortran reads and writes very similar to NumPy - the syntax is very close. This makes it easy to convert NumPy code to Fortran code.
Note that both Cython and f2py support paralleism in some way. For Cython, you'll find help here, whereas for Fortran, there are the standard techniques such as OpenMP or MPI. Furthermore, there are Python wrappers for MPI, too. Personally, I use mpi4py on the Python level as well as OpenMP in Fortran.
Let me recommend a bit of literature: the book Python Scripting For Computational Science by H.-P. Langtangen is a great resource on Python in general as well as on strategies to make Python a bit faster. Unfortunately, AFAIR, it does not mention anything on Cython. As I second resource you may look at these slides. These give examples for everything I mentioned in this post (see also the code and sources here). There are many other good set of slides on the internet.
If you have more specific questions, we are all happy to help!