void testParallelComputation() { System system; const int numParticles = 200; for (int i = 0; i < numParticles; i++) system.addParticle(1.0); HarmonicBondForce* force = new HarmonicBondForce(); for (int i = 1; i < numParticles; i++) force->addBond(i-1, i, 1.1, i); system.addForce(force); vector<Vec3> positions(numParticles); for (int i = 0; i < numParticles; i++) positions[i] = Vec3(i, 0, 0); VerletIntegrator integrator1(0.01); Context context1(system, integrator1, platform); context1.setPositions(positions); State state1 = context1.getState(State::Forces | State::Energy); VerletIntegrator integrator2(0.01); string deviceIndex = platform.getPropertyValue(context1, CudaPlatform::CudaDeviceIndex()); map<string, string> props; props[CudaPlatform::CudaDeviceIndex()] = deviceIndex+","+deviceIndex; Context context2(system, integrator2, platform, props); context2.setPositions(positions); State state2 = context2.getState(State::Forces | State::Energy); ASSERT_EQUAL_TOL(state1.getPotentialEnergy(), state2.getPotentialEnergy(), 1e-5); for (int i = 0; i < numParticles; i++) ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-5); }
void VarianceGammaEngine::calculate() const { QL_REQUIRE(arguments_.exercise->type() == Exercise::European, "not an European Option"); boost::shared_ptr<StrikedTypePayoff> payoff = boost::dynamic_pointer_cast<StrikedTypePayoff>(arguments_.payoff); QL_REQUIRE(payoff, "non-striked payoff given"); DiscountFactor dividendDiscount = process_->dividendYield()->discount( arguments_.exercise->lastDate()); DiscountFactor riskFreeDiscount = process_->riskFreeRate()->discount(arguments_.exercise->lastDate()); DayCounter rfdc = process_->riskFreeRate()->dayCounter(); Time t = rfdc.yearFraction(process_->riskFreeRate()->referenceDate(), arguments_.exercise->lastDate()); Integrand f(payoff, process_->x0(), t, riskFreeDiscount, dividendDiscount, process_->sigma(), process_->nu(), process_->theta()); Real infinity = 15.0 * std::sqrt(process_->nu() * t); Real target = absErr_*1e-4; Real val = f(infinity); while (std::abs(val)>target){ infinity*=1.5; val = f(infinity); } // the integration is split due to occasional singularities at 0 Real split = 0.1; GaussKronrodNonAdaptive integrator1(absErr_, 1000, 0); Real pvA = integrator1(f, 0, split); GaussLobattoIntegral integrator2(2000, absErr_); Real pvB = integrator2(f, split, infinity); results_.value = pvA + pvB; }