def set_communicator(world, rank, size, kcommsize=None):
    """Communicator inilialized."""
    # wcomm is always set to world

    wcomm = world
    
    if kcommsize is None or kcommsize == size or size == 1:
        # By default, only use parallization in kpoints
        # then kcomm is set to world communicator
        # and wS is not parallelized
        kcomm = world
        wScomm = serial_comm
        
    else:
        # If use wS parallization for storage of spectral function
        # then new kpoint and wS communicator are generated
        assert kcommsize != size
        r0 = (rank // kcommsize) * kcommsize
        ranks = np.arange(r0, r0 + kcommsize)
        kcomm = world.new_communicator(ranks)

        # wS comm generated
        r0 = rank % kcommsize
        ranks = np.arange(r0, r0+size, kcommsize)
        wScomm = world.new_communicator(ranks)

    return kcomm, wScomm, wcomm
Esempio n. 2
0
def set_communicator(world, rank, size, kcommsize=None):
    """Communicator inilialized."""
    # wcomm is always set to world

    wcomm = world

    if kcommsize is None or kcommsize == size or size == 1:
        # By default, only use parallization in kpoints
        # then kcomm is set to world communicator
        # and wS is not parallelized
        kcomm = world
        wScomm = serial_comm

    else:
        # If use wS parallization for storage of spectral function
        # then new kpoint and wS communicator are generated
        assert kcommsize != size
        r0 = (rank // kcommsize) * kcommsize
        ranks = np.arange(r0, r0 + kcommsize)
        kcomm = world.new_communicator(ranks)

        # wS comm generated
        r0 = rank % kcommsize
        ranks = np.arange(r0, r0 + size, kcommsize)
        wScomm = world.new_communicator(ranks)

    return kcomm, wScomm, wcomm
Esempio n. 3
0
def main():
    from gpaw.grid_descriptor import GridDescriptor
    from gpaw.mpi import world

    serial = world.new_communicator([world.rank])

    # Generator which must run on all ranks
    gen = np.random.RandomState(0)

    # This one is just used by master
    gen_serial = np.random.RandomState(17)

    maxsize = 5
    for i in range(1):
        N1_c = gen.randint(1, maxsize, 3)
        N2_c = gen.randint(1, maxsize, 3)

        gd1 = GridDescriptor(N1_c, N1_c)
        gd2 = GridDescriptor(N2_c, N2_c)
        serial_gd1 = gd1.new_descriptor(comm=serial)
        serial_gd2 = gd2.new_descriptor(comm=serial)

        a1_serial = serial_gd1.empty()
        a1_serial.flat[:] = gen_serial.rand(a1_serial.size)

        if world.rank == 0:
            print('r0: a1 serial', a1_serial.ravel())

        a1 = gd1.empty()
        a1[:] = -1

        grid2grid(world, serial_gd1, gd1, a1_serial, a1)

        print(world.rank, 'a1 distributed', a1.ravel())
        world.barrier()

        a2 = gd2.zeros()
        a2[:] = -2
        grid2grid(world, gd1, gd2, a1, a2)
        print(world.rank, 'a2 distributed', a2.ravel())
        world.barrier()

        #grid2grid(world, gd2, gd2_serial

        gd1 = GridDescriptor(N1_c, N1_c * 0.2)
        #serialgd = gd2.new_descriptor(

        a1 = gd1.empty()
        a1.flat[:] = gen.rand(a1.size)

        #print a1
        grid2grid(world, gd1, gd2, a1, a2)
Esempio n. 4
0
def test(xc, tol=5e-10):
    N_c = np.array([10, 6, 4])
    # This test is totally serial.
    gd = GridDescriptor(N_c,
                        N_c * 0.2,
                        pbc_c=(1, 0, 1),
                        comm=world.new_communicator([world.rank]))
    actual_n = N_c - (1 - gd.pbc_c)

    gen = np.random.RandomState(17)
    n_sg = gd.zeros(2)
    n_sg[:] = gen.rand(*n_sg.shape)
    #sigma_xg = gd.zeros(3)
    #sigma_xg[:] = gen.random.rand(*sigma_xg.shape)

    if hasattr(xc, 'libvdwxc'):
        xc._nspins = 2
        xc.initialize_backend(gd)

    v_sg = gd.zeros(2)
    E = xc.calculate(gd, n_sg, v_sg)
    print('E', E)

    dn = 1e-6

    all_indices = itertools.product(range(2), range(1, actual_n[0], 2),
                                    range(0, actual_n[1], 2),
                                    range(0, actual_n[2], 2))

    for testindex in all_indices:
        n1_sg = n_sg.copy()
        n2_sg = n_sg.copy()
        v = v_sg[testindex] * gd.dv
        n1_sg[testindex] -= dn
        n2_sg[testindex] += dn

        E1 = xc.calculate(gd, n1_sg, v_sg.copy())
        E2 = xc.calculate(gd, n2_sg, v_sg.copy())

        dedn = 0.5 * (E2 - E1) / dn
        err = abs(dedn - v)
        print('{}{} v={} fd={} err={}'.format(xc.name, list(testindex), v,
                                              dedn, err))
        assert err < tol, err
Esempio n. 5
0
B = parsize_bands   # number of blocks
    
G = 120  # number of grid points (G x G x G)
N = 2000  # number of bands

h = 0.2        # grid spacing
a = h * G      # side length of box
M = N // B     # number of bands per block
assert M * B == N

D = world.size // B  # number of domains
assert D * B == world.size

# Set up communicators:
r = world.rank // D * D
domain_comm = world.new_communicator(np.arange(r, r + D))
band_comm = world.new_communicator(np.arange(world.rank % D, world.size, D))

# Set up grid descriptor:
gd = GridDescriptor((G, G, G), (a, a, a), True, domain_comm, parsize)

# Random wave functions:
np.random.seed(world.rank)
psit_mG = np.random.uniform(-0.5, 0.5, size=(M,) + tuple(gd.n_c))
if world.rank == 0:
    print 'Size of wave function array:', psit_mG.shape

# Send and receive buffers:
send_mG = gd.empty(M)
recv_mG = gd.empty(M)
Esempio n. 6
0
from gpaw.fd_operators import Gradient
import numpy as np
from gpaw.grid_descriptor import GridDescriptor
from gpaw.mpi import world

if world.size > 4:
    # Grid is so small that domain decomposition cannot exceed 4 domains
    assert world.size % 4 == 0
    group, other = divmod(world.rank, 4)
    ranks = np.arange(4 * group, 4 * (group + 1))
    domain_comm = world.new_communicator(ranks)
else:
    domain_comm = world

gd = GridDescriptor((8, 1, 1), (8.0, 1.0, 1.0), comm=domain_comm)
a = gd.zeros()
dadx = gd.zeros()
a[:, 0, 0] = np.arange(gd.beg_c[0], gd.end_c[0])
gradx = Gradient(gd, v=0)
print a.itemsize, a.dtype, a.shape
print dadx.itemsize, dadx.dtype, dadx.shape
gradx.apply(a, dadx)

#   a = [ 0.  1.  2.  3.  4.  5.  6.  7.]
#
#   da
#   -- = [-2.5  1.   1.   1.   1.   1.  1.  -2.5]
#   dx

dadx = gd.collect(dadx, broadcast=True)
assert dadx[3, 0, 0] == 1.0 and np.sum(dadx[:, 0, 0]) == 0.0
Esempio n. 7
0
niter_tolerance = 0

if world.size >= 3:
    calc = GPAW(kpts=[6, 6, 1],
                spinpol=True,
                parallel={'domain': world.size},
                txt='H-a.txt')
    H.set_calculator(calc)
    e1 = H.get_potential_energy()
    niter1 = calc.get_number_of_iterations()
    assert H.get_calculator().wfs.kd.comm.size == 1

    equal(e1, -2.23708481, energy_tolerance)

    if world.rank < 3:
        comm = world.new_communicator(np.array([0, 1, 2]))
        H.set_calculator(
            GPAW(kpts=[6, 6, 1],
                 spinpol=True,
                 communicator=comm,
                 txt='H-b.txt'))
        e2 = H.get_potential_energy()
        assert H.get_calculator().wfs.kd.comm.size == 3
        equal(e1, e2, 5e-9)
    else:
        comm = world.new_communicator(np.array(range(3, world.size)))
        H.set_calculator(
            GPAW(kpts=[6, 6, 1],
                 spinpol=True,
                 communicator=comm,
                 txt='H-b2.txt'))
              cell=(3.5, 3.5, 4. + 2 / 3.),
              pbc=True)

# Only a short, non-converged calcuation
conv = {'eigenstates': 1.24, 'energy': 2e-1, 'density': 1e-1}
calc = GPAW(h=0.30,
            kpts=(1, 1, 3),
            setups={'Na': '1'},
            nbands=3,
            convergence=conv)
atoms.set_calculator(calc)
e0 = atoms.get_potential_energy()
wf0 = calc.get_pseudo_wave_function(2, 1, 1, broadcast=True)
# Write the restart file(s)
for mode in modes:
    calc.write('tmp.%s' % mode, 'all')

del calc
# Now read with single process
comm = world.new_communicator(np.array((rank, )))
for mode in modes:
    calc = GPAW('tmp.%s' % mode, communicator=comm)
    wf1 = calc.get_pseudo_wave_function(2, 1, 1)
    diff = np.abs(wf0 - wf1)
    assert (np.all(diff < 1e-12))

world.barrier()
if rank == 0:
    for mode in modes:
        os.remove('tmp.%s' % mode)
Esempio n. 9
0
#!/usr/bin/env python

import numpy as np
from gpaw import debug, dry_run
from gpaw.mpi import world, serial_comm, _Communicator, \
                     SerialCommunicator, DryRunCommunicator

even_comm = world.new_communicator(np.arange(0, world.size, 2))
if world.size > 1:
    odd_comm = world.new_communicator(np.arange(1, world.size, 2))
else:
    odd_comm = None

if world.rank % 2 == 0:
    assert odd_comm is None
    comm = even_comm
else:
    assert even_comm is None
    comm = odd_comm

hasmpi = False
try:
    import _gpaw
    hasmpi = hasattr(_gpaw, 'Communicator')
except ImportError, AttributeError:
    pass

assert world.parent is None
assert comm.parent is world
if hasmpi:
    assert comm.parent.get_c_object() is world.get_c_object()
Esempio n. 10
0
niter_tolerance = 0

if world.size >= 3:
    calc = GPAW(kpts=[6, 6, 1],
                spinpol=True,
                parallel={'domain': world.size},
                txt='H-a.txt')
    H.set_calculator(calc)
    e1 = H.get_potential_energy()
    niter1 = calc.get_number_of_iterations()
    assert H.get_calculator().wfs.kpt_comm.size == 1

    equal(e1, -2.23708481, energy_tolerance)

    if world.rank < 3:
        comm = world.new_communicator(np.array([0, 1, 2]))
        H.set_calculator(GPAW(kpts=[6, 6, 1],
                              spinpol=True,
                              communicator=comm,
                              txt='H-b.txt'))
        e2 = H.get_potential_energy()
        assert H.get_calculator().wfs.kpt_comm.size == 3
        equal(e1, e2, 5e-9)
    else:
        comm = world.new_communicator(np.array(range(3, world.size)))
        H.set_calculator(GPAW(kpts=[6, 6, 1],
                              spinpol=True,
                              communicator=comm,
                              txt='H-b2.txt'))
        e2 = H.get_potential_energy()
Esempio n. 11
0
if "EON_CLIENT_STANDALONE" in os.environ:
    os.environ["EON_NUMBER_OF_CLIENTS"] = "1"
if "EON_NUMBER_OF_CLIENTS" not in os.environ:
    sys.stderr.write("you must set the env var EON_NUMBER_OF_CLIENTS\n")
    sys.exit(1)
clients = int(os.environ["EON_NUMBER_OF_CLIENTS"])

potential_group_size = potentials / clients

my_client_rank = client_ranks[potential_ranks.index(rank) /
                              potential_group_size]
#print "pot: rank: %i my_client_rank: %i" % (world.rank, my_client_rank)

for i in xrange(clients):
    s = potential_group_size
    new_comm = world.new_communicator(
        numpy.array(potential_ranks[i * s:i * s + s], dtype='i'))
    if new_comm != None:
        my_comm = new_comm

first_time = True
nforce_calls = 0
performance_log = ""
while True:
    nforce_calls += 1
    natoms = numpy.array((0, ), 'i')
    if my_comm.rank == 0:
        world.receive(natoms, my_client_rank, tag=0)
    my_comm.broadcast(natoms, 0)

    atomic_numbers = numpy.zeros(natoms, 'i')
    positions = numpy.zeros(3 * natoms, 'd')
Esempio n. 12
0
        print '-----------'

    if Eref is not None:
        Eerr = abs(E - Eref)
        assert Eerr < 1e-8, 'Bad E: err=%f; parallel=%s' % (Eerr, parallel)
    if Fref is not None:
        Ferr = np.abs(F - Fref).max()
        assert Ferr < 1e-6, 'Bad F: err=%f; parallel=%s' % (Ferr, parallel)
    return E, F

# First calculate reference energy and forces E and F
#
# If we want to really dumb things down, enable this to force an
# entirely serial calculation:
if 0: 
    serial = world.new_communicator([0])
    E = 0.0
    F = np.zeros((len(system), 3))
    if world.rank == 0:
        E, F = calculate({}, serial)
    E = world.sum(E)
    world.sum(F)
else:
    # Normally we'll just do it in parallel;
    # that case is covered well by other tests, so we can probably trust it
    E, F = calculate({}, world)

def check(parallel):
    return calculate(parallel, comm=world, Eref=E, Fref=F)

assert world.size in [1, 2, 4, 8], ('Number of CPUs %d not supported'
Esempio n. 13
0
from ase.build import molecule
from gpaw import GPAW
from gpaw.wavefunctions.pw import PW
from gpaw.mpi import world

a = molecule('H', pbc=1)
a.center(vacuum=2)

comm = world.new_communicator([world.rank])
e0 = 0.0
a.calc = GPAW(mode=PW(250), communicator=comm, txt=None)
e0 = a.get_potential_energy()
e0 = world.sum(e0) / world.size

a.calc = GPAW(mode=PW(250),
              eigensolver='rmm-diis',
              basis='szp(dzp)',
              txt='%d.txt' % world.size)
e = a.get_potential_energy()
f = a.get_forces()
assert abs(e - e0) < 7e-5, abs(e - e0)
assert abs(f).max() < 1e-10, abs(f).max()
Esempio n. 14
0
        potential_ranks.append(i)
if "EON_CLIENT_STANDALONE" in os.environ:
    os.environ["EON_NUMBER_OF_CLIENTS"] = "1"
if "EON_NUMBER_OF_CLIENTS" not in os.environ:
    sys.stderr.write("you must set the env var EON_NUMBER_OF_CLIENTS\n");
    sys.exit(1)
clients = int(os.environ["EON_NUMBER_OF_CLIENTS"])

potential_group_size = potentials/clients

my_client_rank = client_ranks[potential_ranks.index(rank)/potential_group_size]
#print "pot: rank: %i my_client_rank: %i" % (world.rank, my_client_rank)

for i in xrange(clients):
    s = potential_group_size
    new_comm = world.new_communicator(numpy.array(potential_ranks[i*s:i*s+s], dtype='i'))
    if new_comm != None:
        my_comm = new_comm

first_time = True
nforce_calls = 0
performance_log = ""
while True:
    nforce_calls += 1
    natoms = numpy.array((0,), 'i')
    if my_comm.rank == 0:
        world.receive(natoms, my_client_rank, tag=0)
    my_comm.broadcast(natoms, 0)

    atomic_numbers = numpy.zeros(natoms, 'i')
    positions = numpy.zeros(3*natoms, 'd')
Esempio n. 15
0
from __future__ import print_function
import numpy as np
from ase.lattice import bulk
from ase.dft.kpoints import monkhorst_pack
from ase.parallel import paropen

from gpaw import GPAW, PW
from gpaw.mpi import size, rank, world, serial_comm
from gpaw.xc.tools import vxc
from gpaw.xc.hybridg import HybridXC

mgo = bulk('MgO', 'rocksalt', a=4.189)
if rank < 3:
    comm = world.new_communicator(np.arange(min(3, size)))
else:
    comm = world.new_communicator(np.array((rank, )))
if 1:
    mgo.calc = GPAW(mode=PW(500),
                    parallel=dict(band=1),
                    idiotproof=False,
                    communicator=comm,
                    setups={'Mg': '2'},
                    convergence={'eigenstates': 5.e-9},
                    kpts=monkhorst_pack((2, 2, 2)) + 0.25)
    mgo.get_potential_energy()
    if rank < 3:
        mgo.calc.write('mgo', 'all')
    else:
        mgo.calc.write('dummy_%d' % rank, 'all')
    world.barrier()
Esempio n. 16
0
B = parsize_bands  # number of blocks

G = 120  # number of grid points (G x G x G)
N = 2000  # number of bands

h = 0.2  # grid spacing
a = h * G  # side length of box
M = N // B  # number of bands per block
assert M * B == N

D = world.size // B  # number of domains
assert D * B == world.size

# Set up communicators:
r = world.rank // D * D
domain_comm = world.new_communicator(np.arange(r, r + D))
band_comm = world.new_communicator(np.arange(world.rank % D, world.size, D))

# Set up grid descriptor:
gd = GridDescriptor((G, G, G), (a, a, a), True, domain_comm, parsize)

# Random wave functions:
np.random.seed(world.rank)
psit_mG = np.random.uniform(-0.5, 0.5, size=(M, ) + tuple(gd.n_c))
if world.rank == 0:
    print 'Size of wave function array:', psit_mG.shape

# Send and receive buffers:
send_mG = gd.empty(M)
recv_mG = gd.empty(M)
Esempio n. 17
0
from ase.structure import molecule
from gpaw import GPAW
from gpaw.wavefunctions.pw import PW
from gpaw.mpi import world

a = molecule('H', pbc=1)
a.center(vacuum=2)

comm = world.new_communicator([0])
e0 = 0.0
if world.rank == 0:
    a.calc = GPAW(mode=PW(250),
                  communicator=comm,
                  txt=None)
    e0 = a.get_potential_energy()
e0 = world.sum(e0)

a.calc = GPAW(mode=PW(250),
              eigensolver='rmm-diis',
              basis='szp(dzp)',
              txt='%d.txt' % world.size)
e = a.get_potential_energy()
f = a.get_forces()
assert abs(e - e0) < 7e-5, abs(e - e0)
assert abs(f).max() < 1e-10, abs(f).max()

from ase.parallel import parprint as pp

from gpaw import GPAW, PW, restart
from gpaw.response.df import DielectricFunction
from gpaw.mpi import world
from gpaw.version import version
from ase.lattice import bulk

system = Graphene(symbol="C", latticeconstant={"a": 2.45, "c": 1.0}, size=(1, 1, 1))
system.pbc = (1, 1, 0)
system.center(axis=2, vacuum=4.0)

nkpts = 5


communicator = world.new_communicator(np.array([world.rank]))
gpwname = "dump.graphene.gpw"

if world.rank == 0:
    calc = GPAW(
        mode="pw",
        kpts=(nkpts, nkpts, 1),
        communicator=communicator,
        xc="oldLDA",
        nbands=len(system) * 6,
        txt="gpaw.graphene.txt",
    )
    system.set_calculator(calc)
    system.get_potential_energy()
    calc.write(gpwname, mode="all")
from __future__ import print_function
import numpy as np
from ase.lattice import bulk
from ase.dft.kpoints import monkhorst_pack
from ase.parallel import paropen

from gpaw import GPAW, PW
from gpaw.mpi import size, rank, world, serial_comm
from gpaw.xc.tools import vxc
from gpaw.xc.hybridg import HybridXC


mgo = bulk('MgO', 'rocksalt', a=4.189)
if rank < 3:
    comm = world.new_communicator(np.arange(min(3, size)))
else:
    comm = world.new_communicator(np.array((rank,)))
if 1:
    mgo.calc = GPAW(mode=PW(500),
                    parallel=dict(band=1),
                    idiotproof=False,
                    communicator=comm,
                    setups={'Mg': '2'},
                    convergence={'eigenstates': 5.e-9},
                    kpts=monkhorst_pack((2, 2, 2)) + 0.25)
    mgo.get_potential_energy()
    if rank < 3:
       mgo.calc.write('mgo', 'all')
    else:
       mgo.calc.write('dummy_%d' % rank, 'all')
    world.barrier()
Esempio n. 20
0
                              ( 0, d*sqrt(3./4.), d/2.)],
                   magmoms=[1.0, 1.0, 1.0],
                   cell=(3.5, 3.5, 4.+2/3.),
                   pbc=True)

