2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team,
6 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
43 #include<catamount/dclock.h>
49 #ifdef HAVE_SYS_TIME_H
53 #include "visibility.h"
63 #include "chargegroup.h"
86 #include "pull_rotation.h"
87 #include "gmx_random.h"
88 #include "mpelogging.h"
91 #include "gmx_wallcycle.h"
93 #include "nbnxn_atomdata.h"
94 #include "nbnxn_search.h"
95 #include "nbnxn_kernels/nbnxn_kernel_ref.h"
96 #include "nbnxn_kernels/nbnxn_kernel_x86_simd128.h"
97 #include "nbnxn_kernels/nbnxn_kernel_x86_simd256.h"
98 #include "nbnxn_kernels/nbnxn_kernel_gpu_ref.h"
103 #ifdef GMX_THREAD_MPI
110 #include "nbnxn_cuda_data_mgmt.h"
111 #include "nbnxn_cuda/nbnxn_cuda.h"
114 typedef struct gmx_timeprint {
119 /* Portable version of ctime_r implemented in src/gmxlib/string2.c, but we do not want it declared in public installed headers */
122 gmx_ctime_r(const time_t *clock,char *buf, int n);
128 #ifdef HAVE_GETTIMEOFDAY
132 gettimeofday(&t,NULL);
134 seconds = (double) t.tv_sec + 1e-6*(double)t.tv_usec;
140 seconds = time(NULL);
147 #define difftime(end,start) ((double)(end)-(double)(start))
149 void print_time(FILE *out,gmx_runtime_t *runtime,gmx_large_int_t step,
150 t_inputrec *ir, t_commrec *cr)
153 char timebuf[STRLEN];
157 #ifndef GMX_THREAD_MPI
163 fprintf(out,"step %s",gmx_step_str(step,buf));
164 if ((step >= ir->nstlist))
166 runtime->last = gmx_gettime();
167 dt = difftime(runtime->last,runtime->real);
168 runtime->time_per_step = dt/(step - ir->init_step + 1);
170 dt = (ir->nsteps + ir->init_step - step)*runtime->time_per_step;
176 finish = (time_t) (runtime->last + dt);
177 gmx_ctime_r(&finish,timebuf,STRLEN);
178 sprintf(buf,"%s",timebuf);
179 buf[strlen(buf)-1]='\0';
180 fprintf(out,", will finish %s",buf);
183 fprintf(out,", remaining runtime: %5d s ",(int)dt);
187 fprintf(out," performance: %.1f ns/day ",
188 ir->delta_t/1000*24*60*60/runtime->time_per_step);
191 #ifndef GMX_THREAD_MPI
205 static double set_proctime(gmx_runtime_t *runtime)
211 prev = runtime->proc;
212 runtime->proc = dclock();
214 diff = runtime->proc - prev;
218 prev = runtime->proc;
219 runtime->proc = clock();
221 diff = (double)(runtime->proc - prev)/(double)CLOCKS_PER_SEC;
225 /* The counter has probably looped, ignore this data */
232 void runtime_start(gmx_runtime_t *runtime)
234 runtime->real = gmx_gettime();
236 set_proctime(runtime);
237 runtime->realtime = 0;
238 runtime->proctime = 0;
240 runtime->time_per_step = 0;
243 void runtime_end(gmx_runtime_t *runtime)
249 runtime->proctime += set_proctime(runtime);
250 runtime->realtime = now - runtime->real;
254 void runtime_upd_proc(gmx_runtime_t *runtime)
256 runtime->proctime += set_proctime(runtime);
259 void print_date_and_time(FILE *fplog,int nodeid,const char *title,
260 const gmx_runtime_t *runtime)
263 char timebuf[STRLEN];
264 char time_string[STRLEN];
271 tmptime = (time_t) runtime->real;
272 gmx_ctime_r(&tmptime,timebuf,STRLEN);
276 tmptime = (time_t) gmx_gettime();
277 gmx_ctime_r(&tmptime,timebuf,STRLEN);
279 for(i=0; timebuf[i]>=' '; i++)
281 time_string[i]=timebuf[i];
285 fprintf(fplog,"%s on node %d %s\n",title,nodeid,time_string);
289 static void sum_forces(int start,int end,rvec f[],rvec flr[])
294 pr_rvecs(debug,0,"fsr",f+start,end-start);
295 pr_rvecs(debug,0,"flr",flr+start,end-start);
297 for(i=start; (i<end); i++)
298 rvec_inc(f[i],flr[i]);
302 * calc_f_el calculates forces due to an electric field.
304 * force is kJ mol^-1 nm^-1 = e * kJ mol^-1 nm^-1 / e
306 * Et[] contains the parameters for the time dependent
307 * part of the field (not yet used).
308 * Ex[] contains the parameters for
309 * the spatial dependent part of the field. You can have cool periodic
310 * fields in principle, but only a constant field is supported
312 * The function should return the energy due to the electric field
313 * (if any) but for now returns 0.
316 * There can be problems with the virial.
317 * Since the field is not self-consistent this is unavoidable.
318 * For neutral molecules the virial is correct within this approximation.
319 * For neutral systems with many charged molecules the error is small.
320 * But for systems with a net charge or a few charged molecules
321 * the error can be significant when the field is high.
322 * Solution: implement a self-consitent electric field into PME.
324 static void calc_f_el(FILE *fp,int start,int homenr,
325 real charge[],rvec x[],rvec f[],
326 t_cosines Ex[],t_cosines Et[],double t)
332 for(m=0; (m<DIM); m++)
339 Ext[m] = cos(Et[m].a[0]*(t-t0))*exp(-sqr(t-t0)/(2.0*sqr(Et[m].a[2])));
343 Ext[m] = cos(Et[m].a[0]*t);
352 /* Convert the field strength from V/nm to MD-units */
353 Ext[m] *= Ex[m].a[0]*FIELDFAC;
354 for(i=start; (i<start+homenr); i++)
355 f[i][m] += charge[i]*Ext[m];
364 fprintf(fp,"%10g %10g %10g %10g #FIELD\n",t,
365 Ext[XX]/FIELDFAC,Ext[YY]/FIELDFAC,Ext[ZZ]/FIELDFAC);
369 static void calc_virial(FILE *fplog,int start,int homenr,rvec x[],rvec f[],
370 tensor vir_part,t_graph *graph,matrix box,
371 t_nrnb *nrnb,const t_forcerec *fr,int ePBC)
376 /* The short-range virial from surrounding boxes */
378 calc_vir(fplog,SHIFTS,fr->shift_vec,fr->fshift,vir_part,ePBC==epbcSCREW,box);
379 inc_nrnb(nrnb,eNR_VIRIAL,SHIFTS);
381 /* Calculate partial virial, for local atoms only, based on short range.
382 * Total virial is computed in global_stat, called from do_md
384 f_calc_vir(fplog,start,start+homenr,x,f,vir_part,graph,box);
385 inc_nrnb(nrnb,eNR_VIRIAL,homenr);
387 /* Add position restraint contribution */
388 for(i=0; i<DIM; i++) {
389 vir_part[i][i] += fr->vir_diag_posres[i];
392 /* Add wall contribution */
393 for(i=0; i<DIM; i++) {
394 vir_part[i][ZZ] += fr->vir_wall_z[i];
398 pr_rvecs(debug,0,"vir_part",vir_part,DIM);
401 static void posres_wrapper(FILE *fplog,
409 gmx_enerdata_t *enerd,
417 /* Position restraints always require full pbc */
418 set_pbc(&pbc,ir->ePBC,box);
420 v = posres(top->idef.il[F_POSRES].nr,top->idef.il[F_POSRES].iatoms,
421 top->idef.iparams_posres,
422 (const rvec*)x,fr->f_novirsum,fr->vir_diag_posres,
423 ir->ePBC==epbcNONE ? NULL : &pbc,
424 lambda[efptRESTRAINT],&dvdl,
425 fr->rc_scaling,fr->ePBC,fr->posres_com,fr->posres_comB);
428 fprintf(fplog,sepdvdlformat,
429 interaction_function[F_POSRES].longname,v,dvdl);
431 enerd->term[F_POSRES] += v;
432 /* If just the force constant changes, the FEP term is linear,
433 * but if k changes, it is not.
435 enerd->dvdl_nonlin[efptRESTRAINT] += dvdl;
436 inc_nrnb(nrnb,eNR_POSRES,top->idef.il[F_POSRES].nr/2);
438 if ((ir->fepvals->n_lambda > 0) && (flags & GMX_FORCE_DHDL))
440 for(i=0; i<enerd->n_lambda; i++)
442 real dvdl_dum,lambda_dum;
444 lambda_dum = (i==0 ? lambda[efptRESTRAINT] : ir->fepvals->all_lambda[efptRESTRAINT][i-1]);
445 v = posres(top->idef.il[F_POSRES].nr,top->idef.il[F_POSRES].iatoms,
446 top->idef.iparams_posres,
447 (const rvec*)x,NULL,NULL,
448 ir->ePBC==epbcNONE ? NULL : &pbc,lambda_dum,&dvdl,
449 fr->rc_scaling,fr->ePBC,fr->posres_com,fr->posres_comB);
450 enerd->enerpart_lambda[i] += v;
455 static void pull_potential_wrapper(FILE *fplog,
463 gmx_enerdata_t *enerd,
470 /* Calculate the center of mass forces, this requires communication,
471 * which is why pull_potential is called close to other communication.
472 * The virial contribution is calculated directly,
473 * which is why we call pull_potential after calc_virial.
475 set_pbc(&pbc,ir->ePBC,box);
477 enerd->term[F_COM_PULL] +=
478 pull_potential(ir->ePull,ir->pull,mdatoms,&pbc,
479 cr,t,lambda[efptRESTRAINT],x,f,vir_force,&dvdl);
482 fprintf(fplog,sepdvdlformat,"Com pull",enerd->term[F_COM_PULL],dvdl);
484 enerd->dvdl_lin[efptRESTRAINT] += dvdl;
487 static void pme_receive_force_ener(FILE *fplog,
490 gmx_wallcycle_t wcycle,
491 gmx_enerdata_t *enerd,
495 float cycles_ppdpme,cycles_seppme;
497 cycles_ppdpme = wallcycle_stop(wcycle,ewcPPDURINGPME);
498 dd_cycles_add(cr->dd,cycles_ppdpme,ddCyclPPduringPME);
500 /* In case of node-splitting, the PP nodes receive the long-range
501 * forces, virial and energy from the PME nodes here.
503 wallcycle_start(wcycle,ewcPP_PMEWAITRECVF);
505 gmx_pme_receive_f(cr,fr->f_novirsum,fr->vir_el_recip,&e,&dvdl,
509 fprintf(fplog,sepdvdlformat,"PME mesh",e,dvdl);
511 enerd->term[F_COUL_RECIP] += e;
512 enerd->dvdl_lin[efptCOUL] += dvdl;
515 dd_cycles_add(cr->dd,cycles_seppme,ddCyclPME);
517 wallcycle_stop(wcycle,ewcPP_PMEWAITRECVF);
520 static void print_large_forces(FILE *fp,t_mdatoms *md,t_commrec *cr,
521 gmx_large_int_t step,real pforce,rvec *x,rvec *f)
525 char buf[STEPSTRSIZE];
528 for(i=md->start; i<md->start+md->homenr; i++) {
530 /* We also catch NAN, if the compiler does not optimize this away. */
531 if (fn2 >= pf2 || fn2 != fn2) {
532 fprintf(fp,"step %s atom %6d x %8.3f %8.3f %8.3f force %12.5e\n",
533 gmx_step_str(step,buf),
534 ddglatnr(cr->dd,i),x[i][XX],x[i][YY],x[i][ZZ],sqrt(fn2));
539 static void post_process_forces(FILE *fplog,
541 gmx_large_int_t step,
542 t_nrnb *nrnb,gmx_wallcycle_t wcycle,
549 t_forcerec *fr,gmx_vsite_t *vsite,
556 /* Spread the mesh force on virtual sites to the other particles...
557 * This is parallellized. MPI communication is performed
558 * if the constructing atoms aren't local.
560 wallcycle_start(wcycle,ewcVSITESPREAD);
561 spread_vsite_f(fplog,vsite,x,fr->f_novirsum,NULL,
562 (flags & GMX_FORCE_VIRIAL),fr->vir_el_recip,
564 &top->idef,fr->ePBC,fr->bMolPBC,graph,box,cr);
565 wallcycle_stop(wcycle,ewcVSITESPREAD);
567 if (flags & GMX_FORCE_VIRIAL)
569 /* Now add the forces, this is local */
572 sum_forces(0,fr->f_novirsum_n,f,fr->f_novirsum);
576 sum_forces(mdatoms->start,mdatoms->start+mdatoms->homenr,
579 if (EEL_FULL(fr->eeltype))
581 /* Add the mesh contribution to the virial */
582 m_add(vir_force,fr->vir_el_recip,vir_force);
586 pr_rvecs(debug,0,"vir_force",vir_force,DIM);
591 if (fr->print_force >= 0)
593 print_large_forces(stderr,mdatoms,cr,step,fr->print_force,x,f);
597 static void do_nb_verlet(t_forcerec *fr,
598 interaction_const_t *ic,
599 gmx_enerdata_t *enerd,
600 int flags, int ilocality,
603 gmx_wallcycle_t wcycle)
605 int nnbl, kernel_type, enr_nbnxn_kernel_ljc, enr_nbnxn_kernel_lj;
607 nonbonded_verlet_group_t *nbvg;
609 if (!(flags & GMX_FORCE_NONBONDED))
611 /* skip non-bonded calculation */
615 nbvg = &fr->nbv->grp[ilocality];
617 /* CUDA kernel launch overhead is already timed separately */
618 if (fr->cutoff_scheme != ecutsVERLET)
620 gmx_incons("Invalid cut-off scheme passed!");
623 if (nbvg->kernel_type != nbk8x8x8_CUDA)
625 wallcycle_sub_start(wcycle, ewcsNONBONDED);
627 switch (nbvg->kernel_type)
630 nbnxn_kernel_ref(&nbvg->nbl_lists,
636 enerd->grpp.ener[egCOULSR],
638 enerd->grpp.ener[egBHAMSR] :
639 enerd->grpp.ener[egLJSR]);
642 case nbk4xN_X86_SIMD128:
643 nbnxn_kernel_x86_simd128(&nbvg->nbl_lists,
650 enerd->grpp.ener[egCOULSR],
652 enerd->grpp.ener[egBHAMSR] :
653 enerd->grpp.ener[egLJSR]);
655 case nbk4xN_X86_SIMD256:
656 nbnxn_kernel_x86_simd256(&nbvg->nbl_lists,
663 enerd->grpp.ener[egCOULSR],
665 enerd->grpp.ener[egBHAMSR] :
666 enerd->grpp.ener[egLJSR]);
670 nbnxn_cuda_launch_kernel(fr->nbv->cu_nbv, nbvg->nbat, flags, ilocality);
673 case nbk8x8x8_PlainC:
674 nbnxn_kernel_gpu_ref(nbvg->nbl_lists.nbl[0],
679 nbvg->nbat->out[0].f,
681 enerd->grpp.ener[egCOULSR],
683 enerd->grpp.ener[egBHAMSR] :
684 enerd->grpp.ener[egLJSR]);
688 gmx_incons("Invalid nonbonded kernel type passed!");
691 if (nbvg->kernel_type != nbk8x8x8_CUDA)
693 wallcycle_sub_stop(wcycle, ewcsNONBONDED);
696 if (EEL_RF(ic->eeltype) || ic->eeltype == eelCUT)
698 enr_nbnxn_kernel_ljc = eNR_NBNXN_LJ_RF;
700 else if (nbvg->ewald_excl == ewaldexclTable)
702 enr_nbnxn_kernel_ljc = eNR_NBNXN_LJ_TAB;
706 enr_nbnxn_kernel_ljc = eNR_NBNXN_LJ_EWALD;
708 enr_nbnxn_kernel_lj = eNR_NBNXN_LJ;
709 if (flags & GMX_FORCE_ENERGY)
711 /* In eNR_??? the nbnxn F+E kernels are always the F kernel + 1 */
712 enr_nbnxn_kernel_ljc += 1;
713 enr_nbnxn_kernel_lj += 1;
716 inc_nrnb(nrnb,enr_nbnxn_kernel_ljc,
717 nbvg->nbl_lists.natpair_ljq);
718 inc_nrnb(nrnb,enr_nbnxn_kernel_lj,
719 nbvg->nbl_lists.natpair_lj);
720 inc_nrnb(nrnb,enr_nbnxn_kernel_ljc-eNR_NBNXN_LJ_RF+eNR_NBNXN_RF,
721 nbvg->nbl_lists.natpair_q);
724 void do_force_cutsVERLET(FILE *fplog,t_commrec *cr,
725 t_inputrec *inputrec,
726 gmx_large_int_t step,t_nrnb *nrnb,gmx_wallcycle_t wcycle,
729 gmx_groups_t *groups,
730 matrix box,rvec x[],history_t *hist,
734 gmx_enerdata_t *enerd,t_fcdata *fcd,
735 real *lambda,t_graph *graph,
736 t_forcerec *fr, interaction_const_t *ic,
737 gmx_vsite_t *vsite,rvec mu_tot,
738 double t,FILE *field,gmx_edsam_t ed,
746 gmx_bool bSepDVDL,bStateChanged,bNS,bFillGrid,bCalcCGCM,bBS;
747 gmx_bool bDoLongRange,bDoForces,bSepLRF,bUseGPU,bUseOrEmulGPU;
748 gmx_bool bDiffKernels=FALSE;
752 float cycles_pme,cycles_force;
753 nonbonded_verlet_t *nbv;
757 nb_kernel_type = fr->nbv->grp[0].kernel_type;
759 start = mdatoms->start;
760 homenr = mdatoms->homenr;
762 bSepDVDL = (fr->bSepDVDL && do_per_step(step,inputrec->nstlog));
764 clear_mat(vir_force);
767 if (DOMAINDECOMP(cr))
769 cg1 = cr->dd->ncg_tot;
780 bStateChanged = (flags & GMX_FORCE_STATECHANGED);
781 bNS = (flags & GMX_FORCE_NS) && (fr->bAllvsAll==FALSE);
782 bFillGrid = (bNS && bStateChanged);
783 bCalcCGCM = (bFillGrid && !DOMAINDECOMP(cr));
784 bDoLongRange = (fr->bTwinRange && bNS && (flags & GMX_FORCE_DO_LR));
785 bDoForces = (flags & GMX_FORCE_FORCES);
786 bSepLRF = (bDoLongRange && bDoForces && (flags & GMX_FORCE_SEPLRF));
787 bUseGPU = fr->nbv->bUseGPU;
788 bUseOrEmulGPU = bUseGPU || (nbv->grp[0].kernel_type == nbk8x8x8_PlainC);
792 update_forcerec(fplog,fr,box);
794 if (NEED_MUTOT(*inputrec))
796 /* Calculate total (local) dipole moment in a temporary common array.
797 * This makes it possible to sum them over nodes faster.
799 calc_mu(start,homenr,
800 x,mdatoms->chargeA,mdatoms->chargeB,mdatoms->nChargePerturbed,
805 if (fr->ePBC != epbcNONE) {
806 /* Compute shift vectors every step,
807 * because of pressure coupling or box deformation!
809 if ((flags & GMX_FORCE_DYNAMICBOX) && bStateChanged)
810 calc_shifts(box,fr->shift_vec);
813 put_atoms_in_box_omp(fr->ePBC,box,homenr,x);
814 inc_nrnb(nrnb,eNR_SHIFTX,homenr);
816 else if (EI_ENERGY_MINIMIZATION(inputrec->eI) && graph) {
817 unshift_self(graph,box,x);
821 nbnxn_atomdata_copy_shiftvec(flags & GMX_FORCE_DYNAMICBOX,
822 fr->shift_vec,nbv->grp[0].nbat);
825 if (!(cr->duty & DUTY_PME)) {
826 /* Send particle coordinates to the pme nodes.
827 * Since this is only implemented for domain decomposition
828 * and domain decomposition does not use the graph,
829 * we do not need to worry about shifting.
832 wallcycle_start(wcycle,ewcPP_PMESENDX);
833 GMX_MPE_LOG(ev_send_coordinates_start);
835 bBS = (inputrec->nwall == 2);
838 svmul(inputrec->wall_ewald_zfac,boxs[ZZ],boxs[ZZ]);
841 gmx_pme_send_x(cr,bBS ? boxs : box,x,
842 mdatoms->nChargePerturbed,lambda[efptCOUL],
843 (flags & (GMX_FORCE_VIRIAL | GMX_FORCE_ENERGY)),step);
845 GMX_MPE_LOG(ev_send_coordinates_finish);
846 wallcycle_stop(wcycle,ewcPP_PMESENDX);
850 /* do gridding for pair search */
853 if (graph && bStateChanged)
855 /* Calculate intramolecular shift vectors to make molecules whole */
856 mk_mshift(fplog,graph,fr->ePBC,box,x);
860 box_diag[XX] = box[XX][XX];
861 box_diag[YY] = box[YY][YY];
862 box_diag[ZZ] = box[ZZ][ZZ];
864 wallcycle_start(wcycle,ewcNS);
867 wallcycle_sub_start(wcycle,ewcsNBS_GRID_LOCAL);
868 nbnxn_put_on_grid(nbv->nbs,fr->ePBC,box,
870 0,mdatoms->homenr,-1,fr->cginfo,x,
872 nbv->grp[eintLocal].kernel_type,
873 nbv->grp[eintLocal].nbat);
874 wallcycle_sub_stop(wcycle,ewcsNBS_GRID_LOCAL);
878 wallcycle_sub_start(wcycle,ewcsNBS_GRID_NONLOCAL);
879 nbnxn_put_on_grid_nonlocal(nbv->nbs,domdec_zones(cr->dd),
881 nbv->grp[eintNonlocal].kernel_type,
882 nbv->grp[eintNonlocal].nbat);
883 wallcycle_sub_stop(wcycle,ewcsNBS_GRID_NONLOCAL);
886 if (nbv->ngrp == 1 ||
887 nbv->grp[eintNonlocal].nbat == nbv->grp[eintLocal].nbat)
889 nbnxn_atomdata_set(nbv->grp[eintLocal].nbat,eatAll,
890 nbv->nbs,mdatoms,fr->cginfo);
894 nbnxn_atomdata_set(nbv->grp[eintLocal].nbat,eatLocal,
895 nbv->nbs,mdatoms,fr->cginfo);
896 nbnxn_atomdata_set(nbv->grp[eintNonlocal].nbat,eatAll,
897 nbv->nbs,mdatoms,fr->cginfo);
899 wallcycle_stop(wcycle, ewcNS);
902 /* initialize the GPU atom data and copy shift vector */
907 wallcycle_start_nocount(wcycle, ewcLAUNCH_GPU_NB);
908 nbnxn_cuda_init_atomdata(nbv->cu_nbv, nbv->grp[eintLocal].nbat);
909 wallcycle_stop(wcycle, ewcLAUNCH_GPU_NB);
912 wallcycle_start_nocount(wcycle, ewcLAUNCH_GPU_NB);
913 nbnxn_cuda_upload_shiftvec(nbv->cu_nbv, nbv->grp[eintLocal].nbat);
914 wallcycle_stop(wcycle, ewcLAUNCH_GPU_NB);
917 /* do local pair search */
920 wallcycle_start_nocount(wcycle,ewcNS);
921 wallcycle_sub_start(wcycle,ewcsNBS_SEARCH_LOCAL);
922 nbnxn_make_pairlist(nbv->nbs,nbv->grp[eintLocal].nbat,
925 nbv->min_ci_balanced,
926 &nbv->grp[eintLocal].nbl_lists,
928 nbv->grp[eintLocal].kernel_type,
930 wallcycle_sub_stop(wcycle,ewcsNBS_SEARCH_LOCAL);
934 /* initialize local pair-list on the GPU */
935 nbnxn_cuda_init_pairlist(nbv->cu_nbv,
936 nbv->grp[eintLocal].nbl_lists.nbl[0],
939 wallcycle_stop(wcycle, ewcNS);
943 wallcycle_start(wcycle, ewcNB_XF_BUF_OPS);
944 wallcycle_sub_start(wcycle, ewcsNB_X_BUF_OPS);
945 nbnxn_atomdata_copy_x_to_nbat_x(nbv->nbs,eatLocal,FALSE,x,
946 nbv->grp[eintLocal].nbat);
947 wallcycle_sub_stop(wcycle, ewcsNB_X_BUF_OPS);
948 wallcycle_stop(wcycle, ewcNB_XF_BUF_OPS);
953 wallcycle_start(wcycle,ewcLAUNCH_GPU_NB);
954 /* launch local nonbonded F on GPU */
955 do_nb_verlet(fr, ic, enerd, flags, eintLocal, enbvClearFNo,
957 wallcycle_stop(wcycle,ewcLAUNCH_GPU_NB);
960 /* Communicate coordinates and sum dipole if necessary +
961 do non-local pair search */
962 if (DOMAINDECOMP(cr))
964 bDiffKernels = (nbv->grp[eintNonlocal].kernel_type !=
965 nbv->grp[eintLocal].kernel_type);
969 /* With GPU+CPU non-bonded calculations we need to copy
970 * the local coordinates to the non-local nbat struct
971 * (in CPU format) as the non-local kernel call also
972 * calculates the local - non-local interactions.
974 wallcycle_start(wcycle, ewcNB_XF_BUF_OPS);
975 wallcycle_sub_start(wcycle, ewcsNB_X_BUF_OPS);
976 nbnxn_atomdata_copy_x_to_nbat_x(nbv->nbs,eatLocal,TRUE,x,
977 nbv->grp[eintNonlocal].nbat);
978 wallcycle_sub_stop(wcycle, ewcsNB_X_BUF_OPS);
979 wallcycle_stop(wcycle, ewcNB_XF_BUF_OPS);
984 wallcycle_start_nocount(wcycle,ewcNS);
985 wallcycle_sub_start(wcycle,ewcsNBS_SEARCH_NONLOCAL);
989 nbnxn_grid_add_simple(nbv->nbs,nbv->grp[eintNonlocal].nbat);
992 nbnxn_make_pairlist(nbv->nbs,nbv->grp[eintNonlocal].nbat,
995 nbv->min_ci_balanced,
996 &nbv->grp[eintNonlocal].nbl_lists,
998 nbv->grp[eintNonlocal].kernel_type,
1001 wallcycle_sub_stop(wcycle,ewcsNBS_SEARCH_NONLOCAL);
1003 if (nbv->grp[eintNonlocal].kernel_type == nbk8x8x8_CUDA)
1005 /* initialize non-local pair-list on the GPU */
1006 nbnxn_cuda_init_pairlist(nbv->cu_nbv,
1007 nbv->grp[eintNonlocal].nbl_lists.nbl[0],
1010 wallcycle_stop(wcycle,ewcNS);
1014 wallcycle_start(wcycle,ewcMOVEX);
1015 dd_move_x(cr->dd,box,x);
1017 /* When we don't need the total dipole we sum it in global_stat */
1018 if (bStateChanged && NEED_MUTOT(*inputrec))
1020 gmx_sumd(2*DIM,mu,cr);
1022 wallcycle_stop(wcycle,ewcMOVEX);
1024 wallcycle_start(wcycle, ewcNB_XF_BUF_OPS);
1025 wallcycle_sub_start(wcycle, ewcsNB_X_BUF_OPS);
1026 nbnxn_atomdata_copy_x_to_nbat_x(nbv->nbs,eatNonlocal,FALSE,x,
1027 nbv->grp[eintNonlocal].nbat);
1028 wallcycle_sub_stop(wcycle, ewcsNB_X_BUF_OPS);
1029 cycles_force += wallcycle_stop(wcycle, ewcNB_XF_BUF_OPS);
1032 if (bUseGPU && !bDiffKernels)
1034 wallcycle_start(wcycle,ewcLAUNCH_GPU_NB);
1035 /* launch non-local nonbonded F on GPU */
1036 do_nb_verlet(fr, ic, enerd, flags, eintNonlocal, enbvClearFNo,
1038 cycles_force += wallcycle_stop(wcycle,ewcLAUNCH_GPU_NB);
1044 /* launch D2H copy-back F */
1045 wallcycle_start_nocount(wcycle, ewcLAUNCH_GPU_NB);
1046 if (DOMAINDECOMP(cr) && !bDiffKernels)
1048 nbnxn_cuda_launch_cpyback(nbv->cu_nbv, nbv->grp[eintNonlocal].nbat,
1049 flags, eatNonlocal);
1051 nbnxn_cuda_launch_cpyback(nbv->cu_nbv, nbv->grp[eintLocal].nbat,
1053 cycles_force += wallcycle_stop(wcycle,ewcLAUNCH_GPU_NB);
1056 if (bStateChanged && NEED_MUTOT(*inputrec))
1060 gmx_sumd(2*DIM,mu,cr);
1067 fr->mu_tot[i][j] = mu[i*DIM + j];
1071 if (fr->efep == efepNO)
1073 copy_rvec(fr->mu_tot[0],mu_tot);
1077 for(j=0; j<DIM; j++)
1080 (1.0 - lambda[efptCOUL])*fr->mu_tot[0][j] +
1081 lambda[efptCOUL]*fr->mu_tot[1][j];
1085 /* Reset energies */
1086 reset_enerdata(&(inputrec->opts),fr,bNS,enerd,MASTER(cr));
1087 clear_rvecs(SHIFTS,fr->fshift);
1089 if (DOMAINDECOMP(cr))
1091 if (!(cr->duty & DUTY_PME))
1093 wallcycle_start(wcycle,ewcPPDURINGPME);
1094 dd_force_flop_start(cr->dd,nrnb);
1098 /* Start the force cycle counter.
1099 * This counter is stopped in do_forcelow_level.
1100 * No parallel communication should occur while this counter is running,
1101 * since that will interfere with the dynamic load balancing.
1103 wallcycle_start(wcycle,ewcFORCE);
1106 /* Reset forces for which the virial is calculated separately:
1107 * PME/Ewald forces if necessary */
1108 if (fr->bF_NoVirSum)
1110 if (flags & GMX_FORCE_VIRIAL)
1112 fr->f_novirsum = fr->f_novirsum_alloc;
1113 GMX_BARRIER(cr->mpi_comm_mygroup);
1116 clear_rvecs(fr->f_novirsum_n,fr->f_novirsum);
1120 clear_rvecs(homenr,fr->f_novirsum+start);
1122 GMX_BARRIER(cr->mpi_comm_mygroup);
1126 /* We are not calculating the pressure so we do not need
1127 * a separate array for forces that do not contribute
1134 /* Clear the short- and long-range forces */
1135 clear_rvecs(fr->natoms_force_constr,f);
1136 if(bSepLRF && do_per_step(step,inputrec->nstcalclr))
1138 clear_rvecs(fr->natoms_force_constr,fr->f_twin);
1141 clear_rvec(fr->vir_diag_posres);
1143 GMX_BARRIER(cr->mpi_comm_mygroup);
1145 if (inputrec->ePull == epullCONSTRAINT)
1147 clear_pull_forces(inputrec->pull);
1150 /* update QMMMrec, if necessary */
1153 update_QMMMrec(cr,fr,x,mdatoms,box,top);
1156 if ((flags & GMX_FORCE_BONDED) && top->idef.il[F_POSRES].nr > 0)
1158 posres_wrapper(fplog,flags,bSepDVDL,inputrec,nrnb,top,box,x,
1162 /* Compute the bonded and non-bonded energies and optionally forces */
1163 do_force_lowlevel(fplog,step,fr,inputrec,&(top->idef),
1164 cr,nrnb,wcycle,mdatoms,&(inputrec->opts),
1165 x,hist,f, bSepLRF ? fr->f_twin : f,enerd,fcd,mtop,top,fr->born,
1166 &(top->atomtypes),bBornRadii,box,
1167 inputrec->fepvals,lambda,graph,&(top->excls),fr->mu_tot,
1168 flags, &cycles_pme);
1172 if (do_per_step(step,inputrec->nstcalclr))
1174 /* Add the long range forces to the short range forces */
1175 for(i=0; i<fr->natoms_force_constr; i++)
1177 rvec_add(fr->f_twin[i],f[i],f[i]);
1184 /* Maybe we should move this into do_force_lowlevel */
1185 do_nb_verlet(fr, ic, enerd, flags, eintLocal, enbvClearFYes,
1190 if (!bUseOrEmulGPU || bDiffKernels)
1194 if (DOMAINDECOMP(cr))
1196 do_nb_verlet(fr, ic, enerd, flags, eintNonlocal,
1197 bDiffKernels ? enbvClearFYes : enbvClearFNo,
1207 aloc = eintNonlocal;
1210 /* Add all the non-bonded force to the normal force array.
1211 * This can be split into a local a non-local part when overlapping
1212 * communication with calculation with domain decomposition.
1214 cycles_force += wallcycle_stop(wcycle,ewcFORCE);
1215 wallcycle_start(wcycle, ewcNB_XF_BUF_OPS);
1216 wallcycle_sub_start(wcycle, ewcsNB_F_BUF_OPS);
1217 nbnxn_atomdata_add_nbat_f_to_f(nbv->nbs,eatAll,nbv->grp[aloc].nbat,f);
1218 wallcycle_sub_stop(wcycle, ewcsNB_F_BUF_OPS);
1219 cycles_force += wallcycle_stop(wcycle, ewcNB_XF_BUF_OPS);
1220 wallcycle_start_nocount(wcycle,ewcFORCE);
1222 /* if there are multiple fshift output buffers reduce them */
1223 if ((flags & GMX_FORCE_VIRIAL) &&
1224 nbv->grp[aloc].nbl_lists.nnbl > 1)
1226 nbnxn_atomdata_add_nbat_fshift_to_fshift(nbv->grp[aloc].nbat,
1231 cycles_force += wallcycle_stop(wcycle,ewcFORCE);
1232 GMX_BARRIER(cr->mpi_comm_mygroup);
1236 do_flood(fplog,cr,x,f,ed,box,step,bNS);
1239 if (bUseOrEmulGPU && !bDiffKernels)
1241 /* wait for non-local forces (or calculate in emulation mode) */
1242 if (DOMAINDECOMP(cr))
1246 wallcycle_start(wcycle,ewcWAIT_GPU_NB_NL);
1247 nbnxn_cuda_wait_gpu(nbv->cu_nbv,
1248 nbv->grp[eintNonlocal].nbat,
1250 enerd->grpp.ener[egLJSR], enerd->grpp.ener[egCOULSR],
1252 cycles_force += wallcycle_stop(wcycle,ewcWAIT_GPU_NB_NL);
1256 wallcycle_start_nocount(wcycle,ewcFORCE);
1257 do_nb_verlet(fr, ic, enerd, flags, eintNonlocal, enbvClearFYes,
1259 cycles_force += wallcycle_stop(wcycle,ewcFORCE);
1261 wallcycle_start(wcycle, ewcNB_XF_BUF_OPS);
1262 wallcycle_sub_start(wcycle, ewcsNB_F_BUF_OPS);
1263 /* skip the reduction if there was no non-local work to do */
1264 if (nbv->grp[eintLocal].nbl_lists.nbl[0]->nsci > 0)
1266 nbnxn_atomdata_add_nbat_f_to_f(nbv->nbs,eatNonlocal,
1267 nbv->grp[eintNonlocal].nbat,f);
1269 wallcycle_sub_stop(wcycle, ewcsNB_F_BUF_OPS);
1270 cycles_force += wallcycle_stop(wcycle, ewcNB_XF_BUF_OPS);
1276 /* Communicate the forces */
1279 wallcycle_start(wcycle,ewcMOVEF);
1280 if (DOMAINDECOMP(cr))
1282 dd_move_f(cr->dd,f,fr->fshift);
1283 /* Do we need to communicate the separate force array
1284 * for terms that do not contribute to the single sum virial?
1285 * Position restraints and electric fields do not introduce
1286 * inter-cg forces, only full electrostatics methods do.
1287 * When we do not calculate the virial, fr->f_novirsum = f,
1288 * so we have already communicated these forces.
1290 if (EEL_FULL(fr->eeltype) && cr->dd->n_intercg_excl &&
1291 (flags & GMX_FORCE_VIRIAL))
1293 dd_move_f(cr->dd,fr->f_novirsum,NULL);
1297 /* We should not update the shift forces here,
1298 * since f_twin is already included in f.
1300 dd_move_f(cr->dd,fr->f_twin,NULL);
1303 wallcycle_stop(wcycle,ewcMOVEF);
1309 /* wait for local forces (or calculate in emulation mode) */
1312 wallcycle_start(wcycle,ewcWAIT_GPU_NB_L);
1313 nbnxn_cuda_wait_gpu(nbv->cu_nbv,
1314 nbv->grp[eintLocal].nbat,
1316 enerd->grpp.ener[egLJSR], enerd->grpp.ener[egCOULSR],
1318 wallcycle_stop(wcycle,ewcWAIT_GPU_NB_L);
1320 /* now clear the GPU outputs while we finish the step on the CPU */
1321 nbnxn_cuda_clear_outputs(nbv->cu_nbv, flags);
1325 wallcycle_start_nocount(wcycle,ewcFORCE);
1326 do_nb_verlet(fr, ic, enerd, flags, eintLocal,
1327 DOMAINDECOMP(cr) ? enbvClearFNo : enbvClearFYes,
1329 wallcycle_stop(wcycle,ewcFORCE);
1331 wallcycle_start(wcycle, ewcNB_XF_BUF_OPS);
1332 wallcycle_sub_start(wcycle, ewcsNB_F_BUF_OPS);
1333 if (nbv->grp[eintLocal].nbl_lists.nbl[0]->nsci > 0)
1335 /* skip the reduction if there was no non-local work to do */
1336 nbnxn_atomdata_add_nbat_f_to_f(nbv->nbs,eatLocal,
1337 nbv->grp[eintLocal].nbat,f);
1339 wallcycle_sub_stop(wcycle, ewcsNB_F_BUF_OPS);
1340 wallcycle_stop(wcycle, ewcNB_XF_BUF_OPS);
1343 if (DOMAINDECOMP(cr))
1345 dd_force_flop_stop(cr->dd,nrnb);
1348 dd_cycles_add(cr->dd,cycles_force-cycles_pme,ddCyclF);
1354 if (IR_ELEC_FIELD(*inputrec))
1356 /* Compute forces due to electric field */
1357 calc_f_el(MASTER(cr) ? field : NULL,
1358 start,homenr,mdatoms->chargeA,x,fr->f_novirsum,
1359 inputrec->ex,inputrec->et,t);
1362 /* If we have NoVirSum forces, but we do not calculate the virial,
1363 * we sum fr->f_novirum=f later.
1365 if (vsite && !(fr->bF_NoVirSum && !(flags & GMX_FORCE_VIRIAL)))
1367 wallcycle_start(wcycle,ewcVSITESPREAD);
1368 spread_vsite_f(fplog,vsite,x,f,fr->fshift,FALSE,NULL,nrnb,
1369 &top->idef,fr->ePBC,fr->bMolPBC,graph,box,cr);
1370 wallcycle_stop(wcycle,ewcVSITESPREAD);
1374 wallcycle_start(wcycle,ewcVSITESPREAD);
1375 spread_vsite_f(fplog,vsite,x,fr->f_twin,NULL,FALSE,NULL,
1377 &top->idef,fr->ePBC,fr->bMolPBC,graph,box,cr);
1378 wallcycle_stop(wcycle,ewcVSITESPREAD);
1382 if (flags & GMX_FORCE_VIRIAL)
1384 /* Calculation of the virial must be done after vsites! */
1385 calc_virial(fplog,mdatoms->start,mdatoms->homenr,x,f,
1386 vir_force,graph,box,nrnb,fr,inputrec->ePBC);
1390 if (inputrec->ePull == epullUMBRELLA || inputrec->ePull == epullCONST_F)
1392 pull_potential_wrapper(fplog,bSepDVDL,cr,inputrec,box,x,
1393 f,vir_force,mdatoms,enerd,lambda,t);
1396 if (PAR(cr) && !(cr->duty & DUTY_PME))
1398 /* In case of node-splitting, the PP nodes receive the long-range
1399 * forces, virial and energy from the PME nodes here.
1401 pme_receive_force_ener(fplog,bSepDVDL,cr,wcycle,enerd,fr);
1406 post_process_forces(fplog,cr,step,nrnb,wcycle,
1407 top,box,x,f,vir_force,mdatoms,graph,fr,vsite,
1411 /* Sum the potential energy terms from group contributions */
1412 sum_epot(&(inputrec->opts),&(enerd->grpp),enerd->term);
1415 void do_force_cutsGROUP(FILE *fplog,t_commrec *cr,
1416 t_inputrec *inputrec,
1417 gmx_large_int_t step,t_nrnb *nrnb,gmx_wallcycle_t wcycle,
1418 gmx_localtop_t *top,
1420 gmx_groups_t *groups,
1421 matrix box,rvec x[],history_t *hist,
1425 gmx_enerdata_t *enerd,t_fcdata *fcd,
1426 real *lambda,t_graph *graph,
1427 t_forcerec *fr,gmx_vsite_t *vsite,rvec mu_tot,
1428 double t,FILE *field,gmx_edsam_t ed,
1429 gmx_bool bBornRadii,
1435 gmx_bool bSepDVDL,bStateChanged,bNS,bFillGrid,bCalcCGCM,bBS;
1436 gmx_bool bDoLongRangeNS,bDoForces,bDoPotential,bSepLRF;
1437 gmx_bool bDoAdressWF;
1439 rvec vzero,box_diag;
1440 real e,v,dvdlambda[efptNR];
1442 float cycles_pme,cycles_force;
1444 start = mdatoms->start;
1445 homenr = mdatoms->homenr;
1447 bSepDVDL = (fr->bSepDVDL && do_per_step(step,inputrec->nstlog));
1449 clear_mat(vir_force);
1453 pd_cg_range(cr,&cg0,&cg1);
1458 if (DOMAINDECOMP(cr))
1460 cg1 = cr->dd->ncg_tot;
1472 bStateChanged = (flags & GMX_FORCE_STATECHANGED);
1473 bNS = (flags & GMX_FORCE_NS) && (fr->bAllvsAll==FALSE);
1474 /* Should we update the long-range neighborlists at this step? */
1475 bDoLongRangeNS = fr->bTwinRange && bNS;
1476 /* Should we perform the long-range nonbonded evaluation inside the neighborsearching? */
1477 bFillGrid = (bNS && bStateChanged);
1478 bCalcCGCM = (bFillGrid && !DOMAINDECOMP(cr));
1479 bDoForces = (flags & GMX_FORCE_FORCES);
1480 bDoPotential = (flags & GMX_FORCE_ENERGY);
1481 bSepLRF = ((inputrec->nstcalclr>1) && bDoForces &&
1482 (flags & GMX_FORCE_SEPLRF) && (flags & GMX_FORCE_DO_LR));
1484 /* should probably move this to the forcerec since it doesn't change */
1485 bDoAdressWF = ((fr->adress_type!=eAdressOff));
1489 update_forcerec(fplog,fr,box);
1491 if (NEED_MUTOT(*inputrec))
1493 /* Calculate total (local) dipole moment in a temporary common array.
1494 * This makes it possible to sum them over nodes faster.
1496 calc_mu(start,homenr,
1497 x,mdatoms->chargeA,mdatoms->chargeB,mdatoms->nChargePerturbed,
1502 if (fr->ePBC != epbcNONE) {
1503 /* Compute shift vectors every step,
1504 * because of pressure coupling or box deformation!
1506 if ((flags & GMX_FORCE_DYNAMICBOX) && bStateChanged)
1507 calc_shifts(box,fr->shift_vec);
1510 put_charge_groups_in_box(fplog,cg0,cg1,fr->ePBC,box,
1511 &(top->cgs),x,fr->cg_cm);
1512 inc_nrnb(nrnb,eNR_CGCM,homenr);
1513 inc_nrnb(nrnb,eNR_RESETX,cg1-cg0);
1515 else if (EI_ENERGY_MINIMIZATION(inputrec->eI) && graph) {
1516 unshift_self(graph,box,x);
1519 else if (bCalcCGCM) {
1520 calc_cgcm(fplog,cg0,cg1,&(top->cgs),x,fr->cg_cm);
1521 inc_nrnb(nrnb,eNR_CGCM,homenr);
1526 move_cgcm(fplog,cr,fr->cg_cm);
1529 pr_rvecs(debug,0,"cgcm",fr->cg_cm,top->cgs.nr);
1533 if (!(cr->duty & DUTY_PME)) {
1534 /* Send particle coordinates to the pme nodes.
1535 * Since this is only implemented for domain decomposition
1536 * and domain decomposition does not use the graph,
1537 * we do not need to worry about shifting.
1540 wallcycle_start(wcycle,ewcPP_PMESENDX);
1541 GMX_MPE_LOG(ev_send_coordinates_start);
1543 bBS = (inputrec->nwall == 2);
1546 svmul(inputrec->wall_ewald_zfac,boxs[ZZ],boxs[ZZ]);
1549 gmx_pme_send_x(cr,bBS ? boxs : box,x,
1550 mdatoms->nChargePerturbed,lambda[efptCOUL],
1551 (flags & (GMX_FORCE_VIRIAL | GMX_FORCE_ENERGY)),step);
1553 GMX_MPE_LOG(ev_send_coordinates_finish);
1554 wallcycle_stop(wcycle,ewcPP_PMESENDX);
1556 #endif /* GMX_MPI */
1558 /* Communicate coordinates and sum dipole if necessary */
1561 wallcycle_start(wcycle,ewcMOVEX);
1562 if (DOMAINDECOMP(cr))
1564 dd_move_x(cr->dd,box,x);
1568 move_x(fplog,cr,GMX_LEFT,GMX_RIGHT,x,nrnb);
1570 wallcycle_stop(wcycle,ewcMOVEX);
1573 /* update adress weight beforehand */
1574 if(bStateChanged && bDoAdressWF)
1576 /* need pbc for adress weight calculation with pbc_dx */
1577 set_pbc(&pbc,inputrec->ePBC,box);
1578 if(fr->adress_site == eAdressSITEcog)
1580 update_adress_weights_cog(top->idef.iparams,top->idef.il,x,fr,mdatoms,
1581 inputrec->ePBC==epbcNONE ? NULL : &pbc);
1583 else if (fr->adress_site == eAdressSITEcom)
1585 update_adress_weights_com(fplog,cg0,cg1,&(top->cgs),x,fr,mdatoms,
1586 inputrec->ePBC==epbcNONE ? NULL : &pbc);
1588 else if (fr->adress_site == eAdressSITEatomatom){
1589 update_adress_weights_atom_per_atom(cg0,cg1,&(top->cgs),x,fr,mdatoms,
1590 inputrec->ePBC==epbcNONE ? NULL : &pbc);
1594 update_adress_weights_atom(cg0,cg1,&(top->cgs),x,fr,mdatoms,
1595 inputrec->ePBC==epbcNONE ? NULL : &pbc);
1599 if (NEED_MUTOT(*inputrec))
1606 gmx_sumd(2*DIM,mu,cr);
1612 fr->mu_tot[i][j] = mu[i*DIM + j];
1616 if (fr->efep == efepNO)
1618 copy_rvec(fr->mu_tot[0],mu_tot);
1622 for(j=0; j<DIM; j++)
1625 (1.0 - lambda[efptCOUL])*fr->mu_tot[0][j] + lambda[efptCOUL]*fr->mu_tot[1][j];
1630 /* Reset energies */
1631 reset_enerdata(&(inputrec->opts),fr,bNS,enerd,MASTER(cr));
1632 clear_rvecs(SHIFTS,fr->fshift);
1636 wallcycle_start(wcycle,ewcNS);
1638 if (graph && bStateChanged)
1640 /* Calculate intramolecular shift vectors to make molecules whole */
1641 mk_mshift(fplog,graph,fr->ePBC,box,x);
1644 /* Do the actual neighbour searching and if twin range electrostatics
1645 * also do the calculation of long range forces and energies.
1647 for (i=0;i<efptNR;i++) {dvdlambda[i] = 0;}
1649 groups,&(inputrec->opts),top,mdatoms,
1650 cr,nrnb,lambda,dvdlambda,&enerd->grpp,bFillGrid,
1654 fprintf(fplog,sepdvdlformat,"LR non-bonded",0.0,dvdlambda);
1656 enerd->dvdl_lin[efptVDW] += dvdlambda[efptVDW];
1657 enerd->dvdl_lin[efptCOUL] += dvdlambda[efptCOUL];
1659 wallcycle_stop(wcycle,ewcNS);
1662 if (inputrec->implicit_solvent && bNS)
1664 make_gb_nblist(cr,inputrec->gb_algorithm,inputrec->rlist,
1665 x,box,fr,&top->idef,graph,fr->born);
1668 if (DOMAINDECOMP(cr))
1670 if (!(cr->duty & DUTY_PME))
1672 wallcycle_start(wcycle,ewcPPDURINGPME);
1673 dd_force_flop_start(cr->dd,nrnb);
1679 /* Enforced rotation has its own cycle counter that starts after the collective
1680 * coordinates have been communicated. It is added to ddCyclF to allow
1681 * for proper load-balancing */
1682 wallcycle_start(wcycle,ewcROT);
1683 do_rotation(cr,inputrec,box,x,t,step,wcycle,bNS);
1684 wallcycle_stop(wcycle,ewcROT);
1687 /* Start the force cycle counter.
1688 * This counter is stopped in do_forcelow_level.
1689 * No parallel communication should occur while this counter is running,
1690 * since that will interfere with the dynamic load balancing.
1692 wallcycle_start(wcycle,ewcFORCE);
1696 /* Reset forces for which the virial is calculated separately:
1697 * PME/Ewald forces if necessary */
1698 if (fr->bF_NoVirSum)
1700 if (flags & GMX_FORCE_VIRIAL)
1702 fr->f_novirsum = fr->f_novirsum_alloc;
1703 GMX_BARRIER(cr->mpi_comm_mygroup);
1706 clear_rvecs(fr->f_novirsum_n,fr->f_novirsum);
1710 clear_rvecs(homenr,fr->f_novirsum+start);
1712 GMX_BARRIER(cr->mpi_comm_mygroup);
1716 /* We are not calculating the pressure so we do not need
1717 * a separate array for forces that do not contribute
1724 /* Clear the short- and long-range forces */
1725 clear_rvecs(fr->natoms_force_constr,f);
1726 if(bSepLRF && do_per_step(step,inputrec->nstcalclr))
1728 clear_rvecs(fr->natoms_force_constr,fr->f_twin);
1731 clear_rvec(fr->vir_diag_posres);
1733 GMX_BARRIER(cr->mpi_comm_mygroup);
1735 if (inputrec->ePull == epullCONSTRAINT)
1737 clear_pull_forces(inputrec->pull);
1740 /* update QMMMrec, if necessary */
1743 update_QMMMrec(cr,fr,x,mdatoms,box,top);
1746 if ((flags & GMX_FORCE_BONDED) && top->idef.il[F_POSRES].nr > 0)
1748 posres_wrapper(fplog,flags,bSepDVDL,inputrec,nrnb,top,box,x,
1752 /* Compute the bonded and non-bonded energies and optionally forces */
1753 do_force_lowlevel(fplog,step,fr,inputrec,&(top->idef),
1754 cr,nrnb,wcycle,mdatoms,&(inputrec->opts),
1755 x,hist,f, bSepLRF ? fr->f_twin : f,enerd,fcd,mtop,top,fr->born,
1756 &(top->atomtypes),bBornRadii,box,
1757 inputrec->fepvals,lambda,
1758 graph,&(top->excls),fr->mu_tot,
1764 if (do_per_step(step,inputrec->nstcalclr))
1766 /* Add the long range forces to the short range forces */
1767 for(i=0; i<fr->natoms_force_constr; i++)
1769 rvec_add(fr->f_twin[i],f[i],f[i]);
1774 cycles_force = wallcycle_stop(wcycle,ewcFORCE);
1775 GMX_BARRIER(cr->mpi_comm_mygroup);
1779 do_flood(fplog,cr,x,f,ed,box,step,bNS);
1782 if (DOMAINDECOMP(cr))
1784 dd_force_flop_stop(cr->dd,nrnb);
1787 dd_cycles_add(cr->dd,cycles_force-cycles_pme,ddCyclF);
1793 if (IR_ELEC_FIELD(*inputrec))
1795 /* Compute forces due to electric field */
1796 calc_f_el(MASTER(cr) ? field : NULL,
1797 start,homenr,mdatoms->chargeA,x,fr->f_novirsum,
1798 inputrec->ex,inputrec->et,t);
1801 if (bDoAdressWF && fr->adress_icor == eAdressICThermoForce)
1803 /* Compute thermodynamic force in hybrid AdResS region */
1804 adress_thermo_force(start,homenr,&(top->cgs),x,fr->f_novirsum,fr,mdatoms,
1805 inputrec->ePBC==epbcNONE ? NULL : &pbc);
1808 /* Communicate the forces */
1811 wallcycle_start(wcycle,ewcMOVEF);
1812 if (DOMAINDECOMP(cr))
1814 dd_move_f(cr->dd,f,fr->fshift);
1815 /* Do we need to communicate the separate force array
1816 * for terms that do not contribute to the single sum virial?
1817 * Position restraints and electric fields do not introduce
1818 * inter-cg forces, only full electrostatics methods do.
1819 * When we do not calculate the virial, fr->f_novirsum = f,
1820 * so we have already communicated these forces.
1822 if (EEL_FULL(fr->eeltype) && cr->dd->n_intercg_excl &&
1823 (flags & GMX_FORCE_VIRIAL))
1825 dd_move_f(cr->dd,fr->f_novirsum,NULL);
1829 /* We should not update the shift forces here,
1830 * since f_twin is already included in f.
1832 dd_move_f(cr->dd,fr->f_twin,NULL);
1837 pd_move_f(cr,f,nrnb);
1840 pd_move_f(cr,fr->f_twin,nrnb);
1843 wallcycle_stop(wcycle,ewcMOVEF);
1846 /* If we have NoVirSum forces, but we do not calculate the virial,
1847 * we sum fr->f_novirum=f later.
1849 if (vsite && !(fr->bF_NoVirSum && !(flags & GMX_FORCE_VIRIAL)))
1851 wallcycle_start(wcycle,ewcVSITESPREAD);
1852 spread_vsite_f(fplog,vsite,x,f,fr->fshift,FALSE,NULL,nrnb,
1853 &top->idef,fr->ePBC,fr->bMolPBC,graph,box,cr);
1854 wallcycle_stop(wcycle,ewcVSITESPREAD);
1858 wallcycle_start(wcycle,ewcVSITESPREAD);
1859 spread_vsite_f(fplog,vsite,x,fr->f_twin,NULL,FALSE,NULL,
1861 &top->idef,fr->ePBC,fr->bMolPBC,graph,box,cr);
1862 wallcycle_stop(wcycle,ewcVSITESPREAD);
1866 if (flags & GMX_FORCE_VIRIAL)
1868 /* Calculation of the virial must be done after vsites! */
1869 calc_virial(fplog,mdatoms->start,mdatoms->homenr,x,f,
1870 vir_force,graph,box,nrnb,fr,inputrec->ePBC);
1874 if (inputrec->ePull == epullUMBRELLA || inputrec->ePull == epullCONST_F)
1876 pull_potential_wrapper(fplog,bSepDVDL,cr,inputrec,box,x,
1877 f,vir_force,mdatoms,enerd,lambda,t);
1880 /* Add the forces from enforced rotation potentials (if any) */
1883 wallcycle_start(wcycle,ewcROTadd);
1884 enerd->term[F_COM_PULL] += add_rot_forces(inputrec->rot, f, cr,step,t);
1885 wallcycle_stop(wcycle,ewcROTadd);
1888 if (PAR(cr) && !(cr->duty & DUTY_PME))
1890 /* In case of node-splitting, the PP nodes receive the long-range
1891 * forces, virial and energy from the PME nodes here.
1893 pme_receive_force_ener(fplog,bSepDVDL,cr,wcycle,enerd,fr);
1898 post_process_forces(fplog,cr,step,nrnb,wcycle,
1899 top,box,x,f,vir_force,mdatoms,graph,fr,vsite,
1903 /* Sum the potential energy terms from group contributions */
1904 sum_epot(&(inputrec->opts),&(enerd->grpp),enerd->term);
1907 void do_force(FILE *fplog,t_commrec *cr,
1908 t_inputrec *inputrec,
1909 gmx_large_int_t step,t_nrnb *nrnb,gmx_wallcycle_t wcycle,
1910 gmx_localtop_t *top,
1912 gmx_groups_t *groups,
1913 matrix box,rvec x[],history_t *hist,
1917 gmx_enerdata_t *enerd,t_fcdata *fcd,
1918 real *lambda,t_graph *graph,
1920 gmx_vsite_t *vsite,rvec mu_tot,
1921 double t,FILE *field,gmx_edsam_t ed,
1922 gmx_bool bBornRadii,
1925 /* modify force flag if not doing nonbonded */
1926 if (!fr->bNonbonded)
1928 flags &= ~GMX_FORCE_NONBONDED;
1931 switch (inputrec->cutoff_scheme)
1934 do_force_cutsVERLET(fplog, cr, inputrec,
1950 do_force_cutsGROUP(fplog, cr, inputrec,
1965 gmx_incons("Invalid cut-off scheme passed!");
1970 void do_constrain_first(FILE *fplog,gmx_constr_t constr,
1971 t_inputrec *ir,t_mdatoms *md,
1972 t_state *state,rvec *f,
1973 t_graph *graph,t_commrec *cr,t_nrnb *nrnb,
1974 t_forcerec *fr, gmx_localtop_t *top, tensor shake_vir)
1977 gmx_large_int_t step;
1978 real dt=ir->delta_t;
1982 snew(savex,state->natoms);
1985 end = md->homenr + start;
1988 fprintf(debug,"vcm: start=%d, homenr=%d, end=%d\n",
1989 start,md->homenr,end);
1990 /* Do a first constrain to reset particles... */
1991 step = ir->init_step;
1994 char buf[STEPSTRSIZE];
1995 fprintf(fplog,"\nConstraining the starting coordinates (step %s)\n",
1996 gmx_step_str(step,buf));
2000 /* constrain the current position */
2001 constrain(NULL,TRUE,FALSE,constr,&(top->idef),
2002 ir,NULL,cr,step,0,md,
2003 state->x,state->x,NULL,
2004 fr->bMolPBC,state->box,
2005 state->lambda[efptBONDED],&dvdl_dum,
2006 NULL,NULL,nrnb,econqCoord,
2007 ir->epc==epcMTTK,state->veta,state->veta);
2010 /* constrain the inital velocity, and save it */
2011 /* also may be useful if we need the ekin from the halfstep for velocity verlet */
2012 /* might not yet treat veta correctly */
2013 constrain(NULL,TRUE,FALSE,constr,&(top->idef),
2014 ir,NULL,cr,step,0,md,
2015 state->x,state->v,state->v,
2016 fr->bMolPBC,state->box,
2017 state->lambda[efptBONDED],&dvdl_dum,
2018 NULL,NULL,nrnb,econqVeloc,
2019 ir->epc==epcMTTK,state->veta,state->veta);
2021 /* constrain the inital velocities at t-dt/2 */
2022 if (EI_STATE_VELOCITY(ir->eI) && ir->eI!=eiVV)
2024 for(i=start; (i<end); i++)
2026 for(m=0; (m<DIM); m++)
2028 /* Reverse the velocity */
2029 state->v[i][m] = -state->v[i][m];
2030 /* Store the position at t-dt in buf */
2031 savex[i][m] = state->x[i][m] + dt*state->v[i][m];
2034 /* Shake the positions at t=-dt with the positions at t=0
2035 * as reference coordinates.
2039 char buf[STEPSTRSIZE];
2040 fprintf(fplog,"\nConstraining the coordinates at t0-dt (step %s)\n",
2041 gmx_step_str(step,buf));
2044 constrain(NULL,TRUE,FALSE,constr,&(top->idef),
2045 ir,NULL,cr,step,-1,md,
2046 state->x,savex,NULL,
2047 fr->bMolPBC,state->box,
2048 state->lambda[efptBONDED],&dvdl_dum,
2049 state->v,NULL,nrnb,econqCoord,
2050 ir->epc==epcMTTK,state->veta,state->veta);
2052 for(i=start; i<end; i++) {
2053 for(m=0; m<DIM; m++) {
2054 /* Re-reverse the velocities */
2055 state->v[i][m] = -state->v[i][m];
2062 void calc_enervirdiff(FILE *fplog,int eDispCorr,t_forcerec *fr)
2064 double eners[2],virs[2],enersum,virsum,y0,f,g,h;
2065 double r0,r1,r,rc3,rc9,ea,eb,ec,pa,pb,pc,pd;
2066 double invscale,invscale2,invscale3;
2067 int ri0,ri1,ri,i,offstart,offset;
2068 real scale,*vdwtab,tabfactor,tmp;
2070 fr->enershiftsix = 0;
2071 fr->enershifttwelve = 0;
2072 fr->enerdiffsix = 0;
2073 fr->enerdifftwelve = 0;
2075 fr->virdifftwelve = 0;
2077 if (eDispCorr != edispcNO) {
2078 for(i=0; i<2; i++) {
2082 if ((fr->vdwtype == evdwSWITCH) || (fr->vdwtype == evdwSHIFT)) {
2083 if (fr->rvdw_switch == 0)
2085 "With dispersion correction rvdw-switch can not be zero "
2086 "for vdw-type = %s",evdw_names[fr->vdwtype]);
2088 scale = fr->nblists[0].table_elec_vdw.scale;
2089 vdwtab = fr->nblists[0].table_vdw.data;
2091 /* Round the cut-offs to exact table values for precision */
2092 ri0 = floor(fr->rvdw_switch*scale);
2093 ri1 = ceil(fr->rvdw*scale);
2099 if (fr->vdwtype == evdwSHIFT)
2101 /* Determine the constant energy shift below rvdw_switch.
2102 * Table has a scale factor since we have scaled it down to compensate
2103 * for scaling-up c6/c12 with the derivative factors to save flops in analytical kernels.
2105 fr->enershiftsix = (real)(-1.0/(rc3*rc3)) - 6.0*vdwtab[8*ri0];
2106 fr->enershifttwelve = (real)( 1.0/(rc9*rc3)) - 12.0*vdwtab[8*ri0 + 4];
2108 /* Add the constant part from 0 to rvdw_switch.
2109 * This integration from 0 to rvdw_switch overcounts the number
2110 * of interactions by 1, as it also counts the self interaction.
2111 * We will correct for this later.
2113 eners[0] += 4.0*M_PI*fr->enershiftsix*rc3/3.0;
2114 eners[1] += 4.0*M_PI*fr->enershifttwelve*rc3/3.0;
2116 invscale = 1.0/(scale);
2117 invscale2 = invscale*invscale;
2118 invscale3 = invscale*invscale2;
2120 /* following summation derived from cubic spline definition,
2121 Numerical Recipies in C, second edition, p. 113-116. Exact
2122 for the cubic spline. We first calculate the negative of
2123 the energy from rvdw to rvdw_switch, assuming that g(r)=1,
2124 and then add the more standard, abrupt cutoff correction to
2125 that result, yielding the long-range correction for a
2126 switched function. We perform both the pressure and energy
2127 loops at the same time for simplicity, as the computational
2131 enersum = 0.0; virsum = 0.0;
2135 /* Since the dispersion table has been scaled down a factor 6.0 and the repulsion
2136 * a factor 12.0 to compensate for the c6/c12 parameters inside nbfp[] being scaled
2137 * up (to save flops in kernels), we need to correct for this.
2146 for (ri=ri0; ri<ri1; ri++) {
2149 eb = 2.0*invscale2*r;
2153 pb = 3.0*invscale2*r;
2154 pc = 3.0*invscale*r*r;
2157 /* this "8" is from the packing in the vdwtab array - perhaps should be #define'ed? */
2158 offset = 8*ri + offstart;
2159 y0 = vdwtab[offset];
2160 f = vdwtab[offset+1];
2161 g = vdwtab[offset+2];
2162 h = vdwtab[offset+3];
2164 enersum += y0*(ea/3 + eb/2 + ec) + f*(ea/4 + eb/3 + ec/2) + g*(ea/5 + eb/4 + ec/3) + h*(ea/6 + eb/5 + ec/4);
2165 virsum += f*(pa/4 + pb/3 + pc/2 + pd) + 2*g*(pa/5 + pb/4 + pc/3 + pd/2) + 3*h*(pa/6 + pb/5 + pc/4 + pd/3);
2168 enersum *= 4.0*M_PI*tabfactor;
2169 virsum *= 4.0*M_PI*tabfactor;
2170 eners[i] -= enersum;
2174 /* now add the correction for rvdw_switch to infinity */
2175 eners[0] += -4.0*M_PI/(3.0*rc3);
2176 eners[1] += 4.0*M_PI/(9.0*rc9);
2177 virs[0] += 8.0*M_PI/rc3;
2178 virs[1] += -16.0*M_PI/(3.0*rc9);
2180 else if ((fr->vdwtype == evdwCUT) || (fr->vdwtype == evdwUSER)) {
2181 if (fr->vdwtype == evdwUSER && fplog)
2183 "WARNING: using dispersion correction with user tables\n");
2184 rc3 = fr->rvdw*fr->rvdw*fr->rvdw;
2186 /* Contribution beyond the cut-off */
2187 eners[0] += -4.0*M_PI/(3.0*rc3);
2188 eners[1] += 4.0*M_PI/(9.0*rc9);
2189 if (fr->vdw_modifier==eintmodPOTSHIFT) {
2190 /* Contribution within the cut-off */
2191 eners[0] += -4.0*M_PI/(3.0*rc3);
2192 eners[1] += 4.0*M_PI/(3.0*rc9);
2194 /* Contribution beyond the cut-off */
2195 virs[0] += 8.0*M_PI/rc3;
2196 virs[1] += -16.0*M_PI/(3.0*rc9);
2199 "Dispersion correction is not implemented for vdw-type = %s",
2200 evdw_names[fr->vdwtype]);
2202 fr->enerdiffsix = eners[0];
2203 fr->enerdifftwelve = eners[1];
2204 /* The 0.5 is due to the Gromacs definition of the virial */
2205 fr->virdiffsix = 0.5*virs[0];
2206 fr->virdifftwelve = 0.5*virs[1];
2210 void calc_dispcorr(FILE *fplog,t_inputrec *ir,t_forcerec *fr,
2211 gmx_large_int_t step,int natoms,
2212 matrix box,real lambda,tensor pres,tensor virial,
2213 real *prescorr, real *enercorr, real *dvdlcorr)
2215 gmx_bool bCorrAll,bCorrPres;
2216 real dvdlambda,invvol,dens,ninter,avcsix,avctwelve,enerdiff,svir=0,spres=0;
2226 if (ir->eDispCorr != edispcNO) {
2227 bCorrAll = (ir->eDispCorr == edispcAllEner ||
2228 ir->eDispCorr == edispcAllEnerPres);
2229 bCorrPres = (ir->eDispCorr == edispcEnerPres ||
2230 ir->eDispCorr == edispcAllEnerPres);
2232 invvol = 1/det(box);
2235 /* Only correct for the interactions with the inserted molecule */
2236 dens = (natoms - fr->n_tpi)*invvol;
2241 dens = natoms*invvol;
2242 ninter = 0.5*natoms;
2245 if (ir->efep == efepNO)
2247 avcsix = fr->avcsix[0];
2248 avctwelve = fr->avctwelve[0];
2252 avcsix = (1 - lambda)*fr->avcsix[0] + lambda*fr->avcsix[1];
2253 avctwelve = (1 - lambda)*fr->avctwelve[0] + lambda*fr->avctwelve[1];
2256 enerdiff = ninter*(dens*fr->enerdiffsix - fr->enershiftsix);
2257 *enercorr += avcsix*enerdiff;
2259 if (ir->efep != efepNO)
2261 dvdlambda += (fr->avcsix[1] - fr->avcsix[0])*enerdiff;
2265 enerdiff = ninter*(dens*fr->enerdifftwelve - fr->enershifttwelve);
2266 *enercorr += avctwelve*enerdiff;
2267 if (fr->efep != efepNO)
2269 dvdlambda += (fr->avctwelve[1] - fr->avctwelve[0])*enerdiff;
2275 svir = ninter*dens*avcsix*fr->virdiffsix/3.0;
2276 if (ir->eDispCorr == edispcAllEnerPres)
2278 svir += ninter*dens*avctwelve*fr->virdifftwelve/3.0;
2280 /* The factor 2 is because of the Gromacs virial definition */
2281 spres = -2.0*invvol*svir*PRESFAC;
2283 for(m=0; m<DIM; m++) {
2284 virial[m][m] += svir;
2285 pres[m][m] += spres;
2290 /* Can't currently control when it prints, for now, just print when degugging */
2294 fprintf(debug,"Long Range LJ corr.: <C6> %10.4e, <C12> %10.4e\n",
2300 "Long Range LJ corr.: Epot %10g, Pres: %10g, Vir: %10g\n",
2301 *enercorr,spres,svir);
2305 fprintf(debug,"Long Range LJ corr.: Epot %10g\n",*enercorr);
2309 if (fr->bSepDVDL && do_per_step(step,ir->nstlog))
2311 fprintf(fplog,sepdvdlformat,"Dispersion correction",
2312 *enercorr,dvdlambda);
2314 if (fr->efep != efepNO)
2316 *dvdlcorr += dvdlambda;
2321 void do_pbc_first(FILE *fplog,matrix box,t_forcerec *fr,
2322 t_graph *graph,rvec x[])
2325 fprintf(fplog,"Removing pbc first time\n");
2326 calc_shifts(box,fr->shift_vec);
2328 mk_mshift(fplog,graph,fr->ePBC,box,x);
2330 p_graph(debug,"do_pbc_first 1",graph);
2331 shift_self(graph,box,x);
2332 /* By doing an extra mk_mshift the molecules that are broken
2333 * because they were e.g. imported from another software
2334 * will be made whole again. Such are the healing powers
2337 mk_mshift(fplog,graph,fr->ePBC,box,x);
2339 p_graph(debug,"do_pbc_first 2",graph);
2342 fprintf(fplog,"Done rmpbc\n");
2345 static void low_do_pbc_mtop(FILE *fplog,int ePBC,matrix box,
2346 gmx_mtop_t *mtop,rvec x[],
2351 gmx_molblock_t *molb;
2353 if (bFirst && fplog)
2354 fprintf(fplog,"Removing pbc first time\n");
2358 for(mb=0; mb<mtop->nmolblock; mb++) {
2359 molb = &mtop->molblock[mb];
2360 if (molb->natoms_mol == 1 ||
2361 (!bFirst && mtop->moltype[molb->type].cgs.nr == 1)) {
2362 /* Just one atom or charge group in the molecule, no PBC required */
2363 as += molb->nmol*molb->natoms_mol;
2365 /* Pass NULL iso fplog to avoid graph prints for each molecule type */
2366 mk_graph_ilist(NULL,mtop->moltype[molb->type].ilist,
2367 0,molb->natoms_mol,FALSE,FALSE,graph);
2369 for(mol=0; mol<molb->nmol; mol++) {
2370 mk_mshift(fplog,graph,ePBC,box,x+as);
2372 shift_self(graph,box,x+as);
2373 /* The molecule is whole now.
2374 * We don't need the second mk_mshift call as in do_pbc_first,
2375 * since we no longer need this graph.
2378 as += molb->natoms_mol;
2386 void do_pbc_first_mtop(FILE *fplog,int ePBC,matrix box,
2387 gmx_mtop_t *mtop,rvec x[])
2389 low_do_pbc_mtop(fplog,ePBC,box,mtop,x,TRUE);
2392 void do_pbc_mtop(FILE *fplog,int ePBC,matrix box,
2393 gmx_mtop_t *mtop,rvec x[])
2395 low_do_pbc_mtop(fplog,ePBC,box,mtop,x,FALSE);
2398 void finish_run(FILE *fplog,t_commrec *cr,const char *confout,
2399 t_inputrec *inputrec,
2400 t_nrnb nrnb[],gmx_wallcycle_t wcycle,
2401 gmx_runtime_t *runtime,
2402 wallclock_gpu_t *gputimes,
2404 gmx_bool bWriteStat)
2407 t_nrnb *nrnb_tot=NULL;
2411 wallcycle_sum(cr,wcycle);
2417 MPI_Allreduce(nrnb->n,nrnb_tot->n,eNRNB,MPI_DOUBLE,MPI_SUM,
2418 cr->mpi_comm_mysim);
2426 #if defined(GMX_MPI) && !defined(GMX_THREAD_MPI)
2429 /* reduce nodetime over all MPI processes in the current simulation */
2431 MPI_Allreduce(&runtime->proctime,&sum,1,MPI_DOUBLE,MPI_SUM,
2432 cr->mpi_comm_mysim);
2433 runtime->proctime = sum;
2439 print_flop(fplog,nrnb_tot,&nbfs,&mflop);
2446 if ((cr->duty & DUTY_PP) && DOMAINDECOMP(cr))
2448 print_dd_statistics(cr,inputrec,fplog);
2460 snew(nrnb_all,cr->nnodes);
2461 nrnb_all[0] = *nrnb;
2462 for(s=1; s<cr->nnodes; s++)
2464 MPI_Recv(nrnb_all[s].n,eNRNB,MPI_DOUBLE,s,0,
2465 cr->mpi_comm_mysim,&stat);
2467 pr_load(fplog,cr,nrnb_all);
2472 MPI_Send(nrnb->n,eNRNB,MPI_DOUBLE,MASTERRANK(cr),0,
2473 cr->mpi_comm_mysim);
2480 wallcycle_print(fplog,cr->nnodes,cr->npmenodes,runtime->realtime,
2483 if (EI_DYNAMICS(inputrec->eI))
2485 delta_t = inputrec->delta_t;
2494 print_perf(fplog,runtime->proctime,runtime->realtime,
2495 cr->nnodes-cr->npmenodes,
2496 runtime->nsteps_done,delta_t,nbfs,mflop,
2501 print_perf(stderr,runtime->proctime,runtime->realtime,
2502 cr->nnodes-cr->npmenodes,
2503 runtime->nsteps_done,delta_t,nbfs,mflop,
2509 extern void initialize_lambdas(FILE *fplog,t_inputrec *ir,int *fep_state,real *lambda,double *lam0)
2511 /* this function works, but could probably use a logic rewrite to keep all the different
2512 types of efep straight. */
2515 t_lambda *fep = ir->fepvals;
2517 if ((ir->efep==efepNO) && (ir->bSimTemp == FALSE)) {
2518 for (i=0;i<efptNR;i++) {
2527 *fep_state = fep->init_fep_state; /* this might overwrite the checkpoint
2528 if checkpoint is set -- a kludge is in for now
2530 for (i=0;i<efptNR;i++)
2532 /* overwrite lambda state with init_lambda for now for backwards compatibility */
2533 if (fep->init_lambda>=0) /* if it's -1, it was never initializd */
2535 lambda[i] = fep->init_lambda;
2537 lam0[i] = lambda[i];
2542 lambda[i] = fep->all_lambda[i][*fep_state];
2544 lam0[i] = lambda[i];
2549 /* need to rescale control temperatures to match current state */
2550 for (i=0;i<ir->opts.ngtc;i++) {
2551 if (ir->opts.ref_t[i] > 0) {
2552 ir->opts.ref_t[i] = ir->simtempvals->temperatures[*fep_state];
2558 /* Send to the log the information on the current lambdas */
2561 fprintf(fplog,"Initial vector of lambda components:[ ");
2562 for (i=0;i<efptNR;i++)
2564 fprintf(fplog,"%10.4f ",lambda[i]);
2566 fprintf(fplog,"]\n");
2572 void init_md(FILE *fplog,
2573 t_commrec *cr,t_inputrec *ir,const output_env_t oenv,
2574 double *t,double *t0,
2575 real *lambda, int *fep_state, double *lam0,
2576 t_nrnb *nrnb,gmx_mtop_t *mtop,
2578 int nfile,const t_filenm fnm[],
2579 gmx_mdoutf_t **outf,t_mdebin **mdebin,
2580 tensor force_vir,tensor shake_vir,rvec mu_tot,
2581 gmx_bool *bSimAnn,t_vcm **vcm, t_state *state, unsigned long Flags)
2586 /* Initial values */
2587 *t = *t0 = ir->init_t;
2590 for(i=0;i<ir->opts.ngtc;i++)
2592 /* set bSimAnn if any group is being annealed */
2593 if(ir->opts.annealing[i]!=eannNO)
2600 update_annealing_target_temp(&(ir->opts),ir->init_t);
2603 /* Initialize lambda variables */
2604 initialize_lambdas(fplog,ir,fep_state,lambda,lam0);
2608 *upd = init_update(fplog,ir);
2614 *vcm = init_vcm(fplog,&mtop->groups,ir);
2617 if (EI_DYNAMICS(ir->eI) && !(Flags & MD_APPENDFILES))
2619 if (ir->etc == etcBERENDSEN)
2621 please_cite(fplog,"Berendsen84a");
2623 if (ir->etc == etcVRESCALE)
2625 please_cite(fplog,"Bussi2007a");
2633 *outf = init_mdoutf(nfile,fnm,Flags,cr,ir,oenv);
2635 *mdebin = init_mdebin((Flags & MD_APPENDFILES) ? NULL : (*outf)->fp_ene,
2636 mtop,ir, (*outf)->fp_dhdl);
2641 please_cite(fplog,"Fritsch12");
2642 please_cite(fplog,"Junghans10");
2644 /* Initiate variables */
2645 clear_mat(force_vir);
2646 clear_mat(shake_vir);