Index: XIOS/trunk/src/client.cpp
===================================================================
--- XIOS/trunk/src/client.cpp	(revision 510)
+++ XIOS/trunk/src/client.cpp	(revision 511)
@@ -132,6 +132,6 @@
         CTimer::get("XIOS").resume() ;
         CTimer::get("XIOS init").resume() ;
-  
-        if (CXios::usingServer) 
+
+        if (CXios::usingServer)
         {
           MPI_Status status ;
@@ -153,5 +153,7 @@
     {
       CContext::setCurrent(id) ;
-      CContext* context=CContext::create(id) ;
+      CContext* context=CContext::create(id);
+      StdString idServer(id);
+      idServer += "_server";
 
       if (!CXios::isServer)
@@ -169,5 +171,6 @@
 
         CMessage msg ;
-        msg<<id<<size<<globalRank ;
+        msg<<idServer<<size<<globalRank ;
+//        msg<<id<<size<<globalRank ;
 
         int messageSize=msg.size() ;
@@ -192,6 +195,16 @@
         MPI_Comm contextInterComm ;
         MPI_Comm_dup(contextComm,&contextInterComm) ;
-        context->initClient(contextComm,contextInterComm) ;
-        context->initServer(contextComm,contextInterComm) ;
+        CContext* contextServer = CContext::create(idServer);
+
+        // Firstly, initialize context on client side
+        context->initClient(contextComm,contextInterComm, contextServer);
+
+
+        // Secondly, initialize context on server side
+        contextServer->initServer(contextComm,contextInterComm);
+
+        // Finally, we should return current context to context client
+        CContext::setCurrent(id);
+//        context->initServer(contextComm,contextInterComm) ;
       }
     }
@@ -223,6 +236,6 @@
       report(0)<< " Performance report : Ratio : "<< CTimer::get("Blocking time").getCumulatedTime()/CTimer::get("XIOS").getCumulatedTime()*100.<<" %"<<endl ;
       report(0)<< " Performance report : This ratio must be close to zero. Otherwise it may be usefull to increase buffer size or numbers of server"<<endl ;
-      report(0)<< " Memory report : Current buffer_size : "<<CXios::bufferSize<<endl ;
-      report(0)<< " Memory report : Minimum buffer size required : "<<maxRequestSize*2<<endl ;
+//      report(0)<< " Memory report : Current buffer_size : "<<CXios::bufferSize<<endl ;
+      report(0)<< " Memory report : Minimum buffer size required : "<<maxRequestSize*2<< " bytes" << endl ;
       report(0)<< " Memory report : increasing it by a factor will increase performance, depending of the volume of data wrote in file at each time step of the file"<<endl ;
    }
Index: XIOS/trunk/src/context_client.cpp
===================================================================
--- XIOS/trunk/src/context_client.cpp	(revision 510)
+++ XIOS/trunk/src/context_client.cpp	(revision 511)
@@ -17,5 +17,6 @@
 
 
-    CContextClient::CContextClient(CContext* parent,MPI_Comm intraComm_, MPI_Comm interComm_) : mapBufferSize_()
+    CContextClient::CContextClient(CContext* parent,MPI_Comm intraComm_, MPI_Comm interComm_, CContext* cxtSer)
+     : mapBufferSize_(), parentServer(cxtSer)
     {
       context=parent ;
@@ -61,5 +62,11 @@
       }
 
-      if (context->hasServer) waitEvent(ranks) ;
+//      if (context->hasServer)
+      if (0 != parentServer)
+      {
+        waitEvent(ranks);
+        CContext::setCurrent(context->getId());
+      }
+
       timeLine++ ;
     }