# Only a short, non-converged calcuation
conv = {'eigenstates': 1.24, 'energy':2e-1, 'density':1e-1}
calc = GPAW(h=0.30, kpts=(1,1,3), 
            setups={'Na': '1'},
            nbands=3, convergence=conv)
atoms.set_calculator(calc)
e0 = atoms.get_potential_energy()
wf0 = calc.get_pseudo_wave_function(2, 1, 1, broadcast=True)
# Write the restart file(s)
for mode in modes:
    calc.write('tmp.%s' % mode, 'all')

del calc
# Now read with single process
comm = world.new_communicator(np.array((rank,)))
for mode in modes:
    calc = GPAW('tmp.%s' % mode, communicator=comm)
    wf1 = calc.get_pseudo_wave_function(2, 1, 1)
    diff = np.abs(wf0 - wf1)
    assert(np.all(diff < 1e-12))

world.barrier()
if rank == 0:
    for mode in modes:
        os.remove('tmp.%s' % mode)
Esempio n. 21
0
a = 2.5
H = Atoms('H', cell=[a, a, a], pbc=True)

energy_tolerance = 0.00006
niter_tolerance = 0

if world.size >= 3:
    calc = GPAW(kpts=[6, 6, 1],
                spinpol=True,
                parallel={'domain': world.size},
                txt='H-a.txt')
    H.set_calculator(calc)
    e1 = H.get_potential_energy()
    niter1 = calc.get_number_of_iterations()
    assert H.get_calculator().wfs.kpt_comm.size == 1

    equal(e1, -2.23708481, energy_tolerance)
    equal(niter1, 16, niter_tolerance)

    comm = world.new_communicator(np.array([0, 1, 2]))
    if world.rank < 3:
        H.set_calculator(
            GPAW(kpts=[6, 6, 1],
                 spinpol=True,
                 communicator=comm,
                 txt='H-b.txt'))
        e2 = H.get_potential_energy()
        assert H.get_calculator().wfs.kpt_comm.size == 3
        equal(e1, e2, 1e-11)
