OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
BoxDistribution< dim, T > Class Template Reference

Class that distribute sub-sub-domains across processors using Metis Library. More...

Detailed Description

template<unsigned int dim, typename T>
class BoxDistribution< dim, T >

Class that distribute sub-sub-domains across processors using Metis Library.

Given a graph and setting Computational cost, Communication cost (on the edge) and Migration cost or total Communication costs, it produce the optimal distribution

Initialize a Cartesian graph and decompose

// Cartesian grid
size_t sz[3] = { GS_SIZE, GS_SIZE, GS_SIZE };
// Box
Box<3, float> box( { 0.0, 0.0, 0.0 }, { 1.0, 1.0, 1.0 });
// Grid info
grid_sm<3, void> info(sz);
// Set metis on test, It fix the seed (not required if we are not testing)
met_dist.onTest();
// Initialize Cart graph and decompose
met_dist.createCartGraph(info,box);
met_dist.decompose();
BOOST_REQUIRE_EQUAL(met_dist.get_ndec(),1ul);
Vcluster & v_cl
Vcluster.
This class represent an N-dimensional box.
Definition Box.hpp:61
Class that distribute sub-sub-domains across processors using Metis Library.
Declaration grid_sm.
Definition grid_sm.hpp:167

Set Computation Communication and Migration cost

// Initialize the weights to 1.0
// not required, if we set ALL Computation,Migration,Communication cost
// Change set some weight on the graph and re-decompose
for (size_t k = 0; k < met_dist.getNOwnerSubSubDomains(); k++)
{
size_t i = met_dist.getOwnerSubSubDomain(k);
if (i == 0 || i == b || i == 2*b || i == 3*b || i == 4*b)
met_dist.setComputationCost(i,10);
else
met_dist.setComputationCost(i,1);
}
for (size_t i = 0 ; i < met_dist.getNSubSubDomains() ; i++)
{
// We also show how to set some Communication and Migration cost
met_dist.setMigrationCost(i,1);
for (size_t j = 0; j < met_dist.getNSubSubDomainNeighbors(i); j++)
met_dist.setCommunicationCost(i,j,1);
}
met_dist.decompose();
BOOST_REQUIRE_EQUAL(met_dist.get_ndec(),2ul);

Definition at line 55 of file BoxDistribution.hpp.

#include <BoxDistribution.hpp>

Public Member Functions

 BoxDistribution (Vcluster<> &v_cl)
 constructor
 
 BoxDistribution (const BoxDistribution &mt)
 Copy constructor.
 
 BoxDistribution (BoxDistribution &&mt)
 Copy constructor.
 
 ~BoxDistribution ()
 Destructor.
 
void createCartGraph (grid_sm< dim, void > &grid, Box< dim, T > dom)
 create a Cartesian distribution graph
 
Graph_CSR< nm_v< dim >, nm_e > & getGraph ()
 Get the current graph (main)
 
void decompose ()
 Distribute the sub-sub-domains.
 
void refine ()
 Refine current decomposition.
 
void redecompose ()
 Redecompose current decomposition.
 
void getSSDomainPos (size_t id, T(&pos)[dim])
 Function that return the position (point P1) of the sub-sub domain box in the space.
 
size_t getComputationalCost (size_t id)
 function that get the computational cost of the sub-sub-domain
 
void setComputationCost (size_t id, size_t cost)
 Set computation cost on a sub-sub domain.
 
void setMigrationCost (size_t id, size_t cost)
 Set migration cost on a sub-sub domain.
 
void setCommunicationCost (size_t id, size_t e, size_t cost)
 Set communication cost between neighborhood sub-sub-domains (weight on the edge)
 
size_t getNSubSubDomains ()
 Returns total number of sub-sub-domains.
 
size_t getNSubSubDomainNeighbors (size_t id)
 Returns total number of neighbors of one sub-sub-domain.
 
float getUnbalance ()
 Compute the unbalance of the processor compared to the optimal balance.
 
size_t getNOwnerSubSubDomains () const
 Return the total number of sub-sub-domains in the distribution graph.
 
