Ignore:
Timestamp:
06/20/18 09:09:23 (6 years ago)
Author:
ymipsl
Message:

New communication protocol between clients and servers, using hybrid mode of p2p mixt with one_sided communication in order to avoid dead-locking. The constraint of the maximum number of event that can be bufferized on client side is released.

Dev branch is created to be tested before merging.

YM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/dev_ym/XIOS_ONE_SIDED/src/buffer_server.cpp

    r885 r1547  
    77{ 
    88 
    9   CServerBuffer::CServerBuffer(StdSize buffSize) 
     9  CServerBuffer::CServerBuffer(StdSize buffSize) : hasWindows(false) 
    1010  { 
    1111    size = 3 * buffSize; 
     
    1313    current = 1; 
    1414    end = size; 
     15    used=0 ; 
    1516    buffer = new char[size]; // use MPI_ALLOC_MEM later? 
     17    currentWindows=0 ; 
    1618  } 
    1719 
     
    2123  } 
    2224 
     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  } 
    2360 
    2461  bool CServerBuffer::isBufferFree(size_t count) 
     
    72109  } 
    73110 
     111  bool CServerBuffer::isBufferEmpty(void) 
     112  { 
     113    if (used==0) return true ; 
     114    else return false; 
     115  } 
    74116 
    75117  void* CServerBuffer::getBuffer(size_t count) 
     
    128170    } 
    129171 
     172    used+=count ; 
    130173    return ret ; 
    131174  } 
     
    167210      } 
    168211    } 
    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    
    171264} 
Note: See TracChangeset for help on using the changeset viewer.