Commit cc8365cf authored by incardon's avatar incardon

Adding missing testing files

parent 81970c3e
# Change Log # Change Log
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## [1.1.0] ## [1.1.0] February 2018
### Added ### Added
- Interface for Multi-vector dynamic load balancing - Interface for Multi-vector dynamic load balancing
- Added Verlet List with balanced Memory and wise memory form
- Increaded performance for grid ghost get - 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) - 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)
- Added Discrete element Method example (8_DEM)
### Fixed ### Fixed
- Installation/detection of PETSC - Installation/detection of PETSC
- 2D Fixing IO in binary for vector - Fixing 2D IO in binary for vector
- 1D Fixing grid writer in ASCII mode - Fixing 1D grid writer in ASCII mode
### Changed
- VerletList<3, double, FAST, shift<3, double> > is now VerletList<3, double, Mem_fast<>, shift<3, double> >
## [1.0.0] 13 September 2017 (Codename: Vortex) ## [1.0.0] 13 September 2017 (Codename: Vortex)
......
...@@ -7,7 +7,7 @@ LDIR = ...@@ -7,7 +7,7 @@ LDIR =
OBJ = main.o OBJ = main.o
%.o: %.cpp %.o: %.cpp
$(CC) -O0 -g -c --std=c++11 -o $@ $< $(INCLUDE_PATH) $(CC) -O3 -g -c --std=c++11 -o $@ $< $(INCLUDE_PATH)
ps_cma_es: $(OBJ) ps_cma_es: $(OBJ)
$(CC) -o $@ $^ $(CFLAGS) $(LIBS_PATH) $(LIBS) $(CC) -o $@ $^ $(CFLAGS) $(LIBS_PATH) $(LIBS)
......
This diff is collapsed.
openfpm_data @ d4dd1167
Subproject commit 92aa87ad50e32a2999b856387e70a0c161a36945 Subproject commit d4dd11672cd49676ec60d500bc55c26202142ca6
...@@ -41,6 +41,50 @@ ...@@ -41,6 +41,50 @@
#define CARTDEC_ERROR 2000lu #define CARTDEC_ERROR 2000lu
/*! \brief It spread the sub-sub-domain on a regular cartesian grid of size dim
*
* \warning this function only guarantee that the division on each direction is
* 2^n with some n and does not guarantee that the number of
* sub-sub-domain is preserved
*
* \param div number of division on each direction as output
* \param n_sub number of sub-domain
* \param dim_r dimension reduction
*
*/
template<unsigned int dim> static void nsub_to_div2(size_t (& div)[dim], size_t n_sub, size_t dim_r)
{
for (size_t i = 0; i < dim; i++)
{
if (i < dim_r)
{div[i] = openfpm::math::round_big_2(pow(n_sub, 1.0 / dim_r));}
else
{div[i] = 1;}
}
}
/*! \brief It spread the sub-sub-domain on a regular cartesian grid of size dim
*
* \warning this function only guarantee that the division on each direction is
* 2^n with some n and does not guarantee that the number of
* sub-sub-domain is preserved
*
* \param div number of division on each direction as output
* \param n_sub number of sub-domain
* \param dim_r dimension reduction
*
*/
template<unsigned int dim> static void nsub_to_div(size_t (& div)[dim], size_t n_sub, size_t dim_r)
{
for (size_t i = 0; i < dim; i++)
{
if (i < dim_r)
{div[i] = std::floor(pow(n_sub, 1.0 / dim_r));}
else
{div[i] = 1;}
}
}
#define COMPUTE_SKIN_SUB 1 #define COMPUTE_SKIN_SUB 1
/** /**
...@@ -352,13 +396,13 @@ public: ...@@ -352,13 +396,13 @@ public:
// calculate the sub-divisions // calculate the sub-divisions
size_t div[dim]; size_t div[dim];
for (size_t i = 0; i < dim; i++) for (size_t i = 0; i < dim; i++)
div[i] = (size_t) ((bound.getHigh(i) - bound.getLow(i)) / cd.getCellBox().getP2()[i]); {div[i] = (size_t) ((bound.getHigh(i) - bound.getLow(i)) / cd.getCellBox().getP2()[i]);}
// Initialize the geo_cell structure // Initialize the geo_cell structure
ie_ghost<dim,T>::Initialize_geo_cell(bound,div); ie_ghost<dim,T>::Initialize_geo_cell(bound,div);
// Initialize shift vectors // Initialize shift vectors
ie_ghost<dim,T>::generateShiftVectors(domain); ie_ghost<dim,T>::generateShiftVectors(domain,bc);
} }
} }
...@@ -512,9 +556,7 @@ public: ...@@ -512,9 +556,7 @@ public:
\endverbatim \endverbatim
* *
* * ghost margins for each dimensions (p1 negative part) (p2 positive part)
*
* \param ghost margins for each dimensions (p1 negative part) (p2 positive part)
* *
* *
\verbatim \verbatim
...@@ -1045,6 +1087,77 @@ public: ...@@ -1045,6 +1087,77 @@ public:
} }
} }
/*! \brief Set the best parameters for the decomposition
*
* It based on number of processors and dimensionality find a "good" parameter setting
*
* \param domain_ domain to decompose
* \param bc boundary conditions
* \param ghost Ghost size
* \param sec_dist Distribution grid. The distribution grid help in reducing the underlying
* distribution problem simplifying decomposition problem. This is done in order to
* reduce the load/balancing dynamic load balancing problem
*
* \param dec_gran number of sub-sub-domain for each processor
*
*/
void setGoodParameters(::Box<dim,T> domain_,
const size_t (& bc)[dim],
const Ghost<dim,T> & ghost,
size_t dec_gran,
const grid_sm<dim,void> & sec_dist = grid_sm<dim,void>())
{
size_t div[dim];
// Create a valid decomposition of the space
// Get the number of processor and calculate the number of sub-domain
// for decomposition
size_t n_proc = v_cl.getProcessingUnits();
size_t n_sub = n_proc * dec_gran;
// Calculate the maximum number (before merging) of sub-domain on
// each dimension
nsub_to_div2(div,n_sub,dim);
/* for (size_t i = 0; i < dim; i++)
{
div[i] = openfpm::math::round_big_2(pow(n_sub, 1.0 / dim));
}*/
if (dim > 3)
{
long int dim_r = dim-1;
do
{
// Check for adjustment
size_t tot_size = 1;
for (size_t i = 0 ; i < dim ; i++)
{tot_size *= div[i];}
// the granularity is too coarse increase the divisions
if (tot_size / n_proc > 0.75*dec_gran )
{break;}
nsub_to_div(div,n_sub,dim_r);
dim_r--;
} while(dim_r > 0);
}
setParameters(div,domain_,bc,ghost,sec_dist);
}
/*! \brief return the parameters of the decomposition
*
* \param div_ number of divisions in each dimension
*
*/
void getParameters(size_t (& div_)[dim])
{
for (size_t i = 0 ; i < dim ; i++)
{div_[i] = this->gr.size(i);}
}
/*! \brief Set the parameter of the decomposition /*! \brief Set the parameter of the decomposition
* *
...@@ -1057,7 +1170,11 @@ public: ...@@ -1057,7 +1170,11 @@ public:
* reduce the load/balancing dynamic load balancing problem * reduce the load/balancing dynamic load balancing problem
* *
*/ */
void setParameters(const size_t (& div_)[dim], ::Box<dim,T> domain_, const size_t (& bc)[dim] ,const Ghost<dim,T> & ghost, const grid_sm<dim,void> & sec_dist = grid_sm<dim,void>()) void setParameters(const size_t (& div_)[dim],
::Box<dim,T> domain_,
const size_t (& bc)[dim],
const Ghost<dim,T> & ghost,
const grid_sm<dim,void> & sec_dist = grid_sm<dim,void>())
{ {
// set the boundary conditions // set the boundary conditions
for (size_t i = 0 ; i < dim ; i++) for (size_t i = 0 ; i < dim ; i++)
......
...@@ -272,9 +272,7 @@ public: ...@@ -272,9 +272,7 @@ public:
/*! \brief return number of moved vertices in all iterations so far /*! \brief return number of moved vertices in all iterations so far
* *
* \param id vertex id * \return number of moved vertices
*
* \return vector with x, y, z
* *
*/ */
size_t getMaxMovedV() size_t getMaxMovedV()
......
...@@ -422,11 +422,6 @@ BOOST_AUTO_TEST_CASE( Space_distribution_test) ...@@ -422,11 +422,6 @@ BOOST_AUTO_TEST_CASE( Space_distribution_test)
//! [refine with dist_parmetis the decomposition] //! [refine with dist_parmetis the decomposition]
} }
void print_test_v(std::string test, size_t sz)
{
if (create_vcluster().getProcessUnitID() == 0)
std::cout << test << " " << sz << "\n";
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
......
...@@ -304,6 +304,7 @@ public: ...@@ -304,6 +304,7 @@ public:
* *
*/ */
ParMetisDistribution(ParMetisDistribution<dim,T> && pm) ParMetisDistribution(ParMetisDistribution<dim,T> && pm)
:v_cl(pm.v_cl)
{ {
this->operator=(pm); this->operator=(pm);
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "util/mathutil.hpp" #include "util/mathutil.hpp"
#include "NN/CellList/CellDecomposer.hpp" #include "NN/CellList/CellDecomposer.hpp"
#include "Grid/grid_key_dx_iterator_hilbert.hpp"
/*! \brief Class that distribute sub-sub-domains across processors using an hilbert curve /*! \brief Class that distribute sub-sub-domains across processors using an hilbert curve
* to divide the space * to divide the space
...@@ -63,6 +64,7 @@ public: ...@@ -63,6 +64,7 @@ public:
* *
*/ */
SpaceDistribution(SpaceDistribution<dim,T> && pm) SpaceDistribution(SpaceDistribution<dim,T> && pm)
:v_cl(pm.v_cl)
{ {
this->operator=(pm); this->operator=(pm);
} }
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "common.hpp" #include "common.hpp"
#include "nn_processor.hpp" #include "nn_processor.hpp"
#include "Decomposition/shift_vect_converter.hpp"
/*! \brief structure that store and compute the internal and external local ghost box /*! \brief structure that store and compute the internal and external local ghost box
* *
...@@ -49,6 +51,8 @@ class ie_ghost ...@@ -49,6 +51,8 @@ class ie_ghost
//! Temporal buffers to return temporal information //! Temporal buffers to return temporal information
openfpm::vector<size_t> ids; openfpm::vector<size_t> ids;
//! shift converter
shift_vect_converter<dim,T> sc_convert;
/*! \brief Given a local sub-domain i, it give the id of such sub-domain in the sent list /*! \brief Given a local sub-domain i, it give the id of such sub-domain in the sent list
* for the processor p_id * for the processor p_id
...@@ -153,35 +157,9 @@ protected: ...@@ -153,35 +157,9 @@ protected:
* \param domain box that describe the domain * \param domain box that describe the domain
* *
*/ */
void generateShiftVectors(const Box<dim,T> & domain) void generateShiftVectors(const Box<dim,T> & domain, size_t (& bc)[dim])
{ {
shifts.resize(openfpm::math::pow(3,dim)); sc_convert.generateShiftVectors(domain,bc,shifts);
HyperCube<dim> hyp;
for (long int i = dim-1 ; i >= 0 ; i--)
{
std::vector<comb<dim>> cmbs = hyp.getCombinations_R(i);
for (size_t j = 0 ; j < cmbs.size() ; j++)
{
for (size_t k = 0 ; k < dim ; k++)
{
switch (cmbs[j][k])
{
case 1:
shifts.get(cmbs[j].lin()).template get<0>()[k] = -(domain.getHigh(k) - domain.getLow(k));
break;
case 0:
shifts.get(cmbs[j].lin()).template get<0>()[k] = 0;
break;
case -1:
shifts.get(cmbs[j].lin()).template get<0>()[k] = (domain.getHigh(k) - domain.getLow(k));
break;
}
}
}
}
} }
/*! \brief Initialize the geo cell list structure /*! \brief Initialize the geo cell list structure
...@@ -196,7 +174,7 @@ protected: ...@@ -196,7 +174,7 @@ protected:
void Initialize_geo_cell(const Box<dim,T> & domain, const size_t (&div)[dim]) void Initialize_geo_cell(const Box<dim,T> & domain, const size_t (&div)[dim])
{ {
// Initialize the geo_cell structure // Initialize the geo_cell structure
geo_cell.Initialize(domain,div); geo_cell.Initialize(domain,div,0);
} }
/*! \brief Create the box_nn_processor_int (bx part) structure /*! \brief Create the box_nn_processor_int (bx part) structure
...@@ -371,7 +349,7 @@ protected: ...@@ -371,7 +349,7 @@ protected:
b_int.lc_proc = lc_proc; b_int.lc_proc = lc_proc;
// fill the shift id // fill the shift id
b_int.shift_id = nn_p_box_pos.get(k).lin(); b_int.shift_id = convertShift(nn_p_box_pos.get(k));
// //
// Updating // Updating
...@@ -531,6 +509,20 @@ public: ...@@ -531,6 +509,20 @@ public:
return shifts; return shifts;
} }
/*! It return the converted shift vector
*
* In high dimensions the number of shifts vectors explode exponentially, so we are
* expecting that some of the boundary is non periodic to reduce the numbers of shift
* vectors
*
* \return the shift vectors
*
*/
size_t convertShift(const comb<dim> & cmb)
{
return sc_convert.linId(cmb);
}
/*! \brief Get the number of Internal ghost boxes for one processor /*! \brief Get the number of Internal ghost boxes for one processor
* *
* \param id near processor list id (the id go from 0 to getNNProcessor()) * \param id near processor list id (the id go from 0 to getNNProcessor())
......
...@@ -159,7 +159,7 @@ class ie_loc_ghost ...@@ -159,7 +159,7 @@ class ie_loc_ghost
// that must be adjusted, each of this boxes define a shift in case of periodic boundary condition // that must be adjusted, each of this boxes define a shift in case of periodic boundary condition
for (long int i = dim-1 ; i >= 0 ; i--) for (long int i = dim-1 ; i >= 0 ; i--)
{ {
std::vector<comb<dim>> cmbs = hyp.getCombinations_R(i); std::vector<comb<dim>> cmbs = hyp.getCombinations_R_bc(i,bc);
for (size_t j = 0 ; j < cmbs.size() ; j++) for (size_t j = 0 ; j < cmbs.size() ; j++)
{ {
......
...@@ -178,7 +178,7 @@ class nn_prcs ...@@ -178,7 +178,7 @@ class nn_prcs
// that must be adjusted, each of this boxes define a shift in case of periodic boundary condition // that must be adjusted, each of this boxes define a shift in case of periodic boundary condition
for (long int i = dim-1 ; i >= 0 ; i--) for (long int i = dim-1 ; i >= 0 ; i--)
{ {
std::vector<comb<dim>> cmbs = hyp.getCombinations_R(i); std::vector<comb<dim>> cmbs = hyp.getCombinations_R_bc(i,bc);
for (size_t j = 0 ; j < cmbs.size() ; j++) for (size_t j = 0 ; j < cmbs.size() ; j++)
{ {
......
#ifndef CARTDECOMPOSITION_UNIT_TEST_HPP #define BOOST_TEST_DYN_LINK
#define CARTDECOMPOSITION_UNIT_TEST_HPP #include <boost/test/unit_test.hpp>
#include "CartDecomposition.hpp" #include "Decomposition/CartDecomposition.hpp"
#include "util/mathutil.hpp" #include "util/mathutil.hpp"
BOOST_AUTO_TEST_SUITE (CartDecomposition_test) BOOST_AUTO_TEST_SUITE (CartDecomposition_test)
...@@ -414,6 +414,135 @@ BOOST_AUTO_TEST_CASE( CartDecomposition_non_periodic_test_dist_grid) ...@@ -414,6 +414,135 @@ BOOST_AUTO_TEST_CASE( CartDecomposition_non_periodic_test_dist_grid)
BOOST_REQUIRE_EQUAL(val,true); BOOST_REQUIRE_EQUAL(val,true);
} }
BOOST_AUTO_TEST_CASE( CartDecomposition_nsub_algo_functions_test)
{
size_t n_sub = 64*2;
size_t div[3];
nsub_to_div2<3>(div,n_sub,3);
BOOST_REQUIRE_EQUAL(div[0],8ul);
BOOST_REQUIRE_EQUAL(div[1],8ul);
BOOST_REQUIRE_EQUAL(div[2],8ul);
nsub_to_div2<3>(div,n_sub,2);
BOOST_REQUIRE_EQUAL(div[0],16ul);
BOOST_REQUIRE_EQUAL(div[1],16ul);
BOOST_REQUIRE_EQUAL(div[2],1ul);
nsub_to_div2<3>(div,n_sub,1);
BOOST_REQUIRE_EQUAL(div[0],128ul);
BOOST_REQUIRE_EQUAL(div[1],1ul);
BOOST_REQUIRE_EQUAL(div[2],1ul);
n_sub = 64*3;
nsub_to_div<3>(div,n_sub,3);
BOOST_REQUIRE_EQUAL(div[0],5ul);
BOOST_REQUIRE_EQUAL(div[1],5ul);
BOOST_REQUIRE_EQUAL(div[2],5ul);
nsub_to_div<3>(div,n_sub,2);
BOOST_REQUIRE_EQUAL(div[0],13ul);
BOOST_REQUIRE_EQUAL(div[1],13ul);
BOOST_REQUIRE_EQUAL(div[2],1ul);
nsub_to_div<3>(div,n_sub,1);
BOOST_REQUIRE_EQUAL(div[0],192ul);
BOOST_REQUIRE_EQUAL(div[1],1ul);
BOOST_REQUIRE_EQUAL(div[2],1ul);
// Test high dimension cart decomposition subdivision
Box<50,double> domain;
size_t bc[50];
Ghost<50,double> ghost(0.01);
for(size_t i = 0 ; i < 50 ; i++)
{
domain.setLow(i,0.0);
domain.setHigh(i,1.0);
bc[i] = NON_PERIODIC;
}
CartDecomposition<50,double> dec(create_vcluster());
dec.setGoodParameters(domain,bc,ghost,64);
size_t div2[50];
dec.getParameters(div2);
auto & v_cl = create_vcluster();
if (v_cl.size() == 1)
{
for (size_t i = 0 ; i < 50 ; i++)
{
if (i < 6)
{BOOST_REQUIRE_EQUAL(div2[i],2ul);}
else
{BOOST_REQUIRE_EQUAL(div2[i],1ul);}
}
}
if (v_cl.size() == 2)
{
for (size_t i = 0 ; i < 50 ; i++)
{
if (i < 7)
{BOOST_REQUIRE_EQUAL(div2[i],2ul);}
else
{BOOST_REQUIRE_EQUAL(div2[i],1ul);}
}
}
if (v_cl.size() == 3)
{
for (size_t i = 0 ; i < 50 ; i++)
{
if (i < 2)
{BOOST_REQUIRE_EQUAL(div2[i],13ul);}
else
{BOOST_REQUIRE_EQUAL(div2[i],1ul);}
}
}
if (v_cl.size() == 4)
{
for (size_t i = 0 ; i < 50 ; i++)
{
if (i < 8)
{BOOST_REQUIRE_EQUAL(div2[i],2ul);}
else
{BOOST_REQUIRE_EQUAL(div2[i],1ul);}
}
}
if (v_cl.size() == 5)
{
for (size_t i = 0 ; i < 50 ; i++)
{
if (i < 8)
{BOOST_REQUIRE_EQUAL(div2[i],2ul);}
else
{BOOST_REQUIRE_EQUAL(div2[i],1ul);}
}
}
if (v_cl.size() == 6)
{
for (size_t i = 0 ; i < 50 ; i++)
{
if (i < 3)
{BOOST_REQUIRE_EQUAL(div2[i],7ul);}
else
{BOOST_REQUIRE_EQUAL(div2[i],1ul);}
}
}
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
#endif
...@@ -302,7 +302,7 @@ class grid_dist_iterator_sub ...@@ -302,7 +302,7 @@ class grid_dist_iterator_sub
int sx = uhi[0]+1;\ int sx = uhi[0]+1;\
int sxsy = (uhi[0]+1)*(uhi[1]+1); int sxsy = (uhi[0]+1)*(uhi[1]+1);
#define ITERATE_3D_M(n_pt) int i = lo[2];\ #define ITERATE_3D_M(n_pt) int i = lo[2];\
for ( ; i <= hi[2] ; i+=1)\ for ( ; i <= hi[2] ; i+=1)\
{\ {\
int j = lo[1];\ int j = lo[1];\
......
#ifndef GRID_DIST_UNIT_TEST_HPP
#define GRID_DIST_UNIT_TEST_HPP
#define BOOST_TEST_DYN_LINK #define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
...@@ -8,14 +5,10 @@ ...@@ -8,14 +5,10 @@
#include "grid_dist_id.hpp" #include "grid_dist_id.hpp"
#include "data_type/aggregate.hpp" #include "data_type/aggregate.hpp"
extern void print_test_v(std::string test, size_t sz);
BOOST_AUTO_TEST_SUITE( grid_dist_id_test ) BOOST_AUTO_TEST_SUITE( grid_dist_id_test )
void print_test(std::string test, size_t sz)
{
if (create_vcluster().getProcessUnitID() == 0)
std::cout << test << " " << sz << "\n";
}
BOOST_AUTO_TEST_CASE( grid_dist_id_domain_grid_unit_converter3D_test) BOOST_AUTO_TEST_CASE( grid_dist_id_domain_grid_unit_converter3D_test)
{ {
...@@ -38,7 +31,7 @@ BOOST_AUTO_TEST_CASE( grid_dist_id_domain_grid_unit_converter3D_test) ...@@ -38,7 +31,7 @@ BOOST_AUTO_TEST_CASE( grid_dist_id_domain_grid_unit_converter3D_test)
big_step = (big_step == 0)?1:big_step; big_step = (big_step == 0)?1:big_step;
long int small_step = 21; long int small_step = 21;
print_test( "Testing 3D grid converter k<=",k); print_test_v( "Testing 3D grid converter k<=",k);
// 3D test // 3D test
for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step ) for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step )
...@@ -166,7 +159,7 @@ void Test2D(const Box<2,float> & domain, long int k) ...@@ -166,7 +159,7 @@ void Test2D(const Box<2,float> & domain, long int k)
big_step = (big_step == 0)?1:big_step; big_step = (big_step == 0)?1:big_step;
long int small_step = 21; long int small_step = 21;
print_test( "Testing 2D grid k<=",k); print_test_v( "Testing 2D grid k<=",k);
// 2D test // 2D test
for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step ) for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step )
...@@ -287,7 +280,7 @@ void Test1D(const Box<1,float> & domain, long int k) ...@@ -287,7 +280,7 @@ void Test1D(const Box<1,float> & domain, long int k)
if (v_cl.getProcessingUnits() > 48) if (v_cl.getProcessingUnits() > 48)
return; return;
print_test( "Testing 1D grid k<=",k); print_test_v( "Testing 1D grid k<=",k);