Numerical prediction of charged particle dynamics in accelerators is essential for the design and understanding of these machines. Methods to calculate the self-fields of the bunch, the so-called space-charge forces, become increasingly important as the demand for high-quality bunches increases. We report on our development of a new three-dimensional (3-D) space-charge routine in the general particle tracer (GPT) code. It scales linearly with the number of particles in terms of CPU time, allowing over a million particles to be tracked on a normal PC. The model is based on a nonequidistant multigrid Poisson solver that has been constructed to solve the electrostatic fields in the rest frame of the bunch on meshes with large aspect ratio. Theoretical and numerical investigations of the behavior of SOR relaxation and PCG method on nonequidistant grids emphasize the advantages of the multigrid algorithm with adaptive coarsening. Numerical investigations have been performed with a wide range of cylindrically shaped bunches (from very long to very short) occuring in recent applications. The application to the simulation of the TU/e DC/RF gun demonstrates the power of the new 3-D routine.