Vector_unit_tests.hpp 2.43 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * Vector_unit_tests.hpp
 *
 *  Created on: Apr 6, 2016
 *      Author: i-bird
 */

#ifndef OPENFPM_NUMERICS_SRC_VECTOR_VECTOR_UNIT_TESTS_HPP_
#define OPENFPM_NUMERICS_SRC_VECTOR_VECTOR_UNIT_TESTS_HPP_

#include "Vector/Vector.hpp"

BOOST_AUTO_TEST_SUITE( vector_test_suite )

BOOST_AUTO_TEST_CASE(vector_eigen_parallel)
{
17
	Vcluster & vcl = create_vcluster();
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

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

	// 3 Processors 9x9 Matrix to invert

	Vector<double> v(9);

	if (vcl.getProcessUnitID() == 0)
	{
		// v row1
		v.insert(0,0);
		v.insert(1,1);
		v.insert(2,2);
	}
	else if (vcl.getProcessUnitID() == 1)
	{
		v.insert(3,3);
		v.insert(4,4);
		v.insert(5,5);
	}
	else if (vcl.getProcessUnitID() == 2)
	{
		v.insert(6,6);
		v.insert(7,7);
		v.insert(8,8);
	}

	Vector<double> v3;
	v3 = v;

	// force to sync
	v.getVec();

	Vector<double> v2;
	v2 = v;

	// Master has the full vector

	if (vcl.getProcessUnitID() == 0)
	{
		BOOST_REQUIRE_EQUAL(v(0),0);
		BOOST_REQUIRE_EQUAL(v(1),1);
		BOOST_REQUIRE_EQUAL(v(2),2);

		BOOST_REQUIRE_EQUAL(v(3),3);
		BOOST_REQUIRE_EQUAL(v(4),4);
		BOOST_REQUIRE_EQUAL(v(5),5);

		BOOST_REQUIRE_EQUAL(v(6),6);
		BOOST_REQUIRE_EQUAL(v(7),7);
		BOOST_REQUIRE_EQUAL(v(8),8);

		// Change the vector on Master

		v(0) = 8;
		v(1) = 7;
		v(2) = 6;
		v(3) = 5;
		v(4) = 4;
		v(5) = 3;
		v(6) = 2;
		v(7) = 1;
		v(8) = 0;
	}

	v.scatter();
	v2.scatter();
	v3.scatter();

	if (vcl.getProcessUnitID() == 0)
	{
		BOOST_REQUIRE_EQUAL(v(0),8);
		BOOST_REQUIRE_EQUAL(v(1),7);
		BOOST_REQUIRE_EQUAL(v(2),6);

		BOOST_REQUIRE_EQUAL(v2(0),0);
		BOOST_REQUIRE_EQUAL(v2(1),1);
		BOOST_REQUIRE_EQUAL(v2(2),2);

		BOOST_REQUIRE_EQUAL(v3(0),0);
		BOOST_REQUIRE_EQUAL(v3(1),1);
		BOOST_REQUIRE_EQUAL(v3(2),2);
	}
	else if (vcl.getProcessUnitID() == 1)
	{
		BOOST_REQUIRE_EQUAL(v(3),5);
		BOOST_REQUIRE_EQUAL(v(4),4);
		BOOST_REQUIRE_EQUAL(v(5),3);

		BOOST_REQUIRE_EQUAL(v2(3),3);
		BOOST_REQUIRE_EQUAL(v2(4),4);
		BOOST_REQUIRE_EQUAL(v2(5),5);

		BOOST_REQUIRE_EQUAL(v3(0),3);
		BOOST_REQUIRE_EQUAL(v3(1),4);
		BOOST_REQUIRE_EQUAL(v3(2),5);
	}
	else if (vcl.getProcessUnitID() == 2)
	{
		BOOST_REQUIRE_EQUAL(v(6),2);
		BOOST_REQUIRE_EQUAL(v(7),1);
		BOOST_REQUIRE_EQUAL(v(8),0);

		BOOST_REQUIRE_EQUAL(v2(6),6);
		BOOST_REQUIRE_EQUAL(v2(7),7);
		BOOST_REQUIRE_EQUAL(v2(8),8);

		BOOST_REQUIRE_EQUAL(v3(0),6);
		BOOST_REQUIRE_EQUAL(v3(1),7);
		BOOST_REQUIRE_EQUAL(v3(2),8);
	}
}


BOOST_AUTO_TEST_SUITE_END()


#endif /* OPENFPM_NUMERICS_SRC_VECTOR_VECTOR_UNIT_TESTS_HPP_ */