Package mpi4py :: Module rc
[hide private]
[frames] | no frames]

Source Code for Module mpi4py.rc

  1  # Author:  Lisandro Dalcin 
  2  # Contact: dalcinl@gmail.com 
  3  """ 
  4  Runtime configuration parameters 
  5  """ 
  6   
  7  initialize = True 
  8  """ 
  9  Automatic MPI initialization at import time 
 10   
 11  * Any of ``{True  | 1 | "yes" }``: initialize MPI at import time 
 12  * Any of ``{False | 0 | "no"  }``: do not initialize MPI at import time 
 13  """ 
 14   
 15   
 16  threaded = True 
 17  """ 
 18  Request for thread support at MPI initialization 
 19   
 20  * Any of ``{True  | 1 | "yes" }``: initialize MPI with ``MPI_Init_thread()`` 
 21  * Any of ``{False | 0 | "no"  }``: initialize MPI with ``MPI_Init()`` 
 22  """ 
 23   
 24   
 25  thread_level = "multiple" 
 26  """ 
 27  Level of thread support to request at MPI initialization 
 28   
 29  * ``"single"``     : use ``MPI_THREAD_SINGLE`` 
 30  * ``"funneled"``   : use ``MPI_THREAD_FUNNELED`` 
 31  * ``"serialized"`` : use ``MPI_THREAD_SERIALIZED`` 
 32  * ``"multiple"``   : use ``MPI_THREAD_MULTIPLE`` 
 33  """ 
 34   
 35   
 36  finalize = True 
 37  """ 
 38  Automatic MPI finalization at exit time 
 39   
 40  * Any of ``{True  | 1 | "yes" }``: call ``MPI_Finalize()`` at exit time 
 41  * Any of ``{False | 0 | "no"  }``: do not call ``MPI_Finalize()`` at exit time 
 42  """ 
 43   
 44   
 45  _pmpi_ = [] 
 46   
47 -def profile(name='MPE', **kargs):
48 """ 49 MPI profiling interface 50 """ 51 import sys, os, imp 52 # 53 try: 54 from mpi4py.dl import dlopen, RTLD_NOW, RTLD_GLOBAL 55 from mpi4py.dl import dlerror 56 except ImportError: 57 from ctypes import CDLL as dlopen, RTLD_GLOBAL 58 try: 59 from DLFCN import RTLD_NOW 60 except ImportError: 61 RTLD_NOW = 2 62 dlerror = None 63 # 64 logfile = kargs.pop('logfile', None) 65 if logfile: 66 if name in ('mpe', 'MPE'): 67 if 'MPE_LOGFILE_PREFIX' not in os.environ: 68 os.environ['MPE_LOGFILE_PREFIX'] = logfile 69 if name in ('vt', 'vt-mpi', 'vt-hyb'): 70 if 'VT_FILE_PREFIX' not in os.environ: 71 os.environ['VT_FILE_PREFIX'] = logfile 72 # 73 prefix = os.path.dirname(__file__) 74 so = imp.get_suffixes()[0][0] 75 if name == 'MPE': # special case 76 filename = os.path.join(prefix, name + so) 77 else: 78 format = [('', so)] 79 if sys.platform.startswith('win'): 80 format.append(('', '.dll')) 81 elif sys.platform == 'darwin': 82 format.append(('lib', '.dylib')) 83 elif os.name == 'posix': 84 format.append(('lib', '.so')) 85 for (lib, _so) in format: 86 basename = lib + name + _so 87 filename = os.path.join(prefix, 'lib-pmpi', basename) 88 if os.path.isfile(filename): break 89 filename = None 90 if filename is None: 91 relpath = os.path.join(os.path.basename(prefix), 'lib-pmpi') 92 raise ValueError( 93 "profiler '%s' not found in '%s'" % (name, relpath)) 94 # 95 global _pmpi_ 96 handle = dlopen(filename, RTLD_NOW|RTLD_GLOBAL) 97 if handle: 98 _pmpi_.append( (name, (handle, filename)) ) 99 elif dlerror: 100 from warnings import warn 101 warn(dlerror()) 102 # 103 return filename
104