balance#

Syntax#

balance thresh style args ... keyword args ...
  • thresh = imbalance threshold that must be exceeded to perform a re-balance

  • one style/arg pair can be used (or multiple for x, y, z)

  • style = x or y or z or shift

    • x args = uniform or Px-1 numbers between 0 and 1

      • uniform = evenly spaced cuts between processors in x dimension

      • numbers = Px-1 ascending values between 0 and 1, Px - # of processors in x dimension

      • x can be specified together with y or z

    • y args = uniform or Py-1 numbers between 0 and 1

      • uniform = evenly spaced cuts between processors in y dimension

      • numbers = Py-1 ascending values between 0 and 1, Py - # of processors in y dimension

      • y can be specified together with x or z

    • z args = uniform or Pz-1 numbers between 0 and 1

      • uniform = evenly spaced cuts between processors in z dimension

      • numbers = Pz-1 ascending values between 0 and 1, Pz - # of processors in z dimension

      • z can be specified together with x or y

    • shift args = dimstr Niter stopthresh

      • dimstr = sequence of letters containing “x” or “y” or “z”, each not more than once

      • Niter = # of times to iterate within each dimension of dimstr sequence

      • stopthresh = stop balancing when this imbalance threshold is reached

  • zero or more keyword/arg pairs may be appended

  • keyword = procminsize or splitlimit or out

    • procminsize value = hard limit for minimum size of the processors’ sub-domain (distance units)

    • splitlimit value = limit for the maximum fractional distance a processor sub-domain can shift (value between 0.0 and 1.0)

    • out style args = write each processor’s sub-domain to a file

      • style = mdump or vtk

        • mdump filename = output file in Pizza.py mdump tool format

          • filename = name of file

        • vtk filename = output file in vtk format

          • filename = name of file (.vtk will be automatically appended to name)

Examples#

balance 0.9 x uniform y 0.4 0.5 0.6
balance 1.2 shift xz 5 1.1
balance 1.0 shift xz 5 1.1
balance 1.0 shift x 20 1.0 out vtk post/balance
balance 1.0 shift x 20 1.0 procminsize 0.005 out vtk post/balance

Description#

This command adjusts the size of processor sub-domains within the simulation box, to attempt to balance the number of particles and thus the computational cost (load) evenly across processors. The load balancing is “static” in the sense that this command performs the balancing once, before or between simulations. The processor sub-domains will then remain static during the subsequent run. To perform “dynamic” balancing, see the fix balance command, which can adjust processor sub-domain sizes on-the-fly during a run.

Load-balancing is typically most useful if the particles in the simulation box have a spatially-varying density distribution or when the computational cost varies significantly between different particles. E.g. a model of a vapour/liquid interface, or a solid with an irregular-shaped geometry containing void regions. In these cases, the LAMMPS default of dividing the simulation box volume into a regular-spaced grid of 3d bricks, with one equal-volume sub-domain per processor, may assign numbers of particles per processor in a way that the computational effort varies significantly. This can lead to poor performance when the simulation is run in parallel.

Currently, the balancing is performed without per-particle weighting, i.e., the balancing attempts to assign an equal number of particles to each processor.

Note that the processors command allows some control over how the box volume is split across processors. Specifically, for a Px by Py by Pz grid of processors, it allows choice of Px, Py, and Pz, subject to the constraint that Px * Py * Pz = P, the total number of processors. This is sufficient to achieve good load-balance for some problems on some processor counts. However, all the processor sub-domains will still have the same shape and same volume.

The requested load-balancing operation is only performed if the current “imbalance factor” in particles owned by each processor exceeds the specified thresh parameter. The imbalance factor is defined as the maximum number of particles owned by any processor, divided by the average number of particles per processor. Thus an imbalance factor of 1.0 is perfect balance.

As an example, for 10000 particles running on 10 processors, if the most heavily loaded processor has 1200 particles, then the factor is 1.2, meaning there is a 20% imbalance. Note that a re-balance can be forced even if the current balance is perfect (1.0) be specifying a thresh < 1.0.

