From cf8f5ab106fd61e167c78b9b3f3898e000b283a3 Mon Sep 17 00:00:00 2001
From: Pietro Incardona <i-bird@private-incardon-3.mpi-cbg.de>
Date: Mon, 7 Dec 2015 12:10:14 -0500
Subject: [PATCH] Small fixe and changes

---
 configure.ac                           | 23 +++++++++
 install                                | 69 +++++++++++++++++---------
 openfpm_numerics                       |  2 +-
 src/Grid/grid_dist_id.hpp              | 68 +++++++++++++++++++++++--
 src/Grid/grid_dist_id_iterator.hpp     | 38 ++++++++++++--
 src/Grid/grid_dist_id_iterator_sub.hpp | 10 ++--
 src/Grid/grid_dist_id_unit_test.hpp    |  9 ++++
 7 files changed, 179 insertions(+), 40 deletions(-)

diff --git a/configure.ac b/configure.ac
index 00c4690fc..bfa1a6701 100755
--- a/configure.ac
+++ b/configure.ac
@@ -33,6 +33,11 @@ m4_ifdef([AX_BOOST_BASE],,[m4_include([m4/ax_boost_base.m4])])
 m4_ifdef([AX_BOOST_IOSTREAMS],,[m4_include([m4/ax_boost_iostreams.m4])])
 m4_ifdef([AX_BOOST_PROGRAM_OPTIONS],,[m4_include([m4/ax_boost_program_options.m4])])
 m4_ifdef([AX_BOOST_UNIT_TEST_FRAMEWORK],,[m4_include([m4/ax_boost_unit_test_framework.m4])])
+m4_ifdef([AX_BLAS],,[m4_include([m4/ax_blas.m4])])
+m4_ifdef([AX_LAPACK],,[m4_include([m4/ax_lapack.m4])])
+m4_ifdef([AX_SUITESPARSE],,[m4_include([m4/ax_suitesparse.m4])])
+m4_ifdef([AX_EIGEN],,[m4_include([m4/ax_eigen.m4])])
+
 
 CXXFLAGS+=" --std=c++11 "
 NVCCFLAGS=" "
@@ -227,6 +232,24 @@ BOOST_CPPFLAGS=$(echo "$BOOST_CPPFLAGS" | sed -e 's/-I\/usr\/include[ \b]//g')
 AC_SUBST(BOOST_LDFLAGS)
 AC_SUBST(BOOST_CPPFLAGS)
 
+###### Checking for OpenBLAS
+
+AX_BLAS([],[echo "blas not found"
+                    exit 204])
+
+AX_LAPACK([],[echo "lapack not found"
+                    exit 204])
+
+###### Checking for SUITESPARSE
+
+AX_SUITESPARSE([],[echo "suitesparse not found"
+                    exit 205])
+
+###### Checking for EIGEN
+
+AX_EIGEN([],[echo "eigen not found"
+                    exit 206])
+
 ####### Checking for GPU support
 
 AX_CUDA
diff --git a/install b/install
index da99cc11f..ecc631cb6 100755
--- a/install
+++ b/install
@@ -124,6 +124,10 @@ echo -e "Installing requirements into: $i_dir "
 MPI_installed=0
 METIS_installed=0
 BOOST_installed=0
+LAPACK_installed=0
+SUITESPARSE_installed=0
+EIGEN_installed=0
+blas_options=""
 conf_err=1
 
 ## MPI
@@ -140,35 +144,15 @@ else
   fi
 fi
 
