vector_dist.hpp 80.1 KB
Newer Older
incardon's avatar
incardon committed
1 2 3 4 5 6 7 8 9 10
/*
 * Vector.hpp
 *
 *  Created on: Mar 5, 2015
 *      Author: Pietro Incardona
 */

#ifndef VECTOR_HPP_
#define VECTOR_HPP_

incardon's avatar
incardon committed
11
#include "config.h"
incardon's avatar
incardon committed
12
#include "HDF5_wr/HDF5_wr.hpp"
incardon's avatar
incardon committed
13
#include "VCluster/VCluster.hpp"
incardon's avatar
incardon committed
14
#include "Space/Shape/Point.hpp"
incardon's avatar
incardon committed
15
#include "Vector/Iterators/vector_dist_iterator.hpp"
incardon's avatar
incardon committed
16 17
#include "Space/Shape/Box.hpp"
#include "Vector/vector_dist_key.hpp"
incardon's avatar
incardon committed
18
#include "memory/PtrMemory.hpp"
incardon's avatar
incardon committed
19
#include "NN/CellList/CellList.hpp"
incardon's avatar
incardon committed
20
#include "NN/CellList/CellListFast_gen.hpp"
21
#include "util/common.hpp"
incardon's avatar
incardon committed
22
#include "util/object_util.hpp"
incardon's avatar
incardon committed
23
#include "memory/ExtPreAlloc.hpp"
24
#include "CSVWriter/CSVWriter.hpp"
Pietro Incardona's avatar
Pietro Incardona committed
25
#include "VTKWriter/VTKWriter.hpp"
26
#include "Decomposition/common.hpp"
incardon's avatar
incardon committed
27
#include "Grid/Iterators/grid_dist_id_iterator_dec.hpp"
Yaroslav's avatar
Yaroslav committed
28
#include "Grid/grid_key_dx_iterator_hilbert.hpp"
Pietro Incardona's avatar
Pietro Incardona committed
29
#include "Vector/vector_dist_ofb.hpp"
30
#include "Decomposition/CartDecomposition.hpp"
31
#include "data_type/aggregate.hpp"
32
#include "NN/VerletList/VerletList.hpp"
Pietro Incardona's avatar
Pietro Incardona committed
33
#include "vector_dist_comm.hpp"
incardon's avatar
incardon committed
34
#include "DLB/LB_Model.hpp"
incardon's avatar
incardon committed
35
#include "Vector/vector_map_iterator.hpp"
incardon's avatar
incardon committed
36 37
#include "NN/CellList/ParticleIt_Cells.hpp"
#include "NN/CellList/ProcKeys.hpp"
incardon's avatar
incardon committed
38 39
#include "Vector/vector_dist_kernel.hpp"
#include "NN/CellList/cuda/CellList_gpu.hpp"
40 41
#include "lib/pdata.hpp"
#include "cuda/vector_dist_operators_list_ker.hpp"
incardon's avatar
incardon committed
42

incardon's avatar
incardon committed
43 44
#define DEC_GRAN(gr) ((size_t)gr << 32)

incardon's avatar
incardon committed
45
#ifdef CUDA_GPU
incardon's avatar
incardon committed
46
template<unsigned int dim,typename St> using CELLLIST_GPU_SPARSE = CellList_gpu<dim,St,CudaMemory,shift_only<dim, St>,unsigned int,int,true>;
incardon's avatar
incardon committed
47
#endif
incardon's avatar
incardon committed
48

incardon's avatar
incardon committed
49 50 51 52 53 54 55 56 57 58 59 60 61
#define VECTOR_DIST_ERROR_OBJECT std::runtime_error("Runtime vector distributed error");

#ifdef SE_CLASS3
#include "se_class3_vector.hpp"
#endif

#ifdef SE_CLASS3
	#define SE_CLASS3_VDIST_CONSTRUCTOR ,se3(getDecomposition(),*this)
#else
	#define SE_CLASS3_VDIST_CONSTRUCTOR
#endif


incardon's avatar
incardon committed
62 63 64
#define NO_ID false
#define ID true

incardon's avatar
incardon committed
65
// Perform a ghost get or a ghost put
incardon's avatar
incardon committed
66 67
constexpr int GET = 1;
constexpr int PUT = 2;
incardon's avatar
incardon committed
68

incardon's avatar
incardon committed
69
// Write the particles with ghost
incardon's avatar
incardon committed
70 71
constexpr int NO_GHOST = 0;
constexpr int WITH_GHOST = 2;
incardon's avatar
incardon committed
72

incardon's avatar
incardon committed
73 74 75
constexpr int GCL_NON_SYMMETRIC = 0;
constexpr int GCL_SYMMETRIC = 1;
constexpr int GCL_HILBERT = 2;
incardon's avatar
incardon committed
76

incardon's avatar
incardon committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
template<bool is_gpu_celllist>
struct gcl_standard_no_symmetric_impl
{
	template<unsigned int dim, typename St, typename CellL, typename Vector, unsigned int impl>
	static inline CellL get(Vector & vd, const St & r_cut, const Ghost<dim,St> & g)
	{
		return vd.template getCellList<CellL>(r_cut);
	}
};

template<>
struct gcl_standard_no_symmetric_impl<true>
{
	template<unsigned int dim, typename St, typename CellL, typename Vector, unsigned int impl>
	static inline CellL get(Vector & vd, const St & r_cut, const Ghost<dim,St> & g)
	{
incardon's avatar
incardon committed
93
		return vd.template getCellListGPU<CellL>(r_cut);
incardon's avatar
incardon committed
94 95
	}
};
incardon's avatar
incardon committed
96

incardon's avatar
incardon committed
97
//! General function t get a cell-list
incardon's avatar
incardon committed
98
template<unsigned int dim, typename St, typename CellL, typename Vector, unsigned int impl>
incardon's avatar
incardon committed
99 100 101 102 103 104 105 106 107 108 109 110 111
struct gcl
{
	/*! \brief Get the Cell list based on the type
	 *
	 * \param vd Distributed vector
	 * \param r_cut Cut-off radius
	 * \param g Ghost
	 *
	 * \return the constructed cell-list
	 *
	 */
	static inline CellL get(Vector & vd, const St & r_cut, const Ghost<dim,St> & g)
	{
incardon's avatar
incardon committed
112
		return gcl_standard_no_symmetric_impl<is_gpu_celllist<CellL>::value>::template get<dim,St,CellL,Vector,impl>(vd,r_cut,g);
incardon's avatar
incardon committed
113 114 115 116
	}
};

//! General function t get a cell-list
incardon's avatar
incardon committed
117 118
template<unsigned int dim, typename St, typename CellL, typename Vector>
struct gcl<dim,St,CellL,Vector,GCL_HILBERT>
incardon's avatar
incardon committed
119 120 121 122 123 124 125 126 127 128
{
	/*! \brief Get the Cell list based on the type
	 *
	 * \param vd Distributed vector
	 * \param r_cut Cut-off radius
	 * \param g Ghost
	 *
	 * \return the constructed cell-list
	 *
	 */
incardon's avatar
incardon committed
129
	static inline CellL get(Vector & vd, const St & r_cut, const Ghost<dim,St> & g)
incardon's avatar
incardon committed
130 131 132 133 134
	{
		return vd.getCellList_hilb(r_cut,g);
	}
};

incardon's avatar
incardon committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
//! General function t get a cell-list
template<unsigned int dim, typename St, typename CellL, typename Vector>
struct gcl<dim,St,CellL,Vector,GCL_SYMMETRIC>
{
	/*! \brief Get the Cell list based on the type
	 *
	 * \param vd Distributed vector
	 * \param r_cut Cut-off radius
	 * \param g Ghost
	 *
	 * \return the constructed cell-list
	 *
	 */
	static inline CellL get(Vector & vd, const St & r_cut, const Ghost<dim,St> & g)
	{
		return vd.getCellListSym(r_cut);
	}
};

incardon's avatar
incardon committed
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
/////////////////// GCL anisotropic ///////////////////////////////////////////

//! General function t get a cell-list
template<unsigned int dim, typename St, typename CellL, typename Vector, unsigned int impl>
struct gcl_An
{
	/*! \brief Get the Cell list based on the type
	 *
	 * \param vd Distributed vector
	 * \param r_cut Cut-off radius
	 * \param g Ghost
	 *
	 * \return the constructed cell-list
	 *
	 */
	static inline CellL get(Vector & vd, const size_t (& div)[dim], const size_t (& pad)[dim], const Ghost<dim,St> & g)
	{
		return vd.template getCellListSym<CellL>(div,pad);
	}
};

incardon's avatar
incardon committed
175
#define CELL_MEMFAST(dim,St) CellList_gen<dim, St, Process_keys_lin, Mem_fast<>, shift<dim, St> >
incardon's avatar
incardon committed
176 177
#define CELL_MEMBAL(dim,St) CellList_gen<dim, St, Process_keys_lin, Mem_bal<>, shift<dim, St> >
#define CELL_MEMMW(dim,St) CellList_gen<dim, St, Process_keys_lin, Mem_mw<>, shift<dim, St> >
incardon's avatar
incardon committed
178

incardon's avatar
incardon committed
179
#define CELL_MEMFAST_HILB(dim,St) CellList_gen<dim, St, Process_keys_hilb, Mem_fast<>, shift<dim, St> >
incardon's avatar
incardon committed
180 181
#define CELL_MEMBAL_HILB(dim,St) CellList_gen<dim, St, Process_keys_hilb, Mem_bal<>, shift<dim, St> >
#define CELL_MEMMW_HILB(dim,St) CellList_gen<dim, St, Process_keys_hilb, Mem_mw<>, shift<dim, St> >
incardon's avatar
incardon committed
182

incardon's avatar
incardon committed
183 184 185 186
#define VERLET_MEMFAST(dim,St) VerletList<dim,St,Mem_fast<>,shift<dim,St> >
#define VERLET_MEMBAL(dim,St)  VerletList<dim,St,Mem_bal<>,shift<dim,St> >
#define VERLET_MEMMW(dim,St)   VerletList<dim,St,Mem_mw<>,shift<dim,St> >

incardon's avatar
incardon committed
187
#define VERLET_MEMFAST_INT(dim,St) VerletList<dim,St,Mem_fast<HeapMemory,unsigned int>,shift<dim,St> >
incardon's avatar
incardon committed
188 189 190 191 192 193 194 195 196
#define VERLET_MEMBAL_INT(dim,St)  VerletList<dim,St,Mem_bal<unsigned int>,shift<dim,St> >
#define VERLET_MEMMW_INT(dim,St)   VerletList<dim,St,Mem_mw<unsigned int>,shift<dim,St> >

enum reorder_opt
{
	NO_REORDER = 0,
	HILBERT = 1,
	LINEAR = 2
};
incardon's avatar
incardon committed
197

198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
template<typename vector, unsigned int impl>
struct cell_list_selector
{
	typedef decltype(std::declval<vector>().getCellListGPU(0.0).toKernel()) ctype;

	static ctype get(vector & v,
			typename vector::stype & r_cut)
	{
		return v.getCellListGPU(r_cut).toKernel();
	}
};

template<typename vector>
struct cell_list_selector<vector,comp_host>
{
	typedef decltype(std::declval<vector>().getCellList(0.0)) ctype;

	static ctype get(vector & v,
			typename vector::stype & r_cut)
	{
		return v.getCellList(r_cut);
	}
};

incardon's avatar
incardon committed
222
/*! \brief Distributed vector
223
 *
incardon's avatar
incardon committed
224
 * This class represent a distributed vector, the distribution of the structure
225 226 227
 * is based on the positional information of the elements the vector store
 *
 * ## Create a vector of random elements on each processor 2D
incardon's avatar
incardon committed
228
 * \snippet Vector/tests/vector_dist_unit_test.cpp Create a vector of random elements on each processor 2D
229 230
 *
 * ## Create a vector of random elements on each processor 3D
incardon's avatar
incardon committed
231
 * \snippet Vector/tests/vector_dist_unit_test.cpp Create a vector of random elements on each processor 3D
232 233
 *
 * ## Create a vector of elements distributed on a grid like way
incardon's avatar
incardon committed
234
 * \snippet Vector/tests/vector_dist_unit_test.cpp Create a vector of elements distributed on a grid like way
235 236
 *
 * ## Redistribute the particles and sync the ghost properties
incardon's avatar
incardon committed
237 238 239 240 241 242 243 244 245 246
 * \snippet Vector/tests/vector_dist_unit_test.cpp Redistribute the particles and sync the ghost properties
 *
 * ## Create a gpu distributed vector [St = float or double]
 * \snippet Vector/cuda/vector_dist_gpu_unit_tests.cu Create a gpu vector
 *
 * ## Fill a GPU vector_dist on CPU and move the information to GPU and redistribute [St = float or double]
 * \snippet Vector/cuda/vector_dist_gpu_unit_tests.cu Fill gpu vector and move to GPU
 *
 * ## Fill the ghost on GPU
 * \snippet Vector/cuda/vector_dist_gpu_unit_tests.cu Fill the ghost on GPU
247 248 249 250 251 252
 *
 * \tparam dim Dimensionality of the space where the elements lives
 * \tparam St type of space float, double ...
 * \tparam prop properties the vector element store in OpenFPM data structure format
 * \tparam Decomposition Decomposition strategy to use CartDecomposition ...
 * \tparam Memory Memory pool where store the information HeapMemory ...
incardon's avatar
incardon committed
253
 * \tparam Memory layout
incardon's avatar
incardon committed
254 255
 *
 */
incardon's avatar
incardon committed
256 257 258 259 260 261
template<unsigned int dim,
         typename St,
         typename prop,
         typename Decomposition = CartDecomposition<dim,St>,
         typename Memory = HeapMemory,
         template<typename> class layout_base = memory_traits_lin>
262 263
class vector_dist : public vector_dist_comm<dim,St,prop,Decomposition,Memory,layout_base>,
					private vector_dist_ker_list<vector_dist_ker<dim,St,prop,layout_base>>
incardon's avatar
incardon committed
264
{
incardon's avatar
incardon committed
265

incardon's avatar
incardon committed
266 267 268
public:

	//! Self type
incardon's avatar
incardon committed
269
	typedef vector_dist<dim,St,prop,Decomposition,Memory,layout_base> self;
incardon's avatar
incardon committed
270

incardon's avatar
incardon committed
271 272
private:

273
	//! Ghost marker, all the particle with id > g_m are ghost all with g_m < are real particle
274 275
	size_t g_m = 0;

276 277
	//! Particle position vector, (It has 2 elements) the first has real particles assigned to a processor
	//! the second element contain unassigned particles
incardon's avatar
incardon committed
278
	openfpm::vector<Point<dim, St>,Memory,typename layout_base<Point<dim,St>>::type,layout_base> v_pos;
incardon's avatar
incardon committed
279

280 281
	//! Particle properties vector, (It has 2 elements) the first has real particles assigned to a processor
	//! the second element contain unassigned particles
incardon's avatar
incardon committed
282
	openfpm::vector<prop,Memory,typename layout_base<prop>::type,layout_base> v_prp;
incardon's avatar
incardon committed
283

incardon's avatar
incardon committed
284
	//! reordered v_pos buffer
incardon's avatar
incardon committed
285 286
	openfpm::vector<prop,Memory,typename layout_base<prop>::type,layout_base> v_prp_out;

incardon's avatar
incardon committed
287
	//! reordered v_prp buffer
incardon's avatar
incardon committed
288 289 290
	openfpm::vector<Point<dim, St>,Memory,typename layout_base<Point<dim,St>>::type,layout_base> v_pos_out;


291
	//! Virtual cluster
292
	Vcluster<Memory> & v_cl;
incardon's avatar
incardon committed
293

incardon's avatar
incardon committed
294 295 296
	//! option used to create this vector
	size_t opt = 0;

297 298 299
	//! Name of the properties
	openfpm::vector<std::string> prp_names;

incardon's avatar
incardon committed
300 301 302 303 304
#ifdef SE_CLASS3

	se_class3_vector<prop::max_prop,dim,St,Decomposition,self> se3;

#endif
305

Pietro Incardona's avatar
Pietro Incardona committed
306
	/*! \brief Initialize the structures
incardon's avatar
incardon committed
307
	 *
Pietro Incardona's avatar
Pietro Incardona committed
308
	 * \param np number of particles
incardon's avatar
incardon committed
309 310
	 *
	 */
Pietro Incardona's avatar
Pietro Incardona committed
311
	void init_structures(size_t np)
incardon's avatar
incardon committed
312
	{
313
		// convert to a local number of elements
314 315 316 317 318 319 320 321
		size_t p_np = np / v_cl.getProcessingUnits();

		// Get non divisible part
		size_t r = np % v_cl.getProcessingUnits();

		// Distribute the remain particles
		if (v_cl.getProcessUnitID() < r)
			p_np++;
322

incardon's avatar
incardon committed
323
		// resize the position vector
324
		v_pos.resize(p_np);
incardon's avatar
incardon committed
325 326

		// resize the properties vector
327 328 329
		v_prp.resize(p_np);

		g_m = p_np;
Pietro Incardona's avatar
Pietro Incardona committed
330
	}
incardon's avatar
incardon committed
331

incardon's avatar
incardon committed
332
	/*! \brief Check if the parameters describe a valid vector. In case it does not report an error
incardon's avatar
incardon committed
333 334 335 336 337 338 339 340
	 *
	 * \param box Box to check
	 *
	 */
	void check_parameters(Box<dim,St> & box)
	{
		// if the box is not valid return an error
		if (box.isValid() == false)
incardon's avatar
incardon committed
341
		{
incardon's avatar
incardon committed
342
			std::cerr << __FILE__ << ":" << __LINE__ << "  Error the domain is not valid " << box.toString() << std::endl;
incardon's avatar
incardon committed
343 344
			ACTION_ON_ERROR(VECTOR_DIST_ERROR_OBJECT);
		}
incardon's avatar
incardon committed
345 346 347

	}

incardon's avatar
incardon committed
348 349 350 351 352
	/*! \brief It check that the r_cut is not bugger than the ghost
	 *
	 * \param r_cut cut-off radius
	 *
	 */
incardon's avatar
incardon committed
353
	void check_ghost_compatible_rcut(St r_cut)
incardon's avatar
incardon committed
354 355 356
	{
		for (size_t i = 0 ; i < dim ; i++)
		{
incardon's avatar
incardon committed
357 358 359 360 361
			if (fabs(getDecomposition().getGhost().getLow(i)) < r_cut)
			{
				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;
				ACTION_ON_ERROR(VECTOR_DIST_ERROR_OBJECT);
			}
incardon's avatar
incardon committed
362 363 364
		}
	}

incardon's avatar
incardon committed
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
	/*! \brief Reorder based on hilbert space filling curve
	 *
	 * \param v_pos_dest reordered vector of position
	 * \param v_prp_dest reordered vector of properties
	 * \param m order of the space filling curve
	 * \param cell_list cell-list
	 *
	 */
	template<typename CellL, typename sfc_it>
	void reorder_sfc(openfpm::vector<Point<dim,St>> & v_pos_dest,
						 openfpm::vector<prop> & v_prp_dest,
						 sfc_it & h_it,
						 CellL & cell_list)
	{
		v_pos_dest.resize(v_pos.size());
		v_prp_dest.resize(v_prp.size());

		//Index for v_pos_dest
		size_t count = 0;

		grid_key_dx<dim> ksum;

		for (size_t i = 0; i < dim ; i++)
		{ksum.set_d(i,cell_list.getPadding(i));}

		while (h_it.isNext())
		{
		  auto key = h_it.get();
		  key += ksum;

		  size_t lin = cell_list.getGrid().LinId(key);

		  // for each particle in the Cell "lin"
		  for (size_t i = 0; i < cell_list.getNelements(lin); i++)
		  {
			  //reorder
			  auto v = cell_list.get(lin,i);
			  v_pos_dest.get(count) = v_pos.get(v);
			  v_prp_dest.get(count) = v_prp.get(v);

			  count++;
		  }
		  ++h_it;
		}
	}
incardon's avatar
incardon committed
410

Pietro Incardona's avatar
Pietro Incardona committed
411 412
public:

incardon's avatar
incardon committed
413 414 415 416 417 418 419 420 421
	//! property object
	typedef prop value_type;

	typedef Decomposition Decomposition_type;

	typedef decltype(v_pos) internal_position_vector_type;

	typedef CellList<dim, St, Mem_fast<>, shift<dim, St>, internal_position_vector_type > CellList_type;

Pietro Incardona's avatar
Pietro Incardona committed
422 423 424 425 426 427
	//! space type
	typedef St stype;

	//! dimensions of space
	static const unsigned int dims = dim;

incardon's avatar
incardon committed
428 429 430
	//!
	typedef int yes_i_am_vector_dist;

Pietro Incardona's avatar
Pietro Incardona committed
431 432 433 434
	/*! \brief Operator= for distributed vector
	 *
	 * \param v vector to copy
	 *
Pietro Incardona's avatar
Pietro Incardona committed
435 436
	 * \return itself
	 *
Pietro Incardona's avatar
Pietro Incardona committed
437
	 */
incardon's avatar
incardon committed
438 439
	vector_dist<dim,St,prop,Decomposition,Memory,layout_base> &
	operator=(const vector_dist<dim,St,prop,Decomposition,Memory,layout_base> & v)
Pietro Incardona's avatar
Pietro Incardona committed
440
	{
incardon's avatar
incardon committed
441
		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));
