Skip to content

Instantly share code, notes, and snippets.

@charnley
Created January 31, 2019 12:11
Show Gist options
  • Save charnley/f411dd045f64e0b40177795fed7112b9 to your computer and use it in GitHub Desktop.
Save charnley/f411dd045f64e0b40177795fed7112b9 to your computer and use it in GitHub Desktop.
multiprocessing
import multiprocessing as mp
workers = mp.cpu_count()
multithread = False
if multithread:
workers /= 2
def submit_molecule(mol):
return_value = os.popen("../../run_gms "+mol).read()
N = len(dirs) / workers
Nl = len(dirs) % workers
def worker(id, dirs):
# Define work interval
start = N*id
stop = N*id + N
# Distribute leftover work
if(stop == N*workers and Nl > 0):
stop += Nl
local_dirs = dirs[start:stop]
for d in local_dirs:
print d
os.chdir(d)
for f in s22:
submit_molecule('s22_'+f+'_a')
submit_molecule('s22_'+f+'_b')
submit_molecule('s22_'+f+'_c')
for f in s66:
submit_molecule('s66_'+f+'_a')
submit_molecule('s66_'+f+'_b')
submit_molecule('s66_'+f+'_c')
os.chdir('..')
processes = [mp.Process(target=worker, args=(i, dirs)) for i in xrange(workers)]
for p in processes: p.start() # Fork
for p in processes: p.join() # Join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment