From fa585d41aa78a59a6e81c573e490bfe825f219a8 Mon Sep 17 00:00:00 2001
From: Pietro Incardona <incardon@mpi-cbg.de>
Date: Tue, 10 Jan 2017 13:41:56 +0100
Subject: [PATCH] Update modules

---
 CHANGELOG.md                                  |  18 +-
 configure.ac                                  |   2 +-
 openfpm_devices                               |   2 +-
 script/install_BOOST.sh                       |  10 +-
 script/install_EIGEN.sh                       |  12 +-
 script/install_PETSC.sh                       |   8 +-
 script/remove_old                             |   4 +-
 .../{ => Iterators}/grid_dist_id_iterator.hpp |   2 +-
 .../grid_dist_id_iterator_dec.hpp             |  64 ++-
 .../grid_dist_id_iterator_dec_skin.hpp        | 295 +++++++++++++
 .../grid_dist_id_iterator_sub.hpp             |   0
 .../Iterators/grid_dist_id_iterator_util.hpp  |  51 +++
 .../grid_dist_id_iterators_unit_tests.hpp     | 408 ++++++++++++++++++
 src/Grid/grid_dist_id.hpp                     |   6 +-
 src/Grid/grid_dist_id_unit_test.cpp           | 287 ------------
 src/Makefile.am                               |   4 +-
 .../{ => Iterators}/vector_dist_iterator.hpp  |   2 +-
 .../Iterators/vector_dist_iterator_skin.hpp   |  15 +
 src/Vector/vector_dist.hpp                    |   4 +-
 src/main.cpp                                  |   3 +-
 20 files changed, 841 insertions(+), 356 deletions(-)
 rename src/Grid/{ => Iterators}/grid_dist_id_iterator.hpp (99%)
 rename src/Grid/{ => Iterators}/grid_dist_id_iterator_dec.hpp (79%)
 create mode 100644 src/Grid/Iterators/grid_dist_id_iterator_dec_skin.hpp
 rename src/Grid/{ => Iterators}/grid_dist_id_iterator_sub.hpp (100%)
 create mode 100644 src/Grid/Iterators/grid_dist_id_iterator_util.hpp
 create mode 100644 src/Grid/Iterators/grid_dist_id_iterators_unit_tests.hpp
 rename src/Vector/{ => Iterators}/vector_dist_iterator.hpp (97%)
 create mode 100644 src/Vector/Iterators/vector_dist_iterator_skin.hpp

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 587bf61c..5b23dc49 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,19 @@
 # Change Log
 All notable changes to this project will be documented in this file.
 
+## [0.8.0] February
+
+### Added
+- Dynamic Load balancing
+- Added SPH Dam break with Dynamic load balancing
+- Added procedure for update ./install --update
+  (From 0.8.0 version will be supported for bug fixing, version 0.X.0 will be supported untill
+   0.X+2.0 will be out)
+
+### Changed
+- BOOST updated to 1.63
+- Eigen updated to 3.3.7
+
 ## [0.7.0] 15 December 2016
 
 ### Added
@@ -165,19 +178,18 @@ All notable changes to this project will be documented in this file.
 - Algebraic Multigrid solver
 - Parallel VTK, improved visualization
 
-## [0.8.0] - Mid January 2017
+## [0.10.0] -  July 2017
 
 ### Added
 - Dynamic Load Balancies examples and interface fixation
 - Check Point restart
 - More example and documentations
 
-## [0.7.0] - December of October
+## [0.9.0] - May 2017
 
 ### Added
 - Asynchronous communication
 - Support for Microsoft Windows with Cygwin
-- Support for Docker/codenvy
 - Defining a domain an invalid domain like Box<2,float> box({0.0,1.0},{0.0,1.0}) (the correct is {0.0,0.0},{1.0,1.0}  )
            produce dead-lock or unclear error message in SE_CLASS1, not hint is given, added usefull error message
 
diff --git a/configure.ac b/configure.ac
index 0228a575..0431ddd7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4,7 +4,7 @@
 ## Take all the options with the exception of --enable-install-req
 
 AC_PREREQ(2.59)
-AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
+AC_INIT(OpenFPM_pdata, 0.8.0, BUG-REPORT-ADDRESS)
 AC_CANONICAL_SYSTEM
 AC_CONFIG_SRCDIR([src/main.cpp])
 AC_CONFIG_SUBDIRS([openfpm_data openfpm_devices openfpm_vcluster openfpm_io openfpm_numerics])
diff --git a/openfpm_devices b/openfpm_devices
index 90076f0c..a0b02db5 160000
--- a/openfpm_devices
+++ b/openfpm_devices
@@ -1 +1 @@
-Subproject commit 90076f0c7ea6ac954d2b09fc8e84caa64024e8a6
+Subproject commit a0b02db5938003755b85c86fded64b107ac4e55d
diff --git a/script/install_BOOST.sh b/script/install_BOOST.sh
index 87c744be..a610c21e 100755
--- a/script/install_BOOST.sh
+++ b/script/install_BOOST.sh
@@ -1,17 +1,17 @@
 #!/bin/bash 
 
-# check if the directory $1/MPI exist
+# check if the directory $1/BOOST exist
 
 if [ -d "$1/BOOST" ]; then
   echo "BOOST already installed"
   exit 0
 fi
 
-wget http://ppmcore.mpi-cbg.de/upload/boost_1_60_0.tar.bz2
-tar -xvf boost_1_60_0.tar.bz2
-cd boost_1_60_0
+wget http://ppmcore.mpi-cbg.de/upload/boost_1_63_0.tar.bz2
+tar -xvf boost_1_63_0.tar.bz2
+cd boost_1_63_0
 ./bootstrap.sh --with-toolset=$3
 mkdir $1/BOOST
 ./b2 -j $2 install --prefix=$1/BOOST
-rm -rf boost_1_60_0
+rm -rf boost_1_63_0
 
diff --git a/script/install_EIGEN.sh b/script/install_EIGEN.sh
index f4514707..640fb505 100755
--- a/script/install_EIGEN.sh
+++ b/script/install_EIGEN.sh
@@ -17,14 +17,16 @@ if [ ! -d "$1/SUITESPARSE"  ]; then
   exit 1
 fi
 
-wget http://ppmcore.mpi-cbg.de/upload/eigen-3.2.7.tar.bz2
-rm -rf eigen-eigen-b30b87236a1b
-tar -xf eigen-3.2.7.tar.bz2
+wget http://ppmcore.mpi-cbg.de/upload/eigen-3.3.1.tar.bz2
+rm -rf eigen-eigen-f562a193118d
+tar -xf eigen-3.3.1.tar.bz2
 
-cd eigen-eigen-b30b87236a1b
+cd eigen-eigen-f562a193118d
 mkdir $1/EIGEN/
 mv Eigen $1/EIGEN/Eigen
 
 cd ..
-rm -rf eigen-eigen-b30b87236a1b
+rm -rf eigen-eigen-f562a193118d
 
+# Mark the installation
+echo 1 > $1/EIGEN/version
diff --git a/script/install_PETSC.sh b/script/install_PETSC.sh
index b599b55c..24ce0226 100755
--- a/script/install_PETSC.sh
+++ b/script/install_PETSC.sh
@@ -202,13 +202,13 @@ if [ x"$CXX" != x"icpc" ]; then
       cp -r lib $1/MUMPS
 
       MUMPS_extra_lib="--with-mumps-lib=\"$1/MUMPS/lib/libdmumps.a $1/MUMPS/lib/libmumps_common.a $1/MUMPS/lib/libpord.a\""
