Star formation in the centers of galaxies is thought to yield massive stars with a possibly top-heavy stellar mass distribution . It is likely that magnetic fields play a crucial role in the distribution of stellar masses inside star-forming molecular clouds . In this context , we explore the effects of magnetic fields , with a typical field strength of 38 \mu G , such as in RCW 38 , and a field strength of 135 \mu G , similar to NGC 2024 and the infrared dark cloud G28.34+0.06 , on the initial mass function ( IMF ) near ( \leq 10 pc ) a 10 ^ { 7 } solar mass black hole . Using these conditions , we perform a series of numerical simulations with the hydrodynamical code FLASH to elucidate the impact of magnetic fields on the IMF and the star-formation efficiency ( SFE ) emerging from an 800 solar mass cloud . We find that the collapse of a gravitationally unstable molecular cloud is slowed down with increasing magnetic field strength and that stars form along the field lines . The total number of stars formed during the simulations increases by a factor of 1.5 - 2 with magnetic fields . The main component of the IMF has a lognormal shape , with its peak shifted to sub-solar ( \leq 0.3 M _ { \odot } ) masses in the presence of magnetic fields , due to a decrease in the accretion rates from the gas reservoir . In addition , we see a top-heavy , nearly flat IMF above \sim 2 solar masses , from regions that were supported by magnetic pressure until high masses are reached . We also consider the effects of X-ray irradiation if the central black hole is active . X-ray feedback inhibits the formation of sub-solar masses and decreases the SFEs even further . Thus , the second contribution is no longer visible . We conclude that magnetic fields potentially change the SFE and the IMF both in active and inactive galaxies , and need to be taken into account in such calculations . The presence of a flat component of the IMF would be a particularly relevant signature for the importance of magnetic fields , as it is usually not found in simulations .