Пример #1
0
void update_grid(const vector<RiemannSolution>& fluxes,
                 double dt,
                 vector<double>& grid)
{
    class DisplacementCalculator: public Index2Member<double>
    {
    public:

        DisplacementCalculator(const vector<RiemannSolution>& fluxes_i,
                               double dt_i):
            fluxes_(fluxes_i), dt_(dt_i) {}

        size_t getLength(void) const
        {
            return fluxes_.size();
        }

        double operator()(size_t i) const
        {
            return fluxes_[i].velocity*dt_;
        }

    private:
        const vector<RiemannSolution>& fluxes_;
        const double dt_;
    } displacement_calculator(fluxes, dt);

    serial_increment(serial_generate(displacement_calculator),
                     grid);
}
Пример #2
0
void update_momenta(const vector<RiemannSolution>& fluxes,
                    double dt,
                    vector<double>& momenta)
{
    class MomentumDifferenceCalculator: public Index2Member<double>
    {
    public:

        MomentumDifferenceCalculator(const vector<RiemannSolution>& fluxes_i,
                                     double dt_i):
            fluxes_(fluxes_i), dt_(dt_i) {}

        size_t getLength(void) const
        {
            return fluxes_.size() - 1;
        }

        double operator()(size_t i) const
        {
            return dt_*(fluxes_[i].pressure-
                        fluxes_[i+1].pressure);
        }

    private:

        const vector<RiemannSolution>& fluxes_;
        const double dt_;
    } momentum_difference_calculator(fluxes, dt);

    serial_increment(serial_generate(momentum_difference_calculator),
                     momenta);
}
Пример #3
0
void update_energies(const vector<RiemannSolution>& fluxes,
                     double dt,
                     vector<double>& energies)
{
    class EnergyDifferenceCalculator: public Index2Member<double>
    {
    public:

        EnergyDifferenceCalculator(const vector<RiemannSolution>& fluxes_i,
                                   double dt_i):
            fluxes_(fluxes_i), dt_(dt_i) {}

        size_t getLength(void) const
        {
            return fluxes_.size()-1;
        }

        double operator()(size_t i) const
        {
            return dt_*(fluxes_[i].pressure*fluxes_[i].velocity-
                        fluxes_[i+1].pressure*fluxes_[i+1].velocity);
        }

    private:
        const vector<RiemannSolution>& fluxes_;
        const double dt_;
    } energy_difference_calculator(fluxes, dt);

    serial_increment(serial_generate(energy_difference_calculator),
                     energies);
}
Пример #4
0
	bool TestAtomics::doTest()
	{
		hydrazine::Timer timer;
		
		timer.start();
		long long unsigned int atomic = atomic_increment( iterations, 
			threads, ctas );
		timer.stop();
		
		hydrazine::Timer::Second atomic_time = timer.seconds();
		
		timer.start();
		long long unsigned int serial = serial_increment( iterations );
		timer.stop();
		
		hydrazine::Timer::Second serial_time = timer.seconds();
		
		status << "Serial Time: " << serial_time << " seconds \n";
		status << "Atomic Time: " << atomic_time << " seconds \n";
		status << "Serial Speedup: " << ( atomic_time / serial_time ) << "x\n";
		
		if( serial > atomic )
		{
			status << "Serial result " << serial 
				<< " is greater than atomic result " << atomic << "\n";
			return false;
		}
		
		return true;
	}