8#ifndef SRC_DECOMPOSITION_NN_PROCESSOR_HPP_
9#define SRC_DECOMPOSITION_NN_PROCESSOR_HPP_
12#include <unordered_map>
22template<
unsigned int dim,
typename T,
template <
typename>
class layout_base,
typename Memory>
95 for (
size_t k = 0 ; k < dim ; k++)
98 if (box.
getLow(k) == domain.getLow(k) &&
shift.get(k) > 0)
100 box.
setLow(k,domain.getHigh(k));
103 else if (box.
getLow(k) == domain.getHigh(k) &&
shift.get(k) < 0)
105 box.
setLow(k,domain.getLow(k));
108 else if (box.
getHigh(k) == domain.getHigh(k) &&
shift.get(k) < 0)
110 box.
setHigh(k,domain.getLow(k));
113 else if (box.
getHigh(k) == domain.getLow(k) &&
shift.get(k) > 0)
115 box.
setHigh(k,domain.getHigh(k));
139 static void *
message_alloc(
size_t msg_i ,
size_t total_msg,
size_t total_p,
size_t i,
size_t ri,
size_t tag,
void * ptr)
163 nnpst.
r_sub.add(r_sub);
179 for (
long int i = dim-1 ; i >= 0 ; i--)
183 for (
size_t j = 0 ; j < cmbs.size() ; j++)
192 for (
size_t k = 0 ; k < dim ; k++)
198 bp.
setHigh(k,domain.getHigh(k));
199 shift.get(k) = -domain.getHigh(k)+domain.getLow(k);
202 bp.
setLow(k,domain.getLow(k));
203 bp.
setHigh(k,domain.getHigh(k));
207 bp.
setLow(k,domain.getLow(k));
209 shift.get(k) = domain.getHigh(k)-domain.getLow(k);
222 for (
size_t l = 0 ; l < nn_sub.
size(); l++)
257 for (
size_t i = 0 ; i < nnp_bx.
bx.size() ; i++)
262 nnps.
bx.add(nnps_tmp.
bx.get(i));
263 nnps.
pos.add(nnps_tmp.
pos.get(i));
306 if (cmb.n_zero() == dim)
309 for (
size_t i = 0 ; i < dim ; i++)
311 if (bc[i] == NON_PERIODIC && cmb.
getComb()[i] != 0)
358 template<
typename Memory2,
template <
typename>
class layout_base2>
416 template<
typename Memory2,
template <
typename>
class layout_base2>
422 boxes = nnp.private_get_boxes();
437 for (
size_t i = 0 ; i < box_nn_processor.size() ; i++)
439 for (
size_t j = 0 ; j < box_nn_processor.get(i).size() ; j++)
453 for (
size_t i = 0 ; i < box_nn_processor.size() ; i++)
455 for (
size_t j = 0 ; j < box_nn_processor.get(i).size() ; j++)
458 size_t proc_id = box_nn_processor.get(i).get(j);
474 for (
size_t b = 0 ; b < box_nn_processor.size() ; b++)
476 for (
size_t p = 0 ; p < box_nn_processor.get(b).size() ; p++)
478 size_t prc = box_nn_processor.get(b).get(p);
484 boxes.get(
id).add(sub_domains.get(b));
499 for (
size_t i = 0 ; i < nnp_bx.
bx.size() ; i++)
548 std::cerr <<
"Error " << __FILE__ <<
":" << __LINE__ <<
" error this process rank is not adjacent to the local processor";
552 return key->second.r_sub;
568 std::cerr <<
"Error " << __FILE__ <<
":" << __LINE__ <<
" error this process rank is not adjacent to the local processor";
572 return key->second.bx;
590 std::cerr <<
"Error " << __FILE__ <<
":" << __LINE__ <<
" error this process rank is not adjacent to the local processor";
594 return key->second.n_real_sub;
610 std::cerr <<
"Error " << __FILE__ <<
":" << __LINE__ <<
" error this process rank is not adjacent to the local processor";
613 return key->second.pos;
629 std::cerr <<
"Error " << __FILE__ <<
":" << __LINE__ <<
" error this process rank is not adjacent to the local processor";
632 return key->second.id;
662 std::cerr <<
"Error " << __FILE__ <<
":" << __LINE__ <<
" error this process rank is not adjacent to the local processor";
666 return key->second.id;
682 bool write(std::string output)
const
693 vtk_box2.write(output + std::string(
"subdomains_adjacent_") + std::to_string(
v_cl.
getProcessUnitID()) + std::string(
".vtk"));
709 std::cerr <<
"Warning " << __FILE__ <<
":" << __LINE__ <<
" apply BC is suppose to be called only one time\n";
This class represent an N-dimensional box.
__device__ __host__ T getLow(int i) const
get the i-coordinate of the low bound interval of the box
__device__ __host__ bool Intersect(const Box< dim, T > &b, Box< dim, T > &b_out) const
Intersect.
__device__ __host__ T getHigh(int i) const
get the high interval of the box
__device__ __host__ void setHigh(int i, T val)
set the high interval of the box
__device__ __host__ void setLow(int i, T val)
set the low interval of the box
This class calculate elements of the hyper-cube.
static std::vector< comb< dim > > getCombinations_R_bc(size_t d, const size_t(&bc)[dim])
This class implement the point shape in an N-dimensional space.
This class represent an N-dimensional box.
void sendrecvMultipleMessagesNBX(openfpm::vector< size_t > &prc, openfpm::vector< T > &data, openfpm::vector< size_t > &prc_recv, openfpm::vector< size_t > &recv_sz, void *(*msg_alloc)(size_t, size_t, size_t, size_t, size_t, size_t, void *), void *ptr_arg, long int opt=NONE)
Send and receive multiple messages.
size_t getProcessUnitID()
Get the process unit id.
Implementation of VCluster class.
This class store the adjacent processors and the adjacent sub_domains.
std::unordered_map< size_t, N_box< dim, T > > nn_processor_subdomains
for each near processor store the sub-domains of the near processors
void flush()
Flush the temporal added sub-domain to the processor sub-domain.
size_t recv_cnt
Receive counter.
size_t ProctoID(size_t p) const
Convert the processor rank to the id in the list.
void consistent_shift(Box< dim, T > &box, const Box< dim, T > &domain, const Point< dim, T > &shift)
It shift a box but it does consistently.
nn_prcs< dim, T, layout_base, Memory > & operator=(const nn_prcs< dim, T, layout_base, Memory > &nnp)
Copy the object.
openfpm::vector< openfpm::vector< ::SpaceBox< dim, T > > > boxes
contain the set of sub-domains sent to the other processors
const openfpm::vector< comb< dim > > & getNearSubdomainsPos(size_t p_id) const
Get the sub-domains sector position of a near processor.
openfpm::vector< openfpm::vector< size_t > > & private_get_proc_adj_box()
Return the internal proc_adj_box.
size_t getNearProcessor(size_t p_id) const
Get the near processor id.
bool is_equal(nn_prcs< dim, T, layout_base, Memory > &np)
Check if the nn_prcs contain the same information.
size_t getNRealSubdomains(size_t p_id) const
Get the number of real sub-domains of a near processor.
static void * message_alloc(size_t msg_i, size_t total_msg, size_t total_p, size_t i, size_t ri, size_t tag, void *ptr)
Message allocation.
openfpm::vector< openfpm::vector< ::SpaceBox< dim, T > > > & private_get_boxes()
Return the internal boxes structure.
static bool check_valid(comb< dim > cmb, const size_t(&bc)[dim])
const openfpm::vector< size_t > & getNearSubdomainsRealId(size_t p_id) const
Get the real-id of the sub-domains of a near processor.
void add_box_periodic(const Box< dim, T > &domain, const Ghost< dim, T > &ghost, const size_t(&bc)[dim])
In case of periodic boundary conditions we replicate the sub-domains at the border.
size_t getNNProcessors() const
Get the number of Near processors.
void applyBC(const Box< dim, T > &domain, const Ghost< dim, T > &ghost, const size_t(&bc)[dim])
Apply boundary conditions.
Vcluster & v_cl
Virtual cluster.
openfpm::vector< size_t > & private_get_nn_processors()
Return the internal nn_processor struct.
nn_prcs(Vcluster<> &v_cl)
Constructor require Vcluster.
std::unordered_map< size_t, N_box< dim, T > > nn_processor_subdomains_tmp
when we add new boxes, are added here
nn_prcs(const nn_prcs< dim, T, layout_base, Memory > &ilg)
Constructor from another nn_prcs.
openfpm::vector< openfpm::vector< size_t > > proc_adj_box
void add_nn_subdomain(size_t i, size_t r_sub, const Box< dim, T > &bx, const comb< dim > &c)
add sub-domains to processor for a near processor i
openfpm::vector< size_t > & get_nn_processors()
Used for testing porpose do not use.
void create(const openfpm::vector< openfpm::vector< long unsigned int > > &box_nn_processor, const openfpm::vector< SpaceBox< dim, T >, Memory, layout_base > &sub_domains)
Create the list of adjacent processors and the list of adjacent sub-domains.
bool aBC
applyBC function is suppose to be called only one time
const openfpm::vector< ::Box< dim, T > > & getNearSubdomains(size_t p_id) const
Get the sub-domains of a near processor.
openfpm::vector< size_t > nn_processors
List of adjacent processors.
nn_prcs< dim, T, layout_base, Memory > & operator=(nn_prcs< dim, T, layout_base, Memory > &&nnp)
Copy the object.
bool write(std::string output) const
Write the decomposition as VTK file.
nn_prcs< dim, T, layout_base, Memory > & operator=(nn_prcs< dim, T, layout_base2, Memory2 > &&nnp)
Copy the object.
std::unordered_map< size_t, N_box< dim, T > > & get_nn_processor_subdomains()
Used for testing porpose do not use.
const openfpm::vector< size_t > & getSentSubdomains(size_t p_id) const
For each near processor it give a vector with the id of the local sub-domain sent to that processor.
size_t IDtoProc(size_t id) const
Return the processor id of the near processor list at place id.
nn_prcs< dim, T, layout_base, Memory > & operator=(const nn_prcs< dim, T, layout_base2, Memory2 > &nnp)
Copy the object.
std::unordered_map< size_t, N_box< dim, T > > & private_get_nn_processor_subdomains()
Return the internal nn_processor_subdomains.
void reset()
Reset the nn_prcs structure.
nn_prcs(nn_prcs< dim, T, layout_base, Memory > &&ilg)
Constructor from temporal ie_loc_ghost.
Implementation of 1-D std::vector like structure.
openfpm::vector< size_t > r_sub
openfpm::vector<::Box< dim, T > > bx
near processor sub-domains
size_t n_real_sub
Number of real sub-domains or sub-domain in the central sector.
openfpm::vector< comb< dim > > pos
near processor sector position (or where they live outside the domain)
Position of the element of dimension d in the hyper-cube of dimension dim.
signed char * getComb()
get the combination array pointer
void zero()
Set all the elements to zero.