Previous ToC Up Next

0. Preface

0.1. N-Body Simulations

The current manuscript is Volume 1 in the Development Series of the Maya Open Lab project, for constructing a laboratory for simulations of dense stellar systems in astrophysics. The Maya project in turn is the first concrete example of projects developed in an initiative titled The Art of Computational Science (ACS). The aim of the larger ACS series, of which the Maya Series will be a part, is to provide real-world guides to designing, developing, using, and extending computational laboratories. We refer to the preface of Volume 0 for more background.

This volume presents the first steps on a road toward constructing computer codes for N-body simulations. We start in a very modest way, by considering only the 2-body problem. In addition, the only integration scheme we use here is the forward Euler scheme. While of little practical use, its extreme simplicity makes it a useful toy algorithm to illustrate some of the general issues involved in building N-body codes. Various additional algorithms, such as the leapfrog, and a few Runge-Kutta methods, will be discussed in Volume 2, also within the context of the 2-body problem. The general N-body problem will be addressed in Volume 4.

0.2. Ruby

We have decided to present our initial codes in the Ruby language, rather than the more traditional choices of Fortran, C, or C++. Ruby is a fully object-oriented, flexible and extremely powerful scripting language. Just like assembly language is far more expressive than machine language, and Fortran or C or C++ are in turn far more expressive than assembly languages, Ruby is an example of a new generation of languages that occupies yet one level higher in the hierarchy of shifting the burden of programming from the programmer to the compiler -- or in Ruby's case, to the interpreter.

Within a few weeks of working with Ruby, we already became convinced of its superiority for our purpose of developing a state-of-the-art computer code for dense stellar system, with sufficient flexibility to allow us to set up a framework for connecting codes old and new, from ancient legacy codes to new products written in a variety of languages. Among the many attractive features of Ruby, it was especially its practical ease of allowing rapid prototyping that appealed to us most.

0.3. Speed

An essential requirement for any computer code to be used in scientific simulations is its ability to deliver sufficient raw speed. Without that, no matter how much a language excels in elegance and clarity, it would not be practically useful. Therefore, one of our first checks, after turning to Ruby, was to investigate its speed. We knew that we could not expect any significant speed from Ruby out-of-the-box. Unlike C or Fortran, Ruby was designed expressly for flexibility and clarity, rather than for speed. At the same time, Ruby was designed in such as way as to make it easy and natural to replace some compute-intensive core modules with equivalent modules written in more traditional, lower-level languages.

Indeed, after only a few days of experimentation, we convinced ourselves that we could find several ways in which to regain the speed of a C or Fortran code within Ruby, by replacing only a very small fraction of the code by functions written in C, while leaving the vast majority of the code complexity within Ruby's domain. We will describe this process of speeding up Ruby in great detail only in Volume 5, after we have presented Ruby in sufficient detail in practical applications, to set the stage for an informed discussion about what does and does not need such hand-coded speed-up.

0.4. Programming Issues

The current volume contains a rather detailed introduction, from scratch, to how Ruby can be used for numerical applications. We expect this volume to be of use to a broad public, interested in trying out Ruby for applications in computational science, starting with the N-body problem as a comparatively simple example. Even those who already have gained considerable expertise in Ruby may want to consult this volume for a real-life example of how to set up compute-intensive applications, something that is generally left out of Ruby literature, both on introductory and on advanced levels.

In addition, we present reports of bug-tracing sessions, with a degree of realistic detail seldom encountered in the literature. It is our belief that the essential art of debugging code can only be learned through practice. And to the extent that books can help one to get exposed to this type of practice, examples have to come directly from applications, or else they will be, at best, only of theoretical value. Chapter 7, Debugging, is devoted in its entirety to this topic.

0.5. Acknowledgments

Besides thanking our home institutes, the Institute for Advanced Study in Princeton and the University of Tokyo, we want to convey our special gratitude to the Yukawa Institute of Theoretical Physics in Kyoto, where we have produced a substantial part of our ACS material, including its basic infrastructure, during extended visits made possible by the kind invitations to both of us by Professor Masao Ninomiya. In addition, we thank the Observatory of Strasbourg, where the kind invitation of Professor Christian Boily allowed us to make a rapid beginning with the current volume.

Finally, it is our pleasure to thank Douglas Heggie, Stephan Kolassa, Ernest Mamikonyan, Bill Paxton, Michele Trenti, John Tromp and Jason Underdown for their comments on the manuscript.

Piet Hut and Jun Makino

Kyoto, July 2004
Previous ToC Up Next