Elementary divisors and ranked posets with application to matrix compounds