The initial mass function for massive stars in the Galaxy and the Magellanic Clouds