size_t getOwnerSubSubDomain (size_t id) const
 Return the id of the set sub-sub-domain.
 
void onTest ()
 It set the Classs on test mode.
 
void write (std::string out)
 Write the distribution graph into file.
 
size_t getProcessorLoad ()
 Compute the processor load.
 
BoxDistributionoperator= (const BoxDistribution &mt)
 operator=
 
BoxDistributionoperator= (BoxDistribution &&mt)
 operator=
 
bool operator== (const BoxDistribution &mt)
 operator==
 
void setDistTol (double tol)
 Set the tolerance for each partition.
 
size_t getSubSubDomainComputationCost (size_t id)
 function that get the weight of the vertex
 
size_t get_ndec ()
 Get the decomposition counter.
 

Static Public Attributes

static constexpr unsigned int computation = nm_v_computation
 

Private Member Functions

void check_overflow (size_t id)
 Check that the sub-sub-domain id exist.
 
void check_overflowe (size_t id, size_t e)
 Check that the sub-sub-domain id exist.
 

Private Attributes

Vclusterv_cl
 Vcluster.
 
grid_sm< dim, void > gr
 Structure that store the cartesian grid information.
 
Box< dim, T > domain
 rectangular domain to decompose
 
Graph_CSR< nm_v< dim >, nm_egp
 Global sub-sub-domain graph.
 
bool testing = false
 Flag that indicate if we are doing a test (In general it fix the seed)
 
openfpm::vector< int > subsub_own
 

Constructor & Destructor Documentation

◆ BoxDistribution() [1/3]

template<unsigned int dim, typename T >
BoxDistribution< dim, T >::BoxDistribution ( Vcluster<> &  v_cl)
inline

constructor

Parameters
v_clvcluster

Definition at line 115 of file BoxDistribution.hpp.

◆ BoxDistribution() [2/3]

template<unsigned int dim, typename T >
BoxDistribution< dim, T >::BoxDistribution ( const BoxDistribution< dim, T > &  mt)
inline

Copy constructor.

Parameters
mtdistribution to copy

Definition at line 128 of file BoxDistribution.hpp.

◆ BoxDistribution() [3/3]

template<unsigned int dim, typename T >
BoxDistribution< dim, T >::BoxDistribution ( BoxDistribution< dim, T > &&  mt)
inline

Copy constructor.

Parameters
mtdistribution to copy

Definition at line 143 of file BoxDistribution.hpp.

◆ ~BoxDistribution()

template<unsigned int dim, typename T >
BoxDistribution< dim, T >::~BoxDistribution ( )
inline

Destructor.

Definition at line 156 of file BoxDistribution.hpp.

Member Function Documentation

◆ check_overflow()

template<unsigned int dim, typename T >
void BoxDistribution< dim, T >::check_overflow ( size_t  id)
inlineprivate

Check that the sub-sub-domain id exist.

Parameters
idsub-sub-domain id

Definition at line 79 of file BoxDistribution.hpp.

◆ check_overflowe()

template<unsigned int dim, typename T >
void BoxDistribution< dim, T >::check_overflowe ( size_t  id,
size_t  e 
)
inlineprivate

Check that the sub-sub-domain id exist.

Parameters
idsub-sub-domain id

Definition at line 95 of file BoxDistribution.hpp.

◆ createCartGraph()

template<unsigned int dim, typename T >
void BoxDistribution< dim, T >::createCartGraph ( grid_sm< dim, void > &  grid,
Box< dim, T >  dom 
)
inline

create a Cartesian distribution graph

Parameters
gridgrid info (sub-sub somains on each dimension)
domdomain (domain where the sub-sub-domains are defined)

Definition at line 170 of file BoxDistribution.hpp.

◆ decompose()

template<unsigned int dim, typename T >
void BoxDistribution< dim, T >::decompose ( )
inline

Distribute the sub-sub-domains.

Definition at line 218 of file BoxDistribution.hpp.

◆ get_ndec()

template<unsigned int dim, typename T >
size_t BoxDistribution< dim, T >::get_ndec ( )
inline

Get the decomposition counter.

Returns
the decomposition counter

