metis_util_unit_test.hpp 1.82 KB
Newer Older
incardon's avatar
incardon committed
1 2 3 4 5 6 7 8 9 10 11
/*
 * metis_util_unit_test.hpp
 *
 *  Created on: Dec 21, 2014
 *      Author: i-bird
 */

#ifndef METIS_UTIL_UNIT_TEST_HPP_
#define METIS_UTIL_UNIT_TEST_HPP_

#include "Graph/CartesianGraphFactory.hpp"
incardon's avatar
incardon committed
12
#include "Graph/map_graph.hpp"
incardon's avatar
incardon committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#include "metis_util.hpp"

#undef GS_SIZE
#define GS_SIZE 8

/*!
 *
 * Test node
 *
 */

BOOST_AUTO_TEST_SUITE( Metis_test )

BOOST_AUTO_TEST_CASE( Metis_test_use)
{
28 29 30 31 32 33 34 35
	Vcluster & v_cl = *global_v_cluster;

	if (v_cl.getProcessingUnits() != 3)
		return;

	if (v_cl.getProcessUnitID() != 0)
		return;

incardon's avatar
incardon committed
36 37 38 39
	CartesianGraphFactory<3,Graph_CSR<nm_v,nm_e>> g_factory;
	CartesianGraphFactory<3,Graph_CSR<nm_part_v,nm_part_e>> g_factory_part;

	// Cartesian grid
incardon's avatar
incardon committed
40
	size_t sz[3] = {GS_SIZE,GS_SIZE,GS_SIZE};
incardon's avatar
incardon committed
41 42 43 44

	// Box
	Box<3,float> box({0.0,0.0,0.0},{1.0,1.0,1.0});

45 46
	// Boundary conditions, non periodic
	size_t bc[] = {NON_PERIODIC,NON_PERIODIC,NON_PERIODIC};
incardon's avatar
incardon committed
47

48
	// Graph to decompose
49
	Graph_CSR<nm_v,nm_e> g = g_factory.construct<nm_e::communication,NO_VERTEX_ID,float,2,0>(sz,box,bc);
incardon's avatar
incardon committed
50 51

	// Processor graph
52
	Graph_CSR<nm_part_v,nm_part_e> gp = g_factory_part.construct<NO_EDGE,NO_VERTEX_ID,float,2>(sz,box,bc);
incardon's avatar
incardon committed
53 54 55

	// Convert the graph to metis

incardon's avatar
incardon committed
56
	Metis<Graph_CSR<nm_v,nm_e>> met(g,8);
incardon's avatar
incardon committed
57 58 59 60

	// decompose

	met.decompose<nm_part_v::id>(gp);
61 62 63
	met.decompose<nm_v::proc_id>();

	// Write the VTK file
incardon's avatar
incardon committed
64

65 66 67 68 69 70 71 72 73 74 75 76 77
	VTKWriter<Graph_CSR<nm_part_v,nm_part_e>,VTK_GRAPH> vtk(gp);
	vtk.write("vtk_metis_util_gp.vtk");

	VTKWriter<Graph_CSR<nm_v,nm_e>,VTK_GRAPH> vtk2(g);
	vtk2.write("vtk_metis_util_g.vtk");

	// check that match

	bool test = compare("vtk_metis_util_gp.vtk","src/Decomposition/Distribution/test_data/vtk_metis_util_gp_test.vtk");
	bool test2 = compare("vtk_metis_util_g.vtk","src/Decomposition/Distribution/test_data/vtk_metis_util_g_test.vtk");
	BOOST_REQUIRE_EQUAL(true,test);
	BOOST_REQUIRE_EQUAL(true,test2);
}
78

incardon's avatar
incardon committed
79 80 81
BOOST_AUTO_TEST_SUITE_END()

#endif