-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_parallel_writing.py
72 lines (50 loc) · 1.92 KB
/
test_parallel_writing.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from Pool.mpi_pool import MPIPool
import sys,os
from libs.utils import unskewCell,get_standard_frame,s2hms
from libs.input_structure import input2crystal
from libs.LJ_pressure import LJ_vcrelax
import cPickle as pck
import numpy as np
from libs.io import Frame_Dataset_h5
from tqdm import tqdm
from time import time,ctime
def generate_crystal_step_1(sites_z, seed, vdw_ratio, isotropic_external_pressure=1e-2, symprec=1e-5):
crystal, sg, wki = input2crystal(sites_z, seed, vdw_ratio)
crystal = unskewCell(crystal)
crystal = LJ_vcrelax(crystal,isotropic_external_pressure,debug=False)
if crystal is None:
return None
else:
crystal = get_standard_frame(crystal, to_primitive=False, symprec=symprec)
return crystal
def generate_crystal_step_1_wrapper(kwargs):
crystal = generate_crystal_step_1(**kwargs)
if crystal is None:
return kwargs
else:
fout.dump_frames([crystal],[kwargs])
return None
if __name__ == '__main__':
pool = MPIPool()
comm = pool.comm
basename = './structures/relaxed_structures_step1_r'
if not pool.is_master():
rank = comm.Get_rank()
fout = Frame_Dataset_h5(basename + str(rank) + '.h5')
print 'Dumping structures to {}'.format(fout.fname)
# Wait for instructions from the master process.
pool.wait()
sys.exit(0)
vdw_ratio = 1.5
sites_z = [14]
print 'Starting '+ctime()
start = time()
strides = np.arange(2)*10 + int(2e7)
# strides = np.arange(10) * 10 + int(1e7)
for st,nd in zip(strides[:-1],strides[1:]):
print 'Seed from {} to {} {}'.format(st,nd,s2hms(time() - start))
inputs = [{'sites_z':sites_z,'seed':seed,'vdw_ratio':vdw_ratio} for seed in range(st,nd)]
out = pool.map(generate_crystal_step_1_wrapper,inputs,disable_pbar=False)
print out
print 'Elapsed time: {}'.format(s2hms(time()-start))
pool.close()