Qrack  1.7
General classical-emulating-quantum development framework
parallel_for.hpp
Go to the documentation of this file.
1 //
3 // (C) Daniel Strano and the Qrack contributors 2017, 2018. All rights reserved.
4 //
5 // This is a multithreaded, universal quantum register simulation, allowing
6 // (nonphysical) register cloning and direct measurement of probability and
7 // phase, to leverage what advantages classical emulation of qubits can have.
8 //
9 // Licensed under the GNU General Public License V3.
10 // See LICENSE.md in the project root or https://www.gnu.org/licenses/gpl-3.0.en.html
11 // for details.
12 
13 #pragma once
14 
15 #include <functional>
16 
17 /* Needed for bitCapInt typedefs. */
18 #include "qinterface.hpp"
19 
20 namespace Qrack {
21 
22 class ParallelFor {
23 private:
24  int32_t numCores;
25 
26 public:
28  : numCores(1)
29  {
30  }
31  virtual ~ParallelFor() {}
32 
33  void SetConcurrencyLevel(int32_t num) { numCores = num; }
34  int32_t GetConcurrencyLevel() { return numCores; }
35  /*
36  * Parallelization routines for spreading work across multiple cores.
37  */
38 
40  typedef std::function<void(const bitCapInt, const int cpu)> ParallelFunc;
41  typedef std::function<bitCapInt(const bitCapInt, const int cpu)> IncrementFunc;
42 
47  void par_for_inc(const bitCapInt begin, const bitCapInt itemCount, IncrementFunc, ParallelFunc fn);
48 
50  void par_for(const bitCapInt begin, const bitCapInt end, ParallelFunc fn);
51 
60  void par_for_skip(const bitCapInt begin, const bitCapInt end, const bitCapInt skipPower,
61  const bitLenInt skipBitCount, ParallelFunc fn);
62 
64  void par_for_mask(
65  const bitCapInt, const bitCapInt, const bitCapInt* maskArray, const bitLenInt maskLen, ParallelFunc fn);
66 
68  real1 par_norm(const bitCapInt maxQPower, const complex* stateArray);
69 };
70 
71 } // namespace Qrack
std::function< bitCapInt(const bitCapInt, const int cpu)> IncrementFunc
Definition: parallel_for.hpp:41
int32_t numCores
Definition: parallel_for.hpp:24
virtual ~ParallelFor()
Definition: parallel_for.hpp:31
Definition: parallel_for.hpp:22
void par_for_mask(const bitCapInt, const bitCapInt, const bitCapInt *maskArray, const bitLenInt maskLen, ParallelFunc fn)
Skip over the bits listed in maskArray in the same fashion as par_for_skip.
Definition: parallel_for.cpp:129
void SetConcurrencyLevel(int32_t num)
Definition: parallel_for.hpp:33
void par_for_skip(const bitCapInt begin, const bitCapInt end, const bitCapInt skipPower, const bitLenInt skipBitCount, ParallelFunc fn)
Skip over the skipPower bits.
Definition: parallel_for.cpp:96
#define real1
Definition: qinterface.hpp:36
ParallelFor()
Definition: parallel_for.hpp:27
void par_for_inc(const bitCapInt begin, const bitCapInt itemCount, IncrementFunc, ParallelFunc fn)
Iterate through the permutations a maximum of end-begin times, allowing the caller to control the inc...
Definition: parallel_for.cpp:25
void par_for(const bitCapInt begin, const bitCapInt end, ParallelFunc fn)
Call fn once for every numerical value between begin and end.
Definition: parallel_for.cpp:91
real1 par_norm(const bitCapInt maxQPower, const complex *stateArray)
Calculate the normal for the array.
Definition: parallel_for.cpp:166
#define complex
Definition: qinterface.hpp:35
std::function< void(const bitCapInt, const int cpu)> ParallelFunc
Called once per value between begin and end.
Definition: parallel_for.hpp:40
#define bitCapInt
Definition: qinterface.hpp:22
#define bitLenInt
Definition: qinterface.hpp:21
int32_t GetConcurrencyLevel()
Definition: parallel_for.hpp:34
Definition: complex16simd.hpp:21