-      configure_options="$configure_options --with-mumps=yes  --with-mumps-include=$1/MUMPS/include"
+      configure_options="$configure_options --with-mumps=yes --with-mumps-include=$1/MUMPS/include"
 
     fi
   else
     echo "MUMPS already installed"
     MUMPS_extra_lib="--with-mumps-lib=\"$1/MUMPS/lib/libdmumps.a $1/MUMPS/lib/libmumps_common.a $1/MUMPS/lib/libpord.a\""
-    configure_options="$configure_options --with-mumps=yes --with-mumps-lib=\"$MUMPS_extra_lib\"  --with-mumps-include=$1/MUMPS/include"
+    configure_options="$configure_options --with-mumps=yes --with-mumps-include=$1/MUMPS/include" 
   fi
 fi
 
@@ -308,9 +308,9 @@ fi
 tar -xf petsc-lite-3.6.4.tar.gz
 cd petsc-3.6.4
 
-echo "./configure --with-cxx-dialect=C++11 --with-mpi-dir=$mpi_dir  $configure_options  --prefix=$1/PETSC --with-debugging=0"
+echo "./configure --with-cxx-dialect=C++11 $petsc_openmp  --with-mpi-dir=$mpi_dir $configure_options "$MUMPS_extra_lib"  --prefix=$1/PETSC --with-debugging=0"
 
-./configure --with-cxx-dialect=C++11 $petsc_openmp --with-mpi-dir=$mpi_dir $MUMPS_extra_lib  $configure_options  --prefix=$1/PETSC --with-debugging=0
+./configure --with-cxx-dialect=C++11 $petsc_openmp --with-mpi-dir=$mpi_dir $configure_options "$MUMPS_extra_lib" --prefix=$1/PETSC --with-debugging=0
 make all test
 make install
 
diff --git a/script/remove_old b/script/remove_old
index 0fc2ad0f..1159c865 100755
--- a/script/remove_old
+++ b/script/remove_old
@@ -76,7 +76,7 @@ function remove_old()
     ## Check the installed version of the dependencies
   
     if [ -d $1/BOOST ]; then
-    	is_update=$(cat $1/BOOST/include/boost/version.hpp | grep "#define BOOST_VERSION 106003")
+    	is_update=$(cat $1/BOOST/include/boost/version.hpp | grep "#define BOOST_VERSION 106300")
     	if [ x"$is_update" == x"" ]; then
                 echo -e "\033[1;34;5m  --------------------------------------------------------------------------- \033[0m"
                 echo -e "\033[1;34;5m  Boost has been updated to 1.63, the component will be updated automatically \033[0m"
@@ -143,6 +143,8 @@ function remove_old()
                 echo -e "\033[1;34;5m  ---------------------------------------------------------------------- \033[0m"
                 sleep 5
                 rm -rf $1/EIGEN/Eigen
+		rm -rf $1/EIGEN
+		rm -rf $1/PETSC
         fi
     fi
 
diff --git a/src/Grid/grid_dist_id_iterator.hpp b/src/Grid/Iterators/grid_dist_id_iterator.hpp
similarity index 99%
rename from src/Grid/grid_dist_id_iterator.hpp
rename to src/Grid/Iterators/grid_dist_id_iterator.hpp
index de95ef55..b02428e0 100644
--- a/src/Grid/grid_dist_id_iterator.hpp
+++ b/src/Grid/Iterators/grid_dist_id_iterator.hpp
@@ -48,7 +48,7 @@ struct GBoxes
 #define FREE 1
 #define FIXED 2
 
-#include "grid_dist_key.hpp"
+#include "Grid/grid_dist_key.hpp"
 #include "VCluster/VCluster.hpp"
 
 
diff --git a/src/Grid/grid_dist_id_iterator_dec.hpp b/src/Grid/Iterators/grid_dist_id_iterator_dec.hpp
similarity index 79%
rename from src/Grid/grid_dist_id_iterator_dec.hpp
rename to src/Grid/Iterators/grid_dist_id_iterator_dec.hpp
index c9425784..b8aad1ca 100644
--- a/src/Grid/grid_dist_id_iterator_dec.hpp
+++ b/src/Grid/Iterators/grid_dist_id_iterator_dec.hpp
@@ -9,7 +9,8 @@
 #define SRC_GRID_GRID_DIST_ID_ITERATOR_DEC_HPP_
 
 #include "grid_dist_id_iterator.hpp"
-#include "grid_dist_util.hpp"
+#include "Grid/grid_dist_util.hpp"
+#include "grid_dist_id_iterator_util.hpp"
 
 /*! \brief Given the decomposition it create an iterator
  *
@@ -40,41 +41,6 @@ class grid_dist_id_iterator_dec
 	typename Decomposition::stype spacing[Decomposition::dims];
 
 
-	/*! \brief compute the subset where it has to iterate
-	 *
-	 * \param g_c Actual grid
-	 * \param start_c adjusted start point for the grid g_c
-	 * \param stop_c adjusted stop point for the grid g_c
-	 *
-	 * \return false if the sub-set does not contain points
-	 *
-	 */
-	bool compute_subset(size_t gc, grid_key_dx<Decomposition::dims> & start_c, grid_key_dx<Decomposition::dims> & stop_c)
-	{
-		// Intersect the grid keys
-
-		for (size_t i = 0 ; i < Decomposition::dims ; i++)
-		{
-			long int start_p = gdb_ext.get(g_c).Dbox.getP1().get(i) + gdb_ext.get(g_c).origin.get(i);
-			long int stop_p = gdb_ext.get(g_c).Dbox.getP2().get(i) + gdb_ext.get(g_c).origin.get(i);
-			if (start.get(i) <= start_p)
-				start_c.set_d(i,gdb_ext.get(g_c).Dbox.getP1().get(i));
-			else if (start.get(i) <= stop_p)
-				start_c.set_d(i,start.get(i) - gdb_ext.get(g_c).origin.get(i));
-			else
-				return false;
-
-			if (stop.get(i) >= stop_p)
-				stop_c.set_d(i,gdb_ext.get(g_c).Dbox.getP2().get(i));
-			else if (stop.get(i) >= start_p)
-				stop_c.set_d(i,stop.get(i) - gdb_ext.get(g_c).origin.get(i));
-			else
-				return false;
-		}
-
-		return true;
-	}
-
 	/*! \brief from g_c increment g_c until you find a valid grid
 	 *
 	 */
@@ -86,7 +52,7 @@ class grid_dist_id_iterator_dec
 
 		// When the grid has size 0 potentially all the other informations are garbage
 		while (g_c < gdb_ext.size() &&
-			   (gdb_ext.get(g_c).Dbox.isValid() == false || compute_subset(g_c,start_c,stop_c) == false ))
+			   (gdb_ext.get(g_c).Dbox.isValid() == false || compute_subset<Decomposition>(gdb_ext,g_c,start,stop,start_c,stop_c) == false ))
 		{g_c++;}
 
 		// get the next grid iterator
@@ -118,6 +84,8 @@ class grid_dist_id_iterator_dec
 	*
 	* \param tmp iterator to copy
 	*
