Index: /XIOS3/trunk/src/node/context.cpp
===================================================================
--- /XIOS3/trunk/src/node/context.cpp	(revision 2404)
+++ /XIOS3/trunk/src/node/context.cpp	(revision 2405)
@@ -49,5 +49,5 @@
       , allProcessed(false), countChildContextFinalized_(0), isProcessingEvent_(false)
 
-   { /* Ne rien faire de plus */ }
+   { /* Ne rien faire de plus */  }
 
    CContext::CContext(const StdString & id)
@@ -542,5 +542,74 @@
   CATCH_DUMP_ATTR
 
+  
+  void CContext::createServerInterComm(const string& poolId, const string& serverId, vector<pair<string, pair<CContextClient*,CContextServer*>>>& clientServers )
+  TRY
+  {
+    MPI_Comm interCommClient, interCommServer ;
+    int commRank ;
+    MPI_Comm_rank(intraComm_,&commRank) ;
+    
+    int nbPartitions ;
+    if (commRank==0)
+    {
+      CXios::getServicesManager()->getServiceNbPartitions(poolId, serverId, 0, nbPartitions) ;
+      for(int i=0 ; i<nbPartitions; i++) CXios::getContextsManager()->createServerContext(poolId, serverId, i, getContextId()) ;
+    }
+    setCurrent(getId()) ; // getCurrent/setCurrent may be supress, it can cause a lot of trouble (attached ???)
+    MPI_Bcast(&nbPartitions, 1, MPI_INT, 0, intraComm_) ;
+      
+    MPI_Comm interComm ;
+    for(int i=0 ; i<nbPartitions; i++)
+    {
+      parentServerContext_->createIntercomm(poolId, serverId, i, getContextId(), intraComm_, interCommClient, interCommServer) ;
+      int type ; 
+      if (commRank==0) CXios::getServicesManager()->getServiceType(poolId, serverId, 0, type) ;
+      MPI_Bcast(&type,1,MPI_INT,0,intraComm_) ;
+      string fullServerId=CXios::getContextsManager()->getServerContextName(poolId, serverId, i, type, getContextId()) ;
+
+      MPI_Comm intraCommClient, intraCommServer ;
+
+      intraCommClient=intraComm_ ;
+      MPI_Comm_dup(intraComm_, &intraCommServer) ;
+
+      CContextClient* client = CContextClient::getNew(this, intraCommClient, interCommClient) ;
+      CContextServer* server = CContextServer::getNew(this, intraCommServer, interCommServer) ;
+      client->setAssociatedServer(server) ;
+      server->setAssociatedClient(client) ;
+      
+      clientServers.push_back({fullServerId,{client,server}}) ;
+    }
+  }
+  CATCH_DUMP_ATTR
+  
   void CContext::createServerInterComm(void) 
