source: XIOS/dev/branch_openmp/src/buffer_client.cpp @ 1520

Last change on this file since 1520 was 1520, checked in by yushan, 6 years ago

save dev. TO DO : test with xios

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