Commit b929b2a7 authored by Yaroslav's avatar Yaroslav

SGather and SSendRecv with packer are done, but SSendRecv still needs new tests

parent 7ee3820b
......@@ -54,6 +54,15 @@ private:
{
for (size_t i = 0 ; i < recv_buf.size() ; i++)
{
/*ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(recv_buf.get(i).size(),recv_buf.get(i)));
mem.incRef();
Unpack_stat ps;
size_t n_ele = 0;
Unpacker<size_t, HeapMemory>::unpack(mem,n_ele,ps);*/
// calculate the number of received elements
size_t n_ele = recv_buf.get(i).size() / sizeof(typename T::value_type);
......@@ -113,18 +122,39 @@ private:
static void packingRequest(T & send, size_t & tot_size, openfpm::vector<size_t> & sz)
{
typedef typename ::generate_indexes<int, has_max_prop<T, has_value_type<T>::value>::number, MetaFuncOrd>::result ind_prop_to_pack;
call_serialize_variadic<ind_prop_to_pack>::call_pr(send,tot_size);
if (has_pack<typename T::value_type>::type::value == false && is_vector<T>::value == true)
{
sz.add(send.size()*sizeof(typename T::value_type));
}
else
{
call_serialize_variadic<ind_prop_to_pack>::call_pr(send,tot_size);
#ifdef DEBUG
std::cout << "Tot_size: " << tot_size << std::endl;
std::cout << "Tot_size: " << tot_size << std::endl;
#endif
sz.add(tot_size);
sz.add(tot_size);
}
}
static void packing(ExtPreAlloc<HeapMemory> & mem, T & send, Pack_stat & sts, openfpm::vector<const void *> & send_buf)
{
typedef typename ::generate_indexes<int, has_max_prop<T, has_value_type<T>::value>::number, MetaFuncOrd>::result ind_prop_to_pack;
call_serialize_variadic<ind_prop_to_pack>::call_pack(mem,send,sts);
send_buf.add(mem.getPointerBase());
if (has_pack<typename T::value_type>::type::value == false && is_vector<T>::value == true)
{
#ifdef DEBUG
std::cout << "Inside SGather pack (has prp) (vector case) " << std::endl;
#endif
send_buf.add(send.getPointer());
}
else
{
#ifdef DEBUG
std::cout << "Inside SGather pack (has prp) (general case) " << std::endl;
#endif
call_serialize_variadic<ind_prop_to_pack>::call_pack(mem,send,sts);
send_buf.add(mem.getPointerBase());
}
}
static void unpacking(S & recv, openfpm::vector<BHeapMemory> & recv_buf, openfpm::vector<size_t> * sz = NULL)
......@@ -141,12 +171,17 @@ private:
{
static void packingRequest(T & send, size_t & tot_size, openfpm::vector<size_t> & sz)
{
if (has_pack<typename T::value_type>::type::value == true)
if (has_pack<typename T::value_type>::type::value == false && is_vector<T>::value == true)
{
#ifdef DEBUG
std::cout << "Inside SGather pack request (no prp) " << std::endl;
std::cout << "Inside SGather pack request (no prp) (vector case) " << std::endl;
#endif
sz.add(send.size()*sizeof(typename T::value_type));
}
else
{
Packer<T,HeapMemory>::packRequest(send,tot_size);
#ifdef DEBUG
......@@ -154,30 +189,26 @@ private:
#endif
sz.add(tot_size);
}
else
{
sz.add(send.size()*sizeof(typename T::value_type));
}
}
static void packing(ExtPreAlloc<HeapMemory> & mem, T & send, Pack_stat & sts, openfpm::vector<const void *> & send_buf)
{
if (has_pack<typename T::value_type>::type::value == false && is_vector<T>::value == true)
{
#ifdef DEBUG
std::cout << "Inside SGather pack (no prp) " << std::endl;
std::cout << "Inside SGather pack (no prp) (vector case)" << std::endl;
#endif
if (has_pack<typename T::value_type>::type::value == true)
{
Packer<T,HeapMemory>::pack(mem,send,sts);
send_buf.add(mem.getPointerBase());
send_buf.add(send.getPointer());
}
else
{
#ifdef DEBUG
std::cout << "Inside SGather pack (no prp) (no pack inside) " << std::endl;
std::cout << "Inside SGather pack (no prp) (genaral case) " << std::endl;
#endif
send_buf.add(send.getPointer());
Packer<T,HeapMemory>::pack(mem,send,sts);
send_buf.add(mem.getPointerBase());
}
}
......@@ -381,11 +412,13 @@ template<typename T, typename S> bool SGather(T & send, S & recv, openfpm::vecto
openfpm::vector<size_t> send_prc;
send_prc.add(root);
size_t tot_size = 0;
openfpm::vector<size_t> sz;
openfpm::vector<const void *> send_buf;
//Pack requesting
openfpm::vector<size_t> sz;
size_t tot_size = 0;
pack_unpack_cond<has_max_prop<T, has_value_type<T>::value>::value, T, S>::packingRequest(send, tot_size, sz);
......@@ -397,7 +430,6 @@ template<typename T, typename S> bool SGather(T & send, S & recv, openfpm::vecto
//Packing
Pack_stat sts;
openfpm::vector<const void *> send_buf;
pack_unpack_cond<has_max_prop<T, has_value_type<T>::value>::value, T, S>::packing(mem, send, sts, send_buf);
......@@ -530,12 +562,26 @@ template<typename T, typename S> bool SSendRecv(openfpm::vector<T> & send, S & r
openfpm::vector<const void *> send_buf;
openfpm::vector<size_t> sz_byte;
sz_byte.resize(send.size());
for (size_t i = 0; i < send.size() ; i++)
{
send_buf.add((char *)send.get(i).getPointer());
sz_byte.get(i) = send.get(i).size() * sizeof(typename T::value_type);
size_t tot_size = 0;
//Pack requesting
pack_unpack_cond<has_max_prop<T, has_value_type<T>::value>::value, T, S>::packingRequest(send.get(i), tot_size, sz_byte);
HeapMemory pmem;
ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(tot_size,pmem));
mem.incRef();
//Packing
Pack_stat sts;
pack_unpack_cond<has_max_prop<T, has_value_type<T>::value>::value, T, S>::packing(mem, send.get(i), sts, send_buf);
}
// receive information
......
......@@ -74,12 +74,12 @@ BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather_2)
openfpm::vector<openfpm::vector<size_t>> v2;
vcl.SGather(v1,v2,1);
vcl.SGather(v1,v2,0);
if (vcl.getProcessUnitID() == 1)
if (vcl.getProcessUnitID() == 0)
{
size_t n = vcl.getProcessingUnits();
BOOST_REQUIRE_EQUAL(v2.size(),n-1);
BOOST_REQUIRE_EQUAL(v2.size(),n);
bool is_five = true;
for (size_t i = 0 ; i < v2.size() ; i++)
......@@ -91,18 +91,20 @@ BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather_2)
}
vcl.SGather(v1,v2,0);
openfpm::vector<openfpm::vector<size_t>> v3;
if (vcl.getProcessUnitID() == 0)
vcl.SGather(v1,v3,1);
if (vcl.getProcessUnitID() == 1)
{
size_t n = vcl.getProcessingUnits();
BOOST_REQUIRE_EQUAL(v2.size(),n);
BOOST_REQUIRE_EQUAL(v3.size(),n-1);
bool is_five = true;
for (size_t i = 0 ; i < v2.size() ; i++)
for (size_t i = 0 ; i < v3.size() ; i++)
{
for (size_t j = 0 ; j < v2.get(i).size() ; j++)
is_five &= (v2.get(i).get(j) == 5);
for (size_t j = 0 ; j < v3.get(i).size() ; j++)
is_five &= (v3.get(i).get(j) == 5);
}
BOOST_REQUIRE_EQUAL(is_five,true);
......@@ -120,6 +122,7 @@ BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather_3)
return;
openfpm::vector<openfpm::vector<aggregate<float, openfpm::vector<size_t>, Point_test<float>>> > v1;
openfpm::vector<aggregate<float, openfpm::vector<size_t>, Point_test<float>>> v1_int;
aggregate<float, openfpm::vector<size_t>, Point_test<float>> aggr;
openfpm::vector<size_t> v1_int2;
......@@ -203,11 +206,11 @@ BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather_4)
openfpm::vector<grid_cpu<2,Point_test<float>>> v2;
vcl.SGather(g1,v2,1);
vcl.SGather(g1,v2,0);
typedef Point_test<float> p;
if (vcl.getProcessUnitID() == 1)
if (vcl.getProcessUnitID() == 0)
{
size_t n = vcl.getProcessingUnits();
BOOST_REQUIRE_EQUAL(v2.size(),n);
......@@ -362,8 +365,116 @@ BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather_6)
}
BOOST_REQUIRE_EQUAL(is_seven,true);
}
if (vcl.getProcessUnitID() == 0 && i == 99)
std::cout << "Semantic gather test stop" << std::endl;
}
}
BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather_7)
{
for (size_t i = 0 ; i < 100 ; i++)
{
Vcluster & vcl = create_vcluster();
if (vcl.getProcessingUnits() >= 32)
return;
openfpm::vector<Point_test<float>> v1;
Point_test<float> p1;
p1.fill();
v1.resize(vcl.getProcessUnitID());
for(size_t i = 0 ; i < vcl.getProcessUnitID() ; i++)
v1.get(i) = p1;
openfpm::vector<openfpm::vector<Point_test<float>>> v2;
vcl.SGather(v1,v2,0);
typedef Point_test<float> p;
if (vcl.getProcessUnitID() == 0)
{
size_t n = vcl.getProcessingUnits();
BOOST_REQUIRE_EQUAL(v2.size(),n);
bool match = true;
for (size_t i = 0 ; i < v2.size() ; i++)
{
for (size_t j = 0 ; j < v2.get(i).size() ; j++)
{
Point_test<float> p2 = v2.get(i).get(j);
//BOOST_REQUIRE(p2 == p1);
match &= (p2.template get<p::x>() == p1.template get<p::x>());
match &= (p2.template get<p::y>() == p1.template get<p::y>());
match &= (p2.template get<p::z>() == p1.template get<p::z>());
match &= (p2.template get<p::s>() == p1.template get<p::s>());
match &= (p2.template get<p::v>()[0] == p1.template get<p::v>()[0]);
match &= (p2.template get<p::v>()[1] == p1.template get<p::v>()[1]);
match &= (p2.template get<p::v>()[2] == p1.template get<p::v>()[2]);
match &= (p2.template get<p::t>()[0][0] == p1.template get<p::t>()[0][0]);
match &= (p2.template get<p::t>()[0][1] == p1.template get<p::t>()[0][1]);
match &= (p2.template get<p::t>()[0][2] == p1.template get<p::t>()[0][2]);
match &= (p2.template get<p::t>()[1][0] == p1.template get<p::t>()[1][0]);
match &= (p2.template get<p::t>()[1][1] == p1.template get<p::t>()[1][1]);
match &= (p2.template get<p::t>()[1][2] == p1.template get<p::t>()[1][2]);
match &= (p2.template get<p::t>()[2][0] == p1.template get<p::t>()[2][0]);
match &= (p2.template get<p::t>()[2][1] == p1.template get<p::t>()[2][1]);
match &= (p2.template get<p::t>()[2][2] == p1.template get<p::t>()[2][2]);
}
}
BOOST_REQUIRE_EQUAL(match,true);
}
}
}
BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather_8)
{
for (size_t i = 0 ; i < 100 ; i++)
{
Vcluster & vcl = create_vcluster();
if (vcl.getProcessingUnits() >= 32)
return;
openfpm::vector<Box<3,size_t>> v1;
Box<3,size_t> bx;
bx.setLow(0, 1);
bx.setLow(1, 2);
bx.setLow(2, 3);
bx.setHigh(0, 4);
bx.setHigh(1, 5);
bx.setHigh(2, 6);
v1.resize(vcl.getProcessUnitID());
for(size_t i = 0 ; i < vcl.getProcessUnitID() ; i++)
v1.get(i) = bx;
openfpm::vector<openfpm::vector<Box<3,size_t>>> v2;
vcl.SGather(v1,v2,0);
if (vcl.getProcessUnitID() == 0)
{
size_t n = vcl.getProcessingUnits();
BOOST_REQUIRE_EQUAL(v2.size(),n);
for (size_t i = 0 ; i < v2.size() ; i++)
{
for (size_t j = 0 ; j < v2.get(i).size() ; j++)
{
Box<3,size_t> b2 = v2.get(i).get(j);
BOOST_REQUIRE(bx == b2);
}
}
}
}
}
......@@ -405,6 +516,8 @@ BOOST_AUTO_TEST_CASE (Vcluster_semantic_struct_gather)
BOOST_REQUIRE_EQUAL(is_correct,true);
}
if (vcl.getProcessUnitID() == 0 && i == 99)
std::cout << "Semantic gather test stop" << std::endl;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment