A pseudospectral algorithm for three-dimensional magnetohydrodynamic simulation