Esempio n. 22
0
from ase.parallel import parprint as pp

from gpaw import GPAW
from gpaw.response.df import DielectricFunction
from gpaw.mpi import world

system = Graphene(symbol='C',
                  latticeconstant={'a': 2.45,'c': 1.0},
                  size=(1,1,1))
system.pbc = (1, 1, 0)
system.center(axis=2, vacuum=4.0)

nkpts = 5


communicator = world.new_communicator(np.array([world.rank]))
gpwname = 'dump.graphene.gpw'

if world.rank == 0:
    calc = GPAW(mode='pw',
                kpts=(nkpts, nkpts, 1),
                communicator=communicator,
                xc='oldLDA',
                nbands=len(system) * 6,
                txt='gpaw.graphene.txt')
    system.set_calculator(calc)
    system.get_potential_energy()
    calc.write(gpwname, mode='all')

world.barrier()
Esempio n. 23
0
from ase.structure import molecule
from gpaw import GPAW
from gpaw.wavefunctions.pw import PW
from gpaw.mpi import world

a = molecule('H', pbc=1)
a.center(vacuum=2)

comm = world.new_communicator([world.rank])
e0 = 0.0
a.calc = GPAW(mode=PW(250),
              communicator=comm,
              txt=None)
e0 = a.get_potential_energy()
e0 = world.sum(e0) / world.size

