Commit 6c900534 authored by Yaroslav's avatar Yaroslav
Browse files

SGather done but with 1 bug

parent e4065cc7
......@@ -17,14 +17,16 @@ private:
{
template<int ... prp> static void call_unpack(S & recv, openfpm::vector<BHeapMemory> & recv_buf, openfpm::vector<size_t> * sz = NULL)
{
#ifdef DEBUG
std::cout << "Sz.size(): " << sz->size() << std::endl;
std::cout << "Unp: " << demangle(typeid(T).name()) << std::endl;
#endif
for (size_t i = 0 ; i < recv_buf.size() ; i++)
{
#ifdef DEBUG
std::cout << "Recv_buf.get(i).size(): " << recv_buf.get(i).size() << std::endl;
#endif
T unp;
ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(recv_buf.get(i).size(),recv_buf.get(i)));
mem.incRef();
......@@ -32,11 +34,13 @@ private:
Unpacker<T,HeapMemory>::template unpack<prp...>(mem, unp, ps);
size_t recv_size_old = recv.size();
// Merge the information
recv.add(unp);
size_t recv_size_new = recv.size();
/*if (sz != NULL)
sz->get(i) = unp.size();*/
if (sz != NULL)
sz->get(i) = recv_size_new - recv_size_old;
}
}
};
......@@ -95,8 +99,7 @@ private:
template<typename T, typename S> inline static void call_unpack(S & recv, openfpm::vector<BHeapMemory> & recv_buf, openfpm::vector<size_t> * sz = NULL)
{
const bool result = has_pack_agg<typename T::value_type, prp...>::result::value == false && is_vector<T>::value == true;
const bool result = has_pack<typename T::value_type>::type::value == false && is_vector<T>::value == true;
unpack_selector<result, T, S>::template call_unpack<prp...>(recv, recv_buf, sz);
}
};
......@@ -110,16 +113,16 @@ 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;
// Packer<T,HeapMemory>::packRequest< prop_to_pack::data >(send,tot_size);
call_serialize_variadic<ind_prop_to_pack>::call_pr(send,tot_size);
#ifdef DEBUG
std::cout << "Tot_size: " << tot_size << std::endl;
#endif
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;
//Packer<T,HeapMemory>::pack< prop_to_pack::data >(mem,send,sts);
call_serialize_variadic<ind_prop_to_pack>::call_pack(mem,send,sts);
send_buf.add(mem.getPointerBase());
}
......@@ -140,10 +143,15 @@ private:
{
if (has_pack<typename T::value_type>::type::value == true)
{
//tot_size = send.size()*sizeof(typename T::value_type);
#ifdef DEBUG
std::cout << "Inside SGather pack request (no prp) " << std::endl;
Packer<T,HeapMemory>::packRequest(send,tot_size);
#endif
Packer<T,HeapMemory>::packRequest(send,tot_size);
#ifdef DEBUG
std::cout << "Tot_size: " << tot_size << std::endl;
#endif
sz.add(tot_size);
}
......@@ -155,70 +163,33 @@ private:
static void packing(ExtPreAlloc<HeapMemory> & mem, T & send, Pack_stat & sts, openfpm::vector<const void *> & send_buf)
{
#ifdef DEBUG
std::cout << "Inside SGather pack (no prp) " << std::endl;
#endif
if (has_pack<typename T::value_type>::type::value == true)
{
Packer<T,HeapMemory>::pack(mem,send,sts);
send_buf.add(mem.getPointer());
send_buf.add(mem.getPointerBase());
}
else
{
#ifdef DEBUG
std::cout << "Inside SGather pack (no prp) (no pack inside) " << std::endl;
#endif
send_buf.add(send.getPointer());
}
}
static void unpacking(S & recv, openfpm::vector<BHeapMemory> & recv_buf, openfpm::vector<size_t> * sz = NULL)
{
#ifdef DEBUG
std::cout << "Inside SGather unpack (no prp) " << std::endl;
if (has_pack<typename T::value_type>::type::value == true)
{
for (size_t i = 0 ; i < recv_buf.size() ; i++)
{
T unp;
ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(recv_buf.get(i).size(),recv_buf.get(i)));
mem.incRef();
Unpack_stat ps;
Unpacker<T,HeapMemory>::unpack(mem, unp, ps);
// Merge the information
recv.add(unp);
}
}
else
{
std::cout << "Inside SGather unpack (no prp) (no pack inside) " << std::endl;
for (size_t i = 0 ; i < recv_buf.size() ; i++)
{
//std::cout << "I: " << i << ", Rec_buf.get(i).size(): " << recv_buf.get(i).size() << std::endl;
// calculate the number of received elements
size_t n_ele = recv_buf.get(i).size() / sizeof(typename T::value_type);
// add the received particles to the vector
PtrMemory * ptr1 = new PtrMemory(recv_buf.get(i).getPointer(),recv_buf.get(i).size());
// create vector representation to a piece of memory already allocated
openfpm::vector<typename T::value_type,PtrMemory,typename memory_traits_lin<typename T::value_type>::type, memory_traits_lin,openfpm::grow_policy_identity> v2;
v2.setMemory(*ptr1);
#endif
// resize with the number of elements
v2.resize(n_ele);
// Merge the information
recv.add(v2);
if (sz != NULL)
sz->get(i) = v2.size();
}
}
const bool result = has_pack<typename T::value_type>::type::value == false && is_vector<T>::value == true;
unpack_selector<result, T, S>::template call_unpack<>(recv, recv_buf, sz);
}
};
......@@ -277,8 +248,6 @@ static void * msg_alloc(size_t msg_i ,size_t total_msg, size_t total_p, size_t i
rinfo.recv_buf->resize(ri+1);
rinfo.recv_buf->get(ri).resize(msg_i);
std::cout << "Recv_but.get(ri).size(): " << rinfo.recv_buf->get(ri).size() << std::endl;
// Receive info
rinfo.prc.add(i);
......@@ -382,7 +351,9 @@ template<typename T, typename S> bool SGather(T & send, S & recv, openfpm::vecto
// If we are on master collect the information
if (getProcessUnitID() == root)
{
#ifdef DEBUG
std::cout << "Inside root " << root << std::endl;
#endif
// send buffer (master does not send anything) so send req and send_buf
// remain buffer with size 0
openfpm::vector<size_t> send_req;
......@@ -402,7 +373,9 @@ template<typename T, typename S> bool SGather(T & send, S & recv, openfpm::vecto
}
else
{
std::cout << "Inside slave " << std::endl;
#ifdef DEBUG
std::cout << "Inside slave " << getProcessUnitID() << std::endl;
#endif
// send buffer (master does not send anything) so send req and send_buf
// remain buffer with size 0
openfpm::vector<size_t> send_prc;
......
......@@ -9,6 +9,7 @@
#define OPENFPM_VCLUSTER_SRC_VCLUSTER_SEMANTIC_UNIT_TESTS_HPP_
#include "Grid/grid_util_test.hpp"
#include "data_type/aggregate.hpp"
struct Aexample
{
......@@ -26,6 +27,9 @@ BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather)
{
Vcluster & vcl = create_vcluster();
if (vcl.getProcessUnitID() == 0 && i == 0)
std::cout << "Semantic gather test start" << std::endl;
if (vcl.getProcessingUnits() >= 32)
return;
......@@ -53,6 +57,315 @@ BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather)
}
}
BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather_2)
{
for (size_t i = 0 ; i < 100 ; i++)
{
Vcluster & vcl = create_vcluster();
if (vcl.getProcessingUnits() >= 32)
return;
openfpm::vector<size_t> v1;
v1.resize(vcl.getProcessUnitID());
for(size_t i = 0 ; i < vcl.getProcessUnitID() ; i++)
v1.get(i) = 5;
openfpm::vector<openfpm::vector<size_t>> v2;
vcl.SGather(v1,v2,1);
if (vcl.getProcessUnitID() == 1)
{
size_t n = vcl.getProcessingUnits();
BOOST_REQUIRE_EQUAL(v2.size(),n-1);
bool is_five = true;
for (size_t i = 0 ; i < v2.size() ; i++)
{
for (size_t j = 0 ; j < v2.get(i).size() ; j++)
is_five &= (v2.get(i).get(j) == 5);
}
BOOST_REQUIRE_EQUAL(is_five,true);
}
vcl.SGather(v1,v2,0);
if (vcl.getProcessUnitID() == 0)
{
size_t n = vcl.getProcessingUnits();
BOOST_REQUIRE_EQUAL(v2.size(),n);
bool is_five = true;
for (size_t i = 0 ; i < v2.size() ; i++)
{
for (size_t j = 0 ; j < v2.get(i).size() ; j++)
is_five &= (v2.get(i).get(j) == 5);
}
BOOST_REQUIRE_EQUAL(is_five,true);
}
}
}
BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather_3)
{
for (size_t i = 0 ; i < 100 ; i++)
{
Vcluster & vcl = create_vcluster();
if (vcl.getProcessingUnits() >= 32)
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;
v1_int2.add((size_t)7);
v1_int2.add((size_t)7);
aggr.template get<0>() = 7;
aggr.template get<1>() = v1_int2;
Point_test<float> p;
p.fill();
aggr.template get<2>() = p;
v1_int.add(aggr);
v1_int.add(aggr);
v1_int.add(aggr);
v1.add(v1_int);
v1.add(v1_int);
v1.add(v1_int);
v1.add(v1_int);
openfpm::vector<openfpm::vector<aggregate<float, openfpm::vector<size_t>, Point_test<float>>> > v2;
vcl.SGather(v1,v2,0);
if (vcl.getProcessUnitID() == 0)
{
size_t n = vcl.getProcessingUnits();
BOOST_REQUIRE_EQUAL(v2.size(),v1.size()*n);
bool is_seven = true;
for (size_t i = 0 ; i < v2.size() ; i++)
{
for (size_t j = 0 ; j < v2.get(i).size() ; j++)
{
is_seven &= (v2.get(i).template get<0>(j) == 7);
for (size_t k = 0; k < v2.get(i).template get<1>(j).size(); k++)
is_seven &= (v2.get(i).template get<1>(j).get(k) == 7);
Point_test<float> p = v2.get(i).template get<2>(j);
BOOST_REQUIRE(p.template get<0>() == 1);
BOOST_REQUIRE(p.template get<1>() == 2);
BOOST_REQUIRE(p.template get<2>() == 3);
BOOST_REQUIRE(p.template get<3>() == 4);
for (size_t l = 0 ; l < 3 ; l++)
p.template get<4>()[l] = 5;
for (size_t m = 0 ; m < 3 ; m++)
{
for (size_t n = 0 ; n < 3 ; n++)
{
p.template get<5>()[m][n] = 6;
}
}
}
}
BOOST_REQUIRE_EQUAL(is_seven,true);
}
}
}
BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather_4)
{
for (size_t i = 0 ; i < 100 ; i++)
{
Vcluster & vcl = create_vcluster();
if (vcl.getProcessingUnits() >= 32)
return;
size_t sz[] = {16,16};
grid_cpu<2,Point_test<float>> g1(sz);
g1.setMemory();
fill_grid<2>(g1);
openfpm::vector<grid_cpu<2,Point_test<float>>> v2;
vcl.SGather(g1,v2,2);
typedef Point_test<float> p;
if (vcl.getProcessUnitID() == 2)
{
size_t n = vcl.getProcessingUnits();
BOOST_REQUIRE_EQUAL(v2.size(),n);
bool match = true;
for (size_t i = 0 ; i < v2.size() ; i++)
{
auto it = v2.get(i).getIterator();
while (it.isNext())
{
grid_key_dx<2> key = it.get();
match &= (v2.get(i).template get<p::x>(key) == g1.template get<p::x>(key));
match &= (v2.get(i).template get<p::y>(key) == g1.template get<p::y>(key));
match &= (v2.get(i).template get<p::z>(key) == g1.template get<p::z>(key));
match &= (v2.get(i).template get<p::s>(key) == g1.template get<p::s>(key));
match &= (v2.get(i).template get<p::v>(key)[0] == g1.template get<p::v>(key)[0]);
match &= (v2.get(i).template get<p::v>(key)[1] == g1.template get<p::v>(key)[1]);
match &= (v2.get(i).template get<p::v>(key)[2] == g1.template get<p::v>(key)[2]);
match &= (v2.get(i).template get<p::t>(key)[0][0] == g1.template get<p::t>(key)[0][0]);
match &= (v2.get(i).template get<p::t>(key)[0][1] == g1.template get<p::t>(key)[0][1]);
match &= (v2.get(i).template get<p::t>(key)[0][2] == g1.template get<p::t>(key)[0][2]);
match &= (v2.get(i).template get<p::t>(key)[1][0] == g1.template get<p::t>(key)[1][0]);
match &= (v2.get(i).template get<p::t>(key)[1][1] == g1.template get<p::t>(key)[1][1]);
match &= (v2.get(i).template get<p::t>(key)[1][2] == g1.template get<p::t>(key)[1][2]);
match &= (v2.get(i).template get<p::t>(key)[2][0] == g1.template get<p::t>(key)[2][0]);
match &= (v2.get(i).template get<p::t>(key)[2][1] == g1.template get<p::t>(key)[2][1]);
match &= (v2.get(i).template get<p::t>(key)[2][2] == g1.template get<p::t>(key)[2][2]);
++it;
}
}
BOOST_REQUIRE_EQUAL(match,true);
}
}
}
BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather_5)
{
for (size_t i = 0 ; i < 100 ; i++)
{
Vcluster & vcl = create_vcluster();
if (vcl.getProcessingUnits() >= 32)
return;
size_t sz[] = {16,16};
grid_cpu<2,Point_test<float>> g1(sz);
g1.setMemory();
fill_grid<2>(g1);
openfpm::vector<grid_cpu<2,Point_test<float>>> v1;
v1.add(g1);
v1.add(g1);
v1.add(g1);
openfpm::vector<grid_cpu<2,Point_test<float>>> v2;
vcl.SGather(v1,v2,1);
typedef Point_test<float> p;
if (vcl.getProcessUnitID() == 1)
{
size_t n = vcl.getProcessingUnits();
BOOST_REQUIRE_EQUAL(v2.size(),v1.size()*n);
bool match = true;
for (size_t i = 0 ; i < v2.size() ; i++)
{
auto it = v2.get(i).getIterator();
while (it.isNext())
{
grid_key_dx<2> key = it.get();
match &= (v2.get(i).template get<p::x>(key) == g1.template get<p::x>(key));
match &= (v2.get(i).template get<p::y>(key) == g1.template get<p::y>(key));
match &= (v2.get(i).template get<p::z>(key) == g1.template get<p::z>(key));
match &= (v2.get(i).template get<p::s>(key) == g1.template get<p::s>(key));
match &= (v2.get(i).template get<p::v>(key)[0] == g1.template get<p::v>(key)[0]);
match &= (v2.get(i).template get<p::v>(key)[1] == g1.template get<p::v>(key)[1]);
match &= (v2.get(i).template get<p::v>(key)[2] == g1.template get<p::v>(key)[2]);
match &= (v2.get(i).template get<p::t>(key)[0][0] == g1.template get<p::t>(key)[0][0]);
match &= (v2.get(i).template get<p::t>(key)[0][1] == g1.template get<p::t>(key)[0][1]);
match &= (v2.get(i).template get<p::t>(key)[0][2] == g1.template get<p::t>(key)[0][2]);
match &= (v2.get(i).template get<p::t>(key)[1][0] == g1.template get<p::t>(key)[1][0]);
match &= (v2.get(i).template get<p::t>(key)[1][1] == g1.template get<p::t>(key)[1][1]);
match &= (v2.get(i).template get<p::t>(key)[1][2] == g1.template get<p::t>(key)[1][2]);
match &= (v2.get(i).template get<p::t>(key)[2][0] == g1.template get<p::t>(key)[2][0]);
match &= (v2.get(i).template get<p::t>(key)[2][1] == g1.template get<p::t>(key)[2][1]);
match &= (v2.get(i).template get<p::t>(key)[2][2] == g1.template get<p::t>(key)[2][2]);
++it;
}
}
BOOST_REQUIRE_EQUAL(match,true);
}
}
}
BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather_6)
{
for (size_t i = 0 ; i < 100 ; i++)
{
Vcluster & vcl = create_vcluster();
if (vcl.getProcessingUnits() >= 32)
return;
openfpm::vector<openfpm::vector<openfpm::vector<size_t>>> v1;
openfpm::vector<openfpm::vector<size_t>> v1_int;
openfpm::vector<size_t> v1_int2;
v1_int2.add((size_t)7);
v1_int2.add((size_t)7);
v1_int.add(v1_int2);
v1_int.add(v1_int2);
v1_int.add(v1_int2);
v1.add(v1_int);
v1.add(v1_int);
v1.add(v1_int);
v1.add(v1_int);
openfpm::vector<openfpm::vector<openfpm::vector<size_t>>> v2;
vcl.SGather(v1,v2,0);
if (vcl.getProcessUnitID() == 0)
{
size_t n = vcl.getProcessingUnits();
BOOST_REQUIRE_EQUAL(v2.size(),v1.size()*n);
bool is_seven = true;
for (size_t i = 0 ; i < v2.size() ; i++)
{
for (size_t j = 0 ; j < v2.get(i).size() ; j++)
{
for (size_t k = 0 ; k < v2.get(i).get(j).size() ; k++)
is_seven &= (v2.get(i).get(j).get(k) == 7);
}
}
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_struct_gather)
{
......@@ -359,185 +672,6 @@ BOOST_AUTO_TEST_CASE (Vcluster_semantic_struct_sendrecv)
}
}
BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather_2)
{
Vcluster & vcl = create_vcluster();
if (vcl.getProcessingUnits() >= 32)
return;
openfpm::vector<size_t> v1;
v1.resize(vcl.getProcessUnitID());
for(size_t i = 0 ; i < vcl.getProcessUnitID() ; i++)
v1.get(i) = 5;
openfpm::vector<size_t> v2;
vcl.SGather(v1,v2,0);
if (vcl.getProcessUnitID() == 0)
{
size_t n = vcl.getProcessingUnits();
BOOST_REQUIRE_EQUAL(v2.size(),n*(n-1)/2);
bool is_five = true;
for (size_t i = 0 ; i < v2.size() ; i++)
is_five &= (v2.get(i) == 5);
BOOST_REQUIRE_EQUAL(is_five,true);
}
}
BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather_3)
{
Vcluster & vcl = create_vcluster();
if (vcl.getProcessingUnits() >= 32)
return;
openfpm::vector<size_t> v1;
v1.resize(vcl.getProcessUnitID());
for(size_t i = 0 ; i < vcl.getProcessUnitID() ; i++)
v1.get(i) = 5;
openfpm::vector<openfpm::vector<size_t>> v2;
vcl.SGather(v1,v2,1);
if (vcl.getProcessUnitID() == 1)
{
size_t n = vcl.getProcessingUnits();
BOOST_REQUIRE_EQUAL(v2.size(),n-1);
bool is_five = true;
for (size_t i = 0 ; i < v2.size() ; i++)
{
for (size_t j = 0 ; j < v2.get(i).size() ; j++)
is_five &= (v2.get(i).get(j) == 5);
}
BOOST_REQUIRE_EQUAL(is_five,true);
}
vcl.SGather(v1,v2,0);
if (vcl.getProcessUnitID() == 0)
{
size_t n = vcl.getProcessingUnits();
BOOST_REQUIRE_EQUAL(v2.size(),n);
bool is_five = true;
for (size_t i = 0 ; i < v2.size() ; i++)
{
for (size_t j = 0 ; j < v2.get(i).size() ; j++)
is_five &= (v2.get(i).get(j) == 5);