8#ifndef SRC_DECOMPOSITION_BOXDISTRIBUTION_HPP_
9#define SRC_DECOMPOSITION_BOXDISTRIBUTION_HPP_
11#include "SubdomainGraphNodes.hpp"
12#include "Vector/map_vector.hpp"
13#include "VCluster/VCluster.hpp"
14#include "Graph/map_graph.hpp"
15#include "Graph/CartesianGraphFactory.hpp"
16#include "VTKWriter/VTKWriter.hpp"
18#define BOX_DISTRIBUTION_ERROR_OBJECT std::runtime_error("Box distribution runtime error");
28 for (
int i = 3; i <= sqrt(n); i = i+2)
54template<
unsigned int dim,
typename T>
84 std::cerr <<
"Error " << __FILE__
":" << __LINE__ <<
" such sub-sub-domain doesn't exist (id = " <<
id <<
", " <<
"total size = " <<
gp.
getNVertex() <<
")\n";
85 ACTION_ON_ERROR(BOX_DISTRIBUTION_ERROR_OBJECT)
100 std::cerr <<
"Error " << __FILE__
":" << __LINE__ <<
" for the sub-sub-domain " <<
id <<
" such neighborhood doesn't exist (e = " << e <<
", " <<
"total size = " <<
gp.
getNChilds(
id) <<
")\n";
101 ACTION_ON_ERROR(BOX_DISTRIBUTION_ERROR_OBJECT)
108 static constexpr unsigned int computation = nm_v_computation;
119 check_new(
this,8,VECTOR_EVENT,1);
133 check_new(
this,8,VECTOR_EVENT,1);
147 check_new(
this,8,VECTOR_EVENT,1);
178 for (
size_t i = 0 ; i < dim ; i++)
179 bc[i] = NON_PERIODIC;
187 gp = g_factory_part.template construct<NO_EDGE, nm_v_id, T, dim - 1, 0>(
gr.
getSize(),
domain, bc);
194 gp.
vertex(i).template get<nm_v_x>()[2] = 0.0;
199 gp.
vertex(i).template get<nm_v_global_id>() = i;
234 for (
int i = 0 ; i < dim ; i++)
237 for (
int i = 0 ; i < facts.
size() ; i++)
238 {div[i % dim] *= facts.get(i);}
240 for (
int i = 0 ; i < dim ; i++)
242 ln[i] =
gr.
size(i) / div[i];
243 ln_d[i] = (double)
gr.
size(i) / div[i];
254 for (
int i = 0 ; i < dim ; i++)
256 key_prc.
set_d(i,key.get(i)/ln_d[i]);
257 if (key_prc.
get(i) >= div[i])
258 {key_prc.
set_d(i,div[i]-1);}
263 gp.
vertex(i).template get<nm_v_proc_id>() = gr_proc.
LinId(key_prc);
312 pos[0] =
gp.
vertex(
id).template get<nm_v_x>()[0];
313 pos[1] =
gp.
vertex(
id).template get<nm_v_x>()[1];
315 {pos[2] =
gp.
vertex(
id).template get<nm_v_x>()[2];}
331 return gp.
vertex(
id).template get<nm_v_computation>();
433 return subsub_own.
size();
445 return subsub_own.get(
id);
495 {loads.get(
gp.template vertex_p<nm_v_proc_id>(i)) +=
gp.template vertex_p<nm_v_computation>(i);}
499 v_cl.
send(i,1234,&loads.get(i),
sizeof(
size_t));
502 v_cl.
recv(0,1234,&load,
sizeof(
size_t));
525 this->subsub_own = mt.subsub_own;
543 this->domain = mt.domain;
544 this->gp.
swap(mt.gp);
545 this->subsub_own.swap(mt.subsub_own);
564 ret &= (this->gr == mt.
gr);
565 ret &= (this->domain == mt.
domain);
566 ret &= (this->gp == mt.
gp);
568 ret &= this->subsub_own == mt.subsub_own;
593 std::cerr << __FILE__ <<
":" << __LINE__ <<
"Such vertex doesn't exist (id = " <<
id <<
", " <<
"total size = " <<
gp.
getNVertex() <<
")\n";
Class that distribute sub-sub-domains across processors using Metis Library.
size_t get_ndec()
Get the decomposition counter.
float getUnbalance()
Compute the unbalance of the processor compared to the optimal balance.
Graph_CSR< nm_v< dim >, nm_e > gp
Global sub-sub-domain graph.
size_t getNOwnerSubSubDomains() const
Return the total number of sub-sub-domains in the distribution graph.
size_t getSubSubDomainComputationCost(size_t id)
function that get the weight of the vertex
size_t getNSubSubDomainNeighbors(size_t id)
Returns total number of neighbors of one sub-sub-domain.
~BoxDistribution()
Destructor.
void write(std::string out)
Write the distribution graph into file.
Graph_CSR< nm_v< dim >, nm_e > & getGraph()
Get the current graph (main)
void setMigrationCost(size_t id, size_t cost)
Set migration cost on a sub-sub domain.
bool operator==(const BoxDistribution &mt)
operator==
size_t getProcessorLoad()
Compute the processor load.
BoxDistribution & operator=(const BoxDistribution &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.
void redecompose()
Redecompose current decomposition.
BoxDistribution & operator=(BoxDistribution &&mt)
operator=
void setComputationCost(size_t id, size_t cost)
Set computation cost on a sub-sub domain.
grid_sm< dim, void > gr
Structure that store the cartesian grid information.
BoxDistribution(Vcluster<> &v_cl)
constructor
void check_overflow(size_t id)
Check that the sub-sub-domain id exist.
void refine()
Refine current decomposition.
void decompose()
Distribute the sub-sub-domains.
BoxDistribution(const BoxDistribution &mt)
Copy constructor.
void setDistTol(double tol)
Set the tolerance for each partition.
size_t getOwnerSubSubDomain(size_t id) const
Return the id of the set sub-sub-domain.
bool testing
Flag that indicate if we are doing a test (In general it fix the seed)
void createCartGraph(grid_sm< dim, void > &grid, Box< dim, T > dom)
create a Cartesian distribution graph
BoxDistribution(BoxDistribution &&mt)
Copy constructor.
size_t getComputationalCost(size_t id)
function that get the computational cost of the sub-sub-domain
size_t getNSubSubDomains()
Returns total number of sub-sub-domains.
Box< dim, T > domain
rectangular domain to decompose
void setCommunicationCost(size_t id, size_t e, size_t cost)
Set communication cost between neighborhood sub-sub-domains (weight on the edge)
void onTest()
It set the Classs on test mode.
void check_overflowe(size_t id, size_t e)
Check that the sub-sub-domain id exist.
This class represent an N-dimensional box.
This class construct a cartesian graph.
Structure that store a graph in CSR format or basically in compressed adjacency matrix format.
auto vertex(size_t id) -> decltype(v.get(id))
Function to access the vertex.
size_t getNChilds(size_t c) const
Return the number of childs of a vertex.
void swap(Graph_CSR< V, E > &g)
swap the memory of g with this graph
size_t getNVertex() const
Return the number of the vertex.
void execute()
Execute all the requests.
size_t rank()
Get the process unit id.
size_t size()
Get the total number of processors.
size_t getProcessUnitID()
Get the process unit id.
size_t getProcessingUnits()
Get the total number of processors.
bool recv(size_t proc, size_t tag, void *v, size_t sz)
Recv data from a processor.
bool send(size_t proc, size_t tag, const void *mem, size_t sz)
Send data to a processor.
Implementation of VCluster class.
const grid_key_dx< dim > & get() const
Get the actual key.
bool isNext()
Check if there is the next element.
grid_key_dx is the key to access any element in the grid
__device__ __host__ void set_d(index_type i, index_type id)
Set the i index.
__device__ __host__ index_type get(index_type i) const
Get the i index.
mem_id LinId(const grid_key_dx< N, ids_type > &gk, const signed char sum_id[N]) const
Linearization of the grid_key_dx with a specified shift.
__device__ __host__ const size_t(& getSize() const)[N]
Return the size of the grid as an array.
__device__ __host__ size_t size() const
Return the size of the grid.
Implementation of 1-D std::vector like structure.
sub-domain edge graph node