TPIE

v1.1rc1-6-g0c97303
pipes.h
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
2 // vi:set ts=4 sts=4 sw=4 noet :
3 // Copyright 2013, The TPIE development team
4 //
5 // This file is part of TPIE.
6 //
7 // TPIE is free software: you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the
9 // Free Software Foundation, either version 3 of the License, or (at your
10 // option) any later version.
11 //
12 // TPIE is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with TPIE. If not, see <http://www.gnu.org/licenses/>
19 
20 #ifndef __TPIE_PIPELINING_PARALLEL_PIPES_H__
21 #define __TPIE_PIPELINING_PARALLEL_PIPES_H__
22 
23 namespace tpie {
24 
25 namespace pipelining {
26 
35 template <typename fact_t>
36 pipe_middle<parallel_bits::factory<fact_t> >
37 parallel(const pipe_middle<fact_t> & fact, maintain_order_type maintainOrder, size_t numJobs, size_t bufSize = 2048) {
39  switch (maintainOrder) {
40  case arbitrary_order:
41  opts.maintainOrder = false;
42  break;
43  case maintain_order:
44  opts.maintainOrder = true;
45  break;
46  }
47  opts.numJobs = numJobs;
48  opts.bufSize = bufSize;
51  (fact.factory, opts));
52 }
53 
63 template <typename fact_t>
64 pipe_middle<parallel_bits::factory<fact_t> >
66  return parallel(fact, maintainOrder, default_worker_count());
67 }
68 
69 template <typename fact_t>
70 pipe_middle<parallel_bits::factory<fact_t> >
71 parallel(const pipe_middle<fact_t> & fact, bool maintainOrder, size_t numJobs, size_t bufSize = 2048) {
72  log_fatal() << "The second argument to tpie::pipelining::parallel has changed.\n"
73  << "Use maintain_order instead of true and arbitrary_order instead of false."
74  << std::endl;
75  return parallel(fact, maintainOrder ? maintain_order : arbitrary_order, numJobs, bufSize);
76 }
77 
78 template <typename fact_t>
79 pipe_middle<parallel_bits::factory<fact_t> >
80 parallel(const pipe_middle<fact_t> & fact, bool maintainOrder) {
81  log_fatal() << "The second argument to tpie::pipelining::parallel has changed.\n"
82  << "Use maintain_order instead of true and arbitrary_order instead of false."
83  << std::endl;
84  return parallel(fact, maintainOrder ? maintain_order : arbitrary_order);
85 }
86 
87 } // namespace pipelining
88 
89 } // namespace tpie
90 
91 #endif // __TPIE_PIPELINING_PARALLEL_PIPES_H__
Factory instantiating a parallel multithreaded pipeline.
Definition: factory.h:33
Do not maintain order; push items as soon as a worker has processed them.
pipe_middle< parallel_bits::factory< fact_t > > parallel(const pipe_middle< fact_t > &fact, maintain_order_type maintainOrder, size_t numJobs, size_t bufSize=2048)
Runs a pipeline in multiple threads.
Definition: pipes.h:37
logstream & log_fatal()
Return logstream for writing fatal log messages.
Definition: tpie_log.h:99
memory_size_type default_worker_count()
Return the number of job threads initialized by the job framework in init_job().
Maintain order; push items in the same order that a single thread would have.
User-supplied options to the parallelism framework.
Definition: options.h:32
A pipe_middle class pushes input down the pipeline.
Definition: pipe_base.h:119
maintain_order_type
Type describing whether to maintain the order of items in parallel.