a.calc = GPAW(mode=PW(250),
              eigensolver='rmm-diis',
              basis='szp(dzp)',
              txt='%d.txt' % world.size)
e = a.get_potential_energy()
f = a.get_forces()
assert abs(e - e0) < 7e-5, abs(e - e0)
assert abs(f).max() < 1e-10, abs(f).max()

Esempio n. 24
0
from gpaw.fd_operators import Gradient
import numpy as np
from gpaw.grid_descriptor import GridDescriptor
from gpaw.mpi import world

if world.size > 4:
    # Grid is so small that domain decomposition cannot exceed 4 domains
    assert world.size % 4 == 0
    group, other = divmod(world.rank, 4)
    ranks = np.arange(4*group, 4*(group+1))
    domain_comm = world.new_communicator(ranks)
else:
    domain_comm = world

gd = GridDescriptor((8, 1, 1), (8.0, 1.0, 1.0), comm=domain_comm)
a = gd.zeros()
dadx = gd.zeros()
a[:, 0, 0] = np.arange(gd.beg_c[0], gd.end_c[0])
gradx = Gradient(gd, v=0)
print a.itemsize, a.dtype, a.shape
print dadx.itemsize, dadx.dtype, dadx.shape
gradx.apply(a, dadx)

#   a = [ 0.  1.  2.  3.  4.  5.  6.  7.]
#
#   da
#   -- = [-2.5  1.   1.   1.   1.   1.  1.  -2.5]
#   dx

