VCluster_meta_function.hpp 20.1 KB
Newer Older
incardon's avatar
incardon committed
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 * VCluster_meta_function.hpp
 *
 *  Created on: Dec 8, 2016
 *      Author: i-bird
 */

#ifndef OPENFPM_VCLUSTER_SRC_VCLUSTER_VCLUSTER_META_FUNCTION_HPP_
#define OPENFPM_VCLUSTER_SRC_VCLUSTER_VCLUSTER_META_FUNCTION_HPP_

#include "memory/BHeapMemory.hpp"
#include "Packer_Unpacker/has_max_prop.hpp"

incardon's avatar
incardon committed
14
template<bool result, typename T, typename S, template<typename> class layout_base>
incardon's avatar
incardon committed
15 16
struct unpack_selector_with_prp
{
incardon's avatar
incardon committed
17 18 19 20 21 22 23
	template<typename op,
			 int ... prp>
	static void call_unpack(S & recv,
			                openfpm::vector<BHeapMemory> & recv_buf,
							openfpm::vector<size_t> * sz,
							openfpm::vector<size_t> * sz_byte,
							op & op_param)
incardon's avatar
incardon committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
	{
		if (sz_byte != NULL)
			sz_byte->resize(recv_buf.size());

		for (size_t i = 0 ; i < recv_buf.size() ; i++)
		{
			T unp;

			ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(recv_buf.get(i).size(),recv_buf.get(i)));
			mem.incRef();

			Unpack_stat ps;

			Unpacker<T,HeapMemory>::template unpack<>(mem, unp, ps);

			size_t recv_size_old = recv.size();
			// Merge the information

incardon's avatar
incardon committed
42
			op_param.template execute<true,T,decltype(recv),decltype(unp),layout_base,prp...>(recv,unp,i);
incardon's avatar
incardon committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56

			size_t recv_size_new = recv.size();

			if (sz_byte != NULL)
				sz_byte->get(i) = recv_buf.get(i).size();
			if (sz != NULL)
				sz->get(i) = recv_size_new - recv_size_old;

			mem.decRef();
			delete &mem;
		}
	}
};

incardon's avatar
incardon committed
57 58
template<typename op, typename Vt, typename S, template<typename> class layout_base, typename v_mpl>
struct unpack_each_prop_buffer
incardon's avatar
incardon committed
59
{
incardon's avatar
incardon committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
	S & recv;

	openfpm::vector<BHeapMemory> & recv_buf;

	size_t i;

	op & op_param;

    openfpm::vector<size_t> * sz;

    openfpm::vector<size_t> * sz_byte;

	/*! \brief constructor
	 *
	 * \param v set of pointer buffers to set
	 *
	 */
	inline unpack_each_prop_buffer(S & recv,
			                       openfpm::vector<BHeapMemory> & recv_buf,
			                       op & op_param,
			                       size_t i,
			                       openfpm::vector<size_t> * sz,
			                       openfpm::vector<size_t> * sz_byte)
	:recv(recv),recv_buf(recv_buf),op_param(op_param),i(i),sz(sz),sz_byte(sz_byte)
	{};

	//! It call the copy function for each property
	template<typename T>
	inline void operator()(T& t) const
incardon's avatar
incardon committed
89
	{
incardon's avatar
incardon committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
		// here we get the the type of the property at position T::value
		typedef typename boost::mpl::at<typename T::value_type::type,boost::mpl::int_<T::value> >::type prp_type;

		// here we get the the type of the property at position T::value
		typedef typename boost::mpl::at<v_mpl,boost::mpl::int_<T::value>>::type prp_num;

		// calculate the number of received elements
		size_t n_ele = recv_buf.get(i).size() / sizeof(prp_type);

		// add the received particles to the vector
		PtrMemory * ptr1 = new PtrMemory(recv_buf.get(i).getPointer(),recv_buf.get(i).size());

		// create vector representation to a piece of memory already allocated
		openfpm::vector<typename Vt::value_type,PtrMemory,typename layout_base<typename Vt::value_type>::type,layout_base,openfpm::grow_policy_identity> v2;

		v2.template setMemory<prp_num::value>(*ptr1);

		// resize with the number of elements
		v2.resize(n_ele);

		// Merge the information

		size_t recv_size_old = recv.size();

		op_param.template execute<false,T,decltype(recv),decltype(v2),layout_base,prp_num::value>(recv,v2,i);

		size_t recv_size_new = recv.size();

incardon's avatar
incardon committed
118
		if (sz_byte != NULL)
incardon's avatar
incardon committed
119 120 121 122 123
			sz_byte->get(i) = recv_buf.get(i).size();
		if (sz != NULL)
			sz->get(i) = recv_size_new - recv_size_old;
	}
};
incardon's avatar
incardon committed
124

