-
-
Save kris-singh/5bbd24933089ecad452c04218d278f8d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from joblib import Parallel, delayed | |
import Queue | |
import os | |
# Define number of GPUs available | |
N_GPU = 4 | |
# Put indices in queue | |
q = Queue.Queue(maxsize=N_GPU) | |
for i in range(N_GPU): | |
q.put(i) | |
def runner(x): | |
gpu = q.get() | |
print (x, gpu) | |
# Put here your job cmd | |
cmd = "python main.py %s" % x | |
os.system("CUDA_VISIBLE_DEVICES=%d %s" % (gpu, cmd)) | |
# return gpu id to queue | |
q.put(gpu) | |
# Change loop | |
Parallel(n_jobs=N_GPU, backend="threading")( | |
delayed(runner)(i) for i in range(100)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment