#include "xios_spl.hpp" #include "exception.hpp" #include "buffer_server.hpp" namespace xios { CServerBuffer::CServerBuffer(vector& windows, vector& winAddress, int windowsRank, StdSize buffSize) : hasWindows(true), windows_(windows), windowsRank_(windowsRank), winAddress_(winAddress) { size = 3 * buffSize; first = 0; current = 1; end = size; used=0 ; MPI_Alloc_mem(size, MPI_INFO_NULL, &buffer) ; currentWindows=1 ; if (windows[0]==MPI_WIN_NULL && windows[1]==MPI_WIN_NULL) hasWindows=false ; } CServerBuffer::~CServerBuffer() { MPI_Free_mem(buffer) ; } void CServerBuffer::updateCurrentWindows(void) { if (currentWindows==0) currentWindows=1 ; else currentWindows=0 ; } /* void CServerBuffer::createWindows(MPI_Comm oneSidedComm) { MPI_Barrier(oneSidedComm) ; MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, oneSidedComm, &(windows[0])) ; MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, oneSidedComm, &(windows[1])) ; hasWindows=true ; updateCurrentWindows() ; MPI_Barrier(oneSidedComm) ; } */ /* bool CServerBuffer::freeWindows() { if (hasWindows) { size_t header[3] ; size_t& control=header[2] ; MPI_Win_lock(MPI_LOCK_EXCLUSIVE,0,0,windows_[0]) ; MPI_Get(&control, 1, MPI_LONG_LONG_INT, windowsRank , 2*sizeof(size_t), 1, MPI_LONG_LONG_INT,windows[0]) ; MPI_Win_unlock(0,windows[0]) ; if (control==2) // ok for free windows { MPI_Win_free( &(windows[0])) ; MPI_Win_free( &(windows[1])) ; hasWindows=false ; return true ; } else return false ; } else return true ; } */ bool CServerBuffer::isBufferFree(size_t count) { bool ret ; if (count==0) return true ; if (current>first) { if (current+count0) { ret=true ; } else { ret=false ; } } else { if (countfirst) { if (current+count0) { ret=buffer+current ; current=0 ; } else { ERROR("void* CServerBuffer::getBuffer(size_t count)", <<"cannot allocate required size in buffer") ; } } else { end=current ; if (count