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