File: ase_mp.py

package info (click to toggle)
python-dynasor 2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,008 kB
  • sloc: python: 5,263; sh: 20; makefile: 3
file content (36 lines) | stat: -rw-r--r-- 1,062 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import timeit

import numpy as np

from ase.io import read, write  # noqa
from ase.build import bulk

from dynasor.trajectory.extxyz_trajectory_reader import ExtxyzTrajectoryReader  # noqa


fname = 'atoms.extxyz'
frames = 100
atoms = 2000


atoms = bulk('Al').repeat((atoms, 1, 1))

momenta = np.random.random(size=atoms.positions.shape)
atoms.set_momenta(momenta)
atoms.info['Time'] = 1.0
atoms.set_tags(np.ones(len(atoms)))

print(f'Number of atoms:  {len(atoms)}')
print(f'Number of frames: {frames}')
print(f'Number of bytes:  {frames * len(atoms) * 1.8 / 2**12 / 2**12:.3f} GB')

write(fname, [atoms]*frames)
timer = timeit.Timer("read(fname, index=':')", globals=globals())  # noqa
N, T = timer.autorange()
print(f'Time ASE: {T/N:<10.5f}', flush=True)
T0 = T/N
for n in [2, 3, 4, 5, 6, 8, 12]:
    timer = timeit.Timer('list(ExtxyzTrajectoryReader(fname, max_workers=n))', globals=globals())
    N, T = timer.autorange()
    print(f'Workers: {n}  Time: {T/N:<10.5f}  Speedup: {T0/(T/N):<10.5f}  '
          f'Efficiency: {T0/(T/N)/n:<10.5f}', flush=True)