+	* \return itself
+	*
 	*/
 	grid_dist_id_iterator_dec<Decomposition> & operator=(const grid_dist_id_iterator_dec<Decomposition> & tmp)
 	{
@@ -246,7 +214,7 @@ class grid_dist_id_iterator_dec
 	 */
 	inline grid_key_dx<Decomposition::dims> get()
 	{
-		const grid_dist_key_dx<Decomposition::dims> & k = get_int();
+		const grid_dist_key_dx<Decomposition::dims> k = get_int();
 
 		// Get the sub-domain id
 		size_t sub_id = k.getSub();
@@ -258,6 +226,26 @@ class grid_dist_id_iterator_dec
 
 		return k_glob;
 	}
+
+	/*! \brief Get the starting point of the sub-grid we are iterating
+	 *
+	 * \return the starting point
+	 *
+	 */
+	inline grid_key_dx<Decomposition::dims> getStart()
+	{
+		return start;
+	}
+
+	/*! \brief Get the starting point of the sub-grid we are iterating
+	 *
+	 * \return the stop point
+	 *
+	 */
+	inline grid_key_dx<Decomposition::dims> getStop()
+	{
+		return stop;
+	}
 };
 
 
diff --git a/src/Grid/Iterators/grid_dist_id_iterator_dec_skin.hpp b/src/Grid/Iterators/grid_dist_id_iterator_dec_skin.hpp
new file mode 100644
index 00000000..77f0c02f
--- /dev/null
+++ b/src/Grid/Iterators/grid_dist_id_iterator_dec_skin.hpp
@@ -0,0 +1,295 @@
+/*
+ * grid_dist_id_iterator_dec_skin.hpp
+ *
+ *  Created on: Jan 4, 2017
+ *      Author: i-bird
+ */
+
+#ifndef SRC_GRID_ITERATORS_GRID_DIST_ID_ITERATOR_DEC_SKIN_HPP_
+#define SRC_GRID_ITERATORS_GRID_DIST_ID_ITERATOR_DEC_SKIN_HPP_
+
+
+#include "grid_dist_id_iterator.hpp"
+#include "Grid/grid_dist_util.hpp"
+#include "grid_dist_id_iterator_util.hpp"
+
+/*! \brief Given the decomposition it create an iterator
+ *
+ * Iterator across the local elements of the distributed grid
+ *
+ * \tparam dec Decomposition type
+ *
+ */
+template<typename Decomposition>
+class grid_dist_id_iterator_dec_skin : protected grid_skin_iterator_bc<Decomposition::dims>
+{
+	//! a_its element in this moment selected
+	size_t a_its_p;
+
+	//! grid list counter
+	size_t g_c;
+
+	//! Extension of each grid: domain and ghost + domain
+	openfpm::vector<GBoxes<Decomposition::dims>> gdb_ext;
+
+	grid_key_dx_iterator_sub<Decomposition::dims> a_it;
+
+	struct gp_sub
+	{
+		//! from which grid this iterator come from
+		size_t gc;
+
+		//! Iterator
+		grid_key_dx_iterator_sub<Decomposition::dims> it;
+
+		gp_sub(size_t gc, grid_key_dx_iterator_sub<Decomposition::dims> && it)
+		:gc(gc),it(it)
+		{}
+	};
+
+	//! Actual sub-iterators
+	openfpm::vector<gp_sub> a_its;
+
+	//! Spacing
+	typename Decomposition::stype spacing[Decomposition::dims];
+
+
+	/*! \brief from g_c increment g_c until you find a valid grid
+	 *
+	 */
+	void selectValidGrid()
+	{
+		if (a_its_p < a_its.size())
+		{
+			g_c = a_its.get(a_its_p).gc;
+
+			a_it.reinitialize(a_its.get(a_its_p).it);
+		}
+		else
+			g_c = gdb_ext.size();
+	}
+
+	/*! \brief construct sub-iterators
+	 *
+	 *
+	 *
+	 */
+	void construct_sub_it()
+	{
+		// Construct the sub iterators
+		for (size_t i = 0 ; i < 2*Decomposition::dims; i++)
+		{
+			for (size_t gc = 0 ; gc < gdb_ext.size() ; gc++)
+			{
+				grid_key_dx<Decomposition::dims> start = this->sub_it[i].getStart();
+				grid_key_dx<Decomposition::dims> stop = this->sub_it[i].getStop();
+
+				grid_key_dx<Decomposition::dims> start_c;
+				grid_key_dx<Decomposition::dims> stop_c;
+
+				if (compute_subset<Decomposition>(gdb_ext,gc,start,stop,start_c,stop_c) == true)
+				{
+					// Convert global coordinate start_c stop_c into local
+					// and calculate the grid sizes
+					size_t sz[Decomposition::dims];
+					for (size_t j = 0 ; j < Decomposition::dims ; j++)
+						sz[j] = gdb_ext.get(gc).GDbox.getHigh(j) + 1;
+
+					grid_sm<Decomposition::dims,void> g_sm(sz);
+
+					// Non empty sub-set
+					a_its.add(gp_sub(gc,grid_key_dx_iterator_sub<Decomposition::dims>(g_sm,start_c,stop_c)));
+				}
+			}
+		}
+	}
+
+	/*! \brief Get the actual key
+	 *
+	 * \return the actual key
+	 *
+	 */
+	inline grid_dist_key_dx<Decomposition::dims> get_int()
+	{
+		return grid_dist_key_dx<Decomposition::dims>(g_c,a_it.get());
+	}
+
+	public:
+
+
+	/*! \brief Copy constructor
+	*
+	* \param tmp iterator to copy
+	*
+	*/
+	grid_dist_id_iterator_dec_skin(const grid_dist_id_iterator_dec_skin<Decomposition> & tmp)
+	:grid_skin_iterator_bc<Decomposition::dims>(tmp),a_its_p(0)
+	{
+		this->operator=(tmp);
+	}
+
+	/*! \brief Copy constructor
+	*
+	* \param tmp iterator to copy
+	*
+	*/
+	grid_dist_id_iterator_dec_skin(grid_dist_id_iterator_dec_skin<Decomposition> && tmp)
+	:grid_skin_iterator_bc<Decomposition::dims>(tmp),a_its_p(0)
+	{
+		this->operator=(tmp);
+	}
+
+	/*! \brief Constructor of the distributed grid iterator
+	 *
+	 * \param dec Decomposition
+	 * \param sz size of the grid
+	 * \param bc boundary conditions
+	 *
+	 */
+	grid_dist_id_iterator_dec_skin(Decomposition & dec,
+			                       const grid_sm<Decomposition::dims,void> & g_sm,
+								   const Box<Decomposition::dims,size_t> & A,
+								   const Box<Decomposition::dims,size_t> & B,
+								   const size_t (& bc)[Decomposition::dims])
+	:grid_skin_iterator_bc<Decomposition::dims>(g_sm,A,B,bc),a_its_p(0),g_c(0)
+	{
+		// From the decomposition construct gdb_ext
+		create_gdb_ext<Decomposition::dims,Decomposition>(gdb_ext,dec,g_sm.getSize(),dec.getDomain(),spacing);
+
+		// This iterato only work if A is contained into B
+		if (A.isContained(B) == false)
+			std::cout << __FILE__ << ":" << __LINE__ << ", Error Box A must be contained into box B" << std::endl;
+
+		// construct sub_iterators
+		construct_sub_it();
+
+		// Initialize the current iterator
+		// with the first grid
+		selectValidGrid();
+	}
+
+	// Destructor
+	~grid_dist_id_iterator_dec_skin()
+	{
+	}
+
+	/*! \brief Get the next element
+	 *
+	 * \return the next grid_key
+	 *
+	 */
+
+	inline grid_dist_id_iterator_dec_skin<Decomposition> & operator++()
+	{
+		++a_it;
+
+		// check if a_it is at the end
+
+		if (a_it.isNext() == true)
+			return *this;
+		else
+		{
+			// switch to the new grid
+			a_its_p++;
+
+			selectValidGrid();
+		}
+
+		return *this;
+	}
+
+	/*! \brief Check if there is the next element
+	 *
+	 * \return true if there is the next, false otherwise
+	 *
+	 */
+	inline bool isNext()
+	{
+		// If there are no other grid stop
+
+		if (g_c >= gdb_ext.size())
+			return false;
+
+		return true;
+	}
+
+	/*! \brief Get the spacing of the grid
+	 *
+	 * \param i
+	 *
+	 */
+	inline typename Decomposition::stype getSpacing(size_t i)
+	{
+		return spacing[i];
+	}
+
+	/*! \brief Get the actual global key of the grid
+	 *
+	 *
+	 * \return the global position in the grid
+	 *
+	 */
+	inline grid_key_dx<Decomposition::dims> get()
+	{
+		const grid_dist_key_dx<Decomposition::dims> k = get_int();
+
+		// Get the sub-domain id
+		size_t sub_id = k.getSub();
+
+		grid_key_dx<Decomposition::dims> k_glob = k.getKey();
+
+		// shift
+		k_glob = k_glob + gdb_ext.get(sub_id).origin;
+
+		if (k_glob.get(0) > 11)
+		{
+			int debug = 0;
+			debug++;
+		}
+
+		return k_glob;
+	}
+
+	/*! \brief Copy operator=
+	*
+	* \param tmp iterator to copy
+	*
+	*/
+	grid_dist_id_iterator_dec_skin<Decomposition> & operator=(const grid_dist_id_iterator_dec_skin<Decomposition> & tmp)
+	{
+		a_its_p = tmp.a_its_p;
+		g_c = tmp.g_c;
+		gdb_ext = tmp.gdb_ext;
+		a_its = tmp.a_its;
+
+		for (size_t i = 0 ; i < Decomposition::dims ; i++)
+			spacing[i] = tmp.spacing[i];
+
+		a_it.reinitialize(tmp.a_it);
+
+		return *this;
+	}
+
+	/*! \brief Copy operator=
+	*
+	* \param tmp iterator to copy
+	*
+	*/
+	grid_dist_id_iterator_dec_skin<Decomposition> & operator=(grid_dist_id_iterator_dec_skin<Decomposition> && tmp)
+	{
+		a_its_p = tmp.a_its_p;
+		g_c = tmp.g_c;
+		gdb_ext = tmp.gdb_ext;
+		a_its = tmp.a_its;
+
+		for (size_t i = 0 ; i < Decomposition::dims ; i++)
+			spacing[i] = tmp.spacing[i];
+
+		a_it.reinitialize(tmp.a_it);
+
+		return *this;
+	}
+};
+
+
+#endif /* SRC_GRID_ITERATORS_GRID_DIST_ID_ITERATOR_DEC_SKIN_HPP_ */
diff --git a/src/Grid/grid_dist_id_iterator_sub.hpp b/src/Grid/Iterators/grid_dist_id_iterator_sub.hpp
similarity index 100%
rename from src/Grid/grid_dist_id_iterator_sub.hpp
rename to src/Grid/Iterators/grid_dist_id_iterator_sub.hpp
diff --git a/src/Grid/Iterators/grid_dist_id_iterator_util.hpp b/src/Grid/Iterators/grid_dist_id_iterator_util.hpp
new file mode 100644
index 00000000..b4c5413e
--- /dev/null
+++ b/src/Grid/Iterators/grid_dist_id_iterator_util.hpp
@@ -0,0 +1,51 @@
+/*
+ * grid_dist_id_iterator_util.hpp
+ *
+ *  Created on: Jan 6, 2017
+ *      Author: i-bird
+ */
+
+#ifndef SRC_GRID_ITERATORS_GRID_DIST_ID_ITERATOR_UTIL_HPP_
+#define SRC_GRID_ITERATORS_GRID_DIST_ID_ITERATOR_UTIL_HPP_
+
+
+/*! \brief compute the subset where it has to iterate
+ *
+ * \param g_c Actual grid
+ * \param start iterator start in global coordinate
+ * \param stop iterator stop in global coordinate
+ * \param start_c adjusted start point for the grid g_c
+ * \param stop_c adjusted stop point for the grid g_c
+ *
+ * \return false if the sub-set does not contain points
+ *
+ */
+template<typename Decomposition> static inline bool compute_subset(const openfpm::vector<GBoxes<Decomposition::dims>> & gdb_ext, size_t g_c, grid_key_dx<Decomposition::dims> & start, grid_key_dx<Decomposition::dims> & stop, grid_key_dx<Decomposition::dims> & start_c, grid_key_dx<Decomposition::dims> & stop_c)
+{
+	// Intersect the grid keys
+
+	for (size_t i = 0 ; i < Decomposition::dims ; i++)
+	{
+		long int start_p = gdb_ext.get(g_c).Dbox.getP1().get(i) + gdb_ext.get(g_c).origin.get(i);
+		long int stop_p = gdb_ext.get(g_c).Dbox.getP2().get(i) + gdb_ext.get(g_c).origin.get(i);
+		if (start.get(i) <= start_p)
+			start_c.set_d(i,gdb_ext.get(g_c).Dbox.getP1().get(i));
+		else if (start.get(i) <= stop_p)
+			start_c.set_d(i,start.get(i) - gdb_ext.get(g_c).origin.get(i));
+		else
+			return false;
+
+		if (stop.get(i) >= stop_p)
+			stop_c.set_d(i,gdb_ext.get(g_c).Dbox.getP2().get(i));
+		else if (stop.get(i) >= start_p)
+			stop_c.set_d(i,stop.get(i) - gdb_ext.get(g_c).origin.get(i));
+		else
+			return false;
+	}
+
+	return true;
+}
+
+
+
+#endif /* SRC_GRID_ITERATORS_GRID_DIST_ID_ITERATOR_UTIL_HPP_ */
diff --git a/src/Grid/Iterators/grid_dist_id_iterators_unit_tests.hpp b/src/Grid/Iterators/grid_dist_id_iterators_unit_tests.hpp
new file mode 100644
index 00000000..232207c2
--- /dev/null
+++ b/src/Grid/Iterators/grid_dist_id_iterators_unit_tests.hpp
@@ -0,0 +1,408 @@
+/*
+ * grid_dist_id_iterators_unit_tests.hpp
+ *
+ *  Created on: Jan 4, 2017
+ *      Author: i-bird
+ */
+
+#ifndef SRC_GRID_ITERATORS_GRID_DIST_ID_ITERATORS_UNIT_TESTS_HPP_
+#define SRC_GRID_ITERATORS_GRID_DIST_ID_ITERATORS_UNIT_TESTS_HPP_
+
+#include "grid_dist_id_iterator_dec_skin.hpp"
+
+BOOST_AUTO_TEST_SUITE( grid_dist_id_iterators_test )
+
+void print_test(std::string test, size_t sz)
+{
+	if (create_vcluster().getProcessUnitID() == 0)
+		std::cout << test << " " << sz << "\n";
+}
+
+void Test2D_sub(const Box<2,float> & domain, long int k)
+{
+	long int big_step = k / 30;
+	big_step = (big_step == 0)?1:big_step;
+	long int small_step = 21;
+
+	// this test is only performed when the number of processor is <= 32
+	if (create_vcluster().getProcessingUnits() > 32)
+		return;
+
+	print_test( "Testing 2D grid sub iterator k<=",k);
+
+	// 2D test
+	for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step )
+	{
+		BOOST_TEST_CHECKPOINT( "Testing 2D grid k=" << k );
+
+		// grid size
+		size_t sz[2];
+		sz[0] = k;
+		sz[1] = k;
+
+		float factor = pow(create_vcluster().getProcessingUnits()/2.0f,1.0f/2.0f);
+
+		// Ghost
+		Ghost<2,float> g(0.01 / factor);
+
+		// Distributed grid with id decomposition
+		grid_dist_id<2, float, scalar<float>> g_dist(sz,domain,g);
+
+		// check the consistency of the decomposition
+		bool val = g_dist.getDecomposition().check_consistency();
+		BOOST_REQUIRE_EQUAL(val,true);
+
+		size_t count;
+
+		// Grid sm
+		grid_sm<2,void> info(sz);
+
+		{
+		//! [Usage of a sub_grid iterator]
+
+		grid_key_dx<2> one(1,1);
+		grid_key_dx<2> one_end(k-2,k-2);
+
+		bool check = true;
+		count = 0;
+
+		// get the sub-domain iterator
+		auto dom = g_dist.getSubDomainIterator(one,one_end);
+
+		while (dom.isNext())
+		{
+			auto key = dom.get();
+			auto key_g = g_dist.getGKey(key);
+
+			// key_g should never be 1 or k-1
+			check &= (key_g.get(0) == 0 || key_g.get(0) == k-1)?false:true;
+			check &= (key_g.get(1) == 0 || key_g.get(1) == k-1)?false:true;
+
+			g_dist.template get<0>(key) = info.LinId(key_g);
+
+			// Count the point
+			count++;
+
+			++dom;
+		}
+
+		BOOST_REQUIRE_EQUAL(check,true);
+
+		//! [Usage of a sub_grid iterator]
+
+		}
+
+		// Get the virtual cluster machine
+		Vcluster & vcl = g_dist.getVC();
+
+		// reduce
+		vcl.sum(count);
+		vcl.execute();
+
+		// Check
+		BOOST_REQUIRE_EQUAL(count,(size_t)(k-2)*(k-2));
+
+		// check with a 1x1 square
+
+		{
+
+		grid_key_dx<2> one(k/2,k/2);
+		grid_key_dx<2> one_end(k/2,k/2);
+
+		count = 0;
+
+		// get the sub-domain iterator
+		auto dom = g_dist.getSubDomainIterator(one,one_end);
+
+		while (dom.isNext())
+		{
+			auto key = dom.get();
+			auto key_g = g_dist.getGKey(key);
+
+			// key_g
+			BOOST_REQUIRE_EQUAL(key_g.get(0),k/2);
+			BOOST_REQUIRE_EQUAL(key_g.get(1),k/2);
+
+			auto key_s_it = dom.getGKey(key);
+
+			BOOST_REQUIRE_EQUAL(key_g.get(0),key_s_it.get(0));
+			BOOST_REQUIRE_EQUAL(key_g.get(1),key_s_it.get(1));
+
+			// Count the point
+			count++;
+
+			++dom;
+		}
+
+		// reduce
+		vcl.sum(count);
+		vcl.execute();
+
+		BOOST_REQUIRE_EQUAL(count,1ul);
+		}
+	}
+}
+
+// Test decomposition grid iterator
+
+void Test3D_decit(const Box<3,float> & domain, long int k)
+{
+	size_t k_bck = k;
+	{
+		Vcluster & v_cl = create_vcluster();
+
+		if ( v_cl.getProcessingUnits() > 32 )
+			return;
+
+		long int big_step = k / 30;
+		big_step = (big_step == 0)?1:big_step;
+		long int small_step = 21;
+
+		print_test( "Testing grid iterator from decomposition k<=",k);
+
+		// 3D test
+		for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step )
+		{
+			BOOST_TEST_CHECKPOINT( "Testing grid iterator from decomposition k<=" << k );
+
+			// grid size
+			size_t sz[3];
+			sz[0] = k;
+			sz[1] = k;
+			sz[2] = k;
+
+			// factor
+			float factor = pow(create_vcluster().getProcessingUnits()/2.0f,1.0f/3.0f);
+
+			// Ghost
+			Ghost<3,float> g(0.01 / factor);
+
+			// Distributed grid with id decomposition
+			grid_dist_id<3, float, Point_test<float>, CartDecomposition<3,float>> g_dist(sz,domain,g);
+
+			// check the consistency of the decomposition
+			bool val = g_dist.getDecomposition().check_consistency();
+			BOOST_REQUIRE_EQUAL(val,true);
+
+			// Grid sm
+			grid_sm<3,void> info(sz);
+
+			auto dom = g_dist.getDomainIterator();
+
+			bool match = true;
+
+			// create a grid iterator from the decomposition
+
+			grid_dist_id_iterator_dec<CartDecomposition<3,float>> it_dec(g_dist.getDecomposition(),g_dist.getGridInfoVoid().getSize());
+
+			while (dom.isNext())
+			{
+				auto key = dom.get();
+				auto key_g = g_dist.getGKey(key);
+
+				auto key_dec = it_dec.get();
+
+				// Check if the two keys match
+				match &= (key_dec == key_g);
+
+				++dom;
+				++it_dec;
+			}
+
+			BOOST_REQUIRE_EQUAL(match,true);
+		}
+	}
+
+	k = k_bck;
+
+	{
+		Vcluster & v_cl = create_vcluster();
+
+		if ( v_cl.getProcessingUnits() > 32 )
+			return;
+
+		long int big_step = k / 30;
+		big_step = (big_step == 0)?1:big_step;
+		long int small_step = 21;
+
+		print_test( "Testing grid iterator from decomposition subset k<=",k);
+
+		// 3D test
+		for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step )
+		{
+			BOOST_TEST_CHECKPOINT( "Testing grid iterator from decomposition k<=" << k );
+
+			// grid size
+			size_t sz[3];
+			sz[0] = k;
+			sz[1] = k;
+			sz[2] = k;
+
+			// factor
+			float factor = pow(create_vcluster().getProcessingUnits()/2.0f,1.0f/3.0f);
+
+			// Ghost
+			Ghost<3,float> g(0.01 / factor);
+
+			// Distributed grid with id decomposition
+			grid_dist_id<3, float, Point_test<float>, CartDecomposition<3,float>> g_dist(sz,domain,g);
+
+			// check the consistency of the decomposition
+			bool val = g_dist.getDecomposition().check_consistency();
+			BOOST_REQUIRE_EQUAL(val,true);
+
+			// Grid sm
+			grid_sm<3,void> info(sz);
+
+			auto dom = g_dist.getSubDomainIterator({0,0,0},{(long int)sz[0]-2,(long int)sz[1]-2,(long int)sz[2]-2});
+
+			bool match = true;
+
+			// create a grid iterator from the decomposition
+
+			grid_dist_id_iterator_dec<CartDecomposition<3,float>> it_dec(g_dist.getDecomposition(),sz,{0,0,0},{sz[0]-2,sz[1]-2,sz[2]-2});
+
+			while (dom.isNext())
+			{
+				auto key = dom.get();
+				auto key_g = g_dist.getGKey(key);
+
+				auto key_dec = it_dec.get();
+
+				// Check if the two keys match
+				match &= (key_dec == key_g);
+
+				++dom;
+				++it_dec;
+			}
+
+			BOOST_REQUIRE_EQUAL(match,true);
+		}
+	}
+}
+
+
+// Test decomposition grid iterator
+
+void Test3D_decskinit(const Box<3,float> & domain, long int k)
+{
+	{
+		Vcluster & v_cl = create_vcluster();
+
+		if ( v_cl.getProcessingUnits() > 32 )
+			return;
+
+		long int big_step = k / 30;
+		big_step = (big_step == 0)?1:big_step;
+		long int small_step = 21;
+
+		print_test( "Testing grid skin iterator from decomposition k<=",k);
+
+		// 3D test
+		for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step )
+		{
+			BOOST_TEST_CHECKPOINT( "Testing grid skin iterator from decomposition k<=" << k );
+
+			// grid size
+			size_t sz[3];
+			sz[0] = k;
+			sz[1] = k;
+			sz[2] = k;
+
+			// factor
+			float factor = pow(create_vcluster().getProcessingUnits()/2.0f,1.0f/3.0f);
+
+			// Ghost
+			Ghost<3,float> g(0.01 / factor);
+
+			// Distributed grid with id decomposition
+			grid_dist_id<3, float, Point_test<float>, CartDecomposition<3,float>> g_dist(sz,domain,g);
+
+			// check the consistency of the decomposition
+			bool val = g_dist.getDecomposition().check_consistency();
+			BOOST_REQUIRE_EQUAL(val,true);
+
+			// Grid sm
+			grid_sm<3,void> info(sz);
+
+			// create a grid skin iterator from the decomposition
+
+			Box<3,size_t> A({3,3,3},{(size_t)k-3,(size_t)k-3,(size_t)k-3});
+			Box<3,size_t> B = A;
+
+			if (A.isValid() == false)
+				continue;
+
+			size_t bc[3] = {NON_PERIODIC,NON_PERIODIC,NON_PERIODIC};
+			grid_dist_id_iterator_dec_skin<CartDecomposition<3,float>> it_dec(g_dist.getDecomposition(),g_dist.getGridInfoVoid(),A,B,bc);
+
+			size_t cnt = 0;
+
+			bool tot_good = true;
+			while (it_dec.isNext())
+			{
+				auto key_dec = it_dec.get();
+
+				// one of the coordinate has to be or 3 or 8, none of
+				// None of the coordinates must be bigger that
+
+				bool eight_or_three = false;
+				bool good = true;
+				for (size_t i = 0; i < 3 ; i++)
+				{
+					if (key_dec.get(i) == 3 || key_dec.get(i) == k - 3)
+						eight_or_three = true;
+
+					if (key_dec.get(i) > k - 3 || key_dec.get(i) < 3 )
+						good = false;
+				}
+
+				tot_good &= (eight_or_three) || good;
+
+				cnt++;
+				++it_dec;
+			}
+
+			create_vcluster().sum(cnt);
+			create_vcluster().execute();
+
+			BOOST_REQUIRE_EQUAL(cnt,(size_t)((k-5)*(k-5)*(k-5) - (k-7)*(k-7)*(k-7)));
+			BOOST_REQUIRE_EQUAL(tot_good,true);
+		}
+	}
+}
+
+BOOST_AUTO_TEST_CASE( grid_dist_id_sub_iterator_test_use)
+{
+	// Domain
+	Box<2,float> domain({0.0,0.0},{1.0,1.0});
+
+	long int k = 1024*1024*create_vcluster().getProcessingUnits();
+	k = std::pow(k, 1/2.);
+
+	Test2D_sub(domain,k);
+}
+
+BOOST_AUTO_TEST_CASE( grid_dist_id_decomposition_iterator )
+{
+	// Domain
+	Box<3,float> domain3({0.0,0.0,0.0},{1.0,1.0,1.0});
+
+	size_t k = 128*128*128*create_vcluster().getProcessingUnits();
+	k = std::pow(k, 1/3.);
+	Test3D_decit(domain3,k);
+}
+
+BOOST_AUTO_TEST_CASE( grid_dist_it_iterators_skin_test )
+{
+	// Domain
+	Box<3,float> domain3({0.0,0.0,0.0},{1.0,1.0,1.0});
+
+	size_t k = 128*128*128*create_vcluster().getProcessingUnits();
+	k = std::pow(k, 1/3.);
+	Test3D_decskinit(domain3,k);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+#endif /* SRC_GRID_ITERATORS_GRID_DIST_ID_ITERATORS_UNIT_TESTS_HPP_ */
diff --git a/src/Grid/grid_dist_id.hpp b/src/Grid/grid_dist_id.hpp
index 66b25d9a..cfd6791e 100644
--- a/src/Grid/grid_dist_id.hpp
+++ b/src/Grid/grid_dist_id.hpp
@@ -7,9 +7,9 @@
 #include "VCluster/VCluster.hpp"
 #include "Space/SpaceBox.hpp"
 #include "util/mathutil.hpp"
-#include "grid_dist_id_iterator_dec.hpp"
-#include "grid_dist_id_iterator.hpp"
-#include "grid_dist_id_iterator_sub.hpp"
+#include "Iterators/grid_dist_id_iterator_dec.hpp"
+#include "Iterators/grid_dist_id_iterator.hpp"
+#include "Iterators/grid_dist_id_iterator_sub.hpp"
 #include "grid_dist_key.hpp"
 #include "NN/CellList/CellDecomposer.hpp"
 #include "util/object_util.hpp"
diff --git a/src/Grid/grid_dist_id_unit_test.cpp b/src/Grid/grid_dist_id_unit_test.cpp
index 08256477..82b89c5d 100644
--- a/src/Grid/grid_dist_id_unit_test.cpp
+++ b/src/Grid/grid_dist_id_unit_test.cpp
@@ -159,130 +159,6 @@ BOOST_AUTO_TEST_CASE( grid_dist_id_domain_grid_unit_converter_test)
 	}
 }
 
