@@ -122,6 +122,7 @@ class MolWorld_sp3_multi : public MolWorld_sp3, public MultiSolverInterface { pu
122122 Quat4f* MDpars =0 ; // Molecular dynamics params
123123 Quat4f* TDrive =0 ; // temperature and drived dynamics
124124 Quat4f* averageForces =0 ; // accumulated force differences for thermodynamic integration
125+ Quat4i* jeParams = 0 ; // parameters for Jarzynski Equality [ nSystems ]
125126
126127 Quat4f* constr =0 ;
127128 Quat4f* constrK =0 ;
@@ -389,8 +390,8 @@ void TI_step(double lambda, double dE, double sigma, double dLambda, int nMDstep
389390 for (int ia=0 ; ia<ffls[isys].natoms ; ia++){
390391 if (ffls[isys].atypes [ia]==params.getAtomType (" Si" )){
391392 if (si_count < nCVs){
392- Quat4f acon = Quat4f{initial_positions[si_count].x , initial_positions[si_count].y , initial_positions[si_count].z , 1e2f };
393- Quat4f aconK = Quat4f{final_positions[si_count].x , final_positions[si_count].y , final_positions[si_count].z , ( float )nLambda };
393+ Quat4f acon = Quat4f{initial_positions[si_count].x , initial_positions[si_count].y , initial_positions[si_count].z , 5 . 0f };
394+ Quat4f aconK = Quat4f{final_positions[si_count].x , final_positions[si_count].y , final_positions[si_count].z , 0 . 0f };
394395 constr [isys*ocl.nAtoms + ia] = acon;
395396 constrK[isys*ocl.nAtoms + ia] = aconK;
396397 }
@@ -402,6 +403,7 @@ void TI_step(double lambda, double dE, double sigma, double dLambda, int nMDstep
402403 upload ( ocl.ibuff_constrK , constrK );
403404
404405 double beta = 1.0 / (const_kB * go.T_target );
406+ double dLambda = 1.0 / (double )(nLambda - 1 );
405407 nPerVFs = nPerVFs_;
406408 int nBatches = nMDsteps / (nLambda * nPerVFs);
407409 if ( nBatches < 1 ) nBatches = 1 ;
@@ -416,20 +418,15 @@ void TI_step(double lambda, double dE, double sigma, double dLambda, int nMDstep
416418 printf (" Equilibrating %d steps...\n " , nEQsteps);
417419 bSaveTrajectory = false ;
418420 nPerVFs = nEQsteps;
419- for (int isys=0 ; isys<nSystems; isys++){
420- TDrive[isys].z = -1 ;
421- }
422- ocl.upload ( ocl.ibuff_TDrive , TDrive );
421+ for (int isys=0 ; isys<nSystems; isys++){ jeParams[isys].x = -1 ; }
422+ ocl.upload ( ocl.ibuff_jeParams , jeParams );
423423 run_ocl_opt ( nEQsteps, Fconv );
424424
425425 // 2. Pulling
426426 bSaveTrajectory = true ;
427- nPerVFs = nPerVFs_; // High resolution pulling
428- std::vector<bool > bExploring_old (nSystems);
429- for (int isys=0 ; isys<nSystems; isys++){
430- TDrive[isys].z = 0 ;
431- }
432- ocl.upload ( ocl.ibuff_TDrive , TDrive );
427+ nPerVFs = nPerVFs_;
428+ for (int isys=0 ; isys<nSystems; isys++){ jeParams[isys].x = 0 ; jeParams[isys].y = nLambda; jeParams[isys].z = nPerVFs; jeParams[isys].w = 0 ; }
429+ ocl.upload ( ocl.ibuff_jeParams , jeParams );
433430 // Clear work buffer
434431 float * zero_work = new float [nSystems * nLambda];
435432 for (int i=0 ; i<nSystems * nLambda; i++) zero_work[i] = 0 ;
@@ -438,16 +435,24 @@ void TI_step(double lambda, double dE, double sigma, double dLambda, int nMDstep
438435
439436 printf (" Pulling for %d * %d = %d steps...\n " , nLambda, nPerVFs, nLambda*nPerVFs);
440437 run_ocl_opt ( nLambda*nPerVFs, Fconv );
441- for (int isys=0 ; isys<nSystems; isys++) gopts[isys].bExploring = bExploring_old[isys];
442438
443439 // 3. Download work and accumulate
444440 ocl.download ( ocl.ibuff_work , gpu_work );
445441 ocl.finishRaw ();
442+ // DEBUG: Print first few work values for system 0 in first batch
443+ if (batch==0 ){
444+ printf (" DEBUG gpu_work[sys=0]: " );
445+ for (int i=0 ; i<5 ; i++) printf (" [%d]=%g " , i, gpu_work[i]);
446+ printf (" dLambda=%g\n " , dLambda);
447+ printf (" DEBUG gpu_work[sys=0] dW: " );
448+ for (int i=0 ; i<5 ; i++) printf (" [%d]=%g " , i, gpu_work[i]*dLambda);
449+ printf (" \n " );
450+ }
446451
447452 for (int isys=0 ; isys<nSystems; isys++){
448453 double W_traj = 0 ;
449454 for (int i=0 ; i<nLambda; i++){
450- float dW = gpu_work[ isys * nLambda + i ];
455+ float dW = gpu_work[ isys * nLambda + i ]*dLambda ;
451456 W_traj += (double )dW;
452457 // if(isys==0 && i==0) printf("batch %d, isys %d, i %d, W %f\n", batch, isys, i, W);
453458 sum_exp_W[i] += exp (-beta * W_traj);
@@ -526,6 +531,7 @@ void realloc( int nSystems_ ){
526531
527532 // Initialize averageForces buffer for thermodynamic integration
528533 _realloc0 ( averageForces, nSystems, Quat4fZero );
534+ _realloc0 ( jeParams, nSystems, Quat4iMinusOnes );
529535
530536 _realloc ( pbcshifts, ocl.npbc *nSystems );
531537
@@ -1180,7 +1186,8 @@ double evalVFs( double Fconv=1e-6 ){
11801186 // TDrive[isys].z = 0;
11811187 // }
11821188 // printf("evalVFs() TDrive[isys].z = %f\n", TDrive[isys].z);
1183- TDrive[isys].z += 1 ;
1189+ jeParams[isys].x += 1 ;
1190+ jeParams[isys].w = 0 ;
11841191 // printf("evalVFs() TDrive[isys].z = %f\n", TDrive[isys].z);
11851192 TDrive[isys].w = randf (-1.0 ,1.0 );
11861193 }else {
@@ -1193,6 +1200,7 @@ double evalVFs( double Fconv=1e-6 ){
11931200 // printf( "MDpars{%g,%g,%g,%g}\n", MDpars[0].x,MDpars[0].y,MDpars[0].z,MDpars[0].w );
11941201 err |= ocl.upload ( ocl.ibuff_MDpars , MDpars );
11951202 err |= ocl.upload ( ocl.ibuff_TDrive , TDrive );
1203+ if (jeParams)err |= ocl.upload ( ocl.ibuff_jeParams , jeParams );
11961204 err |= ocl.upload ( ocl.ibuff_cvf , cvfs );
11971205 // //printf("MolWorld_sp3_multi::evalVFs() bGroupUpdate=%i \n", bGroupUpdate );
11981206 // if(bGroupUpdate){
0 commit comments