예제 #1
0
def Context(*args, **kwargs):

    kind = kwargs.pop('kind', '')

    if not kind:
        kind = 'ipython' if is_solo_mpi_process() else 'mpi'

    if kind.lower().startswith('mpi'):

        CW = get_comm_world()
        myrank = CW.rank
        if myrank:
            _fire_off_engines(myrank)
            import sys
            sys.exit()
        else:
            return MPIContext(*args, **kwargs)

    elif kind.lower().startswith('ipython'):
        return IPythonContext(*args, **kwargs)

    else:
        raise ContextCreationError("%s is not a valid Context selector string." % kind)
예제 #2
0
def Context(*args, **kwargs):

    kind = kwargs.pop('kind', '')

    if not kind:
        kind = 'ipython' if is_solo_mpi_process() else 'mpi'

    if kind.lower().startswith('mpi'):

        CW = get_comm_world()
        myrank = CW.rank
        if myrank:
            _fire_off_engines(myrank)
            import sys
            sys.exit()
        else:
            return MPIContext(*args, **kwargs)

    elif kind.lower().startswith('ipython'):
        return IPythonContext(*args, **kwargs)

    else:
        raise ContextCreationError(
            "%s is not a valid Context selector string." % kind)
예제 #3
0
    @classmethod
    def setUpClass(cls):
        super(TestContext, cls).setUpClass()
        cls.ndarr = numpy.arange(16).reshape(4, 4)
        cls.darr = cls.context.fromndarray(cls.ndarr)

    def test_get_localarrays(self):
        las = self.darr.get_localarrays()
        self.assertIsInstance(las[0], LocalArray)

    def test_get_ndarrays(self):
        ndarrs = self.darr.get_ndarrays()
        self.assertIsInstance(ndarrs[0], numpy.ndarray)


@unittest.skipIf(not is_solo_mpi_process(),  # not in ipython mode
                 "Cannot test IPythonContext in MPI mode")
class TestIPythonContextCreation(IPythonContextTestCase):
    """Test Context Creation"""

    def test_create_Context(self):
        """Can we create a plain vanilla context?"""
        dac = Context(kind='IPython', client=self.client)
        self.assertIs(dac.client, self.client)

    def test_create_Context_with_targets(self):
        """Can we create a context with a subset of engines?"""
        check_targets(required=2, available=len(self.client))
        dac = Context(self.client, targets=[0, 1])
        self.assertIs(dac.client, self.client)
        dac.close()
예제 #4
0
    @classmethod
    def setUpClass(cls):
        super(TestContext, cls).setUpClass()
        cls.ndarr = numpy.arange(16).reshape(4, 4)
        cls.darr = cls.context.fromndarray(cls.ndarr)

    def test_get_localarrays(self):
        las = self.darr.get_localarrays()
        self.assertIsInstance(las[0], LocalArray)

    def test_get_ndarrays(self):
        ndarrs = self.darr.get_ndarrays()
        self.assertIsInstance(ndarrs[0], numpy.ndarray)


@unittest.skipIf(not is_solo_mpi_process(),  # not in ipython mode
                 "Cannot test IPythonContext in MPI mode")
class TestIPythonContextCreation(IPythonContextTestCase):
    """Test Context Creation"""

    def test_create_Context(self):
        """Can we create a plain vanilla context?"""
        dac = Context(kind='IPython', client=self.client)
        self.assertIs(dac.client, self.client)

    def test_create_Context_with_targets(self):
        """Can we create a context with a subset of engines?"""
        check_targets(required=2, available=len(self.client))
        dac = Context(self.client, targets=[0, 1])
        self.assertIs(dac.client, self.client)
        dac.close()