@@ -92,14 +99,26 @@
     void CContextClient::waitEvent(list<int>& ranks)
     {
-      context->server->setPendingEvent() ;
+//      context->server->setPendingEvent() ;
+//      while(checkBuffers(ranks))
+//      {
+//        context->server->listen() ;
+//        context->server->checkPendingRequest() ;
+//      }
+//
+//      while(context->server->hasPendingEvent())
+//      {
+//       context->server->eventLoop() ;
+//      }
+
+      parentServer->server->setPendingEvent() ;
       while(checkBuffers(ranks))
       {
-        context->server->listen() ;
-        context->server->checkPendingRequest() ;
-      }
-
-      while(context->server->hasPendingEvent())
-      {
-       context->server->eventLoop() ;
+        parentServer->server->listen() ;
+        parentServer->server->checkPendingRequest() ;
+      }
+
+      while(parentServer->server->hasPendingEvent())
+      {
+       parentServer->server->eventLoop() ;
       }
 
@@ -240,5 +259,16 @@
      }
      CTimer::get("Blocking time").suspend();
-     report(0)<< " Memory report : Context <"<<context->getId()<<"> : client side : total memory used for buffer "<<buffers.size()*CXios::bufferSize<<" bytes"<<endl ;
+//     report(0)<< " Memory report : Context <"<<context->getId()<<"> : client side : total memory used for buffer "<<buffers.size()*CXios::bufferSize<<" bytes"<<endl ;
+
+     std::map<int, StdSize>::const_iterator itbMap = mapBufferSize_.begin(),
+                                            iteMap = mapBufferSize_.end(), itMap;
+     StdSize totalBuf = 0;
+     for (itMap = itbMap; itMap != iteMap; ++itMap)
+     {
+       report(10)<< " Memory report : Context <"<<context->getId()<<"> : client side : memory used for buffer of each connection to server" << endl
+                 << "  +)To server with rank " << itMap->first << " : " << itMap->second << " bytes " << endl;
+       totalBuf += itMap->second;
+     }
+     report(0)<< " Memory report : Context <"<<context->getId()<<"> : client side : total memory used for buffer "<<totalBuf<<" bytes"<<endl ;
 
      releaseBuffers() ;
Index: XIOS/trunk/src/context_client.hpp
===================================================================
--- XIOS/trunk/src/context_client.hpp	(revision 510)
+++ XIOS/trunk/src/context_client.hpp	(revision 511)
@@ -16,5 +16,5 @@
 
     public:
-    CContextClient(CContext* parent,MPI_Comm intraComm, MPI_Comm interComm) ;
+    CContextClient(CContext* parent,MPI_Comm intraComm, MPI_Comm interComm, CContext* parentServer = 0) ;
 //    void registerEvent(CEventClient& event) ;
 
@@ -48,4 +48,5 @@
     private:
     std::map<int, StdSize> mapBufferSize_;
+    CContext* parentServer;
 //    bool locked ;
 
Index: XIOS/trunk/src/context_server.cpp
===================================================================
--- XIOS/trunk/src/context_server.cpp	(revision 510)
+++ XIOS/trunk/src/context_server.cpp	(revision 511)
@@ -83,4 +83,5 @@
             StdSize buffSize = 0;
             MPI_Recv(&buffSize, 1, MPI_LONG, rank, 20, interComm, &status);
+            mapBufferSize_.insert(std::make_pair(rank, buffSize));
             it=(buffers.insert(pair<int,CServerBuffer*>(rank,new CServerBuffer(buffSize)))).first ;
           }
@@ -207,7 +208,16 @@
     {
       info(20)<<"Server Side context <"<<context->getId()<<"> finalized"<<endl ;
+      std::map<int, StdSize>::const_iterator itbMap = mapBufferSize_.begin(),
+                                             iteMap = mapBufferSize_.end(), itMap;
+      StdSize totalBuf = 0;
+      for (itMap = itbMap; itMap != iteMap; ++itMap)
+      {
+        report(10)<< " Memory report : Context <"<<context->getId()<<"> : server side : memory used for buffer of each connection to client" << endl
+                  << "  +) With client of rank " << itMap->first << " : " << itMap->second << " bytes " << endl;
+        totalBuf += itMap->second;
+      }
       context->finalize() ;
       finished=true ;
-      report(0)<< " Memory report : Context <"<<context->getId()<<"> : server side : total memory used for buffer "<<buffers.size()*CXios::bufferSize<<" bytes"<<endl ;
+      report(0)<< " Memory report : Context <"<<context->getId()<<"> : server side : total memory used for buffer "<<totalBuf<<" bytes"<<endl ;
     }
     else if (event.classId==CContext::GetType()) CContext::dispatchEvent(event) ;
