Skip to content

Commit 115d603

Browse files
committed
Debug
1 parent 1c94850 commit 115d603

File tree

2 files changed

+168
-7
lines changed

2 files changed

+168
-7
lines changed

src/KOKKOS/fix_metatomic_kokkos.cpp

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,6 @@ template<class DeviceType>
142142
void FixMetatomicKokkos<DeviceType>::initial_integrate(int /*vflag*/)
143143
{
144144
// This function performs ML-driven position and momentum updates using Kokkos
145-
146-
atomKK->sync(execution_space,datamask_read);
147-
atomKK->modified(execution_space,datamask_modify);
148145

149146
auto x = atomKK->k_x.view<DeviceType>();
150147
auto v = atomKK->k_v.view<DeviceType>();
@@ -154,6 +151,9 @@ void FixMetatomicKokkos<DeviceType>::initial_integrate(int /*vflag*/)
154151
auto type = atomKK->k_type.view<DeviceType>();
155152
auto mask = atomKK->k_mask.view<DeviceType>();
156153

154+
atomKK->modified(execution_space,datamask_modify);
155+
atomKK->sync(execution_space,datamask_read);
156+
157157
// print the first few entries of v for debugging
158158
Kokkos::parallel_for(
159159
1,
@@ -420,11 +420,39 @@ void FixMetatomicKokkos<DeviceType>::initial_integrate(int /*vflag*/)
420420
template<class DeviceType>
421421
void FixMetatomicKokkos<DeviceType>::post_force(int /*vflag*/)
422422
{
423+
// auto v = atomKK->k_v.template view<DeviceType>();
424+
425+
// Kokkos::parallel_for(
426+
// 1,
427+
// KOKKOS_LAMBDA(const int& i) {
428+
// printf("Beginning of post force: v[%d] = (%f, %f, %f)\n",
429+
// i,
430+
// v(i,0),
431+
// v(i,1),
432+
// v(i,2));
433+
// }
434+
// );
435+
// Kokkos::fence();
436+
423437
// Take a snapshot of forces for Langevin compatibility
424438
// See fix_metatomic.cpp for detailed explanation
425-
atomKK->sync(execution_space, F_MASK);
439+
440+
// Kokkos::parallel_for(
441+
// 1,
442+
// KOKKOS_LAMBDA(const int& i) {
443+
// printf("After sync: v[%d] = (%f, %f, %f)\n",
444+
// i,
445+
// v(i,0),
446+
// v(i,1),
447+
// v(i,2));
448+
// }
449+
// );
450+
// Kokkos::fence();
426451

427452
auto f = atomKK->k_f.template view<DeviceType>();
453+
454+
atomKK->sync(execution_space, F_MASK);
455+
428456
int nlocal = atomKK->nlocal;
429457
if (igroup == atomKK->firstgroup) nlocal = atomKK->nfirst;
430458

@@ -437,6 +465,18 @@ void FixMetatomicKokkos<DeviceType>::post_force(int /*vflag*/)
437465
auto f_pre_sub = Kokkos::subview(f_pre_kk, std::make_pair(0, nlocal), Kokkos::ALL);
438466
auto f_sub = Kokkos::subview(f, std::make_pair(0, nlocal), Kokkos::ALL);
439467
Kokkos::deep_copy(f_pre_sub, f_sub);
468+
469+
// Kokkos::parallel_for(
470+
// 1,
471+
// KOKKOS_LAMBDA(const int& i) {
472+
// printf("End of post force: v[%d] = (%f, %f, %f)\n",
473+
// i,
474+
// v(i,0),
475+
// v(i,1),
476+
// v(i,2));
477+
// }
478+
// );
479+
// Kokkos::fence();
440480
}
441481

442482
/* ---------------------------------------------------------------------- */
@@ -446,8 +486,6 @@ void FixMetatomicKokkos<DeviceType>::final_integrate()
446486
{
447487
// Apply velocity corrections from forces added after post_force
448488
// This handles stochastic forces from Langevin thermostats
449-
atomKK->sync(execution_space, V_MASK | F_MASK | MASK_MASK | RMASS_MASK | TYPE_MASK);
450-
atomKK->modified(execution_space, V_MASK);
451489

452490
auto v = atomKK->k_v.template view<DeviceType>();
453491
auto f = atomKK->k_f.template view<DeviceType>();
@@ -456,6 +494,23 @@ void FixMetatomicKokkos<DeviceType>::final_integrate()
456494
auto type = atomKK->k_type.template view<DeviceType>();
457495
auto mask = atomKK->k_mask.template view<DeviceType>();
458496

497+
498+
std::cout << execution_space << std::endl; //
499+
500+
// atomKK->sync(execution_space, V_MASK | F_MASK | MASK_MASK | RMASS_MASK | TYPE_MASK);
501+
502+
Kokkos::parallel_for(
503+
1,
504+
KOKKOS_LAMBDA(const int& i) {
505+
printf("Beginning of final_integrate: v[%d] = (%f, %f, %f)\n",
506+
i,
507+
v(i,0),
508+
v(i,1),
509+
v(i,2));
510+
}
511+
);
512+
Kokkos::fence();
513+
459514
auto f_pre_kk = this->f_pre_kk;
460515
auto groupbit = this->groupbit;
461516

@@ -484,14 +539,29 @@ void FixMetatomicKokkos<DeviceType>::final_integrate()
484539
if (mask[i] & groupbit) {
485540
double mass_i = use_rmass ? rmass[i] : mass[type[i]];
486541
double dtfm = dtf / mass_i;
542+
543+
if (i == 0)
544+
printf("Velocities before correction: v[%d] = (%f, %f, %f)\n",
545+
i,
546+
v(i, 0),
547+
v(i, 1),
548+
v(i, 2));
487549

488550
// Apply only the incremental force (f - f_pre) to velocities
489551
v(i, 0) += (f(i, 0) - f_pre_kk(i, 0)) * dtfm;
490552
v(i, 1) += (f(i, 1) - f_pre_kk(i, 1)) * dtfm;
491553
v(i, 2) += (f(i, 2) - f_pre_kk(i, 2)) * dtfm;
554+
555+
if (i == 0)
556+
printf("Velocities after correction: v[%d] = (%f, %f, %f)\n",
557+
i,
558+
v(i, 0),
559+
v(i, 1),
560+
v(i, 2));
492561
}
493562
}
494563
);
564+
Kokkos::fence();
495565

496566
// auto v = atomKK->k_v.template view<DeviceType>();
497567

@@ -511,6 +581,8 @@ void FixMetatomicKokkos<DeviceType>::final_integrate()
511581

512582
// atomKK->sync(execution_space, ALL_MASK);
513583
// atomKK->modified(execution_space, ALL_MASK);
584+
585+
atomKK->modified(execution_space, V_MASK);
514586
}
515587

