Table of Contents


hackcode1, hackcode1_qp - hierarchical N-body code


hackcode1 [parameter=value] ...


hackcode1 is an equal-timestep implementation of a hierarchical N-body code (J. Barnes and P. Hut, Nature 324, 446). It uses an adaptave Eulerian tree to reduce the number of interactions per time-step to O(NlogN). hackcode1_qp is similar, but includes quadrupole corrections to body-cell interactions (L. Hernquist, App. J. Suppl., 64, 715, 1987).

Particles with zero mass will not be included in building the tree structure, and hence in effect produce a restricted N-body code.


The following parameters are recognized; they may be given in any order.
If given, initial conditions will be read from in-file in snapshot format. At most one of in, restart, or continue may be specified.
If given, results are written to out-file in snapshot format.
If given, the system state will be read from state-file. New values are accepted for the following parameters: out, save, eps, tol, options, fcells, tstop, freqout, minor_freqout, and debug. At most one of in, restart, or continue may be specified.
If given, the system state will be read from state-file. New values are accepted for the following parameters: out, save, and debug. At most one of in, restart, or continue may be specified.
If given, the system state will be saved in state-file after each timestep.
Number of bodies for test data, generated only if none of in, restart, or continue are specified. Default is 128.
Random number seed used in generating initial conditions. Default is 123.
If true, generate centrally concentrated test system. Default is false.
Inverse time-step, to be used with a leap-frog integrator. Default is 32.0 (32 steps per unit time).
Force softening parameter. Default is 0.05.
Opening-angle tolerence parameter. Default is 1.0.
Ratio of cells to bodies, used when allocating cells. Default is 0.75.
Miscellaneous control options, specified as a comma-separated list of keywords. Currently recognized keywords are: reset_time: when reading initial data, set tnow to zero; new_tout: when restarting, set new output times; mass, phi, acc: output mass, potential, acceleration data with major data outputs. The phase space coordinates are always output. It also seems that the reset_time and new_tout options have not been implemented yet. Default: mass,phase.
Time to stop integration in N-body model units. Default is 2.0.
Frequency of major N-body data outputs. Default is 4.0 (4 frames per unit time).
Frequency of minor diagnostic outputs. If this frequency is not a simple fraction of freq (see above), the program can waiste significant amounts of time. Default is 32.0 (32 diagnostic measurements per unit time).
Output filename for log. Default is standard output (-). Can also use log=. to make it disappear in case your out=- needs to be part of a pipe.

See Also

treecode(1NEMO) , newton0(1NEMO) , directcode(1NEMO) , gyrfalcON(1NEMO)


This code is the very original 1986 (NEMO) version of the Barnes & Hut treecode and only kept in NEMO for that reason. It is not the most efficient treecode (see e.g. treecode(1NEMO) and gyrfalcON(1NEMO) for improved versions), and also suffers from the Warren & Salmon imploding galaxy bug.

When a restart is specified, values must be given for ALL legal parameters which do not take default values.

continue= does not seem to work. Use restart=


Running hackcode1 with all default parameters will integrate a 128 body plummer sphere for 64 timesteps to time 2 with softening 0.05 and critical opening angle 1 and a seed of 123. Assuming the standard portable ’ran3’ from NumRec is being used in xrandom(3NEMO) , we get the following initial and final printout:
  tnow       T+U       T/U     nttot     nbavg     ncavg   cputime
 0.000   -0.2675   -0.5434      3864         9        20      0.00
          cm pos   -0.0000    0.0000    0.0000
          cm vel   -0.0000    0.0000   -0.0000
  tnow       T+U       T/U     nttot     nbavg     ncavg   cputime
 2.000   -0.2647   -0.4857      4899        17        20      0.00
          cm pos    0.0002   -0.0018    0.0007
          cm vel    0.0003   -0.0019    0.0009


Particles cannot occupy the same position, since building the treestructure is done in integerized coordinates.


Joshua E. Barnes.


src/nbody/evolve/hackcode/hackcode1/    original NEMOized 1986 code
usr/josh/treecode            updated 1990s version


1-jul-87    V1.0  man written    JEB
11-jul-89    V1.2  using getparam()’s debug keyword + doc impr.     PJT
8-jun-90    V1.2  corrected error in man page    PJT
13-may-91    added undocumented feature of restricted Nbody      PJT
6-mar-94    added link to export version    PJT
29-mar-04    V1.4 major code cleanup for MacOS and prototypes    PJT
27-jul-11    V1.5 removed debug=, added log=      PJT
old bench10240 3.652u 0.002s 0:03.65 100.0% 0+0k 0+0io 0pf+0w new bench10240 4.688u 0.003s 0:04.69 99.7% 0+0k 0+0io 0pf+0w

Table of Contents