source: XIOS/branchs/xios-2.5/src/buffer_client.cpp @ 1627

Last change on this file since 1627 was 1227, checked in by oabramkina, 7 years ago

Minor modifications:

  • changing sizes of client buffers from int to size_t
  • adding attribute maxBufferSize.
  • 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    info(10) << "CClientBuffer: allocated 2 x " << bufferSize << " bytes for server " << serverRank << " with a maximum of " << maxBufferedEvents << " buffered events" << endl;
30  }
31
32  CClientBuffer::~CClientBuffer()
33  {
34   delete [] buffer[0];
35   delete [] buffer[1];
36   delete retBuffer;
37  }
38
39  StdSize CClientBuffer::remain(void)
40  {
41    return bufferSize - count;
42  }
43
44  bool CClientBuffer::isBufferFree(StdSize size)
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
66  CBufferOut* CClientBuffer::getBuffer(StdSize size)
67  {
68    if (size <= remain())
69    {
70      retBuffer->realloc(buffer[current] + count, size);
71      count += size;
72      bufferedEvents++;
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
83  bool CClientBuffer::checkBuffer(void)
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
112  bool CClientBuffer::hasPendingRequest(void)
113  {
114    return (pending || count > 0);
115  }
116}
Note: See TracBrowser for help on using the repository browser.