##// END OF EJS Templates
Update version requirement to 2.5, since that's what we're using anyway....
Update version requirement to 2.5, since that's what we're using anyway. Fixes https://bugs.launchpad.net/ipython/+bug/505090

File last commit:

r1395:1feaf0a3
r2413:c859f8d0
Show More
parallelfunction.py
106 lines | 3.1 KiB | text/x-python | PythonLexer
/ IPython / kernel / parallelfunction.py
Brian E Granger
This is a manual merge of certain things in the ipython1-dev branch, revision 46, into the main ...
r1234 # encoding: utf-8
"""A parallelized function that does scatter/execute/gather."""
__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
Brian E Granger
A new version and API for map is now working. We also now have an...
r1346 from zope.interface import Interface, implements
Brian E Granger
This is a manual merge of certain things in the ipython1-dev branch, revision 46, into the main ...
r1234
Brian E Granger
A new version and API for map is now working. We also now have an...
r1346
Brian E Granger
The refactoring of the Task system is nearly complete. Now there are...
r1395 class IMultiEngineParallelDecorator(Interface):
"""A decorator that creates a parallel function."""
def parallel(dist='b', targets=None, block=None):
"""
A decorator that turns a function into a parallel function.
This can be used as:
@parallel()
def f(x, y)
...
f(range(10), range(10))
This causes f(0,0), f(1,1), ... to be called in parallel.
:Parameters:
dist : str
What decomposition to use, 'b' is the only one supported
currently
targets : str, int, sequence of ints
Which engines to use for the map
block : boolean
Should calls to `map` block or not
"""
class ITaskParallelDecorator(Interface):
"""A decorator that creates a parallel function."""
def parallel(clear_before=False, clear_after=False, retries=0,
recovery_task=None, depend=None, block=True):
"""
A decorator that turns a function into a parallel function.
This can be used as:
@parallel()
def f(x, y)
...
f(range(10), range(10))
This causes f(0,0), f(1,1), ... to be called in parallel.
See the documentation for `IPython.kernel.task.BaseTask` for
documentation on the arguments to this method.
"""
class IParallelFunction(Interface):
pass
Brian E Granger
A new version and API for map is now working. We also now have an...
r1346 class ParallelFunction(object):
"""
Brian E Granger
The refactoring of the Task system is nearly complete. Now there are...
r1395 The implementation of a parallel function.
A parallel function is similar to Python's map function:
map(func, *sequences) -> pfunc(*sequences)
Parallel functions should be created by using the @parallel decorator.
Brian E Granger
A new version and API for map is now working. We also now have an...
r1346 """
Brian E Granger
The refactoring of the Task system is nearly complete. Now there are...
r1395 implements(IParallelFunction)
def __init__(self, mapper):
Brian E Granger
A new version and API for map is now working. We also now have an...
r1346 """
Brian E Granger
The refactoring of the Task system is nearly complete. Now there are...
r1395 Create a parallel function from an `IMapper`.
:Parameters:
mapper : an `IMapper` implementer.
The mapper to use for the parallel function
Brian E Granger
This is a manual merge of certain things in the ipython1-dev branch, revision 46, into the main ...
r1234 """
Brian E Granger
The refactoring of the Task system is nearly complete. Now there are...
r1395 self.mapper = mapper
Brian E Granger
This is a manual merge of certain things in the ipython1-dev branch, revision 46, into the main ...
r1234
Brian E Granger
A new version and API for map is now working. We also now have an...
r1346 def __call__(self, func):
"""
Brian E Granger
The refactoring of the Task system is nearly complete. Now there are...
r1395 Decorate a function to make it run in parallel.
Brian E Granger
A new version and API for map is now working. We also now have an...
r1346 """
assert isinstance(func, (str, FunctionType)), "func must be a fuction or str"
self.func = func
def call_function(*sequences):
Brian E Granger
The refactoring of the Task system is nearly complete. Now there are...
r1395 return self.mapper.map(self.func, *sequences)
Brian E Granger
A new version and API for map is now working. We also now have an...
r1346 return call_function