From 46e685e2e265f4147e61824640929440e22138e3 Mon Sep 17 00:00:00 2001
From: Pietro Incardona <i-bird@localhost.localdomain>
Date: Wed, 18 Nov 2015 18:51:21 -0500
Subject: [PATCH] pdata with the latest modules

---
 install                                 |  1 +
 openfpm_data                            |  2 +-
 src/Decomposition/CartDecomposition.hpp |  4 +-
 src/Grid/grid_dist_id.hpp               | 84 +++++++++++++++++--------
 src/Grid/grid_dist_id_iterator_sub.hpp  | 20 ++++++
 src/Grid/grid_dist_id_unit_test.hpp     |  9 +--
 6 files changed, 88 insertions(+), 32 deletions(-)

diff --git a/install b/install
index aa9e7e38..a5673713 100755
--- a/install
+++ b/install
@@ -208,6 +208,7 @@ install_base=$(cat install_dir)
 echo "INCLUDE_PATH=-I. -I$install_base/openfpm_pdata/include/config -I$install_base/openfpm_pdata/include -I$install_base/openfpm_data/include -I$install_base/openfpm_vcluster/include -I$install_base/openfpm_io/include -I$install_base/openfpm_devices/include -I$i_dir/METIS/include -I$i_dir/BOOST/include" > example.mk
 echo "LIBS_PATH=-L$install_base/openfpm_devices/lib -L$install_base/openfpm_vcluster/lib -L$i_dir/METIS/lib -L$i_dir/BOOST/lib " >> example.mk
 echo "LIBS=-lvcluster -lofpmmemory -lmetis -lboost_iostreams" >> example.mk
+echo "LIBS_SE2=-lvcluster -lofpmmemory_se2 -lmetis -lboost_iostreams" >> example.mk
 cp example.mk src/example.mk
 cp example.mk example/example.mk
 
diff --git a/openfpm_data b/openfpm_data
index 080bde84..2baeb7be 160000
--- a/openfpm_data
+++ b/openfpm_data
@@ -1 +1 @@
-Subproject commit 080bde845909ab16f01e8425828b91c7e17110ed
+Subproject commit 2baeb7bec51322aab29ed97f2b9de6b0b6d347d4
diff --git a/src/Decomposition/CartDecomposition.hpp b/src/Decomposition/CartDecomposition.hpp
index f205a31d..9981a969 100644
--- a/src/Decomposition/CartDecomposition.hpp
+++ b/src/Decomposition/CartDecomposition.hpp
@@ -593,7 +593,7 @@ p1[0]<-----+         +----> p2[0]
 	 * \return a duplicated decomposition with different ghost boxes
 	 *
 	 */