incardon's avatar
incardon committed
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
/*! \brief this class is a functor for "for_each" algorithm
 *
 * This class is a functor for "for_each" algorithm. For each
 * element of the boost::vector the operator() is called.
 * Is mainly used to process the receive buffers in case of memory_traits_inte layout receive
 *
 * \tparam encap source
 * \tparam encap dst
 *
 */

template<typename sT, template<typename> class layout_base>
struct process_receive_mem_traits_inte
{
	//! set of pointers
	size_t i;

	//! Receive buffer
	openfpm::vector<BHeapMemory> & recv_buf;

	//! Fake vector that map over received memory
	openfpm::vector<typename sT::value_type,PtrMemory,typename layout_base<typename sT::value_type>::type,layout_base,openfpm::grow_policy_identity> & v2;

	size_t n_ele = 0;

	/*! \brief constructor
	 *
	 * \param v set of pointer buffers to set
	 *
	 */
	inline process_receive_mem_traits_inte(openfpm::vector<typename sT::value_type,PtrMemory,typename layout_base<typename sT::value_type>::type,layout_base,openfpm::grow_policy_identity> & v2,
			                               openfpm::vector<BHeapMemory> & recv_buf,
			                               size_t i)
	:i(i),recv_buf(recv_buf),v2(v2)
	{};

	//! It call the copy function for each property
	template<typename T>
	inline void operator()(T& t)
	{
		typedef typename boost::mpl::at<typename sT::value_type::type,T>::type type_prp;

		// calculate the number of received elements
		this->n_ele = recv_buf.get(i).size() / sizeof(type_prp);

		// add the received particles to the vector
		PtrMemory * ptr1 = new PtrMemory(recv_buf.get(i).getPointer(),recv_buf.get(i).size());

		v2.template setMemory<T::value>(*ptr1);

		++i;
	}
};

incardon's avatar
incardon committed
179 180 181 182 183 184 185 186 187 188 189 190
template<bool inte_or_lin,typename T, typename S, template<typename> class layout_base>
struct unpack_selector_with_prp_lin
{
	template<typename op, unsigned int ... prp> static int call_unpack_impl(S & recv,
                                                                             openfpm::vector<BHeapMemory> & recv_buf,
                                                                             openfpm::vector<size_t> * sz,
                                                                             openfpm::vector<size_t> * sz_byte,
                                                                             op & op_param,
                                                                             size_t i)
	{
		// create vector representation to a piece of memory already allocated
		openfpm::vector<typename T::value_type,PtrMemory,typename layout_base<typename T::value_type>::type,layout_base,openfpm::grow_policy_identity> v2;
incardon's avatar
incardon committed
191

incardon's avatar
incardon committed
192
		process_receive_mem_traits_inte<T,layout_base> prmti(v2,recv_buf,i);
incardon's avatar
incardon committed
193

incardon's avatar
incardon committed
194 195 196
		boost::mpl::for_each_ref<boost::mpl::range_c<int,0,T::value_type::max_prop>>(prmti);

		v2.resize(prmti.n_ele);
incardon's avatar
incardon committed
197

incardon's avatar
incardon committed
198
		// Merge the information
incardon's avatar
incardon committed
199

incardon's avatar
incardon committed
200
		size_t recv_size_old = recv.size();
incardon's avatar
incardon committed
201

incardon's avatar
incardon committed
202
		op_param.template execute<false,T,decltype(recv),decltype(v2),layout_base,prp...>(recv,v2,i);
incardon's avatar
incardon committed
203

incardon's avatar
incardon committed
204
		size_t recv_size_new = recv.size();
incardon's avatar
incardon committed
205

incardon's avatar
incardon committed
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
		if (sz_byte != NULL)
			sz_byte->get(i) = recv_buf.get(i).size();
		if (sz != NULL)
			sz->get(i) = recv_size_new - recv_size_old;

		return sizeof...(prp);
	}
};

