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

Last change on this file since 1460 was 1460, checked in by yushan, 3 years ago

branch_openmp merged with XIOS_DEV_CMIP6@1459

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