8 #ifndef SRC_DECOMPOSITION_METISDISTRIBUTION_HPP_ 
    9 #define SRC_DECOMPOSITION_METISDISTRIBUTION_HPP_ 
   11 #include "SubdomainGraphNodes.hpp" 
   12 #include "metis_util.hpp" 
   14 #define METIS_DISTRIBUTION_ERROR_OBJECT std::runtime_error("Metis runtime error"); 
   29 template<
unsigned int dim, 
typename T>
 
   61         static bool noPointers() {
return true;}
 
   83             std::cerr << 
"Error " << __FILE__ 
":" << __LINE__ << 
" such sub-sub-domain doesn't exist (id = " << 
id << 
", " << 
"total size = " << 
gp.
getNVertex() << 
")\n";
 
   84             ACTION_ON_ERROR(METIS_DISTRIBUTION_ERROR_OBJECT)
 
   99             std::cerr << 
"Error " << __FILE__ 
":" << __LINE__ << 
" for the sub-sub-domain " << 
id << 
" such neighborhood doesn't exist (e = " << e << 
", " << 
"total size = " << 
gp.
getNChilds(
id) << 
")\n";
 
  100             ACTION_ON_ERROR(METIS_DISTRIBUTION_ERROR_OBJECT)
 
  118             check_new(
this,8,VECTOR_EVENT,1);
 
  132             check_new(
this,8,VECTOR_EVENT,1);
 
  146             check_new(
this,8,VECTOR_EVENT,1);
 
  177         for (
size_t i = 0 ; i < dim ; i++)
 
  178             bc[i] = NON_PERIODIC;
 
  193                 gp.
vertex(i).template get<nm_v::x>()[2] = 0.0;
 
  198             gp.
vertex(i).template get<nm_v::global_id>() = i;
 
  232                 for (
size_t i = 0 ; i < 
recv_ass.size() ; i++)
 
  247                 for (
size_t i = 0 ; i < 
recv_ass.size() ; i++)
 
  258                     recv_ass.get(i).w = 
gp.template vertex_p<nm_v::proc_id>(i);
 
  278         for (
size_t i = 0 ; i < 
recv_ass.size() ; i++)
 
  333         pos[0] = 
gp.
vertex(
id).template get<nm_v::x>()[0];
 
  334         pos[1] = 
gp.
vertex(
id).template get<nm_v::x>()[1];
 
  336             pos[2] = 
gp.
vertex(
id).template get<nm_v::x>()[2];
 
  352         return gp.
vertex(
id).template get<nm_v::computation>();
 
  374             std::cerr << __FILE__ << 
":" << __LINE__ << 
" Error you are setting a sub-sub-domain the processor does not own" << std::endl;
 
  378             size_t id = fnd->second;
 
  397         gp.
vertex(
id).template get<nm_v::migration>() = cost;
 
  416         gp.
getChildEdge(
id, e).template get<nm_e::communication>() = cost;
 
  461         float load_avg = load_p;
 
  476         return ((
float)load_p - load_avg) / load_avg;
 
  548                 loads.get(
gp.template vertex_p<nm_v::proc_id>(i)) += 
gp.template vertex_p<nm_v::computation>(i);
 
  552                 v_cl.
send(i,1234,&loads.get(i),
sizeof(size_t));
 
  555         v_cl.
recv(0,1234,&load,
sizeof(
size_t));
 
  618         ret &= (this->
gr == mt.
gr);
 
  620         ret &= (this->
gp == mt.
gp);
 
  646             std::cerr << __FILE__ << 
":" << __LINE__ << 
"Such vertex doesn't exist (id = " << 
id << 
", " << 
"total size = " << 
gp.
getNVertex() << 
")\n";
 
  652             std::cerr << __FILE__ << 
":" << __LINE__ << 
" Error you are setting a sub-sub-domain that the processor does not own" << std::endl;
 
  656         size_t ids = fnd->second;
 
MetisDistribution & operator=(MetisDistribution &&mt)
operator= 
 
Metis< Graph_CSR< nm_v, nm_e > > metis_graph
Metis decomposer utility. 
 
void sum(T &num)
Sum the numbers across all processors and get the result. 
 
size_t getSubSubDomainComputationCost(size_t id)
function that get the weight of the vertex 
 
void onTest()
It set the Classs on test mode. 
 
size_t getNSubSubDomainNeighbors(size_t id)
Returns total number of neighbors of one sub-sub-domain. 
 
bool testing
Flag that indicate if we are doing a test (In general it fix the seed) 
 
size_t getProcessUnitID()
Get the process unit id. 
 
openfpm::vector< met_sub_w > recv_ass
received assignment 
 
void execute()
Execute all the requests. 
 
