|
[Sponsors] |
[PyFoam] Parallel running with PyFoam (not parallelized) |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
April 11, 2014, 08:16 |
Parallel running with PyFoam (not parallelized)
|
#1 |
New Member
Join Date: Nov 2013
Posts: 20
Rep Power: 13 |
I want to carry out a series of simulations with PyFoam. So far they run serially, so one after another, which works fine. To save time, I would like to run them paralley on lets say 4 cores, but not one simulation split onto 4 cores, but 4 simulations, each on one core.
Is there some prepackaged PyFoam utility for that? Or how would you go about doing that? |
|
April 13, 2014, 10:44 |
|
#2 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
If you want it all in one script (job scheduling and data processing) you'll have to write something yourself. There are a number of libraries in Python that support something like this (built in threading or multiprocessing or more advanced stuff - google "python worker thread pool". For a very basic implementation see http://codereview.stackexchange.com/...thread-pooling)
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
||
April 15, 2014, 14:41 |
|
#3 |
New Member
Join Date: Nov 2013
Posts: 20
Rep Power: 13 |
Thanks for your very helpful response Bernhard! As I am not the most proficient programer my solution might be a bit clumsy, but this seems to work, for anyone facing a similar question:
The task was to vary the temperature on a certain boundary of a template case between two limits (tmin, tmax) with a certain step width (tstep), which I enter through a wx GUI. Non-working code snippet containing the crucial parts: Code:
[...] it=tmin while it <=tmax: if threading.activeCount()<=3: case = templateCase.cloneCase(template+"_T_%i" %it) bc=ParsedParameterFile(path.join(case.name,"0","T")) bc["boundaryField"]self.cbound.GetValue()]"value"].setUniform(it) bc.writeFile() mFRunner(self.solvers.GetValue(), "-case", case.name).start() it+=tstep paths.append(case.name) self.Analyze(paths) [...] class mFRunner (threading.Thread): def __init__(self, solver, id, casename): threading.Thread.__init__(self) self.solver=solver self.id=id self.casename=casename def run(self): BasicRunner(argv=[self.solver, self.id, self.casename]).start() However, monitoring the cores via htop shows 3 cores being ~100% busy (why 3 with 2 PyFoam threads!?). Also they seem to take turns working (the non >95% core keeps switching). Is that normal? Like some kind of internal balancing mechanism inside of the threading class? |
|
April 15, 2014, 20:01 |
|
#4 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
About your load: 2 CPUs are your two workers. The third one is your script running in circles "Anyone finished yet? No. Anyone finished yet? No. Anyone finished yet? No. ........." You've got to admire it. It gets a negative answer but it keeps trying .... all the time. That's where the third CPU comes from. That is what these worker pools are for: When a job is finished the master is woken up and starts a new run. Anyway. The quick fix to your script would be (I think "sleep" is in the "time" module) Code:
if threading.activeCount()<=3: start new job else: sleep(1)
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
||
April 16, 2014, 14:48 |
|
#5 |
New Member
Join Date: Nov 2013
Posts: 20
Rep Power: 13 |
That persistence! It is almost ... machine like!
All jokes aside, that really helped again. However I don't understand how the thread count works. If I allow max 1 thread, it runs 1 simulation in parallel. If I allow max 2-5 threads, it runs 2 simulations in parallel. If I allow max 6-9 threads, it runs 3 simulations in parallel. 4,5,6, you see where this is going. And I would not even want to swear that this is reproducible. Is there any particular thing I have missed? This does not make much sense to me. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
error while running in parallel using openmpi on local mc 6 processors | suryawanshi_nitin | OpenFOAM | 10 | February 22, 2017 22:33 |
How to use parallel running to the most? | 6863523 | OpenFOAM Running, Solving & CFD | 5 | January 19, 2017 03:22 |
Running CFX parallel distributed Under linux system with loadleveler queuing system | ahmadbakri | CFX | 1 | December 21, 2014 05:19 |
Problems running in parallel - missing controlDict | Argen | OpenFOAM Running, Solving & CFD | 4 | June 7, 2012 04:50 |
Statically Compiling OpenFOAM Issues | herzfeldd | OpenFOAM Installation | 21 | January 6, 2009 10:38 |