Pietro Incardona's avatar
Pietro Incardona committed
442 443 444 445 446

		g_m = v.g_m;
		v_pos = v.v_pos;
		v_prp = v.v_prp;

incardon's avatar
incardon committed
447 448 449 450 451 452
#ifdef SE_CLASS3
		se3 = v.se3;
#endif

		opt = v.opt;

Pietro Incardona's avatar
Pietro Incardona committed
453 454 455 456 457 458 459
		return *this;
	}

	/*! \brief Operator= for distributed vector
	 *
	 * \param v vector to copy
	 *
Pietro Incardona's avatar
Pietro Incardona committed
460 461
	 * \return itself
	 *
Pietro Incardona's avatar
Pietro Incardona committed
462
	 */
incardon's avatar
incardon committed
463 464
	vector_dist<dim,St,prop,Decomposition,Memory,layout_base> &
	operator=(vector_dist<dim,St,prop,Decomposition,Memory,layout_base> && v)
Pietro Incardona's avatar
Pietro Incardona committed
465
	{
incardon's avatar
incardon committed
466
		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));
Pietro Incardona's avatar
Pietro Incardona committed
467 468 469 470 471

		g_m = v.g_m;
		v_pos.swap(v.v_pos);
		v_prp.swap(v.v_prp);

incardon's avatar
incardon committed
472 473 474 475 476 477
#ifdef SE_CLASS3
		se3 = v.se3;
#endif

		opt = v.opt;

Pietro Incardona's avatar
Pietro Incardona committed
478 479 480
		return *this;
	}

incardon's avatar
incardon committed
481 482 483 484 485
	// default constructor (structure contain garbage)
	vector_dist()
	:v_cl(create_vcluster<Memory>()),opt(opt)
	{}

incardon's avatar
incardon committed
486

Pietro Incardona's avatar
Pietro Incardona committed
487
	/*! \brief Copy Constructor
Pietro Incardona's avatar
Pietro Incardona committed
488
	 *
Pietro Incardona's avatar
Pietro Incardona committed
489
	 * \param v vector to copy
Pietro Incardona's avatar
Pietro Incardona committed
490 491
	 *
	 */
incardon's avatar
incardon committed
492 493
	vector_dist(const vector_dist<dim,St,prop,Decomposition,Memory,layout_base> & v)
	:vector_dist_comm<dim,St,prop,Decomposition,Memory,layout_base>(v.getDecomposition()),v_cl(v.v_cl) SE_CLASS3_VDIST_CONSTRUCTOR
Pietro Incardona's avatar
Pietro Incardona committed
494 495 496 497 498 499 500 501
	{
#ifdef SE_CLASS2
		check_new(this,8,VECTOR_DIST_EVENT,4);
#endif

		this->operator=(v);
	}

Pietro Incardona's avatar
Pietro Incardona committed
502
	/*! \brief Copy constructor
Pietro Incardona's avatar
Pietro Incardona committed
503
	 *
Pietro Incardona's avatar
Pietro Incardona committed
504
	 * \param v vector to copy
Pietro Incardona's avatar
Pietro Incardona committed
505 506
	 *
	 */
incardon's avatar
incardon committed
507
	vector_dist(vector_dist<dim,St,prop,Decomposition,Memory,layout_base> && v) noexcept
incardon's avatar
incardon committed
508
	:v_cl(v.v_cl) SE_CLASS3_VDIST_CONSTRUCTOR
Pietro Incardona's avatar
Pietro Incardona committed
509 510 511 512 513 514
	{
#ifdef SE_CLASS2
		check_new(this,8,VECTOR_DIST_EVENT,4);
#endif

		this->operator=(v);
incardon's avatar
incardon committed
515 516 517 518

#ifdef SE_CLASS3
		se3.Initialize();
#endif
Pietro Incardona's avatar
Pietro Incardona committed
519
	}
Pietro Incardona's avatar
Pietro Incardona committed
520

Pietro Incardona's avatar
Pietro Incardona committed
521
	/*! \brief Constructor with predefined decomposition
Pietro Incardona's avatar
Pietro Incardona committed
522
	 *
Pietro Incardona's avatar
Pietro Incardona committed
523 524
	 * \param dec is the decomposition
	 * \param np number of particles
Pietro Incardona's avatar
Pietro Incardona committed
525 526 527
	 *
	 */
	vector_dist(const Decomposition & dec, size_t np) :
528
	vector_dist_comm<dim,St,prop,Decomposition,Memory,layout_base>(dec), v_cl(create_vcluster<Memory>()) SE_CLASS3_VDIST_CONSTRUCTOR
Pietro Incardona's avatar
Pietro Incardona committed
529 530 531 532 533 534
	{
#ifdef SE_CLASS2
		check_new(this,8,VECTOR_DIST_EVENT,4);
#endif

		init_structures(np);
incardon's avatar
incardon committed
535 536 537 538

#ifdef SE_CLASS3
		se3.Initialize();
#endif
Pietro Incardona's avatar
Pietro Incardona committed
539 540 541
	}


incardon's avatar
incardon committed
542
	/*! \brief Constructor of a distributed vector
Pietro Incardona's avatar
Pietro Incardona committed
543 544 545
	 *
	 * \param np number of elements
	 * \param box domain where the vector of elements live
Pietro Incardona's avatar
Pietro Incardona committed
546
	 * \param bc boundary conditions
Pietro Incardona's avatar
Pietro Incardona committed
547
	 * \param g Ghost margins
incardon's avatar
incardon committed
548
	 * \param opt [Optional] additional options. BIND_DEC_TO_GHOST Bind the decomposition to be multiple of the
549 550
	 *          ghost size. This is required if we want to use symmetric to eliminate
	 *          ghost communications.
incardon's avatar
incardon committed
551
	 * \param gdist [Optional] override the default distribution grid
Pietro Incardona's avatar
Pietro Incardona committed
552 553
	 *
	 */
