Changeset 1547 for XIOS/dev/dev_ym/XIOS_ONE_SIDED/src/buffer_server.cpp
- Timestamp:
- 06/20/18 09:09:23 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/dev_ym/XIOS_ONE_SIDED/src/buffer_server.cpp
r885 r1547 7 7 { 8 8 9 CServerBuffer::CServerBuffer(StdSize buffSize) 9 CServerBuffer::CServerBuffer(StdSize buffSize) : hasWindows(false) 10 10 { 11 11 size = 3 * buffSize; … … 13 13 current = 1; 14 14 end = size; 15 used=0 ; 15 16 buffer = new char[size]; // use MPI_ALLOC_MEM later? 17 currentWindows=0 ; 16 18 } 17 19 … … 21 23 } 22 24 25 void CServerBuffer::updateCurrentWindows(void) 26 { 27 if (currentWindows==0) currentWindows=1 ; 28 else currentWindows=0 ; 29 } 30 31 void CServerBuffer::createWindows(MPI_Comm oneSidedComm) 32 { 33 MPI_Barrier(oneSidedComm) ; 34 MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, oneSidedComm, &(windows[0])) ; 35 MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, oneSidedComm, &(windows[1])) ; 36 hasWindows=true ; 37 MPI_Barrier(oneSidedComm) ; 38 } 39 40 bool CServerBuffer::freeWindows() 41 { 42 if (hasWindows) 43 { 44 size_t header[3] ; 45 size_t& control=header[2] ; 46 MPI_Win_lock(MPI_LOCK_EXCLUSIVE,0,0,windows[0]) ; 47 MPI_Get(&control, 1, MPI_LONG_LONG_INT, 0 , 2*sizeof(size_t), 1, MPI_LONG_LONG_INT,windows[0]) ; 48 MPI_Win_unlock(0,windows[0]) ; 49 if (control==2) // ok for free windows 50 { 51 MPI_Win_free( &(windows[0])) ; 52 MPI_Win_free( &(windows[1])) ; 53 hasWindows=false ; 54 return true ; 55 } 56 else return false ; 57 } 58 else return true ; 59 } 23 60 24 61 bool CServerBuffer::isBufferFree(size_t count) … … 72 109 } 73 110 111 bool CServerBuffer::isBufferEmpty(void) 112 { 113 if (used==0) return true ; 114 else return false; 115 } 74 116 75 117 void* CServerBuffer::getBuffer(size_t count) … … 128 170 } 129 171 172 used+=count ; 130 173 return ret ; 131 174 } … … 167 210 } 168 211 } 169 } 170 212 used-=count ; 213 } 214 215 bool CServerBuffer::getBufferFromClient(size_t timeLine, char*& buffer, size_t& count) 216 { 217 if (!hasWindows) return false ; 218 219 220 size_t header[3] ; 221 size_t& clientTimeline=header[0] ; 222 size_t& clientCount=header[1] ; 223 size_t& control=header[2] ; 224 bool ok=false ; 225 226 MPI_Win_lock(MPI_LOCK_EXCLUSIVE,0,0,windows[currentWindows]) ; 227 228 MPI_Get(&clientTimeline, 1, MPI_LONG_LONG_INT, 0 , 0, 1, MPI_LONG_LONG_INT,windows[currentWindows]) ; 229 MPI_Get(&clientCount, 1, MPI_LONG_LONG_INT, 0 , 1*sizeof(size_t), 1, MPI_LONG_LONG_INT,windows[currentWindows]) ; 230 control=1 ; 231 MPI_Put(&control, 1, MPI_LONG_LONG_INT, 0 , 2*sizeof(size_t), 1, MPI_LONG_LONG_INT,windows[currentWindows]) ; 232 233 MPI_Win_unlock(0,windows[currentWindows]) ; 234 235 if (timeLine==clientTimeline) 236 { 237 238 MPI_Win_lock(MPI_LOCK_EXCLUSIVE,0,0,windows[currentWindows]) ; 239 buffer=(char*)getBuffer(clientCount) ; 240 count=clientCount ; 241 MPI_Get(buffer, clientCount, MPI_CHAR, 0, 3*sizeof(size_t) , clientCount, MPI_CHAR, windows[currentWindows]) ; 242 clientTimeline = 0 ; 243 clientCount = 0 ; 244 control=0 ; 245 MPI_Put(&header[0], 3, MPI_LONG_LONG_INT, 0, 0 , 3, MPI_LONG_LONG_INT,windows[currentWindows]) ; 246 247 MPI_Win_unlock(0,windows[currentWindows]) ; 248 ok=true ; 249 } 250 else 251 { 252 MPI_Win_lock(MPI_LOCK_EXCLUSIVE,0,0,windows[currentWindows]) ; 253 control=0 ; 254 MPI_Put(&control, 1, MPI_LONG_LONG_INT, 0 , 2*sizeof(size_t), 1, MPI_LONG_LONG_INT,windows[currentWindows]) ; 255 MPI_Win_unlock(0,windows[currentWindows]) ; 256 } 257 258 if (ok) return true ; 259 260 return false ; 261 } 262 263 171 264 }
Note: See TracChangeset
for help on using the changeset viewer.