Just to correct myself a bit as I didn't pay much attention to the equation. In the reactants, one mole of Mg does indicate the number of Mg atoms but not when dealing with
O2, but we halved the number of molecules of
O2 as this would be equal to one mole of O atoms. However, on the products, MgO has a giant ionic structure and so we cannot regard MgO as either atoms or molecules, but one mole of MgO represents one mole of O and Mg ions within the structure.
Hope this makes
Mg+21O2→MgO.