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

Last change on this file since 887 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
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 bfSize)
15  {
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;
26  }
27
28  CClientBuffer::~CClientBuffer()
29  {
30   delete [] buffer[0];
31   delete [] buffer[1];
32   delete retBuffer;
33  }
34
35  int CClientBuffer::remain(void)
36  {
37    return bufferSize - count;
38  }
39
40  bool CClientBuffer::isBufferFree(int size)
41  {
42    if (size > maxRequestSize) maxRequestSize = size;
43
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);
47
48    return (size <= remain());
49  }
50
51
52  CBufferOut* CClientBuffer::getBuffer(int size)
53  {
54    if (size <= remain())
55    {
56      retBuffer->realloc(buffer[current] + count, size);
57      count += size;
58      return retBuffer;
59    }
60    else
61    {
62      ERROR("CBufferOut* CClientBuffer::getBuffer(int size)",
63            << "Not enough space in buffer, this should not have happened...");
64      return NULL;
65    }
66  }
67
68  bool CClientBuffer::checkBuffer(void)
69  {
70    MPI_Status status;
71    int flag;
72
73    if (pending)
74    {
75      traceOff();
76      MPI_Test(&request, &flag, &status);
77      traceOn();
78      if (flag == true) pending = false;
79    }
80
81    if (!pending)
82    {
83      if (count > 0)
84      {
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;
90      }
91    }
92
93    return pending;
94  }
95
96  bool CClientBuffer::hasPendingRequest(void)
97  {
98    return (pending || count > 0);
99  }
100}
Note: See TracBrowser for help on using the repository browser.