Commit cfd7dc60 authored by incardon's avatar incardon

Added send recv test for all types

parent ac19a697
......@@ -11,6 +11,8 @@
#define VERBOSE_TEST
#include "VCluster.hpp"
#include "Point_test.hpp"
#include "Vector/vector_test_util.hpp"
#define NBX 1
#define PCX 2
......@@ -18,11 +20,22 @@
#define N_TRY 2
#define N_LOOP 67108864
#define BUFF_STEP 524288
#define P_STRIDE 17
bool totp_check;
size_t global_step = 0;
size_t global_rank;
/*! \brief calculate the x mob m
*
* \param x
* \param m
*
*/
int mod(int x, int m) {
return (x%m + m)%m;
}
// Alloc the buffer to receive the messages
void * msg_alloc(size_t msg_i ,size_t total_msg, size_t total_p, size_t i,size_t ri, void * ptr)
......@@ -406,6 +419,103 @@ template<unsigned int ip> void test()
}
}
/*! \brief Test vectors send for complex structures
*
* \param n test size
* \param vcl VCluster
*
*/
void test_send_recv_complex(const size_t n, Vcluster & vcl)
{
// Point test typedef
typedef Point_test<float> p;
openfpm::vector<Point_test<float>> v_send = allocate_openfpm_fill(n,vcl.getProcessUnitID());
// Send to 8 processors
for (size_t i = 0 ; i < 8 ; i++)
vcl.send( mod(vcl.getProcessUnitID() + i * P_STRIDE, vcl.getProcessingUnits()) ,i,v_send);
openfpm::vector<openfpm::vector<Point_test<float>> > pt_buf;
pt_buf.resize(8);
// Recv from 8 processors
for (size_t i = 0 ; i < 8 ; i++)
{
pt_buf.get(i).resize(n);
vcl.recv( mod( (vcl.getProcessUnitID() - i * P_STRIDE), vcl.getProcessingUnits()) ,i,pt_buf.get(i));
}
vcl.execute();
// Check the received buffers (careful at negative modulo)
for (size_t i = 0 ; i < 8 ; i++)
{
for (size_t j = 0 ; j < n ; j++)
{
Point_test<float> pt = pt_buf.get(i).get(j);
size_t p_recv = mod( (vcl.getProcessUnitID() - i * P_STRIDE), vcl.getProcessingUnits());
BOOST_REQUIRE_EQUAL(pt.template get<p::x>(),p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::y>(),p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::z>(),p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::s>(),p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::v>()[0],p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::v>()[1],p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::v>()[2],p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::t>()[0][0],p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::t>()[0][1],p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::t>()[0][2],p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::t>()[1][0],p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::t>()[1][1],p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::t>()[1][2],p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::t>()[2][0],p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::t>()[2][1],p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::t>()[2][2],p_recv);
}
}
}
/*! \brief Test vectors send for complex structures
*
* \tparam T primitives
*
* \param n size
*
*/
template<typename T> void test_send_recv_primitives(size_t n, Vcluster & vcl)
{
openfpm::vector<T> v_send = allocate_openfpm_primitive<T>(n,vcl.getProcessUnitID());
// Send to 8 processors
for (size_t i = 0 ; i < 8 ; i++)
vcl.send( mod(vcl.getProcessUnitID() + i * P_STRIDE, vcl.getProcessingUnits()) ,i,v_send);
openfpm::vector<openfpm::vector<T> > pt_buf;
pt_buf.resize(8);
// Recv from 8 processors
for (size_t i = 0 ; i < 8 ; i++)
{
pt_buf.get(i).resize(n);
vcl.recv( mod( (vcl.getProcessUnitID() - i * P_STRIDE), vcl.getProcessingUnits()) ,i,pt_buf.get(i));
}
vcl.execute();
// Check the received buffers (careful at negative modulo)
for (size_t i = 0 ; i < 8 ; i++)
{
for (size_t j = 0 ; j < n ; j++)
{
T pt = pt_buf.get(i).get(j);
size_t p_recv = mod( (vcl.getProcessUnitID() - i * P_STRIDE), vcl.getProcessingUnits());
BOOST_REQUIRE_EQUAL(pt,p_recv);
}
}
}
#endif /* VCLUSTER_UNIT_TEST_UTIL_HPP_ */
......@@ -18,16 +18,6 @@
BOOST_AUTO_TEST_SUITE( VCluster_test )
/*! \brief calculate the x mob m
*
* \param x
* \param m
*
*/
int mod(int x, int m) {
return (x%m + m)%m;
}
BOOST_AUTO_TEST_CASE( VCluster_use_reductions)
{
Vcluster & vcl = *global_v_cluster;
......@@ -111,108 +101,24 @@ BOOST_AUTO_TEST_CASE( VCluster_use_reductions)
}
#define N_V_ELEMENTS 16
#define P_STRIDE 17
#include "Vector/vector_test_util.hpp"
BOOST_AUTO_TEST_CASE(VCluster_send_recv)
{
unsigned char uc = 1;
char c = 1;
short s = 1;
unsigned short us = 1;
int i = 1;
unsigned int ui = 1;
long int li = 1;
unsigned long int uli = 1;
float f = 1;
double d = 1;
Vcluster & vcl = *global_v_cluster;
// check an all to all patter with the primitives
/* for (size_t k = 0 ; k < vcl.getProcessingUnits() ; k++)
{
vcl.send(k,uc);
vcl.send(k,c);
vcl.send(k,s);
vcl.send(k,us);
vcl.send(k,i)
}*/
// check Long distance pattern with vectors
typedef Point_test<float> p;
Point_test<float> pt;
openfpm::vector<Point_test<float>> v_send;
pt.setx(vcl.getProcessUnitID());
pt.sety(vcl.getProcessUnitID());
pt.setz(vcl.getProcessUnitID());
pt.sets(vcl.getProcessUnitID());
pt.setv(0,vcl.getProcessUnitID());
pt.setv(1,vcl.getProcessUnitID());
pt.setv(2,vcl.getProcessUnitID());
pt.sett(0,0,vcl.getProcessUnitID());
pt.sett(0,1,vcl.getProcessUnitID());
pt.sett(0,2,vcl.getProcessUnitID());
pt.sett(1,0,vcl.getProcessUnitID());
pt.sett(1,1,vcl.getProcessUnitID());
pt.sett(1,2,vcl.getProcessUnitID());
pt.sett(2,0,vcl.getProcessUnitID());
pt.sett(2,1,vcl.getProcessUnitID());
pt.sett(2,2,vcl.getProcessUnitID());
// ADD n elements
for (size_t i = 0 ; i < N_V_ELEMENTS ; i++)
v_send.add(pt);
// Send to 8 processors
for (size_t i = 0 ; i < 8 ; i++)
vcl.send( mod(vcl.getProcessUnitID() + i * P_STRIDE, vcl.getProcessingUnits()) ,i,v_send);
openfpm::vector<openfpm::vector<Point_test<float>> > pt_buf;
pt_buf.resize(8);
// Recv from 8 processors
for (size_t i = 0 ; i < 8 ; i++)
{
pt_buf.get(i).resize(N_V_ELEMENTS);
vcl.recv( mod( (vcl.getProcessUnitID() - i * P_STRIDE), vcl.getProcessingUnits()) ,i,pt_buf.get(i));
}
vcl.execute();
// Check the received buffers (carefull at negative modulo)
for (size_t i = 0 ; i < 8 ; i++)
{
for (size_t j = 0 ; j < N_V_ELEMENTS ; j++)
{
Point_test<float> pt = pt_buf.get(i).get(j);
size_t p_recv = mod( (vcl.getProcessUnitID() - i * P_STRIDE), vcl.getProcessingUnits());
BOOST_REQUIRE_EQUAL(pt.template get<p::x>(),p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::y>(),p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::z>(),p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::s>(),p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::v>()[0],p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::v>()[1],p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::v>()[2],p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::t>()[0][0],p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::t>()[0][1],p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::t>()[0][2],p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::t>()[1][0],p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::t>()[1][1],p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::t>()[1][2],p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::t>()[2][0],p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::t>()[2][1],p_recv);
BOOST_REQUIRE_EQUAL(pt.template get<p::t>()[2][2],p_recv);
}
}
test_send_recv_complex(N_V_ELEMENTS,vcl);
test_send_recv_primitives<unsigned char>(N_V_ELEMENTS,vcl);
test_send_recv_primitives<char>(N_V_ELEMENTS,vcl);
test_send_recv_primitives<short>(N_V_ELEMENTS,vcl);
test_send_recv_primitives<unsigned short>(N_V_ELEMENTS,vcl);
test_send_recv_primitives<int>(N_V_ELEMENTS,vcl);
test_send_recv_primitives<unsigned int>(N_V_ELEMENTS,vcl);
test_send_recv_primitives<long int>(N_V_ELEMENTS,vcl);
test_send_recv_primitives<unsigned long int>(N_V_ELEMENTS,vcl);
test_send_recv_primitives<float>(N_V_ELEMENTS,vcl);
test_send_recv_primitives<double>(N_V_ELEMENTS,vcl);
}
BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv)
......
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