grid_dist_id_unit_test.hpp 2.8 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
#ifndef GRID_DIST_UNIT_TEST_HPP
#define GRID_DIST_UNIT_TEST_HPP

#include "grid_dist_id.hpp"
#include "data_type/scalar.hpp"

BOOST_AUTO_TEST_SUITE( grid_dist_id_test )

template<typename iterator> void jacobi_iteration(iterator g_it, grid_dist_id<2, scalar<float>, CartDecomposition<2,size_t>> & g_dist)
{
	// scalar
	typedef scalar<size_t> S;

	// iterator

	while(g_it.isNext())
	{
		// Jacobi update

		auto pos = g_it.get();

		g_dist.template get<S::ele>(pos) = (g_dist.template get<S::ele>(pos.move(0,1)) +
	                             g_dist.template get<S::ele>(pos.move(0,-1)) +
	                             g_dist.template get<S::ele>(pos.move(1,1)) +
	                             g_dist.template get<S::ele>(pos.move(1,-1)) / 4.0);

		++g_it;
	}
}

BOOST_AUTO_TEST_CASE( grid_dist_id_iterator_test_use)
{
incardon's avatar
incardon committed
33 34 35
	// Initialize the global VCluster
	init_global_v_cluster(&boost::unit_test::framework::master_test_suite().argc,&boost::unit_test::framework::master_test_suite().argv);

incardon's avatar
incardon committed
36 37 38 39 40 41 42
	// grid size
	size_t sz[2] = {1024,1024};

	// Distributed grid with id decomposition

	grid_dist_id<2, scalar<float>, CartDecomposition<2,size_t>> g_dist(sz);

incardon's avatar
incardon committed
43 44 45 46 47
	// get the domain iterator

	size_t count = 0;

	auto dom = g_dist.getDomainIterator();
incardon's avatar
incardon committed
48

incardon's avatar
incardon committed
49 50 51 52
	while (dom.isNext())
	{
		auto key = dom.get();

incardon's avatar
incardon committed
53 54 55
		g_dist.template get<0>(key) = count;

		// Count the point
incardon's avatar
incardon committed
56
		count++;
incardon's avatar
incardon committed
57

incardon's avatar
incardon committed
58 59
		++dom;
	}
incardon's avatar
incardon committed
60

incardon's avatar
incardon committed
61 62 63 64 65 66 67 68 69 70
	// Get the virtual cluster machine
	Vcluster & vcl = g_dist.getVC();

	// reduce
	vcl.reduce(count);
	vcl.execute();

	// Check
	BOOST_REQUIRE_EQUAL(count,1024*1024);

incardon's avatar
incardon committed
71 72 73 74 75 76 77 78 79 80 81 82 83
	size_t count_check = 0;
	dom = g_dist.getDomainIterator();

	while (dom.isNext())
	{
		auto key = dom.get();

		BOOST_REQUIRE_EQUAL(g_dist.template get<0>(key),count_check);

		count_check++;
		++dom;
	}

incardon's avatar
incardon committed
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
/*	auto g_it = g_dist.getIteratorBulk();

	auto g_it_halo = g_dist.getHalo();

	// Let try to solve the poisson equation d2(u) = f with f = 1 and computation
	// comunication overlap (100 Jacobi iteration)

	for (int i = 0 ; i < 100 ; i++)
	{
		g_dist.ghost_get();

		// Compute the bulk

		jacobi_iteration(g_it);

		g_dist.ghost_sync();

		// Compute the halo

		jacobi_iteration(g_it_halo);
	}*/
}

BOOST_AUTO_TEST_CASE( grid_dist_id_poisson_test_use)
{
	// grid size
incardon's avatar
incardon committed
110
/*	size_t sz[2] = {1024,1024};
incardon's avatar
incardon committed
111 112 113 114 115 116 117

	// Distributed grid with id decomposition

	grid_dist_id<2, scalar<float>, CartDecomposition<2,size_t>> g_dist(sz);

	// Create the grid on memory

incardon's avatar
incardon committed
118
	g_dist.Create();*/
incardon's avatar
incardon committed
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

/*	auto g_it = g_dist.getIteratorBulk();

	auto g_it_halo = g_dist.getHalo();

	// Let try to solve the poisson equation d2(u) = f with f = 1 and computation
	// comunication overlap (100 Jacobi iteration)

	for (int i = 0 ; i < 100 ; i++)
	{
		g_dist.ghost_get();

		// Compute the bulk

		jacobi_iteration(g_it);

		g_dist.ghost_sync();

		// Compute the halo

		jacobi_iteration(g_it_halo);
	}*/
}

BOOST_AUTO_TEST_SUITE_END()

#endif