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