#include namespace Eigen { template struct pow12_op EIGEN_EMPTY_STRUCT { inline const Scalar operator() (const Scalar& a) const { Scalar b = a*a*a; Scalar c = b*b; return c*c; } template inline const PacketScalar packetOp(const PacketScalar& a) const { PacketScalar b = ei_pmul(a, ei_pmul(a, a)); PacketScalar c = ei_pmul(b, b); return ei_pmul(c, c); } }; template struct ei_functor_traits > { enum { Cost = 4 * NumTraits::MulCost, PacketAccess = int(ei_packet_traits::size) > 1 }; }; } // namespace Eigen using Eigen::pow12_op; USING_PART_OF_NAMESPACE_EIGEN #ifndef SCALAR #define SCALAR float #endif #ifndef SIZE #define SIZE 10000 #endif #ifndef REPEAT #define REPEAT 10000 #endif typedef Matrix Vec; using namespace std; SCALAR E_VDW(const Vec &interactions1, const Vec &interactions2) { return interactions2 .cwiseQuotient(interactions1) .cwise(pow12_op()) .sum(); } int main() { // // 1 2 3 4 ... (interactions) // ka . . . . ... // rab . . . . ... // energy . . . . ... // ... ... ... ... ... ... // (variables // for // interaction) // Vec interactions1(SIZE), interactions2(SIZE); // SIZE is the number of vdw interactions in our system // SetupCalculations() SCALAR rab = 1.0; interactions1.setConstant(2.4); interactions2.setConstant(rab); // Energy() SCALAR energy = 0.0; for (unsigned int i = 0; i