When the balance command completes, it prints statistics about the result, including the change in the imbalance factor and the change in the maximum number of particles on any processor. For “grid” methods (defined below) that create a logical 3d grid of processors, the positions of all cutting planes in each of the 3 dimensions (as fractions of the box length) are also printed.

Note

This command attempts to minimise the imbalance factor, as defined above. But depending on the method a perfect balance (1.0) may not be achieved. For example, “grid” methods (defined below) that create a logical 3d grid cannot achieve perfect balance for many irregular distributions of particles. Likewise, if a portion of the system is a perfect lattice, e.g. the initial system is generated by the create_atoms command, then “grid” methods may be unable to achieve exact balance. This is because entire lattice planes will be owned or not owned by a single processor.

Note

The imbalance factor is also an estimate of the maximum speed-up you can hope to achieve by running a perfectly balanced simulation versus an imbalanced one. In the example above, the 10000 particle simulation could run up to 20% faster if it were perfectly balanced, versus when imbalanced. However, computational cost is not strictly proportional to particle count, and changing the relative size and shape of processor sub-domains may lead to additional computational and communication overheads. Thus you should benchmark the run times of a simulation before and after balancing.

Note

The load balancing can be used for spherical, multisphere and superquadric particles.


The method used to perform a load balance is specified by one of the listed styles (or more in the case of x, y, z), which are described in detail below.

The x, y, z, and shift styles are “grid” methods which produce a logical 3d grid of processors. They operate by changing the cutting planes (or lines) between processors in 3d (or 2d), to adjust the volume (area in 2d) assigned to each processor, as in the following 2d diagram where processor sub-domains are shown and particles are coloured by the processor that owns them.

../../../_images/balance.jpg

The top row of diagrams shows the default partitioning of the simulation box across processors (one sub-box for each of 9 processors) while the bottom row shows the shift style “grid” method being performed.


The x, y, and z styles invoke a “grid” method for balancing, as described above. Note that any or all of these 3 styles can be specified together, one after the other, but they cannot be used with any other style. This style adjusts the position of cutting planes between processor sub-domains in specific dimensions. Only the specified dimensions are altered.

The uniform argument spaces the planes evenly, as in the left diagram above. The numeric argument requires listing Ps-1 numbers that specify the position of the cutting planes. This requires knowing Ps = Px or Py or Pz = the number of processors assigned by LAMMPS to the relevant dimension. This assignment is made (and the Px, Py, Pz values printed out) when the simulation box is created by the create_box or read_data or read_restart command and is influenced by the settings of the processors command.

Each of the numeric values must be between 0 and 1, and they must be listed in ascending order. They represent the fractional position of the cutting place. The left (or lower) edge of the box is 0.0, and the right (or upper) edge is 1.0. Neither of these values is specified. Only the interior Ps-1 positions are specified. Thus is there are 2 processors in the x dimension, you specify a single value such as 0.75, which would make the left processor’s sub-domain 3x larger than the right processor’s sub-domain.


The shift style invokes a “grid” method for balancing, as described above. It changes the positions of cutting planes between processors in an iterative fashion, seeking to reduce the imbalance factor.

The dimstr argument is a string of characters, each of which must be an “x” or “y” or “z”. Each character can appear zero or one time, since there is no advantage to balancing on a dimension more than once. You should normally only list dimensions where you expect there to be a density variation in the particles.

Balancing proceeds by adjusting the cutting planes in each of the dimensions listed in dimstr, one dimension at a time. For a single dimension, the balancing operation (described below) is iterated on up to Niter times. After each dimension finishes, the imbalance factor is re-computed, and the balancing operation halts if the stopthresh criterion is met.

A re-balance operation in a single dimension is performed using a recursive multisectioning algorithm, where the position of each cutting plane (line in 2d) in the dimension is adjusted independently. This is similar to a recursive bisectioning for a single value, except that the bounds used for each bisectioning take advantage of information from neighbouring cuts if possible. At each iteration, the count of particles on either side of each plane is tallied. If the counts do not match the target value for the plane, the position of the cut is adjusted to be halfway between a low and high bound. The low and high bounds are adjusted on each iteration, using new count information, so that they become closer together over time. Thus as the recursion progresses, the count of particles on either side of the plane gets closer to the target value.

