Skip to content

Commit

Permalink
Fix the issue in parallel gulp relaxation
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhu2017 committed Aug 22, 2024
1 parent 0943e9f commit 42279ff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
25 changes: 21 additions & 4 deletions pyxtal/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,15 @@ def gulp_opt_par(ids, xtals, ff, path, criteria):
"""
results = []
for id, xtal in zip(ids, xtals):
res = gulp_opt_single(id, xtal, ff, path, criteria)
folder = path + '/g' + str(id)
res = gulp_opt_single(id, xtal, ff, folder, criteria)
(xtal, eng, status) = res
if status:
results.append((id, xtal, eng))
try:
os.rmdir(folder)
except:
print("Folder is not empty", folder)
return results


Expand Down Expand Up @@ -985,6 +990,7 @@ def update_row_ff_energy(

os.makedirs(calc_folder, exist_ok=True)
ids, xtals = self.select_xtals(ids, overwrite, "ff_energy")
assert len(ids) == len(set(ids))

if len(ids) > 0:
gulp_results = []
Expand All @@ -1006,10 +1012,21 @@ def update_row_ff_energy(
print("\n# Parallel GULP optimizations", ncpu, N_cycle, len(ids))
args_list = []

#for i in range(ncpu):
# id1 = i * N_cycle
# id2 = min([id1 + N_cycle, len(ids)])
# args_list.append((ids[id1:id2], xtals[id1:id2], ff, calc_folder, criteria))

# Partition to ensure that each proc get the a similar load for the sorted structures
for i in range(ncpu):
id1 = i * N_cycle
id2 = min([id1 + N_cycle, len(ids)])
args_list.append((ids[id1:id2], xtals[id1:id2], ff, calc_folder, criteria))
par_ids = []
par_xtals = []
for j in range(N_cycle):
_id = j * ncpu + i
if _id < len(ids):
par_ids.append(ids[_id])
par_xtals.append(xtals[_id])
args_list.append((par_ids, par_xtals, ff, calc_folder, criteria))

with ProcessPoolExecutor(max_workers=ncpu) as executor:
results = [executor.submit(gulp_opt_par, *p) for p in args_list]
Expand Down
6 changes: 6 additions & 0 deletions pyxtal/interface/gulp.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,17 @@ def set_catlow(self):
"""

def run(self, clean=True):
"""
Always go to the directory to run one gulp at once
"""
cwd = os.getcwd()
os.chdir(self.folder)
self.write()
self.execute()
self.read()
if clean:
self.clean()
os.chdir(cwd)

def execute(self):
cmd = self.exe + "<" + self.input + ">" + self.output
Expand Down

0 comments on commit 42279ff

Please sign in to comment.