554
	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>())
555
	:v_cl(create_vcluster<Memory>()),opt(opt) SE_CLASS3_VDIST_CONSTRUCTOR
Pietro Incardona's avatar
Pietro Incardona committed
556 557 558 559 560
	{
#ifdef SE_CLASS2
		check_new(this,8,VECTOR_DIST_EVENT,4);
#endif

incardon's avatar
incardon committed
561 562 563
		if (opt >> 32 != 0)
			this->setDecompositionGranularity(opt >> 32);

incardon's avatar
incardon committed
564 565
		check_parameters(box);

Pietro Incardona's avatar
Pietro Incardona committed
566
		init_structures(np);
incardon's avatar
incardon committed
567

568
		this->init_decomposition(box,bc,g,opt,gdist);
incardon's avatar
incardon committed
569

570

incardon's avatar
incardon committed
571 572 573
#ifdef SE_CLASS3
		se3.Initialize();
#endif
Pietro Incardona's avatar
Pietro Incardona committed
574 575
	}

576 577 578 579 580 581 582
	~vector_dist()
	{
#ifdef SE_CLASS2
		check_delete(this);
#endif
	}

583 584 585 586 587 588 589 590 591
	/*! \brief remove all the elements
	 *
	 *
	 */
	void clear()
	{
		resize(0);
	}

Pietro Incardona's avatar
Pietro Incardona committed
592
	/*! \brief return the local size of the vector
593
	 *
Pietro Incardona's avatar
Pietro Incardona committed
594
	 * \return local size
595 596
	 *
	 */
incardon's avatar
incardon committed
597
	size_t size_local() const
598
	{
Pietro Incardona's avatar
Pietro Incardona committed
599
		return g_m;
600 601
	}

incardon's avatar
incardon committed
602 603 604 605 606
	/*! \brief return the local size of the vector
	 *
	 * \return local size
	 *
	 */
incardon's avatar
incardon committed
607
	size_t size_local_with_ghost() const
incardon's avatar
incardon committed
608
	{
Pietro Incardona's avatar
Pietro Incardona committed
609
		return v_pos.size();
incardon's avatar
incardon committed
610 611
	}

incardon's avatar
incardon committed
612 613
#ifndef ONLY_READWRITE_GETTER

614
	/*! \brief Get the position of an element
incardon's avatar
incardon committed
615
	 *
616 617 618 619 620
	 * see the vector_dist iterator usage to get an element key
	 *
	 * \param vec_key element
	 *
	 * \return the position of the element in space
incardon's avatar
incardon committed
621 622
	 *
	 */
Pietro Incardona's avatar
Pietro Incardona committed
623
	inline auto getPos(vect_dist_key_dx vec_key) -> decltype(v_pos.template get<0>(vec_key.getKey()))
incardon's avatar
incardon committed
624
	{
incardon's avatar
incardon committed
625 626 627 628
#ifdef SE_CLASS3
		check_for_pos_nan_inf<prop::max_prop_real,prop::max_prop>(*this,vec_key.getKey());
#endif

Pietro Incardona's avatar
Pietro Incardona committed
629
		return v_pos.template get<0>(vec_key.getKey());
incardon's avatar
incardon committed
630 631
	}

632 633 634 635 636 637 638 639 640 641 642
	/*! \brief Get the position of an element
	 *
	 * see the vector_dist iterator usage to get an element key
	 *
	 * \param vec_key element
	 *
	 * \return the position of the element in space
	 *
	 */
	inline auto getPos(vect_dist_key_dx vec_key) const -> decltype(v_pos.template get<0>(vec_key.getKey()))
	{
incardon's avatar
incardon committed
643 644 645
#ifdef SE_CLASS3
		check_for_pos_nan_inf<prop::max_prop_real,prop::max_prop>(*this,vec_key.getKey());
#endif
646 647 648
		return v_pos.template get<0>(vec_key.getKey());
	}

649 650 651 652 653 654 655 656 657
	/*! \brief Get the position of an element
	 *
	 * see the vector_dist iterator usage to get an element key
	 *
	 * \param vec_key element
	 *
	 * \return the position of the element in space
	 *
	 */
incardon's avatar
incardon committed
658 659
	inline auto getPos(size_t vec_key) -> decltype(v_pos.template get<0>(vec_key))
	{
incardon's avatar
incardon committed
660 661 662
#ifdef SE_CLASS3
		check_for_pos_nan_inf<prop::max_prop_real,prop::max_prop>(*this,vec_key);
#endif
incardon's avatar
incardon committed
663 664 665 666 667 668 669 670 671 672 673 674
		return v_pos.template get<0>(vec_key);
	}

	/*! \brief Get the position of an element
	 *
	 * see the vector_dist iterator usage to get an element key
	 *
	 * \param vec_key element
	 *
	 * \return the position of the element in space
	 *
	 */
incardon's avatar
incardon committed
675
	inline auto getPos(size_t vec_key) const -> decltype(v_pos.template get<0>(vec_key))
676
	{
incardon's avatar
incardon committed
677 678 679
#ifdef SE_CLASS3
		check_for_pos_nan_inf<prop::max_prop_real,prop::max_prop>(*this,vec_key);
#endif
680 681 682
		return v_pos.template get<0>(vec_key);
	}

683
	/*! \brief Get the property of an element
incardon's avatar
incardon committed
684
	 *
685 686 687
	 * see the vector_dist iterator usage to get an element key
	 *
	 * \tparam id property id
incardon's avatar
incardon committed
688 689
	 * \param vec_key vector element
	 *
690 691
	 * \return return the selected property of the vector element
	 *
incardon's avatar
incardon committed
692
	 */
693
	template<unsigned int id> inline auto getProp(vect_dist_key_dx vec_key) -> decltype(v_prp.template get<id>(vec_key.getKey()))
incardon's avatar
incardon committed
694
	{
incardon's avatar
incardon committed
695 696 697
#ifdef SE_CLASS3
		check_for_prop_nan_inf<id,prop::max_prop+SE3_STATUS>(*this,vec_key.getKey());
#endif
698
		return v_prp.template get<id>(vec_key.getKey());
incardon's avatar
incardon committed
699 700
	}

Pietro Incardona's avatar
Pietro Incardona committed
701 702 703 704 705 706 707 708 709 710
	/*! \brief Get the property of an element
	 *
	 * see the vector_dist iterator usage to get an element key
	 *
	 * \tparam id property id
	 * \param vec_key vector element
	 *
	 * \return return the selected property of the vector element
	 *
	 */
