source: XIOS/trunk/src/buffer_client.cpp @ 830

Last change on this file since 830 was 732, checked in by rlacroix, 9 years ago

CClientBuffer: Improve the error messages.

  • 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: 2.3 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
[732]14  CClientBuffer::CClientBuffer(MPI_Comm interComm_, int serverRank_, StdSize bfSize)
[300]15  {
[732]16    interComm = interComm_;
17    serverRank = serverRank_;
18    bufferSize = bfSize;
19    buffer[0] = new char[bufferSize]; // transform it with MPI_ALLOC_MEM later
20    buffer[1] = new char[bufferSize];
21    current = 0;
22    count = 0;
23    pending = false;
24    retBuffer = new CBufferOut(buffer[current], bufferSize);
25    info(10) << "CClientBuffer: allocated " << bufferSize << " bytes for server " << serverRank_ << endl;
[300]26  }
[509]27
[300]28  CClientBuffer::~CClientBuffer()
29  {
[732]30   delete [] buffer[0];
31   delete [] buffer[1];
32   delete retBuffer;
[300]33  }
[509]34
[300]35  int CClientBuffer::remain(void)
36  {
[732]37    return bufferSize - count;
[300]38  }
[509]39
[300]40  bool CClientBuffer::isBufferFree(int size)
41  {
[732]42    if (size > maxRequestSize) maxRequestSize = size;
[509]43
[732]44    if (size > bufferSize)
45      ERROR("bool CClientBuffer::isBufferFree(int size)",
46            << "The requested size (" << size << " bytes) is too big to fit the buffer (" << bufferSize << " bytes), please increase the client buffer size." << endl);
[509]47
[732]48    return (size <= remain());
[300]49  }
[509]50
51
[732]52  CBufferOut* CClientBuffer::getBuffer(int size)
[300]53  {
[732]54    if (size <= remain())
[300]55    {
[732]56      retBuffer->realloc(buffer[current] + count, size);
57      count += size;
58      return retBuffer;
[300]59    }
60    else
61    {
[732]62      ERROR("CBufferOut* CClientBuffer::getBuffer(int size)",
63            << "Not enough space in buffer, this should not have happened...");
64      return NULL;
[300]65    }
[509]66  }
67
[300]68  bool CClientBuffer::checkBuffer(void)
69  {
[732]70    MPI_Status status;
71    int flag;
[509]72
[300]73    if (pending)
74    {
[732]75      traceOff();
76      MPI_Test(&request, &flag, &status);
77      traceOn();
78      if (flag == true) pending = false;
[300]79    }
80
81    if (!pending)
82    {
[732]83      if (count > 0)
[300]84      {
[732]85        MPI_Issend(buffer[current], count, MPI_CHAR, serverRank, 20, interComm, &request);
86        pending = true;
87        if (current == 1) current = 0;
88        else current = 1;
89        count = 0;
[300]90      }
91    }
[732]92
93    return pending;
[300]94  }
[509]95
[300]96  bool CClientBuffer::hasPendingRequest(void)
97  {
[732]98    return (pending || count > 0);
[300]99  }
[509]100}
Note: See TracBrowser for help on using the repository browser.