From fdf82a8becef6dfda34e2ed33dcad79dff2bcdec Mon Sep 17 00:00:00 2001
From: Pietro Incardona <incardon@mpi-cbg.de>
Date: Sat, 14 Apr 2018 19:46:38 +0200
Subject: [PATCH] example fixed

---
 CHANGELOG.md                                  |  4 ++--
 example/Debugging/1_classes/main.cpp          |  3 +--
 example/Grid/3_gray_scott_3d/main.cpp         | 16 +++++++-------
 .../3_gray_scott_3d_vectorization/main.cpp    |  2 +-
 .../PSE/0_Derivative_approx_1D/main.cpp       |  2 +-
 example/Vector/1_HDF5_save_load/Makefile      |  2 +-
 .../Vector/3_molecular_dynamic/main_vl.cpp    |  4 ++--
 example/Vector/4_complex_prop/Makefile        |  2 +-
 example/Vector/4_complex_prop/main_ser.cpp    | 18 ++++++++++++++-
 .../4_multiphase_celllist_verlet/Makefile     |  2 +-
 .../4_multiphase_celllist_verlet/main.cpp     |  6 ++++-
 .../Vector/5_molecular_dynamic_sym/main.cpp   |  6 +++--
 .../5_molecular_dynamic_sym_crs/main.cpp      | 10 +++++----
 .../Distribution/parmetis_util.hpp            | 22 +++++++++----------
 src/Grid/Iterators/grid_dist_id_iterator.hpp  | 15 -------------
 15 files changed, 61 insertions(+), 53 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index f180e501..781548f8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,9 +9,9 @@ All notable changes to this project will be documented in this file.
 - Increaded performance for grid ghost get
 - Introduced forms to increase the performance of the grid iterator in case of stencil code (see example 5_GrayScott)
 - EMatrix wrapped eigen matrices compatibles with vector_dist_id
-- General tuning for high dimension vector_dist_id (up to 50 dimensions)
+- General tuning for high dimension vector_dist_id (up to 50 dimensions) + PS_CMA_ES (Particle-Swarm Covariant Matrix Adaptation Evolution Strategy) example in Numerics
 - Added Discrete element Method example (8_DEM)
-- Introduced map(LOCAL) for fast communication in case we have small moovement
+- Introduced map(LOCAL) for fast communication in case we have small movement
 
 ### Fixed
 
diff --git a/example/Debugging/1_classes/main.cpp b/example/Debugging/1_classes/main.cpp
index 1662be01..bb95b45c 100644
--- a/example/Debugging/1_classes/main.cpp
+++ b/example/Debugging/1_classes/main.cpp
@@ -17,7 +17,6 @@
 #define SE_CLASS3
 #define THROW_ON_ERROR
 #include "Memleak_check.hpp"
-#include "data_type/scalar.hpp"
 #include "Grid/grid_dist_id.hpp"
 #include "Decomposition/CartDecomposition.hpp"
 #include "Point_test.hpp"
@@ -72,7 +71,7 @@ int main(int argc, char* argv[])
 	// * g: ghost extension
 	//
 	//
-	grid_dist_id<3, float, scalar<float[3]>, CartDecomposition<3,float>> * g_dist = new grid_dist_id<3, float, scalar<float[3]>, CartDecomposition<3,float>>(sz,domain,g);
+	grid_dist_id<3, float, aggregate<float[3]>, CartDecomposition<3,float>> * g_dist = new grid_dist_id<3, float, aggregate<float[3]> >(sz,domain,g);
 
 	//
 	// ### WIKI 6 ###