516588
/* ---------------------------------------------------------------------- */

src/KOKKOS/verlet_kokkos.cpp

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,16 @@ void VerletKokkos::run(int n)
352352
//atomKK->sync(Host,ALL_MASK);
353353
//atomKK->modified(Host,ALL_MASK);
354354

355+
Kokkos::parallel_for(
356+
1,
357+
KOKKOS_LAMBDA(const int& i) {
358+
printf("1: %f %f %f\n",
359+
v(i,0),
360+
v(i,1),
361+
v(i,2));
362+
});
363+
Kokkos::fence();
364+
355365
if (n_pre_exchange) {
356366
timer->stamp();
357367
modify->pre_exchange();
@@ -377,6 +387,16 @@ void VerletKokkos::run(int n)
377387
if (sortflag && ntimestep >= atomKK->nextsort) atomKK->sort();
378388
comm->borders();
379389

390+
Kokkos::parallel_for(
391+
1,
392+
KOKKOS_LAMBDA(const int& i) {
393+
printf("2: %f %f %f\n",
394+
v(i,0),
395+
v(i,1),
396+
v(i,2));
397+
});
398+
Kokkos::fence();
399+
380400
// added debug
381401
//atomKK->sync(Host,ALL_MASK);
382402
//atomKK->modified(Host,ALL_MASK);
@@ -396,6 +416,16 @@ void VerletKokkos::run(int n)
396416
}
397417
}
398418

