1 """
2 Class that implements the common functionality for running cases in parallel
3 """
4 from optparse import OptionGroup
5
6 from PyFoam.Execution.ParallelExecution import LAMMachine
7
9 """ The class that defines options for parallel execution
10 """
11
13 grp=OptionGroup(self.parser,
14 "Parallel",
15 "Defines whether and on how many processors a parallel run should be executed")
16
17 grp.add_option("--procnr",
18 type="int",
19 dest="procnr",
20 default=None,
21 help="The number of processors the run should be started on")
22
23 grp.add_option("--machinefile",
24 dest="machinefile",
25 default=None,
26 help="The machinefile that specifies the parallel machine")
27
28 grp.add_option("--autosense-parallel",
29 action="store_true",
30 dest="autosenseParallel",
31 default=False,
32 help="Automatically determine for how many processors the case is decomposed and start an adequat parallel run")
33
34 self.parser.add_option_group(grp)
35
37 """
38 @param sol: SolutionDirectory for which the LAMMachine will be
39 constructed (with autosense)
40 """
41 lam=None
42 if self.opts.procnr!=None or self.opts.machinefile!=None:
43 lam=LAMMachine(machines=self.opts.machinefile,nr=self.opts.procnr)
44 elif self.opts.autosenseParallel and sol!=None:
45 if sol.nrProcs()>1:
46 lam=LAMMachine(nr=sol.nrProcs())
47
48 return lam
49