Example #1
0
void CowichanTBB::life(BoolMatrix input, BoolMatrix output) {
  GameOfLife game(input, output, nr, nc);

  for (index_t i = 0; i < LIFE_ITERATIONS; ++i) {

    // update CA simulation
    parallel_reduce(Range2D(0, nr, 0, nc), game, auto_partitioner());

    // check if there are alive cells
    if (!game.isAlive()) {
      no_cells_alive();
    }

    // swap arrays (ping-pong approach)
    game.swap();

  }

  // final result is in input - copy to output
  if (LIFE_ITERATIONS % 2 == 0) {
    for (index_t r = 0; r < nr; r++) {
      for (index_t c = 0; c < nc; c++) {
        MATRIX_RECT(output, r, c) = MATRIX_RECT(input, r, c);
      }
    }
  }
}
Example #2
0
void CowichanTBB::norm(PointVector pointsIn, PointVector pointsOut) {

  MinMaxReducer minmax(pointsIn);

  // find min/max coordinates
  parallel_reduce(Range(0, n), minmax, auto_partitioner());

  Point minPoint = minmax.getMinimum();
  Point maxPoint = minmax.getMaximum();

  // compute scaling factors
  real xfactor = (real)((maxPoint.x == minPoint.x) ?
      0.0 : 1.0 / (maxPoint.x - minPoint.x));
  real yfactor = (real)((maxPoint.y == minPoint.y) ?
      0.0 : 1.0 / (maxPoint.y - minPoint.y));

  Normalizer normalizer(pointsIn, pointsOut, minPoint.x, minPoint.y, xfactor,
      yfactor);

  // normalize the vector
  parallel_for(Range(0, n), normalizer, auto_partitioner());

}
void I2D_CoreFMM_AggressiveVel::solve(const Real theta, const Real inv_scaling, BlockInfo * dest, const int nblocks, VelocitySourceParticle * srcparticles, const int nparticles)
{
	Profiler profiler;
	
	_THETA = theta;
	
	tBox * rootBox=new tBox;
	tick_count start_before_tree = tick_count::now ();
	profiler.push_start("tree");
	tBoxBuilder::buildBoxes(srcparticles, nparticles, rootBox);
	profiler.pop_stop();
	
	tick_count start_before_expansions = tick_count::now ();
	profiler.push_start("expansions");
	tBoxBuilder::generateExpansions(rootBox);
	profiler.pop_stop();
	
	tick_count start_before_evaluations = tick_count::now ();
	profiler.push_start("evaluations");
	Measurements measurements (nblocks);
	VelocityEvaluator evaluator(rootBox, inv_scaling, measurements);
	evaluator.destblocks = dest;
	tbb::parallel_for(blocked_range<int>(0, nblocks), evaluator, auto_partitioner());
	profiler.pop_stop();
	tick_count end = tick_count::now ();

	if (timestamp++ % 5 == 0) profiler.printSummary();
	
	if (b_verbose) {
	
		const double tree_wallclock_time = (start_before_expansions - start_before_tree).seconds();
		const double evaluations_wallclock_time = (end - start_before_evaluations).seconds();
		const double expansions_wallclock_time = (start_before_evaluations - start_before_expansions).seconds();

		const double num_effective_interactions = (double)nparticles*nblocks*_BLOCKSIZE_*_BLOCKSIZE_;

		double effective_direct_gflops, effective_indirect_gflops, effective_total_gflops;
		double actual_direct_gflops, actual_indirect_gflops, actual_total_gflops;

		double num_direct_evals, num_indirect_evals;
		num_direct_evals = num_indirect_evals = 0;
		for (int i=0; i<nblocks; ++i) {
			num_direct_evals += (double)measurements.num_direct_evals[i];
			num_indirect_evals += (double)measurements.num_indirect_evals[i] ;
		}

		effective_direct_gflops = num_direct_evals * 11./1e9;
		actual_direct_gflops = num_direct_evals * 15./1e9;
		effective_indirect_gflops = num_indirect_evals * (16 + 14*_ORDER_) * 1./1e9;
		actual_indirect_gflops = num_indirect_evals * (20 + 14*_ORDER_) * 1./1e9;

		effective_total_gflops = effective_direct_gflops + effective_indirect_gflops;
		actual_total_gflops = actual_direct_gflops + actual_indirect_gflops;

		//Write data for break even plot
		std::fstream file;


		file.open ("measurements.txt",  std::fstream::app | std::fstream::out);
		file << setprecision (6) << scientific << num_effective_interactions << "\t" << effective_total_gflops << "\t" \
				<< actual_total_gflops << "\t" << evaluations_wallclock_time << "\t" << \
				expansions_wallclock_time << "\t" << tree_wallclock_time << "\n";
		file.close ();


	}
	delete rootBox;
}