-## if a new compiler has been installed reinstall all the dependencies
-
-if [ x"$compiler_opt" != x"" ]; then
-  ./script/install_MPI.sh $i_dir $compiler_opt
-  export PATH="$PATH:$i_dir/MPI/bin"
-  configure_options="$configure_options CXX=mpic++ "
-  MPI_installed=1
-  ./script/install_BOOST.sh $i_dir $compiler_opt
-  configure_options=" $configure_options --with-boost=$i_dir/BOOST "
-  BOOST_installed=1
-  ./script/install_METIS.sh $i_dir $compiler_gcc $compiler_gpp
-  configure_options=" $configure_options --with-metis=$i_dir/METIS "
-  METIS_installed=1
-  ./script/install_SuiteSparse.sh $i_dir $compiler_opt
-  configure_options=" $configure_options --with-suitesparse=$i_dir/SUITESPARSE "
-  SUITESPARSE_installed=1
-  ./script/install_lapack.sh $i_dir $compiler_opt
-  configure_option="$configure_options --with-lapack=$i_dir/LAPACK"
-  LAPACK_installed=1
-fi
 
 echo "./configure $options $configure_options" 
 
 if [ $install_req -eq 0 ]; then
-    ./configure $options $configure_options
+    ./configure $options $configure_options "$blas_options"
 else
     while [ $conf_err -ne 0 ]
     do
-        ./configure $options $configure_options
+        ./configure $options $configure_options "$blas_options"
         conf_err=$?
 
 	echo "Configure script terminated with $conf_err"
@@ -208,7 +192,9 @@ else
                 echo "Error the installation of LAPACK failed"
                 exit 1
             fi
-            ./script/install_SUITESPARSE.sh $i_dir $compiler_opt
+            ./script/install_OPENBLAS.sh $i_dir $compiler_opt
+            LAPACK_installed=1
+            blas_options="--with-blas=-L/home/i-bird/OPENBLAS/lib/ -lopenblas"
         elif [ $conf_err -eq 205 ]; then
             echo "SuiteSparse not found try to install"
             if [ $SUITESPARSE_installed -eq 1  ]; then
@@ -216,6 +202,17 @@ else
                 exit 1
             fi
             ./script/install_SUITESPARSE.sh $i_dir $compiler_opt
+            configure_options=" $configure_options --with-suitesparse=$i_dir/SUITESPARSE "
+            SUITESPARSE_installed=1
+        elif [ $conf_err -eq 206 ]; then
+            echo "Eigen not found try to install"
+            if [ $EIGEN_installed -eq 1  ]; then
+                echo "Error the installation of Eigen failed"
+                exit 1
+            fi
+            ./script/install_EIGEN.sh $i_dir $compiler_opt
+            configure_options=" $configure_options --with-eigen=$i_dir/EIGEN "
+            EIGEN_installed=1
         elif [ $conf_err -ne 0 ]; then
             echo "I do not know how to recover from this error"
             exit 1
@@ -249,7 +246,7 @@ fi
 
 echo "Command used to configure"
 echo ""
-echo -e "\033[1m ./configure $options $configure_options \033[0m "
+echo -e "\033[1m ./configure $options $configure_options "$blas_options" \033[0m "
 echo ""
 if [ $MPI_installed -eq 1 ]; then
   echo -e "\033[1;34;5m ---------------------------------------  \033[0m"
@@ -290,6 +287,30 @@ if [ $BOOST_installed -eq 1 ]; then
     echo -e "\033[1m  export DYLD_LIBRARY_PATH=\"\$DYLD_LIBRARY_PATH:$i_dir/BOOST/lib\" \033[0m"
   fi
 fi
