VCluster_base.hpp 34 KB
Newer Older
incardon's avatar
incardon committed
1 2
#ifndef VCLUSTER_BASE_HPP_
#define VCLUSTER_BASE_HPP_
incardon's avatar
incardon committed
3

incardon's avatar
incardon committed
4
#include "util/cuda_util.hpp"
5
#ifdef OPENMPI
incardon's avatar
incardon committed
6
#include <mpi.h>
7 8 9 10
#include <mpi-ext.h>
#else
#include <mpi.h>
#endif
11
#include "MPI_wrapper/MPI_util.hpp"
incardon's avatar
incardon committed
12
#include "Vector/map_vector.hpp"
13 14 15
#include "MPI_wrapper/MPI_IallreduceW.hpp"
#include "MPI_wrapper/MPI_IrecvW.hpp"
#include "MPI_wrapper/MPI_IsendW.hpp"
incardon's avatar
incardon committed
16
#include "MPI_wrapper/MPI_IAllGather.hpp"
incardon's avatar
incardon committed
17
#include "MPI_wrapper/MPI_IBcastW.hpp"
incardon's avatar
incardon committed
18
#include <exception>
19
#include "Vector/map_vector.hpp"
20 21
#ifdef DEBUG
#include "util/check_no_pointers.hpp"
22
#include "util/util_debug.hpp"
23
#endif
incardon's avatar
incardon committed
24
#include "util/Vcluster_log.hpp"
25
#include "memory/BHeapMemory.hpp"
26
#include "Packer_Unpacker/has_max_prop.hpp"
incardon's avatar
incardon committed
27
#include "data_type/aggregate.hpp"
28 29 30
#if defined(CUDA_GPU) && defined(__NVCC__)
#include "util/cuda/moderngpu/launch_box.hxx"
#endif
31
#include "util/cuda/ofp_context.hxx"
incardon's avatar
incardon committed
32

Pietro Incardona's avatar
Pietro Incardona committed
33 34 35 36
#ifdef HAVE_PETSC
#include <petscvec.h>
#endif

incardon's avatar
incardon committed
37 38
#define MSG_LENGTH 1024
#define MSG_SEND_RECV 1025
39
#define SEND_SPARSE 8192
incardon's avatar
incardon committed
40 41 42
#define NONE 1
#define NEED_ALL_SIZE 2

43
#define SERIVCE_MESSAGE_TAG 16384
44
#define SEND_RECV_BASE 4096
incardon's avatar
incardon committed
45
#define GATHER_BASE 24576
incardon's avatar
incardon committed
46

47 48
#define RECEIVE_KNOWN 4
#define KNOWN_ELEMENT_OR_BYTE 8
49
#define MPI_GPU_DIRECT 16
50

51
// number of vcluster instances
incardon's avatar
incardon committed
52
extern size_t n_vcluster;
53
// Global MPI initialization
incardon's avatar
incardon committed
54
extern bool global_mpi_init;
Pietro Incardona's avatar
Pietro Incardona committed
55 56
// initialization flag
extern bool ofp_initialized;
incardon's avatar
incardon committed
57 58
extern size_t tot_sent;
extern size_t tot_recv;
incardon's avatar
incardon committed
59

incardon's avatar
incardon committed
60 61 62 63 64 65 66 67
///////////////////// Post functions /////////////

template<typename T> void assign(T * ptr1, T * ptr2)
{
	*ptr1 = *ptr2;
};


incardon's avatar
incardon committed
68
//! temporal buffer for reductions
incardon's avatar
incardon committed
69 70
union red
{
incardon's avatar
incardon committed
71
	//! char
incardon's avatar
incardon committed
72
	char c;
incardon's avatar
incardon committed
73
	//! unsigned char
incardon's avatar
incardon committed
74
	unsigned char uc;
incardon's avatar
incardon committed
75
	//! signed
incardon's avatar
incardon committed
76
	short s;
incardon's avatar
incardon committed
77
	//! unsigned short
incardon's avatar
incardon committed
78
	unsigned short us;
incardon's avatar
incardon committed
79
	//! integer
incardon's avatar
incardon committed
80
	int i;
incardon's avatar
incardon committed
81
	//! unsigned integer
incardon's avatar
incardon committed
82
	unsigned int ui;
incardon's avatar
incardon committed
83
	//! float
incardon's avatar
incardon committed
84
	float f;
incardon's avatar
incardon committed
85
	//! double
incardon's avatar
incardon committed
86 87 88
	double d;
};

89
/*! \brief This class virtualize the cluster of PC as a set of processes that communicate
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
 * At the moment it is an MPI-like interface, with a more type aware, and simple, interface.
 *  It also give some more complex communication functionalities like **Dynamic Sparse Data Exchange**
 *
 * Actually VCluster expose a Computation driven parallelism (MPI-like), with a plan of extending to
 * communication driven parallelism
 *
 * * In computation driven parallelism, the program compute than communicate to the other processors
 *
 * * In a communication driven parallelism, (Charm++ or HPX), the program receive messages, this receiving
 *   messages trigger computation
 *
 * ### An example of sending and receive plain buffers
 * \snippet VCluster_unit_test_util.hpp Send and receive plain buffer data
 * ### An example of sending vectors of primitives with (T=float,double,lont int,...)
 * \snippet VCluster_unit_test_util.hpp Sending and receiving primitives
 * ### An example of sending vectors of complexes object
 * \snippet VCluster_unit_test_util.hpp Send and receive vectors of complex
 * ### An example of gathering numbers from all processors
 * \snippet VCluster_unit_test_util.hpp allGather numbers
incardon's avatar
incardon committed
110 111
 *
 */
112
template<typename InternalMemory>
incardon's avatar
incardon committed
113
class Vcluster_base
incardon's avatar
incardon committed
114
{
incardon's avatar
incardon committed
115
	//! log file
incardon's avatar
incardon committed
116 117
	Vcluster_log log;

118 119 120
	//! NBX has a potential pitfall that must be addressed,
	//! NBX Send all the messages and probe for incoming messages,
	//! if there is an incoming message it receive it producing
121
	//! an acknowledge notification on the sending processor.
122 123 124 125 126 127
	//! When all the sends has been acknowledged, the processor call the MPI_Ibarrier
	//! when all the processors call MPI_Ibarrier all send has been received.
	//! While the processors are waiting for the MPI_Ibarrier to complete, all processors
	//! are still probing for incoming message, Unfortunately some processor
	//! can quit the MPI_Ibarrier before others and this mean that some
	//! processor can exit the probing status before others, these processors can in theory
128 129 130 131
	//! start new communications while the other processor are still in probing status producing
	//! a wrong send/recv association to
	//! resolve this problem an incremental NBX_cnt is used as message TAG to distinguish that the
	//! messages come from other send or subsequent NBX procedures
incardon's avatar
incardon committed
132
	size_t NBX_cnt;
133

incardon's avatar
incardon committed
134 135
	//! temporal vector used for meta-communication
	//! ( or meta-data before the real communication )
incardon's avatar
incardon committed
136 137
	openfpm::vector<size_t> proc_com;

incardon's avatar
incardon committed
138
	//! vector that contain the scatter map (it is basically an array of one)
incardon's avatar
incardon committed
139 140
	openfpm::vector<int> map_scatter;

incardon's avatar
incardon committed
141
	//! vector of MPI requests
incardon's avatar
incardon committed
142 143
	openfpm::vector<MPI_Request> req;

incardon's avatar
incardon committed
144
	//! vector of MPI status
incardon's avatar
incardon committed
145 146
	openfpm::vector<MPI_Status> stat;

incardon's avatar
incardon committed
147
	//! vector of functions to execute after all the request has been performed
incardon's avatar
incardon committed
148 149
	std::vector<int> post_exe;

incardon's avatar
incardon committed
150
	//! standard context for mgpu (if cuda is detected otherwise is unused)
151
	mgpu::ofp_context_t * context;
152 153


incardon's avatar
incardon committed
154 155 156 157 158
	// Object array


	// Single objects

incardon's avatar
incardon committed
159
	//! number of processes
incardon's avatar
incardon committed
160
	int m_size;
incardon's avatar
incardon committed
161
	//! actual rank
incardon's avatar
incardon committed
162
	int m_rank;
incardon's avatar
incardon committed
163

incardon's avatar
incardon committed
164
	//! number of processing unit per process
incardon's avatar
incardon committed
165 166
	int numPE = 1;

incardon's avatar
incardon committed
167
	/*! This buffer is a temporal buffer for reductions
incardon's avatar
incardon committed
168 169 170 171 172 173 174 175
	 *
	 * MPI_Iallreduce does not accept recv and send buffer to be the same
	 * r is used to overcome this problem (is given as second parameter)
	 * after the execution the data is copied back
	 *
	 */
	std::vector<red> r;

incardon's avatar
incardon committed
176
	//! vector of pointers of send buffers
177 178
	openfpm::vector<void *> ptr_send;

incardon's avatar
incardon committed
179
	//! vector of the size of send buffers
180 181
	openfpm::vector<size_t> sz_send;

incardon's avatar
incardon committed
182
	//! barrier request
183
	MPI_Request bar_req;
incardon's avatar
incardon committed
184 185

	//! barrier status
186 187
	MPI_Status bar_stat;

incardon's avatar
incardon committed
188
	//! disable operator=
incardon's avatar
incardon committed
189
	Vcluster_base & operator=(const Vcluster_base &)	{return *this;};
Pietro Incardona's avatar
Pietro Incardona committed
190

191 192 193
	//! rank within the node
	int shmrank;

incardon's avatar
incardon committed
194
	//! disable copy constructor
incardon's avatar
incardon committed
195
	Vcluster_base(const Vcluster_base &)
incardon's avatar
incardon committed
196 197
	:NBX_cnt(0)
	{};
Pietro Incardona's avatar
Pietro Incardona committed
198

incardon's avatar
incardon committed
199 200 201
protected:

	//! Receive buffers
incardon's avatar
incardon committed
202
	openfpm::vector_fr<BMemory<InternalMemory>> recv_buf;
incardon's avatar
incardon committed
203

incardon's avatar
incardon committed
204 205 206
	//! tags receiving
	openfpm::vector<size_t> tags;

incardon's avatar
incardon committed
207 208 209
public:

	// Finalize the MPI program
incardon's avatar
incardon committed
210
	~Vcluster_base()
incardon's avatar
incardon committed
211
	{
212 213 214
#ifdef SE_CLASS2
		check_delete(this);
#endif
incardon's avatar
incardon committed
215 216 217 218
		n_vcluster--;

		// if there are no other vcluster instances finalize
		if (n_vcluster == 0)
219
		{
220 221 222 223
			int already_finalised;

			MPI_Finalized(&already_finalised);
			if (!already_finalised)
224
			{
225 226 227 228
				if (MPI_Finalize() != 0)
				{
					std::cerr << __FILE__ << ":" << __LINE__  << " MPI_Finalize FAILED \n";
				}
229
			}
230
		}
231 232

		delete context;
incardon's avatar
incardon committed
233 234
	}

235 236 237 238 239 240
	/*! \brief Virtual cluster constructor
	 *
	 * \param argc pointer to arguments counts passed to the program
	 * \param argv pointer to arguments vector passed to the program
	 *
	 */
incardon's avatar
incardon committed
241
	Vcluster_base(int *argc, char ***argv)
incardon's avatar
incardon committed
242
	:NBX_cnt(0)
incardon's avatar
incardon committed
243
	{
244 245 246 247
#ifdef SE_CLASS2
		check_new(this,8,VCLUSTER_EVENT,PRJ_VCLUSTER);
#endif

incardon's avatar
incardon committed
248 249
		n_vcluster++;

250 251 252
		int already_initialised;
		MPI_Initialized(&already_initialised);

incardon's avatar
incardon committed
253
		// Check if MPI is already initialized
254
		if (!already_initialised)
incardon's avatar
incardon committed
255 256
		{
			MPI_Init(argc,argv);
incardon's avatar
incardon committed
257
		}
258

incardon's avatar
incardon committed
259
		// We try to get the local processors rank
260

incardon's avatar
incardon committed
261 262 263
		MPI_Comm shmcomm;
		MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, 0,
		                    MPI_INFO_NULL, &shmcomm);
264

incardon's avatar
incardon committed
265 266
		MPI_Comm_rank(shmcomm, &shmrank);
		MPI_Comm_free(&shmcomm);
incardon's avatar
incardon committed
267

268 269
		// Get the total number of process
		// and the rank of this process
incardon's avatar
incardon committed
270

incardon's avatar
incardon committed
271 272
		MPI_Comm_size(MPI_COMM_WORLD, &m_size);
		MPI_Comm_rank(MPI_COMM_WORLD, &m_rank);
incardon's avatar
incardon committed
273

274
#ifdef SE_CLASS2
incardon's avatar
incardon committed
275
			process_v_cl = m_rank;
incardon's avatar
incardon committed
276 277
#endif

278
		// create and fill map scatter with one
incardon's avatar
incardon committed
279
		map_scatter.resize(m_size);
incardon's avatar
incardon committed
280 281 282 283 284

		for (size_t i = 0 ; i < map_scatter.size() ; i++)
		{
			map_scatter.get(i) = 1;
		}
incardon's avatar
incardon committed
285 286

		// open the log file
incardon's avatar
incardon committed
287
		log.openLog(m_rank);
288 289 290 291

		// Initialize bar_req
		bar_req = MPI_Request();
		bar_stat = MPI_Status();
292

293 294 295 296 297 298 299 300
#ifdef EXTERNAL_SET_GPU
                int dev;
                cudaGetDevice(&dev);
                context = new mgpu::ofp_context_t(mgpu::gpu_context_opt::no_print_props,dev);
#else
                context = new mgpu::ofp_context_t(mgpu::gpu_context_opt::no_print_props,shmrank);
#endif

301

incardon's avatar
incardon committed
302 303 304 305
#if defined(PRINT_RANK_TO_GPU) && defined(CUDA_GPU)

                char node_name[MPI_MAX_PROCESSOR_NAME];
                int len;
306

incardon's avatar
incardon committed
307
                MPI_Get_processor_name(node_name,&len);
308

incardon's avatar
incardon committed
309
                std::cout << "Rank: " << m_rank << " on host: " << node_name << " work on GPU: " << context->getDevice() << "/" << context->getNDevice() << std::endl;
310
#endif
incardon's avatar
incardon committed
311 312
	}

