12 #include "util/cuda_util.hpp"
13 #include "HDF5_wr/HDF5_wr.hpp"
14 #include "VCluster/VCluster.hpp"
15 #include "Space/Shape/Point.hpp"
16 #include "Vector/Iterators/vector_dist_iterator.hpp"
17 #include "Space/Shape/Box.hpp"
18 #include "Vector/vector_dist_key.hpp"
19 #include "memory/PtrMemory.hpp"
20 #include "NN/CellList/CellList.hpp"
21 #include "util/common.hpp"
22 #include "util/object_util.hpp"
23 #include "memory/ExtPreAlloc.hpp"
24 #include "CSVWriter/CSVWriter.hpp"
25 #include "VTKWriter/VTKWriter.hpp"
26 #include "Decomposition/common.hpp"
27 #include "Grid/Iterators/grid_dist_id_iterator_dec.hpp"
28 #include "Grid/grid_key_dx_iterator_hilbert.hpp"
29 #include "Vector/vector_dist_ofb.hpp"
30 #include "Decomposition/CartDecomposition.hpp"
31 #include "data_type/aggregate.hpp"
32 #include "NN/VerletList/VerletList.hpp"
33 #include "vector_dist_comm.hpp"
34 #include "DLB/LB_Model.hpp"
35 #include "Vector/vector_map_iterator.hpp"
36 #include "NN/CellList/ParticleIt_Cells.hpp"
37 #include "NN/CellList/SFCKeys.hpp"
38 #include "Vector/vector_dist_kernel.hpp"
39 #include "NN/CellList/cuda/CellList_gpu.hpp"
40 #include "lib/pdata.hpp"
41 #include "cuda/vector_dist_operators_list_ker.hpp"
44 #include <type_traits>
46 #define DEC_GRAN(gr) ((size_t)gr << 32)
49 template<
unsigned int dim,
typename St>
using CELLLIST_GPU_SPARSE = CellList_gpu<dim,St,CudaMemory,shift_only<dim, St>,
true>;
52 #define VECTOR_DIST_ERROR_OBJECT std::runtime_error("Runtime vector distributed error");
55 #include "se_class3_vector.hpp"
59 #define SE_CLASS3_VDIST_CONSTRUCTOR ,se3(getDecomposition(),*this)
61 #define SE_CLASS3_VDIST_CONSTRUCTOR
65 constexpr
int GET = 1;
66 constexpr
int PUT = 2;
69 constexpr
int NO_GHOST = 0;
70 constexpr
int WITH_GHOST = 2;
80 template<
typename vector_type>
107 v.template getMemory<T::value>().decRef();
116 template<
typename T,
typename VectorType,
unsigned id,
typename =
void>
118 static T get(VectorType
const& vectorDist,
unsigned p) {
return 0.0; }
121 template<
typename T,
typename VectorType,
unsigned id>
123 struct getPropSFINAE<T, VectorType, id, std::enable_if_t<std::is_same<typename std::remove_reference<typename boost::fusion::result_of::at_c<typename VectorType::value_type::type, id>::type>::type, T>::value>> {
124 static T get(VectorType
const& vectorDist,
unsigned p) {
return vectorDist.template getProp<id>(p); }
162 template<
unsigned int dim,
184 static const unsigned int dims = dim;
188 typedef Memory Memory_type;
267 std::cerr << __FILE__ <<
":" << __LINE__ <<
" Error the domain is not valid " << box.
toString() << std::endl;
268 ACTION_ON_ERROR(VECTOR_DIST_ERROR_OBJECT);
280 for (
size_t i = 0 ; i < dim ; i++)
284 std::cerr << __FILE__ <<
":" << __LINE__ <<
" Error the cut off radius " << r_cut <<
" is bigger that the ghost layer on the dimension " << i <<
" lower=" <<
getDecomposition().getGhost().getLow(i) << std::endl;
285 ACTION_ON_ERROR(VECTOR_DIST_ERROR_OBJECT);
298 template<
typename CellL,
typename sfc_it>
304 v_pos_dest.resize(
vPos.size());
305 v_prp_dest.resize(
vPrp.size());
312 for (
size_t i = 0; i < dim ; i++)
313 {ksum.
set_d(i,cellList.getPadding(i));}
315 while (h_it.isNext())
317 auto key = h_it.get();
320 size_t lin = cellList.getGrid().LinId(key);
323 for (
size_t i = 0; i < cellList.getNelements(lin); i++)
326 auto v = cellList.get(lin,i);
327 v_pos_dest.get(count) =
vPos.get(v);
328 v_prp_dest.get(count) =
vPrp.get(v);
337 typedef decltype(
vPos) internal_position_vector_type;
358 static_cast<vector_dist_comm<dim,St,prop,Decomposition,Memory,layout_base> *
>(
this)->
operator=(
static_cast<vector_dist_comm<dim,St,prop,Decomposition,Memory,layout_base>>(v));
383 static_cast<vector_dist_comm<dim,St,prop,Decomposition,Memory,layout_base> *
>(
this)->
operator=(
static_cast<vector_dist_comm<dim,St,prop,Decomposition,Memory,layout_base> >(v));
412 check_new(
this,8,VECTOR_DIST_EVENT,4);
426 check_new(
this,8,VECTOR_DIST_EVENT,4);
446 check_new(
this,8,VECTOR_DIST_EVENT,4);
469 :
opt(0) SE_CLASS3_VDIST_CONSTRUCTOR
499 :
opt(
opt) SE_CLASS3_VDIST_CONSTRUCTOR
502 check_new(
this,8,VECTOR_DIST_EVENT,4);
532 for (
int i = 0 ; i <
vPos.template getMemory<0>().ref() - 1; i++)
534 vPos.template getMemory<0>().decRef();
537 for (
int i = 0 ; i <
vPrp.template getMemory<0>().ref() - 1; i++)
541 boost::mpl::for_each_ref<boost::mpl::range_c<
int,0,decltype(
vPrp)::value_type::max_prop>>(m);
574 #ifndef ONLY_READWRITE_GETTER
588 check_for_pos_nan_inf<prop::max_prop_real,prop::max_prop>(*
this,vec_key.getKey());
591 return vPos.template get<0>(vec_key.getKey());
606 check_for_pos_nan_inf<prop::max_prop_real,prop::max_prop>(*
this,vec_key.getKey());
608 return vPos.template get<0>(vec_key.getKey());
620 inline auto getPos(
size_t vec_key) -> decltype(
vPos.template get<0>(vec_key))
623 check_for_pos_nan_inf<prop::max_prop_real,prop::max_prop>(*
this,vec_key);
625 return vPos.template get<0>(vec_key);
637 inline auto getPos(
size_t vec_key)
const -> decltype(
vPos.template get<0>(vec_key))
640 check_for_pos_nan_inf<prop::max_prop_real,prop::max_prop>(*
this,vec_key);
642 return vPos.template get<0>(vec_key);
658 check_for_prop_nan_inf<id,prop::max_prop+SE3_STATUS>(*
this,vec_key.getKey());
660 return vPrp.template get<id>(vec_key.getKey());
676 check_for_prop_nan_inf<id,prop::max_prop+SE3_STATUS>(*
this,vec_key.getKey());
678 return vPrp.template get<id>(vec_key.getKey());
691 template<
unsigned int id>
inline auto getProp(
size_t vec_key) -> decltype(
vPrp.template get<id>(vec_key))
694 check_for_prop_nan_inf<id,prop::max_prop+SE3_STATUS>(*
this,vec_key);
696 return vPrp.template get<id>(vec_key);
709 template<
unsigned int id>
inline auto getProp(
size_t vec_key)
const -> decltype(
vPrp.template get<id>(vec_key))
712 check_for_prop_nan_inf<id,prop::max_prop+SE3_STATUS>(*
this,vec_key);
714 return vPrp.template get<id>(vec_key);
732 return vPos.template get<0>(vec_key.getKey());
746 return vPos.template get<0>(vec_key.getKey());
758 inline auto getPosNC(
size_t vec_key) -> decltype(
vPos.template get<0>(vec_key))
760 return vPos.template get<0>(vec_key);
772 inline auto getPosNC(
size_t vec_key)
const -> decltype(
vPos.template get<0>(vec_key))
774 return vPos.template get<0>(vec_key);
789 return vPrp.template get<id>(vec_key.getKey());
804 return vPrp.template get<id>(vec_key.getKey());
817 template<
unsigned int id>
inline auto getPropNC(
size_t vec_key) -> decltype(
vPrp.template get<id>(vec_key))
819 return vPrp.template get<id>(vec_key);
832 template<
unsigned int id>
inline auto getPropNC(
size_t vec_key)
const -> decltype(
vPrp.template get<id>(vec_key))
834 return vPrp.template get<id>(vec_key);
851 se3.template write<prop::max_prop_real>(*
this,vec_key.getKey());
854 return vPos.template get<0>(vec_key.getKey());
869 se3.template read<prop::max_prop_real>(*
this,vec_key.getKey());
872 return vPos.template get<0>(vec_key.getKey());
888 se3.template write<id>(*
this,vec_key.getKey());
891 return vPrp.template get<id>(vec_key.getKey());
907 se3.template read<id>(*
this,vec_key.getKey());
910 return vPrp.template get<id>(vec_key.getKey());
931 for (
size_t i = 0 ; i < prop::max_prop_real+1 ; i++)
932 vPrp.template get<prop::max_prop_real>(
ghostMarker-1)[i] = UNINITIALIZED;
951 #ifndef ONLY_READWRITE_GETTER
971 return vPos.template get<0>(
vPos.size() - 1);
981 template<
unsigned int id>
inline auto getLastProp() -> decltype(
vPrp.template get<id>(0))
998 se3.template read<prop::max_prop_real>(*
this,
ghostMarker-1);
1029 se3.template write<prop::max_prop_real>(*
this,
ghostMarker-1);
1062 template<
typename CellList_type = CellList<dim, St, Mem_fast<>, shift<dim, St>,
internal_position_vector_type > >
1077 template<
typename CellList_type = CellList<dim, St, Mem_fast<>, shift<dim, St>,
internal_position_vector_type > >
1093 template<
typename CellList_type = CellList<dim, St, Mem_fast<>, shift<dim, St>, decltype(vPos) > >
1096 if (
opt & CL_SYMMETRIC ||
opt & CL_LOCAL_SYMMETRIC) {
1098 if (!(
opt & BIND_DEC_TO_GHOST))
1102 std::cerr << __FILE__ <<
":" << __LINE__ <<
" Error the vector has been constructed without BIND_DEC_TO_GHOST, If you construct a vector without BIND_DEC_TO_GHOST the ghost must be full without reductions " << std::endl;
1103 ACTION_ON_ERROR(VECTOR_DIST_ERROR_OBJECT);
1108 CellDecomposer_sm<dim,St,shift<dim,St>> cd_sm;
1129 if (no_se3 ==
false)
1137 ghostEnlarge.
magnify(ghostEnlargeFactor);
1146 cl_param_calculate(pbox, div, r_cut, ghostEnlarge);
1172 template<
typename CellL = CellList<dim, St, Mem_fast<>, shift<dim, St> > >
1174 const size_t (& div)[dim],
1175 const size_t (& pad)[dim],
1176 size_t opt = CL_LINEAR_CELL_KEYS)
1179 if (!(
opt & BIND_DEC_TO_GHOST))
1183 std::cerr << __FILE__ <<
":" << __LINE__ <<
" Error the vector has been constructed without BIND_DEC_TO_GHOST, If you construct a vector without BIND_DEC_TO_GHOST the ghost must be full without reductions " << std::endl;
1184 ACTION_ON_ERROR(VECTOR_DIST_ERROR_OBJECT);
1189 size_t pad_max = pad[0];
1190 for (
size_t i = 1 ; i < dim ; i++)
1191 if (pad[i] > pad_max) pad_max = pad[i];
1194 CellDecomposer_sm<dim,St,shift<dim,St>> cd_sm;
1202 cellList.setOpt(
opt | CL_SYMMETRIC);
1203 cellList.Initialize(cd_sm,pbox,pad_max);
1222 template<
typename CellType = CellList_gpu<dim,St,CudaMemory,shift_only<dim, St>>>
1223 CellType getCellListGPU(St r_cut,
size_t opt = CL_NON_SYMMETRIC,
size_t NNIteratorBox = 1,
bool no_se3 =
false,
float ghostEnlargeFactor = 1.013)
1226 if (no_se3 ==
false)
1235 ghostEnlarge.
magnify(ghostEnlargeFactor);
1246 cl_param_calculate(pbox, div, r_cut, ghostEnlarge);
1248 CellType cellList(pbox,div);
1253 cellList.setOpt(
opt);
1254 cellList.setBoxNN(NNIteratorBox);
1273 template<
typename CellL = CellList<dim, St, Mem_fast<>, shift<dim, St> > >
1287 template<
unsigned int ... prp,
typename CellL>
1291 if (no_se3 ==
false)
1297 bool to_reconstruct = cellList.get_ndec() !=
getDecomposition().get_ndec();
1299 if (to_reconstruct ==
false)
1308 St r_cut = cellList.getCellBox().getRcut();
1310 if (cellList.getOpt() & CL_SYMMETRIC) {
1311 CellL cellListTmp = getCellListSym<CellL>(cellList.getDivWP(), cellList.getPadding());
1312 cellList.swap(cellListTmp);
1316 CellL cellListTmp = getCellList<CellL>(r_cut, cellList.getOpt());
1317 cellList.swap(cellListTmp);
1334 template<
unsigned int ... prp,
typename CellList_type>
1335 void updateCellListGPU(CellList_type & cellList,
bool no_se3 =
false)
1338 if (no_se3 ==
false)
1343 if (cellList.getOpt() & CL_GPU_REORDER_POSITION)
1346 if (cellList.getOpt() & CL_GPU_REORDER_PROPERTY)
1351 bool to_reconstruct = cellList.get_ndec() !=
getDecomposition().get_ndec();
1353 if (to_reconstruct ==
false)
1355 if (cellList.getOpt() & CL_GPU_REORDER_POSITION || cellList.getOpt() & CL_GPU_REORDER_PROPERTY) {
1357 cellList.template construct<decltype(
vPos),decltype(
vPrp),prp ...>(
1378 St r_cut = cellList.getCellBox().getRcut();
1380 CellList_type cellListTmp = getCellListGPU<CellList_type>(r_cut, cellList.getOpt(), cellList.getBoxNN());
1382 if (cellList.getOpt() & CL_GPU_REORDER_POSITION || cellList.getOpt() & CL_GPU_REORDER_PROPERTY) {
1383 cellListTmp.template construct<decltype(
vPos),decltype(
vPrp),prp ...>(
1399 cellList.swap(cellListTmp);
1412 template <
typename VerletList_type = VerletList<dim,St,VL_SYMMETRIC,Mem_fast<>,shift<dim,St>,decltype(vPos)>>
1415 return getVerlet<VL_SYMMETRIC, VerletList_type>(r_cut);
1425 template <
typename VerletList_type = VerletList<dim,St,VL_CRS_SYMMETRIC,Mem_fast<>,shift<dim,St>,decltype(vPos)>>
1429 if (!(
opt & BIND_DEC_TO_GHOST))
1431 std::cerr << __FILE__ <<
":" << __LINE__ <<
" Error the vector has been constructed without BIND_DEC_TO_GHOST, getVerletCrs require the vector to be constructed with BIND_DEC_TO_GHOST option " << std::endl;
1432 ACTION_ON_ERROR(VECTOR_DIST_ERROR_OBJECT);
1440 VerletList_type verletList;
1449 auto & cellList = verletList.getInternalCellList();
1455 for (
size_t i = 0 ; i < dim ; i++)
1456 shift.set_d(i,cellList.getPadding(i));
1479 template <
typename VerletList_type = VerletList<dim,St,VL_NON_SYMMETRIC|VL_ADAPTIVE_RCUT,Mem_fast<>,shift<dim,St>,decltype(vPos)>>
1487 for (
int i = 0; i <
vPos.size(); ++i)
1490 VerletList_type verletList;
1514 template <
unsigned int optVerlet=VL_NON_SYMMETRIC,
typename VerletList_type = VerletList<dim,St,optVerlet,Mem_fast<>,shift<dim,St>,decltype(vPos)>>
1515 VerletList_type
getVerlet(St r_cut,
size_t neighborMaxNum = 0)
1521 VerletList_type verletList;
1524 verletList.setNeighborMaxNum(neighborMaxNum);
1529 if (verletList.getOpt() & VL_SYMMETRIC)
1555 template<
unsigned int opt,
typename Mem_type>
1561 if ((
opt & VL_SYMMETRIC) || (
opt & VL_NON_SYMMETRIC))
1563 auto & cellList = verletList.getInternalCellList();
1567 bool to_reconstruct = cellList.get_ndec() !=
getDecomposition().get_ndec();
1569 if (to_reconstruct ==
false)
1576 VerletList<dim,St,opt,Mem_type,shift<dim,St>> ver_tmp = getVerlet<opt, VerletList<dim,St,opt,Mem_type,shift<dim,St>>>(r_cut);
1577 verletList.
swap(ver_tmp);
1580 else if (
opt & VL_CRS_SYMMETRIC)
1583 if ((this->opt & BIND_DEC_TO_GHOST))
1585 std::cerr << __FILE__ <<
":" << __LINE__ <<
" Error the vector has been constructed without BIND_DEC_TO_GHOST, updateVerlet with the option VL_CRS_SYMMETRIC require the vector to be constructed with BIND_DEC_TO_GHOST option " << std::endl;
1586 ACTION_ON_ERROR(VECTOR_DIST_ERROR_OBJECT);
1590 auto & cellList = verletList.getInternalCellList();
1594 bool to_reconstruct = cellList.get_ndec() !=
getDecomposition().get_ndec();
1596 if (to_reconstruct ==
false)
1602 for (
size_t i = 0 ; i < dim ; i++)
1603 shift.set_d(i,cellList.getPadding(i));
1616 VerletList<dim,St,opt,Mem_type,shift<dim,St>> ver_tmp = getVerletCrs<VerletList<dim,St,opt,Mem_type,shift<dim,St> >>(r_cut);
1617 verletList.
swap(ver_tmp);
1628 template<
unsigned int opt,
typename Mem_type>
1638 for (
int i = 0; i <
vPos.size(); ++i)
1660 template<
typename CellL=CellList<dim,St,Mem_bal<>,shift<dim,St> > >
1680 template<
typename CellL=CellList<dim,St,Mem_bal<>,shift<dim,St> > >
1700 for (
size_t i = 0 ; i < dim ; i++)
1705 cellList.Initialize(pbox,div);
1714 auto key = it.get();
1718 cellList.add(xp,key.getKey());
1729 if (
opt == reorder_opt::HILBERT)
1733 reorder_sfc<CellL,grid_key_dx_iterator_hilbert<dim>>(v_pos_dest,v_prp_dest,h_it,cellList);
1735 else if (
opt == reorder_opt::LINEAR)
1740 reorder_sfc<CellL,grid_key_dx_iterator<dim>>(v_pos_dest,v_prp_dest,h_it,cellList);
1745 vPos.swap(v_pos_dest);
1746 vPrp.swap(v_prp_dest);
1749 vPos.swap(v_pos_dest);
1750 vPrp.swap(v_prp_dest);
1766 template<
typename CellL=CellList<dim,St,Mem_bal<>,shift<dim,St> > >
1773 auto cellList = getCellList<CellL>(r_cut);
1782 for (
size_t i = 0 ; i < dim ; i++)
1783 {div[i] = cellList.getGrid().
size(i) - 2*cellList.getPadding()[i];}
1788 reorder_sfc<CellL,grid_key_dx_iterator<dim>>(vPosReorder,vPrpReorder,h_it,cellList);
1790 vPos.swap(vPosReorder);
1791 vPrp.swap(vPrpReorder);
1874 for (
size_t i = 0; i < dim; i++)
1877 stop.
set_d(i, sz[i] - 1);
1927 for (
size_t i = 0 ; i < dim ; i++)
1958 ite_gpu<1> getDomainIteratorGPU(
size_t n_thr = default_kernel_wg_threads_)
const
1972 ite_gpu<1> getDomainAndGhostIteratorGPU(
size_t n_thr = default_kernel_wg_threads_)
const
1978 return vPos.getGPUIteratorTo(
vPos.size()-1,n_thr);
1987 template<
unsigned int prp>
1988 void debugPrintVector()
1990 this->vPrp.template deviceToHost<prp>();
1998 for (
size_t i = 0 ; i < std::extent<typename boost::mpl::at<typename prop::type,boost::mpl::int_<prp>>::type>::value ; i++)
2000 std::cout <<
vPrp.template get<prp>(p.getKey())[i] <<
" ";
2003 std::cout << std::endl;
2015 template<
unsigned int prp>
2016 void debugPrintScalar()
2018 this->vPrp.template deviceToHost<prp>();
2026 std::cout <<
vPrp.template get<prp>(p.getKey()) <<
" " << std::endl;
2041 auto getDomainIteratorDevice(
size_t n_thr = default_kernel_wg_threads_)
const -> decltype(this->getDomainIteratorGPU(n_thr))
2043 return this->getDomainIteratorGPU(n_thr);
2138 this->
update(this->toKernel());
2158 template<
typename obp = KillParticle>
void map(
size_t opt = NONE)
2170 this->
update(this->toKernel());
2178 int getMapCtr()
const
2210 std::cerr << __FILE__ <<
":" << __LINE__ <<
" Error the processor " <<
v_cl.
getProcessUnitID() <<
" has particles, but is supposed to be unloaded" << std::endl;
2211 ACTION_ON_ERROR(VECTOR_DIST_ERROR_OBJECT);
2216 se3.template ghost_get_pre<prp...>(
opt);
2222 this->
update(this->toKernel());
2229 se3.template ghost_get_post<prp...>(
opt);
2248 std::cerr << __FILE__ <<
":" << __LINE__ <<
" Error the processor " <<
v_cl.
getProcessUnitID() <<
" has particles, but is supposed to be unloaded" << std::endl;
2249 ACTION_ON_ERROR(VECTOR_DIST_ERROR_OBJECT);
2254 se3.template ghost_get_pre<prp...>(
opt);
2274 std::cerr << __FILE__ <<
":" << __LINE__ <<
" Error the processor " <<
v_cl.
getProcessUnitID() <<
" has particles, but is supposed to be unloaded" << std::endl;
2275 ACTION_ON_ERROR(VECTOR_DIST_ERROR_OBJECT);
2282 this->
update(this->toKernel());
2289 se3.template ghost_get_post<prp...>(
opt);
2304 template<
template<
typename,
typename>
class op,
int ... prp>
inline void ghost_put(
size_t opt_ = NONE)
2322 for (
auto it = keys.begin(); it != keys.end(); ++it)
2339 vPos.remove(keys, start);
2340 vPrp.remove(keys, start);
2355 vPos.remove(keys, start);
2356 vPrp.remove(keys, start);
2383 CellDecomposer_sm<dim, St, shift<dim,St>> cdsm;
2389 auto it = vd.getDomainIterator();
2394 size_t v = cdsm.getCell(p);
2396 md.addComputation(
dec,vd,v,it.get().getKey());
2419 for (
size_t i = 0 ; i < dist.getNOwnerSubSubDomains(); i++)
2420 {md.applyModel(
dec,dist.getOwnerSubSubDomain(i));}
2422 dist.setDistTol(md.distributionTol());
2433 for (
size_t i = 0; i < dist.getNOwnerSubSubDomains() ; i++)
2459 inline void save(
const std::string & filename)
const
2471 inline void load(
const std::string & filename)
2498 inline bool write(std::string out ,
int opt = VTK_WRITER)
2513 inline bool write(std::string out, std::string meta_info ,
int opt = VTK_WRITER)
2517 if ((
opt & 0x0FFF0000) == CSV_WRITER)
2521 vector_dist_prop > csv_writer;
2523 std::string output = std::to_string(out +
"_" + std::to_string(
v_cl.
getProcessUnitID()) + std::to_string(
".csv"));
2526 return csv_writer.write(output,
vPos,
vPrp);
2530 file_type ft = file_type::ASCII;
2532 if (
opt & FORMAT_BINARY)
2533 ft = file_type::BINARY;
2536 VTKWriter<boost::mpl::pair<vector_dist_pos,
2538 VECTOR_POINTS> vtk_writer;
2541 std::string output = std::to_string(out +
"_" + std::to_string(
v_cl.
getProcessUnitID()) + std::to_string(
".vtp"));
2550 bool ret=vtk_writer.write(output,
prp_names,
"particles",meta_info,ft);
2582 this->
update(this->toKernel());
2597 this->
update(this->toKernel());
2628 inline bool write_frame(std::string out,
size_t iteration, std::string meta_info,
int opt = VTK_WRITER)
2632 if ((
opt & 0x0FFF0000) == CSV_WRITER)
2636 vector_dist_prop > csv_writer;
2638 std::string output = std::to_string(out +
"_" + std::to_string(
v_cl.
getProcessUnitID()) +
"_" + std::to_string(iteration) + std::to_string(
".csv"));
2641 return csv_writer.write(output,
vPos,
vPrp);
2645 file_type ft = file_type::ASCII;
2647 if (
opt & FORMAT_BINARY)
2648 ft = file_type::BINARY;
2651 VTKWriter<boost::mpl::pair<vector_dist_pos,
2652 vector_dist_prop>, VECTOR_POINTS> vtk_writer;
2655 std::string output = std::to_string(out +
"_" + std::to_string(
v_cl.
getProcessUnitID()) +
"_" + std::to_string(iteration) + std::to_string(
".vtp"));
2666 bool ret=vtk_writer.write(output,
prp_names,
"particles",meta_info,ft);
2683 inline bool write_frame(std::string out,
size_t iteration,
double time,
int opt = VTK_WRITER)
2687 if ((
opt & 0x0FFF0000) == CSV_WRITER)
2692 std::string output = std::to_string(out +
"_" + std::to_string(
v_cl.
getProcessUnitID()) +
"_" + std::to_string(iteration) + std::to_string(
".csv"));
2699 file_type ft = file_type::ASCII;
2701 if (
opt & FORMAT_BINARY)
2702 ft = file_type::BINARY;
2708 std::string output = std::to_string(out +
"_" + std::to_string(
v_cl.
getProcessUnitID()) +
"_" + std::to_string(iteration) + std::to_string(
".vtp"));
2718 bool ret=vtk_writer.write(output,
prp_names,
"particles",
"",ft);
2741 cl_param_calculate(pbox, div,r_cut,enlarge);
2756 check_valid(
this,8);
2758 return create_vcluster<Memory>();;
2820 {sz += accu.get(i);}
2840 if (!(
opt & BIND_DEC_TO_GHOST))
2842 std::cerr << __FILE__ <<
":" << __LINE__ <<
" Error the vector has been constructed without BIND_DEC_TO_GHOST, getParticleIteratorCRS_Cell require the vector to be constructed with BIND_DEC_TO_GHOST option " << std::endl;
2843 ACTION_ON_ERROR(VECTOR_DIST_ERROR_OBJECT);
2851 for (
size_t i = 0 ; i < dim ; i++)
2852 shift.set_d(i,cellList.getPadding(i));
2862 cellList.getNNc_sym()
2897 template<
typename VerletList_type>
2901 if (!(
opt & BIND_DEC_TO_GHOST))
2903 std::cerr << __FILE__ <<
":" << __LINE__ <<
" Error the vector has been constructed without BIND_DEC_TO_GHOST, getParticleIteratorCRS_Cell require the vector to be constructed with BIND_DEC_TO_GHOST option " << std::endl;
2904 ACTION_ON_ERROR(VECTOR_DIST_ERROR_OBJECT);
2922 return cellList.getStartDomainCell();
2937 for (
size_t i = 0 ; i < dim ; i++)
2961 template<
unsigned int ... prp> vector_dist_ker<dim,St,prop,layout_base> toKernel()
2986 vPrp.template deviceToHost<prp ...>();
2997 template<
unsigned int ... prp>
void deviceToHostProp(
size_t start,
size_t stop)
2999 vPrp.template deviceToHost<prp ...>(start,stop);
3009 vPos.template deviceToHost<0>();
3019 vPrp.template hostToDevice<prp ...>();
3029 vPos.template hostToDevice<0>();
3042 template<
unsigned int ...prp,
typename CellList_type>
3043 void restoreOrder(CellList_type & cellList)
3058 bool compareHostAndDevicePos(St tol, St near = -1.0,
bool silent =
false)
3071 template<
unsigned int prp>
3072 bool compareHostAndDeviceProp(St tol, St near = -1.0,
bool silent =
false)
3075 boost::mpl::int_<prp> >::type,prp>::compare(
vPrp,tol,near,silent);
3126 template<
unsigned int dim,
typename St,
typename prop,
typename Decomposition = CartDecomposition<dim,St,CudaMemory,memory_traits_
inte>>
using vector_dist_gpu =
vector_dist<dim,St,prop,Decomposition,CudaMemory,memory_traits_inte>;
3127 template<
unsigned int dim,
typename St,
typename prop,
typename Decomposition = CartDecomposition<dim,St,HeapMemory,memory_traits_
inte>>
using vector_dist_soa =
vector_dist<dim,St,prop,Decomposition,HeapMemory,memory_traits_inte>;
3128 template<
unsigned int dim,
typename St,
typename prop,
typename Decomposition = CartDecomposition<dim,St,CudaMemory,memory_traits_
inte>>
using vector_dist_dev =
vector_dist<dim,St,prop,Decomposition,CudaMemory,memory_traits_inte>;
Header file containing functions for creating files and folders.
static void create_directory_if_not_exist(std::string path, bool silent=0)
Creates a directory if not already existent.
std::string toString() const
Produce a string from the object.
void enlarge(const Box< dim, T > &gh)
Enlarge the box with ghost margin.
bool isValid() const
Check if the Box is a valid box P2 >= P1.
void magnify(T mg)
Magnify the box.
bool write(std::string file, v_pos &v, v_prp &prp, size_t offset=0)
It write a CSV file.
const grid_sm< dim, void > getDistGrid()
Distribution grid.
const Box< dim, T > & getDomain() const
Return the box of the physical domain.
void computeCommunicationAndMigrationCosts(size_t ts)
Calculate communication and migration costs.
void setSubSubDomainComputationCost(size_t id, size_t weight)
Function that set the computational cost for a of a sub-sub domain.
Class for FAST cell list implementation.
void setGhostMarker(size_t ghostMarker)
Set the ghost marker.
void set_ndec(size_t n_dec)
Set the n_dec number.
void fill(vector_pos_type2 &vPos, vector_prp_type &vPrp, size_t ghostMarker)
Fill cell list with particles at positions vPos.
size_t getPadding(size_t i) const
Return the number of padding cells of the Cell decomposer.
void setOpt(size_t opt)
Sets the option flags that control the cell list.
void Initialize(CellDecomposer_sm< dim, T, transform > &cd_sm, const Box< dim, T > &dom_box, const size_t pad=1, size_t slot=STARTING_NSLOT)
This class define the domain decomposition interface.
This class allocate, and destroy CPU memory.
This iterator iterate across the particles of a Cell-list following the Cell structure.
This iterator iterate across the particles of a Cell-list following the Cell structure.
This class implement the point shape in an N-dimensional space.
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.
gpu::ofp_context_t & getGpuContext(bool iw=true)
If nvidia cuda is activated return a gpu context.
size_t getProcessingUnits()
Get the total number of processors.
bool allGather(T &send, openfpm::vector< T, Mem, gr > &v)
Gather the data from all processors.
Implementation of VCluster class.
void barrier()
Just a call to mpi_barrier.
Class for Verlet list implementation.
void swap(VerletList< dim, T, opt, Mem_type, transform, vPos_type, CellListImpl > &vl)
Swap the memory.
Given the decomposition it create an iterator.
__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.
__device__ __host__ const size_t(& getSize() const)[N]
Return the size of the grid as an array.
Implementation of 1-D std::vector like structure.
This class check for inconsistency access.
void map_post()
Operation to do after map.
void Initialize()
Initialize the se_class2 structure.
Grid key for a distributed grid.
This class is an helper for the communication of vector_dist.
void init_decomposition(Box< dim, St > &box, const size_t(&bc)[dim], const Ghost< dim, St > &g, size_t opt, const grid_sm< dim, void > &gdist)
Initialize the decomposition.
void init_decomposition_gr_cell(Box< dim, St > &box, const size_t(&bc)[dim], const Ghost< dim, St > &g, size_t opt, const grid_sm< dim, void > &gdist)
Initialize the decomposition.
void ghost_wait_(openfpm::vector< Point< dim, St >, HeapMemory, memory_traits_lin > &v_pos, openfpm::vector< prop, HeapMemory, memory_traits_lin > &v_prp, size_t &ghostMarker, size_t opt=WITH_POSITION)
It synchronize the properties and position of the ghost particles.
void ghost_get_(openfpm::vector< Point< dim, St >, HeapMemory, memory_traits_lin > &v_pos, openfpm::vector< prop, HeapMemory, memory_traits_lin > &v_prp, size_t &ghostMarker, size_t opt=WITH_POSITION)
It synchronize the properties and position of the ghost particles.
CartDecomposition< dim, St > dec
Domain decomposition.
Decomposition & getDecomposition()
Get the decomposition.
void map_list_(openfpm::vector< Point< dim, St >> &v_pos, openfpm::vector< prop > &v_prp, size_t &ghostMarker, size_t opt)
It move all the particles that does not belong to the local processor to the respective processor.
Vcluster< HeapMemory > & v_cl
VCluster.
void ghost_put_(openfpm::vector< Point< dim, St >, HeapMemory, memory_traits_lin > &v_pos, openfpm::vector< prop, HeapMemory, memory_traits_lin > &v_prp, size_t &ghostMarker, size_t opt)
Ghost put.
void setDecompositionGranularity(size_t n_sub)
Set the minimum number of sub-domain per processor.
Iterator that Iterate across particle indexes.
This class contain a list of all tracked vector_dist_ker around.
void update(const int &v)
Update the addresses of all vector_dist_kernels around.
void remove(size_t key)
Remove one element from the distributed vector.
Vcluster< Memory > & getVC()
Get the Virtual Cluster machine.
auto getPropNC(size_t vec_key) const -> decltype(vPrp.template get< id >(vec_key))
Get the property of an element.
size_t size_local() const
return the local size of the vector
VerletList_type getVerletSym(St r_cut)
for each particle get the symmetric verlet list
auto getDomainIteratorDevice(size_t n_thr=default_kernel_wg_threads_) const -> decltype(this->getDomainIterator())
Get an iterator that traverse the particles in the domain.
void remove(openfpm::vector< size_t > &keys, size_t start=0)
Remove a set of elements from the distributed vector.
auto getPos(size_t vec_key) const -> decltype(vPos.template get< 0 >(vec_key))
Get the position of an element.
vector_dist_prop & getPropVector()
return the property vector of all the particles
bool write_frame(std::string out, size_t iteration, int opt=VTK_WRITER)
Output particle position and properties.
void getCellListParams(St r_cut, size_t(&div)[dim], Box< dim, St > &box, Ghost< dim, St > enlarge=Ghost< dim, St >(0.0))
Get the Celllist parameters.
void resize(size_t rs)
Resize the vector (locally)
auto getProp(vect_dist_key_dx vec_key) -> decltype(vPrp.template get< id >(vec_key.getKey()))
Get the property of an element.
auto getPos(vect_dist_key_dx vec_key) const -> decltype(vPos.template get< 0 >(vec_key.getKey()))
Get the position of an element.
static const unsigned int dims
template parameters typedefs
void updateCellList(CellL &cellList, bool no_se3=false)
Update a cell list using the stored particles.
void Ighost_get(size_t opt=WITH_POSITION)
It synchronize the properties and position of the ghost particles.
size_t init_size_accum(size_t np)
It return the number of particles contained by the previous processors.
void check_parameters(Box< dim, St > &box)
Check if the parameters describe a valid vector. In case it does not report an error.
void appendLocal()
Add at the END of local and ghost particle.
bool isSubset() const
Indicate that this class is not a subset.
size_t size_local_with_ghost() const
return the local size of the vector
void deviceToHostPos()
Move the memory from the device to host memory.
vector_dist_pos & getPosVector()
return the position vector of all the particles
void init_structures(size_t np)
Initialize the structures.
void check_ghost_compatible_rcut(St r_cut)
It check that the r_cut is not bugger than the ghost.
vector_dist_iterator getDomainIterator_no_se3() const
Get an iterator that traverse the particles in the domain.
auto getPosNC(vect_dist_key_dx vec_key) -> decltype(vPos.template get< 0 >(vec_key.getKey()))
Get the position of an element.
grid_key_dx< dim > getCRSStart(Celllist &cellList)
Return from which cell we have to start in case of CRS interation scheme.
auto getPropNC(vect_dist_key_dx vec_key) -> decltype(vPrp.template get< id >(vec_key.getKey()))
Get the property of an element.
const vector_dist_prop & getPropVector() const
return the property vector of all the particles
int yes_i_am_vector_dist
yes I am vector dist
void setCapacity(unsigned int ns)
Reserve space for the internal vectors.
CellList_type getCellListSym(St r_cut, size_t opt=CL_LINEAR_CELL_KEYS)
Construct a cell list symmetric based on a cut-off radius.
vector_dist_iterator getDomainAndGhostIterator_no_se3() const
Get an iterator that traverse the particles in the domain.
void updateVerletAdaptRCut(VerletList< dim, St, opt, Mem_type, shift< dim, St > > &verletList)
Update non-symmetric adaptive r-cut Verlet list.
Decomposition & getDecomposition()
Get the decomposition.
void setPropNames(const openfpm::vector< std::string > &names)
Set the properties names.
auto getLastPosWrite() -> decltype(vPos.template get< 0 >(0))
Get the position of the last element.
vector_dist_iterator getGhostIterator() const
Get the iterator across the position of the ghost particles.
VerletList_type getVerlet(St r_cut, size_t neighborMaxNum=0)
for each particle get the verlet list
auto getProp(vect_dist_key_dx vec_key) const -> decltype(vPrp.template get< id >(vec_key.getKey()))
Get the property of an element.
grid_dist_id_iterator_dec< Decomposition > getGridIterator(const size_t(&sz)[dim])
vector_dist_pos vPosReordered
const Decomposition & getDecomposition() const
Get the decomposition.
openfpm::vector_key_iterator_seq< typename VerletList_type::Mem_type_type::local_index_type > getParticleIteratorCRS(VerletList_type &cellList)
Get a special particle iterator able to iterate across particles using symmetric crossing scheme.
bool write_frame(std::string out, size_t iteration, double time, int opt=VTK_WRITER)
Output particle position and properties and add a time stamp to pvtp.
auto getPos(vect_dist_key_dx vec_key) -> decltype(vPos.template get< 0 >(vec_key.getKey()))
Get the position of an element.
auto getPosRead(vect_dist_key_dx vec_key) const -> decltype(vPos.template get< 0 >(vec_key.getKey()))
Get the position of an element.
void map_list(size_t opt=NONE)
It move all the particles that does not belong to the local processor to the respective processor.
CellL getCellListSym(const size_t(&div)[dim], const size_t(&pad)[dim], size_t opt=CL_LINEAR_CELL_KEYS)
Construct a symmetric cell list based on a number of divisions and padding.
size_t opt
option used to create this vector
std::integral_constant< bool, false > is_it_a_subset
yes I am vector subset dist
auto getPropNC(vect_dist_key_dx vec_key) const -> decltype(vPrp.template get< id >(vec_key.getKey()))
Get the property of an element.
size_t ghostMarker
Ghost marker, all the particle with id > ghostMarker are ghost all with ghostMarker < are real partic...
auto getLastPropWrite() -> decltype(vPrp.template get< id >(0))
Get the property of the last element.
void remove(std::set< size_t > &keys)
Remove a set of elements from the distributed vector.
const vector_dist_pos & getPosVector() const
return the position vector of all the particles
void updateVerlet(VerletList< dim, St, opt, Mem_type, shift< dim, St > > &verletList, St r_cut)
for each particle get the verlet list
void reorder(int32_t m, const Ghost< dim, St > &enlarge, reorder_opt opt=reorder_opt::HILBERT)
Construct a cell list starting from the stored particles and reorder a vector according to the Hilber...
openfpm::vector< std::string > prp_names
Name of the properties.
void ghost_wait(size_t opt=WITH_POSITION)
It synchronize the properties and position of the ghost particles.
vector_dist_iterator getDomainIterator() const
Get an iterator that traverse the particles in the domain.
vector_dist(const Decomposition &dec, size_t np)
Constructor with predefined decomposition.
bool write(std::string out, std::string meta_info, int opt=VTK_WRITER)
Output particle position and properties.
void ghost_get(size_t opt=WITH_POSITION)
It synchronize the properties and position of the ghost particles.
auto getProp(size_t vec_key) const -> decltype(vPrp.template get< id >(vec_key))
Get the property of an element.
VerletList_type getVerletAdaptRCut()
Get Verlet list with unique cut-off radius for every particle.
void setReferenceCounterToOne()
vector_dist_iterator getIterator(size_t start, size_t stop)
Get an iterator that traverse domain and ghost particles.
void finalizeComputationCosts(Model md=Model(), size_t ts=1)
Add the computation cost on the decomposition coming from the particles.
void hostToDevicePos()
Move the memory from the device to host memory.
grid_key_dx< dim > getCRSStop(Celllist &cellList)
Return from which cell we have to stop in case of CRS interation scheme.
auto getPos(size_t vec_key) -> decltype(vPos.template get< 0 >(vec_key))
Get the position of an element.
void map(size_t opt=NONE)
It move all the particles that does not belong to the local processor to the respective processor.
void ghost_put(size_t opt_=NONE)
It synchronize the properties and position of the ghost particles.
auto getLastPropRead() -> decltype(vPrp.template get< id >(0))
Get the property of the last element.
vector_dist_iterator getIterator()
Get an iterator that traverse domain and ghost particles.
size_t accum()
It return the sum of the particles in the previous processors.
void reorder_sfc(openfpm::vector< Point< dim, St >> &v_pos_dest, openfpm::vector< prop > &v_prp_dest, sfc_it &h_it, CellL &cellList)
Reorder based on hilbert space filling curve.
CellL getCellList_hilb(St r_cut, size_t opt=CL_NON_SYMMETRIC)
Construct an hilbert cell list starting from the stored particles.
vector_dist< dim, St, prop, Decomposition, Memory, layout_base > & operator=(vector_dist< dim, St, prop, Decomposition, Memory, layout_base > &&v)
Operator= for distributed vector.
void initializeComputationCosts()
Initialize the computational cost.
auto getPropRead(vect_dist_key_dx vec_key) const -> decltype(vPrp.template get< id >(vec_key.getKey()))
Get the property of an element.
bool write_frame(std::string out, size_t iteration, std::string meta_info, int opt=VTK_WRITER)
Output particle position and properties.
void clear()
remove all the elements
openfpm::vector< std::string > & getPropNames()
Get the properties names.
ParticleIt_Cells< dim, CellList > getDomainIteratorCells(CellList &cellList)
Get an iterator that traverse the particles in the domain using a cell list.
bool write(std::string out, int opt=VTK_WRITER)
Output particle position and properties.
void reorder_rcut(St r_cut)
Construct a cell list starting from the stored particles and reorder a vector according to the Hilber...
auto getLastPosRead() -> decltype(vPos.template get< 0 >(0))
Get the position of the last element.
vector_dist< dim, St, prop, Decomposition, Memory, layout_base > & operator=(const vector_dist< dim, St, prop, Decomposition, Memory, layout_base > &v)
Operator= for distributed vector.
void reorder(int32_t m, reorder_opt opt=reorder_opt::HILBERT)
Construct a cell list starting from the stored particles and reorder a vector according to the Hilber...
auto getLastProp() -> decltype(vPrp.template get< id >(0))
Get the property of the last element.
void deviceToHostProp()
Move the memory from the device to host memory.
vector_dist_iterator getDomainAndGhostIterator() const
Get an iterator that traverse the particles in the domain.
void save(const std::string &filename) const
Save the distributed vector on HDF5 file.
vector_dist_iterator getGhostIterator_no_se3() const
Get the iterator across the position of the ghost particles.
auto getPosNC(size_t vec_key) -> decltype(vPos.template get< 0 >(vec_key))
Get the position of an element.
auto getLastPosEnd() -> decltype(vPos.template get< 0 >(0))
Get the position of the last element after ghost.
vector_dist_prop vPrpReordered
void remove(openfpm::vector< aggregate< int >> &keys, size_t start=0)
Remove a set of elements from the distributed vector.
vector_dist(const vector_dist< dim, St, prop, Decomposition, Memory, layout_base > &v)
Copy Constructor.
void add()
Add local particle.
CellList_type getCellList(St r_cut, size_t opt=CL_NON_SYMMETRIC|CL_LINEAR_CELL_KEYS, bool no_se3=false, float ghostEnlargeFactor=1.013)
Construct a cell list starting from the stored particles.
VerletList_type getVerletCrs(St r_cut)
for each particle get the symmetric verlet list
ParticleItCRS_Cells< dim, cli, decltype(vPos)> getParticleIteratorCRS_Cell(cli &cellList)
Get a special particle iterator able to iterate across particles using symmetric crossing scheme.
void hostToDeviceProp()
Move the memory from the device to host memory.
CellList_type getCellListSymLocal(St r_cut, size_t opt=CL_LINEAR_CELL_KEYS)
Construct a local symmetric cell list based on a cut-off radius.
void addComputationCosts(Model md=Model(), size_t ts=1)
Add the computation cost on the decomposition coming from the particles.
void load(const std::string &filename)
Load the distributed vector from an HDF5 file.
auto getPropNC(size_t vec_key) -> decltype(vPrp.template get< id >(vec_key))
Get the property of an element.
auto getPosWrite(vect_dist_key_dx vec_key) -> decltype(vPos.template get< 0 >(vec_key.getKey()))
Get the position of an element.
vector_dist(size_t np, Box< dim, St > box, const size_t(&bc)[dim], const Ghost< dim, St > &g, const grid_sm< dim, void > &gdist)
Constructor of a distributed vector.
void addComputationCosts(const self &vd, Model md=Model())
Add the computation cost on the decomposition coming from the particles.
auto getProp(size_t vec_key) -> decltype(vPrp.template get< id >(vec_key))
Get the property of an element.
vector_dist(vector_dist< dim, St, prop, Decomposition, Memory, layout_base > &&v) noexcept
Copy constructor.
auto getPropWrite(vect_dist_key_dx vec_key) -> decltype(vPrp.template get< id >(vec_key.getKey()))
Get the property of an element.
vector_dist(size_t np, Box< dim, St > box, const size_t(&bc)[dim], const Ghost< dim, St > &g, size_t opt=0, const grid_sm< dim, void > &gdist=grid_sm< dim, void >())
Constructor of a distributed vector.
void ghost_get_subset()
Stub does not do anything.
void deleteGhost()
Delete the particles on the ghost.
auto getPosNC(vect_dist_key_dx vec_key) const -> decltype(vPos.template get< 0 >(vec_key.getKey()))
Get the position of an element.
void discardLocalAppend(size_t rs)
Resize the vector at the end of the ghost (locally)
auto getPosNC(size_t vec_key) const -> decltype(vPos.template get< 0 >(vec_key))
Get the position of an element.
auto getLastPos() -> decltype(vPos.template get< 0 >(0))
Get the position of the last element.
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
boost::fusion::vector< list... > type
internal type containing the data
decrement_memory(vector_type &v)
constructor
void operator()(T &t) const
It call the copy function for each property.
Transform the boost::fusion::vector into memory specification (memory_traits)