XIOS  1.0
Xml I/O Server
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Définitions de type Énumérations Valeurs énumérées Amis Macros
buffer_client.cpp
Aller à la documentation de ce fichier.
1 #include "xios_spl.hpp"
2 #include "exception.hpp"
3 #include "log.hpp"
4 #include "buffer_out.hpp"
5 #include "buffer_client.hpp"
6 #include "cxios.hpp"
7 #include "mpi.hpp"
8 #include "tracer.hpp"
9 
10 namespace xios
11 {
13 
14  CClientBuffer::CClientBuffer(MPI_Comm interComm, int serverRank, StdSize bufferSize, StdSize estimatedMaxEventSize, StdSize maxBufferedEvents)
15  : interComm(interComm)
16  , serverRank(serverRank)
17  , bufferSize(bufferSize)
18  , estimatedMaxEventSize(estimatedMaxEventSize)
19  , maxEventSize(0)
20  , current(0)
21  , count(0)
22  , bufferedEvents(0)
23  , maxBufferedEvents(maxBufferedEvents)
24  , pending(false)
25  {
26  buffer[0] = new char[bufferSize]; // transform it with MPI_ALLOC_MEM later
27  buffer[1] = new char[bufferSize];
28  retBuffer = new CBufferOut(buffer[current], bufferSize);
29  info(10) << "CClientBuffer: allocated 2 x " << bufferSize << " bytes for server " << serverRank << " with a maximum of " << maxBufferedEvents << " buffered events" << endl;
30  }
31 
33  {
34  delete [] buffer[0];
35  delete [] buffer[1];
36  delete retBuffer;
37  }
38 
40  {
41  return bufferSize - count;
42  }
43 
45  {
46  if (size > bufferSize)
47  ERROR("bool CClientBuffer::isBufferFree(StdSize size)",
48  << "The requested size (" << size << " bytes) is too big to fit the buffer (" << bufferSize << " bytes), please increase the client buffer size." << endl);
49 
50  if (size > maxEventSize)
51  {
52  maxEventSize = size;
53 
54  if (size > estimatedMaxEventSize)
55  error(0) << "WARNING: Unexpected event of size " << size << " for server " << serverRank
56  << " (estimated max event size = " << estimatedMaxEventSize << ")" << std::endl;
57 
58  if (size > maxRequestSize) maxRequestSize = size;
59  }
60 
61 
62  return (size <= remain() && bufferedEvents < maxBufferedEvents);
63  }
64 
65 
67  {
68  if (size <= remain())
69  {
71  count += size;
73  return retBuffer;
74  }
75  else
76  {
77  ERROR("CBufferOut* CClientBuffer::getBuffer(StdSize size)",
78  << "Not enough space in buffer, this should not have happened...");
79  return NULL;
80  }
81  }
82 
84  {
85  MPI_Status status;
86  int flag;
87 
88  if (pending)
89  {
90  traceOff();
91  MPI_Test(&request, &flag, &status);
92  traceOn();
93  if (flag == true) pending = false;
94  }
95 
96  if (!pending)
97  {
98  if (count > 0)
99  {
100  MPI_Issend(buffer[current], count, MPI_CHAR, serverRank, 20, interComm, &request);
101  pending = true;
102  if (current == 1) current = 0;
103  else current = 1;
104  count = 0;
105  bufferedEvents = 0;
106  }
107  }
108 
109  return pending;
110  }
111 
113  {
114  return (pending || count > 0);
115  }
116 }
StdSize remain(void)
CClientBuffer(MPI_Comm intercomm, int serverRank, StdSize bufferSize, StdSize estimatedMaxEventSize, StdSize maxBufferedEvents)
int count
Definition: tracer.cpp:26
CLog info("info")
Definition: log.hpp:55
bool hasPendingRequest(void)
void traceOn(void)
Definition: tracer.cpp:28
#define xios(arg)
CBufferOut * getBuffer(StdSize size)
CBufferOut * retBuffer
CATCH CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CScalar *scalarDestination, CScalar *scalarSource, CReduceScalarToScalar *algo ERROR)("CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CScalar* scalarDestination, CScalar* scalarSource, CReduceScalarToScalar* algo)",<< "Operation must be defined."<< "Scalar source "<< scalarSource->getId()<< std::endl<< "Scalar destination "<< scalarDestination->getId())
std::size_t StdSize
Definition: xios_spl.hpp:49
CLog error("error", cerr.rdbuf())
Definition: log.hpp:57
bool isBufferFree(StdSize size)
void traceOff(void)
Definition: tracer.cpp:39
const MPI_Comm interComm
const StdSize maxBufferedEvents
void realloc(size_t size)
Definition: buffer_out.cpp:25
static size_t maxRequestSize
const StdSize estimatedMaxEventSize
const StdSize bufferSize