incardon's avatar
incardon committed
313
#ifdef SE_CLASS1
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329

	/*! \brief Check for wrong types
	 *
	 * In general we do not know if a type T make sense to be sent or not, but if it has pointer
	 * inside it does not. This function check if the basic type T has a method called noPointers,
	 * This function in general notify if T has internally pointers. If T has pointer an error
	 * is printed, is T does not have the method a WARNING is printed
	 *
	 * \tparam T type to check
	 *
	 */
	template<typename T> void checkType()
	{
		// if T is a primitive like int, long int, float, double, ... make sense
		// (pointers, l-references and r-references are not fundamentals)
		if (std::is_fundamental<T>::value == true)
incardon's avatar
incardon committed
330
		{return;}
331 332 333

		// if it is a pointer make no sense
		if (std::is_pointer<T>::value == true)
incardon's avatar
incardon committed
334
		{std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " the type " << demangle(typeid(T).name()) << " is a pointer, sending pointers values has no sense\n";}
335 336 337

		// if it is an l-value reference make no send
		if (std::is_lvalue_reference<T>::value == true)
incardon's avatar
incardon committed
338
		{std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " the type " << demangle(typeid(T).name()) << " is a pointer, sending pointers values has no sense\n";}
339 340 341

		// if it is an r-value reference make no send
		if (std::is_rvalue_reference<T>::value == true)
incardon's avatar
incardon committed
342
		{std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " the type " << demangle(typeid(T).name()) << " is a pointer, sending pointers values has no sense\n";}
343 344 345 346 347 348

		// ... if not, check that T has a method called noPointers
		switch (check_no_pointers<T>::value())
		{
			case PNP::UNKNOWN:
			{
incardon's avatar
incardon committed
349
				std::cerr << "Warning: " << __FILE__ << ":" << __LINE__ << " impossible to check the type " << demangle(typeid(T).name()) << " please consider to add a static method \"static bool noPointers()\" \n" ;
350 351 352 353 354 355 356 357 358 359 360 361 362 363
				break;
			}
			case PNP::POINTERS:
			{
				std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " the type " << demangle(typeid(T).name()) << " has pointers inside, sending pointers values has no sense\n";
				break;
			}
			default:
			{

			}
		}
	}

364 365 366 367
#endif

	/*! \brief If nvidia cuda is activated return a mgpu context
	 *
incardon's avatar
incardon committed
368
	 * \param iw ignore warning
369 370
	 *
	 */
371
	mgpu::ofp_context_t & getmgpuContext(bool iw = true)
372
	{
incardon's avatar
incardon committed
373
		if (context == NULL && iw == true)
374
		{
incardon's avatar
incardon committed
375
			std::cout << __FILE__ << ":" << __LINE__ << " Warning: it seem that modern gpu context is not initialized."
376 377 378
					                                    "Either a compatible working cuda device has not been found, either openfpm_init has been called in a file that not compiled with NVCC" << std::endl;
		}

379 380 381
		return *context;
	}

Pietro Incardona's avatar
Pietro Incardona committed
382 383 384 385 386 387 388 389 390 391
	/*! \brief Get the MPI_Communicator (or processor group) this VCluster is using
	 *
	 * \return MPI comunicator
	 *
	 */
	MPI_Comm getMPIComm()
	{
		return MPI_COMM_WORLD;
	}

incardon's avatar
incardon committed
392 393 394 395 396
	/*! \brief Get the total number of processors
	 *
	 * \return the total number of processors
	 *
	 */
incardon's avatar
incardon committed
397 398
	size_t getProcessingUnits()
	{
incardon's avatar
incardon committed
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
		return m_size*numPE;
	}

	/*! \brief Get the total number of processors
	 *
	 * It is the same as getProcessingUnits()
	 *
	 * \see getProcessingUnits()
	 *
	 * \return the total number of processors
	 *
	 */
	size_t size()
	{
		return this->m_size*numPE;
incardon's avatar
incardon committed
414 415
	}

incardon's avatar
incardon committed
416 417 418 419 420
	/*! \brief Get the process unit id
	 *
	 * \return the process ID
	 *
	 */