dadx = gd.collect(dadx, broadcast=True)
assert dadx[3, 0, 0] == 1.0 and np.sum(dadx[:, 0, 0]) == 0.0
Esempio n. 25
0
from gpaw.test import equal

a = 2.5
H = Atoms('H', cell=[a, a, a], pbc=True)

energy_tolerance = 0.00006
niter_tolerance = 0

if world.size >= 3:
    calc = GPAW(kpts=[6, 6, 1],
                spinpol=True,
                parallel={'domain': world.size},
                txt='H-a.txt')
    H.set_calculator(calc)
    e1 = H.get_potential_energy()
    niter1 = calc.get_number_of_iterations()
    assert H.get_calculator().wfs.kpt_comm.size == 1

    equal(e1, -2.23708481, energy_tolerance)
    equal(niter1, 16, niter_tolerance)

    comm = world.new_communicator(np.array([0, 1, 2]))
    if world.rank < 3:
        H.set_calculator(GPAW(kpts=[6, 6, 1],
                              spinpol=True,
                              communicator=comm,
                              txt='H-b.txt'))
        e2 = H.get_potential_energy()
        assert H.get_calculator().wfs.kpt_comm.size == 3
        equal(e1, e2, 1e-11)
Esempio n. 26
0
    if Eref is not None:
        Eerr = abs(E - Eref)
        assert Eerr < 1e-8, 'Bad E: err=%f; parallel=%s' % (Eerr, parallel)
    if Fref is not None:
        Ferr = np.abs(F - Fref).max()
        assert Ferr < 1e-6, 'Bad F: err=%f; parallel=%s' % (Ferr, parallel)
    return E, F


