[300] | 1 | #include "xmlioserver_spl.hpp" |
---|
| 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 | |
---|
[335] | 10 | namespace xios |
---|
[300] | 11 | { |
---|
[317] | 12 | |
---|
[400] | 13 | size_t maxRequestSize=0 ; |
---|
| 14 | |
---|
[300] | 15 | CClientBuffer::CClientBuffer(MPI_Comm interComm_,int serverRank_) |
---|
| 16 | { |
---|
[317] | 17 | bufferSizeByServer=CXios::bufferSize ; |
---|
[380] | 18 | info(10)<<"bufferSizeByServer "<<bufferSizeByServer<<endl ; |
---|
[300] | 19 | interComm=interComm_ ; |
---|
| 20 | serverRank=serverRank_ ; |
---|
| 21 | bufferSize=bufferSizeByServer/2 ; |
---|
| 22 | buffer[0]=new char[bufferSize] ; // transform it with MPI_ALLOC_MEM later |
---|
| 23 | buffer[1]=new char[bufferSize] ; |
---|
| 24 | current=0 ; |
---|
| 25 | count=0 ; |
---|
| 26 | pending=false ; |
---|
| 27 | retBuffer=new CBufferOut(buffer[current],bufferSize) ; |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | CClientBuffer::~CClientBuffer() |
---|
| 31 | { |
---|
| 32 | delete [] buffer[0] ; |
---|
| 33 | delete [] buffer[1] ; |
---|
| 34 | delete retBuffer ; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | int CClientBuffer::remain(void) |
---|
| 38 | { |
---|
| 39 | return bufferSize-count ; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | bool CClientBuffer::isBufferFree(int size) |
---|
| 43 | { |
---|
[400] | 44 | if (size>maxRequestSize) maxRequestSize=size ; |
---|
| 45 | |
---|
[300] | 46 | if (size>bufferSize) ERROR("CClientBuffer::hasSpace(int size)", |
---|
[400] | 47 | <<"request size is too big for buffer, increase buffer client size"<<endl |
---|
| 48 | <<"Current buffer_size : "<<CXios::bufferSize<<endl |
---|
| 49 | <<"buffer_size must be > "<<size*2<<endl) |
---|
[300] | 50 | |
---|
| 51 | if (size<=remain()) return true ; |
---|
| 52 | else return false ; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | CBufferOut* CClientBuffer::getBuffer(int size) |
---|
| 57 | { |
---|
| 58 | if (size<=remain()) |
---|
| 59 | { |
---|
| 60 | retBuffer->realloc(buffer[current]+count,size) ; |
---|
| 61 | count+=size ; |
---|
| 62 | return retBuffer ; |
---|
| 63 | } |
---|
| 64 | else |
---|
| 65 | { |
---|
| 66 | ERROR("CBufferOut* CClientBuffer::getSpace(int size) ;", |
---|
| 67 | <<"No ennough space in buffer, that may not happen..."); |
---|
| 68 | return NULL ; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | bool CClientBuffer::checkBuffer(void) |
---|
| 74 | { |
---|
| 75 | MPI_Status status ; |
---|
| 76 | int flag ; |
---|
| 77 | |
---|
| 78 | if (pending) |
---|
| 79 | { |
---|
[347] | 80 | traceOff() ; |
---|
[300] | 81 | MPI_Test(&request,&flag,&status) ; |
---|
[347] | 82 | traceOn() ; |
---|
[300] | 83 | if (flag==true) pending=false ; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | if (!pending) |
---|
| 87 | { |
---|
| 88 | if (count>0) |
---|
| 89 | { |
---|
| 90 | MPI_Issend(buffer[current],count,MPI_CHAR,serverRank,20,interComm,&request) ; |
---|
| 91 | pending=true ; |
---|
| 92 | if (current==1) current=0 ; |
---|
| 93 | else current=1 ; |
---|
| 94 | count=0 ; |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | return pending ; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | bool CClientBuffer::hasPendingRequest(void) |
---|
| 101 | { |
---|
| 102 | if (pending) return true ; |
---|
| 103 | else if (count>0) return true ; |
---|
| 104 | else return false ; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | } |
---|
| 110 | |
---|