Molecular dynamics (MD) simulations play an important role in studying heat transport in complex materials. The lattice thermal conductivity can be computed either using the Green-Kubo formula in equilibrium MD (EMD) simulations or using Fourier's law in nonequilibrium MD (NEMD) simulations. These two methods have not been systematically compared for materials with different dimensions and inconsistencies between them have been occasionally reported in the literature. Here we give an in-depth comparison of them in terms of heat transport in three allotropes of Si: three-dimensional bulk silicon, two-dimensional silicene, and quasi-one-dimensional silicon nanowire. By multiplying the correlation time in the Green-Kubo formula with an appropriate effective group velocity, we can express the running thermal conductivity in the EMD method as a function of an effective length and directly compare it to the length-dependent thermal conductivity in the NEMD method. We find that the two methods quantitatively agree with each other for all the systems studied, firmly establishing their equivalence in computing thermal conductivity.