incardon's avatar
incardon committed
711
	template<unsigned int id> inline auto getProp(vect_dist_key_dx vec_key) const -> decltype(v_prp.template get<id>(vec_key.getKey()))
Pietro Incardona's avatar
Pietro Incardona committed
712
	{
incardon's avatar
incardon committed
713 714 715
#ifdef SE_CLASS3
		check_for_prop_nan_inf<id,prop::max_prop+SE3_STATUS>(*this,vec_key.getKey());
#endif
Pietro Incardona's avatar
Pietro Incardona committed
716 717 718
		return v_prp.template get<id>(vec_key.getKey());
	}

incardon's avatar
incardon committed
719 720 721 722 723 724 725 726 727 728 729 730
	/*! \brief Get the property of an element
	 *
	 * see the vector_dist iterator usage to get an element key
	 *
	 * \tparam id property id
	 * \param vec_key vector element
	 *
	 * \return return the selected property of the vector element
	 *
	 */
	template<unsigned int id> inline auto getProp(size_t vec_key) -> decltype(v_prp.template get<id>(vec_key))
	{
incardon's avatar
incardon committed
731 732 733
#ifdef SE_CLASS3
		check_for_prop_nan_inf<id,prop::max_prop+SE3_STATUS>(*this,vec_key);
#endif
incardon's avatar
incardon committed
734 735 736
		return v_prp.template get<id>(vec_key);
	}

737 738 739 740 741 742 743 744 745 746
	/*! \brief Get the property of an element
	 *
	 * see the vector_dist iterator usage to get an element key
	 *
	 * \tparam id property id
	 * \param vec_key vector element
	 *
	 * \return return the selected property of the vector element
	 *
	 */
incardon's avatar
incardon committed
747
	template<unsigned int id> inline auto getProp(size_t vec_key) const -> decltype(v_prp.template get<id>(vec_key))
748
	{
incardon's avatar
incardon committed
749 750 751
#ifdef SE_CLASS3
		check_for_prop_nan_inf<id,prop::max_prop+SE3_STATUS>(*this,vec_key);
#endif
752 753 754
		return v_prp.template get<id>(vec_key);
	}

incardon's avatar
incardon committed
755 756
#endif

incardon's avatar
incardon committed
757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839
///////////////////// Read and write with no check

	/*! \brief Get the position of an element
	 *
	 * see the vector_dist iterator usage to get an element key
	 *
	 * \param vec_key element
	 *
	 * \return the position of the element in space
	 *
	 */
	inline auto getPosNC(vect_dist_key_dx vec_key) -> decltype(v_pos.template get<0>(vec_key.getKey()))
	{
		return v_pos.template get<0>(vec_key.getKey());
	}

	/*! \brief Get the position of an element
	 *
	 * see the vector_dist iterator usage to get an element key
	 *
	 * \param vec_key element
	 *
	 * \return the position of the element in space
	 *
	 */
	inline auto getPosNC(vect_dist_key_dx vec_key) const -> decltype(v_pos.template get<0>(vec_key.getKey()))
	{
		return v_pos.template get<0>(vec_key.getKey());
	}

	/*! \brief Get the position of an element
	 *
	 * see the vector_dist iterator usage to get an element key
	 *
	 * \param vec_key element
	 *
	 * \return the position of the element in space
	 *
	 */
	inline auto getPosNC(size_t vec_key) -> decltype(v_pos.template get<0>(vec_key))
	{
		return v_pos.template get<0>(vec_key);
	}

	/*! \brief Get the position of an element
	 *
	 * see the vector_dist iterator usage to get an element key
	 *
	 * \param vec_key element
	 *
	 * \return the position of the element in space
	 *
	 */
	inline auto getPosNC(size_t vec_key) const -> decltype(v_pos.template get<0>(vec_key))
	{
		return v_pos.template get<0>(vec_key);
	}

	/*! \brief Get the property of an element
	 *
	 * see the vector_dist iterator usage to get an element key
	 *
	 * \tparam id property id
	 * \param vec_key vector element
	 *
	 * \return return the selected property of the vector element
	 *
	 */
	template<unsigned int id> inline auto getPropNC(vect_dist_key_dx vec_key) -> decltype(v_prp.template get<id>(vec_key.getKey()))
	{
		return v_prp.template get<id>(vec_key.getKey());
	}

	/*! \brief Get the property of an element
	 *
	 * see the vector_dist iterator usage to get an element key
	 *
	 * \tparam id property id
	 * \param vec_key vector element
	 *
	 * \return return the selected property of the vector element
	 *
	 */
incardon's avatar
incardon committed
840
	template<unsigned int id> inline auto getPropNC(vect_dist_key_dx vec_key) const -> decltype(v_prp.template get<id>(vec_key.getKey()))
incardon's avatar
incardon committed
841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869
	{
		return v_prp.template get<id>(vec_key.getKey());
	}

	/*! \brief Get the property of an element
	 *
	 * see the vector_dist iterator usage to get an element key
	 *
	 * \tparam id property id
	 * \param vec_key vector element
	 *
	 * \return return the selected property of the vector element
	 *
	 */
	template<unsigned int id> inline auto getPropNC(size_t vec_key) -> decltype(v_prp.template get<id>(vec_key))
	{
		return v_prp.template get<id>(vec_key);
	}

	/*! \brief Get the property of an element
	 *
	 * see the vector_dist iterator usage to get an element key
	 *
	 * \tparam id property id
	 * \param vec_key vector element
	 *
	 * \return return the selected property of the vector element
	 *
	 */
incardon's avatar
incardon committed
870
	template<unsigned int id> inline auto getPropNC(size_t vec_key) const -> decltype(v_prp.template get<id>(vec_key))
incardon's avatar
incardon committed
871 872 873 874
	{
		return v_prp.template get<id>(vec_key);
	}

incardon's avatar
incardon committed
875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941
///////////////////// Read and Write function

	/*! \brief Get the position of an element
	 *
	 * see the vector_dist iterator usage to get an element key
	 *
	 * \param vec_key element
	 *
	 * \return the position of the element in space
	 *
	 */
	inline auto getPosWrite(vect_dist_key_dx vec_key) -> decltype(v_pos.template get<0>(vec_key.getKey()))
	{
#ifdef SE_CLASS3
		se3.template write<prop::max_prop_real>(*this,vec_key.getKey());
#endif

		return v_pos.template get<0>(vec_key.getKey());
	}

	/*! \brief Get the position of an element
	 *
	 * see the vector_dist iterator usage to get an element key
	 *
	 * \param vec_key element
	 *
	 * \return the position of the element in space
	 *
	 */
	inline auto getPosRead(vect_dist_key_dx vec_key) const -> decltype(v_pos.template get<0>(vec_key.getKey()))
	{
#ifdef SE_CLASS3
		se3.template read<prop::max_prop_real>(*this,vec_key.getKey());
#endif

		return v_pos.template get<0>(vec_key.getKey());
	}

	/*! \brief Get the property of an element
	 *
	 * see the vector_dist iterator usage to get an element key
	 *
	 * \tparam id property id
	 * \param vec_key vector element
	 *
	 * \return return the selected property of the vector element
	 *
	 */
	template<unsigned int id> inline auto getPropWrite(vect_dist_key_dx vec_key) -> decltype(v_prp.template get<id>(vec_key.getKey()))
	{
#ifdef SE_CLASS3
		se3.template write<id>(*this,vec_key.getKey());
#endif

		return v_prp.template get<id>(vec_key.getKey());
	}

	/*! \brief Get the property of an element
	 *
	 * see the vector_dist iterator usage to get an element key
	 *
	 * \tparam id property id
	 * \param vec_key vector element
	 *
	 * \return return the selected property of the vector element
	 *
	 */