Index: XIOS/trunk/src/context_server.hpp
===================================================================
--- XIOS/trunk/src/context_server.hpp	(revision 510)
+++ XIOS/trunk/src/context_server.hpp	(revision 511)
@@ -9,9 +9,9 @@
 {
   class CContext ;
-  
+
   class CContextServer
   {
     public:
-    
+
     CContextServer(CContext* parent,MPI_Comm intraComm,MPI_Comm interComm) ;
     bool eventLoop(void) ;
@@ -23,25 +23,28 @@
     void setPendingEvent(void) ;
     bool hasPendingEvent(void) ;
-    
+
     MPI_Comm intraComm ;
     int intraCommSize ;
     int intraCommRank ;
-    
+
     MPI_Comm interComm ;
     int commSize ;
-  
+
     map<int,CServerBuffer*> buffers ;
     map<int,MPI_Request> pendingRequest ;
     map<int,char*> bufferRequest ;
-    
+
     map<size_t,CEventServer*> events ;
     size_t currentTimeLine ;
     CContext* context ;
-    
+
     bool finished ;
     bool pendingEvent ;
     bool scheduled  ;    /*!< event of current timeline is alreading scheduled ? */
     size_t hashId ;
-    ~CContextServer() ;    
+    ~CContextServer() ;
+
+    private:
+      std::map<int, StdSize> mapBufferSize_;
   } ;
 
Index: XIOS/trunk/src/cxios.cpp
===================================================================
--- XIOS/trunk/src/cxios.cpp	(revision 510)
+++ XIOS/trunk/src/cxios.cpp	(revision 511)
@@ -29,5 +29,5 @@
   bool CXios::printInfo2File;
   bool CXios::isServerSide;
-
+  bool CXios::isOptPerformance = true;
 
   void CXios::initialize()
@@ -35,13 +35,29 @@
     set_new_handler(noMemory);
     parseFile(rootFile);
+    parseXiosConfig();
+  }
+
+  void CXios::parseXiosConfig()
+  {
     usingOasis=getin<bool>("using_oasis",false) ;
     usingServer=getin<bool>("using_server",false) ;
     info.setLevel(getin<int>("info_level",0)) ;
+    report.setLevel(getin<int>("info_level",0));
     printInfo2File=getin<bool>("print_file",false);
     bufferSize=getin<size_t>("buffer_size",defaultBufferSize) ;
-    bufferServerFactorSize=getin<double>("buffer_server_factor_size",defaultBufferServerFactorSize) ;
+    StdString bufMemory("memory");
+    StdString bufPerformance("performance");
+    StdString bufOpt = getin<StdString>("optimal_buffer_size", bufPerformance);
+    std::transform(bufOpt.begin(), bufOpt.end(), bufOpt.begin(), ::tolower);
+    if (0 == bufOpt.compare(bufMemory)) isOptPerformance = false;
+    else if (0 != bufOpt.compare(bufPerformance))
+    {
+      ERROR("CXios::parseXiosConfig()", << "optimal_buffer_size must be memory or performance "<< endl );
+    }
+
+//    bufferServerFactorSize=getin<double>("buffer_server_factor_size",defaultBufferServerFactorSize) ;
+    bufferServerFactorSize=getin<double>("buffer_factor_size",defaultBufferServerFactorSize) ;
     globalComm=MPI_COMM_WORLD ;
   }
-
 
   void CXios::initClientSide(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm)
@@ -79,12 +95,5 @@
     parseList.insert("xios");
     xml::CXMLParser::ParseFile(rootFile, parseList);
