Ignore:
Timestamp:
05/26/15 16:13:47 (9 years ago)
Author:
rlacroix
Message:

Add basic infrastructure for servers to clients communication.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/node/context.cpp

    r595 r597  
    2323   CContext::CContext(void) 
    2424      : CObjectTemplate<CContext>(), CContextAttributes() 
    25       , calendar(),hasClient(false),hasServer(false), isPostProcessed(false), dataSize_(), idServer_() 
     25      , calendar(), hasClient(false), hasServer(false), isPostProcessed(false), finalized(false) 
     26      , dataSize_(), idServer_(), client(0), server(0) 
    2627   { /* Ne rien faire de plus */ } 
    2728 
    2829   CContext::CContext(const StdString & id) 
    2930      : CObjectTemplate<CContext>(id), CContextAttributes() 
    30       , calendar(),hasClient(false),hasServer(false), isPostProcessed(false), dataSize_(), idServer_() 
     31      , calendar(), hasClient(false), hasServer(false), isPostProcessed(false), finalized(false) 
     32      , dataSize_(), idServer_(), client(0), server(0) 
    3133   { /* Ne rien faire de plus */ } 
    3234 
    3335   CContext::~CContext(void) 
    3436   { 
    35      if (hasClient) delete client; 
    36      if (hasServer) delete server; 
     37     delete client; 
     38     delete server; 
    3739   } 
    3840 
     
    231233 
    232234   //! Initialize client side 
    233    void CContext::initClient(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtServer) 
     235   void CContext::initClient(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtServer /*= 0*/) 
    234236   { 
    235237     hasClient=true; 
    236238     client = new CContextClient(this,intraComm, interComm, cxtServer); 
     239     MPI_Comm intraCommServer, interCommServer; 
     240     if (cxtServer) // Attached mode 
     241     { 
     242       intraCommServer = intraComm; 
     243       interCommServer = interComm; 
     244     } 
     245     else 
     246     { 
     247       MPI_Comm_dup(intraComm, &intraCommServer); 
     248       MPI_Comm_dup(interComm, &interCommServer); 
     249     } 
     250     server = new CContextServer(this,intraCommServer,interCommServer); 
    237251   } 
    238252 
     
    277291 
    278292   //! Initialize server 
    279    void CContext::initServer(MPI_Comm intraComm,MPI_Comm interComm) 
     293   void CContext::initServer(MPI_Comm intraComm,MPI_Comm interComm, CContext* cxtClient /*= 0*/) 
    280294   { 
    281295     hasServer=true; 
    282296     server = new CContextServer(this,intraComm,interComm); 
     297     MPI_Comm intraCommClient, interCommClient; 
     298     if (cxtClient) // Attached mode 
     299     { 
     300       intraCommClient = intraComm; 
     301       interCommClient = interComm; 
     302     } 
     303     else 
     304     { 
     305       MPI_Comm_dup(intraComm, &intraCommClient); 
     306       MPI_Comm_dup(interComm, &interCommClient); 
     307     } 
     308     client = new CContextClient(this,intraCommClient,interCommClient, cxtClient); 
     309     // Do something clever instead 
     310     std::map<int, StdSize> bufferSize; 
     311     for (int r = 0; r < client->serverSize; r++) 
     312       bufferSize[r] = 10 * sizeof(size_t) * 1024; 
     313     client->setBufferSize(bufferSize); 
    283314   } 
    284315 
     
    289320   } 
    290321 
     322   //! Try to send the buffers and receive possible answers 
     323   bool CContext::checkBuffersAndListen(void) 
     324   { 
     325     client->checkBuffers(); 
     326     return server->eventLoop(); 
     327   } 
     328 
    291329   //! Terminate a context 
    292330   void CContext::finalize(void) 
    293331   { 
    294       if (hasClient && !hasServer) 
    295       { 
    296          client->finalize(); 
    297       } 
    298       if (hasServer) 
    299       { 
    300         closeAllFile(); 
     332      if (!finalized) 
     333      { 
     334        finalized = true; 
     335 
     336        client->finalize(); 
     337        while (!server->hasFinished()) 
     338        { 
     339          server->eventLoop(); 
     340        } 
     341 
     342        if (hasServer) 
     343        { 
     344          closeAllFile(); 
     345        } 
    301346      } 
    302347   } 
Note: See TracChangeset for help on using the changeset viewer.