diff --git a/example/Grid/3_gray_scott_3d/main.cpp b/example/Grid/3_gray_scott_3d/main.cpp
index 7c7e8f4f..474a6d3d 100644
--- a/example/Grid/3_gray_scott_3d/main.cpp
+++ b/example/Grid/3_gray_scott_3d/main.cpp
@@ -166,7 +166,7 @@ int main(int argc, char* argv[])
 	for (size_t i = 0; i < timeSteps; ++i)
 	{
 		if (i % 300 == 0)
-			std::cout << "STEP: " << i << std::endl;
+		{std::cout << "STEP: " << i << std::endl;}
 
 		//! \cond [stencil get and use] \endcond
 
@@ -175,15 +175,15 @@ int main(int argc, char* argv[])
 		while (it.isNext())
 		{
 			// center point
-			auto Cp = it.getStencilGrid<0>();
+			auto Cp = it.getStencil<0>();
 
 			// plus,minus X,Y,Z
-			auto mx = it.getStencilGrid<1>();
-			auto px = it.getStencilGrid<2>();
-			auto my = it.getStencilGrid<3>();
-			auto py = it.getStencilGrid<4>();
-			auto mz = it.getStencilGrid<5>();
-			auto pz = it.getStencilGrid<6>();
+			auto mx = it.getStencil<1>();
+			auto px = it.getStencil<2>();
+			auto my = it.getStencil<3>();
+			auto py = it.getStencil<4>();
+			auto mz = it.getStencil<5>();
+			auto pz = it.getStencil<6>();
 
 			// update based on Eq 2
 			New.get<U>(Cp) = Old.get<U>(Cp) + uFactor * (
diff --git a/example/Grid/3_gray_scott_3d_vectorization/main.cpp b/example/Grid/3_gray_scott_3d_vectorization/main.cpp
index f153be0d..8b7596cf 100644
--- a/example/Grid/3_gray_scott_3d_vectorization/main.cpp
+++ b/example/Grid/3_gray_scott_3d_vectorization/main.cpp
@@ -167,7 +167,7 @@ void step(grid_dist_id<3, double, aggregate<double>> & OldU,
 
 			out1.store(&U_new.get<0>(Cp),Vc::Unaligned);
 			out2.store(&V_new.get<0>(Cp),Vc::Unaligned);
-	END_LOOP_M
+	END_LOOP_M(Vc::double_v::Size)
 
 	//! \cond [cpp_update] \endcond
 
diff --git a/example/Numerics/PSE/0_Derivative_approx_1D/main.cpp b/example/Numerics/PSE/0_Derivative_approx_1D/main.cpp
index 06007039..5471efad 100644
--- a/example/Numerics/PSE/0_Derivative_approx_1D/main.cpp
+++ b/example/Numerics/PSE/0_Derivative_approx_1D/main.cpp
@@ -100,7 +100,7 @@ int main(int argc, char* argv[])
 	// we create a set of N+1 particles to have a fully covered domain of particles between 0.0 and 4.0
 	// Suppose we have a spacing given by 1.0 you need 4 +1 particles to cover your domain
 	//
-	vector_dist<1,double, aggregate<double>, CartDecomposition<1,double> > vd(Npart+1,box,bc,g);
+	vector_dist<1,double, aggregate<double> > vd(Npart+1,box,bc,g);
 
 	//
 	// ### WIKI 4 ###
diff --git a/example/Vector/1_HDF5_save_load/Makefile b/example/Vector/1_HDF5_save_load/Makefile
index 32fc2c54..703912df 100644
--- a/example/Vector/1_HDF5_save_load/Makefile
+++ b/example/Vector/1_HDF5_save_load/Makefile
@@ -11,7 +11,7 @@ all: hdf5
 
 
 %.o: %.cpp
-	$(CC) -O0 $(OPT) -g -c --std=c++11 -o $@ $< $(INCLUDE_PATH)
+	$(CC) -O3 $(OPT) -g -c --std=c++11 -o $@ $< $(INCLUDE_PATH)
 
 hdf5: $(OBJ)
 	$(CC) -o $@ $^ $(CFLAGS) $(LIBS_PATH) $(LIBS)
diff --git a/example/Vector/3_molecular_dynamic/main_vl.cpp b/example/Vector/3_molecular_dynamic/main_vl.cpp
index c039c991..a3db6257 100644
--- a/example/Vector/3_molecular_dynamic/main_vl.cpp
+++ b/example/Vector/3_molecular_dynamic/main_vl.cpp
@@ -62,7 +62,7 @@ constexpr int force = 1;
 
 //! \cond [arg diff] \endcond
 
-void calc_forces(vector_dist<3,double, aggregate<double[3],double[3]> > & vd, VerletList<3, double, FAST, shift<3, double> > & NN, double sigma12, double sigma6, double r_cut)
+void calc_forces(vector_dist<3,double, aggregate<double[3],double[3]> > & vd, VerletList<3, double, Mem_fast<>, shift<3, double> > & NN, double sigma12, double sigma6, double r_cut)
 {
 	//! \cond [arg diff] \endcond
 
@@ -150,7 +150,7 @@ void calc_forces(vector_dist<3,double, aggregate<double[3],double[3]> > & vd, Ve
 
 //! \cond [calc energy vl] \endcond
 
-double calc_energy(vector_dist<3,double, aggregate<double[3],double[3]> > & vd, VerletList<3, double, FAST, shift<3, double> > & NN, double sigma12, double sigma6, double r_cut)
+double calc_energy(vector_dist<3,double, aggregate<double[3],double[3]> > & vd, VerletList<3, double, Mem_fast<>, shift<3, double> > & NN, double sigma12, double sigma6, double r_cut)
 {
 	double E = 0.0;
 
diff --git a/example/Vector/4_complex_prop/Makefile b/example/Vector/4_complex_prop/Makefile
index 2de12f95..32a3dea5 100644
--- a/example/Vector/4_complex_prop/Makefile
+++ b/example/Vector/4_complex_prop/Makefile
@@ -10,7 +10,7 @@ OBJ_SER = main_ser.o
 all: vect_cp vect_ser
 
 %.o: %.cpp
-	$(CC) -O3 -c --std=c++11 -o $@ $< $(INCLUDE_PATH)
+	$(CC) -O0 -c --std=c++11 -o $@ $< $(INCLUDE_PATH)
 
 vect_cp: $(OBJ)
 	$(CC) -o $@ $^ $(CFLAGS) $(LIBS_PATH) $(LIBS)
diff --git a/example/Vector/4_complex_prop/main_ser.cpp b/example/Vector/4_complex_prop/main_ser.cpp
index 94868acb..0089bbc5 100644
--- a/example/Vector/4_complex_prop/main_ser.cpp
+++ b/example/Vector/4_complex_prop/main_ser.cpp
@@ -112,6 +112,15 @@ public:
 
 	//! \cond [pack request] \endcond
 
+	//! \cond [noPointers] \endcond
+
+	static bool noPointers()
+	{
+		return false;
+	}
+
+	//! \cond [noPointers] \endcond
+
 	//! \cond [pack serialize] \endcond
 
 	//! Serialize the data structure
@@ -210,11 +219,12 @@ public:
  *
  * \page Vector_4_complex_prop_ser Vector 4 property serialization
  *
- * In order to make my_struct serializable we need 3 methods
+ * In order to make my_struct serializable we need 4 methods
  *
  * * **packRequest** This method indicate how many byte are needed to serialize this structure
  * * **pack** This method serialize the data-structure
  * * **unpack** This method de-serialize the data structure
+ * * **noPointers()** a static method that inform the OpenFPM sub-system that the structure has no pointers inside 
  *
  * ### packRequest ###
  *
@@ -294,6 +304,12 @@ public:
  *
  * \snippet Vector/4_complex_prop/main_ser.cpp unpacker ser other
  *
+ * ### noPointers ###
+ *
+ * This method inform the sub-system that the custom structure does not have pointers
+ *
+ * \snippet Vector/4_complex_prop/main_ser.cpp noPointers
+ *
  * ### Constructor and destructor and operator= ###
  *
  * Constructor and destructor are not releated to serialization and de-serialization concept.
diff --git a/example/Vector/4_multiphase_celllist_verlet/Makefile b/example/Vector/4_multiphase_celllist_verlet/Makefile
index e14eedbb..4c82311a 100644
--- a/example/Vector/4_multiphase_celllist_verlet/Makefile
+++ b/example/Vector/4_multiphase_celllist_verlet/Makefile
@@ -7,7 +7,7 @@ LDIR =
 OBJ = main.o
 
 %.o: %.cpp
-	$(CC) -O3 -g -c --std=c++11 -o $@ $< $(INCLUDE_PATH)
+	$(CC) -O0 -g -c --std=c++11 -o $@ $< $(INCLUDE_PATH)
 
 multip: $(OBJ)
 	$(CC) -o $@ $^ $(CFLAGS) $(LIBS_PATH) $(LIBS)
diff --git a/example/Vector/4_multiphase_celllist_verlet/main.cpp b/example/Vector/4_multiphase_celllist_verlet/main.cpp
index cfa51c31..0f2fcc79 100644
--- a/example/Vector/4_multiphase_celllist_verlet/main.cpp
+++ b/example/Vector/4_multiphase_celllist_verlet/main.cpp
@@ -237,7 +237,11 @@ int main(int argc, char* argv[])
 	//! \cond [create multi-phase multi verlet] \endcond
 
 	// This function create an "Empty" Multiphase Cell List from all the phases
-	auto CL_all = createCellListM<2>(phases,r_cut);
+
+	// We just create a cell list with slightly bigget r_cut to avoid error in Verlet creation
+	// because of round off errors
+	float r_cut2 = r_cut*1.00001;
+	auto CL_all = createCellListM<2>(phases,r_cut2);
 
 	// This create a Verlet-list between phase0 and all the other phases
 	auto NNver0_all = createVerletM<2>(0,phases.get(0),phases,CL_all,r_cut);
diff --git a/example/Vector/5_molecular_dynamic_sym/main.cpp b/example/Vector/5_molecular_dynamic_sym/main.cpp
index 4225ae30..0d35dba8 100644
--- a/example/Vector/5_molecular_dynamic_sym/main.cpp
+++ b/example/Vector/5_molecular_dynamic_sym/main.cpp
@@ -76,7 +76,8 @@ constexpr int force = 1;
 
 //! \cond [calc forces vl] \endcond
 
-void calc_forces(vector_dist<3,double, aggregate<double[3],double[3]> > & vd, VerletList<3, double, FAST, shift<3, double> > & NN, double sigma12, double sigma6, double r_cut)
+template<typename VerletList>
+void calc_forces(vector_dist<3,double, aggregate<double[3],double[3]> > & vd, VerletList & NN, double sigma12, double sigma6, double r_cut)
 {
 	// Reset force on the ghost
 
@@ -186,7 +187,8 @@ void calc_forces(vector_dist<3,double, aggregate<double[3],double[3]> > & vd, Ve
 
 //! \cond [calc energy vl] \endcond
 
-double calc_energy(vector_dist<3,double, aggregate<double[3],double[3]> > & vd, VerletList<3, double, FAST, shift<3, double> > & NN, double sigma12, double sigma6, double r_cut)
+template<typename VerletList>
+double calc_energy(vector_dist<3,double, aggregate<double[3],double[3]> > & vd, VerletList & NN, double sigma12, double sigma6, double r_cut)
 {
 	double E = 0.0;
 
diff --git a/example/Vector/5_molecular_dynamic_sym_crs/main.cpp b/example/Vector/5_molecular_dynamic_sym_crs/main.cpp
index 7983316c..8697222c 100644
--- a/example/Vector/5_molecular_dynamic_sym_crs/main.cpp
+++ b/example/Vector/5_molecular_dynamic_sym_crs/main.cpp
@@ -127,7 +127,8 @@ constexpr int force = 1;
 
 //! \cond [calc forces vl] \endcond
 
-void calc_forces(vector_dist<3,double, aggregate<double[3],double[3]> > & vd, VerletList<3, double, FAST, shift<3, double> > & NN, double sigma12, double sigma6, double r_cut)
+template<typename VerletList>
+void calc_forces(vector_dist<3,double, aggregate<double[3],double[3]> > & vd, VerletList & NN, double sigma12, double sigma6, double r_cut)
 {
 	// Reset force on the ghost
 
@@ -163,7 +164,7 @@ void calc_forces(vector_dist<3,double, aggregate<double[3],double[3]> > & vd, Ve
 
 		// Get an iterator over the neighborhood particles of p
 		// Note that in case of symmetric
-		auto Np = NN.getNNIterator<NO_CHECK>(p);
+		auto Np = NN.template getNNIterator<NO_CHECK>(p);
 
 		// For each neighborhood particle ...
 		while (Np.isNext())
@@ -242,7 +243,8 @@ void calc_forces(vector_dist<3,double, aggregate<double[3],double[3]> > & vd, Ve
 
 //! \cond [calc energy vl] \endcond
 
-double calc_energy(vector_dist<3,double, aggregate<double[3],double[3]> > & vd, VerletList<3, double, FAST, shift<3, double> > & NN, double sigma12, double sigma6, double r_cut)
+template<typename VerletList>
+double calc_energy(vector_dist<3,double, aggregate<double[3],double[3]> > & vd, VerletList & NN, double sigma12, double sigma6, double r_cut)
 {
 	double E = 0.0;
 
@@ -262,7 +264,7 @@ double calc_energy(vector_dist<3,double, aggregate<double[3],double[3]> > & vd,
 		Point<3,double> xp = vd.getPos(p);
 
 		// Get an iterator over the neighborhood particles of p
-		auto Np = NN.getNNIterator<NO_CHECK>(p);
+		auto Np = NN.template getNNIterator<NO_CHECK>(p);
 
 		double Ep = E;
 
diff --git a/src/Decomposition/Distribution/parmetis_util.hpp b/src/Decomposition/Distribution/parmetis_util.hpp
index c34bc34a..68fbf891 100755
--- a/src/Decomposition/Distribution/parmetis_util.hpp
+++ b/src/Decomposition/Distribution/parmetis_util.hpp
@@ -14,7 +14,7 @@
 #include "VCluster/VCluster.hpp"
 #include "Graph/ids.hpp"
 
-#define PARMETSI_ERROR_OBJECT std::runtime_error("Runtime Parmetis error");
+#define PARMETIS_ERROR_OBJECT std::runtime_error("Runtime Parmetis error");
 
 
 /*! \brief Metis graph structure
@@ -213,6 +213,16 @@ public:
 	Parmetis(Vcluster & v_cl, size_t nc)
 	:v_cl(v_cl), nc(nc),n_dec(0)
 	{
+#ifdef SE_CLASS1
+
+		if (sizeof(idx_t) != 8)
+		{
+			std::cerr << __FILE__ << ":" << __LINE__ << " Error detected invalid installation of Parmetis. OpenFPM support Parmetis/Metis version with 64 bit idx_t" << std::endl;
+			ACTION_ON_ERROR(PARMETIS_ERROR_OBJECT);
+		}
+
+#endif
+
 		// TODO Move into VCluster
 		MPI_Comm_dup(MPI_COMM_WORLD, &comm);
 
@@ -246,16 +256,6 @@ public:
 	 */
 	~Parmetis()
 	{
-#ifdef SE_CLASS1
-
-		if (sizeof(idx_t) != 8)
-		{
-			std::cerr << __FILE__ << ":" << __LINE__ << " Error detected invalid installation of Parmetis. OpenFPM support Parmetis/Metis version with 64 bit idx_t" << std::endl;
-			ACTION_ON_ERROR(PARMETIS_ERROR_OBJECT);
-		}
-
-#endif
-
 		// Deallocate the Mg structure
 		if (Mg.nvtxs != NULL)
 		{
diff --git a/src/Grid/Iterators/grid_dist_id_iterator.hpp b/src/Grid/Iterators/grid_dist_id_iterator.hpp
index 60cb2e0c..7c3ca85e 100644
--- a/src/Grid/Iterators/grid_dist_id_iterator.hpp
+++ b/src/Grid/Iterators/grid_dist_id_iterator.hpp
@@ -59,9 +59,6 @@ class grid_dist_iterator<dim,device_grid,FREE,stencil>
 	//! stop point (is the grid size)
 	grid_key_dx<dim> stop;
 
-	// device grid pointer
-	device_grid * dg;
-
 	/*! \brief from g_c increment g_c until you find a valid grid
 	 *
 	 */
@@ -244,18 +241,6 @@ class grid_dist_iterator<dim,device_grid,FREE,stencil>
 	{
 		return grid_dist_lin_dx(g_c,a_it.template getStencil<id>());
 	}
-
-	/*! \brief Return the stencil point offset
-	 *
-	 * \tparam id
-	 *
-	 * \return linearized distributed key
-	 *
-	 */
-	template<unsigned int id> inline grid_dist_g_dx<device_grid> getStencilGrid()
-	{
-		return grid_dist_g_dx<device_grid>(dg,a_it.template getStencil<id>());
-	}
 };
 
 
-- 
GitLab