The production and space-time evolution of charm and bottom quarks in nucleus-nucleus collisions at RHIC and LHC are investigated with the partonic transport model BAMPS (Boltzmann Approach of MultiParton Scatterings). Heavy quarks, produced in primary hard parton scatterings during nucleon-nucleon collisions, are sampled using the Monte Carlo event generator PYTHIA or the leading order mini-jet model in conjunction with the Glauber model, revealing a strong sensitivity on the parton distribution functions, scales, and heavy quark mass. In a comprehensive study exploring different charm masses, K factors, and possible initial gluon conditions, secondary production and the evolution of heavy quarks are examined within a fully dynamic BAMPS simulation for central heavy ion collisions at RHIC and LHC. Although charm production in the quark-gluon plasma can be neglected at RHIC, it is significant at LHC but very sensitive to the initial conditions and the charm mass. Bottom production in the quark-gluon plasma, however, is negligible both at RHIC and LHC.