+  TRY
+  {
+    vector<pair<string, pair<CContextClient*,CContextServer*>>> clientServers ;
+
+    if (serviceType_ == CServicesManager::CLIENT)
+    {
+      if (attached_mode) createServerInterComm(CClient::getPoolRessource()->getId(), getContextId()+"_"+CXios::defaultServerId, clientServers) ;
+      else if (CXios::usingServer2) createServerInterComm(CXios::defaultPoolId, CXios::defaultGathererId, clientServers) ;
+      else createServerInterComm(CXios::defaultPoolId, CXios::defaultServerId, clientServers) ;
+      
+      client = clientServers[0].second.first ;
+      server = clientServers[0].second.second ;
+    }
+    else if (serviceType_ == CServicesManager::GATHERER)
+    {
+      createServerInterComm(CXios::defaultPoolId, CXios::defaultServerId, clientServers) ;
+      for(auto& clientServer : clientServers)
+      {
+        primServerId_.push_back(clientServer.first) ;
+        clientPrimServer.push_back(clientServer.second.first);
+        serverPrimServer.push_back(clientServer.second.second); 
+      }
+    }
+
+  }
+  CATCH_DUMP_ATTR
+
+  void CContext::createServerInterComm_old(void) 
   TRY
   {
@@ -582,4 +651,5 @@
       else
       {
+        
         //CXios::getContextsManager()->createServerContextIntercomm(CXios::defaultPoolId, CXios::defaultServerId, 0, getContextId(), intraComm_, interComm) ;
         parentServerContext_->createIntercomm(CXios::defaultPoolId, CXios::defaultServerId, 0, getContextId(), intraComm_,
@@ -1638,8 +1708,4 @@
              return true;
              break;
-           case EVENT_ID_CREATE_FILE_HEADER :
-             recvCreateFileHeader(event);
-             return true;
-             break;
            case EVENT_ID_COUPLER_IN_READY:
              recvCouplerInReady(event);
@@ -1761,50 +1827,4 @@
    CATCH_DUMP_ATTR
 
-   //! Client side: Send a message to create header part of netcdf file
-   void CContext::sendCreateFileHeader(void)
-   TRY
-   {
-     int nbSrvPools ;
-     if (serviceType_==CServicesManager::CLIENT) nbSrvPools = 1 ;
-     else if (serviceType_==CServicesManager::GATHERER) nbSrvPools = this->clientPrimServer.size() ;
-     else nbSrvPools = 0 ;
-     CContextClient* contextClientTmp ;
-
-     for (int i = 0; i < nbSrvPools; ++i)
-     {
-       if (serviceType_==CServicesManager::CLIENT) contextClientTmp = client ;
-       else if (serviceType_==CServicesManager::GATHERER ) contextClientTmp = clientPrimServer[i] ;
-       CEventClient event(getType(),EVENT_ID_CREATE_FILE_HEADER);
-
-       if (contextClientTmp->isServerLeader())
-       {
-         CMessage msg;
-         const std::list<int>& ranks = contextClientTmp->getRanksServerLeader();
-         for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
-           event.push(*itRank,1,msg) ;
-         contextClientTmp->sendEvent(event);
-       }
-       else contextClientTmp->sendEvent(event);
-     }
-   }
-   CATCH_DUMP_ATTR
-
-   //! Server side: Receive a message of client annoucing the creation of header part of netcdf file
-   void CContext::recvCreateFileHeader(CEventServer& event)
-   TRY
-   {
-      CBufferIn* buffer=event.subEvents.begin()->buffer;
-      getCurrent()->recvCreateFileHeader(*buffer);
-   }
-   CATCH
-
-   //! Server side: Receive a message of client annoucing the creation of header part of netcdf file
-   void CContext::recvCreateFileHeader(CBufferIn& buffer)
-   TRY
-   {
-      if (serviceType_==CServicesManager::IO_SERVER || serviceType_==CServicesManager::OUT_SERVER) 
-        createFileHeader();
-   }
-   CATCH_DUMP_ATTR
 
    void CContext::createCouplerInterCommunicator(void)
Index: /XIOS3/trunk/src/node/context.hpp
===================================================================
--- /XIOS3/trunk/src/node/context.hpp	(revision 2404)
+++ /XIOS3/trunk/src/node/context.hpp	(revision 2405)
@@ -55,5 +55,5 @@
            EVENT_ID_COLLECTIVE=100,
            EVENT_ID_CLOSE_DEFINITION,EVENT_ID_UPDATE_CALENDAR,
-           EVENT_ID_CREATE_FILE_HEADER,EVENT_ID_CONTEXT_FINALIZE,
+           EVENT_ID_CONTEXT_FINALIZE,
            EVENT_ID_CONTEXT_FINALIZE_CLIENT,
            EVENT_ID_COUPLER_IN_READY,
@@ -104,5 +104,9 @@
          void initServer(MPI_Comm intraComm, int serviceType );
          void createClientInterComm(MPI_Comm interCommClient, MPI_Comm interCommServer)  ;
+ 
          void createServerInterComm(void)  ;
+         void createServerInterComm_old(void)  ;
+         void createServerInterComm(const string& poolId, const string& serverId, vector<pair<string, pair<CContextClient*,CContextServer*>>>& clientServers ) ;
+ 
 
          bool isInitialized(void);
@@ -168,5 +172,4 @@
          // There are something to send on closing context defintion
          void sendUpdateCalendar(int step);
-         void sendCreateFileHeader(void);
          void sendEnabledFiles(const std::vector<CFile*>& activeFiles);
          void sendEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles);
@@ -187,6 +190,4 @@
          void recvUpdateCalendar(CBufferIn& buffer);
          static void recvCloseDefinition(CEventServer& event);
-         static void recvCreateFileHeader(CEventServer& event);
-         void recvCreateFileHeader(CBufferIn& buffer);
          static void recvSolveInheritanceContext(CEventServer& event);
          void recvSolveInheritanceContext(CBufferIn& buffer);
@@ -315,4 +316,13 @@
          // list of slave servers (IO server or others)
          set<CContextClient*> slaveServers_ ;
+
+      private:
+        std::string defaultReaderId ;
+        std::string defaultWriterId ;
+        std::string defaultGathererId ;
+
+        std::map<std::string, CContextClient*> clients_ ;
+        std::map<std::string, CContextClient*> servers_ ;
+
       private:
          // the map containing context client associated to it string id for coupling out ;