-void Test2D_sub(const Box<2,float> & domain, long int k)
-{
-	long int big_step = k / 30;
-	big_step = (big_step == 0)?1:big_step;
-	long int small_step = 21;
-
-	// this test is only performed when the number of processor is <= 32
-	if (create_vcluster().getProcessingUnits() > 32)
-		return;
-
-	print_test( "Testing 2D grid sub iterator k<=",k);
-
-	// 2D test
-	for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step )
-	{
-		BOOST_TEST_CHECKPOINT( "Testing 2D grid k=" << k );
-
-		// grid size
-		size_t sz[2];
-		sz[0] = k;
-		sz[1] = k;
-
-		float factor = pow(create_vcluster().getProcessingUnits()/2.0f,1.0f/2.0f);
-
-		// Ghost
-		Ghost<2,float> g(0.01 / factor);
-
-		// Distributed grid with id decomposition
-		grid_dist_id<2, float, scalar<float>> g_dist(sz,domain,g);
-
-		// check the consistency of the decomposition
-		bool val = g_dist.getDecomposition().check_consistency();
-		BOOST_REQUIRE_EQUAL(val,true);
-
-		size_t count;
-
-		// Grid sm
-		grid_sm<2,void> info(sz);
-
-		{
-		//! [Usage of a sub_grid iterator]
-
-		grid_key_dx<2> one(1,1);
-		grid_key_dx<2> one_end(k-2,k-2);
-
-		bool check = true;
-		count = 0;
-
-		// get the sub-domain iterator
-		auto dom = g_dist.getSubDomainIterator(one,one_end);
-
-		while (dom.isNext())
-		{
-			auto key = dom.get();
-			auto key_g = g_dist.getGKey(key);
-
-			// key_g should never be 1 or k-1
-			check &= (key_g.get(0) == 0 || key_g.get(0) == k-1)?false:true;
-			check &= (key_g.get(1) == 0 || key_g.get(1) == k-1)?false:true;
-
-			g_dist.template get<0>(key) = info.LinId(key_g);
-
-			// Count the point
-			count++;
-
-			++dom;
-		}
-
-		BOOST_REQUIRE_EQUAL(check,true);
-
-		//! [Usage of a sub_grid iterator]
-
-		}
-
-		// Get the virtual cluster machine
-		Vcluster & vcl = g_dist.getVC();
-
-		// reduce
-		vcl.sum(count);
-		vcl.execute();
-
-		// Check
-		BOOST_REQUIRE_EQUAL(count,(size_t)(k-2)*(k-2));
-
-		// check with a 1x1 square
-
-		{
-
-		grid_key_dx<2> one(k/2,k/2);
-		grid_key_dx<2> one_end(k/2,k/2);
-
-		count = 0;
-
-		// get the sub-domain iterator
-		auto dom = g_dist.getSubDomainIterator(one,one_end);
-
-		while (dom.isNext())
-		{
-			auto key = dom.get();
-			auto key_g = g_dist.getGKey(key);
-
-			// key_g
-			BOOST_REQUIRE_EQUAL(key_g.get(0),k/2);
-			BOOST_REQUIRE_EQUAL(key_g.get(1),k/2);
-
-			auto key_s_it = dom.getGKey(key);
-
-			BOOST_REQUIRE_EQUAL(key_g.get(0),key_s_it.get(0));
-			BOOST_REQUIRE_EQUAL(key_g.get(1),key_s_it.get(1));
-
-			// Count the point
-			count++;
-
-			++dom;
-		}
-
-		// reduce
-		vcl.sum(count);
-		vcl.execute();
-
-		BOOST_REQUIRE_EQUAL(count,1ul);
-		}
-	}
-}
 
 void Test2D(const Box<2,float> & domain, long int k)
 {
@@ -1325,143 +1201,6 @@ void Test3D_dup(const Box<3,float> & domain, long int k)
 	}
 }
 