Definition at line 603 of file BoxDistribution.hpp.

◆ getComputationalCost()

template<unsigned int dim, typename T >
size_t BoxDistribution< dim, T >::getComputationalCost ( size_t  id)
inline

function that get the computational cost of the sub-sub-domain

Parameters
idsub-sub-domain
Returns
the comutational cost

Definition at line 325 of file BoxDistribution.hpp.

◆ getGraph()

template<unsigned int dim, typename T >
Graph_CSR< nm_v< dim >, nm_e > & BoxDistribution< dim, T >::getGraph ( )
inline

Get the current graph (main)

Returns
the current sub-sub domain Graph

Definition at line 207 of file BoxDistribution.hpp.

◆ getNOwnerSubSubDomains()

template<unsigned int dim, typename T >
size_t BoxDistribution< dim, T >::getNOwnerSubSubDomains ( ) const
inline

Return the total number of sub-sub-domains in the distribution graph.

Returns
the total number of sub-sub-domains set

Definition at line 431 of file BoxDistribution.hpp.

◆ getNSubSubDomainNeighbors()

template<unsigned int dim, typename T >
size_t BoxDistribution< dim, T >::getNSubSubDomainNeighbors ( size_t  id)
inline

Returns total number of neighbors of one sub-sub-domain.

Parameters
idof the sub-sub-domain

Definition at line 400 of file BoxDistribution.hpp.

◆ getNSubSubDomains()

template<unsigned int dim, typename T >
size_t BoxDistribution< dim, T >::getNSubSubDomains ( )
inline

Returns total number of sub-sub-domains.

Returns
sub-sub domain numbers

Definition at line 388 of file BoxDistribution.hpp.

◆ getOwnerSubSubDomain()

template<unsigned int dim, typename T >
size_t BoxDistribution< dim, T >::getOwnerSubSubDomain ( size_t  id) const
inline

Return the id of the set sub-sub-domain.

Parameters
idid in the list of the set sub-sub-domains
Returns
the id

Definition at line 443 of file BoxDistribution.hpp.

◆ getProcessorLoad()

template<unsigned int dim, typename T >
size_t BoxDistribution< dim, T >::getProcessorLoad ( )
inline

Compute the processor load.

Warning
all processors must call this function
Returns
the total computation cost

Definition at line 483 of file BoxDistribution.hpp.

◆ getSSDomainPos()

template<unsigned int dim, typename T >
void BoxDistribution< dim, T >::getSSDomainPos ( size_t  id,
T(&)  pos[dim] 
)
inline

Function that return the position (point P1) of the sub-sub domain box in the space.

Parameters
idvertex id
posvector that contain x, y, z

Definition at line 304 of file BoxDistribution.hpp.

◆ getSubSubDomainComputationCost()

template<unsigned int dim, typename T >
size_t BoxDistribution< dim, T >::getSubSubDomainComputationCost ( size_t  id)
inline

function that get the weight of the vertex

Parameters
idvertex id

Definition at line 589 of file BoxDistribution.hpp.

◆ getUnbalance()

template<unsigned int dim, typename T >
float BoxDistribution< dim, T >::getUnbalance ( )
inline

Compute the unbalance of the processor compared to the optimal balance.

Warning
all processor must call this function
Returns
the unbalance from the optimal one 0.01 mean 1%

Definition at line 418 of file BoxDistribution.hpp.

◆ onTest()

template<unsigned int dim, typename T >
void BoxDistribution< dim, T >::onTest ( )
inline

It set the Classs on test mode.

At the moment it fix the seed to have reproducible results

Definition at line 453 of file BoxDistribution.hpp.

◆ operator=() [1/2]

template<unsigned int dim, typename T >
BoxDistribution & BoxDistribution< dim, T >::operator= ( BoxDistribution< dim, T > &&  mt)
inline

operator=

Parameters
mtobject to copy
Returns
itself

Definition at line 536 of file BoxDistribution.hpp.

◆ operator=() [2/2]

template<unsigned int dim, typename T >
BoxDistribution & BoxDistribution< dim, T >::operator= ( const BoxDistribution< dim, T > &  mt)
inline

