source: vendor/nemo/current/NEMOGCM/EXTERNAL/XIOS/src/buffer_client.cpp @ 44

Last change on this file since 44 was 44, checked in by cholod, 12 years ago

Load NEMO_TMP into vendor/nemo/current.

File size: 2.2 KB
Line 
1#include "xmlioserver_spl.hpp"
2#include "exception.hpp"
3#include "buffer_out.hpp"
4#include "buffer_client.hpp"
5#include "cxios.hpp"
6#include <mpi.h>
7#include "tracer.hpp"
8
9namespace xios
10{
11 
12  CClientBuffer::CClientBuffer(MPI_Comm interComm_,int serverRank_)
13  {
14    bufferSizeByServer=CXios::bufferSize ;
15    cout<<"bufferSizeByServer"<<bufferSizeByServer<<endl ;
16    interComm=interComm_ ;
17    serverRank=serverRank_ ;
18    bufferSize=bufferSizeByServer/2 ;
19    buffer[0]=new char[bufferSize] ; // transform it with MPI_ALLOC_MEM later
20    buffer[1]=new char[bufferSize] ;
21    current=0 ;
22    count=0 ;
23    pending=false ;
24    retBuffer=new CBufferOut(buffer[current],bufferSize) ;
25  }
26 
27  CClientBuffer::~CClientBuffer()
28  {
29   delete [] buffer[0] ;
30   delete [] buffer[1] ;
31   delete retBuffer ;
32  }
33 
34  int CClientBuffer::remain(void)
35  {
36    return bufferSize-count ;
37  }
38 
39  bool CClientBuffer::isBufferFree(int size)
40  {
41    if (size>bufferSize) ERROR("CClientBuffer::hasSpace(int size)",
42                               <<"request size is too big for buffer, increase buffer client size");
43 
44    if (size<=remain()) return true ;
45    else return false ;
46  }
47   
48 
49  CBufferOut*  CClientBuffer::getBuffer(int size)
50  {
51    if (size<=remain())
52    {
53      retBuffer->realloc(buffer[current]+count,size) ;
54      count+=size ;
55      return retBuffer ;
56    }
57    else
58    {
59       ERROR("CBufferOut*  CClientBuffer::getSpace(int size) ;",
60               <<"No ennough space in buffer, that may not happen...");
61       return NULL ;
62    }
63 
64  } 
65 
66  bool CClientBuffer::checkBuffer(void)
67  {
68    MPI_Status status ;
69    int flag ;
70   
71    if (pending)
72    {
73      traceOff() ;
74      MPI_Test(&request,&flag,&status) ;
75      traceOn() ;
76      if (flag==true) pending=false ;
77    }
78
79    if (!pending)
80    {
81      if (count>0)
82      {
83        MPI_Issend(buffer[current],count,MPI_CHAR,serverRank,20,interComm,&request) ;
84        pending=true ;
85        if (current==1) current=0 ;
86        else current=1 ;
87        count=0 ;
88      }
89    }
90    return pending ;
91  }
92 
93  bool CClientBuffer::hasPendingRequest(void)
94  {
95    if (pending) return true ;
96    else if (count>0) return true ;
97    else return false ;
98  }
99   
100 
101 
102}   
103   
Note: See TracBrowser for help on using the repository browser.