template<typename T, typename S, template<typename> class layout_base>
struct unpack_selector_with_prp_lin<true,T,S,layout_base>
{
	template<typename op, unsigned int ... prp> static int call_unpack_impl(S & recv,
                                                                             openfpm::vector<BHeapMemory> & recv_buf,
                                                                             openfpm::vector<size_t> * sz,
                                                                             openfpm::vector<size_t> * sz_byte,
                                                                             op & op_param,
                                                                             size_t i)
	{
		// calculate the number of received elements
		size_t n_ele = recv_buf.get(i).size() / sizeof(typename T::value_type);

		// add the received particles to the vector
		PtrMemory * ptr1 = new PtrMemory(recv_buf.get(i).getPointer(),recv_buf.get(i).size());

		// create vector representation to a piece of memory already allocated
		openfpm::vector<typename T::value_type,PtrMemory,typename layout_base<typename T::value_type>::type,layout_base,openfpm::grow_policy_identity> v2;

		v2.setMemory(*ptr1);

		// resize with the number of elements
		v2.resize(n_ele);

		// Merge the information

		size_t recv_size_old = recv.size();

		op_param.template execute<false,T,decltype(recv),decltype(v2),layout_base,prp...>(recv,v2,i);

		size_t recv_size_new = recv.size();

		if (sz_byte != NULL)
			sz_byte->get(i) = recv_buf.get(i).size();
		if (sz != NULL)
			sz->get(i) = recv_size_new - recv_size_old;

		return 1;
	}
};

typedef aggregate<int,int> dummy_type;

//
template<typename T, typename S, template<typename> class layout_base>
struct unpack_selector_with_prp<true,T,S,layout_base>
{
	template<typename op, unsigned int ... prp> static void call_unpack(S & recv,
			                                                            openfpm::vector<BHeapMemory> & recv_buf,
			                                                            openfpm::vector<size_t> * sz,
			                                                            openfpm::vector<size_t> * sz_byte,
			                                                            op & op_param)
	{
		if (sz_byte != NULL)
			sz_byte->resize(recv_buf.size());

		for (size_t i = 0 ; i < recv_buf.size() ; )
		{
			i += unpack_selector_with_prp_lin<is_layout_mlin<layout_base<dummy_type>>::value,T,S,layout_base>::template call_unpack_impl<op,prp...>(recv,recv_buf,sz,sz_byte,op_param,i);
incardon's avatar
incardon committed
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
		}
	}
};


template<typename T>
struct call_serialize_variadic {};

template<int ... prp>
struct call_serialize_variadic<index_tuple<prp...>>
{
	template<typename T> inline static void call_pr(T & send, size_t & tot_size)
	{
		Packer<T,HeapMemory>::template packRequest<prp...>(send,tot_size);
	}

	template<typename T> inline static void call_pack(ExtPreAlloc<HeapMemory> & mem, T & send, Pack_stat & sts)
	{
		Packer<T,HeapMemory>::template pack<prp...>(mem,send,sts);
	}

incardon's avatar
incardon committed
295 296 297 298 299 300
	template<typename op, typename T, typename S, template<typename> class layout_base>
	inline static void call_unpack(S & recv,
			                       openfpm::vector<BHeapMemory> & recv_buf,
			                       openfpm::vector<size_t> * sz,
			                       openfpm::vector<size_t> * sz_byte,
			                       op & op_param)
incardon's avatar
incardon committed
301 302 303
	{
		const bool result = has_pack_gen<typename T::value_type>::value == false && is_vector<T>::value == true;

incardon's avatar
incardon committed
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
		unpack_selector_with_prp<result, T, S,layout_base>::template call_unpack<op,prp...>(recv, recv_buf, sz, sz_byte, op_param);
	}
};

