OSDN Git Service

7eec04a63cbcb56451d3e3f6f10c88d81261dbf8
[qcad/qcad.git] / calcunits / QCalcUnit.h
1 //---------------------------------------------------------------------------
2 //  Calc unit
3 //---------------------------------------------------------------------------
4 #ifndef QCalcUnitH
5 #define QCalcUnitH
6 //---------------------------------------------------------------------------
7 #include <string>
8 #include <sstream>
9
10 #ifdef __USE__MPI
11 #include <mpi.h>
12 #endif //__USE__MPI
13
14 #include "QBits.h"
15 //---------------------------------------------------------------------------
16 class QCalcUnit
17 {
18 protected :
19 //---
20 // for MPI
21 //---
22 #ifdef __USE__MPI
23     static int gMdata;  // the number of the states which each process treats
24     static int gNqubits;
25     static int gProcMask;
26     static int gProcBit;
27     static int gMyID;
28     static int gNumprocs;
29 #endif //__USE__MPI
30
31
32 public:
33     virtual void Calc(QBits *qBits) = 0;
34     virtual std::string GetName(void) const = 0;
35     virtual ~QCalcUnit(void) = 0;
36     static unsigned int insert0(unsigned int i0, unsigned int BitNum);
37     static unsigned int insert1(unsigned int i0, unsigned int BitNum);
38     static void swap(double &x,double &y) {
39         double tmp = x;
40         x = y;
41         y = tmp;
42     };
43     static void swap(int    &x,int    &y) {
44         int    tmp = x;
45         x = y;
46         y = tmp;
47     };
48
49 //---
50 // for MPI
51 //---
52
53     static inline int getOriginalID(int id);
54     static inline int getProcFromID(int id);
55     static bool setup(const double R[], const double I[],
56                       const unsigned int &ix0, const unsigned int &ix1,
57                       double &r0, double &i0,
58                       double &r1, double &i1);
59     static void store(double R[], double I[],
60                       const unsigned int &ix0, const unsigned int &ix1,
61                       const double &r0, const double &i0,
62                       const double &r1, const double &i1);
63     static void showdata(double R[], double I[]);
64
65     static int initmpi(int N, int myid, int numprocs);
66     static void initdata(double R[], double I[]);
67
68 };
69 //---------------------------------------------------------------------------
70 #endif //QCalcUnitH