Changeset 732 for XIOS/trunk/src/buffer_client.cpp
- Timestamp:
- 10/13/15 15:14:23 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/buffer_client.cpp
r591 r732 10 10 namespace xios 11 11 { 12 size_t CClientBuffer::maxRequestSize = 0; 12 13 13 size_t maxRequestSize=0 ; 14 15 CClientBuffer::CClientBuffer(MPI_Comm interComm_,int serverRank_, StdSize bfSize) 14 CClientBuffer::CClientBuffer(MPI_Comm interComm_, int serverRank_, StdSize bfSize) 16 15 { 17 bufferSizeByServer=bfSize; //CXios::bufferSize ; 18 info(10)<<"bufferSizeByServer "<<bufferSizeByServer<<endl ; 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) ; 16 interComm = interComm_; 17 serverRank = serverRank_; 18 bufferSize = bfSize; 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 info(10) << "CClientBuffer: allocated " << bufferSize << " bytes for server " << serverRank_ << endl; 28 26 } 29 27 30 28 CClientBuffer::~CClientBuffer() 31 29 { 32 delete [] buffer[0] 33 delete [] buffer[1] 34 delete retBuffer 30 delete [] buffer[0]; 31 delete [] buffer[1]; 32 delete retBuffer; 35 33 } 36 34 37 35 int CClientBuffer::remain(void) 38 36 { 39 return bufferSize -count;37 return bufferSize - count; 40 38 } 41 39 42 40 bool CClientBuffer::isBufferFree(int size) 43 41 { 44 if (size >maxRequestSize) maxRequestSize=size;42 if (size > maxRequestSize) maxRequestSize = size; 45 43 46 if (size >bufferSize) ERROR("CClientBuffer::hasSpace(int size)",47 <<"request size is too big for buffer, increase buffer client size"<<endl48 <<"buffer_size must be > "<<size*2<<endl)44 if (size > bufferSize) 45 ERROR("bool CClientBuffer::isBufferFree(int size)", 46 << "The requested size (" << size << " bytes) is too big to fit the buffer (" << bufferSize << " bytes), please increase the client buffer size." << endl); 49 47 50 if (size<=remain()) return true ; 51 else return false ; 48 return (size <= remain()); 52 49 } 53 50 54 51 55 CBufferOut* 52 CBufferOut* CClientBuffer::getBuffer(int size) 56 53 { 57 if (size <=remain())54 if (size <= remain()) 58 55 { 59 retBuffer->realloc(buffer[current] +count,size);60 count +=size;61 return retBuffer 56 retBuffer->realloc(buffer[current] + count, size); 57 count += size; 58 return retBuffer; 62 59 } 63 60 else 64 61 { 65 ERROR("CBufferOut* CClientBuffer::getSpace(int size) ;",66 <<"No ennough space in buffer, that may not happen...");67 return NULL;62 ERROR("CBufferOut* CClientBuffer::getBuffer(int size)", 63 << "Not enough space in buffer, this should not have happened..."); 64 return NULL; 68 65 } 69 70 66 } 71 67 72 68 bool CClientBuffer::checkBuffer(void) 73 69 { 74 MPI_Status status 75 int flag 70 MPI_Status status; 71 int flag; 76 72 77 73 if (pending) 78 74 { 79 traceOff() 80 MPI_Test(&request, &flag,&status);81 traceOn() 82 if (flag ==true) pending=false;75 traceOff(); 76 MPI_Test(&request, &flag, &status); 77 traceOn(); 78 if (flag == true) pending = false; 83 79 } 84 80 85 81 if (!pending) 86 82 { 87 if (count >0)83 if (count > 0) 88 84 { 89 MPI_Issend(buffer[current], count,MPI_CHAR,serverRank,20,interComm,&request);90 pending =true;91 if (current ==1) current=0;92 else current =1;93 count =0;85 MPI_Issend(buffer[current], count, MPI_CHAR, serverRank, 20, interComm, &request); 86 pending = true; 87 if (current == 1) current = 0; 88 else current = 1; 89 count = 0; 94 90 } 95 91 } 96 return pending ; 92 93 return pending; 97 94 } 98 95 99 96 bool CClientBuffer::hasPendingRequest(void) 100 97 { 101 if (pending) return true ; 102 else if (count>0) return true ; 103 else return false ; 98 return (pending || count > 0); 104 99 } 105 106 107 108 100 } 109
Note: See TracChangeset
for help on using the changeset viewer.