grid dimension of the problem. We denote the processor number by [ncpus]{} and the directional processor numbers as [nprocx]{}, [nprocy]{}, [nprocz]{}.

Changes made to the Pencil Code
-------------------------------

### Memory optimisation {#s:memory}

![Scaling test for particle-mesh problem with $512^3$ grid cells and $64\times10^6$ particles. The particles are distributed evenly over the grid, so that each core has the same number of particles. The inverse code speed is normalised by the number of time-steps and by either the total number of grid points and particles (top panel) or by the number of grid points and particles per core (bottom panel).[]{data-label="f:timings"}](timings.eps){width="8.7cm"}

We had to remove several uses of [*global*]{} arrays, i.e. 2-D or 3-D arrays of linear size equal to the full grid. This mostly affected certain special initial conditions and boundary conditions. An additional problem was the use of an array of size [(ncpus,ncpus)]{} in the particle communication. This array was replaced by a 1-D array with no problems.

The runtime calculation of 2-D averages (e.g. gas and particle column density) was done in such a way that the whole [(nxgrid,nygrid)]{} array was collected at the root processor in an array of size [(nxgrid,nygrid,ncpus)]{}, before appending a chunk of size [(nxgrid,nygrid)]{} 