incardon's avatar
incardon committed
421 422
	size_t getProcessUnitID()
	{
incardon's avatar
incardon committed
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
		return m_rank;
	}

	/*! \brief Get the process unit id
	 *
	 * It is the same as getProcessUnitID()
	 *
	 * \see getProcessUnitID()
	 *
	 * \return the process ID
	 *
	 */
	size_t rank()
	{
		return m_rank;
incardon's avatar
incardon committed
438 439
	}

incardon's avatar
incardon committed
440

441
	/*! \brief Sum the numbers across all processors and get the result
incardon's avatar
incardon committed
442 443 444 445 446
	 *
	 * \param num to reduce, input and output
	 *
	 */

447
	template<typename T> void sum(T & num)
incardon's avatar
incardon committed
448
	{
incardon's avatar
incardon committed
449
#ifdef SE_CLASS1
450 451 452
		checkType<T>();
#endif

incardon's avatar
incardon committed
453 454 455 456 457 458 459 460 461
		// reduce over MPI

		// Create one request
		req.add();

		// reduce
		MPI_IallreduceW<T>::reduce(num,MPI_SUM,req.last());
	}

462
	/*! \brief Get the maximum number across all processors (or reduction with infinity norm)
incardon's avatar
incardon committed
463 464 465 466 467 468
	 *
	 * \param num to reduce
	 *
	 */
	template<typename T> void max(T & num)
	{
incardon's avatar
incardon committed
469
#ifdef SE_CLASS1
470 471
		checkType<T>();
#endif
incardon's avatar
incardon committed
472 473 474 475 476 477 478 479 480
		// reduce over MPI

		// Create one request
		req.add();

		// reduce
		MPI_IallreduceW<T>::reduce(num,MPI_MAX,req.last());
	}

tonynsyde's avatar
tonynsyde committed
481 482 483 484 485 486 487 488
	/*! \brief Get the minimum number across all processors (or reduction with insinity norm)
	 *
	 * \param num to reduce
	 *
	 */

	template<typename T> void min(T & num)
	{
incardon's avatar
incardon committed
489
#ifdef SE_CLASS1
tonynsyde's avatar
tonynsyde committed
490 491 492 493 494 495 496 497 498 499 500
		checkType<T>();
#endif
		// reduce over MPI

		// Create one request
		req.add();

		// reduce
		MPI_IallreduceW<T>::reduce(num,MPI_MIN,req.last());
	}

501
	/*! \brief Send and receive multiple messages
502
	 *
503 504
	 * It send multiple messages to a set of processors the and receive
	 * multiple messages from another set of processors, all the processor must call this
505 506 507
	 * function. In this particular case the receiver know from which processor is going
	 * to receive.
	 *
508 509
	 *
	 * suppose the following situation the calling processor want to communicate
510 511 512 513
	 * * 2 messages of size 100 byte to processor 1
	 * * 1 message of size 50 byte to processor 6
	 * * 1 message of size 48 byte to processor 7
	 * * 1 message of size 70 byte to processor 8
514 515
	 *
	 *
516 517
	 * \param prc list of processor with which it should communicate
	 *        [1,1,6,7,8]
518
	 *
incardon's avatar
incardon committed
519 520 521 522
	 * \param data data to send for each processors in contain a pointer to some type T
	 *        this type T must have a method size() that return the size of the data-structure
	 *
	 * \param prc_recv processor that receive data
523
	 *
incardon's avatar
incardon committed
524
	 * \param recv_sz for each processor indicate the size of the data received
525 526 527
	 *
	 * \param msg_alloc This is a call-back with the purpose of allocate space
	 *        for the incoming message and give back a valid pointer, supposing that this call-back has been triggered by
528 529
	 *        the processor of id 5 that want to communicate with me a message of size 100 byte the call-back will have
	 *        the following 6 parameters
530 531
	 *        in the call-back are in order:
	 *        * message size required to receive the message [100]
532 533
	 *        * total message size to receive from all the processors (NBX does not provide this information)
	 *        * the total number of processor want to communicate with you (NBX does not provide this information)
534
	 *        * processor id [5]
535
	 *        * ri request id (it is an id that goes from 0 to total_p, and is incremented
536
	 *           every time message_alloc is called)
537
	 *        * void pointer, parameter for additional data to pass to the call-back
538
	 *
incardon's avatar
incardon committed
539 540
	 * \param ptr_arg data passed to the call-back function specified
	 *
541
	 * \param opt options, NONE (ignored in this moment)
542 543
	 *
	 */
incardon's avatar
incardon committed
544 545 546 547
	template<typename T> void sendrecvMultipleMessagesNBX(openfpm::vector< size_t > & prc,
			                                              openfpm::vector< T > & data,
														  openfpm::vector< size_t > prc_recv,
														  openfpm::vector< size_t > & recv_sz ,
incardon's avatar
incardon committed
548
														  void * (* msg_alloc)(size_t,size_t,size_t,size_t,size_t,size_t,void *),
incardon's avatar
incardon committed
549 550
														  void * ptr_arg,
														  long int opt=NONE)
551
	{
552
		// Allocate the buffers
553 554

		for (size_t i = 0 ; i < prc.size() ; i++)
555
		{send(prc.get(i),SEND_SPARSE + NBX_cnt*131072,data.get(i).getPointer(),data.get(i).size());}
556 557

		for (size_t i = 0 ; i < prc_recv.size() ; i++)
558
		{
559
			void * ptr_recv = msg_alloc(recv_sz.get(i),0,0,prc_recv.get(i),i,SEND_SPARSE + NBX_cnt*131072,ptr_arg);
560

561
			recv(prc_recv.get(i),SEND_SPARSE + NBX_cnt*131072,ptr_recv,recv_sz.get(i));
562 563
		}

564 565 566
		execute();

		// Circular counter
567
		NBX_cnt = (NBX_cnt + 1) % 2048;
568 569
	}

