void comm_simopts(SIMOPTS *simopts,MPI_Comm world) /*=======================================================================*/ /* Begin routine */ {/*begin routine */ /*=======================================================================*/ /* Local variable declarations */ #include "../typ_defs/typ_mask.h" MPI_Datatype simopts_comm; MPI_Datatype types[1]; MPI_Aint displs[1]; int blockcounts[1]; Address(&(simopts->md),&displs[0]); types[0] = MPI_INT; blockcounts[0] = 18; Barrier(world); Type_struct(1,blockcounts,displs,types,&simopts_comm); Barrier(world); Type_commit(&simopts_comm); Barrier(world); Bcast(MPI_BOTTOM,1,simopts_comm,0,world); Barrier(world); Type_free(&simopts_comm); Barrier(world); Bcast(&(simopts->ann_rate),1,MPI_DOUBLE,0,world); Bcast(&(simopts->ann_start_temp),1,MPI_DOUBLE,0,world); Bcast(&(simopts->ann_target_temp),1,MPI_DOUBLE,0,world); /*------------------------------------------------------------------------*/ } /*end routine*/
void comm_cp_wannier(CP_WANNIER *cp_wannier,MPI_Comm world) /*=======================================================================*/ /* Begin routine */ {/*begin routine */ /*=======================================================================*/ /* Local variable declarations */ #include "../typ_defs/typ_mask.h" int ninfo = 4; MPI_Datatype cp_wannier_comm; MPI_Datatype types[1]; MPI_Aint displs[1]; int blockcounts[1]; Address(&(cp_wannier->cp_wan_calc_frq),&displs[0]); types[0] = MPI_INT; blockcounts[0] = ninfo; Barrier(world); Type_struct(1,blockcounts,displs,types,&cp_wannier_comm); Barrier(world); Type_commit(&cp_wannier_comm); Barrier(world); Bcast(MPI_BOTTOM,1,cp_wannier_comm,0,world); Barrier(world); Type_free(&cp_wannier_comm); Barrier(world); Bcast(&(cp_wannier->rcut_wan_orb),1,MPI_DOUBLE,0,world); Bcast(&(cp_wannier->rcut_wan_nl),1,MPI_DOUBLE,0,world); /*------------------------------------------------------------------------*/ }/*end routine*/
void comm_cptherm_info(CPTHERM_INFO *cptherm_info,MPI_Comm world) /*=======================================================================*/ /* Begin routine */ {/*begin routine */ /*=======================================================================*/ /* Local variable declarations */ #include "../typ_defs/typ_mask.h" int ninfo = 5; MPI_Datatype cptherm_info_comm; MPI_Datatype types[1]; MPI_Aint displs[1]; int blockcounts[1]; Address(&(cptherm_info->len_c_nhc),&displs[0]); types[0] = MPI_INT; blockcounts[0] = ninfo; Barrier(world); Type_struct(1,blockcounts,displs,types,&cptherm_info_comm); Barrier(world); Type_commit(&cptherm_info_comm); Barrier(world); Bcast(MPI_BOTTOM,1,cptherm_info_comm,0,world); Barrier(world); Type_free(&cptherm_info_comm); Barrier(world); Bcast(&(cptherm_info->cp_therm_heat_fact),1,MPI_DOUBLE,0,world); Barrier(world); /*------------------------------------------------------------------------*/ } /*end routine*/
void comm_cpcoeffs_info(CPCOEFFS_INFO *cpcoeffs_info,MPI_Comm world) /*=======================================================================*/ /* Begin routine */ {/*begin routine */ /*=======================================================================*/ /* Local variable declarations */ #include "../typ_defs/typ_mask.h" int ninfo = 17; MPI_Datatype cpcoeffs_info_comm; MPI_Datatype types[1]; MPI_Aint displs[1]; int blockcounts[1]; Address(&(cpcoeffs_info->pi_beads),&displs[0]); types[0] = MPI_INT; blockcounts[0] = ninfo; Barrier(world); Type_struct(1,blockcounts,displs,types,&cpcoeffs_info_comm); Barrier(world); Type_commit(&cpcoeffs_info_comm); Barrier(world); Bcast(MPI_BOTTOM,1,cpcoeffs_info_comm,0,world); Barrier(world); Type_free(&cpcoeffs_info_comm); Barrier(world); Bcast(&(cpcoeffs_info->ecut),1,MPI_DOUBLE,0,world); Bcast(&(cpcoeffs_info->cp_hess_cut),1,MPI_DOUBLE,0,world); /*------------------------------------------------------------------------*/ }/*end routine*/
void comm_cp_parse_info(CP_PARSE *cp_parse, MPI_Comm world) /*=======================================================================*/ /* Begin routine */ {/*begin routine */ /*=======================================================================*/ /* Local variable declarations */ #include "../typ_defs/typ_mask.h" int ncp_parse_int = 6; int ncp_parse_double = 11; MPI_Datatype cp_parse_info_comm_int; MPI_Datatype cp_parse_info_comm_double; MPI_Datatype types_int[1]; MPI_Datatype types_double[1]; MPI_Aint displs_int[1]; MPI_Aint displs_double[1]; int blockcounts_int[1]; int blockcounts_double[1]; Address(&(cp_parse->istart_cp),&displs_int[0]); Address(&(cp_parse->cp_mass_tau_def),&displs_double[0]); types_int[0] = MPI_INT; types_double[0] = MPI_DOUBLE; blockcounts_int[0] = ncp_parse_int; blockcounts_double[0] = ncp_parse_double; Barrier(world); Type_struct(1,blockcounts_int,displs_int,types_int, &cp_parse_info_comm_int); Barrier(world); Type_struct(1,blockcounts_double,displs_double,types_double, &cp_parse_info_comm_double); Barrier(world); Type_commit(&cp_parse_info_comm_int); Barrier(world); Type_commit(&cp_parse_info_comm_double); Barrier(world); Bcast(MPI_BOTTOM,1,cp_parse_info_comm_int,0,world); Barrier(world); Bcast(MPI_BOTTOM,1,cp_parse_info_comm_double,0,world); Barrier(world); Type_free(&cp_parse_info_comm_int); Barrier(world); Type_free(&cp_parse_info_comm_double); Barrier(world); /*------------------------------------------------------------------------*/ } /*end routine*/
void comm_cpconstrnt(CPCONSTRNT *cpconstrnt,MPI_Comm world) /*=======================================================================*/ /* Begin routine */ {/*begin routine */ /*=======================================================================*/ /* Local variable declarations */ #include "../typ_defs/typ_mask.h" int nscal_cpconstrnt = 3; MPI_Datatype cpconstrnt_comm; MPI_Datatype types[1]; MPI_Aint displs[1]; int blockcounts[1]; Address(&(cpconstrnt->c_tolshake),&displs[0]); types[0] = MPI_DOUBLE; blockcounts[0] = nscal_cpconstrnt; Barrier(world); Type_struct(1,blockcounts,displs,types,&cpconstrnt_comm); Barrier(world); Type_commit(&cpconstrnt_comm); Barrier(world); Bcast(MPI_BOTTOM,1,cpconstrnt_comm,0,world); Barrier(world); Type_free(&cpconstrnt_comm); /*------------------------------------------------------------------------*/ } /*end routine*/
void comm_filenames(FILENAMES *filenames,MPI_Comm world) /*=======================================================================*/ /* Begin routine */ {/*begin routine */ /*=======================================================================*/ /* Local variable declarations */ #include "../typ_defs/typ_mask.h" int filenames_num = 14; MPI_Datatype filenames_comm; MPI_Datatype types[1]; MPI_Aint displs[1]; int blockcounts[1]; Address(&(filenames->iwrite_screen),&displs[0]); types[0] = MPI_INT; blockcounts[0] = filenames_num; Barrier(world); Type_struct(1,blockcounts,displs,types,&filenames_comm); Barrier(world); Type_commit(&filenames_comm); Barrier(world); Bcast(MPI_BOTTOM,1,filenames_comm,0,world); Barrier(world); Type_free(&filenames_comm); /*------------------------------------------------------------------------*/ } /*end routine*/
void comm_cpopts(CPOPTS *cpopts,MPI_Comm world) /*=======================================================================*/ /* Begin routine */ {/*begin routine */ /*=======================================================================*/ /* Local variable declarations */ #include "../typ_defs/typ_mask.h" int cpopts_num = 39; MPI_Datatype cpopts_comm; MPI_Datatype types[1]; MPI_Aint displs[1]; int blockcounts[1]; Address(&(cpopts->cp_lda),&displs[0]); types[0] = MPI_INT; blockcounts[0] = cpopts_num; Barrier(world); Type_struct(1,blockcounts,displs,types,&cpopts_comm); Barrier(world); Type_commit(&cpopts_comm); Barrier(world); Bcast(MPI_BOTTOM,1,cpopts_comm,0,world); Barrier(world); Type_free(&cpopts_comm); /*------------------------------------------------------------------------*/ } /*end routine*/
void comm_ensopts(ENSOPTS *ensopts,MPI_Comm world) /*=======================================================================*/ /* Begin routine */ {/*begin routine */ /*=======================================================================*/ /* Local variable declarations */ #include "../typ_defs/typ_mask.h" int nensopts = 5; MPI_Datatype ensopts_comm; MPI_Datatype types[1]; MPI_Aint displs[1]; int blockcounts[1]; Address(&(ensopts->nve),&displs[0]); types[0] = MPI_INT; blockcounts[0] = nensopts; Barrier(world); Type_struct(1,blockcounts,displs,types,&ensopts_comm); Barrier(world); Type_commit(&ensopts_comm); Barrier(world); Bcast(MPI_BOTTOM,1,ensopts_comm,0,world); Barrier(world); Type_free(&ensopts_comm); /*------------------------------------------------------------------------*/ } /*end routine*/
void comm_vel_samp_cp(VEL_SAMP_CP *vel_samp_cp,MPI_Comm world,int myid) /*=======================================================================*/ /* Begin routine */ { /* begin routine */ /*=======================================================================*/ /* Local variable declarations */ #include "../typ_defs/typ_mask.h" int i,itemp; double temp,qseed; int nint = 8; MPI_Datatype vel_samp_comm; MPI_Datatype types[1]; MPI_Aint displs[1]; int blockcounts[1]; Address(&(vel_samp_cp->ivelc_smpl_on),&displs[0]); types[0] = MPI_INT; blockcounts[0] = nint; Barrier(world); Type_struct(1,blockcounts,displs,types,&vel_samp_comm); Barrier(world); Type_commit(&vel_samp_comm); Barrier(world); Bcast(MPI_BOTTOM,1,vel_samp_comm,0,world); Barrier(world); Type_free(&vel_samp_comm); Barrier(world); Bcast(&(vel_samp_cp->qseed),1,MPI_DOUBLE,0,world); Bcast(&(vel_samp_cp->vc_scal_tol),1,MPI_DOUBLE,0,world); /*Randomize random seed */ qseed = vel_samp_cp->qseed; for(i=1;i<=myid;i++){ temp=10000.0*ran_essl(&qseed); itemp = temp; }/*endfor*/ if(myid>0){vel_samp_cp->qseed = (double)itemp;} /*------------------------------------------------------------------------*/ } /*end routine*/
void comm_minopts(MINOPTS *minopts,MPI_Comm world) /*=======================================================================*/ /* Begin routine */ {/*begin routine */ /*=======================================================================*/ /* Local variable declarations */ #include "../typ_defs/typ_mask.h" int nmin_int = 10; MPI_Datatype minopts_comm; MPI_Datatype types[1]; MPI_Aint displs[1]; int blockcounts[1]; Address(&(minopts->min_std),&displs[0]); types[0] = MPI_INT; blockcounts[0] = nmin_int; Barrier(world); Type_struct(1,blockcounts,displs,types,&minopts_comm); Barrier(world); Type_commit(&minopts_comm); Barrier(world); Bcast(MPI_BOTTOM,1,minopts_comm,0,world); Barrier(world); Type_free(&minopts_comm); Barrier(world); Bcast(&(minopts->tol_coef),1,MPI_DOUBLE,0,world); Barrier(world); Bcast(&(minopts->tol_atom),1,MPI_DOUBLE,0,world); /*------------------------------------------------------------------------*/ } /*end routine*/
int main(int argc, char* argv[]) { int p, my_rank; MPI_Comm comm; int in_val; MPI_Init(&argc, &argv); comm = MPI_COMM_WORLD; MPI_Comm_size(comm, &p); MPI_Comm_rank(comm, &my_rank); if (my_rank == 0) { printf("Enter an int\n"); scanf("%d", &in_val); } Bcast(in_val, my_rank, p, comm); MPI_Finalize(); return 0; } /* main */
int main(int argc, char* argv[]) { int p, my_rank; MPI_Comm comm; int result, in_val; MPI_Init(&argc, &argv); comm = MPI_COMM_WORLD; MPI_Comm_size(comm, &p); MPI_Comm_rank(comm, &my_rank); if (my_rank == 0) { printf("Enter an int\n"); scanf("%d", &in_val); } MPI_Barrier(comm); result = Bcast(in_val, my_rank, p, comm); printf("Proc %d > result = %d\n", my_rank, result); MPI_Finalize(); return 0; } /* main */
void comm_pseudo(PSEUDO *pseudo,MPI_Comm world,int myid) /*=======================================================================*/ /* Begin routine */ {/*begin routine */ /*=======================================================================*/ /* Local variable declarations */ #include "../typ_defs/typ_mask.h" if(myid!=0){ pseudo->vxc_typ = (char *)cmalloc(MAXWORD*sizeof(char)); pseudo->ggax_typ = (char *)cmalloc(MAXWORD*sizeof(char)); pseudo->ggac_typ = (char *)cmalloc(MAXWORD*sizeof(char)); }/*endif*/ Barrier(world); Bcast(&(pseudo->vxc_typ[0]),MAXWORD,MPI_CHAR,0,world); /* must be from 0*/ Bcast(&(pseudo->ggax_typ[0]),MAXWORD,MPI_CHAR,0,world); Bcast(&(pseudo->ggac_typ[0]),MAXWORD,MPI_CHAR,0,world); Bcast(&(pseudo->gga_cut),1,MPI_DOUBLE,0,world); Bcast(&(pseudo->b3_cut),1,MPI_DOUBLE,0,world); Bcast(&(pseudo->b3_alp),1,MPI_DOUBLE,0,world); Bcast(&(pseudo->alpha_conv_dual),1,MPI_DOUBLE,0,world); Bcast(&(pseudo->n_interp_pme_dual),1,MPI_INT,0,world); Bcast(&(pseudo->nsplin_g),1,MPI_INT,0,world); Bcast(&(pseudo->nl_cut_on),1,MPI_INT,0,world); Bcast(&(pseudo->nlvps_skin),1,MPI_DOUBLE,0,world); Barrier(world); /*------------------------------------------------------------------------*/ } /*end routine*/
void communicate_cp_info(GENERAL_DATA *general_data, CP *cp,CP_PARSE *cp_parse, MPI_Comm world,int myid) /*=======================================================================*/ /* Begin routine */ {/*begin routine */ #include "../typ_defs/typ_mask.h" /*=======================================================================*/ /* Local variable declarations */ comm_cpcoeffs_info(&(cp->cpcoeffs_info),world); Barrier(world); if(cp->cpopts.cp_wan_opt == 1 || cp->cpopts.cp_wan_min_opt==1 || cp->cpopts.cp_wan_init_opt == 1) { comm_cp_wannier(&(cp->cp_wannier),world); Barrier(world); } comm_cptherm_info(&(cp->cptherm_info),world); Barrier(world); comm_cp_parse_info(cp_parse,world); Barrier(world); comm_vel_samp_cp(&(cp->vel_samp_cp),world,myid); Barrier(world); Bcast(&(cp->cp_sclr_fft_pkg3d_lg.igeneric_opt),1,MPI_INT,0,world); Bcast(&(cp->cp_para_fft_pkg3d_lg.igeneric_opt),1,MPI_INT,0,world); Bcast(&(cp->cp_sclr_fft_pkg3d_sm.igeneric_opt),1,MPI_INT,0,world); Bcast(&(cp->cp_para_fft_pkg3d_sm.igeneric_opt),1,MPI_INT,0,world); Bcast(&(cp->cp_sclr_fft_pkg3d_dens_cp_box.igeneric_opt),1,MPI_INT,0,world); Bcast(&(cp->cp_para_fft_pkg3d_dens_cp_box.igeneric_opt),1,MPI_INT,0,world); Bcast(&(cp->cpscr.cpscr_atom_pme.n_interp),1,MPI_INT,0,world); Bcast(&(cp->cpscr.cpscr_atom_pme.pme_on),1,MPI_INT,0,world); Bcast(&(cp->cpscr.cpscr_atom_pme.nlen_pme),1,MPI_INT,0,world); Barrier(world); if(cp->cpcoeffs_info.iopt_cp_dvr ==1 && general_data->cell.iperd ==0){ cp->cp_dvr_clus.cp_clus_opt=1; Bcast(&(cp->cp_dvr_clus.num_twindow),1,MPI_INT,0,world); Bcast(&(cp->cp_dvr_clus.num_tquad),1,MPI_INT,0,world); Bcast(&(cp->cp_dvr_clus.grid_dens),1,MPI_DOUBLE,0,world); Bcast(&(cp->cp_dvr_clus.tmax),1,MPI_DOUBLE,0,world); Bcast(&(cp->cp_dvr_clus.rmax),1,MPI_DOUBLE,0,world); } Barrier(world); /*------------------------------------------------------------------------*/ } /*end routine*/
/*==========================================================================*/ void check_coef_grad_mag_dvr(CP *cp,SIMOPTS *simopts, double *fc_mag_up_ret,double *fc_mag_dn_ret, int *ireset_ret,int *idone_ret, double tol_coef, int ip_start,int ip_end,STAT_AVG *stat_avg) /*=======================================================================*/ /* Begin subprogram: */ {/*begin routine*/ /*=======================================================================*/ /* Local variable declarations */ #include "../typ_defs/typ_mask.h" int iii; double fc_mag_up_old = *fc_mag_up_ret; double fc_mag_dn_old = *fc_mag_dn_ret; double fc_mag_up,fc_mag_dn; double fc_max_up,fc_max_dn; double fc_mag_up_tmp,fc_mag_dn_tmp; double fc_max_up_tmp,fc_max_dn_tmp; int pi_beads = cp->cpcoeffs_info.pi_beads; int pi_beads_proc = cp->cpcoeffs_info.pi_beads_proc; int ip; int i,idone,ireset; int ncoef_tot; double *dvrfc_up,*dvrfc_dn; double *dvrc_up, *dvrc_dn; double *ksmat_up,*ksmat_dn; double *occ_up = cp->cpopts.occ_up; double *occ_dn = cp->cpopts.occ_dn; double *ksmat_scr = cp->cpscr.cpscr_ovmat.ovlap1; int *ioff_upt = cp->cpcoeffs_info.ioff_upt; int *ioff_dnt = cp->cpcoeffs_info.ioff_dnt; int cp_norb = cp->cpopts.cp_norb; int cp_min; int ncoef_up = cp->cp_comm_state_pkg_dvr_up.nstate_ncoef_proc; int ncoef_dn = cp->cp_comm_state_pkg_dvr_dn.nstate_ncoef_proc; int nstate_up = cp->cpcoeffs_info.nstate_up; int nstate_dn = cp->cpcoeffs_info.nstate_dn; int cp_lsda = cp->cpopts.cp_lsda; int myid_state = cp->communicate.myid_state; int myid_bead = cp->communicate.myid_bead; int np_states = cp->communicate.np_states; int np_beads = cp->communicate.np_beads; int icoef_orth_up,icoef_orth_dn; int icoef_form_up,icoef_form_dn; int ifcoef_orth_up,ifcoef_orth_dn; int ifcoef_form_up,ifcoef_form_dn; MPI_Comm comm_states = cp->communicate.comm_states; MPI_Comm comm_beads = cp->communicate.comm_beads; /*=======================================================================*/ /* 0) Parallel checks */ if(np_states>1){ for(ip=ip_start;ip<=ip_end;ip++){ ifcoef_form_up = cp->cpcoeffs_pos_dvr[ip].ifcoef_form_up; ifcoef_form_dn = cp->cpcoeffs_pos_dvr[ip].ifcoef_form_dn; if(ifcoef_form_up!=1){ printf("@@@@@@@@@@@@@@@@@@@@_ERROR_@@@@@@@@@@@@@@@@@@@@\n"); printf("Up Coef forces are not in transposed form \n"); printf("on state processor %d in check_coef_grad \n",myid_state); printf("@@@@@@@@@@@@@@@@@@@@_ERROR_@@@@@@@@@@@@@@@@@@@@\n"); fflush(stdout); exit(1); }/*endif*/ if(cp_lsda==1){ if(ifcoef_form_dn!=1){ printf("@@@@@@@@@@@@@@@@@@@@_ERROR_@@@@@@@@@@@@@@@@@@@@\n"); printf("Dn Coef forces are not in transposed form \n"); printf("on state processor %d in check_coef_grad \n",myid_state); printf("@@@@@@@@@@@@@@@@@@@@_ERROR_@@@@@@@@@@@@@@@@@@@@\n"); fflush(stdout); exit(1); }/*endif*/ }/*endif*/ }/* endfor */ }/*endif*/ /*=======================================================================*/ /* 0.1) Initialize and calculate some useful quantities */ ncoef_tot = ncoef_up*nstate_up; cp_min = simopts->cp_min + simopts->cp_wave_min + simopts->cp_wave_min_pimd; fc_mag_up = 0.0; fc_max_up = 0.0; fc_mag_dn = 0.0; fc_max_dn = 0.0; /*=======================================================================*/ /* Begin for loop over beads */ for(ip=ip_start;ip<=ip_end;ip++){ /*-----------------------------------------------------------------------*/ /* Assign and project forces if necessary */ dvrc_up = cp->cpcoeffs_pos_dvr[ip].dvrc_up; dvrc_dn = cp->cpcoeffs_pos_dvr[ip].dvrc_dn; icoef_orth_up = cp->cpcoeffs_pos_dvr[ip].icoef_orth_up; icoef_orth_dn = cp->cpcoeffs_pos_dvr[ip].icoef_orth_dn; icoef_form_up = cp->cpcoeffs_pos_dvr[ip].icoef_form_up; icoef_form_dn = cp->cpcoeffs_pos_dvr[ip].icoef_form_dn; ifcoef_orth_up = cp->cpcoeffs_pos_dvr[ip].ifcoef_orth_up; ifcoef_orth_dn = cp->cpcoeffs_pos_dvr[ip].ifcoef_orth_dn; ifcoef_form_up = cp->cpcoeffs_pos_dvr[ip].ifcoef_form_up; ifcoef_form_dn = cp->cpcoeffs_pos_dvr[ip].ifcoef_form_dn; ksmat_up = cp->cpcoeffs_pos_dvr[ip].ksmat_up; ksmat_dn = cp->cpcoeffs_pos_dvr[ip].ksmat_dn; if(cp_min == 1 || cp_norb >= 1) { dvrfc_up = cp->cpcoeffs_pos_dvr[ip].dvrfc_up; dvrfc_dn = cp->cpcoeffs_pos_dvr[ip].dvrfc_dn; }else { /* CHECK PARALLEL */ dvrfc_up = cp->cpscr.cpscr_wave.cre_up; dvrfc_dn = cp->cpscr.cpscr_wave.cre_dn; for(i=1;i<=ncoef_tot; i++){ dvrfc_up[i] = cp->cpcoeffs_pos_dvr[ip].dvrfc_up[i]; } if(cp->cpopts.cp_lsda == 1 && nstate_dn != 0){ for(i=1;i<=ncoef_tot; i++){ dvrfc_dn[i] = cp->cpcoeffs_pos_dvr[ip].dvrfc_dn[i]; } }/* endif */ cp_add_ksmat_force_dvr(dvrc_up,icoef_form_up,icoef_orth_up, dvrfc_up,ifcoef_form_up,ifcoef_orth_up, ksmat_up,ksmat_scr,ioff_upt,cp_lsda,cp_min,occ_up, cp->cpcoeffs_info.scale_fact, &(cp->cp_comm_state_pkg_dvr_up)); if( (cp_lsda==1) && (nstate_dn!=0) ){ cp_add_ksmat_force_dvr(dvrc_dn,icoef_form_dn,icoef_orth_dn, dvrfc_dn,ifcoef_form_dn,ifcoef_orth_dn, ksmat_dn,ksmat_scr,ioff_dnt,cp_lsda,cp_min,occ_dn, cp->cpcoeffs_info.scale_fact, &(cp->cp_comm_state_pkg_dvr_dn)); }/*endif*/ }/* endif */ /*-----------------------------------------------------------------------*/ /* I) Up tolerence */ for(i=1;i <= ncoef_tot; i++) { fc_mag_up += (dvrfc_up[i]*dvrfc_up[i]); fc_max_up = MAX(fabs(dvrfc_up[i]),fc_max_up); }/*endfor*/ /*-----------------------------------------------------------------------*/ /* II) Dn tolerence */ if(cp_lsda == 1){ ncoef_tot = ncoef_dn*nstate_dn; for(i=1;i <= ncoef_tot; i++) { fc_mag_dn += dvrfc_dn[i] * dvrfc_dn[i]; fc_max_dn = MAX(fabs(dvrfc_dn[i]),fc_max_dn); }/*endfor*/ }/*endif*/ }/* endfor ip */ /*=======================================================================*/ /* II.V) Parallel reductions */ /*------------------------------------------------------------------------*/ /* i) First state level */ if(np_states > 1){ fc_mag_up_tmp = fc_mag_up; fc_mag_dn_tmp = fc_mag_dn; Allreduce(&(fc_mag_up_tmp),&(fc_mag_up),1,MPI_DOUBLE,MPI_SUM,0,comm_states); Allreduce(&(fc_mag_dn_tmp),&(fc_mag_dn),1,MPI_DOUBLE,MPI_SUM,0,comm_states); fc_max_up_tmp = fc_max_up; fc_max_dn_tmp = fc_max_dn; Allreduce(&(fc_max_up_tmp),&(fc_max_up),1,MPI_DOUBLE,MPI_MAX,0,comm_states); Allreduce(&(fc_max_dn_tmp),&(fc_max_dn),1,MPI_DOUBLE,MPI_MAX,0,comm_states); }/*endif*/ /*------------------------------------------------------------------------*/ /* ii) Next, bead level */ if(np_beads > 1 && cp_min == 0){ fc_mag_up_tmp = fc_mag_up; fc_mag_dn_tmp = fc_mag_dn; Allreduce(&(fc_mag_up_tmp),&(fc_mag_up),1,MPI_DOUBLE,MPI_SUM,0,comm_beads); Allreduce(&(fc_mag_dn_tmp),&(fc_mag_dn),1,MPI_DOUBLE,MPI_SUM,0,comm_beads); fc_max_up_tmp = fc_max_up; fc_max_dn_tmp = fc_max_dn; Allreduce(&(fc_max_up_tmp),&(fc_max_up),1,MPI_DOUBLE,MPI_MAX,0,comm_beads); Allreduce(&(fc_max_dn_tmp),&(fc_max_dn),1,MPI_DOUBLE,MPI_MAX,0,comm_beads); }/*endif*/ /*=======================================================================*/ /* II.VI) Calculate the magnitude */ fc_mag_up = sqrt(fc_mag_up/((double)pi_beads)); fc_mag_dn = sqrt(fc_mag_dn/((double)pi_beads)); /*=======================================================================*/ /* III) Set the flags (used for minimization) */ if(myid_state==0){ idone = 1; if(fc_mag_up > tol_coef){idone=0;} if((fc_mag_dn > tol_coef)&&(cp_lsda==1)){idone=0;} ireset = 0; if(fc_mag_up > fc_mag_up_old){ireset=1;} if((fc_mag_dn > fc_mag_dn_old)&&(cp_lsda==1)){ireset=1;} }/*endif*/ if(np_states>1){ Bcast(&idone,1,MPI_INT,0,comm_states); Bcast(&ireset,1,MPI_INT,0,comm_states); }/*endif*/ /*=======================================================================*/ /* IV) Set return values and put things in structures */ *fc_mag_up_ret = fc_mag_up; *fc_mag_dn_ret = fc_mag_dn; *idone_ret = idone; *ireset_ret = ireset; (stat_avg->fc_mag_up) = fc_mag_up; (stat_avg->fc_mag_dn) = fc_mag_dn; (stat_avg->fc_max_up) = fc_max_up; (stat_avg->fc_max_dn) = fc_max_dn; /*-----------------------------------------------------------------------*/ }/*end routine*/
void apply_c_nhc(CPTHERM_INFO *cptherm_info,CPTHERM_POS *cptherm_pos, CPCOEFFS_INFO *cpcoeffs_info,CPCOEFFS_POS *cpcoeffs_pos, CPSCR *cpscr,int cp_lsda,COMMUNICATE *communicate) /*==========================================================================*/ /* Begin Routine */ {/*begin routine*/ /*========================================================================*/ /* Local variable declarations */ #include "../typ_defs/typ_mask.h" int icoef,inhc,ichain; /* Num: for loop counters */ int iresn,iyosh; /* Num: for loop counters */ int len_c_nhc,len_c_nhcm1,len_c_nhcp1; /* Num: length of chains */ int len_c_nhcm2; double arg,aa; /* Num: scalar temps */ int iii; int nstate_up,nstate_dn; int ncoef; int ncoef_up_tot,ncoef_dn_tot; int num_c_nhc; int is, i,ichain1,itemp,jtemp; /* Define local pointers */ double *cpscr_coef_kin = cpscr->cpscr_therm.coef_kin; double *cpscr_sc = cpscr->cpscr_therm.sc_cp; double *vc_nhc_tmp = cpscr->cpscr_therm.coef_kin; double *c_nhc_tmp = cpscr->cpscr_therm.sc_cp; int *icmapup_nhc = cptherm_info->icmapup_nhc; int *icmapdn_nhc = cptherm_info->icmapdn_nhc; double *cpcoeffs_cmass = cpcoeffs_info->cmass; double *cpcoeffs_vcre_up = cpcoeffs_pos->vcre_up; double *cpcoeffs_vcim_up = cpcoeffs_pos->vcim_up; double *cpcoeffs_vcre_dn = cpcoeffs_pos->vcre_dn; double *cpcoeffs_vcim_dn = cpcoeffs_pos->vcim_dn; double **fc_nhc = cptherm_pos->fc_nhc; double **vc_nhc = cptherm_pos->vc_nhc; double **c_nhc = cptherm_pos->c_nhc; double **c_gkt = cptherm_info->c_gkt; double **cmass_nhc = cptherm_info->cmass_nhc; double *wdti2 = cptherm_info->wdti2; double *wdti4 = cptherm_info->wdti4; double *wdti8 = cptherm_info->wdti8; int *cpcoeffs_ioff_up = cpcoeffs_info->ioff_upt; int *cpcoeffs_ioff_dn = cpcoeffs_info->ioff_dnt; int myid_state = communicate->myid_state; MPI_Comm comm_states = communicate->comm_states; int icmoff_up = cpcoeffs_info->icoef_start_up-1; int icmoff_dn = cpcoeffs_info->icoef_start_dn-1; int np_states = communicate->np_states; int ncoef_up,ncoef_dn; int ivcoef_form_up = cpcoeffs_pos->ivcoef_form_up; int ivcoef_form_dn = cpcoeffs_pos->ivcoef_form_dn; /*==========================================================================*/ /* 0) Checks */ if(np_states>1){ if(ivcoef_form_up!=1){ printf("@@@@@@@@@@@@@@@@@@@@_ERROR_@@@@@@@@@@@@@@@@@@@@\n"); printf("Up CP velocities are not in transposed form \n"); printf("on state processor %d in apply_c_nhc \n",myid_state); printf("@@@@@@@@@@@@@@@@@@@@_ERROR_@@@@@@@@@@@@@@@@@@@@\n"); fflush(stdout); exit(1); }/*endif*/ if(cp_lsda==1){ if(ivcoef_form_dn!=1){ printf("@@@@@@@@@@@@@@@@@@@@_ERROR_@@@@@@@@@@@@@@@@@@@@\n"); printf("Dn CP velocities are not in transposed form \n"); printf("on state processor %d in int_NVE_cp \n",myid_state); printf("@@@@@@@@@@@@@@@@@@@@_ERROR_@@@@@@@@@@@@@@@@@@@@\n"); fflush(stdout); exit(1); }/*endif*/ }/*endif*/ }/*endif*/ /*==========================================================================*/ /* 0) Simple definitions */ nstate_up = cpcoeffs_info->nstate_up; nstate_dn = cpcoeffs_info->nstate_dn; if(np_states==1){ ncoef_up = cpcoeffs_info->ncoef; ncoef_dn = cpcoeffs_info->ncoef; }else{ ncoef_up = cpcoeffs_info->nstate_ncoef_proc_up; ncoef_dn = cpcoeffs_info->nstate_ncoef_proc_dn; }/*endif*/ num_c_nhc = cptherm_info->num_c_nhc_proc; /*==========================================================================*/ /* I) Map the ke of each particle to the appropriate nose-hoover chain */ /* and assemble the total particle ke associated */ /* with each chain. The num_c_nhc+1 cpthermo is the null cptherm */ for(inhc=1;inhc<=num_c_nhc+1;inhc++){ cpscr_coef_kin[inhc] = 0.0; /*endfor*/} for(is=1;is<=nstate_up;is++) { for(i=1;i<=ncoef_up;i++) { icoef = i+cpcoeffs_ioff_up[is]; cpscr_coef_kin[icmapup_nhc[is]] += cpcoeffs_cmass[(i+icmoff_up)] *cpcoeffs_vcre_up[icoef]*cpcoeffs_vcre_up[icoef]; }/*endfor*/ for(i=1;i<=ncoef_up;i++) { icoef = i+cpcoeffs_ioff_up[is]; cpscr_coef_kin[icmapup_nhc[is]] += cpcoeffs_cmass[(i+icmoff_up)] *cpcoeffs_vcim_up[icoef]*cpcoeffs_vcim_up[icoef]; }/*endfor*/ }/* endfor */ if( (cp_lsda == 1) && (nstate_dn != 0) ){ for(is=1;is<=nstate_dn;is++) { for(i=1;i<=ncoef_dn;i++) { icoef = i+cpcoeffs_ioff_dn[is]; cpscr_coef_kin[icmapdn_nhc[is]] += cpcoeffs_cmass[(i+icmoff_dn)] *cpcoeffs_vcre_dn[icoef]*cpcoeffs_vcre_dn[icoef]; }/*endfor*/ for(i=1;i<=ncoef_dn;i++) { icoef = i+cpcoeffs_ioff_dn[is]; cpscr_coef_kin[icmapdn_nhc[is]] += cpcoeffs_cmass[(i+icmoff_dn)] *cpcoeffs_vcim_dn[icoef]*cpcoeffs_vcim_dn[icoef]; }/*endfor*/ }/* endfor */ }/* endif cp_lsda */ if(np_states>1){ Allreduce(&(cpscr_coef_kin[1]), &(cpscr_sc[1]),num_c_nhc, MPI_DOUBLE,MPI_SUM,0,comm_states); for(inhc=1;inhc<=num_c_nhc;inhc++){ cpscr_coef_kin[inhc] = cpscr_sc[inhc]; }/*endfor*/ }/*endif*/ /*==========================================================================*/ /* III) Get the force on the first NHC in each chain */ for(inhc=1;inhc<=num_c_nhc;inhc++){ fc_nhc[1][inhc] = (cpscr_coef_kin[inhc]-c_gkt[1][inhc]) /cmass_nhc[1][inhc]; }/*endfor*/ /*==========================================================================*/ /* IV) Apply the nhc evolution operator using RESPA */ len_c_nhc = (cptherm_info->len_c_nhc); len_c_nhcm1 = (cptherm_info->len_c_nhc)-1; len_c_nhcm2 = (cptherm_info->len_c_nhc)-2; len_c_nhcp1 = (cptherm_info->len_c_nhc)+1; for(inhc=1;inhc<=num_c_nhc+1;inhc++){ cpscr_sc[inhc] = 1.0; }/*endfor*/ for(iresn=1;iresn<=cptherm_info->nres_c_nhc;iresn++){ for(iyosh=1;iyosh<=cptherm_info->nyosh_c_nhc;iyosh++){ /*--------------------------------------------------------------------------*/ /* 1) Evolve the last cptherm velocity in each chain */ if(len_c_nhc>2){ for(inhc=1;inhc<=num_c_nhc;inhc++){ arg = -wdti8[iyosh]*vc_nhc[len_c_nhcm1][inhc]; aa = exp(arg); vc_nhc[len_c_nhc][inhc] = vc_nhc[len_c_nhc][inhc]*aa*aa + wdti4[iyosh]*fc_nhc[len_c_nhc][inhc]*aa; }/*endfor*/ for(inhc=1;inhc<=num_c_nhc;inhc++){ fc_nhc[len_c_nhcm1][inhc] = (cmass_nhc[len_c_nhc][inhc]* vc_nhc[len_c_nhc][inhc]*vc_nhc[len_c_nhc][inhc] +cmass_nhc[len_c_nhcm2][inhc]* vc_nhc[len_c_nhcm2][inhc]*vc_nhc[len_c_nhcm2][inhc] -c_gkt[len_c_nhcm1][inhc])/cmass_nhc[len_c_nhcm1][inhc]; }/*endfor*/ }else{ for(inhc=1;inhc<=num_c_nhc;inhc++){ vc_nhc[len_c_nhc][inhc] = vc_nhc[len_c_nhc][inhc] + wdti4[iyosh]*fc_nhc[len_c_nhc][inhc]; }/*endfor*/ }/*endif*/ /*--------------------------------------------------------------------------*/ /* 2) Evolve the last-1 to the first cpthermo velocitiy in each chain */ for(ichain=1;ichain<=len_c_nhcm1;ichain++){ itemp = (len_c_nhc-ichain); jtemp = (len_c_nhcp1-ichain); for(inhc=1;inhc<=num_c_nhc;inhc++){ arg = -wdti8[iyosh]*vc_nhc[jtemp][inhc]; aa = exp(arg); vc_nhc[itemp][inhc] = vc_nhc[itemp][inhc]*aa*aa + wdti4[iyosh]*fc_nhc[itemp][inhc]*aa; }/*endfor*/ }/*endfor*/ /*--------------------------------------------------------------------------*/ /* 3) Evolve the particle velocities (by adding to the scaling factor) */ for(inhc=1;inhc<=num_c_nhc;inhc++){ arg = -wdti2[iyosh]*vc_nhc[1][inhc]; aa = exp(arg); cpscr_sc[inhc] *= aa; cpscr_coef_kin[inhc] *= (aa*aa); }/*endfor*/ /*--------------------------------------------------------------------------*/ /* 4) Evolve the cptherm positions */ for(ichain=1;ichain<=len_c_nhc;ichain++){ for(inhc=1;inhc<=num_c_nhc;inhc++){ c_nhc[ichain][inhc] += vc_nhc[ichain][inhc]*wdti2[iyosh]; }/*endfor*/ }/*endfor*/ /*--------------------------------------------------------------------------*/ /* 5) Evolve the 1 to last-1 cptherm velocity in each chain */ /* calculting cptherm forces as you go along */ /* careful with the len-1st puppy. */ for(inhc=1;inhc<=num_c_nhc;inhc++){ fc_nhc[1][inhc] = (cpscr_coef_kin[inhc]-c_gkt[1][inhc]) /cmass_nhc[1][inhc]; }/*endfor*/ for(ichain=1;ichain<=len_c_nhcm1;ichain++){ ichain1 = ichain+1; for(inhc=1;inhc<=num_c_nhc;inhc++){ arg = -wdti8[iyosh]*vc_nhc[ichain1][inhc]; aa = exp(arg); vc_nhc[ichain][inhc] = vc_nhc[ichain][inhc]*aa*aa + wdti4[iyosh]*fc_nhc[ichain][inhc]*aa; }/*endfor*/ if(ichain1!=len_c_nhcm1 || len_c_nhc<=2){ for(inhc=1;inhc<=num_c_nhc;inhc++){ fc_nhc[ichain1][inhc] = (cmass_nhc[ichain][inhc]* vc_nhc[ichain][inhc]*vc_nhc[ichain][inhc] -c_gkt[ichain1][inhc])/cmass_nhc[ichain1][inhc]; }/*endfor*/ }else{ for(inhc=1;inhc<=num_c_nhc;inhc++){ fc_nhc[len_c_nhcm1][inhc] = (cmass_nhc[len_c_nhc][inhc]* vc_nhc[len_c_nhc][inhc]*vc_nhc[len_c_nhc][inhc] +cmass_nhc[len_c_nhcm2][inhc]* vc_nhc[len_c_nhcm2][inhc]*vc_nhc[len_c_nhcm2][inhc] -c_gkt[len_c_nhcm1][inhc])/cmass_nhc[len_c_nhcm1][inhc]; }/*endfor*/ }/*endif*/ }/*endfor*/ /*--------------------------------------------------------------------------*/ /* 6) Evolve the last cptherm velocotiy in each chain */ if(len_c_nhc>2){ for(inhc=1;inhc<=num_c_nhc;inhc++){ arg = -wdti8[iyosh]*vc_nhc[len_c_nhcm1][inhc]; aa = exp(arg); vc_nhc[len_c_nhc][inhc] = vc_nhc[len_c_nhc][inhc]*aa*aa + wdti4[iyosh]*fc_nhc[len_c_nhc][inhc]*aa; }/*endfor*/ }else{ for(inhc=1;inhc<=num_c_nhc;inhc++){ arg = -wdti8[iyosh]*vc_nhc[len_c_nhcm1][inhc]; aa = exp(arg); vc_nhc[len_c_nhc][inhc] = vc_nhc[len_c_nhc][inhc]*aa*aa + wdti4[iyosh]*fc_nhc[len_c_nhc][inhc]*aa; }/*endfor*/ }/*endif*/ /*--------------------------------------------------------------------------*/ /* 7) End Respa */ /*endfor: iyosh */} /*endfor: iresn*/} /*==========================================================================*/ /* V) Apply the accumulated scaling factor to the velocities */ for(is=1;is<=nstate_up;is++) { for(i=1;i<=ncoef_up;i++) { icoef = i+cpcoeffs_ioff_up[is]; cpcoeffs_vcre_up[icoef] *= cpscr_sc[icmapup_nhc[is]]; }/*endfor*/ for(i=1;i<=ncoef_up;i++) { icoef = i+cpcoeffs_ioff_up[is]; cpcoeffs_vcim_up[icoef] *= cpscr_sc[icmapup_nhc[is]]; } /*endfor*/ } /*endfor*/ if( (cp_lsda == 1) && (nstate_dn != 0)){ for(is=1;is<=nstate_dn;is++) { for(i=1;i<=ncoef_dn;i++) { icoef = i+cpcoeffs_ioff_dn[is]; cpcoeffs_vcre_dn[icoef] *= cpscr_sc[icmapdn_nhc[is]]; }/*endfor*/ for(i=1;i<=ncoef_dn;i++) { cpcoeffs_vcim_dn[icoef] *= cpscr_sc[icmapdn_nhc[is]]; }/*endfor*/ }/*endfor*/ }/* endif cp_lsda */ /*==========================================================================*/ /* V) Broadcast the results to keep consistency */ if(np_states>1){ for(ichain=1;ichain<=len_c_nhc;ichain++){ if(myid_state==0){ for(inhc=1;inhc<=num_c_nhc;inhc++){ vc_nhc_tmp[inhc] = vc_nhc[ichain][inhc]; c_nhc_tmp[inhc] = c_nhc[ichain][inhc]; }/*endfor : inhc*/ }/*endif*/ Bcast(&vc_nhc_tmp[1],num_c_nhc,MPI_DOUBLE,0,comm_states); Bcast(&c_nhc_tmp[1],num_c_nhc,MPI_DOUBLE,0,comm_states); for(inhc=1;inhc<=num_c_nhc;inhc++){ vc_nhc[ichain][inhc] = vc_nhc_tmp[inhc]; c_nhc[ichain][inhc] = c_nhc_tmp[inhc]; }/*endfor : inhc*/ }/*endfor : ichain*/ }/*endif*/ /*--------------------------------------------------------------------------*/ }/*end routine*/