After the balanced plane positions are determined, if any pair of adjacent planes are closer together than the neighbour skin distance (as specified by the neigh_modify command), then the plane positions are shifted to separate them by at least this amount. This is to prevent particles being lost when dynamics are run with processor sub-domains that are too narrow in one or more dimensions.

Once the re-balancing is complete and final processor sub-domains assigned, particles are migrated to their new owning processor, and the balance procedure ends.

Note

At each re-balance operation, the bisectioning for each cutting plane (line in 2d) typically starts with low and high bounds separated by the extent of a processor’s sub-domain in one dimension. The size of this bracketing region shrinks by 1/2 every iteration. Thus if Niter is specified as 10, the cutting plane will typically be positioned to 1 part in 1000 accuracy (relative to the perfect target position). For Niter = 20, it will be accurate to 1 part in a million. Thus there is no need to set Niter to a large value. LIGGGHTS will check if the threshold accuracy is reached (in a dimension) is less iterations than Niter and exit early. However, Niter should also not be set too small, since it will take roughly the same number of iterations to converge even if the cutting plane is initially close to the target value.


The optional procminsize keyword is used to set a hard limit for the minimum size of the sub-domain allocated to the processors. The default value is zero which is recommended for spherical and superquadric particles. For multisphere particles, it is recommended to set procminsize to at least larger than the multisphere (clump) particle size (not the subsphere size). This is to eliminate warnings given by LIGGGHTS when the sub-domain size is too small for multiphere cases.


The optional splitlimit keyword can be used to limit how aggressively cutting planes are moved during a re-balance operation. The specified value must be between 0.0 and 1.0. This value acts as a multiplier against the initial distance to the adjacent cutting plane; for example, setting a limit of 0.5 restricts a cutting plane from shifting more than 50% of the distance into the neighbouring processor’s original domain.


The out keyword writes a text file to the specified filename with the results of the balancing operation. The file contains the bounds of the sub-domain for each processor after the balancing operation completes. There are two file formats which can be chosen.

The mdump format is compatible with the Pizza.py mdump tool which has support for manipulating and visualising mesh files. An example is shown here for a balancing by 4 processors for a 2d problem:

ITEM: TIMESTEP
0
ITEM: NUMBER OF NODES
16
ITEM: BOX BOUNDS
0 10
0 10
0 10
ITEM: NODES
1 1 0 0 0
2 1 5 0 0
3 1 5 5 0
4 1 0 5 0
5 1 5 0 0
6 1 10 0 0
7 1 10 5 0
8 1 5 5 0
9 1 0 5 0
10 1 5 5 0
11 1 5 10 0
12 1 10 5 0
13 1 5 5 0
14 1 10 5 0
15 1 10 10 0
16 1 5 10 0
ITEM: TIMESTEP
0
ITEM: NUMBER OF SQUARES
4
ITEM: SQUARES
1 1 1 2 3 4
2 1 5 6 7 8
3 1 9 10 11 12
4 1 13 14 15 16

The coordinates of all the vertices are listed in the “NODES” section, 5 per processor. Note that the 4 sub-domains share vertices, so there will be duplicate nodes in the list. The “SQUARES” section lists the node IDs of the 4 vertices in a rectangle for each processor (1 to 4). For a 3d problem, the syntax is similar with 8 vertices listed for each processor, instead of 4, and “SQUARES” replaced by “CUBES”.

The vtk format generates an ASCII rectilinear grid dataset vtk file which can be visualised by ParaView. An example is given below for the same 2D problem above. For a 3d problem, more than one “Z_COORDINATES” will be given.

# vtk DataFile Version 4.2
Generated by WASHLIGGGHTS
ASCII
DATASET RECTILINEAR_GRID
DIMENSIONS 3 3 1
X_COORDINATES 3 float
0.0 5.0 10.0
Y_COORDINATES 3 float
0.0 5.0 10.0
Z_COORDINATES 1 float
0.0

Restrictions#

This command cannot be used together with meshes (e.g. a fix mesh/surface command). To use load balancing with meshes, see the fix balance command.

For 2d simulations, the z style cannot be used. Nor can a “z” appear in dimstr for the shift style.

Default#

procminsize = 0, splitlimit = 0.5