419+
Kokkos::parallel_for(
420+
1,
421+
KOKKOS_LAMBDA(const int& i) {
422+
printf("3: %f %f %f\n",
423+
v(i,0),
424+
v(i,1),
425+
v(i,2));
426+
});
427+
Kokkos::fence();
428+
399429
// check if kernels can be fused, must come after initial_integrate
400430

401431
fuse_check(i,n);
@@ -415,6 +445,16 @@ void VerletKokkos::run(int n)
415445
timer->stamp(Timer::MODIFY);
416446
}
417447

448+
Kokkos::parallel_for(
449+
1,
450+
KOKKOS_LAMBDA(const int& i) {
451+
printf("4: %f %f %f\n",
452+
v(i,0),
453+
v(i,1),
454+
v(i,2));
455+
});
456+
Kokkos::fence();
457+
418458
bool execute_on_host = false;
419459
unsigned int datamask_read_host = 0;
420460
unsigned int datamask_exclude = 0;
@@ -467,6 +507,16 @@ void VerletKokkos::run(int n)
467507
}
468508
}
469509

510+
Kokkos::parallel_for(
511+
1,
512+
KOKKOS_LAMBDA(const int& i) {
513+
printf("5: %f %f %f\n",
514+
v(i,0),
515+
v(i,1),
516+
v(i,2));
517+
});
518+
Kokkos::fence();
519+
470520
if (pair_compute_flag) {
471521
atomKK->sync(force->pair->execution_space,force->pair->datamask_read);
472522
atomKK->sync(force->pair->execution_space,~(~force->pair->datamask_read|datamask_exclude));
@@ -487,6 +537,16 @@ void VerletKokkos::run(int n)
487537
}
488538
}
489539

540+
Kokkos::parallel_for(
541+
1,
542+
KOKKOS_LAMBDA(const int& i) {
543+
printf("6: %f %f %f\n",
544+
v(i,0),
545+
v(i,1),
546+
v(i,2));
547+
});
548+
Kokkos::fence();
549+
490550
if (atomKK->molecular) {
491551
if (force->bond) {
492552
atomKK->sync(force->bond->execution_space,~(~force->bond->datamask_read|datamask_exclude));
@@ -535,6 +595,16 @@ void VerletKokkos::run(int n)
535595
timer->stamp(Timer::MODIFY);
536596
}
537597

598+
Kokkos::parallel_for(
599+
1,
600+
KOKKOS_LAMBDA(const int& i) {
601+
printf("7: %f %f %f\n",
602+
v(i,0),
603+
v(i,1),
604+
v(i,2));
605+
});
606+
Kokkos::fence();
607+
538608
// reverse communication of forces
539609

540610
if (force->newton) {
@@ -543,11 +613,30 @@ void VerletKokkos::run(int n)
543613
timer->stamp(Timer::COMM);
544614
}
545615

616+
Kokkos::parallel_for(
617+
1,
618+
KOKKOS_LAMBDA(const int& i) {
619+
printf("8: %f %f %f\n",
620+
v(i,0),
621+
v(i,1),
622+
v(i,2));
623+
});
624+
Kokkos::fence();
625+
546626
// force modifications, final time integration, diagnostics
547627

548628
if (n_post_force) modify->post_force(vflag);
549629

550-
// print positions
630+
Kokkos::parallel_for(
631+
1,
632+
KOKKOS_LAMBDA(const int& i) {
633+
printf("9: %f %f %f\n",
634+
v(i,0),
635+
v(i,1),
636+
v(i,2));
637+
});
638+
Kokkos::fence();
639+
551640
Kokkos::parallel_for(
552641
1,
553642
KOKKOS_LAMBDA(const int& i) {

0 commit comments

Comments
 (0)