modified diagonalize_elemental.cpp