Skip to content
Snippets Groups Projects
Commit f60b3c18 authored by Pietro Incardona's avatar Pietro Incardona
Browse files

Adding sub grid iterator

parent 5e6198ef
No related branches found
No related tags found
No related merge requests found
openfpm_data @ 49040a1f
Subproject commit 2e36a553e379e6712b62abeffce479b005774c91 Subproject commit 49040a1f74848f700ffda26002d98191b25ea813
openfpm_numerics @ 1a6ed291
Subproject commit 0c51112a6a0808e7209329de9d4639c1e440a815 Subproject commit 1a6ed29114ae41e2befcfcfb33ffab58986b6f6b
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "Space/SpaceBox.hpp" #include "Space/SpaceBox.hpp"
#include "util/mathutil.hpp" #include "util/mathutil.hpp"
#include "grid_dist_id_iterator.hpp" #include "grid_dist_id_iterator.hpp"
#include "grid_dist_id_iterator_sub.hpp"
#include "grid_dist_key.hpp" #include "grid_dist_key.hpp"
#include "NN/CellList/CellDecomposer.hpp" #include "NN/CellList/CellDecomposer.hpp"
#include "util/object_util.hpp" #include "util/object_util.hpp"
...@@ -39,6 +40,8 @@ ...@@ -39,6 +40,8 @@
* \snippet grid_dist_id_unit_test.hpp Create and access a distributed grid complex * \snippet grid_dist_id_unit_test.hpp Create and access a distributed grid complex
* ### Synchronize a distributed grid for complex structures * ### Synchronize a distributed grid for complex structures
* \snippet grid_dist_id_unit_test.hpp Synchronized distributed grid complex * \snippet grid_dist_id_unit_test.hpp Synchronized distributed grid complex
* ### Usage of a grid dist iterator sub
* \snippet grid_dist_id_unit_test.hpp Usage of a sub_grid iterator
* *
*/ */
template<unsigned int dim, typename St, typename T, typename Decomposition,typename Memory=HeapMemory , typename device_grid=grid_cpu<dim,T> > template<unsigned int dim, typename St, typename T, typename Decomposition,typename Memory=HeapMemory , typename device_grid=grid_cpu<dim,T> >
...@@ -538,6 +541,20 @@ public: ...@@ -538,6 +541,20 @@ public:
return it; return it;
} }
/*! \brief It return an iterator that span the grid domain only in the specified
* part
*
* \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> it(start,stop,loc_grid,gdb_ext);
return it;
}
//! Destructor //! Destructor
~grid_dist_id() ~grid_dist_id()
{ {
......
...@@ -74,6 +74,89 @@ BOOST_AUTO_TEST_CASE( grid_dist_id_domain_grid_unit_converter_test) ...@@ -74,6 +74,89 @@ 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 = 1;
// this test is only performed when the number of processor is <= 32
if (global_v_cluster->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 );
//! [Create and access a distributed grid]
// grid size
size_t sz[2];
sz[0] = k;
sz[1] = k;
float factor = pow(global_v_cluster->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>, CartDecomposition<2,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<2,void> info(sz);
// get the domain iterator
size_t count = 0;
//! [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;
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,(k-2)*(k-2));
}
}
void Test2D(const Box<2,float> & domain, long int k) void Test2D(const Box<2,float> & domain, long int k)
{ {
long int big_step = k / 30; long int big_step = k / 30;
...@@ -179,6 +262,119 @@ void Test2D(const Box<2,float> & domain, long int k) ...@@ -179,6 +262,119 @@ void Test2D(const Box<2,float> & domain, long int k)
} }
} }
void Test3D_sub(const Box<3,float> & domain, long int k)
{
long int big_step = k / 30;
big_step = (big_step == 0)?1:big_step;
long int small_step = 1;
// this test is only performed when the number of processor is <= 32
if (global_v_cluster->getProcessingUnits() > 32)
return;
print_test( "Testing 3D grid sub k<=",k);
// 3D test
for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step )
{
BOOST_TEST_CHECKPOINT( "Testing 3D grid sub k=" << k );
// grid size
size_t sz[3];
sz[0] = k;
sz[1] = k;
sz[2] = k;
// factor
float factor = pow(global_v_cluster->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, scalar<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);
// get the domain iterator
size_t count = 0;
auto dom = g_dist.getDomainIterator();
while (dom.isNext())
{
auto key = dom.get();
auto key_g = g_dist.getGKey(key);
g_dist.template get<0>(key) = info.LinId(key_g);
// Count the point
count++;
++dom;
}
// Get the virtual cluster machine
Vcluster & vcl = g_dist.getVC();
// reduce
vcl.sum(count);
vcl.execute();
// Check
BOOST_REQUIRE_EQUAL(count,k*k*k);
bool match = true;
auto dom2 = g_dist.getDomainIterator();
// check that the grid store the correct information
while (dom2.isNext())
{
auto key = dom2.get();
auto key_g = g_dist.getGKey(key);
match &= (g_dist.template get<0>(key) == info.LinId(key_g))?true:false;
++dom2;
}
BOOST_REQUIRE_EQUAL(match,true);
//! [Synchronize the ghost and check the information]
g_dist.template ghost_get<0>();
// check that the communication is correctly completed
auto domg = g_dist.getDomainGhostIterator();
// check that the grid with the ghost past store the correct information
while (domg.isNext())
{
auto key = domg.get();
auto key_g = g_dist.getGKey(key);
// In this case the boundary condition are non periodic
if (g_dist.isInside(key_g))
{
match &= (g_dist.template get<0>(key) == info.LinId(key_g))?true:false;
}
++domg;
}
BOOST_REQUIRE_EQUAL(match,true);
//! [Synchronize the ghost and check the information]
}
}
void Test3D(const Box<3,float> & domain, long int k) void Test3D(const Box<3,float> & domain, long int k)
{ {
long int big_step = k / 30; long int big_step = k / 30;
...@@ -187,7 +383,7 @@ void Test3D(const Box<3,float> & domain, long int k) ...@@ -187,7 +383,7 @@ void Test3D(const Box<3,float> & domain, long int k)
print_test( "Testing 3D grid k<=",k); print_test( "Testing 3D grid k<=",k);
// 2D 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 )
{ {
BOOST_TEST_CHECKPOINT( "Testing 3D grid k=" << k ); BOOST_TEST_CHECKPOINT( "Testing 3D grid k=" << k );
...@@ -634,6 +830,26 @@ BOOST_AUTO_TEST_CASE( grid_dist_id_iterator_test_use) ...@@ -634,6 +830,26 @@ BOOST_AUTO_TEST_CASE( grid_dist_id_iterator_test_use)
Test3D_complex(domain3,k); Test3D_complex(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});
// Initialize the global VCluster
init_global_v_cluster(&boost::unit_test::framework::master_test_suite().argc,&boost::unit_test::framework::master_test_suite().argv);
long int k = 1024*1024*global_v_cluster->getProcessingUnits();
k = std::pow(k, 1/2.);
Test2D_sub(domain,k);
// Domain
Box<3,float> domain3({0.0,0.0,0.0},{1.0,1.0,1.0});
k = 128*128*128*global_v_cluster->getProcessingUnits();
k = std::pow(k, 1/3.);
Test3D_sub(domain3,k);
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
#endif #endif
...@@ -26,4 +26,3 @@ ...@@ -26,4 +26,3 @@
#include "Grid/grid_dist_id_unit_test.hpp" #include "Grid/grid_dist_id_unit_test.hpp"
#include "Vector/vector_dist_unit_test.hpp" #include "Vector/vector_dist_unit_test.hpp"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment