OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
processcomm.h
Go to the documentation of this file.
1 /*
2  *
3  * ##### ##### ###### ###### ### ###
4  * ## ## ## ## ## ## ## ### ##
5  * ## ## ## ## #### #### ## # ##
6  * ## ## ## ## ## ## ## ##
7  * ## ## ## ## ## ## ## ##
8  * ##### ##### ## ###### ## ##
9  *
10  *
11  * OOFEM : Object Oriented Finite Element Code
12  *
13  * Copyright (C) 1993 - 2013 Borek Patzak
14  *
15  *
16  *
17  * Czech Technical University, Faculty of Civil Engineering,
18  * Department of Structural Mechanics, 166 29 Prague, Czech Republic
19  *
20  * This library is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU Lesser General Public
22  * License as published by the Free Software Foundation; either
23  * version 2.1 of the License, or (at your option) any later version.
24  *
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28  * Lesser General Public License for more details.
29  *
30  * You should have received a copy of the GNU Lesser General Public
31  * License along with this library; if not, write to the Free Software
32  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33  */
34 
35 #ifndef processcomm_h
36 #define processcomm_h
37 
38 #include "oofemcfg.h"
39 #include "combuff.h"
40 #include "commbufftype.h"
41 #include "communicatormode.h"
42 #include "floatmatrix.h"
43 #include "floatarray.h"
44 #include "intarray.h"
45 #include "error.h"
46 #include "logger.h"
47 
48 #include <string>
49 
50 namespace oofem {
64 class OOFEM_EXPORT ProcessCommunicatorBuff: public DataStream
65 {
66 protected:
71 public:
74  virtual ~ProcessCommunicatorBuff();
75 
76  virtual int givePackSizeOfInt(int count) { return send_buff->givePackSizeOfInt(count); }
77  virtual int givePackSizeOfDouble(int count) { return send_buff->givePackSizeOfDouble(count); }
78  virtual int givePackSizeOfChar(int count) { return send_buff->givePackSizeOfChar(count); }
79  virtual int givePackSizeOfBool(int count) { return send_buff->givePackSizeOfBool(count); }
80  virtual int givePackSizeOfLong(int count) { return send_buff->givePackSizeOfLong(count); }
81 
82  using DataStream::write;
83  virtual int write(const int *data, int count) { return send_buff->write(data, count); }
84  virtual int write(const long *data, int count) { return send_buff->write(data, count); }
85  virtual int write(const unsigned long *data, int count) { return send_buff->write(data, count); }
86  virtual int write(const double *data, int count) { return send_buff->write(data, count); }
87  virtual int write(const char *data, int count) { return send_buff->write(data, count); }
88  virtual int write(bool data) { return send_buff->write(data); }
89 
90  using DataStream::read;
91  virtual int read(int *data, int count) { return this->recv_buff->read(data, count); }
92  virtual int read(long *data, int count) { return this->recv_buff->read(data, count); }
93  virtual int read(unsigned long *data, int count) { return this->recv_buff->read(data, count); }
94  virtual int read(double *data, int count) { return this->recv_buff->read(data, count); }
95  virtual int read(char *data, int count) { return this->recv_buff->read(data, count); }
96  virtual int read(bool &data) { return recv_buff->read(data); }
97 
99  void initSendBuff() { send_buff->init(); }
101  void initRecvBuff() { recv_buff->init(); }
103  void init() {
104  initSendBuff();
105  initRecvBuff();
106  }
107 
109  void initForPacking() { send_buff->initForPacking(); }
111  void initForUnpacking() { recv_buff->initForUnpacking(); }
112 
120  int initExchange(int rank, int tag) {
121  int result = 1;
122  result &= initSend(rank, tag);
123  result &= initReceive(rank, tag);
124 
125  return result;
126  }
134  int initSend(int rank, int tag) { return send_buff->iSend(rank, tag); }
142  int initReceive(int rank, int tag) { return recv_buff->iRecv(rank, tag); }
143 
147  void clearBuffers() { }
148 
149  void resizeSendBuffer(int size) { send_buff->resize(size); }
150  void resizeReceiveBuffer(int size) { recv_buff->resize(size); }
151 
154  int sendCompleted() { return send_buff->testCompletion(); }
155  int receiveCompleted() { return recv_buff->testCompletion(); }
156  int testCompletion() { return ( send_buff->testCompletion() && recv_buff->testCompletion() ); }
157  int waitCompletion() { return ( send_buff->waitCompletion() && recv_buff->waitCompletion() ); }
159 
163  CommunicationBuffer *giveSendBuff() { return send_buff; }
167  CommunicationBuffer *giveRecvBuff() { return recv_buff; }
168 };
169 
170 
176 class OOFEM_EXPORT ProcessCommunicator
177 {
178 protected:
180  int rank; // remote problem id = rank
181 
184 
191 
192 public:
203 
207  int giveRank() { return rank; }
208 
211  if ( pcBuffer ) {
212  return pcBuffer;
213  }
214 
215  OOFEM_ERROR("ProcessCommunicatorBuff undefined");
216  return NULL;
217  }
218 
219 
223  const IntArray *giveToSendMap() { return & toSend; }
227  const IntArray *giveToRecvMap() { return & toReceive; }
228 
229 
240  template< class T > void setToSendArry(T *emodel, const IntArray &src, int packUnpackType);
251  template< class T > void setToRecvArry(T *emodel, const IntArray &src, int packUnpackType);
259  template< class T > int packData( T *emodel, int ( T :: *packFunc )( ProcessCommunicator & ) )
260  {
261  if ( !toSend.isEmpty() || ( this->mode == CommMode_Dynamic ) ) {
262  giveProcessCommunicatorBuff()->initForPacking();
263  return ( emodel->*packFunc )(* this);
264  } else {
265  return 1;
266  }
267  }
276  template< class T, class P > int packData( T *emodel, P *src, int ( T :: *packFunc )( P *, ProcessCommunicator & ) )
277  {
278  if ( !toSend.isEmpty() || ( this->mode == CommMode_Dynamic ) ) {
279  giveProcessCommunicatorBuff()->initForPacking();
280  return ( emodel->*packFunc )(src, * this);
281  } else {
282  return 1;
283  }
284  }
292  template< class T > int unpackData( T *emodel, int ( T :: *unpackFunc )( ProcessCommunicator & ) )
293  {
294  if ( !toReceive.isEmpty() || ( this->mode == CommMode_Dynamic ) ) {
295  giveProcessCommunicatorBuff()->initForUnpacking();
296  return ( emodel->*unpackFunc )(* this);
297  } else {
298  return 1;
299  }
300  }
309  template< class T, class P > int unpackData( T *emodel, P *dest, int ( T :: *unpackFunc )( P *, ProcessCommunicator & ) )
310  {
311  if ( !toReceive.isEmpty() || ( this->mode == CommMode_Dynamic ) ) {
312  giveProcessCommunicatorBuff()->initForUnpacking();
313  return ( emodel->*unpackFunc )(dest, * this);
314  } else {
315  return 1;
316  }
317  }
324  int initExchange(int tag);
331  int initSend(int tag);
338  int initReceive(int tag);
340  int finishExchange();
341 
342 
345  int sendCompleted();
346  int receiveCompleted();
347  int testCompletion();
348  int waitCompletion();
349 
351  void clearBuffers();
353 
354 private:
364  template< class T > int resizeSendBuff(T *emodel, int packUnpackType);
374  template< class T > int resizeRecvBuff(T *emodel, int packUnpackType);
375 };
376 
377 template< class T > void
378 ProcessCommunicator :: setToSendArry(T *emodel, const IntArray &src, int packUnpackType)
379 {
380  toSend = src;
381  // toSend.sort (&NlDEIDynamicDomainComunicator::nodeSortFunct);
382  //sortCommMap (toSend);
383  resizeSendBuff(emodel, packUnpackType);
384 }
385 
386 
387 template< class T > void
388 ProcessCommunicator :: setToRecvArry(T *emodel, const IntArray &src, int packUnpackType)
389 {
390  toReceive = src;
391  //toReceive.sort (&NlDEIDynamicDomainComunicator::nodeSortFunct);
392  //sortCommMap (toReceive);
393  resizeRecvBuff(emodel, packUnpackType);
394 }
395 
396 
397 template< class T > int
398 ProcessCommunicator :: resizeSendBuff(T *emodel, int packUnpackType)
399 {
400  int size;
401  // determine space for send buffer
402  size = emodel->estimateMaxPackSize(toSend, * giveProcessCommunicatorBuff()->giveSendBuff(), packUnpackType);
403  giveProcessCommunicatorBuff()->resizeSendBuffer(size);
404  //giveSendBuff()->resize (size);
405  return 1;
406 }
407 
408 
409 template< class T > int
410 ProcessCommunicator :: resizeRecvBuff(T *emodel, int packUnpackType)
411 {
412  int size;
413 
414  // determine space for recv buffer
415  size = emodel->estimateMaxPackSize(toReceive, * giveProcessCommunicatorBuff()->giveRecvBuff(), packUnpackType);
416  giveProcessCommunicatorBuff()->resizeReceiveBuffer(size);
417  //giveRecvBuff()->resize (size);
418 
419  return 1;
420 }
421 } // end namespace oofem
422 #endif // processcomm_h
virtual int resize(int newSize)=0
Resizes buffer to given size.
int packData(T *emodel, int(T::*packFunc)(ProcessCommunicator &))
Pack nodal data to send buff.
Definition: processcomm.h:259
virtual int givePackSizeOfLong(int count)
Definition: combuff.C:299
virtual void init()=0
Initializes buffer to empty state.
virtual int givePackSizeOfChar(int count)
Definition: processcomm.h:78
virtual void initForPacking()=0
Initialize for packing.
virtual int read(unsigned long *data, int count)
Reads count unsigned long values into array pointed by data.
Definition: processcomm.h:93
The purpose of DataStream abstract class is to allow to store/restore context to different streams...
Definition: datastream.h:54
bool isEmpty() const
Checks if receiver is empty (i.e., zero sized).
Definition: intarray.h:208
virtual int givePackSizeOfBool(int count)
Definition: processcomm.h:79
CommBuffType
Definition: commbufftype.h:40
void setToSendArry(T *emodel, const IntArray &src, int packUnpackType)
Sets receiver toSend array to src.
Definition: processcomm.h:378
virtual int givePackSizeOfInt(int count)
Definition: processcomm.h:76
virtual int givePackSizeOfChar(int count)
Definition: combuff.C:285
The mode can be static, meaning that each node can assemble its communication maps independently (or ...
void resizeReceiveBuffer(int size)
Definition: processcomm.h:150
CommunicationBuffer * giveRecvBuff()
Returns receive buffer of receiver.
Definition: processcomm.h:167
void initForUnpacking()
Initialize for Unpacking (data already received).
Definition: processcomm.h:111
virtual void initForUnpacking()=0
Initialize for Unpacking (data already received)
The ProcessCommunicator and corresponding buffers (represented by this class) are separated in order ...
Definition: processcomm.h:64
int giveRank()
Returns corresponding rank of associated partition.
Definition: processcomm.h:207
ProcessCommunicatorBuff * pcBuffer
Communicator buffers representation.
Definition: processcomm.h:183
void init()
Initializes receiver buffers.
Definition: processcomm.h:103
Class implementing an array of integers.
Definition: intarray.h:61
virtual int read(int *data, int count)=0
Reads count integer values into array pointed by data.
CommunicatorMode
The communicator mode determines the communication.
~ProcessCommunicator()
Destructor.
Definition: processcomm.h:202
const IntArray * giveToSendMap()
Returns receiver to send map.
Definition: processcomm.h:223
int rank
Associated partition (problem) number (rank)
Definition: processcomm.h:180
virtual int iSend(int dest, int tag)=0
Starts standard mode, nonblocking send.
virtual int write(const int *data, int count)=0
Writes count integer values from array pointed by data.
CommunicatorMode mode
Mode.
Definition: processcomm.h:190
int initReceive(int rank, int tag)
Initialize the receive data exchange with associate problem.
Definition: processcomm.h:142
virtual int write(const int *data, int count)
Writes count integer values from array pointed by data.
Definition: processcomm.h:83
CommunicationBuffer * send_buff
Send buffer.
Definition: processcomm.h:68
Class CommunicationBuffer provides abstraction for communication buffer.
Definition: combuff.h:208
virtual int givePackSizeOfInt(int count)
Definition: combuff.C:271
#define OOFEM_ERROR(...)
Definition: error.h:61
virtual int read(char *data, int count)
Reads count char values into array pointed by data.
Definition: processcomm.h:95
CommunicationBuffer * recv_buff
Receive buffer.
Definition: processcomm.h:70
virtual int write(const long *data, int count)
Writes count long values from array pointed by data.
Definition: processcomm.h:84
ProcessCommunicatorBuff * giveProcessCommunicatorBuff()
Returns communication buffer.
Definition: processcomm.h:210
virtual int read(double *data, int count)
Reads count double values into array pointed by data.
Definition: processcomm.h:94
virtual int write(bool data)
Writes a bool value.
Definition: combuff.C:265
const IntArray * giveToRecvMap()
Returns receiver to receive map.
Definition: processcomm.h:227
virtual int testCompletion()=0
Tests if the operation identified by this->request is complete.
Class representing process communicator for engineering model.
Definition: processcomm.h:176
virtual int write(bool data)
Writes a bool value.
Definition: processcomm.h:88
IntArray toReceive
Nodes to receive.
Definition: processcomm.h:188
virtual int givePackSizeOfDouble(int count)
Definition: combuff.C:278
int initExchange(int rank, int tag)
Initializes data exchange with associated problem.
Definition: processcomm.h:120
virtual int waitCompletion()=0
Waits until a completion of a nonblocking communication.
virtual int read(long *data, int count)
Reads count long values into array pointed by data.
Definition: processcomm.h:92
IntArray toSend
Nodes to send.
Definition: processcomm.h:186
void clearBuffers()
Clears all buffer contents.
Definition: processcomm.h:147
(Dynamic) In this case the communication pattern and the amount of data sent between nodes is not kno...
virtual int iRecv(int source, int tag, int count=0)=0
Starts standard mode, nonblocking receive.
virtual int givePackSizeOfDouble(int count)
Definition: processcomm.h:77
void initSendBuff()
Initializes send buffer to empty state. All packed data are lost.
Definition: processcomm.h:99
CommunicationBuffer * giveSendBuff()
Returns send buffer of receiver.
Definition: processcomm.h:163
virtual int write(const double *data, int count)
Writes count double values from array pointed by data.
Definition: processcomm.h:86
void setToRecvArry(T *emodel, const IntArray &src, int packUnpackType)
Sets receiver toRecv array to src.
Definition: processcomm.h:388
virtual int write(const char *data, int count)
Writes count char values from array pointed by data.
Definition: processcomm.h:87
int resizeRecvBuff(T *emodel, int packUnpackType)
Resizes receive buffer to needs according to toRecv array.
Definition: processcomm.h:410
int packData(T *emodel, P *src, int(T::*packFunc)(P *, ProcessCommunicator &))
Pack nodal data to send buff.
Definition: processcomm.h:276
void initRecvBuff()
Initializes send buffer to empty state. All packed data are lost.
Definition: processcomm.h:101
virtual int read(int *data, int count)
Reads count integer values into array pointed by data.
Definition: processcomm.h:91
int resizeSendBuff(T *emodel, int packUnpackType)
Resizes send buffer to needs according to toSend array.
Definition: processcomm.h:398
int unpackData(T *emodel, int(T::*unpackFunc)(ProcessCommunicator &))
Unpack nodal data from recv buff.
Definition: processcomm.h:292
void initForPacking()
Initialize for packing.
Definition: processcomm.h:109
the oofem namespace is to define a context or scope in which all oofem names are defined.
virtual int read(bool &data)
Reads a bool value from data.
Definition: combuff.C:257
int initSend(int rank, int tag)
Initialize the send data exchange with associate problem.
Definition: processcomm.h:134
virtual int read(bool &data)
Reads a bool value from data.
Definition: processcomm.h:96
virtual int write(const unsigned long *data, int count)
Writes count unsigned long values from array pointed by data.
Definition: processcomm.h:85
virtual int givePackSizeOfLong(int count)
Definition: processcomm.h:80
int unpackData(T *emodel, P *dest, int(T::*unpackFunc)(P *, ProcessCommunicator &))
Unpack nodal data from recv buff.
Definition: processcomm.h:309
virtual int givePackSizeOfBool(int count)
Definition: combuff.C:292

This page is part of the OOFEM documentation. Copyright (c) 2011 Borek Patzak
Project e-mail: info@oofem.org
Generated at Tue Jan 2 2018 20:07:30 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011