Commit be8c849c authored by Pietro Incardona's avatar Pietro Incardona
Browse files

Semantic gather

parent c8ddf7f3
...@@ -7,6 +7,16 @@ ...@@ -7,6 +7,16 @@
* Author: Pietro Incardona * Author: Pietro Incardona
*/ */
/*! \brief Reset the receive buffer
*
*
*/
void reset_recv_buf()
{
for (size_t i = 0 ; i < recv_buf.size() ; i++)
recv_buf.get(i).resize(0);
}
/*! \brief Call-back to allocate buffer to receive data /*! \brief Call-back to allocate buffer to receive data
* *
* \param msg_i size required to receive the message from i * \param msg_i size required to receive the message from i
...@@ -27,10 +37,9 @@ static void * msg_alloc(size_t msg_i ,size_t total_msg, size_t total_p, size_t i ...@@ -27,10 +37,9 @@ static void * msg_alloc(size_t msg_i ,size_t total_msg, size_t total_p, size_t i
if (recv_buf == NULL) if (recv_buf == NULL)
std::cerr << __FILE__ << ":" << __LINE__ << " Internal error this processor is not suppose to receive\n"; std::cerr << __FILE__ << ":" << __LINE__ << " Internal error this processor is not suppose to receive\n";
// We need one more slot recv_buf->resize(ri+1);
recv_buf->add();
recv_buf->last().resize(msg_i); recv_buf->get(ri).resize(msg_i);
// return the pointer // return the pointer
return recv_buf->last().getPointer(); return recv_buf->last().getPointer();
...@@ -62,6 +71,9 @@ static void * msg_alloc(size_t msg_i ,size_t total_msg, size_t total_p, size_t i ...@@ -62,6 +71,9 @@ static void * msg_alloc(size_t msg_i ,size_t total_msg, size_t total_p, size_t i
*/ */
template<typename T, typename S> bool SGather(T & send, S & recv,size_t root) template<typename T, typename S> bool SGather(T & send, S & recv,size_t root)
{ {
// Reset the receive buffer
reset_recv_buf();
// If we are on master collect the information // If we are on master collect the information
if (getProcessUnitID() == root) if (getProcessUnitID() == root)
{ {
...@@ -92,13 +104,15 @@ template<typename T, typename S> bool SGather(T & send, S & recv,size_t root) ...@@ -92,13 +104,15 @@ template<typename T, typename S> bool SGather(T & send, S & recv,size_t root)
// Merge the information // Merge the information
recv.add(v2); recv.add(v2);
} }
recv.add(send);
} }
else else
{ {
// send buffer (master does not send anything) so send req and send_buf // send buffer (master does not send anything) so send req and send_buf
// remain buffer with size 0 // remain buffer with size 0
openfpm::vector<size_t> send_prc; openfpm::vector<size_t> send_prc;
send_prc.add(0); send_prc.add(root);
openfpm::vector<void *> send_buf; openfpm::vector<void *> send_buf;
send_buf.add(send.getPointer()); send_buf.add(send.getPointer());
openfpm::vector<size_t> sz; openfpm::vector<size_t> sz;
......
...@@ -20,78 +20,146 @@ BOOST_AUTO_TEST_SUITE( VCluster_semantic_test ) ...@@ -20,78 +20,146 @@ BOOST_AUTO_TEST_SUITE( VCluster_semantic_test )
BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather) BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather)
{ {
Vcluster & vcl = *global_v_cluster; {
Vcluster & vcl = *global_v_cluster;
if (vcl.getProcessingUnits() >= 32)
return;
if (vcl.getProcessingUnits() >= 32) //! [Gather the data on master]
return;
//! [Gather the data on master] openfpm::vector<size_t> v1;
v1.resize(vcl.getProcessUnitID());
openfpm::vector<size_t> v1; for(size_t i = 0 ; i < vcl.getProcessUnitID() ; i++)
v1.resize(vcl.getProcessUnitID()); v1.get(i) = 5;
for(size_t i = 0 ; i < vcl.getProcessUnitID() ; i++) openfpm::vector<size_t> v2;
v1.get(i) = 5;
openfpm::vector<size_t> v2; vcl.SGather(v1,v2,0);
vcl.SGather(v1,v2,0); //! [Gather the data on master]
if (vcl.getProcessUnitID() == 0)
{
size_t n = vcl.getProcessingUnits();
BOOST_REQUIRE_EQUAL(v2.size(),n*(n-1)/2);
//! [Gather the data on master] bool is_five = true;
for (size_t i = 0 ; i < v2.size() ; i++)
is_five &= (v2.get(i) == 5);
if (vcl.getProcessUnitID() == 0) BOOST_REQUIRE_EQUAL(is_five,true);
}
}
{ {
size_t n = vcl.getProcessingUnits(); Vcluster & vcl = *global_v_cluster;
BOOST_REQUIRE_EQUAL(v2.size(),n*(n-1)/2);
if (vcl.getProcessingUnits() >= 32)
return;
bool is_five = true; openfpm::vector<size_t> v1;
for (size_t i = 0 ; i < v2.size() ; i++) v1.resize(vcl.getProcessUnitID());
is_five &= (v2.get(i) == 5);
BOOST_REQUIRE_EQUAL(is_five,true); for(size_t i = 0 ; i < vcl.getProcessUnitID() ; i++)
v1.get(i) = 5;
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*(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_struct_gather) BOOST_AUTO_TEST_CASE (Vcluster_semantic_struct_gather)
{ {
Vcluster & vcl = *global_v_cluster; {
Vcluster & vcl = *global_v_cluster;
if (vcl.getProcessingUnits() >= 32) if (vcl.getProcessingUnits() >= 32)
return; return;
//! [Gather the data on master complex] //! [Gather the data on master complex]
openfpm::vector<A> v1; openfpm::vector<A> v1;
v1.resize(vcl.getProcessUnitID()); v1.resize(vcl.getProcessUnitID());
for(size_t i = 0 ; i < vcl.getProcessUnitID() ; i++) for(size_t i = 0 ; i < vcl.getProcessUnitID() ; i++)
{ {
v1.get(i).a = 5; v1.get(i).a = 5;
v1.get(i).b = 10.0; v1.get(i).b = 10.0;
v1.get(i).c = 11.0; v1.get(i).c = 11.0;
} }
openfpm::vector<A> v2; openfpm::vector<A> v2;
vcl.SGather(v1,v2,0); vcl.SGather(v1,v2,0);
//! [Gather the data on master complex] //! [Gather the data on master complex]
if (vcl.getProcessUnitID() == 0) if (vcl.getProcessUnitID() == 0)
{
size_t n = vcl.getProcessingUnits();
BOOST_REQUIRE_EQUAL(v2.size(),n*(n-1)/2);
bool is_correct = true;
for (size_t i = 0 ; i < v2.size() ; i++)
{
is_correct &= (v2.get(i).a == 5);
is_correct &= (v2.get(i).b == 10.0);
is_correct &= (v2.get(i).c == 11.0);
}
BOOST_REQUIRE_EQUAL(is_correct,true);
}
}
{ {
size_t n = vcl.getProcessingUnits(); Vcluster & vcl = *global_v_cluster;
BOOST_REQUIRE_EQUAL(v2.size(),n*(n-1)/2);
if (vcl.getProcessingUnits() >= 32)
return;
bool is_correct = true; openfpm::vector<A> v1;
for (size_t i = 0 ; i < v2.size() ; i++) v1.resize(vcl.getProcessUnitID());
for(size_t i = 0 ; i < vcl.getProcessUnitID() ; i++)
{ {
is_correct &= (v2.get(i).a == 5); v1.get(i).a = 5;
is_correct &= (v2.get(i).b == 10.0); v1.get(i).b = 10.0;
is_correct &= (v2.get(i).c == 11.0); v1.get(i).c = 11.0;
} }
BOOST_REQUIRE_EQUAL(is_correct,true); openfpm::vector<A> v2;
vcl.SGather(v1,v2,1);
if (vcl.getProcessUnitID() == 1)
{
size_t n = vcl.getProcessingUnits();
BOOST_REQUIRE_EQUAL(v2.size(),n*(n-1)/2);
bool is_correct = true;
for (size_t i = 0 ; i < v2.size() ; i++)
{
is_correct &= (v2.get(i).a == 5);
is_correct &= (v2.get(i).b == 10.0);
is_correct &= (v2.get(i).c == 11.0);
}
BOOST_REQUIRE_EQUAL(is_correct,true);
}
} }
} }
......
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