def testImportModuleAs(self): pmi.exec_("import random as s") # check that it's loaded self.assert_(hasattr(pmi, "s")) self.assertEqual(pmi.s.__name__, "random") # clean up pmi.exec_("del(s)")
def testLambda(self): pmi.exec_("myadd = lambda a,b: a+b") res = pmi.reduce("myadd", mockFunc) if pmi.isController: self.assertEqual(res, 42 * pmi.size) else: self.assertEqual(res, None) pmi.exec_("del myadd")
def testImportModule(self): pmi.exec_("import random") # check that it's loaded into pmi self.assert_(hasattr(pmi, "random")) # check that the main namespace is not polluted try: exec "n=random.__name__" self.fail("expected a NameError") except NameError: pass else: self.fail("expected a NameError") # clean up pmi.exec_("del(random)") # check that it's gone self.assertFalse(hasattr(pmi, "random"))
# Copyright 2014 Pierre de Buyl # # This file is part of pmi-h5py # # pmi-h5py is free software and is licensed under the modified BSD license (see # LICENSE file). import pmi from mpi4py import MPI pmi.exec_('import test_pmi_mod') import numpy as np import h5py class MyTestLocal(object): def __init__(self, filename, n): self.filename = filename self.f = h5py.File(self.filename, 'w', driver='mpio', comm=MPI.COMM_WORLD) self.n = n self.data = np.random.random(n) def show(self): print MPI.COMM_WORLD.rank, self.data def fill(self): self.f.create_dataset('ds1', dtype=self.data.dtype, shape=(MPI.COMM_WORLD.size * self.n, ),
import pmi pmi.setup(2) # create the parallel function pmi.exec_( """ from mpi4py import MPI def hello_parallel(name): return 'Hello %s, this is MPI task %d!' % (name, MPI.COMM_WORLD.rank) """ ) # invoke the function on all workers and get the results as a list res = pmi.invoke("hello_parallel", "Olaf") print("\n".join(res))
def testCommandMismatch(self): if pmi.isController: pmi.exec_("pass") else: self.assertRaises(pmi.UserError, pmi.call, None)
# Copyright 2014 Pierre de Buyl # # This file is part of pmi-h5py # # pmi-h5py is free software and is licensed under the modified BSD license (see # LICENSE file). import pmi from mpi4py import MPI pmi.exec_('import test_pmi_mod') import numpy as np import h5py class MyTestLocal(object): def __init__(self, filename, n): self.filename = filename self.f = h5py.File( self.filename, 'w', driver='mpio', comm=MPI.COMM_WORLD) self.n = n self.data = np.random.random(n) def show(self): print MPI.COMM_WORLD.rank, self.data def fill(self): self.f.create_dataset('ds1', dtype=self.data.dtype, shape=(MPI.COMM_WORLD.size*self.n,), chunks=(self.n,))