incardon's avatar
incardon committed
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608

	/*! \brief Send and receive multiple messages
	 *
	 * It send multiple messages to a set of processors the and receive
	 * multiple messages from another set of processors, all the processor must call this
	 * function
	 *
	 * suppose the following situation the calling processor want to communicate
	 * * 2 vector of 100 integers to processor 1
	 * * 1 vector of 50 integers to processor 6
	 * * 1 vector of 48 integers to processor 7
	 * * 1 vector of 70 integers to processor 8
	 *
	 * \param prc list of processors you should communicate with [1,1,6,7,8]
	 *
	 * \param data vector containing the data to send [v=vector<vector<int>>, v.size()=4, T=vector<int>], T at the moment
	 *          is only tested for vectors of 0 or more generic elements (without pointers)
	 *
	 * \param msg_alloc This is a call-back with the purpose to allocate space
	 *        for the incoming messages and give back a valid pointer, supposing that this call-back has been triggered by
	 *        the processor of id 5 that want to communicate with me a message of size 100 byte the call-back will have
	 *        the following 6 parameters
	 *        in the call-back in order:
	 *        * message size required to receive the message (100)
	 *        * total message size to receive from all the processors (NBX does not provide this information)
	 *        * the total number of processor want to communicate with you (NBX does not provide this information)
	 *        * processor id (5)
	 *        * ri request id (it is an id that goes from 0 to total_p, and is incremented
	 *           every time message_alloc is called)
	 *        * void pointer, parameter for additional data to pass to the call-back
	 *
	 * \param ptr_arg data passed to the call-back function specified
	 *
	 * \param opt options, only NONE supported
	 *
	 */
	template<typename T>
	void sendrecvMultipleMessagesNBX(openfpm::vector< size_t > & prc,
									 openfpm::vector< T > & data,
609
									 void * (* msg_alloc)(size_t,size_t,size_t,size_t,size_t,size_t,void *),
incardon's avatar
incardon committed
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
									 void * ptr_arg, long int opt=NONE)
	{
#ifdef SE_CLASS1
		checkType<typename T::value_type>();
#endif
		// resize the pointer list
		ptr_send.resize(prc.size());
		sz_send.resize(prc.size());

		for (size_t i = 0 ; i < prc.size() ; i++)
		{
			ptr_send.get(i) = data.get(i).getPointer();
			sz_send.get(i) = data.get(i).size() * sizeof(typename T::value_type);
		}

		sendrecvMultipleMessagesNBX(prc.size(),(size_t *)sz_send.getPointer(),(size_t *)prc.getPointer(),(void **)ptr_send.getPointer(),msg_alloc,ptr_arg,opt);
	}

628 629 630 631 632 633 634
	/*! \brief Send and receive multiple messages
	 *
	 * It send multiple messages to a set of processors the and receive
	 * multiple messages from another set of processors, all the processor must call this
	 * function. In this particular case the receiver know from which processor is going
	 * to receive.
	 *
635
	 * \warning this function only work with one send for each processor
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
	 *
	 * suppose the following situation the calling processor want to communicate
	 * * 2 messages of size 100 byte to processor 1
	 * * 1 message of size 50 byte to processor 6
	 * * 1 message of size 48 byte to processor 7
	 * * 1 message of size 70 byte to processor 8
	 *
	 * \param n_send number of send for this processor [4]
	 *
	 * \param prc list of processor with which it should communicate
	 *        [1,1,6,7,8]
	 *
	 * \param sz the array contain the size of the message for each processor
	 *        (zeros must not be presents) [100,100,50,48,70]
	 *
	 * \param ptr array that contain the pointers to the message to send
	 *
	 * \param msg_alloc This is a call-back with the purpose of allocate space
	 *        for the incoming message and give back a valid pointer, supposing that this call-back has been triggered by
	 *        the processor of id 5 that want to communicate with me a message of size 100 byte the call-back will have
	 *        the following 6 parameters
	 *        in the call-back are in order:
	 *        * message size required to receive the message [100]
	 *        * total message size to receive from all the processors (NBX does not provide this information)
	 *        * the total number of processor want to communicate with you (NBX does not provide this information)
	 *        * processor id [5]
	 *        * ri request id (it is an id that goes from 0 to total_p, and is incremented
	 *           every time message_alloc is called)
	 *        * void pointer, parameter for additional data to pass to the call-back
	 *
	 * \param ptr_arg data passed to the call-back function specified
	 *
	 * \param opt options, NONE (ignored in this moment)
	 *
	 */
incardon's avatar
incardon committed
671 672 673 674 675
	void sendrecvMultipleMessagesNBX(size_t n_send , size_t sz[],
			                         size_t prc[] , void * ptr[],
			                         size_t n_recv, size_t prc_recv[] ,
			                         size_t sz_recv[] ,void * (* msg_alloc)(size_t,size_t,size_t,size_t,size_t, size_t,void *),
			                         void * ptr_arg, long int opt=NONE)
676 677 678 679
	{
		// Allocate the buffers

		for (size_t i = 0 ; i < n_send ; i++)
680
		{send(prc[i],SEND_SPARSE + NBX_cnt*131072,ptr[i],sz[i]);}
681 682 683

		for (size_t i = 0 ; i < n_recv ; i++)
		{
684
			void * ptr_recv = msg_alloc(sz_recv[i],0,0,prc_recv[i],i,SEND_SPARSE + NBX_cnt*131072,ptr_arg);
685

686
			recv(prc_recv[i],SEND_SPARSE + NBX_cnt*131072,ptr_recv,sz_recv[i]);
687 688 689 690 691
		}

		execute();

		// Circular counter
692
		NBX_cnt = (NBX_cnt + 1) % 2048;
693 694
	}

incardon's avatar
incardon committed
695 696
	openfpm::vector<size_t> sz_recv_tmp;

