HWRF  trunk@4391
inside_aprun.py
1 ## @namespace produtil.mpi_impl.inside_aprun
2 # Adds support for running serial programs when one is inside an aprun
3 # execution.
4 #
5 # This module is part of the mpi_impl package -- see produtil.mpi_impl
6 # for details. This implements execution of serial programs when one
7 # is inside an aprun execution.
8 
9 import os, socket, logging
11 
12 from .mpi_impl_base import MPIMixed, MPIDisabled, OpenMPDisabled
13 
14 module_logger=logging.getLogger('lsf_cray_intel')
15 
16 def runsync(logger=None):
17  """!Runs the "sync" command as an exe()."""
18  if logger is None: logger=module_logger
19  sync=produtil.prog.Runner(['/bin/sync'])
20  p=produtil.pipeline.Pipeline(sync,capture=True,logger=logger)
21  version=p.to_string()
22  status=p.poll()
23 
24 def detect():
25  inside_aprun=os.environ.get('INSIDE_APRUN','')
26  if inside_aprun:
27  inside_aprun=int(inside_aprun)
28  if inside_aprun>0:
29  return True
30  return False
31 
32 def openmp(arg,threads):
33  """!When more than one thread is requested, this raises
34  OpenMPDisabled to indicate OpenMP is not allowed.
35 
36  @param arg An produtil.prog.Runner or
37  produtil.mpiprog.MPIRanksBase object tree
38  @param threads the number of threads, or threads per rank, an
39  integer"""
40  if threads is not None:
41  threads=int(threads)
42  if threads!=1:
43  raise OpenMPDisabled("You cannot start a new OpenMP program from within an aprun invocation.")
44 
45 def mpirunner(arg,**kwargs):
46  """!Raises an exception to indicate MPI is not supported
47  @param arg,kwargs Ignored."""
48  raise MPIDisabled('You cannot start a new MPI program from within an aprun invocation.')
49 
51  """!Returns False to indicate MPI is not supported."""
52  return False
53 
54 def make_bigexe(exe,**kwargs):
55  """!Returns an ImmutableRunner that will run the specified program.
56  @returns an empty list
57  @param exe The executable to run on compute nodes.
58  @param kwargs Ignored."""
59  return produtil.prog.ImmutableRunner([str(exe)],**kwargs)
This module provides a set of utility functions to do filesystem operations.
Definition: fileop.py:1
def runsync
Runs the "sync" command as an exe().
Definition: inside_aprun.py:16
def openmp(arg, threads)
When more than one thread is requested, this raises OpenMPDisabled to indicate OpenMP is not allowed...
Definition: inside_aprun.py:32
This class is a wrapper around launch and manage.
Definition: pipeline.py:564
def mpirunner(arg, kwargs)
Raises an exception to indicate MPI is not supported.
Definition: inside_aprun.py:45
Implements the produtil.run: provides the object tree for representing shell commands.
Definition: prog.py:1
def make_bigexe(exe, kwargs)
Returns an ImmutableRunner that will run the specified program.
Definition: inside_aprun.py:54
def can_run_mpi()
Returns False to indicate MPI is not supported.
Definition: inside_aprun.py:50
Object structure for describing MPI programs.
Definition: mpiprog.py:1
Represents a single stage of a pipeline to execute.
Definition: prog.py:299
Internal module that launches and monitors processes.
Definition: pipeline.py:1
An copy-on-write version of Runner.
Definition: prog.py:884