@@ -142,9 +142,6 @@ template<class DeviceType>
142142void 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*/)
420420template <class DeviceType >
421421void 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/* ---------------------------------------------------------------------- */
0 commit comments