incardon's avatar
incardon committed
697 698
	/*! \brief Send and receive multiple messages
	 *
699
	 * It send multiple messages to a set of processors the and receive
700
	 * multiple messages from another set of processors, all the processor must call this
incardon's avatar
incardon committed
701 702 703
	 * function. In this particular case the receiver know from which processor is going
	 * to receive, but does not know the size.
	 *
704 705
	 *
	 * suppose the following situation the calling processor want to communicate
incardon's avatar
incardon committed
706 707 708 709
	 * * 2 messages of size 100 byte to processor 1
	 * * 1 message of size 50 byte to processor 6
	 * * 1 message of size 48 byte to processor 7
	 * * 1 message of size 70 byte to processor 8
710
	 *
incardon's avatar
incardon committed
711
	 * \param n_send number of send for this processor [4]
712
	 *
incardon's avatar
incardon committed
713 714
	 * \param prc list of processor with which it should communicate
	 *        [1,1,6,7,8]
715
	 *
incardon's avatar
incardon committed
716 717 718 719 720 721 722
	 * \param sz the array contain the size of the message for each processor
	 *        (zeros must not be presents) [100,100,50,48,70]
	 *
	 * \param ptr array that contain the pointers to the message to send
	 *
	 * \param msg_alloc This is a call-back with the purpose of allocate space
	 *        for the incoming message and give back a valid pointer, supposing that this call-back has been triggered by
723 724
	 *        the processor of id 5 that want to communicate with me a message of size 100 byte the call-back will have
	 *        the following 6 parameters
incardon's avatar
incardon committed
725 726
	 *        in the call-back are in order:
	 *        * message size required to receive the message [100]
727 728
	 *        * total message size to receive from all the processors (NBX does not provide this information)
	 *        * the total number of processor want to communicate with you (NBX does not provide this information)
incardon's avatar
incardon committed
729
	 *        * processor id [5]
730
	 *        * ri request id (it is an id that goes from 0 to total_p, and is incremented
731
	 *           every time message_alloc is called)
732
	 *        * void pointer, parameter for additional data to pass to the call-back
incardon's avatar
incardon committed
733
	 *
incardon's avatar
incardon committed
734 735
	 * \param ptr_arg data passed to the call-back function specified
	 *
incardon's avatar
incardon committed
736
	 * \param opt options, NONE (ignored in this moment)
incardon's avatar
incardon committed
737 738
	 *
	 */
739 740 741 742
	void sendrecvMultipleMessagesNBX(size_t n_send , size_t sz[], size_t prc[] ,
									 void * ptr[], size_t n_recv, size_t prc_recv[] ,
									 void * (* msg_alloc)(size_t,size_t,size_t,size_t,size_t,size_t,void *),
									 void * ptr_arg, long int opt=NONE)
incardon's avatar
incardon committed
743
	{
incardon's avatar
incardon committed
744
		sz_recv_tmp.resize(n_recv);
incardon's avatar
incardon committed
745

incardon's avatar
incardon committed
746 747 748
		// First we understand the receive size for each processor

		for (size_t i = 0 ; i < n_send ; i++)
749
		{send(prc[i],SEND_SPARSE + NBX_cnt*131072,&sz[i],sizeof(size_t));}
incardon's avatar
incardon committed
750 751

		for (size_t i = 0 ; i < n_recv ; i++)
752
		{recv(prc_recv[i],SEND_SPARSE + NBX_cnt*131072,&sz_recv_tmp.get(i),sizeof(size_t));}
incardon's avatar
incardon committed
753 754 755 756

		execute();

		// Circular counter
757
		NBX_cnt = (NBX_cnt + 1) % 2048;
incardon's avatar
incardon committed
758 759 760 761

		// Allocate the buffers

		for (size_t i = 0 ; i < n_send ; i++)
762
		{send(prc[i],SEND_SPARSE + NBX_cnt*131072,ptr[i],sz[i]);}
incardon's avatar
incardon committed
763 764

		for (size_t i = 0 ; i < n_recv ; i++)
incardon's avatar
incardon committed
765
		{
766
			void * ptr_recv = msg_alloc(sz_recv_tmp.get(i),0,0,prc_recv[i],i,0,ptr_arg);
incardon's avatar
incardon committed
767

768
			recv(prc_recv[i],SEND_SPARSE + NBX_cnt*131072,ptr_recv,sz_recv_tmp.get(i));
incardon's avatar
incardon committed
769
		}
770

incardon's avatar
incardon committed
771
		execute();
772

incardon's avatar
incardon committed
773
		// Circular counter
774
		NBX_cnt = (NBX_cnt + 1) % 2048;
incardon's avatar
incardon committed
775
	}
776

777
	/*! \brief Send and receive multiple messages
778
	 *
779 780
	 * It send multiple messages to a set of processors the and receive
	 * multiple messages from another set of processors, all the processor must call this
781
	 * function
782
	 *
783 784 785 786 787
	 * suppose the following situation the calling processor want to communicate
	 * * 2 messages of size 100 byte to processor 1
	 * * 1 message of size 50 byte to processor 6
	 * * 1 message of size 48 byte to processor 7
	 * * 1 message of size 70 byte to processor 8
788
	 *
789
	 * \param n_send number of send for this processor [4]
790 791
	 *
	 * \param prc list of processor with which it should communicate
792
	 *        [1,1,6,7,8]
793
	 *
794 795 796 797
	 * \param sz the array contain the size of the message for each processor
	 *        (zeros must not be presents) [100,100,50,48,70]
	 *
	 * \param ptr array that contain the pointers to the message to send
798 799
	 *
	 * \param msg_alloc This is a call-back with the purpose of allocate space
800 801 802
	 *        for the incoming message and give back a valid pointer, supposing that this call-back has been triggered by
	 *        the processor of id 5 that want to communicate with me a message of size 100 byte the call-back will have
	 *        the following 6 parameters
803
	 *        in the call-back are in order:
804 805 806 807 808
	 *        * message size required to receive the message [100]
	 *        * total message size to receive from all the processors (NBX does not provide this information)
	 *        * the total number of processor want to communicate with you (NBX does not provide this information)
	 *        * processor id [5]
	 *        * ri request id (it is an id that goes from 0 to total_p, and is incremented
809
	 *           every time message_alloc is called)
810
	 *        * void pointer, parameter for additional data to pass to the call-back
811
	 *
incardon's avatar
incardon committed
812 813
	 * \param ptr_arg data passed to the call-back function specified
	 *
814 815 816
	 * \param opt options, NONE (ignored in this moment)
	 *
	 */
incardon's avatar
incardon committed
817 818 819 820
	void sendrecvMultipleMessagesNBX(size_t n_send , size_t sz[],
			                         size_t prc[] , void * ptr[],
			                         void * (* msg_alloc)(size_t,size_t,size_t,size_t,size_t,size_t,void *),
			                         void * ptr_arg, long int opt = NONE)