# First calculate reference energy and forces E and F
#
# If we want to really dumb things down, enable this to force an
# entirely serial calculation:
if 0:
    serial = world.new_communicator([0])
    E = 0.0
    F = np.zeros((len(system), 3))
    if world.rank == 0:
        E, F = calculate({}, serial)
    E = world.sum(E)
    world.sum(F)
else:
    # Normally we'll just do it in parallel;
    # that case is covered well by other tests, so we can probably trust it
    E, F = calculate({}, world)


def check(parallel):
    return calculate(parallel, comm=world, Eref=E, Fref=F)
Esempio n. 27
0
from gpaw.matrix import Matrix
from gpaw.mpi import world

N = 6

if world.rank < 2:
    comm = world.new_communicator([0, 1])
else:
    comm = world.new_communicator([2, 3])

A0 = Matrix(N, N, dist=(comm, 2, 1))
A0.array[:] = world.rank
A = Matrix(N, N, dist=(world, 2, 2, 2))
A0.redist(A)
world.barrier()
print(A.array)
A0.array[:] = 117
A.redist(A0, 0)
print(A0.array)
Esempio n. 28
0
        client_ranks[k] = i
        k += 1
    elif process_types[i] == 2:
        if first_potential_rank == None:
            first_potential_rank = i
        potential_ranks[j] = i
        j += 1

