OSDN Git Service

Initial Commit
[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     static unsigned int insert0(unsigned int i0, unsigned int BitNum);
36     static unsigned int insert1(unsigned int i0, unsigned int BitNum);
37     static void swap(double &x,double &y) {
38         double tmp = x;
39         x = y;
40         y = tmp;
41     };
42     static void swap(int    &x,int    &y) {
43         int    tmp = x;
44         x = y;
45         y = tmp;
46     };
47
48 //---
49 // for MPI
50 //---
51
52     static inline int getOriginalID(int id);
53     static inline int getProcFromID(int id);
54     static bool setup(const double R[], const double I[],
55                       const unsigned int &ix0, const unsigned int &ix1,
56                       double &r0, double &i0,
57                       double &r1, double &i1);
58     static void store(double R[], double I[],
59                       const unsigned int &ix0, const unsigned int &ix1,
60                       const double &r0, const double &i0,
61                       const double &r1, const double &i1);
62     static void showdata(double R[], double I[]);
63
64     static int initmpi(int N, int myid, int numprocs);
65     static void initdata(double R[], double I[]);
66
67 };
68 //---------------------------------------------------------------------------
69 #endif //QCalcUnitH