vector_dist_gg_map_performance.hpp 3.91 KB
Newer Older
incardon's avatar
incardon committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
#ifndef VECTOR_DIST_GG_MAP_PERFORMANCE_HPP_

#include "Vector/vector_dist.hpp"
#include "data_type/aggregate.hpp"
#include "Plot/GoogleChart.hpp"
#include <functional>

// Property tree
struct report_vector_gg_map_tests
{
	boost::property_tree::ptree graphs;
};

report_vector_gg_map_tests report_ggm;

///////////////////// INPUT DATA //////////////////////

// The starting amount of particles (remember that this number is multiplied by number of processors you use for testing)
size_t k_start = 100000;
// The minimal amount of particles
size_t k_min = 15000;

///////////////////////////////////////////////////////

BOOST_AUTO_TEST_SUITE( vector_gg_map_performance_test )


// Numbers of particles vector
openfpm::vector<size_t> n_particles;

template<unsigned int dim>
double benchmark_map(size_t k_int, Vcluster<HeapMemory> & v_cl)
{
	Box<dim,float> box;

	for (size_t i = 0; i < dim; i++)
	{
		box.setLow(i,0.0);
		box.setHigh(i,1.0);
	}

	// Boundary conditions
	size_t bc[dim];

	for (size_t i = 0; i < dim; i++)
	{bc[i] = PERIODIC;}

	vector_dist<dim,float, aggregate<float[dim]> > vd(k_int,box,bc,Ghost<dim,float>(0.1));

	auto & dec = vd.getDecomposition();

	for (size_t i = 0 ; i < v_cl.size() ; i++)
	{
		if (i == v_cl.rank())
		{continue;}

		auto & nn_box = dec.getNearSubdomains(i);

		if (nn_box.size() != 0)
		{
			// generate all particles in the near processor

			vd_initialize_box_nomap<dim>(vd,nn_box.get(0),v_cl,k_int);
		}
	}

	//Timer
	timer t;
	t.start();

	// benckmark map
	vd.map();

	t.stop();

	return t.getwct();
}


/*! \brief Function for cell list test without an Hilbert curve reordering (unordered positioning)
 *
 */
template<unsigned int dim>
void vector_gg_map_benchmark(size_t cl_k_start,
		                     size_t cl_k_min,
							 openfpm::vector<size_t> & cl_n_particles)
{
	std::string str("Testing " + std::to_string(dim) + "D vector, no-order, map ghost_get");
	print_test_v(str,0);

	{

		Vcluster<> & v_cl = create_vcluster();

		if (v_cl.size() != 3)
		{return;}

		//Number of particles
		size_t k = cl_k_start * v_cl.getProcessingUnits();

		//Counter number for amounts of particles
		size_t k_count = 1 + log2(k/cl_k_min);

		int c = 0;

		//For different number of particles
		for (size_t k_int = k ; k_int >= cl_k_min ; k_int/=2 )
		{
			BOOST_TEST_CHECKPOINT( "Testing " << dim << "D vector without an Hilbert curve reordering k=" << k_int );

			report_ggm.graphs.put("performance.map_" + std::to_string(dim) + "D.npart(" + std::to_string(c) + ").n",k_int);

			if (cl_n_particles.size() < k_count)
			{cl_n_particles.add(k_int);}

			openfpm::vector<double> measures;
			double sum_map_mean = 0.0;
			double sum_map_dev = 0.0;
			for (size_t h = 0 ; h < N_STAT_TEST; h++)
			{measures.add(benchmark_map<dim>(k_int,v_cl));}
			standard_deviation(measures,sum_map_mean,sum_map_dev);

			report_ggm.graphs.put("performance.map_" + std::to_string(dim) + "D.npart(" + std::to_string(c) + ").mean",sum_map_mean);
			report_ggm.graphs.put("performance.map_" + std::to_string(dim) + "D.npart(" + std::to_string(c) + ").dev",sum_map_dev);

			c++;
		}
	}
}



BOOST_AUTO_TEST_CASE( vector_dist_map_test )
{
	//Benchmark test for 2D and 3D
	vector_gg_map_benchmark<3>(k_start,k_min,n_particles);
	vector_gg_map_benchmark<2>(k_start,k_min,n_particles);
}


BOOST_AUTO_TEST_CASE(vector_dist_gg_map_performance_write_report)
{
	// Create a graphs

	report_ggm.graphs.put("graphs.graph.type","line");
	report_ggm.graphs.add("graphs.graph.title","Map performance");
	report_ggm.graphs.add("graphs.graph.x.title","number of particles");
	report_ggm.graphs.add("graphs.graph.y.title","Time seconds");
	report_ggm.graphs.add("graphs.graph.y.data(0).source","performance.map_3D.npart(#).mean");
	report_ggm.graphs.add("graphs.graph.x.data(0).source","performance.map_3D.npart(#).n");
	report_ggm.graphs.add("graphs.graph.y.data(0).title","Map function");
	report_ggm.graphs.add("graphs.graph.options.log_y","true");
}

BOOST_AUTO_TEST_SUITE_END()

#endif