From ede7ff531adb025d0930de050d0aa65a4ead16cd Mon Sep 17 00:00:00 2001 From: Pietro Incardona Date: Fri, 18 Mar 2016 22:26:33 +0100 Subject: [PATCH] Fixing semantic communication --- src/VCluster.hpp | 3 +- src/VCluster_semantic.ipp | 6 +- src/VCluster_semantic_unit_tests.hpp | 82 ++-------------------------- 3 files changed, 11 insertions(+), 80 deletions(-) diff --git a/src/VCluster.hpp b/src/VCluster.hpp index 9ff9f73..714a68c 100644 --- a/src/VCluster.hpp +++ b/src/VCluster.hpp @@ -17,6 +17,7 @@ #include "util/util_debug.hpp" #endif #include "util/Vcluster_log.hpp" +#include "memory/BHeapMemory.hpp" #define MSG_LENGTH 1024 #define MSG_SEND_RECV 1025 @@ -161,7 +162,7 @@ class Vcluster openfpm::vector map; // Receive buffers - openfpm::vector recv_buf; + openfpm::vector recv_buf; // barrier request MPI_Request bar_req; diff --git a/src/VCluster_semantic.ipp b/src/VCluster_semantic.ipp index 8b4fa79..82841c8 100644 --- a/src/VCluster_semantic.ipp +++ b/src/VCluster_semantic.ipp @@ -32,7 +32,7 @@ void reset_recv_buf() */ static void * msg_alloc(size_t msg_i ,size_t total_msg, size_t total_p, size_t i, size_t ri, void * ptr) { - openfpm::vector * recv_buf = (openfpm::vector *)ptr; + openfpm::vector * recv_buf = (openfpm::vector *)ptr; if (recv_buf == NULL) std::cerr << __FILE__ << ":" << __LINE__ << " Internal error this processor is not suppose to receive\n"; @@ -69,7 +69,7 @@ static void * msg_alloc(size_t msg_i ,size_t total_msg, size_t total_p, size_t i * \return true if the function completed succefully * */ -template bool SGather(T & send, S & recv,size_t root) +template bool SGather(T & send, S & recv,size_t root, int debug = 0) { // Reset the receive buffer reset_recv_buf(); @@ -89,7 +89,7 @@ template bool SGather(T & send, S & recv,size_t root) // for each received buffer create a memory reppresentation // 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()); diff --git a/src/VCluster_semantic_unit_tests.hpp b/src/VCluster_semantic_unit_tests.hpp index d3cb483..23c719f 100644 --- a/src/VCluster_semantic_unit_tests.hpp +++ b/src/VCluster_semantic_unit_tests.hpp @@ -20,38 +20,7 @@ BOOST_AUTO_TEST_SUITE( VCluster_semantic_test ) BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather) { - { - Vcluster & vcl = *global_v_cluster; - - if (vcl.getProcessingUnits() >= 32) - return; - - //! [Gather the data on master] - - openfpm::vector v1; - v1.resize(vcl.getProcessUnitID()); - - for(size_t i = 0 ; i < vcl.getProcessUnitID() ; i++) - v1.get(i) = 5; - - openfpm::vector v2; - - 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); - - 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); - } - } + for (size_t i = 0 ; i < 100 ; i++) { Vcluster & vcl = *global_v_cluster; @@ -66,9 +35,9 @@ BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather) openfpm::vector v2; - vcl.SGather(v1,v2,1); + vcl.SGather(v1,v2,(i%vcl.getProcessingUnits())); - if (vcl.getProcessUnitID() == 1) + if (vcl.getProcessUnitID() == (i%vcl.getProcessingUnits())) { size_t n = vcl.getProcessingUnits(); BOOST_REQUIRE_EQUAL(v2.size(),n*(n-1)/2); @@ -85,46 +54,7 @@ BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather) BOOST_AUTO_TEST_CASE (Vcluster_semantic_struct_gather) { - { - Vcluster & vcl = *global_v_cluster; - - if (vcl.getProcessingUnits() >= 32) - return; - - //! [Gather the data on master complex] - - openfpm::vector v1; - v1.resize(vcl.getProcessUnitID()); - - for(size_t i = 0 ; i < vcl.getProcessUnitID() ; i++) - { - v1.get(i).a = 5; - v1.get(i).b = 10.0; - v1.get(i).c = 11.0; - } - - openfpm::vector v2; - - vcl.SGather(v1,v2,0); - - //! [Gather the data on master complex] - - 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); - } - } + for (size_t i = 0 ; i < 100 ; i++) { Vcluster & vcl = *global_v_cluster; @@ -143,9 +73,9 @@ BOOST_AUTO_TEST_CASE (Vcluster_semantic_struct_gather) openfpm::vector v2; - vcl.SGather(v1,v2,1); + vcl.SGather(v1,v2,(i%vcl.getProcessingUnits())); - if (vcl.getProcessUnitID() == 1) + if (vcl.getProcessUnitID() == (i%vcl.getProcessingUnits())) { size_t n = vcl.getProcessingUnits(); BOOST_REQUIRE_EQUAL(v2.size(),n*(n-1)/2); -- GitLab