+if [ $LAPACK_installed -eq 1 ]; then
+  echo ""
+  echo -e "\033[1;34;5m ---------------------------------------  \033[0m"
+  echo -e "\033[1;34;5m --------------- OPENBLAS -------------- \033[0m"
+  echo -e "  OPENBLAS has been installed into: \033[1m $i_dir/OPENBLAS \033[0m"
+  echo ""
+  if [ x"$platform" = x"linux" ]; then
+    echo -e "\033[1m  export LD_LIBRARY_PATH=\"\$LD_LIBRARY_PATH:$i_dir/OPENBLAS/lib\" \033[0m "
+  else
+    echo -e "\033[1m  export DYLD_LIBRARY_PATH=\"\$DYLD_LIBRARY_PATH:$i_dir/OPENBLAS/lib\" \033[0m"
+  fi
+fi
+if [ $SUITESPARSE_installed -eq 1 ]; then
+  echo ""
+  echo -e "\033[1;34;5m ---------------------------------------  \033[0m"
+  echo -e "\033[1;34;5m ------------- SUITESPARSE ------------- \033[0m"
+  echo -e "  SUITESPARSE has been installed into: \033[1m $i_dir/SUITESPARSE \033[0m"
+  echo ""
+  if [ x"$platform" = x"linux" ]; then
+    echo -e "\033[1m  export LD_LIBRARY_PATH=\"\$LD_LIBRARY_PATH:$i_dir/SUITESPARSE/lib\" \033[0m "
+  else
+    echo -e "\033[1m  export DYLD_LIBRARY_PATH=\"\$DYLD_LIBRARY_PATH:$i_dir/SUITESPARSE/lib\" \033[0m"
+  fi
+fi
 echo ""
 echo ""
 if [ $conf_err -ne 0 ]; then
diff --git a/openfpm_numerics b/openfpm_numerics
index 32914d0aa..dfb8b8f7b 160000
--- a/openfpm_numerics
+++ b/openfpm_numerics
@@ -1 +1 @@
-Subproject commit 32914d0aad507eae2f82e3ac006e4bab42e9e3ed
+Subproject commit dfb8b8f7b56e455c3e1db0ff39e5d513055eb472
diff --git a/src/Grid/grid_dist_id.hpp b/src/Grid/grid_dist_id.hpp
index 9c859af9b..bd1e22a4b 100644
--- a/src/Grid/grid_dist_id.hpp
+++ b/src/Grid/grid_dist_id.hpp
@@ -484,6 +484,19 @@ public:
 	// Decomposition used
 	typedef Decomposition decomposition;
 
+	// value_type
+	typedef T value_type;
+
+	/*! \brief Return the total number of points in the grid
+	 *
+	 * \return number of points
+	 *
+	 */
+	size_t size() const
+	{
+		return ginfo_v.size();
+	}
+
 	static inline Ghost<dim,float> convert_ghost(const Ghost<dim,long int> & gd,const CellDecomposer_sm<dim,St> & cd_sm)
 	{
 		Ghost<dim,float> gc;
@@ -527,6 +540,16 @@ public:
 		InitializeStructures(g_sz);
 	}
 
+    /*! \brief Get the spacing of the grid in direction i
+     *
+     * \return the spacing
+     *
+     */
+    inline St spacing(size_t i) const
+    {
+    	return cd_sm.getCellBox().getHigh(i);
+    }
+
 	/*! \brief Constrcuctor
 	 *
 	 * \param g_sz array with the grid size on each dimension
@@ -639,7 +662,7 @@ public:
 	 * \return an information object about this grid
 	 *
 	 */
-	const grid_sm<dim,T> & getGridInfo()
+	const grid_sm<dim,T> & getGridInfo() const
 	{
 		return ginfo;
 	}
@@ -649,7 +672,7 @@ public:
 	 * \return an information object about this grid
 	 *
 	 */
-	const grid_sm<dim,void> & getGridInfoVoid()
+	const grid_sm<dim,void> & getGridInfoVoid() const
 	{
 		return ginfo_v;
 	}
@@ -724,7 +747,12 @@ public:
 	 */
 	grid_dist_iterator<dim,device_grid,FREE> getDomainIterator()
 	{
-		grid_dist_iterator<dim,device_grid,FREE> it(loc_grid,gdb_ext);
+		grid_key_dx<dim> stop(ginfo_v.getSize());
+		grid_key_dx<dim> one;
+		one.one();
+		stop = stop - one;
+
+		grid_dist_iterator<dim,device_grid,FREE> it(loc_grid,gdb_ext,stop);
 
 		return it;
 	}
@@ -733,7 +761,7 @@ public:
 	 *
 	 *
 	 */