-	CartDecomposition<dim,T,Memory,Domain> duplicate(const Ghost<dim,T> & g)
+	CartDecomposition<dim,T,Memory,Domain> duplicate(const Ghost<dim,T> & g) const
 	{
 		CartDecomposition<dim,T,Memory,Domain> cart(v_cl);
 
@@ -626,7 +626,7 @@ p1[0]<-----+         +----> p2[0]
 	 * \return a duplicated decomposition
 	 *
 	 */
-	CartDecomposition<dim,T,Memory,Domain> duplicate()
+	CartDecomposition<dim,T,Memory,Domain> duplicate() const
 	{
 		CartDecomposition<dim,T,Memory,Domain> cart(v_cl);
 
diff --git a/src/Grid/grid_dist_id.hpp b/src/Grid/grid_dist_id.hpp
index f6637d0c..9c859af9 100644
--- a/src/Grid/grid_dist_id.hpp
+++ b/src/Grid/grid_dist_id.hpp
@@ -59,7 +59,7 @@ class grid_dist_id
 	Vcluster_object_array<device_grid> loc_grid;
 
 	//! Space Decomposition
-	Decomposition & dec;
+	Decomposition dec;
 
 	//! Extension of each grid: Domain and ghost + domain
 	openfpm::vector<GBoxes<device_grid::dims>> gdb_ext;
@@ -423,9 +423,6 @@ class grid_dist_id
 	 */
 	inline void InitializeCellDecomposer(const size_t (& g_sz)[dim])
 	{
-		// Increment the reference counter of the decomposition
-		dec.incRef();
-
 		// check that the grid has valid size
 		check_size(g_sz);
 
@@ -509,9 +506,12 @@ public:
 
 
     //! constructor
-    grid_dist_id(Decomposition & dec, const size_t (& g_sz)[dim], const Box<dim,St> & domain, const Ghost<dim,St> & ghost)
+    grid_dist_id(const Decomposition & dec, const size_t (& g_sz)[dim], const Box<dim,St> & domain, const Ghost<dim,St> & ghost)
     :domain(domain),ghost(ghost),dec(dec),v_cl(*global_v_cluster)
 	{
+		// Increment the reference counter of the decomposition
+		this->dec.incRef();
+
 		InitializeCellDecomposer(g_sz);
 		InitializeStructures(g_sz);
 	}
@@ -520,6 +520,9 @@ public:
     grid_dist_id(Decomposition && dec, const size_t (& g_sz)[dim], const Box<dim,St> & domain, const Ghost<dim,St> & ghost)
     :domain(domain),ghost(ghost),dec(dec),v_cl(*global_v_cluster)
 	{
+		// Increment the reference counter of the decomposition
+    	this->dec.incRef();
+
 		InitializeCellDecomposer(g_sz);
 		InitializeStructures(g_sz);
 	}
@@ -528,14 +531,20 @@ public:
 	 *
 	 * \param g_sz array with the grid size on each dimension
 	 * \param domain domain where this grid live
-	 * \param g Ghost
+	 * \param g Ghost given in grid units
 	 *
 	 */
-	grid_dist_id(const size_t (& g_sz)[dim],const Box<dim,St> & domain, const Ghost<dim,St> & g)
-	:domain(domain),ghost(g),dec(* new Decomposition(*global_v_cluster)),v_cl(*global_v_cluster),ginfo(g_sz),ginfo_v(g_sz)
+	grid_dist_id(const Decomposition & dec, const size_t (& g_sz)[dim],const Box<dim,St> & domain, const Ghost<dim,long int> & g)
+	:domain(domain),dec(dec),v_cl(*global_v_cluster),ginfo(g_sz),ginfo_v(g_sz)
 	{
+		// Increment the reference counter of the decomposition
+		this->dec.incRef();
+
 		InitializeCellDecomposer(g_sz);
-		InitializeDecomposition(g_sz);
+
+		ghost = convert_ghost(g,cd_sm);
+
+		// Initialize structures
 		InitializeStructures(g_sz);
 	}
 
@@ -546,14 +555,16 @@ public:
 	 * \param g Ghost given in grid units
 	 *
 	 */
-	grid_dist_id(const size_t (& g_sz)[dim],const Box<dim,St> & domain, const Ghost<dim,long int> & g)
-	:domain(domain),dec(*new Decomposition(*global_v_cluster)),v_cl(*global_v_cluster),ginfo(g_sz),ginfo_v(g_sz)
+	grid_dist_id(Decomposition && dec, const size_t (& g_sz)[dim],const Box<dim,St> & domain, const Ghost<dim,long int> & g)
+	:domain(domain),dec(dec),v_cl(*global_v_cluster),ginfo(g_sz),ginfo_v(g_sz)
 	{
+		// Increment the reference counter of the decomposition
+		this->dec.incRef();
+
 		InitializeCellDecomposer(g_sz);
 
 		ghost = convert_ghost(g,cd_sm);
 
-		InitializeDecomposition(g_sz);
 		// Initialize structures
 		InitializeStructures(g_sz);
 	}
@@ -562,18 +573,17 @@ public:
 	 *
 	 * \param g_sz array with the grid size on each dimension
 	 * \param domain domain where this grid live
-	 * \param g Ghost given in grid units
+	 * \param g Ghost
 	 *
 	 */
-	grid_dist_id(Decomposition & dec, const size_t (& g_sz)[dim],const Box<dim,St> & domain, const Ghost<dim,long int> & g)
-	:domain(domain),dec(dec),v_cl(*global_v_cluster),ginfo(g_sz),ginfo_v(g_sz)
+	grid_dist_id(const size_t (& g_sz)[dim],const Box<dim,St> & domain, const Ghost<dim,St> & g)
+	:domain(domain),ghost(g),dec(*global_v_cluster),v_cl(*global_v_cluster),ginfo(g_sz),ginfo_v(g_sz)
 	{
-		InitializeCellDecomposer(g_sz);
-
-		ghost = convert_ghost(g,cd_sm);
+		// Increment the reference counter of the decomposition
+		this->dec.incRef();
 
+		InitializeCellDecomposer(g_sz);
 		InitializeDecomposition(g_sz);
-		// Initialize structures
 		InitializeStructures(g_sz);
 	}
 
@@ -584,9 +594,12 @@ public:
 	 * \param g Ghost given in grid units
 	 *
 	 */
-	grid_dist_id(Decomposition && dec, const size_t (& g_sz)[dim],const Box<dim,St> & domain, const Ghost<dim,long int> & g)
-	:domain(domain),dec(dec),v_cl(*global_v_cluster),ginfo(g_sz),ginfo_v(g_sz)
+	grid_dist_id(const size_t (& g_sz)[dim],const Box<dim,St> & domain, const Ghost<dim,long int> & g)
+	:domain(domain),dec(*global_v_cluster),v_cl(*global_v_cluster),ginfo(g_sz),ginfo_v(g_sz)
 	{
+		// Increment the reference counter of the decomposition
+		this->dec.incRef();
+
 		InitializeCellDecomposer(g_sz);
 
 		ghost = convert_ghost(g,cd_sm);
@@ -596,6 +609,31 @@ public:
 		InitializeStructures(g_sz);
 	}
 
+	/*! \brief Constrcuctor
+	 *
+	 * \param g_sz std::vector with the grid size on each dimension
+	 * \param domain domain where this grid live
+	 * \param g Ghost given in grid units
+	 *
+	 */
+	grid_dist_id(const Decomposition & dec, const std::vector<size_t> & g_sz,const Box<dim,St> & domain, const Ghost<dim,long int> & g)
+	:grid_dist_id(dec,*static_cast<const size_t(*) [dim]>(static_cast<const void*>(&g_sz[0])),domain,g)
+	{
+
+	}
+
+	/*! \brief Constrcuctor
+	 *
+	 * \param g_sz std::vector with the grid size on each dimension
+	 * \param domain domain where this grid live
+	 * \param g Ghost given in grid units
+	 *
+	 */
+	grid_dist_id(Decomposition && dec,const std::vector<size_t> & g_sz,const Box<dim,St> & domain, const Ghost<dim,long int> & g)
+	:grid_dist_id(dec, *static_cast<const size_t(*) [dim]>(static_cast<const void*>(&g_sz[0])) , domain, g)
+	{
+	}
+
 	/*! \brief Get an object containing the grid informations
 	 *
 	 * \return an information object about this grid
@@ -720,10 +758,6 @@ public:
 	~grid_dist_id()
 	{
 		dec.decRef();
-
-		// if we reach the 0, destroy the object
-		if (dec.ref() == 0)
-			delete &dec;
 	}
 
 	/*! \brief Get the Virtual Cluster machine
diff --git a/src/Grid/grid_dist_id_iterator_sub.hpp b/src/Grid/grid_dist_id_iterator_sub.hpp
index a3c96cc4..11ac7cc1 100644
--- a/src/Grid/grid_dist_id_iterator_sub.hpp
+++ b/src/Grid/grid_dist_id_iterator_sub.hpp
@@ -227,6 +227,26 @@ class grid_dist_iterator_sub
 
 		return k_glob;
 	}
+
+	/* \brief Get the starting point of the grid iterator
+	 *
+	 * \return the starting point
+	 *
+	 */
+	inline grid_key_dx<dim> getStart()
+	{
+		return start;
+	}
+
+	/* \brief Get the stop point of the grid iterator
+	 *
+	 * \return the stop point
+	 *
+	 */
+	inline grid_key_dx<dim> getStop()
+	{
+		return stop;
+	}
 };
 
 
diff --git a/src/Grid/grid_dist_id_unit_test.hpp b/src/Grid/grid_dist_id_unit_test.hpp
index baa7039b..2c17ed99 100644
--- a/src/Grid/grid_dist_id_unit_test.hpp
+++ b/src/Grid/grid_dist_id_unit_test.hpp
@@ -946,7 +946,11 @@ void Test3D_dup(const Box<3,float> & domain, long int k)
 
 		//! [Construct two grid with the same decomposition]
 
-		BOOST_REQUIRE_EQUAL(g_dist2.getDecomposition().ref(),2);
+		bool ret = g_dist2.getDecomposition().check_consistency();
+		BOOST_REQUIRE_EQUAL(ret,true);
+		ret = g_dist2.getDecomposition().is_equal(g_dist2.getDecomposition());
+		BOOST_REQUIRE_EQUAL(ret,true);
+
 
 		auto dom_g1 = g_dist1.getDomainIterator();
 		auto dom_g2 = g_dist2.getDomainIterator();
@@ -996,11 +1000,8 @@ void Test3D_dup(const Box<3,float> & domain, long int k)
 
 		//! [Construct two grid with the same decomposition]
 
-		BOOST_REQUIRE_EQUAL(g_dist2->getDecomposition().ref(),2);
-
 		delete g_dist1;
 
-		BOOST_REQUIRE_EQUAL(g_dist2->getDecomposition().ref(),1);
 		bool ret = g_dist2->getDecomposition().check_consistency();
 		BOOST_REQUIRE_EQUAL(ret,true);
 	}
-- 
GitLab