コード例 #1
0
ファイル: test_pmi.py プロジェクト: stuehn/pmi
 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)")
コード例 #2
0
ファイル: test_pmi.py プロジェクト: stuehn/pmi
        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")
コード例 #3
0
ファイル: test_pmi.py プロジェクト: stuehn/pmi
 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"))
コード例 #4
0
ファイル: test_pmi_mod.py プロジェクト: xinmeng2020/pmi-h5py
# 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, ),
コード例 #5
0
ファイル: hello_basic1.py プロジェクト: stuehn/pmi
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))
コード例 #6
0
ファイル: test_pmi.py プロジェクト: stuehn/pmi
 def testCommandMismatch(self):
     if pmi.isController:
         pmi.exec_("pass")
     else:
         self.assertRaises(pmi.UserError, pmi.call, None)
コード例 #7
0
ファイル: test_pmi_mod.py プロジェクト: pdebuyl/pmi-h5py
# 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,))