Repository navigation
Expand file tree
/
Copy pathmixing.cpp
More file actions
113 lines (109 loc) · 3.49 KB
/
Copy pathmixing.cpp
File metadata and controls
113 lines (109 loc) · 3.49 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "mixing.h"
#include "source_base/module_container/base/third_party/blas.h"
namespace Base_Mixing
{
void Mixing::push_data(Mixing_Data& mdata,
const double* data_in,
const double* data_out,
std::function<void(double*)> screen,
const bool& need_calcoef)
{
const size_t length = mdata.length;
this->push_data(
mdata,
data_in,
data_out,
screen,
[this, length](double* out, const double* in, const double* sres) {
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 512)
#endif
for (int i = 0; i < length; ++i)
{
out[i] = in[i] + this->mixing_beta * sres[i];
}
},
need_calcoef);
return;
}
void Mixing::push_data(Mixing_Data& mdata,
const std::complex<double>* data_in,
const std::complex<double>* data_out,
std::function<void(std::complex<double>*)> screen,
const bool& need_calcoef)
{
const size_t length = mdata.length;
this->push_data(
mdata,
data_in,
data_out,
screen,
[this, length](std::complex<double>* out, const std::complex<double>* in, const std::complex<double>* sres) {
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 256)
#endif
for (int i = 0; i < length; ++i)
{
out[i] = in[i] + this->mixing_beta * sres[i];
}
},
need_calcoef);
return;
}
void Mixing::mix_data(const Mixing_Data& mdata, double* data_mix)
{
if (mdata.length <= 0)
return;
double* FP_data = static_cast<double*>(mdata.data);
if (mdata.ndim_use == 1)
{
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 512)
#endif
for (int i = 0; i < mdata.length; ++i)
data_mix[i] = FP_data[i];
return;
}
container::BlasConnector::gemv('N',
mdata.length,
mdata.ndim_use,
1.0,
FP_data,
mdata.length,
coef.data(),
1,
0.0,
data_mix,
1);
}
void Mixing::mix_data(const Mixing_Data& mdata, std::complex<double>* data_mix)
{
if (mdata.length <= 0)
return;
std::complex<double>* FP_data = static_cast<std::complex<double>*>(mdata.data);
if (mdata.ndim_use == 1)
{
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 256)
#endif
for (int i = 0; i < mdata.length; ++i)
data_mix[i] = FP_data[i];
return;
}
// conver coef to complex
std::vector<std::complex<double>> coef_complex(coef.size());
for (int i = 0; i < coef.size(); ++i)
coef_complex[i] = coef[i];
container::BlasConnector::gemv('N',
mdata.length,
mdata.ndim_use,
1.0,
FP_data,
mdata.length,
coef_complex.data(),
1,
0.0,
data_mix,
1);
}
} // namespace Base_Mixing