How expensive is evtally?

Dear LAMMPS,

I have coded up a pair-style potential in LAMMPS, and so far everything seems to be working, so now I’m at the stage of optimising the code as much as possible. One part which I’ve been treating as a black box up until now is the ev_tally family of functions. At the moment, my code is calling them several times as a result of the fact that they occur within nested loops. Looking in pair.cpp, it doesn’t seem as though it is too costly, so I’ve left it as is… or is it better to accumulate energies and forces myself and then make a single call to ev_tally at the end?

Cheers,
~/Sam/McSweeney

Dear LAMMPS,

I have coded up a pair-style potential in LAMMPS, and so far everything
seems to be working, so now I'm at the stage of optimising the code as much
as possible. One part which I've been treating as a black box up until now
is the ev_tally family of functions. At the moment, my code is calling them
several times as a result of the fact that they occur within nested loops.
Looking in pair.cpp, it doesn't seem as though it is too costly, so I've
left it as is... or is it better to accumulate energies and forces myself
and then make a single call to ev_tally at the end?

you cannot. it is needed to be called in the innerloops in case per
atom energies and forces are requested.
however, the function is only called when this information is needed,
that is typically only when output is requested.
in addition, for simple potentials, the virial is computed more
efficiently from F dot r.

there is still a cost associated with putting an if statement into the
innerloops (and there are some other issues).
you could have a look at pair_lj_cut_omp.cpp (it works fine w/o
OpenMP) and compare its performance to pair_lj_cut.cpp to see which
kinds of improvements are possible through this.

axel.