1import pytest 2from gpaw.utilities.elpa import LibElpa 3import numpy as np 4from gpaw.blacs import BlacsGrid 5from gpaw.mpi import world 6 7pytestmark = pytest.mark.skipif(not LibElpa.have_elpa(), 8 reason='not LibElpa.have_elpa()') 9 10 11def test_libelpa(): 12 rng = np.random.RandomState(87878787) 13 14 if world.size == 1: 15 shape = 1, 1 16 else: 17 shape = world.size // 2, 2 18 bg = BlacsGrid(world, *shape) 19 20 M = 8 21 blocksize = 2 22 23 desc = bg.new_descriptor(M, M, blocksize, blocksize) 24 sdesc = desc.as_serial() 25 26 Aserial = sdesc.zeros() 27 if world.rank == 0: 28 Aserial[:] = rng.rand(*Aserial.shape) 29 Aserial += Aserial.T.copy() 30 A = desc.distribute_from_master(Aserial) 31 C1 = desc.zeros() 32 C2 = desc.zeros() 33 eps1 = np.zeros(M) 34 eps2 = np.zeros(M) 35 36 elpa = LibElpa(desc) 37 print(elpa) 38 39 desc.diagonalize_dc(A.copy(), C1, eps1), 40 41 elpa.diagonalize(A.copy(), C2, eps2) 42 43 print(eps1) 44 print(eps2) 45 err = np.abs(eps1 - eps2).max() 46 assert err < 1e-13, err 47