#include #ifndef C11 #ifdef HAVE_STRINGS_H #include #endif CPS_START_NAMESPACE //------------------------------------------------------------------ /*!\file \brief Definitions of the AlgHmcPhi methods. $Id: alg_hmc_phi.C,v 1.24 2006/12/14 17:53:37 chulwoo Exp $ */ //-------------------------------------------------------------------- // CVS keywords // // $Author: chulwoo $ // $Date: 2006/12/14 17:53:37 $ // $Header: /space/cvs/cps/cps++/src/alg/alg_hmd/alg_hmc_phi.C,v 1.24 2006/12/14 17:53:37 chulwoo Exp $ // $Id: alg_hmc_phi.C,v 1.24 2006/12/14 17:53:37 chulwoo Exp $ // $Name: v5_0_16_hantao_io_test_v7 $ // $Locker: $ // $RCSfile: alg_hmc_phi.C,v $ // $Revision: 1.24 $ // $Source: /space/cvs/cps/cps++/src/alg/alg_hmd/alg_hmc_phi.C,v $ // $State: Exp $ // //-------------------------------------------------------------------- //------------------------------------------------------------------ // // alg_hmc_phi.C // // AlgHmcPhi is derived from Alg and is relevant to the phi // Hybrid Monte Carlo Algorithm. // //------------------------------------------------------------------ CPS_END_NAMESPACE #include #include #include #include #include #include #include #include #include #include #include #ifdef HAVE_QCDOCOS_SCU_CHECKSUM_H #include #endif CPS_START_NAMESPACE //------------------------------------------------------------------ /*! \param latt The lattice on which the HMC algorithm runs. \param c_arg The common argument structure for all algorithms. \param arg The algorithm parameters. */ //------------------------------------------------------------------ AlgHmcPhi::AlgHmcPhi(Lattice& latt, CommonArg *c_arg, HmdArg *arg) : AlgHmd(latt, c_arg, arg) { int i; cname = "AlgHmcPhi"; char *fname = "AlgHmcPhi(L&,CommonArg*,HmdArg*)"; VRB.Func(cname,fname); int n_masses; // Initialize the number of dynamical fermion masses //---------------------------------------------------------------- n_frm_masses = hmd_arg->n_frm_masses; if(n_frm_masses > MAX_HMD_MASSES){ ERR.General(cname,fname, "hmd_arg->n_frm_masses = %d is larger than MAX_HMD_MASSES = %d\n", n_frm_masses, MAX_HMD_MASSES); } // Initialize the number of dynamical boson masses //---------------------------------------------------------------- n_bsn_masses = hmd_arg->n_bsn_masses; if(n_bsn_masses > MAX_HMD_MASSES){ ERR.General(cname,fname, "hmd_arg->n_bsn_masses = %d is larger than MAX_HMD_MASSES = %d\n", n_bsn_masses, MAX_HMD_MASSES); } // Calculate the fermion field size. //---------------------------------------------------------------- f_size = GJP.VolNodeSites() * latt.FsiteSize() / (latt.FchkbEvl()+1); // Allocate memory for the fermion CG arguments. //---------------------------------------------------------------- if(n_frm_masses != 0){ frm_cg_arg = (CgArg **) smalloc(n_frm_masses * sizeof(int)); if(frm_cg_arg == 0) ERR.Pointer(cname,fname, "frm_cg_arg"); VRB.Smalloc(cname,fname, "frm_cg_arg",frm_cg_arg, n_frm_masses * sizeof(int)); for(i=0; imass = hmd_arg->frm_mass[i]; frm_cg_arg[i]->max_num_iter = hmd_arg->max_num_iter[i]; frm_cg_arg[i]->stop_rsd = hmd_arg->stop_rsd[i]; } // Allocate memory for the boson CG arguments. //---------------------------------------------------------------- if(n_bsn_masses != 0){ bsn_cg_arg = (CgArg **) smalloc(n_bsn_masses * sizeof(int)); if(bsn_cg_arg == 0) ERR.Pointer(cname,fname, "bsn_cg_arg"); VRB.Smalloc(cname,fname, "bsn_cg_arg",bsn_cg_arg, n_bsn_masses * sizeof(int)); for(i=0; imass = hmd_arg->bsn_mass[i]; bsn_cg_arg[i]->max_num_iter = hmd_arg->max_num_iter[i]; bsn_cg_arg[i]->stop_rsd = hmd_arg->stop_rsd[i]; } // Allocate memory for the phi pseudo fermion field. //---------------------------------------------------------------- if(n_frm_masses != 0){ phi = (Vector **) smalloc(n_frm_masses * sizeof(int)); if(phi == 0) ERR.Pointer(cname,fname, "phi"); VRB.Smalloc(cname,fname, "phi",phi, n_frm_masses * sizeof(int)); for(i=0; i n_frm_masses) n_masses = n_bsn_masses; if(n_masses != 0){ frm1 = (Vector **) smalloc(n_masses * sizeof(int)); if(frm1 == 0) ERR.Pointer(cname,fname, "frm1"); VRB.Smalloc(cname,fname, "frm1",frm1, n_masses * sizeof(int)); frm2 = (Vector **) smalloc(n_masses * sizeof(int)); if(frm2 == 0) ERR.Pointer(cname,fname, "frm2"); VRB.Smalloc(cname,fname, "frm2",frm2, n_masses * sizeof(int)); for(i=0; i n_frm_masses) n_masses = n_bsn_masses; if(n_masses != 0){ for(i=0; istep_size; // Initialize monitor variables //---------------------------------------------------------------- cg_iter_av = 0.0; cg_iter_min = 1000000; cg_iter_max = 0; true_res_av = 0.0; true_res_min = 3.4e+38; true_res_max = 0.0; cg_calls = 0; // reset MD time in Lattice //---------------------------------------------------------------- lat.MdTime(0.0); VRB.Flow(cname,fname,"%s%f\n", md_time_str, IFloat(lat.MdTime())); if(hmd_arg->metropolis){ // Save initial gauge field configuration //-------------------------------------------------------------- lat.CopyGaugeField(gauge_field_init); } // Heat Bath for the conjugate momenta //---------------------------------------------------------------- lat.RandGaussAntiHermMatrix(mom, 1.0); // Heat Bath for the boson field bsn //---------------------------------------------------------------- for(i=0; ibsn_mass[i]); lat.RandGaussVector(bsn[i], 0.5, Ncb); lat.FmatEvlInv(bsn[i], phi[i], bsn_cg_arg[i], CNV_FRM_NO); } // Heat Bath for the pseudo-fermions (phi) //---------------------------------------------------------------- for(i=0; ifrm_mass[i]); } //---------------------------------------------------------------- // Molecular Dynamics Trajectory //---------------------------------------------------------------- h_init = lat.GhamiltonNode() + lat.MomHamiltonNode(mom); // Evolve momenta by half a step using the pure gauge force //---------------------------------------------------------------- lat.EvolveMomGforce(mom, 0.5*dt); // Evolve momenta by half a step using the fermion force //---------------------------------------------------------------- for(i=0; i cg_iter_max) cg_iter_max = cg_iter; true_res_av = true_res_av + true_res; if(true_res < true_res_min) true_res_min = true_res; if(true_res > true_res_max) true_res_max = true_res; cg_calls++; frm2[i]->CopyVec(frm1[i], f_size); cg_sol_prev[i] = frm2[i]; cg_sol_cur[i] = frm1[i]; h_init = h_init + lat.FhamiltonNode(phi[i], frm1[i]); lat.EvolveMomFforce(mom, frm1[i], hmd_arg->frm_mass[i], 0.5*dt); } // Evolve momenta by half a step using the boson force //---------------------------------------------------------------- for(i=0; ibsn_mass[i]); lat.EvolveMomFforce(mom, bsn[i], hmd_arg->bsn_mass[i], -0.5*dt); } // First leap frog step has occurred. Increment MD Time clock in // Lattice one half time step. //---------------------------------------------------------------- lat.MdTimeInc(0.5) ; VRB.Flow(cname,fname,"%s%f\n", md_time_str, IFloat(lat.MdTime())); // Run through the trajectory //---------------------------------------------------------------- for(step=0; step < hmd_arg->steps_per_traj; step++){ CSM.SaveComment(++step_cnt); // Evolve gauge field by one step //-------------------------------------------------------------- lat.EvolveGfield(mom, dt); // Increment MD Time clock in Lattice by one half time step. //-------------------------------------------------------------- lat.MdTimeInc(0.5); VRB.Flow(cname,fname,"%s%f\n", md_time_str, IFloat(lat.MdTime())); // Evolve momenta by one step using the pure gauge force //-------------------------------------------------------------- lat.EvolveMomGforce(mom, dt); // Evolve momenta by one step using the fermion force //-------------------------------------------------------------- for(i=0; iFTimesV1MinusV2(2.0, cg_sol_cur[i], cg_sol_prev[i], f_size); cg_sol = cg_sol_prev[i]; cg_iter = lat.FmatEvlInv(cg_sol, phi[i], frm_cg_arg[i], &true_res, CNV_FRM_NO); cg_iter_av = cg_iter_av + cg_iter; if(cg_iter < cg_iter_min) cg_iter_min = cg_iter; if(cg_iter > cg_iter_max) cg_iter_max = cg_iter; true_res_av = true_res_av + true_res; if(true_res < true_res_min) true_res_min = true_res; if(true_res > true_res_max) true_res_max = true_res; cg_calls++; cg_sol_prev[i] = cg_sol_cur[i]; cg_sol_cur[i] = cg_sol; lat.EvolveMomFforce(mom, cg_sol, hmd_arg->frm_mass[i], dt); } // Evolve momenta by one step using the boson force //-------------------------------------------------------------- for(i=0; ibsn_mass[i], -dt); } // Increment MD Time clock in Lattice by one half time step. //-------------------------------------------------------------- lat.MdTimeInc(0.5); VRB.Flow(cname,fname,"%s%f\n", md_time_str, IFloat(lat.MdTime())); } CSM.SaveComment(++step_cnt); // Evolve gauge field by one last step //---------------------------------------------------------------- lat.EvolveGfield(mom, dt); // Reunitarize //---------------------------------------------------------------- Float dev = 0.0; Float max_diff = 0.0; if(hmd_arg->reunitarize == REUNITARIZE_YES){ lat.Reunitarize(dev, max_diff); } h_final = lat.GhamiltonNode(); // Increment MD Time clock in Lattice by one half time step. //---------------------------------------------------------------- lat.MdTimeInc(0.5); VRB.Flow(cname,fname,"%s%f\n", md_time_str, IFloat(lat.MdTime())); // Evolve momenta by a last half step using the pure gauge force //---------------------------------------------------------------- lat.EvolveMomGforce(mom, 0.5*dt); // Evolve momenta by a last half step using the fermion force //---------------------------------------------------------------- for(i=0; iFTimesV1MinusV2(2.0, cg_sol_cur[i], cg_sol_prev[i], f_size); cg_sol = cg_sol_prev[i]; cg_iter = lat.FmatEvlInv(cg_sol, phi[i], frm_cg_arg[i], &true_res, CNV_FRM_NO); cg_iter_av = cg_iter_av + cg_iter; if(cg_iter < cg_iter_min) cg_iter_min = cg_iter; if(cg_iter > cg_iter_max) cg_iter_max = cg_iter; true_res_av = true_res_av + true_res; if(true_res < true_res_min) true_res_min = true_res; if(true_res > true_res_max) true_res_max = true_res; cg_calls++; h_final = h_final + lat.FhamiltonNode(phi[i], cg_sol); lat.EvolveMomFforce(mom, cg_sol, hmd_arg->frm_mass[i], 0.5*dt); } // Evolve momenta by a last half step using the boson force //--------------------------------------------------------------- for(i=0; ibsn_mass[i]); lat.EvolveMomFforce(mom, bsn[i], hmd_arg->bsn_mass[i], -0.5*dt); } h_final = h_final + lat.MomHamiltonNode(mom); // Calculate Final-Initial Hemiltonian //--------------------------------------------------------------- delta_h = h_final - h_init; glb_sum(&delta_h); VRB.Flow(cname,fname, "delta_h=%e\n",delta_h); // Check that delta_h is the same accross all s-slices // (relevant only if GJP.Snodes() != 1) //---------------------------------------------------------------- if(GJP.Snodes() != 1) { VRB.Flow(cname,fname, "Checking Delta H across s-slices\n"); lat.SoCheck(delta_h); } // Calculate average of monitor variables //--------------------------------------------------------------- cg_iter_av = Float(cg_iter_av) / Float(cg_calls); true_res_av = Float(true_res_av) / Float(cg_calls); // Metropolis step //--------------------------------------------------------------- if(hmd_arg->metropolis){ // Metropolis accept-reject step //-------------------------------------------------------------- accept = lat.MetropolisAccept(delta_h,&acceptance); if( !(accept) ){ // Trajectory rejected //------------------------------------------------------------ lat.GaugeField(gauge_field_init); VRB.Result(cname,fname,"Metropolis step -> Rejected\n"); } else { // Trajectory accepted. // Increment the Gauge Update counter in Lattice. //------------------------------------------------------------- lat.GupdCntInc(1); VRB.Result(cname,fname,"Metropolis step -> Accepted\n"); } } else { accept = 1; acceptance = 1.0; lat.GupdCntInc(1); VRB.Result(cname,fname,"No Metropolis step -> Accepted\n"); } // If GJP.Snodes() !=1 the gauge field is spread out // accross s-slices of processors. It must be identical // on each slice. Check to make sure and exit if it // is not identical. A case where this is relevant // is the DWF spread-out case. //---------------------------------------------------------------- if(GJP.Snodes() != 1) { VRB.Flow(cname,fname, "Checking gauge field across s-slices\n"); lat.GsoCheck(); } // Print out monitor info //--------------------------------------------------------------- if(common_arg->results != 0){ VRB.Flow(cname,fname,"Results ptr is %p\n",common_arg->results); if (common_arg->results == NULL) printf("FUCK\n");fflush(stdout); if( (fp = Fopen((char *)common_arg->results, "a")) == NULL ) { ERR.FileA(cname,fname, (char *)common_arg->results); } Fprintf(fp,"%d %.16e %d %.16e %.16e %.16e %d %d %.16e %.16e %.16e\n", hmd_arg->steps_per_traj+2, IFloat(delta_h), accept, IFloat(dev), IFloat(max_diff), IFloat(cg_iter_av), cg_iter_min, cg_iter_max, IFloat(true_res_av), IFloat(true_res_min), IFloat(true_res_max)); Fclose(fp); } VRB.Result(cname,fname, "Hmc steps = %d, Delta_hamilton = %e, accept = %d, dev = %e, max_diff = %e\n", hmd_arg->steps_per_traj+2, IFloat(delta_h), accept, IFloat(dev), IFloat(max_diff)); VRB.Result(cname,fname, "CG iterations: average = %e, min = %d, max = %d\n", IFloat(cg_iter_av), cg_iter_min, cg_iter_max); VRB.Result(cname,fname, "True Residual / |source|: average = %e, min = %e, max = %e\n", IFloat(true_res_av), IFloat(true_res_min), IFloat(true_res_max)); VRB.Result(cname,fname,"Configuration number = %d\n", lat.GupdCnt()); // Reset Molecular Dynamics time counter //---------------------------------------------------------------- lat.MdTime(0.0); VRB.Flow(cname,fname,"%s%f\n", md_time_str, IFloat(lat.MdTime())); #ifdef HAVE_QCDOCOS_SCU_CHECKSUM_H if ( ! ScuChecksum::CsumSwap() ) ERR.Hardware(cname,fname, "SCU Checksum mismatch\n"); #endif return acceptance; } CPS_END_NAMESPACE #endif