forked from abacusmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgint.cpp
More file actions
263 lines (242 loc) · 8.44 KB
/
Copy pathgint.cpp
File metadata and controls
263 lines (242 loc) · 8.44 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#include "gint.h"
#include "../module_base/memory.h"
#include "../module_base/timer.h"
#include "../src_pw/global.h"
#ifdef _OPENMP
#include <omp.h>
#endif
#ifdef __MKL
#include <mkl_service.h>
#endif
void Gint::cal_gint(Gint_inout *inout)
{
ModuleBase::TITLE("Gint_interface","cal_gint");
ModuleBase::timer::tick("Gint_interface", "cal_gint");
const int max_size = GlobalC::GridT.max_atom;
const int LD_pool = max_size*GlobalC::ucell.nwmax;
const int lgd = GlobalC::GridT.lgd;
if(max_size!=0)
{
#ifdef __MKL
const int mkl_threads = mkl_get_max_threads();
mkl_set_num_threads(1);
#endif
#ifdef _OPENMP
#pragma omp parallel
#endif
{
//prepare some constants
const int ncyz = GlobalC::rhopw->ny*GlobalC::rhopw->nplane; // mohan add 2012-03-25
const double dv = GlobalC::ucell.omega/this->ncxyz;
// it's a uniform grid to save orbital values, so the delta_r is a constant.
const double delta_r = GlobalC::ORB.dr_uniform;
if((inout->job==Gint_Tools::job_type::vlocal || inout->job==Gint_Tools::job_type::vlocal_meta) && !GlobalV::GAMMA_ONLY_LOCAL)
{
if(!pvpR_alloc_flag)
{
ModuleBase::WARNING_QUIT("Gint_interface::cal_gint","pvpR has not been allocated yet!");
}
else
{
ModuleBase::GlobalFunc::ZEROS(this->pvpR_reduced[inout->ispin], GlobalC::GridT.nnrg);
}
}
//perpare auxiliary arrays to store thread-specific values
#ifdef _OPENMP
double* pvpR_thread;
if(inout->job==Gint_Tools::job_type::vlocal || inout->job==Gint_Tools::job_type::vlocal_meta)
{
if(!GlobalV::GAMMA_ONLY_LOCAL)
{
pvpR_thread = new double[GlobalC::GridT.nnrg];
ModuleBase::GlobalFunc::ZEROS(pvpR_thread, GlobalC::GridT.nnrg);
}
if(GlobalV::GAMMA_ONLY_LOCAL && lgd>0)
{
pvpR_thread = new double[lgd*lgd];
ModuleBase::GlobalFunc::ZEROS(pvpR_thread, lgd*lgd);
}
}
ModuleBase::matrix fvl_dphi_thread;
ModuleBase::matrix svl_dphi_thread;
if(inout->job==Gint_Tools::job_type::force || inout->job==Gint_Tools::job_type::force_meta)
{
if(inout->isforce)
{
fvl_dphi_thread.create(inout->fvl_dphi->nr,inout->fvl_dphi->nc);
fvl_dphi_thread.zero_out();
}
if(inout->isstress)
{
svl_dphi_thread.create(inout->svl_dphi->nr,inout->svl_dphi->nc);
svl_dphi_thread.zero_out();
}
}
#pragma omp for
#endif
// entering the main loop of grid points
for(int grid_index = 0; grid_index < GlobalC::bigpw->nbxx; grid_index++)
{
// get the value: how many atoms has orbital value on this grid.
const int na_grid = GlobalC::GridT.how_many_atoms[ grid_index ];
if(na_grid==0) continue;
if(inout->job == Gint_Tools::job_type::rho)
{
//int* vindex = Gint_Tools::get_vindex(ncyz, ibx, jby, kbz);
int* vindex = Gint_Tools::get_vindex(GlobalC::GridT.start_ind[grid_index], ncyz);
this->gint_kernel_rho(na_grid, grid_index, delta_r, vindex, LD_pool, inout);
delete[] vindex;
}
else if(inout->job == Gint_Tools::job_type::tau)
{
int* vindex = Gint_Tools::get_vindex(GlobalC::GridT.start_ind[grid_index], ncyz);
this->gint_kernel_tau(na_grid, grid_index, delta_r, vindex, LD_pool, inout);
delete[] vindex;
}
else if(inout->job == Gint_Tools::job_type::force)
{
double* vldr3 = Gint_Tools::get_vldr3(inout->vl, GlobalC::GridT.start_ind[grid_index], ncyz, dv);
double** DM_in;
if(GlobalV::GAMMA_ONLY_LOCAL) DM_in = inout->DM[GlobalV::CURRENT_SPIN];
if(!GlobalV::GAMMA_ONLY_LOCAL) DM_in = inout->DM_R;
#ifdef _OPENMP
this->gint_kernel_force(na_grid, grid_index, delta_r, vldr3, LD_pool,
DM_in, inout->isforce, inout->isstress,
&fvl_dphi_thread, &svl_dphi_thread);
#else
this->gint_kernel_force(na_grid, grid_index, delta_r, vldr3, LD_pool,
DM_in, inout->isforce, inout->isstress,
inout->fvl_dphi, inout->svl_dphi);
#endif
delete[] vldr3;
}
else if(inout->job==Gint_Tools::job_type::vlocal)
{
double* vldr3 = Gint_Tools::get_vldr3(inout->vl, GlobalC::GridT.start_ind[grid_index], ncyz, dv);
#ifdef _OPENMP
if((GlobalV::GAMMA_ONLY_LOCAL && lgd>0) || !GlobalV::GAMMA_ONLY_LOCAL)
{
this->gint_kernel_vlocal(na_grid, grid_index, delta_r, vldr3, LD_pool,
pvpR_thread);
}
#else
if(GlobalV::GAMMA_ONLY_LOCAL && lgd>0)
{
this->gint_kernel_vlocal(na_grid, grid_index, delta_r, vldr3, LD_pool, pvpR_grid);
}
if(!GlobalV::GAMMA_ONLY_LOCAL)
{
this->gint_kernel_vlocal(na_grid, grid_index, delta_r, vldr3, LD_pool,
this->pvpR_reduced[inout->ispin]);
}
#endif
delete[] vldr3;
}
else if(inout->job==Gint_Tools::job_type::vlocal_meta)
{
double* vldr3 = Gint_Tools::get_vldr3(inout->vl, GlobalC::GridT.start_ind[grid_index], ncyz, dv);
double* vkdr3 = Gint_Tools::get_vldr3(inout->vofk, GlobalC::GridT.start_ind[grid_index], ncyz, dv);
#ifdef _OPENMP
if((GlobalV::GAMMA_ONLY_LOCAL && lgd>0) || !GlobalV::GAMMA_ONLY_LOCAL)
{
this->gint_kernel_vlocal_meta(na_grid, grid_index, delta_r, vldr3, vkdr3, LD_pool,
pvpR_thread);
}
#else
if(GlobalV::GAMMA_ONLY_LOCAL && lgd>0)
{
this->gint_kernel_vlocal_meta(na_grid, grid_index, delta_r, vldr3, vkdr3, LD_pool, pvpR_grid);
}
if(!GlobalV::GAMMA_ONLY_LOCAL)
{
this->gint_kernel_vlocal_meta(na_grid, grid_index, delta_r, vldr3, vkdr3, LD_pool,
this->pvpR_reduced[inout->ispin]);
}
#endif
delete[] vldr3;
delete[] vkdr3;
}
else if(inout->job == Gint_Tools::job_type::force_meta)
{
double* vldr3 = Gint_Tools::get_vldr3(inout->vl, GlobalC::GridT.start_ind[grid_index], ncyz, dv);
double* vkdr3 = Gint_Tools::get_vldr3(inout->vofk, GlobalC::GridT.start_ind[grid_index], ncyz, dv);
double** DM_in;
if(GlobalV::GAMMA_ONLY_LOCAL) DM_in = inout->DM[GlobalV::CURRENT_SPIN];
if(!GlobalV::GAMMA_ONLY_LOCAL) DM_in = inout->DM_R;
#ifdef _OPENMP
this->gint_kernel_force_meta(na_grid, grid_index, delta_r, vldr3, vkdr3, LD_pool,
DM_in, inout->isforce, inout->isstress,
&fvl_dphi_thread, &svl_dphi_thread);
#else
this->gint_kernel_force_meta(na_grid, grid_index, delta_r, vldr3, vkdr3, LD_pool,
DM_in, inout->isforce, inout->isstress,
inout->fvl_dphi, inout->svl_dphi);
#endif
delete[] vldr3;
delete[] vkdr3;
}
} // int grid_index
#ifdef _OPENMP
if(inout->job==Gint_Tools::job_type::vlocal || inout->job==Gint_Tools::job_type::vlocal_meta)
{
if(GlobalV::GAMMA_ONLY_LOCAL && lgd>0)
{
for(int i=0;i<lgd*lgd;i++)
{
#pragma omp critical(gint_gamma)
pvpR_grid[i] += pvpR_thread[i];
}
delete[] pvpR_thread;
}
if(!GlobalV::GAMMA_ONLY_LOCAL)
{
for(int innrg=0; innrg<GlobalC::GridT.nnrg; innrg++)
{
#pragma omp critical(gint_k)
pvpR_reduced[inout->ispin][innrg] += pvpR_thread[innrg];
}
delete[] pvpR_thread;
}
}
if(inout->job==Gint_Tools::job_type::force || inout->job==Gint_Tools::job_type::force_meta)
{
if(inout->isforce)
{
#pragma omp critical(gint)
inout->fvl_dphi[0]+=fvl_dphi_thread;
}
if(inout->isstress)
{
#pragma omp critical(gint)
inout->svl_dphi[0]+=svl_dphi_thread;
}
}
#endif
} // end of #pragma omp parallel
#ifdef __MKL
mkl_set_num_threads(mkl_threads);
#endif
} // end of if (max_size)
ModuleBase::timer::tick("Gint_interface","cal_gint");
return;
}
void Gint::prep_grid(
const int &nbx_in,
const int &nby_in,
const int &nbz_in,
const int &nbz_start_in,
const int& ncxyz_in)
{
ModuleBase::TITLE(GlobalV::ofs_running,"Gint_k","prep_grid");
this->nbx = nbx_in;
this->nby = nby_in;
this->nbz = nbz_in;
this->ncxyz = ncxyz_in;
this->nbz_start = nbz_start_in;
assert(nbx>0);
assert(nby>0);
assert(nbz>=0);
assert(ncxyz>0);
assert( GlobalC::ucell.omega > 0.0);
return;
}