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

Fixed grid_dist

parent acdb15b8
No related branches found
No related tags found
No related merge requests found
......@@ -106,11 +106,11 @@ private:
// Here we use METIS
// Create a cartesian grid graph
CartesianGraphFactory<3,Graph_CSR<nm_part_v,nm_part_e>> g_factory_part;
CartesianGraphFactory<dim,Graph_CSR<nm_v,nm_e>> g_factory_part;
// Processor graph
Graph_CSR<nm_part_v,nm_part_e> gp = g_factory_part.construct<NO_EDGE,float,2>(div,domain);
Graph_CSR<nm_v,nm_e> gp = g_factory_part.template construct<NO_EDGE,T,dim-1,0,1>(div,domain);
// Get the number of processing units
size_t Np = v_cl.getProcessingUnits();
......@@ -119,30 +119,41 @@ private:
long int p_id = v_cl.getProcessUnitID();
// Convert the graph to metis
Metis<Graph_CSR<nm_part_v,nm_part_e>> met(gp,Np);
Metis<Graph_CSR<nm_v,nm_e>> met(gp,Np);
// decompose
met.decompose<nm_part_v::id>();
met.decompose<nm_v::id>();
// Optimize the decomposition creating bigger spaces
// And reducing Ghost over-stress
dec_optimizer<3,Graph_CSR<nm_part_v,nm_part_e>> d_o(gp,div);
dec_optimizer<dim,Graph_CSR<nm_v,nm_e>> d_o(gp,div);
// set of Boxes produced by the decomposition optimizer
openfpm::vector<::Box<dim,size_t>> loc_box;
grid_key_dx<3> keyZero(0,0,0);
d_o.optimize<nm_part_v::sub_id,nm_part_v::id>(keyZero,gp,p_id,loc_box);
// a grig key poiting to the origin
grid_key_dx<dim> keyZero;
keyZero.zero();
// optimize the decomposition
d_o.template optimize<nm_v::sub_id,nm_v::id>(keyZero,gp,p_id,loc_box);
//-------------------DEBUG---------
VTKWriter<decltype(gp)> vtk(gp);
vtk.write("out_graph.vtk");
//---------------------------------
exit(1);
// convert into sub-domain
for (size_t s = 0 ; s < loc_box.size() ; s++)
{
SpaceBox<dim,T> sub_d(loc_box.get(s));
// re-scale with the spacing
sub_d.mul(spacing);
// re-scale with spacing
sub_d.spacing(spacing);
// add the sub-domain
sub_domains.add(sub_d);
......
......@@ -30,8 +30,6 @@ BOOST_AUTO_TEST_CASE( CartDecomposition_test_use)
// Decompose
dec.setParameters(div,box);
}
BOOST_AUTO_TEST_SUITE_END()
......
......@@ -364,8 +364,7 @@ public:
* no property will store this information
* \tparam T type of the domain like (int real complex ... )
* \tparam dim_c Connectivity dimension
* \tparam Memory class that create new memory
* \tparam pos... one or more integer indicating the spatial properties
* \tparam pos... (optional)one or more integer indicating the spatial properties
*
*/
template <unsigned int se,typename T, unsigned int dim_c, int... pos>
......
......@@ -7,7 +7,6 @@
#include "Space/SpaceBox.hpp"
#include "mathutil.hpp"
#include "grid_dist_id_iterator.hpp"
#include "grid_dist_id_iterator_margin.hpp"
#include "grid_dist_key.hpp"
#define SUB_UNIT_FACTOR 64
......@@ -93,7 +92,7 @@ class grid_dist_id
for (size_t d = 0 ; d < dim ; d++)
{
// push the size of the local grid
v_size[d] = sp.getHigh(d) - sp.getLow(d);
v_size[d] = sp.getHigh(d) - sp.getLow(d) + 1;
}
}
......@@ -119,16 +118,36 @@ public:
// Create the sub-domains
dec.setParameters(div);
// Create local grid
Create();
}
//! constructor
grid_dist_id(size_t (& g_sz)[dim])
:v_cl(*global_v_cluster),dec(Decomposition(v_cl))
:dec(Decomposition(*global_v_cluster)),v_cl(*global_v_cluster)
{
// fill the global size of the grid
for (int i = 0 ; i < dim ; i++) {this->g_sz[i] = g_sz[i];}
// first compute a decomposition
// 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 * SUB_UNIT_FACTOR;
// Calculate the maximum number (before merging) of sub-domain on
// each dimension
size_t div[dim];
for (int i = 0 ; i < dim ; i++)
{div[i] = round_big_2(pow(n_sub,1.0/dim));}
// Box
Box<dim,size_t> b(g_sz);
// Create the sub-domains
dec.setParameters(div,b);
// Create local grid
Create();
}
......@@ -193,9 +212,9 @@ public:
* \return An iterator to a grid with specified margins
*
*/
grid_dist_iterator_margin<dim,device_grid> getBulkIterator(size_t margin)
grid_dist_iterator<dim,device_grid> getDomainIterator()
{
grid_dist_iterator_margin<dim,device_grid> it(loc_grid,margin);
grid_dist_iterator<dim,device_grid> it(loc_grid,0);
return it;
}
......
/*
* grid_dist_id_iterator.hpp
* grid_dist_id_iterator_sub.hpp
*
* Created on: Feb 4, 2015
* Author: Pietro Incardona
......@@ -9,7 +9,7 @@
#define GRID_DIST_ID_ITERATOR_HPP_
#include "grid_dist_key.hpp"
#include "Grid/grid.hpp"
#include "VCluster.hpp"
/*! \brief Distributed grid iterator
*
......@@ -17,18 +17,20 @@
*
*/
template<unsigned int dim, typename l_grid>
template<unsigned int dim, typename device_grid>
class grid_dist_iterator
{
//! grid list counter
size_t g_c;
//! List of the grids we are going to iterate
std::vector<l_grid> & gList;
Vcluster_object_array<device_grid> & gList;
//! Actual iterator
grid_key_dx_iterator<dim> a_it;
grid_key_dx_iterator_sub<dim> a_it;
//! margin of the grid iterator
size_t m;
public:
......@@ -37,18 +39,19 @@ class grid_dist_iterator
* \param gk std::vector of the local grid
*
*/
grid_dist_iterator(std::vector<l_grid> & gk)
:g_c(0),gList(gk)
grid_dist_iterator(Vcluster_object_array<device_grid> & gk, size_t m)
:g_c(0),gList(gk),m(m)
{
// Initialize with the current iterator
// Initialize the current iterator
// with the first grid
a_it = gList[0].getIterator();
a_it.reinitialize(gList[0].getDomainIterator());
}
// Destructor
~grid_dist_iterator()
{}
{
}
/*! \brief Get the next element
*
......@@ -56,13 +59,13 @@ class grid_dist_iterator
*
*/
grid_key_dx_iterator<dim> operator++()
grid_dist_iterator<dim,device_grid> operator++()
{
a_it++;
++a_it;
// check if a_it is at the end
if (a_it.isEnd() == false)
if (a_it.isNext() == true)
return *this;
else
{
......@@ -72,11 +75,8 @@ class grid_dist_iterator
// get the next grid iterator
a_it = a_it = gList[g_c].getIterator();
// increment to a valid point
a_it++;
if (g_c < gList.size())
a_it = gList[g_c].getDomainIterator();
}
return *this;
......@@ -88,12 +88,14 @@ class grid_dist_iterator
*
*/
bool isEnd()
bool isNext()
{
// If there are no other grid stop
if (g_c >= gList.size())
return true;
return false;
return true;
}
/*! \brief Get the actual key
......@@ -103,9 +105,9 @@ class grid_dist_iterator
*/
grid_dist_key_dx<dim> get()
{
return a_it;
return grid_dist_key_dx<dim>(g_c,a_it.get());
}
};
#endif /* GRID_DIST_ID_ITERATOR_HPP_ */
#endif /* GRID_DIST_ID_ITERATOR_SUB_HPP_ */
/*
* grid_dist_id_iterator_sub.hpp
*
* Created on: Feb 4, 2015
* Author: Pietro Incardona
*/
#ifndef GRID_DIST_ID_ITERATOR_SUB_HPP_
#define GRID_DIST_ID_ITERATOR_SUB_HPP_
#include "VCluster.hpp"
/*! \brief Distributed grid iterator
*
* Iterator across the local element of the distributed grid
*
*/
template<unsigned int dim, typename device_grid>
class grid_dist_iterator_margin
{
//! grid list counter
size_t g_c;
//! List of the grids we are going to iterate
Vcluster_object_array<device_grid> & gList;
//! Actual iterator
grid_key_dx_iterator_sub<dim> * a_it;
//! margin of the grid iterator
size_t m;
public:
/*! \brief Constructor of the distributed grid
*
* \param gk std::vector of the local grid
*
*/
grid_dist_iterator_margin(Vcluster_object_array<device_grid> & gk, size_t m)
:g_c(0),gList(gk),m(m)
{
// Initialize the current iterator
// with the first grid
a_it = new grid_key_dx_iterator_sub<dim>(gList[0].getSubIterator(m));
}
// Destructor
~grid_dist_iterator_margin()
{
// delete the grid iterator
delete a_it;
}
/*! \brief Get the next element
*
* \return the next grid_key
*
*/
grid_key_dx_iterator<dim> operator++()
{
a_it++;
// check if a_it is at the end
if (a_it.isEnd() == false)
return *this;
else
{
// switch to the new grid
g_c++;
// get the next grid iterator
a_it = a_it = gList[g_c].getIterator();
// increment to a valid point
a_it++;
}
return *this;
}
/*! \brief Check if there is the next element
*
* \return true if there is the next, false otherwise
*
*/
bool isEnd()
{
// If there are no other grid stop
if (g_c >= gList.size())
return true;
}
/*! \brief Get the actual key
*
* \return the actual key
*
*/
grid_dist_key_dx<dim> get()
{
return a_it;
}
};
#endif /* GRID_DIST_ID_ITERATOR_SUB_HPP_ */
......@@ -30,6 +30,9 @@ template<typename iterator> void jacobi_iteration(iterator g_it, grid_dist_id<2,
BOOST_AUTO_TEST_CASE( grid_dist_id_iterator_test_use)
{
// Initialize the global VCluster
init_global_v_cluster(&boost::unit_test::framework::master_test_suite().argc,&boost::unit_test::framework::master_test_suite().argv);
// grid size
size_t sz[2] = {1024,1024};
......@@ -37,13 +40,22 @@ BOOST_AUTO_TEST_CASE( grid_dist_id_iterator_test_use)
grid_dist_id<2, scalar<float>, CartDecomposition<2,size_t>> g_dist(sz);
// Create the grid on memory
// get the domain iterator
g_dist.Create();
size_t count = 0;
auto dom = g_dist.getDomainIterator();
// get the Bulk iterator
while (dom.isNext())
{
auto key = dom.get();
count++;
++dom;
}
auto bulk = g_dist.getBulkIterator(2);
BOOST_REQUIRE_EQUAL(count,1024*1024);
/* auto g_it = g_dist.getIteratorBulk();
......
......@@ -16,7 +16,14 @@ class grid_dist_key_dx
//! Local grid iterator
grid_key_dx_iterator<dim> a_it;
grid_key_dx<dim> key;
public:
grid_dist_key_dx(int g_c, grid_key_dx<dim> key)
:g_c(g_c),key(key)
{
}
};
#endif
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