CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Running, Solving & CFD

Parallel running with PyFoam (not parallelized)

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By gschaider

Reply
 
LinkBack Thread Tools Display Modes
Old   April 11, 2014, 07:16
Default Parallel running with PyFoam (not parallelized)
  #1
New Member
 
Join Date: Nov 2013
Posts: 20
Rep Power: 3
Jakob1 is on a distinguished road
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?
Jakob1 is offline   Reply With Quote

Old   April 13, 2014, 09:44
Default
  #2
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,905
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by Jakob1 View Post
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?
There is no support for that in PyFoam because I usually use a proper queuing system to do such a thing (in my case SunGridEngine but there are others too). I then collect the data from the information the cases have written to disk.

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
gschaider is offline   Reply With Quote

Old   April 15, 2014, 13:41
Default
  #3
New Member
 
Join Date: Nov 2013
Posts: 20
Rep Power: 3
Jakob1 is on a distinguished road
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()
I am only running on a 4 core CPU right now, so I can't run more than 2 PyFoam threads at the same time (one reserved for the OS, one for the Python script), but as soon as I get to an 8 core I'll try more.

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?
Jakob1 is offline   Reply With Quote

Old   April 15, 2014, 19:01
Default
  #4
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,905
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by Jakob1 View Post
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()
I am only running on a 4 core CPU right now, so I can't run more than 2 PyFoam threads at the same time (one reserved for the OS, one for the Python script), but as soon as I get to an 8 core I'll try more.

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?
At first: not bad for a first stab at parallel computation, but this is a field where one learns most from experience ....

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)
That way the script only polls every second whether a job has finished using an amount of CPU that is barely measurable. Of course you've got to live with the fact that some runs are started 0.99999 seconds later than they could have been, but the extra CPU (because now you can use that for computations too) should make up for this
Jakob1 likes this.
__________________
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
gschaider is offline   Reply With Quote

Old   April 16, 2014, 13:48
Default
  #5
New Member
 
Join Date: Nov 2013
Posts: 20
Rep Power: 3
Jakob1 is on a distinguished road
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.
Jakob1 is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running parallel: ./Allrun: 62: shift: can't shift that many adambarfi OpenFOAM Running, Solving & CFD 9 August 17, 2013 12:58
running OpenFoam in parallel vishwa OpenFOAM 20 November 7, 2012 16:33
Problems running in parallel - missing controlDict Argen OpenFOAM Running, Solving & CFD 4 June 7, 2012 03:50
error while running in parallel using openmpi on local mc 6 processors suryawanshi_nitin OpenFOAM 5 May 21, 2012 14:13
Running mapFields with Parallel Source and Parallel Target RDanks OpenFOAM Mesh Utilities 2 June 6, 2011 07:56


All times are GMT -4. The time now is 11:34.