size_t getNSubSubDomains()
Returns total number of sub-sub-domains. 
 
void onTest(bool testing)
It set Metis on test. 
 
Graph_CSR< nm_v, nm_e > gp
Global sub-sub-domain graph. 
 
void decompose()
Decompose the graph. 
 
bool Bcast(openfpm::vector< T, Mem, gr > &v, size_t root)
Broadcast the data to all processors. 
 
size_t getProcessorLoad()
Compute the processor load. 
 
std::unordered_map< size_t, size_t > owner_scs
unordered map that map global sub-sub-domain to owned_cost_sub id 
 
size_t getOwnerSubSubDomain(size_t id) const 
Return the id of the set sub-sub-domain. 
 
void setMigrationCost(size_t id, size_t cost)
Set migration cost on a sub-sub domain. 
 
Helper class to define Metis graph. 
 
bool send(size_t proc, size_t tag, const void *mem, size_t sz)
Send data to a processor. 
 
auto getChildEdge(size_t v, size_t v_e) -> decltype(e.get(0))
Get the vertex edge. 
 
Implementation of VCluster class. 
 
void createCartGraph(grid_sm< dim, void > &grid, Box< dim, T > dom)
create a Cartesian distribution graph 
 
This class construct a cartesian graph. 
 
void write(std::string out)
Write the distribution graph into file. 
 
size_t getComputationalCost(size_t id)
function that get the computational cost of the sub-sub-domain 
 
void setDistTol(real_t tol)
Distribution tolerance. 
 
void check_overflow(size_t id)
Check that the sub-sub-domain id exist. 
 
static const unsigned int computation
computation property id in boost::fusion::vector 
 
MetisDistribution(Vcluster &v_cl)
constructor 
 
bool recv(size_t proc, size_t tag, void *v, size_t sz)
Recv data from a processor. 
 
const size_t(& getSize() const)[N]
Return the size of the grid as an array. 
 
bool SGather(T &send, S &recv, size_t root)
Semantic Gather, gather the data from all processors into one node. 
 
void setCommunicationCost(size_t id, size_t e, size_t cost)
Set communication cost between neighborhood sub-sub-domains (weight on the edge) 
 
void setDistTol(double tol)
Set the tolerance for each partition. 
 
This class represent an N-dimensional box. 
 
MetisDistribution(const MetisDistribution &mt)
Copy constructor. 
 
void redecompose()
Redecompose current decomposition. 
 
float getUnbalance()
Compute the unbalance of the processor compared to the optimal balance. 
 
auto vertex(size_t id) -> decltype(v.get(id))
Function to access the vertex. 
 
size_t w
sub-domain weight / assignment (it depend in which context is used) 
 
size_t getNVertex() const 
Return the number of the vertex. 
 
size_t getNOwnerSubSubDomains() const 
Return the total number of sub-sub-domains in the distribution graph. 
 
static const unsigned int id
id property id in boost::fusion::vector 
 
size_t get_ndec()
Get the decomposition counter. 
 
void swap(Graph_CSR< V, E > &g)
swap the memory of g with this graph 
 
size_t getNChilds(size_t c) const 
Return the number of childs of a vertex. 
 
~MetisDistribution()
Destructor. 
 
size_t get_ndec()
Get the decomposition counter. 
 
MetisDistribution(MetisDistribution &&mt)
Copy constructor. 
 
openfpm::vector< met_sub_w > owner_cost_sub
list owned sub-sub-domains set for computation cost 
 
void setComputationCost(size_t id, size_t cost)
Set computation cost on a sub-sub domain. 
 
void inc_dec()
Increment the decomposition counter. 
 
sub-domain list and weight 
 
void decompose()
Distribute the sub-sub-domains. 
 
MetisDistribution & operator=(const MetisDistribution &mt)
operator= 
 
void getSSDomainPos(size_t id, T(&pos)[dim])
Function that return the position (point P1) of the sub-sub domain box in the space. 
 
bool operator==(const MetisDistribution &mt)
operator== 
 
Graph_CSR< nm_v, nm_e > & getGraph()
Get the current graph (main) 
 
Box< dim, T > domain
rectangular domain to decompose 
 
void initMetisGraph(int nc, bool useWeights)
Initialize the METIS graph. 
 
Class that distribute sub-sub-domains across processors using Metis Library. 
 
static const unsigned int proc_id
proc_id property id in boost::fusion::vector 
 
Implementation of 1-D std::vector like structure. 
 
size_t getProcessingUnits()
Get the total number of processors. 
 
void check_overflowe(size_t id, size_t e)
Check that the sub-sub-domain id exist. 
 
void refine()
Refine current decomposition. 
 
grid_sm< dim, void > gr
Structure that store the cartesian grid information.