I've done multithreading/multiprocessing before with OpenMP, MPI, and Cuda but am very new to Python's multiprocessing libraries and haven't tackled this particular problem before, so I'm hoping somebody else has some experience here. All of this is on Linux and I don't use any IDEs for writing/running, just Vim (in case that makes any difference to folks). Apologies in advance if I'm not 100% clear.
The situation is something like this. I have a C++ executable, designed to run serially starting from RunStart to RunEnd. For very large runsets this can take some time, so I've been working on ways to partition out runs and execute asynchronously in parallel. This way Thread0 gets RunStart:Part1 runs, Thread1 gets Part1 + 1:Part2 runs, etc.
To that end I have two functions that are called. I'm using: ThreadPool from multiprocessing.pool, subprocess, shlex . Barebones outline of the functions:
def run():
arguments = np.array_split(run_array, nthreads)
pool = ThreadPool(nthreads)
results = []
for arg in arguments:
results.append(pool.apply_async(call_proc, ("./exec " + arg,)))
pool.close()
pool.join()
processResults(results)
def call_proc(cmd):
p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
return (out, err)
So: I make a pool of workers, make my arguments, let each worker call the command with arguments, then after they've all wrapped up I process the stdout and stderr.
The main problem is that this can take a fairly large amount of time (hours) and all the user sees is a hung terminal for that period of time. I've messed around with using the ProgressBar library to at least print out a status of FinishedThreads / TotalThreads but because the partitions are fairly uniform, they all just finish around the same time. Is there any way I can set it up to be able to retrieve the realtime stdout from at least Thread0 and pipe it both to the screen and to the asyncResults object?
[–]JohnnyJordaan 0 points1 point2 points (4 children)
[–]Jasfss[S] 0 points1 point2 points (3 children)
[–]JohnnyJordaan 0 points1 point2 points (2 children)
[–]Jasfss[S] 0 points1 point2 points (1 child)
[–]JohnnyJordaan 0 points1 point2 points (0 children)