incardon's avatar
incardon committed
942
	template<unsigned int id> inline auto getPropRead(vect_dist_key_dx vec_key) const -> decltype(v_prp.template get<id>(vec_key.getKey()))
incardon's avatar
incardon committed
943 944 945 946 947 948 949 950 951 952
	{
#ifdef SE_CLASS3
		se3.template read<id>(*this,vec_key.getKey());
#endif

		return v_prp.template get<id>(vec_key.getKey());
	}

//////////////////////////////////////////////

953 954 955 956 957 958 959 960 961 962 963 964 965 966
	/*! \brief Add local particle
	 *
	 * It add a local particle, with "local" we mean in this processor
	 * the particle can be also created out of the processor domain, in this
	 * case a call to map is required. Added particles are always created at the
	 * end and can be accessed with getLastPos and getLastProp
	 *
	 */
	void add()
	{
		v_prp.insert(g_m);
		v_pos.insert(g_m);

		g_m++;
incardon's avatar
incardon committed
967 968 969 970 971

#ifdef SE_CLASS3
		for (size_t i = 0 ; i < prop::max_prop_real+1 ; i++)
			v_prp.template get<prop::max_prop_real>(g_m-1)[i] = UNINITIALIZED;
#endif
972 973
	}

incardon's avatar
incardon committed
974 975
#ifndef ONLY_READWRITE_GETTER

976 977 978 979 980
	/*! \brief Get the position of the last element
	 *
	 * \return the position of the element in space
	 *
	 */
Pietro Incardona's avatar
Pietro Incardona committed
981
	inline auto getLastPos() -> decltype(v_pos.template get<0>(0))
982
	{
Pietro Incardona's avatar
Pietro Incardona committed
983
		return v_pos.template get<0>(g_m - 1);
984 985 986 987 988 989 990 991 992 993 994
	}

	/*! \brief Get the property of the last element
	 *
	 * \tparam id property id
	 *
	 * \return return the selected property of the vector element
	 *
	 */
	template<unsigned int id> inline auto getLastProp() -> decltype(v_prp.template get<id>(0))
	{
995
		return v_prp.template get<id>(g_m - 1);
996 997
	}

incardon's avatar
incardon committed
998 999
#endif

incardon's avatar
incardon committed
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
////////////////////////////// READ AND WRITE VERSION //////////

	/*! \brief Get the position of the last element
	 *
	 * \return the position of the element in space
	 *
	 */
	inline auto getLastPosRead() -> decltype(v_pos.template get<0>(0))
	{
#ifdef SE_CLASS3
incardon's avatar
incardon committed
1010
		se3.template read<prop::max_prop_real>(*this,g_m-1);
incardon's avatar
incardon committed
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
#endif

		return v_pos.template get<0>(g_m - 1);
	}

	/*! \brief Get the property of the last element
	 *
	 * \tparam id property id
	 *
	 * \return return the selected property of the vector element
	 *
	 */
	template<unsigned int id> inline auto getLastPropRead() -> decltype(v_prp.template get<id>(0))
	{
#ifdef SE_CLASS3
		se3.read<id>(*this,g_m-1);
#endif

		return v_prp.template get<id>(g_m - 1);
	}


	/*! \brief Get the position of the last element
	 *
	 * \return the position of the element in space
	 *
	 */
	inline auto getLastPosWrite() -> decltype(v_pos.template get<0>(0))
	{
#ifdef SE_CLASS3
incardon's avatar
incardon committed
1041
		se3.template write<prop::max_prop_real>(*this,g_m-1);
incardon's avatar
incardon committed
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056
#endif

		return v_pos.template get<0>(g_m - 1);
	}

	/*! \brief Get the property of the last element
	 *
	 * \tparam id property id
	 *
	 * \return return the selected property of the vector element
	 *
	 */
	template<unsigned int id> inline auto getLastPropWrite() -> decltype(v_prp.template get<id>(0))
	{
#ifdef SE_CLASS3
incardon's avatar
incardon committed
1057
		se3.template write<id>(*this,g_m-1);
incardon's avatar
incardon committed
1058 1059 1060 1061 1062 1063 1064
#endif

		return v_prp.template get<id>(g_m - 1);
	}

////////////////////////////////////////////////////////////////

incardon's avatar
incardon committed
1065 1066 1067 1068 1069 1070 1071 1072 1073
	/*! \brief Construct a cell list symmetric based on a cut of radius
	 *
	 * \tparam CellL CellList type to construct
	 *
	 * \param r_cut interation radius, or size of each cell
	 *
	 * \return the Cell list
	 *
	 */
incardon's avatar
incardon committed
1074 1075
	template<typename CellL = CellList<dim, St, Mem_fast<>, shift<dim, St>,internal_position_vector_type > >
	CellL getCellListSym(St r_cut)
incardon's avatar
incardon committed
1076
	{
incardon's avatar
incardon committed
1077
#ifdef SE_CLASS1
incardon's avatar
incardon committed
1078
		if (!(opt & BIND_DEC_TO_GHOST))
incardon's avatar
incardon committed
1079
		{
incardon's avatar
incardon committed
1080
			if (getDecomposition().getGhost().getLow(dim-1) == 0.0)
1081 1082 1083 1084
			{
				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;
				ACTION_ON_ERROR(VECTOR_DIST_ERROR_OBJECT);
			}
incardon's avatar
incardon committed
1085 1086 1087
		}
#endif

incardon's avatar
incardon committed
1088 1089 1090 1091
		// Cell list
		CellL cell_list;

		size_t pad = 0;
incardon's avatar
incardon committed
1092 1093
		CellDecomposer_sm<dim,St,shift<dim,St>> cd_sm;
		cl_param_calculateSym(getDecomposition().getDomain(),cd_sm,getDecomposition().getGhost(),r_cut,pad);
incardon's avatar
incardon committed
1094

incardon's avatar
incardon committed
1095
		// Processor bounding box
incardon's avatar
incardon committed
1096 1097
		Box<dim, St> pbox = getDecomposition().getProcessorBounds();

incardon's avatar
incardon committed
1098 1099 1100
		// Ghost padding extension
		Ghost<dim,size_t> g_ext(0);
		cell_list.Initialize(cd_sm,pbox,pad);
1101
		cell_list.set_ndec(getDecomposition().get_ndec());
incardon's avatar
incardon committed
1102

incardon's avatar
incardon committed
1103
		updateCellListSym(cell_list);
incardon's avatar
incardon committed
1104 1105

		return cell_list;
incardon's avatar
incardon committed
1106 1107
	}

