File: Scientific_32.html

package info (click to toggle)
python-scientific 2.2-5
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,368 kB
  • ctags: 2,396
  • sloc: python: 6,468; ansic: 3,643; xml: 3,596; makefile: 79; sh: 27
file content (47 lines) | stat: -rw-r--r-- 1,839 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<a name="Module:Scientific.Threading.TaskManager"><h1>Module Scientific.Threading.TaskManager</h1></a>

<hr width=70%>
<a name="Class:Scientific.Threading.TaskManager.TaskManager"><h2>Class TaskManager: Parallel task manager for shared-memory multiprocessor machines</h2></a>

<p>This class provides a rather simple way to profit from
shared-memory multiprocessor machines by running several tasks
in parallel. The calling program decides how many execution threads
should run at any given time, and then feeds compute tasks to
the task manager, who runs them as soon as possible without exceeding
the maximum number of threads.</p>

<p>The major limitation of this approach lies in Python's Global
Interpreter Lock. This effectively means that no more than one
Python thread can run at the same time. Consequently, parallelization
can only be achieved if the tasks to be parallelized spend
significant time in C extension modules that release the Global
Interpreter Lock.</p>

<p>Constructor: TaskManager(<i>nthreads</i>)</p>

<p><dl>
<dt><i>nthreads</i></dt>
<dd><p>
the maximum number of compute threads that should
              run in parallel. Note: This does not include the
              main thread which generated and feeds the task
              manager!
</p></dd>
</dl>
</p>

<b>Methods:</b><br>
<ul>
<li> <b><i>runTask</i></b>(<i>function</i>, <i>args</i>)
<p>Add a task defined by <i>function</i>. This must be a callable
object, which will be called exactly once. The arguments of the
call are the elements of the tuple <i>args</i> plus one additional
argument which is a lock object. The task can use this lock
object in order to get temporary exclusive acces to data
shared with other tasks, e.g. a list in which to accumulate
results.</p>

<li> <b><i>terminate</i></b>()
<p>Wait until all tasks have finished.</p>

</ul>