/*! \brief this class is a functor for "for_each" algorithm
 *
 * This class is a functor for "for_each" algorithm. For each
 * element of the boost::vector the operator() is called.
 * Is mainly used to copy one encap into another encap object
 *
 * \tparam encap source
 * \tparam encap dst
 *
 */
template<typename sT>
struct set_buf_pointer_for_each_prop
{
	//! set of pointers
	sT & v;

	openfpm::vector<const void *> & send_buf;

326 327
	size_t opt;

incardon's avatar
incardon committed
328 329 330 331 332
	/*! \brief constructor
	 *
	 * \param v set of pointer buffers to set
	 *
	 */
333 334
	inline set_buf_pointer_for_each_prop(sT & v, openfpm::vector<const void *> & send_buf, size_t opt)
	:v(v),send_buf(send_buf),opt(opt)
incardon's avatar
incardon committed
335 336 337 338 339 340
	{};

	//! It call the copy function for each property
	template<typename T>
	inline void operator()(T& t) const
	{
341 342 343 344 345 346 347 348 349 350 351 352 353 354
		// If we have GPU direct activated use directly the cuda buffer
		if (opt & MPI_GPU_DIRECT)
		{
#if defined(MPIX_CUDA_AWARE_SUPPORT) && MPIX_CUDA_AWARE_SUPPORT
			send_buf.add(v.template getDevicePointer<T::value>());
#else
			v.template deviceToHost<T::value>();
			send_buf.add(v.template getPointer<T::value>());
#endif
		}
		else
		{
			send_buf.add(v.template getPointer<T::value>());
		}
incardon's avatar
incardon committed
355 356 357
	}
};

incardon's avatar
incardon committed
358 359 360 361 362 363 364 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
/*! \brief this class is a functor for "for_each" algorithm
 *
 * This class is a functor for "for_each" algorithm. For each
 * element of the boost::vector the operator() is called.
 * Is mainly used to copy one encap into another encap object
 *
 * \tparam encap source
 * \tparam encap dst
 *
 */

template<typename sT>
struct set_buf_size_for_each_prop
{
	//! set of pointers
	sT & v;

	openfpm::vector<size_t> & sz;

	/*! \brief constructor
	 *
	 * \param v set of pointer buffers to set
	 *
	 */
	inline set_buf_size_for_each_prop(sT & v, openfpm::vector<size_t> & sz)
	:v(v),sz(sz)
	{};

	//! It call the copy function for each property
	template<typename T>
	inline void operator()(T& t) const
	{
		typedef typename boost::mpl::at<typename sT::value_type::type,T>::type type_prp;

		sz.add(sizeof(type_prp)*v.size());
	}
};

incardon's avatar
incardon committed
396 397 398
template<typename T, bool impl = is_multiple_buffer_each_prp<T>::value >
struct pack_unpack_cond_with_prp_inte_lin
{
399
	static void set_buffers(T & send, openfpm::vector<const void *> & send_buf, size_t opt)
incardon's avatar
incardon committed
400 401 402
	{
		send_buf.add(send.getPointer());
	}
incardon's avatar
incardon committed
403 404 405 406 407 408 409 410 411 412 413 414 415

	static void set_size_buffers(T & send, openfpm::vector<size_t> & sz)
	{
		sz.add(send.size()*sizeof(typename T::value_type));
	}

	static void construct_prc(openfpm::vector<size_t> & prc_send, openfpm::vector<size_t> & prc_send_)
	{
		for (size_t i = 0 ; i < prc_send.size() ; i++)
		{
			prc_send_.add(prc_send.get(i));
		}
	}
incardon's avatar
incardon committed
416 417 418 419 420 421
};