-// Test decomposition grid iterator
-
-void Test3D_decit(const Box<3,float> & domain, long int k)
-{
-	size_t k_bck = k;
-	{
-		Vcluster & v_cl = create_vcluster();
-
-		if ( v_cl.getProcessingUnits() > 32 )
-			return;
-
-		long int big_step = k / 30;
-		big_step = (big_step == 0)?1:big_step;
-		long int small_step = 21;
-
-		print_test( "Testing grid iterator from decomposition k<=",k);
-
-		// 3D test
-		for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step )
-		{
-			BOOST_TEST_CHECKPOINT( "Testing grid iterator from decomposition k<=" << k );
-
-			// grid size
-			size_t sz[3];
-			sz[0] = k;
-			sz[1] = k;
-			sz[2] = k;
-
-			// factor
-			float factor = pow(create_vcluster().getProcessingUnits()/2.0f,1.0f/3.0f);
-
-			// Ghost
-			Ghost<3,float> g(0.01 / factor);
-
-			// Distributed grid with id decomposition
-			grid_dist_id<3, float, Point_test<float>, CartDecomposition<3,float>> g_dist(sz,domain,g);
-
-			// check the consistency of the decomposition
-			bool val = g_dist.getDecomposition().check_consistency();
-			BOOST_REQUIRE_EQUAL(val,true);
-
-			// Grid sm
-			grid_sm<3,void> info(sz);
-
-			auto dom = g_dist.getDomainIterator();
-
-			bool match = true;
-
-			// create a grid iterator from the decomposition
-
-			grid_dist_id_iterator_dec<CartDecomposition<3,float>> it_dec(g_dist.getDecomposition(),g_dist.getGridInfoVoid().getSize());
-
-			while (dom.isNext())
-			{
-				auto key = dom.get();
-				auto key_g = g_dist.getGKey(key);
-
-				auto key_dec = it_dec.get();
-
-				// Check if the two keys match
-				match &= (key_dec == key_g);
-
-				++dom;
-				++it_dec;
-			}
-
-			BOOST_REQUIRE_EQUAL(match,true);
-		}
-	}
-
-	k = k_bck;
-
-	{
-		Vcluster & v_cl = create_vcluster();
-
-		if ( v_cl.getProcessingUnits() > 32 )
-			return;
-
-		long int big_step = k / 30;
-		big_step = (big_step == 0)?1:big_step;
-		long int small_step = 21;
-
-		print_test( "Testing grid iterator from decomposition subset k<=",k);
-
-		// 3D test
-		for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step )
-		{
-			BOOST_TEST_CHECKPOINT( "Testing grid iterator from decomposition k<=" << k );
-
-			// grid size
-			size_t sz[3];
-			sz[0] = k;
-			sz[1] = k;
-			sz[2] = k;
-
-			// factor
-			float factor = pow(create_vcluster().getProcessingUnits()/2.0f,1.0f/3.0f);
-
-			// Ghost
-			Ghost<3,float> g(0.01 / factor);
-
-			// Distributed grid with id decomposition
-			grid_dist_id<3, float, Point_test<float>, CartDecomposition<3,float>> g_dist(sz,domain,g);
-
-			// check the consistency of the decomposition
-			bool val = g_dist.getDecomposition().check_consistency();
-			BOOST_REQUIRE_EQUAL(val,true);
-
-			// Grid sm
-			grid_sm<3,void> info(sz);
-
-			auto dom = g_dist.getSubDomainIterator({0,0,0},{(long int)sz[0]-2,(long int)sz[1]-2,(long int)sz[2]-2});
-
-			bool match = true;
-
-			// create a grid iterator from the decomposition
-
-			grid_dist_id_iterator_dec<CartDecomposition<3,float>> it_dec(g_dist.getDecomposition(),sz,{0,0,0},{sz[0]-2,sz[1]-2,sz[2]-2});
-
-			while (dom.isNext())
-			{
-				auto key = dom.get();
-				auto key_g = g_dist.getGKey(key);
-
-				auto key_dec = it_dec.get();
-
-				// Check if the two keys match
-				match &= (key_dec == key_g);
-
-				++dom;
-				++it_dec;
-			}
-
-			BOOST_REQUIRE_EQUAL(match,true);
-		}
-	}
-}
 
 // Test grid periodic
 
