  Nonequilibrium molecular dynamics (NEMD) has been extensively used to study
thermal transport at various length scales in many materials. In this method,
two local thermostats at different temperatures are used to generate a
nonequilibrium steady state with a constant heat flux. Conventionally, the
thermal conductivity of a finite system is calculated as the ratio between the
heat flux and the temperature gradient extracted from the linear part of the
temperature profile away from the local thermostats. Here we show that, with a
proper choice of the thermostat, the nonlinear part of the temperature profile
should actually not be excluded in thermal transport calculations. We compare
NEMD results against those from the atomistic Green's function method in the
ballistic regime, and those from the homogeneous nonequilibrium molecular
dynamics method in the ballistic-to-diffusive regime. These comparisons suggest
that in all the transport regimes, one should directly calculate the thermal
conductance from the temperature difference between the heat source and sink
and, if needed, convert it to the thermal conductivity by multiplying it with
the system length. Furthermore, we find that the Langevin thermostat
outperforms the Nos\'{e}-Hoover (chain) thermostat in NEMD simulations because
of its stochastic and local nature. We show that this is particularly important
for studying asymmetric carbon-based nanostructures, for which the
Nos\'{e}-Hoover thermostat can produce artifacts leading to unphysical thermal
rectification. Our findings are important to obtain correct results from
molecular dynamics simulations of nanoscale heat transport as the accuracy of
the interatomic potentials is rapidly improving.
