Also fixed a memory leak.
Change-Id: I9c4bd3ed1919c82cf26d1181ea98d4c2dcc37b0b
/* Reset all the counters related to performance over the run */
wallcycle_stop(wcycle, ewcRUN);
wallcycle_reset_all(wcycle);
- init_nrnb(nrnb);
+ *nrnb = { 0 };
wallcycle_start(wcycle, ewcRUN);
walltime_accounting_reset_time(walltime_accounting, step);
changePinningPolicy(&pme_pp->x, pme_get_pinning_policy());
}
- init_nrnb(mynrnb);
+ clear_nrnb(mynrnb);
count = 0;
do /****** this is a quasi-loop over time steps! */
#include "gromacs/fileio/xvgr.h"
#include "gromacs/gmxana/gmx_ana.h"
#include "gromacs/gmxana/gstat.h"
-#include "gromacs/gmxlib/nrnb.h"
#include "gromacs/listed_forces/disre.h"
#include "gromacs/math/do_fit.h"
#include "gromacs/math/functions.h"
FILE *out = nullptr, *aver = nullptr, *numv = nullptr, *maxxv = nullptr, *xvg = nullptr;
gmx_localtop_t top;
t_fcdata fcd;
- t_nrnb nrnb;
t_graph *g;
int i, j, kkk;
t_trxstatus *status;
auto mdAtoms = gmx::makeMDAtoms(fplog, *topInfo.mtop(), *ir, false);
atoms2md(topInfo.mtop(), ir, -1, nullptr, ntopatoms, mdAtoms.get());
update_mdatoms(mdAtoms->mdatoms(), ir->fepvals->init_lambda);
- init_nrnb(&nrnb);
if (ir->ePBC != epbcNONE)
{
gpbc = gmx_rmpbc_init(&top.idef, ir->ePBC, natoms);
#include <cstring>
#include <algorithm>
+#include <vector>
#include "gromacs/mdtypes/commrec.h"
#include "gromacs/mdtypes/md_enums.h"
#include "gromacs/utility/arraysize.h"
-#include "gromacs/utility/smalloc.h"
typedef struct {
const char *name;
fprintf(out, "\n");
}
-void init_nrnb(t_nrnb *nrnb)
+void clear_nrnb(t_nrnb *nrnb)
{
int i;
}
}
-void cp_nrnb(t_nrnb *dest, t_nrnb *src)
-{
- int i;
-
- for (i = 0; (i < eNRNB); i++)
- {
- dest->n[i] = src->n[i];
- }
-}
-
void add_nrnb(t_nrnb *dest, t_nrnb *s1, t_nrnb *s2)
{
int i;
void pr_load(FILE *log, t_commrec *cr, t_nrnb nrnb[])
{
- int i, j, perc;
- double dperc, unb, uf, us;
- double *ftot, fav;
- double *stot, sav;
- t_nrnb *av;
-
- snew(av, 1);
- snew(ftot, cr->nnodes);
- snew(stot, cr->nnodes);
- init_nrnb(av);
- for (i = 0; (i < cr->nnodes); i++)
+ t_nrnb av;
+
+ std::vector<double> ftot(cr->nnodes);
+ std::vector<double> stot(cr->nnodes);
+ for (int i = 0; (i < cr->nnodes); i++)
{
- add_nrnb(av, av, &(nrnb[i]));
+ add_nrnb(&av, &av, &(nrnb[i]));
/* Cost due to forces */
- for (j = 0; (j < eNR_NBKERNEL_TOTAL_NR); j++)
+ for (int j = 0; (j < eNR_NBKERNEL_TOTAL_NR); j++)
{
ftot[i] += nrnb[i].n[j]*cost_nrnb(j);
}
- for (j = 0; (j < NFORCE_INDEX); j++)
+ for (int j = 0; (j < NFORCE_INDEX); j++)
{
ftot[i] += nrnb[i].n[force_index[j]]*cost_nrnb(force_index[j]);
}
/* Due to shake */
- for (j = 0; (j < NCONSTR_INDEX); j++)
+ for (int j = 0; (j < NCONSTR_INDEX); j++)
{
stot[i] += nrnb[i].n[constr_index[j]]*cost_nrnb(constr_index[j]);
}
}
- for (j = 0; (j < eNRNB); j++)
+ for (int j = 0; (j < eNRNB); j++)
{
- av->n[j] = av->n[j]/static_cast<double>(cr->nnodes - cr->npmenodes);
+ av.n[j] = av.n[j]/static_cast<double>(cr->nnodes - cr->npmenodes);
}
fprintf(log, "\nDetailed load balancing info in percentage of average\n");
fprintf(log, " Type RANK:");
- for (i = 0; (i < cr->nnodes); i++)
+ for (int i = 0; (i < cr->nnodes); i++)
{
fprintf(log, "%3d ", i);
}
fprintf(log, "Scaling\n");
fprintf(log, "---------------------------");
- for (i = 0; (i < cr->nnodes); i++)
+ for (int i = 0; (i < cr->nnodes); i++)
{
fprintf(log, "----");
}
fprintf(log, "-------\n");
- for (j = 0; (j < eNRNB); j++)
+ for (int j = 0; (j < eNRNB); j++)
{
- unb = 100.0;
- if (av->n[j] > 0)
+ double unb = 100.0;
+ if (av.n[j] > 0)
{
+ double dperc;
+ int perc;
fprintf(log, " %-26s", nrnb_str(j));
- for (i = 0; (i < cr->nnodes); i++)
+ for (int i = 0; (i < cr->nnodes); i++)
{
- dperc = (100.0*nrnb[i].n[j])/av->n[j];
+ dperc = (100.0*nrnb[i].n[j])/av.n[j];
unb = std::max(unb, dperc);
perc = static_cast<int>(dperc);
fprintf(log, "%3d ", perc);
}
}
}
- fav = sav = 0;
- for (i = 0; (i < cr->nnodes); i++)
+ double fav = 0;
+ double sav = 0;
+ for (int i = 0; (i < cr->nnodes); i++)
{
fav += ftot[i];
sav += stot[i];
}
- uf = pr_av(log, cr, fav, ftot, "Total Force");
- us = pr_av(log, cr, sav, stot, "Total Constr.");
+ double uf = pr_av(log, cr, fav, ftot.data(), "Total Force");
+ double us = pr_av(log, cr, sav, stot.data(), "Total Constr.");
- unb = (uf*fav+us*sav)/(fav+sav);
+ double unb = (uf*fav+us*sav)/(fav+sav);
if (unb > 0)
{
unb = 10000.0/unb;
};
-typedef struct t_nrnb
+struct t_nrnb
{
- double n[eNRNB];
-}
-t_nrnb;
-struct t_commrec;
-struct t_nrnb;
+ double n[eNRNB] = { 0 };
+};
-void init_nrnb(t_nrnb *nrnb);
+struct t_commrec;
-void cp_nrnb(t_nrnb *dest, t_nrnb *src);
+void clear_nrnb(t_nrnb *nrnb);
void add_nrnb(t_nrnb *dest, t_nrnb *s1, t_nrnb *s2);
{
reset_dd_statistics_counters(cr->dd);
}
- init_nrnb(nrnb);
+ clear_nrnb(nrnb);
wallcycle_start(wcycle, ewcRUN);
walltime_accounting_reset_time(walltime_accounting, step);
print_date_and_time(fplog, cr->nodeid, "Restarted time", gmx_gettime());
{
pleaseCiteCouplingAlgorithms(fplog, *ir);
}
- init_nrnb(nrnb);
gmx_mdoutf *outf = init_mdoutf(fplog, nfile, fnm, mdrunOptions, cr, outputProvider, ir, top_global, oenv, wcycle,
StartingBehavior::NewSimulation);
gmx::EnergyOutput energyOutput(mdoutf_get_fp_ene(outf), top_global, ir, pull_work, mdoutf_get_fp_dhdl(outf), false);
top_global->intermolecularExclusionGroup = genQmmmIndices(*top_global);
initialize_lambdas(fplog, *ir, MASTER(cr), &state_global->fep_state, state_global->lambda, lam0);
- init_nrnb(nrnb);
gmx_mdoutf *outf = init_mdoutf(fplog, nfile, fnm, mdrunOptions, cr, outputProvider, ir, top_global, oenv, wcycle,
StartingBehavior::NewSimulation);
}
initialize_lambdas(fplog, *ir, MASTER(cr), &(state_global->fep_state), state_global->lambda, nullptr);
- init_nrnb(nrnb);
-
if (ir->eI == eiNM)
{
GMX_ASSERT(shellfc != nullptr, "With NM we always support shells");
snew(full_matrix, sz*sz);
}
- init_nrnb(nrnb);
-
-
/* Write start time and temperature */
print_em_start(fplog, cr, walltime_accounting, wcycle, NM);
}
initialize_lambdas(fplog, *ir, MASTER(cr), &state_global->fep_state, state_global->lambda, lam0);
- init_nrnb(nrnb);
gmx_mdoutf *outf = init_mdoutf(fplog, nfile, fnm, mdrunOptions, cr, outputProvider, ir, top_global, oenv, wcycle,
StartingBehavior::NewSimulation);
gmx::EnergyOutput energyOutput(mdoutf_get_fp_ene(outf), top_global, ir, pull_work, mdoutf_get_fp_dhdl(outf), true);
const gmx_pme_t *pme,
gmx_bool bWriteStat)
{
- t_nrnb *nrnb_tot = nullptr;
double delta_t = 0;
double nbfs = 0, mflop = 0;
double elapsed_time,
printReport = false;
}
+ t_nrnb *nrnb_tot;
+ std::unique_ptr<t_nrnb> nrnbTotalStorage;
if (cr->nnodes > 1)
{
- snew(nrnb_tot, 1);
+ nrnbTotalStorage = std::make_unique<t_nrnb>();
+ nrnb_tot = nrnbTotalStorage.get();
#if GMX_MPI
MPI_Allreduce(nrnb->n, nrnb_tot->n, eNRNB, MPI_DOUBLE, MPI_SUM,
cr->mpi_comm_mysim);
{
print_flop(fplog, nrnb_tot, &nbfs, &mflop);
}
- if (cr->nnodes > 1)
- {
- sfree(nrnb_tot);
- }
if (thisRankHasDuty(cr, DUTY_PP) && DOMAINDECOMP(cr))
{
int Mdrunner::mdrunner()
{
matrix box;
- t_nrnb *nrnb;
t_forcerec *fr = nullptr;
t_fcdata *fcd = nullptr;
real ewaldcoeff_q = 0;
std::unique_ptr<MDAtoms> mdAtoms;
std::unique_ptr<gmx_vsite_t> vsite;
- snew(nrnb, 1);
+ t_nrnb nrnb;
if (thisRankHasDuty(cr, DUTY_PP))
{
/* Initiate forcerecord */
|| observablesHistory.edsamHistory);
auto constr = makeConstraints(mtop, *inputrec, pull_work, doEssentialDynamics,
fplog, *mdAtoms->mdatoms(),
- cr, ms, nrnb, wcycle, fr->bMolPBC);
+ cr, ms, &nrnb, wcycle, fr->bMolPBC);
/* Energy terms and groups */
gmx_enerdata_t enerd(mtop.groups.groups[SimulationAtomGroupType::EnergyOutput].size(), inputrec->fepvals->n_lambda);
fcd,
globalState.get(),
&observablesHistory,
- mdAtoms.get(), nrnb, wcycle, fr,
+ mdAtoms.get(), &nrnb, wcycle, fr,
&enerd,
&ppForceWorkload,
replExParams,
GMX_RELEASE_ASSERT(pmedata, "pmedata was NULL while cr->duty was not DUTY_PP");
/* do PME only */
walltime_accounting = walltime_accounting_init(gmx_omp_nthreads_get(emntPME));
- gmx_pmeonly(pmedata, cr, nrnb, wcycle, walltime_accounting, inputrec, pmeRunMode);
+ gmx_pmeonly(pmedata, cr, &nrnb, wcycle, walltime_accounting, inputrec, pmeRunMode);
}
wallcycle_stop(wcycle, ewcRUN);
* if rerunMD, don't write last frame again
*/
finish_run(fplog, mdlog, cr,
- inputrec, nrnb, wcycle, walltime_accounting,
+ inputrec, &nrnb, wcycle, walltime_accounting,
fr ? fr->nbv.get() : nullptr,
pmedata,
EI_DYNAMICS(inputrec->eI) && !isMultiSim(ms));
/* Does what it says */
print_date_and_time(fplog, cr->nodeid, "Finished mdrun", gmx_gettime());
walltime_accounting_destroy(walltime_accounting);
- sfree(nrnb);
// Ensure log file content is written
if (logFileHandle)