821
	{
822
		if (stat.size() != 0 || req.size() != 0)
incardon's avatar
incardon committed
823
			std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " this function must be called when no other requests are in progress. Please remember that if you use function like max(),sum(),send(),recv() check that you did not miss to call the function execute() \n";
824 825 826


		stat.clear();
827 828 829 830 831
		req.clear();
		// Do MPI_Issend

		for (size_t i = 0 ; i < n_send ; i++)
		{
incardon's avatar
incardon committed
832 833 834
			if (sz[i] != 0)
			{
				req.add();
835 836 837 838 839

#ifdef SE_CLASS2
				check_valid(ptr[i],sz[i]);
#endif

incardon's avatar
incardon committed
840
				tot_sent += sz[i];
incardon's avatar
incardon committed
841
				MPI_SAFE_CALL(MPI_Issend(ptr[i], sz[i], MPI_BYTE, prc[i], SEND_SPARSE + NBX_cnt*131072 + i, MPI_COMM_WORLD,&req.last()));
incardon's avatar
incardon committed
842
				log.logSend(prc[i]);
incardon's avatar
incardon committed
843
			}
844 845 846 847 848 849 850
		}

		size_t rid = 0;
		int flag = false;

		bool reached_bar_req = false;

incardon's avatar
incardon committed
851 852
		log.start(10);

853 854 855
		// Wait that all the send are acknowledge
		do
		{
incardon's avatar
incardon committed
856

857 858 859 860 861
			// flag that notify that this processor reach the barrier
			// Barrier request

			MPI_Status stat_t;
			int stat = false;
incardon's avatar
incardon committed
862
			MPI_SAFE_CALL(MPI_Iprobe(MPI_ANY_SOURCE,MPI_ANY_TAG/*SEND_SPARSE + NBX_cnt*/,MPI_COMM_WORLD,&stat,&stat_t));
863

864
			// If I have an incoming message and is related to this NBX communication
865 866 867
			if (stat == true)
			{
				int msize;
incardon's avatar
incardon committed
868 869

				// Get the message tag and size
870 871
				MPI_SAFE_CALL(MPI_Get_count(&stat_t,MPI_BYTE,&msize));

incardon's avatar
incardon committed
872 873 874 875 876
				// Ok we check if the TAG come from one of our send TAG
				if (stat_t.MPI_TAG >= (int)(SEND_SPARSE + NBX_cnt*131072) && stat_t.MPI_TAG < (int)(SEND_SPARSE + (NBX_cnt + 1)*131072))
				{
					// Get the pointer to receive the message
					void * ptr = msg_alloc(msize,0,0,stat_t.MPI_SOURCE,rid,stat_t.MPI_TAG,ptr_arg);
877

incardon's avatar
incardon committed
878 879
					// Log the receiving request
					log.logRecv(stat_t);
incardon's avatar
incardon committed
880

incardon's avatar
incardon committed
881
					rid++;
882

incardon's avatar
incardon committed
883
					// Check the pointer
884
#ifdef SE_CLASS2
incardon's avatar
incardon committed
885
					check_valid(ptr,msize);
886
#endif
incardon's avatar
incardon committed
887 888
					tot_recv += msize;
					MPI_SAFE_CALL(MPI_Recv(ptr,msize,MPI_BYTE,stat_t.MPI_SOURCE,stat_t.MPI_TAG,MPI_COMM_WORLD,&stat_t));
889 890

#ifdef SE_CLASS2
incardon's avatar
incardon committed
891
					check_valid(ptr,msize);
892
#endif
incardon's avatar
incardon committed
893
				}
894 895 896 897 898 899 900
			}

			// Check the status of all the MPI_issend and call the barrier if finished

			if (reached_bar_req == false)
			{
				int flag = false;
incardon's avatar
incardon committed
901 902 903 904
				if (req.size() != 0)
				{MPI_SAFE_CALL(MPI_Testall(req.size(),&req.get(0),&flag,MPI_STATUSES_IGNORE));}
				else
					flag = true;
905 906 907 908 909 910

				// If all send has been completed
				if (flag == true)
				{MPI_SAFE_CALL(MPI_Ibarrier(MPI_COMM_WORLD,&bar_req));reached_bar_req = true;}
			}

911
			// Check if all processor reached the async barrier
912
			if (reached_bar_req)
913
			{MPI_SAFE_CALL(MPI_Test(&bar_req,&flag,&bar_stat))};
incardon's avatar
incardon committed
914 915

			// produce a report if communication get stuck
916
			log.NBXreport(NBX_cnt,req,reached_bar_req,bar_stat);
incardon's avatar
incardon committed
917

918 919 920 921 922 923
		} while (flag == false);

		// Remove the executed request

		req.clear();
		stat.clear();
incardon's avatar
incardon committed
924
		log.clear();
925 926

		// Circular counter
927
		NBX_cnt = (NBX_cnt + 1) % 2048;
incardon's avatar
incardon committed
928 929
	}

930 931 932 933 934 935
	/*! \brief Send data to a processor
	 *
	 * \warning In order to avoid deadlock every send must be coupled with a recv
	 *          in case you want to send data without knowledge from the other side
	 *          consider to use sendRecvMultipleMessages
	 *
incardon's avatar
incardon committed
936 937 938 939 940 941 942 943 944 945 946 947
	 * \warning operation is asynchronous execute must be called to ensure they are executed
	 *
	 * \see sendRecvMultipleMessages
	 *
	 * \param proc processor id
	 * \param tag id
	 * \param mem buffer with the data to send
	 * \param sz size
	 *
	 * \return true if succeed false otherwise
	 *
	 */
948
	bool send(size_t proc, size_t tag, const void * mem, size_t sz)
incardon's avatar
incardon committed
949 950 951 952 953 954 955 956 957 958 959 960
	{
		// send over MPI

		// Create one request
		req.add();

		// send
		MPI_IsendWB::send(proc,SEND_RECV_BASE + tag,mem,sz,req.last());

		return true;
	}

incardon's avatar
incardon committed
961

incardon's avatar
incardon committed
962 963 964 965 966 967 968
	/*! \brief Send data to a processor
	 *
	 * \warning In order to avoid deadlock every send must be coupled with a recv
	 *          in case you want to send data without knowledge from the other side
	 *          consider to use sendRecvMultipleMessages
	 *
	 * \warning operation is asynchronous execute must be called to ensure they are executed
969 970 971 972 973 974 975
	 *
	 * \see sendRecvMultipleMessages
	 *
	 * \param proc processor id
	 * \param tag id
	 * \param v buffer to send
	 *
976 977
	 * \return true if succeed false otherwise
	 *
978
	 */