// memory_traits_inte
template<typename T>
struct pack_unpack_cond_with_prp_inte_lin<T,true>
{
422
	static void set_buffers(T & send, openfpm::vector<const void *> & send_buf, size_t opt)
incardon's avatar
incardon committed
423
	{
424
		set_buf_pointer_for_each_prop<T> sbp(send,send_buf,opt);
incardon's avatar
incardon committed
425 426

		boost::mpl::for_each_ref<boost::mpl::range_c<int,0,T::value_type::max_prop>>(sbp);
incardon's avatar
incardon committed
427
	}
incardon's avatar
incardon committed
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442

	static void set_size_buffers(T & send, openfpm::vector<size_t> & sz)
	{
		set_buf_size_for_each_prop<T> sbp(send,sz);

		boost::mpl::for_each_ref<boost::mpl::range_c<int,0,T::value_type::max_prop>>(sbp);
	}

	static void construct_prc(openfpm::vector<size_t> & prc_send, openfpm::vector<size_t> & prc_send_)
	{
		for (size_t i = 0 ; i < prc_send.size() ; i++)
		{
			for (size_t j = 0 ; j < T::value_type::max_prop ; j++)
			{prc_send_.add(prc_send.get(i));}
		}
443
	}
incardon's avatar
incardon committed
444 445 446
};

//! There is max_prop inside
incardon's avatar
incardon committed
447 448 449 450 451 452
template<bool cond,
         typename op,
		 typename T,
		 typename S,
		 template <typename> class layout_base,
		 unsigned int ... prp>
incardon's avatar
incardon committed
453 454 455 456 457 458 459
struct pack_unpack_cond_with_prp
{
	static void packingRequest(T & send, size_t & tot_size, openfpm::vector<size_t> & sz)
	{
		typedef typename ::generate_indexes<int, has_max_prop<T, has_value_type<T>::value>::number, MetaFuncOrd>::result ind_prop_to_pack;
		if (has_pack_gen<typename T::value_type>::value == false && is_vector<T>::value == true)
		{
incardon's avatar
incardon committed
460
			pack_unpack_cond_with_prp_inte_lin<T>::set_size_buffers(send,sz);
incardon's avatar
incardon committed
461 462 463 464 465 466 467 468 469
		}
		else
		{
			call_serialize_variadic<ind_prop_to_pack>::call_pr(send,tot_size);

			sz.add(tot_size);
		}
	}

470
	static void packing(ExtPreAlloc<HeapMemory> & mem, T & send, Pack_stat & sts, openfpm::vector<const void *> & send_buf, size_t opt = 0)
incardon's avatar
incardon committed
471 472 473 474
	{
		typedef typename ::generate_indexes<int, has_max_prop<T, has_value_type<T>::value>::number, MetaFuncOrd>::result ind_prop_to_pack;
		if (has_pack_gen<typename T::value_type>::value == false && is_vector<T>::value == true)
		{
475
			pack_unpack_cond_with_prp_inte_lin<T>::set_buffers(send,send_buf,opt);
incardon's avatar
incardon committed
476 477 478 479 480 481 482 483
		}
		else
		{
			send_buf.add(mem.getPointerEnd());
			call_serialize_variadic<ind_prop_to_pack>::call_pack(mem,send,sts);
		}
	}

incardon's avatar
incardon committed
484 485
	static void unpacking(S & recv,
			              openfpm::vector<BHeapMemory> & recv_buf,
incardon's avatar
incardon committed
486 487 488
						  openfpm::vector<size_t> * sz,
						  openfpm::vector<size_t> * sz_byte,
						  op & op_param)
incardon's avatar
incardon committed
489 490
	{
		typedef index_tuple<prp...> ind_prop_to_pack;
incardon's avatar
incardon committed
491
		call_serialize_variadic<ind_prop_to_pack>::template call_unpack<op,T,S,layout_base>(recv, recv_buf, sz, sz_byte, op_param);
incardon's avatar
incardon committed
492 493 494 495 496 497 498 499 500 501 502
	}
};


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