my_potential_rank = world.rank - first_potential_rank

my_client_rank = client_ranks[my_potential_rank / potential_group_size]
print "pot: rank: %i my_client_rank: %i" % (world.rank, my_client_rank)

for i in xrange(clients):
    s = potential_group_size
    new_comm = world.new_communicator(potential_ranks[i * s:i * s + s])
    if new_comm != None:
        my_comm = new_comm

first_time = True
while True:
    natoms = numpy.array((0, ), 'i')
    if my_comm.rank == 0:
        world.receive(natoms, my_client_rank, tag=0)
    my_comm.broadcast(natoms, 0)

    atomic_numbers = numpy.zeros(natoms, 'i')
    positions = numpy.zeros(3 * natoms, 'd')
    cell = numpy.zeros(9, 'd')
    pbc = numpy.array((0, ), 'i')
    if my_comm.rank == 0:
Esempio n. 29
0
        client_ranks[k] = i
        k += 1
    elif process_types[i] == 2:
        if first_potential_rank == None:
            first_potential_rank = i
        potential_ranks[j] = i
        j += 1

my_potential_rank = world.rank-first_potential_rank

my_client_rank = client_ranks[my_potential_rank/potential_group_size]
print "pot: rank: %i my_client_rank: %i" % (world.rank, my_client_rank)

for i in xrange(clients):
    s = potential_group_size
    new_comm = world.new_communicator(potential_ranks[i*s:i*s+s])
    if new_comm != None:
        my_comm = new_comm

first_time = True
while True:
    natoms = numpy.array((0,), 'i')
    if my_comm.rank == 0:
        world.receive(natoms, my_client_rank, tag=0)
    my_comm.broadcast(natoms, 0)

    atomic_numbers = numpy.zeros(natoms, 'i')
    positions = numpy.zeros(3*natoms, 'd')
    cell = numpy.zeros(9, 'd')
    pbc = numpy.array((0,), 'i')
    if my_comm.rank == 0: