  The paper presents ab initio results on the structural phase stability of
beryllium and magnesium crystals under high and ultrahigh pressures
(multi-terapascal regime). Magnesium is shown to undergo a number of structural
transformations which markedly reduce the crystal packing factor. As for
beryllium, its high-pressure body-centered cubic phase remains stable even
under ultrahigh pressures. Changes in the electronic structure of Be and Mg
crystals under compression are analyzed and some interesting effects are
revealed. Specifically, a narrow band gap appears in the electronic structure
of magnesium under pressures above 2.5 TPa. For the metals of interest,
PT-diagrams are constructed and compared with available experimental and
theoretical results from other investigations.
