  We study the production of $D^0$ meson in $p$+$p$ and $p-$Pb collisions using
the improved AMPT model considering both coalescence and independent
fragmentation of charm quarks after the Cronin broadening are included. After a
detailed discussion of the improvements implemented in the AMPT model for heavy
quark production, we show that the modified AMPT model can provide good
description of $D^0$ meson spectra in $p-$Pb collisions, the $Q_{\rm pPb}$ data
at different centrality and $R_{\rm pPb}$ data in both mid- and forward
(backward) rapidities. We also studied the effects of nuclear shadowing and
parton cascade on the rapidity dependence of $D^{0}$ meson production and
$R_{\rm pPb}$. Our results indicate that having the same strength of the Cronin
(i.e $\delta$ value) obtained from the mid-rapidity data leads to a
considerable overestimation of the $D^0$ meson spectra and $R_{\rm pPb}$ data
at high $p_{T}$ in the backward rapidity. As a result, the $\delta$ is
determined via a $\chi^2$ fitting of the $R_{\rm pPb}$ data across various
rapidities. This work lays the foundation for a better understanding of
cold-nuclear-matter (CNM) effects in relativistic heavy-ion collisions.