//! Helper class to add data without serialization
template<bool sr>
struct op_ssend_recv_add_sr
{
	//! Add data
incardon's avatar
incardon committed
503 504 505 506 507
	template<typename T,
	         typename D,
			 typename S,
			 template <typename> class layout_base,
			 int ... prp> static void execute(D & recv,S & v2, size_t i)
incardon's avatar
incardon committed
508 509
	{
		// Merge the information
incardon's avatar
incardon committed
510
		recv.template add_prp<typename T::value_type,
incardon's avatar
incardon committed
511
		                      PtrMemory,
incardon's avatar
incardon committed
512 513
							  openfpm::grow_policy_identity,
							  openfpm::vect_isel<typename T::value_type>::value,
incardon's avatar
incardon committed
514
							  layout_base,
incardon's avatar
incardon committed
515
							  prp...>(v2);
incardon's avatar
incardon committed
516 517 518 519 520 521 522 523
	}
};

//! Helper class to add data with serialization
template<>
struct op_ssend_recv_add_sr<true>
{
	//! Add data
incardon's avatar
incardon committed
524 525 526 527 528 529
	template<typename T,
	         typename D,
			 typename S,
			 template <typename> class layout_base,
			 int ... prp>
	static void execute(D & recv,S & v2, size_t i)
incardon's avatar
incardon committed
530 531
	{
		// Merge the information
incardon's avatar
incardon committed
532 533
		recv.template add_prp<typename T::value_type,
		                      HeapMemory,
534
		                      typename T::grow_policy,
incardon's avatar
incardon committed
535 536 537
							  openfpm::vect_isel<typename T::value_type>::value,
							  layout_base,
							  prp...>(v2);
incardon's avatar
incardon committed
538 539 540 541 542 543 544 545
	}
};

//! Helper class to add data
template<typename op>
struct op_ssend_recv_add
{
	//! Add data
incardon's avatar
incardon committed
546 547 548 549 550 551 552
	template<bool sr,
	         typename T,
			 typename D,
			 typename S,
			 template <typename> class layout_base,
			 int ... prp>
	static void execute(D & recv,S & v2, size_t i)
incardon's avatar
incardon committed
553 554
	{
		// Merge the information
incardon's avatar
incardon committed
555
		op_ssend_recv_add_sr<sr>::template execute<T,D,S,layout_base,prp...>(recv,v2,i);
incardon's avatar
incardon committed
556 557 558 559 560 561 562 563
	}
};

//! Helper class to merge data without serialization
template<bool sr,template<typename,typename> class op>
struct op_ssend_recv_merge_impl
{
	//! Merge the
incardon's avatar
incardon committed
564 565 566 567 568 569
	template<typename T,
	         typename D,
			 typename S,
			 template <typename> class layout_base,
			 int ... prp>
	inline static void execute(D & recv,S & v2,size_t i,openfpm::vector<openfpm::vector<aggregate<size_t,size_t>>> & opart)
incardon's avatar
incardon committed
570 571
	{
		// Merge the information
incardon's avatar
incardon committed
572 573 574 575 576 577
		recv.template merge_prp_v<op,
		                          typename T::value_type,
								  PtrMemory,
								  openfpm::grow_policy_identity,
								  layout_base,
								  prp...>(v2,opart.get(i));
incardon's avatar
incardon committed
578 579 580 581 582 583 584 585
	}
};