979
	template<typename T, typename Mem, typename gr> bool send(size_t proc, size_t tag, openfpm::vector<T,Mem,gr> & v)
980
	{
incardon's avatar
incardon committed
981
#ifdef SE_CLASS1
982 983 984 985 986 987 988 989
		checkType<T>();
#endif

		// send over MPI

		// Create one request
		req.add();

990
		// send
991
		MPI_IsendW<T,Mem,gr>::send(proc,SEND_RECV_BASE + tag,v,req.last());
992 993

		return true;
994 995 996 997 998 999
	}

	/*! \brief Recv data from a processor
	 *
	 * \warning In order to avoid deadlock every recv must be coupled with a send
	 *          in case you want to send data without knowledge from the other side
1000
	 *          consider to use or sendrecvMultipleMessagesNBX
1001
	 *
incardon's avatar
incardon committed
1002
	 * \warning operation is asynchronous execute must be called to ensure they are executed
1003
	 *
1004
	 * \see sendrecvMultipleMessagesNBX
1005 1006 1007 1008
	 *
	 * \param proc processor id
	 * \param tag id
	 * \param v buffer to send
incardon's avatar
incardon committed
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
	 * \param sz size of the buffer
	 *
	 * \return true if succeed false otherwise
	 *
	 */
	bool recv(size_t proc, size_t tag, void * v, size_t sz)
	{
		// recv over MPI

		// Create one request
		req.add();

		// receive
		MPI_IrecvWB::recv(proc,SEND_RECV_BASE + tag,v,sz,req.last());

		return true;
	}

incardon's avatar
incardon committed
1027 1028 1029 1030
    /*! \brief Recv data from a processor
     *
     * \warning In order to avoid deadlock every recv must be coupled with a send
     *          in case you want to send data without knowledge from the other side
1031
     *          consider to use sendrecvMultipleMessagesNBX
incardon's avatar
incardon committed
1032 1033 1034
     *
     * \warning operation is asynchronous execute must be called to ensure they are executed
     *
1035
     * \see sendrecvMultipleMessagesNBX
incardon's avatar
incardon committed
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045
     *
     * \param proc processor id
     * \param tag id
     * \param v vector to send
     *
     * \return true if succeed false otherwise
     *
     */
    template<typename T, typename Mem, typename gr> bool recv(size_t proc, size_t tag, openfpm::vector<T,Mem,gr> & v)
    {
incardon's avatar
incardon committed
1046
#ifdef SE_CLASS1
incardon's avatar
incardon committed
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061
            checkType<T>();
#endif

            // recv over MPI

            // Create one request
            req.add();

            // receive
            MPI_IrecvW<T>::recv(proc,SEND_RECV_BASE + tag,v,req.last());

            return true;
    }

	/*! \brief Gather the data from all processors
1062 1063
	 *
	 * send a primitive data T receive the same primitive T from all the other processors
incardon's avatar
incardon committed
1064 1065 1066
	 *
	 * \warning operation is asynchronous execute must be called to ensure they are executed
	 *
1067
	 * \param v vector to receive (automaticaly resized)
incardon's avatar
incardon committed
1068
	 * \param send data to send
1069
	 *
1070 1071
	 * \return true if succeed false otherwise
	 *
1072
	 */
incardon's avatar
incardon committed
1073
	template<typename T, typename Mem, typename gr> bool allGather(T & send, openfpm::vector<T,Mem,gr> & v)
1074
	{
incardon's avatar
incardon committed
1075
#ifdef SE_CLASS1
1076 1077 1078 1079 1080 1081
		checkType<T>();
#endif

		// Create one request
		req.add();

incardon's avatar
incardon committed
1082 1083 1084
		// Number of processors
		v.resize(getProcessingUnits());

1085
		// gather
incardon's avatar
incardon committed
1086
		MPI_IAllGatherW<T>::gather(&send,1,v.getPointer(),1,req.last());
1087 1088

		return true;
1089 1090
	}

incardon's avatar
incardon committed
1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
	/*! \brief Broadcast the data to all processors
	 *
	 * broadcast a vector of primitives.
	 *
	 * \warning operation is asynchronous execute must be called to ensure the operation is executed
	 *
	 * \warning the non-root processor must resize the vector to the exact receive size. This mean the
	 *          each processor must known a priory the receiving size
	 *
	 * \param v vector to send in the case of the root processor and vector where to receive in the case of
	 *          non-root
	 * \param root processor (who broadcast)
	 *
	 * \return true if succeed false otherwise
	 *
	 */
1107 1108
	template<typename T, typename Mem, typename lt_type, template<typename> class layout_base >
	bool Bcast(openfpm::vector<T,Mem,lt_type,layout_base> & v, size_t root)
incardon's avatar
incardon committed
1109 1110 1111 1112 1113
	{
#ifdef SE_CLASS1
		checkType<T>();
#endif

1114
		b_cast_helper<openfpm::vect_isel<T>::value == STD_VECTOR || is_layout_mlin<layout_base<T>>::value >::bcast_(req,v,root);
incardon's avatar
incardon committed
1115 1116 1117 1118

		return true;
	}

1119
	/*! \brief Execute all the requests
incardon's avatar
incardon committed
1120 1121 1122 1123
	 *
	 */
	void execute()
	{
1124 1125 1126 1127
		// if req == 0 return
		if (req.size() == 0)
			return;

incardon's avatar
incardon committed
1128
		// Wait for all the requests
1129
		stat.resize(req.size());
1130
		MPI_SAFE_CALL(MPI_Waitall(req.size(),&req.get(0),&stat.get(0)));
incardon's avatar
incardon committed
1131

1132
		// Remove executed request and status
incardon's avatar
incardon committed
1133 1134 1135
		req.clear();
		stat.clear();
	}
1136 1137 1138 1139 1140 1141 1142 1143 1144

	/*! \brief Release the buffer used for communication
	 *
	 *
	 */
	void clear()
	{
		recv_buf.clear();
	}
incardon's avatar
incardon committed
1145 1146
};

1147

Pietro Incardona's avatar
Pietro Incardona committed
1148

1149

incardon's avatar
incardon committed
1150 1151
#endif