##// END OF EJS Templates
A new version and API for map is now working. We also now have an...
A new version and API for map is now working. We also now have an @parallel decorator that creates a parallel implementation of a function.

File last commit:

r1346:fd7bff6e
r1346:fd7bff6e
Show More
mapper.py
41 lines | 1.4 KiB | text/x-python | PythonLexer
# encoding: utf-8
"""A parallelized version of Python's builtin map."""
__docformat__ = "restructuredtext en"
#-------------------------------------------------------------------------------
# Copyright (C) 2008 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Imports
#-------------------------------------------------------------------------------
from types import FunctionType
from zope.interface import Interface, implements
class IMapper(Interface):
def __call__(func, *sequences):
"""Do map in parallel."""
class Mapper(object):
implements(IMapper)
def __init__(self, multiengine, dist='b', targets='all', block=True):
self.multiengine = multiengine
self.dist = dist
self.targets = targets
self.block = block
def __call__(self, func, *sequences):
return self.map(func, *sequences)
def map(self, func, *sequences):
assert isinstance(func, (str, FunctionType)), "func must be a fuction or str"
return self.multiengine._map(func, sequences, dist=self.dist,
targets=self.targets, block=self.block)