source: XMLIO_V2/dev/common/src/buffer_client.cpp @ 300

Last change on this file since 300 was 300, checked in by ymipsl, 12 years ago

nouvelle version de developpement de xios

  • nouvelle interface fortran
  • recodage complet de la couche de communication
  • et bien d'autres choses...

YM

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