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

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

modif for Curie, CurrContext?->CurrContext_ptr in object_factory and group_factory

  • 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.5 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
[1037]10
[335]11namespace xios
[300]12{
[732]13  size_t CClientBuffer::maxRequestSize = 0;
[509]14
[917]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)
[300]24  {
[732]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);
[1094]28    //info(10) << "CClientBuffer: allocated 2 x " << bufferSize << " bytes for server " << serverRank << " with a maximum of " << maxBufferedEvents << " buffered events" << endl;
[300]29  }
[509]30
[300]31  CClientBuffer::~CClientBuffer()
32  {
[732]33   delete [] buffer[0];
34   delete [] buffer[1];
35   delete retBuffer;
[300]36  }
[509]37
[300]38  int CClientBuffer::remain(void)
39  {
[732]40    return bufferSize - count;
[300]41  }
[509]42
[300]43  bool CClientBuffer::isBufferFree(int size)
44  {
[732]45    if (size > maxRequestSize) maxRequestSize = size;
[509]46
[732]47    if (size > bufferSize)
48      ERROR("bool CClientBuffer::isBufferFree(int size)",
49            << "The requested size (" << size << " bytes) is too big to fit the buffer (" << bufferSize << " bytes), please increase the client buffer size." << endl);
[509]50
[917]51    return (size <= remain() && bufferedEvents < maxBufferedEvents);
[300]52  }
[509]53
54
[732]55  CBufferOut* CClientBuffer::getBuffer(int size)
[300]56  {
[732]57    if (size <= remain())
[300]58    {
[732]59      retBuffer->realloc(buffer[current] + count, size);
60      count += size;
[917]61      bufferedEvents++;
[732]62      return retBuffer;
[300]63    }
64    else
65    {
[732]66      ERROR("CBufferOut* CClientBuffer::getBuffer(int size)",
67            << "Not enough space in buffer, this should not have happened...");
68      return NULL;
[300]69    }
[509]70  }
71
[300]72  bool CClientBuffer::checkBuffer(void)
73  {
[732]74    MPI_Status status;
75    int flag;
[509]76
[300]77    if (pending)
78    {
[732]79      traceOff();
80      MPI_Test(&request, &flag, &status);
81      traceOn();
82      if (flag == true) pending = false;
[300]83    }
84
85    if (!pending)
86    {
[732]87      if (count > 0)
[300]88      {
[732]89        MPI_Issend(buffer[current], count, MPI_CHAR, serverRank, 20, interComm, &request);
90        pending = true;
91        if (current == 1) current = 0;
92        else current = 1;
93        count = 0;
[917]94        bufferedEvents = 0;
[300]95      }
96    }
[732]97
98    return pending;
[300]99  }
[509]100
[300]101  bool CClientBuffer::hasPendingRequest(void)
102  {
[732]103    return (pending || count > 0);
[300]104  }
[509]105}
Note: See TracBrowser for help on using the repository browser.