source: XIOS/dev/XIOS_DEV_CMIP6/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
RevLine 
[591]1#include "xios_spl.hpp"
[300]2#include "exception.hpp"
[380]3#include "log.hpp"
[300]4#include "buffer_out.hpp"
5#include "buffer_client.hpp"
[317]6#include "cxios.hpp"
[382]7#include "mpi.hpp"
[347]8#include "tracer.hpp"
[300]9
[335]10namespace xios
[300]11{
[732]12  size_t CClientBuffer::maxRequestSize = 0;
[509]13
[1201]14  CClientBuffer::CClientBuffer(MPI_Comm interComm, int serverRank, StdSize bufferSize, StdSize estimatedMaxEventSize, StdSize maxBufferedEvents)
[917]15    : interComm(interComm)
16    , serverRank(serverRank)
17    , bufferSize(bufferSize)
[1201]18    , estimatedMaxEventSize(estimatedMaxEventSize)
19    , maxEventSize(0)
[917]20    , current(0)
21    , count(0)
22    , bufferedEvents(0)
23    , maxBufferedEvents(maxBufferedEvents)
24    , pending(false)
[300]25  {
[732]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);
[917]29    info(10) << "CClientBuffer: allocated 2 x " << bufferSize << " bytes for server " << serverRank << " with a maximum of " << maxBufferedEvents << " buffered events" << endl;
[300]30  }
[509]31
[300]32  CClientBuffer::~CClientBuffer()
33  {
[732]34   delete [] buffer[0];
35   delete [] buffer[1];
36   delete retBuffer;
[300]37  }
[509]38
[1227]39  StdSize CClientBuffer::remain(void)
[300]40  {
[732]41    return bufferSize - count;
[300]42  }
[509]43
[1227]44  bool CClientBuffer::isBufferFree(StdSize size)
[300]45  {
[732]46    if (size > bufferSize)
[1227]47      ERROR("bool CClientBuffer::isBufferFree(StdSize size)",
[732]48            << "The requested size (" << size << " bytes) is too big to fit the buffer (" << bufferSize << " bytes), please increase the client buffer size." << endl);
[509]49
[1201]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
[917]62    return (size <= remain() && bufferedEvents < maxBufferedEvents);
[300]63  }
[509]64
65
[1227]66  CBufferOut* CClientBuffer::getBuffer(StdSize size)
[300]67  {
[732]68    if (size <= remain())
[300]69    {
[732]70      retBuffer->realloc(buffer[current] + count, size);
71      count += size;
[917]72      bufferedEvents++;
[732]73      return retBuffer;
[300]74    }
75    else
76    {
[1227]77      ERROR("CBufferOut* CClientBuffer::getBuffer(StdSize size)",
[732]78            << "Not enough space in buffer, this should not have happened...");
79      return NULL;
[300]80    }
[509]81  }
82
[300]83  bool CClientBuffer::checkBuffer(void)
84  {
[732]85    MPI_Status status;
86    int flag;
[509]87
[300]88    if (pending)
89    {
[732]90      traceOff();
[1130]91      MPI_Test(&request, &flag, &status);
[732]92      traceOn();
93      if (flag == true) pending = false;
[300]94    }
95
96    if (!pending)
97    {
[732]98      if (count > 0)
[300]99      {
[1130]100        MPI_Issend(buffer[current], count, MPI_CHAR, serverRank, 20, interComm, &request);
[732]101        pending = true;
102        if (current == 1) current = 0;
103        else current = 1;
104        count = 0;
[917]105        bufferedEvents = 0;
[300]106      }
107    }
[732]108
109    return pending;
[300]110  }
[509]111
[300]112  bool CClientBuffer::hasPendingRequest(void)
113  {
[732]114    return (pending || count > 0);
[300]115  }
[509]116}
Note: See TracBrowser for help on using the repository browser.