OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
MetisDistribution< 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 MetisDistribution< 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);

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 30 of file MetisDistribution.hpp.

#include <MetisDistribution.hpp>

Data Structures

struct  met_sub_w
 sub-domain list and weight More...
 

Public Member Functions

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

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. More...
 
void check_overflowe (size_t id, size_t e)
 Check that the sub-sub-domain id exist. More...
 

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, 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)
 
Metis< Graph_CSR< nm_v, nm_e > > metis_graph
 Metis decomposer utility.
 
std::unordered_map< size_t,
size_t > 
owner_scs
 unordered map that map global sub-sub-domain to owned_cost_sub id
 
openfpm::vector< met_sub_wowner_cost_sub
 list owned sub-sub-domains set for computation cost
 
openfpm::vector< met_sub_wrecv_ass
 received assignment
 

Constructor & Destructor Documentation

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

constructor

Parameters
v_clvcluster

Definition at line 114 of file MetisDistribution.hpp.

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

Copy constructor.

Parameters
mtdistribution to copy

Definition at line 127 of file MetisDistribution.hpp.

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

Copy constructor.

Parameters
mtdistribution to copy

Definition at line 142 of file MetisDistribution.hpp.

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

Destructor.

Definition at line 155 of file MetisDistribution.hpp.

Member Function Documentation

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

Check that the sub-sub-domain id exist.

Parameters
idsub-sub-domain id

Definition at line 78 of file MetisDistribution.hpp.

template<unsigned int dim, typename T>
void MetisDistribution< 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 94 of file MetisDistribution.hpp.

template<unsigned int dim, typename T>
void MetisDistribution< 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 169 of file MetisDistribution.hpp.

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

Distribute the sub-sub-domains.

Definition at line 217 of file MetisDistribution.hpp.

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

Get the decomposition counter.

Returns
the decomposition counter

Definition at line 665 of file MetisDistribution.hpp.

template<unsigned int dim, typename T>
size_t MetisDistribution< 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 346 of file MetisDistribution.hpp.

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

Get the current graph (main)

Returns
the current sub-sub domain Graph

Definition at line 206 of file MetisDistribution.hpp.

template<unsigned int dim, typename T>
size_t MetisDistribution< 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 484 of file MetisDistribution.hpp.

template<unsigned int dim, typename T>
size_t MetisDistribution< 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 436 of file MetisDistribution.hpp.

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

Returns total number of sub-sub-domains.

Returns
sub-sub domain numbers

Definition at line 424 of file MetisDistribution.hpp.

template<unsigned int dim, typename T>
size_t MetisDistribution< 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 496 of file MetisDistribution.hpp.

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

Compute the processor load.

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

Definition at line 536 of file MetisDistribution.hpp.

template<unsigned int dim, typename T>
void MetisDistribution< 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 325 of file MetisDistribution.hpp.

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

function that get the weight of the vertex

Parameters
idvertex id

Definition at line 642 of file MetisDistribution.hpp.

template<unsigned int dim, typename T>
float MetisDistribution< 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 454 of file MetisDistribution.hpp.

template<unsigned int dim, typename T>
void MetisDistribution< 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 506 of file MetisDistribution.hpp.

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

operator=

Parameters
mtobject to copy
Returns
itself

Definition at line 568 of file MetisDistribution.hpp.

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

operator=

Parameters
mtobject to copy
Returns
itself

Definition at line 589 of file MetisDistribution.hpp.

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

operator==

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

Definition at line 610 of file MetisDistribution.hpp.

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

Redecompose current decomposition.

Definition at line 310 of file MetisDistribution.hpp.

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

Refine current decomposition.

In metis case it just re-decompose

Definition at line 298 of file MetisDistribution.hpp.

template<unsigned int dim, typename T>
void MetisDistribution< 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 406 of file MetisDistribution.hpp.

template<unsigned int dim, typename T>
void MetisDistribution< 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 362 of file MetisDistribution.hpp.

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

Set the tolerance for each partition.

Parameters
toltolerance

Definition at line 630 of file MetisDistribution.hpp.

template<unsigned int dim, typename T>
void MetisDistribution< 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 388 of file MetisDistribution.hpp.

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

Write the distribution graph into file.

Parameters
outoutput filename

Definition at line 519 of file MetisDistribution.hpp.


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