Write MPI parallel for 2d/3d periodic grids