Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. import multiprocessing
  2. import subprocess
  3. import os
  4.  
  5. def init(queue):
  6. global gpuid
  7. gpuid = queue.get()
  8.  
  9. gpus_list = list(range(8))
  10. num_gpus = len(gpus_list)
  11. manager = multiprocessing.Manager()
  12. gpuQueue = manager.Queue()
  13. [gpuQueue.put(i) for i in gpus_list]
  14.  
  15. filename = 'evaluate_experiment.py'
  16.  
  17. def f(snap_dir, env):
  18. global gpuid
  19. env = env.copy()
  20. env['CUDA_VISIBLE_DEVICES'] = str(gpuid)
  21. print(gpuid, snap_dir)
  22. command = ['python', filename, '--snap_dir', snap_dir]
  23. command = list(map(str, command))
  24. subprocess.run(command, env=env)
  25. return ' '.join(command)
  26.  
  27. snap_dirs = os.listdir('/homes/agolinsk/code/sylvester-flows-ortho/snapshots')
  28. env = os.environ.copy()
  29.  
  30. with multiprocessing.Pool(num_gpus, init, (gpuQueue,)) as p:
  31. res = [p.apply_async(f, (snap_dir, env)) for snap_dir in snap_dirs]
  32. print([r.get() for r in res])
  33.  
  34. print("Done")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement