Sunday, July 10, 2011

Code Profiling and the Slowest Steps of Galaxy Formation

Galacticus isn't the fastest semi-analytic model of galaxy formation out there. It was never meant to be. Instead, the goal was to focus on flexibility and accuracy. Want it to go faster? Buy more computers!

Of course, speed is an issue though, so it's useful to know which parts of the calculation are the slowest. Building merger trees is actually very fast - it's a minor contributor to the overall run time. Solving the baryonic physics is the slow part. I regularly run Galacticus through valgrind to profile the code. As a result of this, many parts have been optimized and there's now no single part where additional optimization would result in a significant improvement in speed.

Instead, the limiting factor is the size and number of timesteps that the ODE solver must take to advance galaxies forward in time with the requested accuracy. I recently added some new functionality to Galacticus to track the sizes of timesteps taken the the ODE solver as it solves the physics of galaxy formation (*). Perhaps more importantly, it also figures out which properties of galaxies are responsible for limiting those timesteps - i.e. which cause the bottleneck in evolving galaxies forward in time.

Here's some typical output from the new ODE evolver meta-data collecting routines, showing the distribution of timesteps taken:

and which properties limit the timesteps:

The timestep distribution peaks around 10-3Gyr, which is a small fraction of typical galaxy dynamical times. It falls off rapidly below this, but has an extended tail to long times. From the histogram it's clear that it's the gas component of the spheroid that mostly limits the stepsize taken. Some exploration shows that this is due to disk instabilities.

An unstable disk can funnel gas (and stars) to the spheroid on a timescale as short as the disk dynamical time. The timescale for changing the gas mass of the spheroid in this way is therefore (Mspheroid/Mdisk) tdisk which can be arbitrarily short if the spheroid mass is low (as happens when a spheroid is created as a result of a disk instability event. Even with sensible absolute tolerance limits set on the spheroid evolution this can require some short timesteps to accurately track the evolution of the spheroid. Probably the best solution for this would be a better motivated model for disk instabilities.....

(* The ODE profiling code is available in the current development version of Galacticus, but is deactivated by default as it needs a hacked FGSL library to work. If you want to use it, let me know and I'll send you the modified FGSL.)

No comments:

Post a Comment