-//    parseFile(rootFile);
-    usingOasis=getin<bool>("using_oasis",false) ;
-    info.setLevel(getin<int>("info_level",0)) ;
-    printInfo2File=getin<bool>("print_file",false);
-    bufferSize=getin<size_t>("buffer_size",defaultBufferSize) ;
-    bufferServerFactorSize=getin<double>("buffer_server_factor_size",defaultBufferServerFactorSize) ;
-    globalComm=MPI_COMM_WORLD ;
-
+    parseXiosConfig();
   }
 
Index: XIOS/trunk/src/cxios.hpp
===================================================================
--- XIOS/trunk/src/cxios.hpp	(revision 510)
+++ XIOS/trunk/src/cxios.hpp	(revision 511)
@@ -42,4 +42,5 @@
      static double bufferServerFactorSize ;
      static double defaultBufferServerFactorSize ;
+     static bool isOptPerformance;
 
      public:
@@ -54,4 +55,7 @@
 
      static  void initServer();
+
+     private:
+      static void parseXiosConfig();
 
   } ;
Index: XIOS/trunk/src/node/context.cpp
===================================================================
--- XIOS/trunk/src/node/context.cpp	(revision 510)
+++ XIOS/trunk/src/node/context.cpp	(revision 511)
@@ -23,10 +23,10 @@
    CContext::CContext(void)
       : CObjectTemplate<CContext>(), CContextAttributes()
-      , calendar(),hasClient(false),hasServer(false), isPostProcessed(false), dataSize_()
+      , calendar(),hasClient(false),hasServer(false), isPostProcessed(false), dataSize_(), idServer_()
    { /* Ne rien faire de plus */ }
 
    CContext::CContext(const StdString & id)
       : CObjectTemplate<CContext>(id), CContextAttributes()
-      , calendar(),hasClient(false),hasServer(false), isPostProcessed(false), dataSize_()
+      , calendar(),hasClient(false),hasServer(false), isPostProcessed(false), dataSize_(), idServer_()
    { /* Ne rien faire de plus */ }
 
@@ -280,8 +280,8 @@
 
    //! Initialize client side
-   void CContext::initClient(MPI_Comm intraComm, MPI_Comm interComm)
+   void CContext::initClient(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtServer)
    {
      hasClient=true ;
-     client = new CContextClient(this,intraComm, interComm) ;
+     client = new CContextClient(this,intraComm, interComm, cxtServer) ;
    }
 