operator=

Parameters
mtobject to copy
Returns
itself

Definition at line 515 of file BoxDistribution.hpp.

◆ operator==()

template<unsigned int dim, typename T >
bool BoxDistribution< dim, T >::operator== ( const BoxDistribution< dim, T > &  mt)
inline

operator==

Parameters
mtMetis distribution to compare with
Returns
true if the distribution match

Definition at line 556 of file BoxDistribution.hpp.

◆ redecompose()

template<unsigned int dim, typename T >
void BoxDistribution< dim, T >::redecompose ( )
inline

Redecompose current decomposition.

Definition at line 289 of file BoxDistribution.hpp.

◆ refine()

template<unsigned int dim, typename T >
void BoxDistribution< dim, T >::refine ( )
inline

Refine current decomposition.

In metis case it just re-decompose

Definition at line 277 of file BoxDistribution.hpp.

◆ setCommunicationCost()

template<unsigned int dim, typename T >
void BoxDistribution< dim, T >::setCommunicationCost ( size_t  id,
size_t  e,
size_t  cost 
)
inline

Set communication cost between neighborhood sub-sub-domains (weight on the edge)

Parameters
idsub-sub domain
eid in the neighborhood list (id in the adjacency list)
cost

Definition at line 372 of file BoxDistribution.hpp.

◆ setComputationCost()

template<unsigned int dim, typename T >
void BoxDistribution< dim, T >::setComputationCost ( size_t  id,
size_t  cost 
)
inline

Set computation cost on a sub-sub domain.

Parameters
idsub-sub domain id
cost

Definition at line 341 of file BoxDistribution.hpp.

◆ setDistTol()

template<unsigned int dim, typename T >
void BoxDistribution< dim, T >::setDistTol ( double  tol)
inline

Set the tolerance for each partition.

Parameters
toltolerance

Definition at line 578 of file BoxDistribution.hpp.

◆ setMigrationCost()

template<unsigned int dim, typename T >
void BoxDistribution< dim, T >::setMigrationCost ( size_t  id,
size_t  cost 
)
inline

Set migration cost on a sub-sub domain.

Parameters
idof the sub-sub domain
cost

Definition at line 356 of file BoxDistribution.hpp.

◆ write()

template<unsigned int dim, typename T >
void BoxDistribution< dim, T >::write ( std::string  out)
inline

Write the distribution graph into file.

Parameters
outoutput filename

Definition at line 466 of file BoxDistribution.hpp.

Field Documentation

◆ computation

template<unsigned int dim, typename T >
constexpr unsigned int BoxDistribution< dim, T >::computation = nm_v_computation
staticconstexpr

Definition at line 108 of file BoxDistribution.hpp.

◆ domain

template<unsigned int dim, typename T >
Box<dim, T> BoxDistribution< dim, T >::domain
private

rectangular domain to decompose

Definition at line 64 of file BoxDistribution.hpp.

◆ gp

template<unsigned int dim, typename T >
Graph_CSR<nm_v<dim>, nm_e> BoxDistribution< dim, T >::gp
private

Global sub-sub-domain graph.

Definition at line 67 of file BoxDistribution.hpp.

◆ gr

template<unsigned int dim, typename T >
grid_sm<dim, void> BoxDistribution< dim, T >::gr
private

Structure that store the cartesian grid information.

Definition at line 61 of file BoxDistribution.hpp.

◆ subsub_own

template<unsigned int dim, typename T >
openfpm::vector<int> BoxDistribution< dim, T >::subsub_own
private

Definition at line 72 of file BoxDistribution.hpp.

◆ testing

template<unsigned int dim, typename T >
bool BoxDistribution< dim, T >::testing = false
private

Flag that indicate if we are doing a test (In general it fix the seed)

Definition at line 70 of file BoxDistribution.hpp.

◆ v_cl

template<unsigned int dim, typename T >
Vcluster& BoxDistribution< dim, T >::v_cl
private

Vcluster.

Definition at line 58 of file BoxDistribution.hpp.


The documentation for this class was generated from the following file: