source: XIOS/dev/branch_yushan/src/buffer_client.cpp @ 1128

Last change on this file since 1128 was 1128, checked in by yushan, 7 years ago

log OK with threads

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