incardon's avatar
incardon committed
1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153
	/*! \brief Construct a cell list symmetric based on a cut of radius
	 *
	 * \tparam CellL CellList type to construct
	 *
	 * \param r_cut interation radius, or size of each cell
	 *
	 * \return the Cell list
	 *
	 */
	template<typename CellL = CellList<dim, St, Mem_fast<>, shift<dim, St> > >
	CellL getCellListSym(const size_t (& div)[dim],
						 const size_t (& pad)[dim])
	{
#ifdef SE_CLASS1
		if (!(opt & BIND_DEC_TO_GHOST))
		{
			if (getDecomposition().getGhost().getLow(dim-1) == 0.0)
			{
				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;
				ACTION_ON_ERROR(VECTOR_DIST_ERROR_OBJECT);
			}
		}
#endif

		size_t pad_max = pad[0];
		for (size_t i = 1 ; i < dim ; i++)
		{if (pad[i] > pad_max)	{pad_max = pad[i];}}

		// Cell list
		CellL cell_list;

		CellDecomposer_sm<dim,St,shift<dim,St>> cd_sm;
		cd_sm.setDimensions(getDecomposition().getDomain(),div,pad_max);

		// Processor bounding box
		Box<dim, St> pbox = getDecomposition().getProcessorBounds();

		// Ghost padding extension
		Ghost<dim,size_t> g_ext(0);
		cell_list.Initialize(cd_sm,pbox,pad_max);
		cell_list.set_ndec(getDecomposition().get_ndec());

		updateCellListSym(cell_list);

		return cell_list;
	}
1154

1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170
	/*! \brief Construct a cell list starting from the stored particles
	 *
	 * \tparam CellL CellList type to construct
	 *
	 * \param r_cut interation radius, or size of each cell
	 * \param no_se3 avoid SE_CLASS3 checking
	 *
	 * \return the Cell list
	 *
	 */
	template<unsigned int impl>
	typename cell_list_selector<self,impl>::ctype getCellListDev(St r_cut)
	{
		return cell_list_selector<self,impl>::get(*this,r_cut);
	}

Pietro Incardona's avatar
Pietro Incardona committed
1171 1172 1173 1174
	/*! \brief Construct a cell list starting from the stored particles
	 *
	 * \tparam CellL CellList type to construct
	 *
1175
	 * \param r_cut interation radius, or size of each cell
incardon's avatar
incardon committed
1176
	 * \param no_se3 avoid SE_CLASS3 checking
1177 1178 1179
	 *
	 * \return the Cell list
	 *
Pietro Incardona's avatar
Pietro Incardona committed
1180
	 */
incardon's avatar
incardon committed
1181
	template<typename CellL = CellList_gen<dim, St, Process_keys_lin, Mem_fast<>, shift<dim, St>, decltype(v_pos) > >
incardon's avatar
incardon committed
1182
	CellL getCellList(St r_cut, bool no_se3 = false)
1183
	{
incardon's avatar
incardon committed
1184
#ifdef SE_CLASS3
incardon's avatar
incardon committed
1185 1186
		if (no_se3 == false)
		{se3.getNN();}
incardon's avatar
incardon committed
1187 1188 1189 1190 1191
#endif
#ifdef SE_CLASS1
		check_ghost_compatible_rcut(r_cut);
#endif

Pietro Incardona's avatar
Pietro Incardona committed
1192
		// Get ghost and anlarge by 1%
Pietro Incardona's avatar
Pietro Incardona committed
1193
		Ghost<dim,St> g = getDecomposition().getGhost();
1194
		g.magnify(1.013);
Pietro Incardona's avatar
Pietro Incardona committed
1195

incardon's avatar
incardon committed
1196
		return getCellList<CellL>(r_cut, g,no_se3);
1197 1198
	}

incardon's avatar
incardon committed
1199 1200
#ifdef CUDA_GPU

incardon's avatar
incardon committed
1201
	/*! \brief Construct a cell list starting from the stored particles
incardon's avatar
incardon committed
1202 1203 1204 1205 1206 1207
	 *
	 * \param r_cut interation radius, or size of each cell
	 *
	 * \return the Cell list
	 *
	 */
incardon's avatar
incardon committed
1208 1209
	template<typename CellType = CellList_gpu<dim,St,CudaMemory,shift_only<dim, St>>>
	CellType getCellListGPU(St r_cut, bool no_se3 = false)
incardon's avatar
incardon committed
1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222
	{
#ifdef SE_CLASS3
		if (no_se3 == false)
		{se3.getNN();}
#endif
#ifdef SE_CLASS1
		check_ghost_compatible_rcut(r_cut);
#endif

		// Get ghost and anlarge by 1%
		Ghost<dim,St> g = getDecomposition().getGhost();
		g.magnify(1.013);

incardon's avatar
incardon committed
1223
		return getCellListGPU<CellType>(r_cut, g,no_se3);
incardon's avatar
incardon committed
1224 1225
	}

incardon's avatar
incardon committed
1226

incardon's avatar
incardon committed
1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241
	/*! \brief Construct a cell list starting from the stored particles
	 *
	 * It differ from the get getCellList for an additional parameter, in case the
	 * domain + ghost is not big enough to contain additional padding particles, a Cell list
	 * with bigger space can be created
	 * (padding particles in general are particles added by the user out of the domains)
	 *
	 * \tparam CellL CellList type to construct
	 *
	 * \param r_cut interation radius, or size of each cell
	 * \param enlarge In case of padding particles the cell list must be enlarged, like a ghost this parameter say how much must be enlarged
	 *
	 * \return the CellList
	 *
	 */
incardon's avatar
incardon committed
1242 1243
	template<typename CellType = CellList_gpu<dim,St,CudaMemory,shift_only<dim, St>>>
	CellType getCellListGPU(St r_cut, const Ghost<dim, St> & enlarge, bool no_se3 = false)
incardon's avatar
incardon committed
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258
	{
#ifdef SE_CLASS3
		if (no_se3 == false)
		{se3.getNN();}
#endif

		// Division array
		size_t div[dim];

		// get the processor bounding box
		Box<dim, St> pbox = getDecomposition().getProcessorBounds();

		// Processor bounding box
		cl_param_calculate(pbox, div, r_cut, enlarge);

incardon's avatar
incardon committed
1259
		CellType cell_list(pbox,div);