source: XIOS/dev/branch_yushan_merged/src/buffer_client.cpp @ 1205

Last change on this file since 1205 was 1205, checked in by yushan, 7 years ago

branch merged with trunk @1200

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
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
10namespace xios
11{
12  size_t CClientBuffer::maxRequestSize = 0;
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    #pragma omp critical (_output)
30    info(10) << "CClientBuffer: allocated 2 x " << bufferSize << " bytes for server " << serverRank << " with a maximum of " << maxBufferedEvents << " buffered events" << endl;
31  }
32
33  CClientBuffer::~CClientBuffer()
34  {
35   delete [] buffer[0];
36   delete [] buffer[1];
37   delete retBuffer;
38  }
39
40  int CClientBuffer::remain(void)
41  {
42    return bufferSize - count;
43  }
44
45  bool CClientBuffer::isBufferFree(int size)
46  {
47    if (size > bufferSize)
48      ERROR("bool CClientBuffer::isBufferFree(int size)",
49            << "The requested size (" << size << " bytes) is too big to fit the buffer (" << bufferSize << " bytes), please increase the client buffer size." << endl);
50
51    if (size > maxEventSize)
52    {
53      maxEventSize = size;
54
55      if (size > estimatedMaxEventSize)
56        error(0) << "WARNING: Unexpected event of size " << size << " for server " << serverRank
57                 << " (estimated max event size = " << estimatedMaxEventSize << ")" << std::endl;
58
59      if (size > maxRequestSize) maxRequestSize = size;
60    }
61
62
63    return (size <= remain() && bufferedEvents < maxBufferedEvents);
64  }
65
66
67  CBufferOut* CClientBuffer::getBuffer(int size)
68  {
69    if (size <= remain())
70    {
71      retBuffer->realloc(buffer[current] + count, size);
72      count += size;
73      bufferedEvents++;
74      return retBuffer;
75    }
76    else
77    {
78      ERROR("CBufferOut* CClientBuffer::getBuffer(int size)",
79            << "Not enough space in buffer, this should not have happened...");
80      return NULL;
81    }
82  }
83
84  bool CClientBuffer::checkBuffer(void)
85  {
86    MPI_Status status;
87    int flag;
88
89    if (pending)
90    {
91      traceOff();
92      MPI_Test(&request, &flag, &status);
93      traceOn();
94      if (flag == true) pending = false;
95    }
96
97    if (!pending)
98    {
99      if (count > 0)
100      {
101        MPI_Issend(buffer[current], count, MPI_CHAR, serverRank, 20, interComm, &request);
102        pending = true;
103        if (current == 1) current = 0;
104        else current = 1;
105        count = 0;
106        bufferedEvents = 0;
107      }
108    }
109
110    return pending;
111  }
112
113  bool CClientBuffer::hasPendingRequest(void)
114  {
115    return (pending || count > 0);
116  }
117}
Note: See TracBrowser for help on using the repository browser.