source: XIOS/dev/dev_trunk_omp/src/buffer_client.cpp @ 1670

Last change on this file since 1670 was 1646, checked in by yushan, 5 years ago

branch merged with trunk @1645. arch file (ep&mpi) added for ADA

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