//! Helper class to merge data with serialization
template<template<typename,typename> class op>
struct op_ssend_recv_merge_impl<true,op>
{
	//! merge the data
incardon's avatar
incardon committed
586 587 588 589 590 591
	template<typename T,
	         typename D,
			 typename S,
			 template <typename> class layout_base,
			 int ... prp>
	inline static void execute(D & recv,S & v2,size_t i,openfpm::vector<openfpm::vector<aggregate<size_t,size_t>>> & opart)
incardon's avatar
incardon committed
592 593
	{
		// Merge the information
incardon's avatar
incardon committed
594 595 596 597 598 599
		recv.template merge_prp_v<op,
		                          typename T::value_type,
								  HeapMemory,
								  openfpm::grow_policy_double,
								  layout_base,
								  prp...>(v2,opart.get(i));
incardon's avatar
incardon committed
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
	}
};

//! Helper class to merge data
template<template<typename,typename> class op>
struct op_ssend_recv_merge
{
	//! For each processor contain the list of the particles with which I must merge the information
	openfpm::vector<openfpm::vector<aggregate<size_t,size_t>>> & opart;

	//! constructor
	op_ssend_recv_merge(openfpm::vector<openfpm::vector<aggregate<size_t,size_t>>> & opart)
	:opart(opart)
	{}

	//! execute the merge
incardon's avatar
incardon committed
616 617 618 619 620 621 622
	template<bool sr,
	         typename T,
			 typename D,
			 typename S,
			 template <typename> class layout_base,
			 int ... prp>
	void execute(D & recv,S & v2,size_t i)
incardon's avatar
incardon committed
623
	{
incardon's avatar
incardon committed
624
		op_ssend_recv_merge_impl<sr,op>::template execute<T,D,S,layout_base,prp...>(recv,v2,i,opart);
incardon's avatar
incardon committed
625 626 627 628 629 630 631 632
	}
};

//! Helper class to merge data without serialization
template<bool sr>
struct op_ssend_gg_recv_merge_impl
{
	//! Merge the
incardon's avatar
incardon committed
633 634 635 636 637 638
	template<typename T,
	         typename D,
			 typename S,
			 template <typename> class layout_base,
			 int ... prp>
	inline static void execute(D & recv,S & v2,size_t i,size_t & start)
incardon's avatar
incardon committed
639 640
	{
		// Merge the information
incardon's avatar
incardon committed
641 642 643 644 645 646
		recv.template merge_prp_v<replace_,
		                          typename T::value_type,
								  PtrMemory,
								  openfpm::grow_policy_identity,
								  layout_base,
								  prp...>(v2,start);
incardon's avatar
incardon committed
647 648 649 650 651 652 653 654 655 656

		start += v2.size();
	}
};

//! Helper class to merge data with serialization
template<>
struct op_ssend_gg_recv_merge_impl<true>
{
	//! merge the data
incardon's avatar
incardon committed
657 658 659 660 661
	template<typename T,
	         typename D,
			 typename S,
			 template <typename> class layout_base,
			 int ... prp> inline static void execute(D & recv,S & v2,size_t i,size_t & start)
incardon's avatar
incardon committed
662 663
	{
		// Merge the information
incardon's avatar
incardon committed
664 665 666 667 668 669
		recv.template merge_prp_v<replace_,
		                          typename T::value_type,
								  HeapMemory,
								  openfpm::grow_policy_double,
								  layout_base,
								  prp...>(v2,start);
incardon's avatar
incardon committed
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687

		// from
		start += v2.size();
	}
};

//! Helper class to merge data
struct op_ssend_gg_recv_merge
{
	//! starting marker
	size_t start;

	//! constructor
	op_ssend_gg_recv_merge(size_t start)
	:start(start)
	{}

	//! execute the merge
incardon's avatar
incardon committed
688
	template<bool sr, typename T, typename D, typename S, template<typename> class layout_base, int ... prp> void execute(D & recv,S & v2,size_t i)
incardon's avatar
incardon committed
689
	{
incardon's avatar
incardon committed
690
		op_ssend_gg_recv_merge_impl<sr>::template execute<T,D,S,layout_base,prp...>(recv,v2,i,start);
incardon's avatar
incardon committed
691 692 693 694 695 696 697 698
	}
};

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



#endif /* OPENFPM_VCLUSTER_SRC_VCLUSTER_VCLUSTER_META_FUNCTION_HPP_ */