source: XIOS/dev/dev_trunk_omp/src/buffer_client.cpp @ 1670

Last change on this file since 1670 was 1646, checked in by yushan, 5 years ago

branch merged with trunk @1645. arch file (ep&mpi) added for ADA

  • 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.1 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
10
11#ifdef _usingEP
12using namespace ep_lib;
13#endif
14
15namespace xios
16{
17  size_t CClientBuffer::maxRequestSize = 0;
18
19  CClientBuffer::CClientBuffer(MPI_Comm interComm, int serverRank, StdSize bufferSize, StdSize estimatedMaxEventSize, StdSize maxBufferedEvents)
20    : interComm(interComm)
21    , serverRank(serverRank)
22    , bufferSize(bufferSize)
23    , estimatedMaxEventSize(estimatedMaxEventSize)
24    , maxEventSize(0)
25    , current(0)
26    , count(0)
27    , bufferedEvents(0)
28    , maxBufferedEvents(maxBufferedEvents)
29    , pending(false)
30  {
31    buffer[0] = new char[bufferSize]; // transform it with MPI_ALLOC_MEM later
32    buffer[1] = new char[bufferSize];
33    retBuffer = new CBufferOut(buffer[current], bufferSize);
34    #pragma omp critical (_output)
35    {
36      info(10) << "CClientBuffer: allocated 2 x " << bufferSize << " bytes for server " << serverRank << " with a maximum of " << maxBufferedEvents << " buffered events" << endl;
37    }
38  }
39
40  CClientBuffer::~CClientBuffer()
41  {
42   delete [] buffer[0];
43   delete [] buffer[1];
44   delete retBuffer;
45  }
46
47  StdSize CClientBuffer::remain(void)
48  {
49    return bufferSize - count;
50  }
51
52  bool CClientBuffer::isBufferFree(StdSize size)
53  {
54    if (size > bufferSize)
55      ERROR("bool CClientBuffer::isBufferFree(StdSize size)",
56            << "The requested size (" << size << " bytes) is too big to fit the buffer (" << bufferSize << " bytes), please increase the client buffer size." << endl);
57
58    if (size > maxEventSize)
59    {
60      maxEventSize = size;
61
62      if (size > estimatedMaxEventSize)
63        error(0) << "WARNING: Unexpected event of size " << size << " for server " << serverRank
64                 << " (estimated max event size = " << estimatedMaxEventSize << ")" << std::endl;
65
66      if (size > maxRequestSize) maxRequestSize = size;
67    }
68
69
70    return (size <= remain() && bufferedEvents < maxBufferedEvents);
71  }
72
73
74  CBufferOut* CClientBuffer::getBuffer(StdSize size)
75  {
76    if (size <= remain())
77    {
78      retBuffer->realloc(buffer[current] + count, size);
79      count += size;
80      bufferedEvents++;
81      return retBuffer;
82    }
83    else
84    {
85      ERROR("CBufferOut* CClientBuffer::getBuffer(StdSize size)",
86            << "Not enough space in buffer, this should not have happened...");
87      return NULL;
88    }
89  }
90
91  bool CClientBuffer::checkBuffer(void)
92  {
93    MPI_Status status;
94    int flag;
95
96    if (pending)
97    {
98      traceOff();
99      MPI_Test(&request, &flag, &status);
100      traceOn();
101      if (flag == true) pending = false;
102    }
103
104    if (!pending)
105    {
106      if (count > 0)
107      {
108        MPI_Issend(buffer[current], count, MPI_CHAR, serverRank, 20, interComm, &request);
109        pending = true;
110        if (current == 1) current = 0;
111        else current = 1;
112        count = 0;
113        bufferedEvents = 0;
114      }
115    }
116
117    return pending;
118  }
119
120  bool CClientBuffer::hasPendingRequest(void)
121  {
122    return (pending || count > 0);
123  }
124}
Note: See TracBrowser for help on using the repository browser.