-	grid_dist_iterator<dim,device_grid,FIXED> getDomainGhostIterator()
+	grid_dist_iterator<dim,device_grid,FIXED> getDomainGhostIterator() const
 	{
 		grid_dist_iterator<dim,device_grid,FIXED> it(loc_grid,gdb_ext);
 
@@ -743,17 +771,37 @@ public:
 	/*! \brief It return an iterator that span the grid domain only in the specified
 	 * part
 	 *
+	 * The key spanned are the one inside the box spanned by the start point and the end
+	 * point included
+	 *
 	 * \param start point
 	 * \param stop point
 	 *
 	 */
-	grid_dist_iterator_sub<dim,device_grid> getSubDomainIterator(const grid_key_dx<dim> & start, const grid_key_dx<dim> & stop)
+	grid_dist_iterator_sub<dim,device_grid> getSubDomainIterator(const grid_key_dx<dim> & start, const grid_key_dx<dim> & stop) const
 	{
 		grid_dist_iterator_sub<dim,device_grid> it(start,stop,loc_grid,gdb_ext);
 
 		return it;
 	}
 
+	/*! \brief It return an iterator that span the grid domain only in the specified
+	 * part
+	 *
+	 * The key spanned are the one inside the box spanned by the start point and the end
+	 * point included
+	 *
+	 * \param start point
+	 * \param stop point
+	 *
+	 */
+	grid_dist_iterator_sub<dim,device_grid> getSubDomainIterator(const long int (& start)[dim], const long int (& stop)[dim]) const
+	{
+		grid_dist_iterator_sub<dim,device_grid> it(grid_key_dx<dim>(start),grid_key_dx<dim>(stop),loc_grid,gdb_ext);
+
+		return it;
+	}
+
 	//! Destructor
 	~grid_dist_id()
 	{
@@ -771,6 +819,16 @@ public:
 		return v_cl;
 	}
 
+	/*! \brief Indicate that this grid is not staggered
+	 *
+	 * \return false
+	 *
+	 */
+	bool is_staggered()
+	{
+		return false;
+	}
+
 	/*! \brief Get the reference of the selected element
 	 *
 	 * \param p property to get (is an integer)
diff --git a/src/Grid/grid_dist_id_iterator.hpp b/src/Grid/grid_dist_id_iterator.hpp
index f7b64159c..56ba2ea60 100644
--- a/src/Grid/grid_dist_id_iterator.hpp
+++ b/src/Grid/grid_dist_id_iterator.hpp
@@ -93,8 +93,8 @@ class grid_dist_iterator<dim,device_grid,FREE>
 	//! Actual iterator
 	grid_key_dx_iterator_sub<dim> a_it;
 
-	//! margin of the grid iterator
-	size_t m;
+	//! stop point (is the grid size)
+	grid_key_dx<dim> stop;
 
 	/*! \brief from g_c increment g_c until you find a valid grid
 	 *
@@ -124,7 +124,7 @@ class grid_dist_iterator<dim,device_grid,FREE>
 		gList = tmp.gList;
 		gdb_ext = tmp.gdb_ext;
 		a_it.reinitialize(tmp.a_it);
-		m = tmp.m;
+		stop = tmp.stop;
 
 		return *this;
 	}
@@ -134,8 +134,8 @@ class grid_dist_iterator<dim,device_grid,FREE>
 	 * \param gk std::vector of the local grid
 	 *
 	 */
-	grid_dist_iterator(Vcluster_object_array<device_grid> & gk, openfpm::vector<GBoxes<device_grid::dims>> & gdb_ext)
-	:g_c(0),gList(gk),gdb_ext(gdb_ext),m(0)
+	grid_dist_iterator(Vcluster_object_array<device_grid> & gk, openfpm::vector<GBoxes<device_grid::dims>> & gdb_ext, grid_key_dx<dim> stop)
+	:g_c(0),gList(gk),gdb_ext(gdb_ext),stop(stop)
 	{
 		// Initialize the current iterator
 		// with the first grid
@@ -196,6 +196,34 @@ class grid_dist_iterator<dim,device_grid,FREE>
 	{
 		return grid_dist_key_dx<dim>(g_c,a_it.get());
 	}
+
+	/*! \brief it return the stop point of the iterator
+	 *
+	 * The stop point of the iterator is just the grid size
+	 *
+	 * \return the stop point
+	 *
+	 */
+	inline grid_key_dx<dim> getStop() const
+	{
+		return stop;
+	}
+
+	/*! \brief it return the start point of the iterator
+	 *
+	 * The start point of the iterator is the point with all coordinates zeros
+	 *
+	 * \return the start point
+	 *
+	 */
+	inline grid_key_dx<dim> getStart() const
+	{
+		grid_key_dx<dim> start;
+
+		start.zero();
+
+		return start;
+	}
 };
 
 
diff --git a/src/Grid/grid_dist_id_iterator_sub.hpp b/src/Grid/grid_dist_id_iterator_sub.hpp
index 11ac7cc10..4ae562c8a 100644
--- a/src/Grid/grid_dist_id_iterator_sub.hpp
+++ b/src/Grid/grid_dist_id_iterator_sub.hpp
@@ -34,10 +34,10 @@ class grid_dist_iterator_sub
 	size_t g_c;
 
 	//! List of the grids we are going to iterate
-	Vcluster_object_array<device_grid> & gList;
+	const Vcluster_object_array<device_grid> & gList;
 
 	//! Extension of each grid: domain and ghost + domain
-	openfpm::vector<GBoxes<device_grid::dims>> & gdb_ext;
+	const openfpm::vector<GBoxes<device_grid::dims>> & gdb_ext;
 
 	//! Actual iterator
 	grid_key_dx_iterator_sub<dim> a_it;
@@ -144,7 +144,7 @@ class grid_dist_iterator_sub
 	 * \param gdb_ext information about the local grids
 	 *
 	 */
-	grid_dist_iterator_sub(const grid_key_dx<dim> & start, const grid_key_dx<dim> & stop ,Vcluster_object_array<device_grid> & gk, openfpm::vector<GBoxes<device_grid::dims>> & gdb_ext)
+	grid_dist_iterator_sub(const grid_key_dx<dim> & start, const grid_key_dx<dim> & stop ,const Vcluster_object_array<device_grid> & gk, const openfpm::vector<GBoxes<device_grid::dims>> & gdb_ext)
 	:g_c(0),gList(gk),gdb_ext(gdb_ext),start(start),stop(stop),m(0)
 	{
 		// Initialize the current iterator
@@ -233,7 +233,7 @@ class grid_dist_iterator_sub
 	 * \return the starting point
 	 *
 	 */
-	inline grid_key_dx<dim> getStart()
+	inline grid_key_dx<dim> getStart() const
 	{
 		return start;
 	}
@@ -243,7 +243,7 @@ class grid_dist_iterator_sub
 	 * \return the stop point
 	 *
 	 */
-	inline grid_key_dx<dim> getStop()
+	inline grid_key_dx<dim> getStop() const
 	{
 		return stop;
 	}
diff --git a/src/Grid/grid_dist_id_unit_test.hpp b/src/Grid/grid_dist_id_unit_test.hpp
index 2c17ed99f..27bb837e9 100644
--- a/src/Grid/grid_dist_id_unit_test.hpp
+++ b/src/Grid/grid_dist_id_unit_test.hpp
@@ -268,6 +268,15 @@ void Test2D(const Box<2,float> & domain, long int k)
 
 		auto dom2 = g_dist.getDomainIterator();
 
+		grid_key_dx<2> start = dom2.getStart();
+		grid_key_dx<2> stop = dom2.getStop();
+
+		BOOST_REQUIRE_EQUAL(stop.get(0),g_dist.size(0));
+		BOOST_REQUIRE_EQUAL(stop.get(1),g_dist.size(1));
+
+		BOOST_REQUIRE_EQUAL(start.get(0),0);
+		BOOST_REQUIRE_EQUAL(start.get(1),0);
+
 		bool match = true;
 
 		// check that the grid store the correct information
-- 
GitLab