# Path: enchilada_import.py
# class mpi4py_finder(finder):        
#     def __init__(self,skip_checks=True):
#         from mpi4py import MPI
#         comm = MPI.COMM_WORLD
#         rank = comm.Get_rank()
#         if rank == 0:
#             finder.__init__(self,skip_checks)
#         else:
#             finder.__init__(self,skip_checks,False)
#         self._syspath,self._cache = comm.bcast((self._syspath,self._cache))
# 
# Path: mpiimport.py
# class Importer:
#     def __init__(self, path=None):
#         if path is not None and not os.path.isdir(path):
#             raise ImportError
#         self.path = path
# 
#     def find_module(self, fullname, path=None):
#         rank = MPI.COMM_WORLD.Get_rank()
#         #        print "[%d] find_module %s %s" % (rank, fullname, path)
# 
#         subname = fullname.split(".")[-1]
#         if subname != fullname and path is None:
#             return None
#         try:
#             file, filename, stuff = mpiimporter.find_module(subname, path)
#         except ImportError:
#             #            print ImportError
#             return None
# 
#         #        print "[%d] find_module found: %s %s" % (rank, file, filename)
# 
#         ignore, ext = os.path.splitext(filename)
# 
#         if ext == '.so':
#             file, filename, stuff = imp.find_module(subname, path)
#             return ImpLoader(file, filename, stuff)
#         
#         return Loader(file, filename, stuff)


import time
import sys
from enchilada_import import mpi4py_finder
from mpiimport import Importer
from mpi4py import MPI
from clawpack import pyclaw

full_start = time.time()


# all processes need to synch up 
MPI.COMM_WORLD.Barrier()
enchilada_start = time.time()

# try cached importer first
sys.meta_path.insert(0, mpi4py_finder())

# fall back to our importer
sys.meta_path.insert(1, Importer())


MPI.COMM_WORLD.Barrier() 
enchilada_elapsed = time.time() - enchilada_start
full_elapsed = time.time() - full_start


if (MPI.COMM_WORLD.rank == 0):

# Path: enchilada_import.py
# class mpi4py_finder(finder):        
#     def __init__(self,skip_checks=True):
#         from mpi4py import MPI
#         comm = MPI.COMM_WORLD
#         rank = comm.Get_rank()
#         if rank == 0:
#             finder.__init__(self,skip_checks)
#         else:
#             finder.__init__(self,skip_checks,False)
#         self._syspath,self._cache = comm.bcast((self._syspath,self._cache))
# 
# Path: mpiimport.py
# class Importer:
#     def __init__(self, path=None):
#         if path is not None and not os.path.isdir(path):
#             raise ImportError
#         self.path = path
# 
#     def find_module(self, fullname, path=None):
#         rank = MPI.COMM_WORLD.Get_rank()
#         #        print "[%d] find_module %s %s" % (rank, fullname, path)
# 
#         subname = fullname.split(".")[-1]
#         if subname != fullname and path is None:
#             return None
#         try:
#             file, filename, stuff = mpiimporter.find_module(subname, path)
#         except ImportError:
#             #            print ImportError
#             return None
# 
#         #        print "[%d] find_module found: %s %s" % (rank, file, filename)
# 
#         ignore, ext = os.path.splitext(filename)
# 
#         if ext == '.so':
#             file, filename, stuff = imp.find_module(subname, path)
#             return ImpLoader(file, filename, stuff)
#         
#         return Loader(file, filename, stuff)


# Path: test_enchilada.py
import time
import sys
from enchilada_import import mpi4py_finder
from mpiimport import Importer
from mpi4py import MPI
from clawpack import pyclaw


full_start = time.time()


# all processes need to synch up 
MPI.COMM_WORLD.Barrier()
enchilada_start = time.time()

# try cached importer first
sys.meta_path.insert(0, mpi4py_finder())

# fall back to our importer
sys.meta_path.insert(1, Importer())


MPI.COMM_WORLD.Barrier() 
enchilada_elapsed = time.time() - enchilada_start
full_elapsed = time.time() - full_start


if (MPI.COMM_WORLD.rank == 0):

    print "elapsed time (enchilada): %f" % enchilada_elapsed