@@ -1765,16 +1504,6 @@ BOOST_AUTO_TEST_CASE( grid_dist_id_sub)
 	Test3D_sub(domain3,k);
 }
 
-BOOST_AUTO_TEST_CASE( grid_dist_id_sub_iterator_test_use)
-{
-	// Domain
-	Box<2,float> domain({0.0,0.0},{1.0,1.0});
-
-	long int k = 1024*1024*create_vcluster().getProcessingUnits();
-	k = std::pow(k, 1/2.);
-
-	Test2D_sub(domain,k);
-}
 
 BOOST_AUTO_TEST_CASE( grid_dist_id_with_grid_unit_ghost )
 {
@@ -1792,22 +1521,6 @@ BOOST_AUTO_TEST_CASE( grid_dist_id_with_grid_unit_ghost )
 	Test3D_gg(domain3,k,1);
 }
 
-BOOST_AUTO_TEST_CASE( grid_dist_id_decomposition_iterator )
-{
-	// Domain
-	Box<2,float> domain({0.0,0.0},{1.0,1.0});
-
-	long int k = 1024*1024*create_vcluster().getProcessingUnits();
-	k = std::pow(k, 1/2.);
-
-	// Domain
-	Box<3,float> domain3({0.0,0.0,0.0},{1.0,1.0,1.0});
-
-	k = 128*128*128*create_vcluster().getProcessingUnits();
-	k = std::pow(k, 1/3.);
-	Test3D_decit(domain3,k);
-}
-
 
 BOOST_AUTO_TEST_CASE( grid_dist_id_domain_test_use)
 {
diff --git a/src/Makefile.am b/src/Makefile.am
index 73184447..23d87159 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,8 +8,8 @@ pdata_LDADD = $(LINKLIBS) -lparmetis -lmetis
 nobase_include_HEADERS = Decomposition/CartDecomposition.hpp Decomposition/CartDecomposition_ext.hpp  Decomposition/common.hpp Decomposition/Decomposition.hpp  Decomposition/ie_ghost.hpp \
          Decomposition/Domain_NN_calculator_cart.hpp Decomposition/nn_processor.hpp Decomposition/ie_loc_ghost.hpp Decomposition/ORB.hpp \
          Graph/CartesianGraphFactory.hpp \
-         Grid/grid_dist_id.hpp Grid/grid_dist_id_iterator_dec.hpp Grid/grid_dist_util.hpp  Grid/grid_dist_id_iterator_sub.hpp Grid/grid_dist_id_iterator.hpp Grid/grid_dist_key.hpp Grid/staggered_dist_grid.hpp Grid/staggered_dist_grid_util.hpp Grid/staggered_dist_grid_copy.hpp \
-         Vector/vector_dist_multiphase_functions.hpp Vector/vector_dist_comm.hpp Vector/vector_dist.hpp Vector/vector_dist_ofb.hpp Vector/vector_dist_iterator.hpp Vector/vector_dist_key.hpp \
+         Grid/grid_dist_id.hpp Grid/Iterators/grid_dist_id_iterator_util.hpp Grid/Iterators/grid_dist_id_iterator_dec.hpp Grid/Iterators/grid_dist_id_iterator_dec_skin.hpp Grid/grid_dist_util.hpp  Grid/Iterators/grid_dist_id_iterator_sub.hpp Grid/Iterators/grid_dist_id_iterator.hpp Grid/grid_dist_key.hpp Grid/staggered_dist_grid.hpp Grid/staggered_dist_grid_util.hpp Grid/staggered_dist_grid_copy.hpp \
+         Vector/vector_dist_multiphase_functions.hpp Vector/vector_dist_comm.hpp Vector/vector_dist.hpp Vector/vector_dist_ofb.hpp Vector/Iterators/vector_dist_iterator.hpp Vector/vector_dist_key.hpp \
          config/config.h \
          example.mk \
          Decomposition/Distribution/metis_util.hpp Decomposition/Distribution/SpaceDistribution.hpp Decomposition/Distribution/parmetis_dist_util.hpp  Decomposition/Distribution/parmetis_util.hpp Decomposition/Distribution/MetisDistribution.hpp Decomposition/Distribution/ParMetisDistribution.hpp Decomposition/Distribution/DistParMetisDistribution.hpp  dec_optimizer.hpp SubdomainGraphNodes.hpp \
diff --git a/src/Vector/vector_dist_iterator.hpp b/src/Vector/Iterators/vector_dist_iterator.hpp
similarity index 97%
rename from src/Vector/vector_dist_iterator.hpp
rename to src/Vector/Iterators/vector_dist_iterator.hpp
index 20426a29..17bd3446 100644
--- a/src/Vector/vector_dist_iterator.hpp
+++ b/src/Vector/Iterators/vector_dist_iterator.hpp
@@ -8,7 +8,7 @@
 #ifndef VECTOR_DIST_ITERATOR_HPP_
 #define VECTOR_DIST_ITERATOR_HPP_
 
-#include "vector_dist_key.hpp"
+#include "Vector/vector_dist_key.hpp"
 #include "VCluster/VCluster.hpp"
 
 //! Iterator that Iterate across particle indexes
diff --git a/src/Vector/Iterators/vector_dist_iterator_skin.hpp b/src/Vector/Iterators/vector_dist_iterator_skin.hpp
new file mode 100644
index 00000000..c53d7ab9
--- /dev/null
+++ b/src/Vector/Iterators/vector_dist_iterator_skin.hpp
@@ -0,0 +1,15 @@
+/*
+ * vector_dist_iterator_skin.hpp
+ *
+ *  Created on: Jan 4, 2017
+ *      Author: i-bird
+ */
+
+#ifndef SRC_VECTOR_ITERATORS_VECTOR_DIST_ITERATOR_SKIN_HPP_
+#define SRC_VECTOR_ITERATORS_VECTOR_DIST_ITERATOR_SKIN_HPP_
+
+
+
+
+
+#endif /* SRC_VECTOR_ITERATORS_VECTOR_DIST_ITERATOR_SKIN_HPP_ */
diff --git a/src/Vector/vector_dist.hpp b/src/Vector/vector_dist.hpp
index bced135d..031a0d43 100644
--- a/src/Vector/vector_dist.hpp
+++ b/src/Vector/vector_dist.hpp
@@ -11,7 +11,7 @@
 #include "HDF5_XdmfWriter/HDF5_XdmfWriter.hpp"
 #include "VCluster/VCluster.hpp"
 #include "Space/Shape/Point.hpp"
-#include "Vector/vector_dist_iterator.hpp"
+#include "Vector/Iterators/vector_dist_iterator.hpp"
 #include "Space/Shape/Box.hpp"
 #include "Vector/vector_dist_key.hpp"
 #include "memory/PtrMemory.hpp"
@@ -23,7 +23,7 @@
 #include "CSVWriter/CSVWriter.hpp"
 #include "VTKWriter/VTKWriter.hpp"
 #include "Decomposition/common.hpp"
-#include "Grid/grid_dist_id_iterator_dec.hpp"
+#include "Grid/Iterators/grid_dist_id_iterator_dec.hpp"
 #include "Grid/grid_key_dx_iterator_hilbert.hpp"
 #include "Vector/vector_dist_ofb.hpp"
 #include "Decomposition/CartDecomposition.hpp"
diff --git a/src/main.cpp b/src/main.cpp
index c8c4a388..117f3256 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -31,8 +31,6 @@ int main(int argc, char* argv[])
 #include "Space/Shape/Box.hpp"
 #include "util.hpp"
 
-//using namespace openfpm;
-
 #include "unit_test_init_cleanup.hpp"
 #include "Graph/CartesianGraphFactory_unit_test.hpp"
 #include "Decomposition/CartDecomposition_unit_test.hpp"
@@ -41,6 +39,7 @@ int main(int argc, char* argv[])
 #include "dec_optimizer_unit_test.hpp"
 #include "Vector/vector_dist_unit_test.hpp"
 #include "Decomposition/Distribution/Distribution_unit_tests.hpp"
+#include "Grid/Iterators/grid_dist_id_iterators_unit_tests.hpp"
 //#include "DLB/DLB_unit_test.hpp"
 #include "Graph/dist_map_graph_unit_test.hpp"
 #include "Graph/DistGraphFactory.hpp"
-- 
GitLab