forked from leopwma/spilady
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core_dp_GPU.cu
596 lines (485 loc) · 22.6 KB
/
core_dp_GPU.cu
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
/********************************************************************************
*
* Copyright (C) 2015 Culham Centre for Fusion Energy,
* United Kingdom Atomic Energy Authority, Oxfordshire OX14 3DB, UK
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
********************************************************************************
*
* Program: SPILADY - A Spin-Lattice Dynamics Simulation Program
* Version: 1.0
* Date: Aug 2015
* Author: Pui-Wai (Leo) MA
* Contact: [email protected]
* Address: Culham Centre for Fusion Energy, OX14 3DB, United Kingdom
*
*********************************************************************************
*
* Edit notes:
* Date: Apr 2016
* Author: Pui-Wai (Leo) MA
* Address: Culham Centre for Fusion Energy, OX14 3DB, United Kingdom
* 1) variable "Msteps_quantum" and "Nfrequency_quantum" are added.
* 2) Now the quantum noise change every "Msteps_quantum" steps.
*
*******************************************************************************/
#if (defined MD || defined SLDH || defined SLDHL || defined SLDNC) && defined GPU
#include "spilady.h"
#include "prototype_GPU.h"
/************************************************************************
* GPU prototypes
************************************************************************/
#if defined lattlang && defined localcolmot
__global__ void LP1dp(int i,
int *allocate_threads_ptr_d,
struct cell_struct **allocate_cell_ptr_ptr_d,
int *max_no_of_members_ptr_d,
struct varGPU *var_ptr_d,
struct atom_struct *first_atom_ptr_d,
struct cell_struct *first_cell_ptr_d,
curandState *rand_state_ptr_d,
double dt);
__global__ void LP2dp(struct varGPU *var_ptr_d, struct atom_struct *first_atom_ptr_d,
struct cell_struct *first_cell_ptr_d, double dt);
#endif
#ifdef lattlang
__global__ void LP3dp(struct varGPU *var_ptr_d, struct atom_struct *first_atom_ptr_d,
struct cell_struct *first_cell_ptr_d, curandState *rand_state_ptr_d,
#ifdef quantumnoise
double* quantum_rand_memory_ptr_d, double* H_ptr_d,
double* quantum_noise_ptr_d, int* quantum_count_ptr_d,
int Msteps, int Nf2,
#endif
double dt);
__global__ void LP4dp(struct varGPU *var_ptr_d, struct atom_struct *first_atom_ptr_d,
struct cell_struct *first_cell_ptr_d, double dt);
#endif
#if defined lattlang && defined localcolmot
__global__ void LP5dp(int i,
int *allocate_threads_ptr_d,
struct cell_struct **allocate_cell_ptr_ptr_d,
int *max_no_of_members_ptr_d,
struct varGPU *var_ptr_d,
struct atom_struct *first_atom_ptr_d,
struct cell_struct *first_cell_ptr_d,
double dt);
__global__ void LP6dp(int i,
int *allocate_threads_ptr_d,
struct cell_struct **allocate_cell_ptr_ptr_d,
int *max_no_of_members_ptr_d,
struct varGPU *var_ptr_d,
struct atom_struct *first_atom_ptr_d,
struct cell_struct *first_cell_ptr_d,
double dt);
#endif
#ifndef lattlang
__global__ void LP7dp(struct varGPU *var_ptr_d, struct atom_struct *first_atom_ptr_d, double dt);
#endif
__global__ void LP8dp_part1(struct varGPU *var_ptr_d, struct atom_struct *first_atom_ptr_d, vector *ave_p_ptr_d);
__global__ void LP8dp_part2(struct varGPU *var_ptr_d, vector *ave_p_ptr_d);
__global__ void LP9dp_part1(struct varGPU *var_ptr_d, struct atom_struct *first_atom_ptr_d, double *total_ke_old_ptr_d, double *total_ke_new_ptr_d, vector ave_p);
__global__ void LP9dp_part2(struct varGPU *var_ptr_d, double *total_ke_old_ptr_d, double *total_ke_new_ptr_d);
__global__ void LP10dp(struct varGPU *var_ptr_d, struct atom_struct *first_atom_ptr_d, double factor);
__global__ void LP11dp(struct varGPU *var_ptr_d, struct atom_struct *first_atom_ptr_d);
/************************************************************************
* CPU codes
************************************************************************/
#ifdef lattlang
void core_dp_A_GPU(double dt);
void core_dp_B_GPU(double dt);
#endif
#if defined lattlang && defined localcolmot
void core_dp_C1_GPU(double dt);
void core_dp_C2_GPU(double dt);
#endif
void rescale_momentum();
void core_dp_GPU(double dt){
#ifdef lattlang
#ifdef localcolmot
core_dp_C1_GPU(dt/2e0); //subtract average momentum in a cell
#endif
core_dp_B_GPU(dt/2e0); // solution of dp/dt = -gamma/mass*p
core_dp_A_GPU(dt); // add (forces + noise)*dt and substract average noise in a cel ifdef localcolmot
core_dp_B_GPU(dt/2e0); // solution of dp/dt = -gamma/mass*p
#ifdef localcolmot
core_dp_C2_GPU(dt/2e0); //subtract average momentum in a cell
#endif
#else
LP7dp<<<no_of_blocks, no_of_threads>>>(var_ptr_d, first_atom_ptr_d, dt);
#endif
rescale_momentum();
LP11dp<<<no_of_blocks, no_of_threads>>>(var_ptr_d, first_atom_ptr_d);
}
void core_dp(double dt){
core_dp_GPU(dt);
}
#ifdef lattlang
void core_dp_A_GPU(double dt){
#ifdef localcolmot
for (int i = 0 ; i < ngroups ; ++i){
LP1dp<<<no_of_blocks_members, no_of_threads>>>(i,
allocate_threads_ptr_d,
allocate_cell_ptr_ptr_d,
max_no_of_members_ptr_d,
var_ptr_d,
first_atom_ptr_d,
first_cell_ptr_d,
rand_state_ptr_d,
dt);
}
LP2dp<<<no_of_blocks, no_of_threads>>>(var_ptr_d, first_atom_ptr_d,
first_cell_ptr_d, dt);
#else
LP3dp<<<no_of_blocks, no_of_threads>>>(var_ptr_d, first_atom_ptr_d,
first_cell_ptr_d, rand_state_ptr_d,
#ifdef quantumnoise
quantum_rand_memory_ptr_d, H_ptr_d,
quantum_noise_ptr_d, quantum_count_ptr_d,
Msteps_quantum, Nfrequency_quantum_2,
#endif
dt);
#endif
}
void core_dp_B_GPU(double dt){
LP4dp<<<no_of_blocks,no_of_threads>>>(var_ptr_d, first_atom_ptr_d, first_cell_ptr_d, dt);
}
#endif
#if defined lattlang && defined localcolmot
void core_dp_C1_GPU(double dt){
for (int i = 0 ; i < ngroups ; ++i){
LP5dp<<<no_of_blocks_members, no_of_threads>>>(i,
allocate_threads_ptr_d,
allocate_cell_ptr_ptr_d,
max_no_of_members_ptr_d,
var_ptr_d,
first_atom_ptr_d,
first_cell_ptr_d,
dt);
}
}
void core_dp_C2_GPU(double dt){
for (int i = ngroups - 1 ; i >=0 ; --i){
LP6dp<<<no_of_blocks_members, no_of_threads>>>(i,
allocate_threads_ptr_d,
allocate_cell_ptr_ptr_d,
max_no_of_members_ptr_d,
var_ptr_d,
first_atom_ptr_d,
first_cell_ptr_d,
dt);
}
}
#endif
void rescale_momentum(){
size_t size1 = no_of_MP*no_of_threads*sizeof(vector);
vector ave_p = vec_zero();
vector *ave_p_ptr_d;
cudaMalloc((void**)&ave_p_ptr_d, size1);
LP8dp_part1<<<no_of_MP, no_of_threads>>>(var_ptr_d, first_atom_ptr_d, ave_p_ptr_d);
LP8dp_part2<<<no_of_MP, no_of_threads>>>(var_ptr_d, ave_p_ptr_d);
cudaMemcpy(&ave_p, ave_p_ptr_d, sizeof(vector), cudaMemcpyDeviceToHost);
ave_p = vec_divide(ave_p, double(natom));
size_t size2 = no_of_MP*no_of_threads*sizeof(double);
double total_ke_old = 0e0;
double total_ke_new = 0e0;
double *total_ke_old_ptr_d;
double *total_ke_new_ptr_d;
cudaMalloc((void**)&total_ke_old_ptr_d, size2);
cudaMalloc((void**)&total_ke_new_ptr_d, size2);
LP9dp_part1<<<no_of_MP, no_of_threads>>>(var_ptr_d, first_atom_ptr_d, total_ke_old_ptr_d, total_ke_new_ptr_d, ave_p);
LP9dp_part2<<<no_of_MP, no_of_threads>>>(var_ptr_d, total_ke_old_ptr_d, total_ke_new_ptr_d);
cudaMemcpy(&total_ke_old, total_ke_old_ptr_d, sizeof(double), cudaMemcpyDeviceToHost);
cudaMemcpy(&total_ke_new, total_ke_new_ptr_d, sizeof(double), cudaMemcpyDeviceToHost);
double factor = sqrt(total_ke_old/total_ke_new);
if(total_ke_new < 1e-10) factor = 1e0;
LP10dp<<<no_of_blocks, no_of_threads>>>(var_ptr_d, first_atom_ptr_d, factor);
cudaFree(ave_p_ptr_d);
cudaFree(total_ke_old_ptr_d);
cudaFree(total_ke_new_ptr_d);
}
/**************************************************************************************
* GPU codes
**************************************************************************************/
#if defined lattlang && defined localcolmot
__global__ void LP1dp(int i,
int *allocate_threads_ptr_d,
struct cell_struct **allocate_cell_ptr_ptr_d,
int *max_no_of_members_ptr_d,
struct varGPU *var_ptr_d,
struct atom_struct *first_atom_ptr_d,
struct cell_struct *first_cell_ptr_d,
curandState *rand_state_ptr_d,
double dt){
int j = blockIdx.x*blockDim.x + threadIdx.x;
if (j < *(allocate_threads_ptr_d + i)){
struct atom_struct *atom_ptr;
atom_ptr = (*(allocate_cell_ptr_ptr_d + i*(*max_no_of_members_ptr_d) + j))->head_ptr;
struct cell_struct *cell_ptr;
bool ave_activated = 0;
if (atom_ptr != NULL){
cell_ptr = first_cell_ptr_d + atom_ptr->new_cell_index;
cell_ptr->ave_fluct_force = vec_zero_d();
ave_activated = 1;
}
while(atom_ptr != NULL){
#ifdef extforce
atom_ptr->f = vec_add_d(atom_ptr->f, atom_ptr->fext);
#endif
//generating random numbers
vector fluct_force;
fluct_force.x = normal_rand_d(rand_state_ptr_d + j);
fluct_force.y = normal_rand_d(rand_state_ptr_d + j);
fluct_force.z = normal_rand_d(rand_state_ptr_d + j);
#ifdef eltemp
double fluct_force_length = sqrt(2e0*cell_ptr->Te*var_ptr_d->gamma_L/dt);
#else
double fluct_force_length = sqrt(2e0*var_ptr_d->temperature*var_ptr_d->gamma_L/dt);
#endif
fluct_force = vec_times_d(fluct_force_length, fluct_force);
atom_ptr->p = vec_add_d(atom_ptr->p, vec_times_d(dt, vec_add_d(atom_ptr->f, fluct_force)));
cell_ptr->ave_fluct_force = vec_add_d(cell_ptr->ave_fluct_force, fluct_force);
atom_ptr = atom_ptr->next_atom_ptr;
}
if (ave_activated){
cell_ptr->ave_fluct_force = vec_divide_d(cell_ptr->ave_fluct_force, cell_ptr->no_of_atoms_in_cell);
}
}
}
__global__ void LP2dp(struct varGPU *var_ptr_d, struct atom_struct *first_atom_ptr_d,
struct cell_struct *first_cell_ptr_d, double dt){
int i = blockIdx.x*blockDim.x + threadIdx.x;
if (i < var_ptr_d->natom){
struct atom_struct *atom_ptr;
atom_ptr = first_atom_ptr_d + i;
struct cell_struct *cell_ptr;
cell_ptr = first_cell_ptr_d + (atom_ptr->new_cell_index);
atom_ptr->p = vec_sub_d(atom_ptr->p, vec_times_d(dt, cell_ptr->ave_fluct_force));
}
}
#endif
#ifdef lattlang
__global__ void LP3dp(struct varGPU *var_ptr_d, struct atom_struct *first_atom_ptr_d,
struct cell_struct *first_cell_ptr_d, curandState *rand_state_ptr_d,
#ifdef quantumnoise
double* quantum_rand_memory_ptr_d, double* H_ptr_d,
double* quantum_noise_ptr_d, int* quantum_count_ptr_d,
int Msteps, int Nf2,
#endif
double dt){
int i = blockIdx.x*blockDim.x + threadIdx.x;
if (i < var_ptr_d->natom){
struct atom_struct *atom_ptr;
atom_ptr = first_atom_ptr_d + i;
#ifdef extforce
atom_ptr->f = vec_add_d(atom_ptr->f, atom_ptr->fext);
#endif
vector fluct_force;
//generating random numbers
#ifdef quantumnoise
double h = dt*Msteps;
double fluct_force_length = sqrt(2e0*var_ptr_d->gamma_L/h);
fluct_force.x = quantum_noise_d(3*i, i, quantum_rand_memory_ptr_d, rand_state_ptr_d, H_ptr_d,
quantum_noise_ptr_d, quantum_count_ptr_d, Msteps, Nf2);
fluct_force.y = quantum_noise_d(3*i+1, i, quantum_rand_memory_ptr_d, rand_state_ptr_d, H_ptr_d,
quantum_noise_ptr_d, quantum_count_ptr_d, Msteps, Nf2);
fluct_force.z = quantum_noise_d(3*i+2, i, quantum_rand_memory_ptr_d, rand_state_ptr_d, H_ptr_d,
quantum_noise_ptr_d, quantum_count_ptr_d, Msteps, Nf2);
#else
#ifdef eltemp
struct cell_struct *cell_ptr;
cell_ptr = first_cell_ptr_d + (atom_ptr->new_cell_index);
double fluct_force_length = sqrt(2e0*cell_ptr->Te*var_ptr_d->gamma_L/dt);
#else
double fluct_force_length = sqrt(2e0*var_ptr_d->temperature*var_ptr_d->gamma_L/dt);
#endif
fluct_force.x = normal_rand_d(rand_state_ptr_d + i);
fluct_force.y = normal_rand_d(rand_state_ptr_d + i);
fluct_force.z = normal_rand_d(rand_state_ptr_d + i);
#endif
fluct_force = vec_times_d(fluct_force_length, fluct_force);
atom_ptr->p = vec_add_d(atom_ptr->p, vec_times_d(dt, vec_add_d(atom_ptr->f, fluct_force)));
}
}
__global__ void LP4dp(struct varGPU *var_ptr_d, struct atom_struct *first_atom_ptr_d,
struct cell_struct *first_cell_ptr_d, double dt){
int i = blockIdx.x*blockDim.x + threadIdx.x;
if (i < var_ptr_d->natom){
struct atom_struct *atom_ptr;
atom_ptr = first_atom_ptr_d + i;
#ifdef localcolmot
struct cell_struct *cell_ptr;
cell_ptr = first_cell_ptr_d + atom_ptr->new_cell_index;
double exp_dt = exp(-(var_ptr_d->gamma_L)/(var_ptr_d->atmass)*dt*(1e0-1e0/cell_ptr->no_of_atoms_in_cell));
#else
double exp_dt = exp(-(var_ptr_d->gamma_L)/(var_ptr_d->atmass)*dt);
#endif
atom_ptr->p = vec_times_d(exp_dt, atom_ptr->p);
}
}
#endif
#if defined lattlang && defined localcolmot
__global__ void LP5dp(int i,
int *allocate_threads_ptr_d,
struct cell_struct **allocate_cell_ptr_ptr_d,
int *max_no_of_members_ptr_d,
struct varGPU *var_ptr_d,
struct atom_struct *first_atom_ptr_d,
struct cell_struct *first_cell_ptr_d,
double dt){
int j = blockIdx.x*blockDim.x + threadIdx.x;
if (j < *(allocate_threads_ptr_d + i)){
struct atom_struct *atom_ptr;
atom_ptr = (*(allocate_cell_ptr_ptr_d + i*(*max_no_of_members_ptr_d) + j))->head_ptr;
while(atom_ptr != NULL){
vector sum_p;
sum_p = vec_zero_d();
struct atom_struct *work_ptr;
work_ptr = (*(allocate_cell_ptr_ptr_d + i*(*max_no_of_members_ptr_d) + j))->head_ptr;
while(work_ptr != NULL){
sum_p = vec_add_d(sum_p, work_ptr->p);
work_ptr = work_ptr->next_atom_ptr;
}
double factor = var_ptr_d->gamma_L/var_ptr_d->atmass*dt/
((first_cell_ptr_d + atom_ptr->new_cell_index)->no_of_atoms_in_cell);
atom_ptr->p = vec_add_d(atom_ptr->p, vec_times_d(factor, vec_sub_d(sum_p, atom_ptr->p)));
atom_ptr = atom_ptr->next_atom_ptr;
}
}
}
__global__ void LP6dp(int i,
int *allocate_threads_ptr_d,
struct cell_struct **allocate_cell_ptr_ptr_d,
int *max_no_of_members_ptr_d,
struct varGPU *var_ptr_d,
struct atom_struct *first_atom_ptr_d,
struct cell_struct *first_cell_ptr_d,
double dt){
int j = blockIdx.x*blockDim.x + threadIdx.x;
if (j < *(allocate_threads_ptr_d + i)){
struct atom_struct *atom_ptr;
atom_ptr = (*(allocate_cell_ptr_ptr_d + i*(*max_no_of_members_ptr_d) + j))->tail_ptr;
while(atom_ptr != NULL){
vector sum_p;
sum_p = vec_zero_d();
struct atom_struct *work_ptr;
work_ptr = (*(allocate_cell_ptr_ptr_d + i*(*max_no_of_members_ptr_d) + j))->tail_ptr;
while(work_ptr != NULL){
sum_p = vec_add_d(sum_p, work_ptr->p);
work_ptr = work_ptr->prev_atom_ptr;
}
double factor = var_ptr_d->gamma_L/var_ptr_d->atmass*dt/
((first_cell_ptr_d + atom_ptr->new_cell_index)->no_of_atoms_in_cell);
atom_ptr->p = vec_add_d(atom_ptr->p, vec_times_d(factor, vec_sub_d(sum_p, atom_ptr->p)));
atom_ptr = atom_ptr->prev_atom_ptr;
}
}
}
#endif
#ifndef lattlang
__global__ void LP7dp(struct varGPU *var_ptr_d, struct atom_struct *first_atom_ptr_d, double dt){
int i = blockIdx.x*blockDim.x + threadIdx.x;
if (i < var_ptr_d->natom){
struct atom_struct *atom_ptr;
atom_ptr = first_atom_ptr_d + i;
#ifdef quench
atom_ptr->p = vec_zero_d();
#endif
atom_ptr->p = vec_add_d(atom_ptr->p, vec_times_d(dt,atom_ptr->f));
}
}
#endif
__global__ void LP8dp_part1(struct varGPU *var_ptr_d, struct atom_struct *first_atom_ptr_d, vector *ave_p_ptr_d)
{
int i = blockIdx.x*blockDim.x + threadIdx.x;
*(ave_p_ptr_d + i) = vec_zero_d();
int area = blockDim.x*gridDim.x;
int k = (var_ptr_d->natom - 1)/area + 1;
for (int j = 0; j < k; ++j){
int m = i + j*area;
if (m < var_ptr_d->natom) {
struct atom_struct *atom_ptr;
atom_ptr = first_atom_ptr_d + m;
*(ave_p_ptr_d + i) = vec_add_d(*(ave_p_ptr_d + i), atom_ptr->p);
}
}
__syncthreads();
}
__global__ void LP8dp_part2(struct varGPU *var_ptr_d, vector *ave_p_ptr_d)
{
int depth = blockIdx.x*blockDim.x;
if (threadIdx.x == 0){
for (int j = 1; j < blockDim.x; ++j) *(ave_p_ptr_d + depth) = vec_add_d(*(ave_p_ptr_d + depth), *(ave_p_ptr_d + depth + j));
}
__threadfence();
if (blockIdx.x == 0 && threadIdx.x == 0){
for (int j = 1; j < gridDim.x; ++j) *ave_p_ptr_d = vec_add_d(*ave_p_ptr_d, *(ave_p_ptr_d + j*blockDim.x));
}
}
__global__ void LP9dp_part1(struct varGPU *var_ptr_d, struct atom_struct *first_atom_ptr_d, double *total_ke_old_ptr_d, double *total_ke_new_ptr_d, vector ave_p)
{
int i = blockIdx.x*blockDim.x + threadIdx.x;
*(total_ke_old_ptr_d + i) = 0e0;
*(total_ke_new_ptr_d + i) = 0e0;
int area = blockDim.x*gridDim.x;
int k = (var_ptr_d->natom - 1)/area + 1;
for (int j = 0; j < k; ++j){
int m = i + j*area;
if (m < var_ptr_d->natom) {
struct atom_struct *atom_ptr;
atom_ptr = first_atom_ptr_d + m;
atom_ptr->ke = vec_sq_d(atom_ptr->p)/2e0/var_ptr_d->atmass;
*(total_ke_old_ptr_d + i) += atom_ptr->ke;
atom_ptr->p = vec_sub_d(atom_ptr->p, ave_p);
atom_ptr->ke = vec_sq_d(atom_ptr->p)/2e0/var_ptr_d->atmass;
*(total_ke_new_ptr_d + i) += atom_ptr->ke;
}
}
__syncthreads();
}
__global__ void LP9dp_part2(struct varGPU *var_ptr_d, double *total_ke_old_ptr_d, double *total_ke_new_ptr_d)
{
int depth = blockIdx.x*blockDim.x;
if (threadIdx.x == 0){
for (int j = 1; j < blockDim.x; ++j) *(total_ke_old_ptr_d + depth) += *(total_ke_old_ptr_d + depth + j);
}
if (threadIdx.x == 1){
for (int j = 1; j < blockDim.x; ++j) *(total_ke_new_ptr_d + depth) += *(total_ke_new_ptr_d + depth + j);
}
__threadfence();
if (blockIdx.x == 0 && threadIdx.x == 0){
for (int j = 1; j < gridDim.x; ++j) *total_ke_old_ptr_d += *(total_ke_old_ptr_d + j*blockDim.x);
}
if (blockIdx.x == 0 && threadIdx.x == 1){
for (int j = 1; j < gridDim.x; ++j) *total_ke_new_ptr_d += *(total_ke_new_ptr_d + j*blockDim.x);
}
}
__global__ void LP10dp(struct varGPU *var_ptr_d, struct atom_struct *first_atom_ptr_d, double factor)
{
int i = blockIdx.x*blockDim.x + threadIdx.x;
if (i < var_ptr_d->natom){
struct atom_struct *atom_ptr;
atom_ptr = first_atom_ptr_d + i;
atom_ptr->p = vec_times_d(factor,atom_ptr->p);
}
}
__global__ void LP11dp(struct varGPU *var_ptr_d, struct atom_struct *first_atom_ptr_d)
{
int i = blockIdx.x*blockDim.x + threadIdx.x;
if (i < var_ptr_d->natom){
struct atom_struct *atom_ptr;
atom_ptr = first_atom_ptr_d + i;
atom_ptr->ke = vec_sq_d(atom_ptr->p)/2e0/var_ptr_d->atmass;
}
}
#endif