source: XIOS/dev/branch_openmp/src/buffer_client.cpp @ 1328

Last change on this file since 1328 was 1328, checked in by yushan, 6 years ago

dev_omp

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