@@ -575,5 +575,5 @@
      {
        CMessage msg ;
-       msg<<this->getId() ;
+       msg<<this->getIdServer() ;
        event.push(client->getServerLeader(),1,msg) ;
        client->sendEvent(event) ;
@@ -601,5 +601,5 @@
        {
          CMessage msg ;
-         msg<<this->getId()<<step ;
+         msg<<this->getIdServer()<<step ;
          event.push(client->getServerLeader(),1,msg) ;
          client->sendEvent(event) ;
@@ -634,5 +634,5 @@
      {
        CMessage msg ;
-       msg<<this->getId() ;
+       msg<<this->getIdServer() ;
        event.push(client->getServerLeader(),1,msg) ;
        client->sendEvent(event) ;
@@ -665,5 +665,5 @@
        {
          CMessage msg ;
-         msg<<this->getId();
+         msg<<this->getIdServer();
          event.push(client->getServerLeader(),1,msg) ;
          client->sendEvent(event) ;
@@ -686,4 +686,15 @@
    {
       postProcessing();
+   }
+
+   const StdString& CContext::getIdServer()
+   {
+      if (hasClient)
+      {
+        idServer_ = this->getId();
+        idServer_ += "_server";
+        return idServer_;
+      }
+      if (hasServer) return (this->getId());
    }
 
@@ -736,7 +747,7 @@
          else
          {
+           std::map<int, StdSize>::const_iterator it = mapSize.begin(), itE = mapSize.end();
            if (domainIds.find(prDomAxisId.first) == domainIds.end())
            {
-             std::map<int, StdSize>::const_iterator it = mapSize.begin(), itE = mapSize.end();
              for (; it != itE; ++it)
              {
@@ -744,8 +755,18 @@
                else dataSize_.insert(make_pair(it->first, it->second));
              }
+           } else
+           {
+             for (; it != itE; ++it)
+             {
+               if (0 < dataSize_.count(it->first))
+                if (CXios::isOptPerformance) dataSize_[it->first] += it->second;
+                else
+                {
+                  if (dataSize_[it->first] < it->second) dataSize_[it->first] = it->second;
+                }
+               else dataSize_.insert(make_pair(it->first, it->second));
+             }
            }
-
          }
-
        }
      }
Index: XIOS/trunk/src/node/context.hpp
===================================================================
--- XIOS/trunk/src/node/context.hpp	(revision 510)
+++ XIOS/trunk/src/node/context.hpp	(revision 511)
@@ -88,5 +88,5 @@
          // Initialize server or client
          void initServer(MPI_Comm intraComm, MPI_Comm interComm) ;
-         void initClient(MPI_Comm intraComm, MPI_Comm interComm) ;
+         void initClient(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtServer=0) ;
          bool isInitialized(void) ;
 
@@ -129,4 +129,6 @@
          void sendPostProcessing();
 
+         const StdString& getIdServer();
+
          // Client side: Receive and process messages
          static void recvUpdateCalendar(CEventServer& event) ;
@@ -206,4 +208,5 @@
          bool isPostProcessed;
          std::map<int, StdSize> dataSize_;
+         StdString idServer_;
 
 
Index: XIOS/trunk/src/node/grid.cpp
===================================================================
--- XIOS/trunk/src/node/grid.cpp	(revision 510)
+++ XIOS/trunk/src/node/grid.cpp	(revision 511)
@@ -177,5 +177,5 @@
        if (this->withAxis) retVal *= this->axis->size.getValue();
        retVal *= sizeof(double);
-       retVal *= 1.2; // Secure factor
+       retVal *= 1.2 * CXios::bufferServerFactorSize; // Secure factor
        ret.insert(make_pair(it->first, retVal));
      }
Index: XIOS/trunk/src/object.cpp
===================================================================
--- XIOS/trunk/src/object.cpp	(revision 510)
+++ XIOS/trunk/src/object.cpp	(revision 511)
@@ -20,21 +20,26 @@
    { /* Ne rien faire de plus */ }
 
-   const StdString & CObject::getId(void) const 
-   { 
+   const StdString & CObject::getId(void) const
+   {
       return (this->id);
    }
 
-   bool CObject::hasId(void) const  
-   { 
+   const StdString& CObject::getIdServer()
+   {
+      return (this->id);
+   }
+
+   bool CObject::hasId(void) const
+   {
       return (this->IdDefined);
    }
 
-   void CObject::resetId(void) 
-   { 
+   void CObject::resetId(void)
+   {
       this->IdDefined = false ;
    }
 
    void CObject::setId(const StdString & id)
-   { 
+   {
       this->id = id ;
       this->IdDefined = true ;
@@ -49,10 +54,10 @@
 
    bool CObject::operator!=(const CObject & other) const
-   { 
+   {
       return (!(*this == other));
    }
 */
    StdOStream & operator << (StdOStream & os, const CObject & object)
-   { 
+   {
       os << object.toString();
       return (os);
Index: XIOS/trunk/src/object.hpp
===================================================================
--- XIOS/trunk/src/object.hpp	(revision 510)
+++ XIOS/trunk/src/object.hpp	(revision 511)
@@ -18,4 +18,6 @@
          /// Accesseurs ///
          const StdString & getId(void) const;
+
+         virtual const StdString& getIdServer();
 
          /// Mutateurs ///
Index: XIOS/trunk/src/object_template_impl.hpp
===================================================================
--- XIOS/trunk/src/object_template_impl.hpp	(revision 510)
+++ XIOS/trunk/src/object_template_impl.hpp	(revision 511)
@@ -193,5 +193,6 @@
        {
          CMessage msg ;
-         msg<<this->getId() ;
+//         msg<<this->getId() ;
+         msg<<this->getIdServer();
          msg<<attr.getName() ;
          msg<<attr ;
