Index: XIOS/dev/XIOS_DEV_CMIP6/src/node/domain.cpp
===================================================================
--- XIOS/dev/XIOS_DEV_CMIP6/src/node/domain.cpp	(revision 1337)
+++ XIOS/dev/XIOS_DEV_CMIP6/src/node/domain.cpp	(revision 1345)
@@ -33,4 +33,5 @@
       , lonvalue(), latvalue(), bounds_lonvalue(), bounds_latvalue()
       , globalLocalIndexMap_(), computedWrittenIndex_(false)
+	  , clients()
    {
    }
@@ -44,4 +45,5 @@
       , lonvalue(), latvalue(), bounds_lonvalue(), bounds_latvalue()
       , globalLocalIndexMap_(), computedWrittenIndex_(false)
+	  , clients()
    {
     }
@@ -2065,11 +2067,9 @@
   {
     int ns, n, i, j, ind, nv, idx;
-    CContext* context = CContext::getCurrent();
-
-    // int nbSrvPools = (context->hasServer) ? context->clientPrimServer.size() : 1;
-    int nbSrvPools = (context->hasServer) ? (context->hasClient ? context->clientPrimServer.size() : 0) : 1;
-    for (int p = 0; p < nbSrvPools; ++p)
+    std::set<CContextClient*>::iterator it;
+    for (it=clients.begin(); it!=clients.end(); ++it)
     {
-      CContextClient* client = (0 != context->clientPrimServer.size()) ? context->clientPrimServer[p] : context->client;
+      CContextClient* client = *it;
+
       int serverSize = client->serverSize;
       CEventClient eventIndex(getType(), EVENT_ID_INDEX);
@@ -2115,13 +2115,9 @@
   void CDomain::sendDistributionAttributes(void)
   {
-    CContext* context = CContext::getCurrent();
-     // Use correct context client to send message
-    // int nbSrvPools = (context->hasServer) ? context->clientPrimServer.size() : 1;
-    int nbSrvPools = (context->hasServer) ? (context->hasClient ? context->clientPrimServer.size() : 0) : 1;
-    for (int i = 0; i < nbSrvPools; ++i)
+    std::set<CContextClient*>::iterator it;
+    for (it=clients.begin(); it!=clients.end(); ++it)
     {
-      CContextClient* contextClientTmp = (context->hasServer) ? context->clientPrimServer[i]
-                                                                         : context->client;    
-      int nbServer = contextClientTmp->serverSize;
+      CContextClient* client = *it;
+      int nbServer = client->serverSize;
       std::vector<int> nGlobDomain(2);
       nGlobDomain[0] = this->ni_glo;
@@ -2136,9 +2132,9 @@
 
       CEventClient event(getType(),EVENT_ID_SERVER_ATTRIBUT);
-      if (contextClientTmp->isServerLeader())
+      if (client->isServerLeader())
       {
         std::list<CMessage> msgs;
 
-        const std::list<int>& ranks = contextClientTmp->getRanksServerLeader();
+        const std::list<int>& ranks = client->getRanksServerLeader();
         for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
         {
@@ -2158,7 +2154,7 @@
           event.push(*itRank,1,msg);
         }
-        contextClientTmp->sendEvent(event);
-      }
-      else contextClientTmp->sendEvent(event);
+        client->sendEvent(event);
+      }
+      else client->sendEvent(event);
     }
   }
@@ -2170,11 +2166,8 @@
   {
     int ns, n, i, j, ind, nv, idx;
-    CContext* context = CContext::getCurrent();
-
-    // int nbSrvPools = (context->hasServer) ? context->clientPrimServer.size() : 1;
-    int nbSrvPools = (context->hasServer) ? (context->hasClient ? context->clientPrimServer.size() : 0) : 1;
-    for (int p = 0; p < nbSrvPools; ++p)
+    std::set<CContextClient*>::iterator it;
+    for (it=clients.begin(); it!=clients.end(); ++it)
     {
-      CContextClient* client = (0 != context->clientPrimServer.size()) ? context->clientPrimServer[p] : context->client;
+      CContextClient* client = *it;
       int serverSize = client->serverSize;
 
@@ -2219,11 +2212,9 @@
 
     int ns, n, i, j, ind, nv, idx;
-    CContext* context = CContext::getCurrent();
-
-    // int nbSrvPools = (context->hasServer) ? context->clientPrimServer.size() : 1;
-    int nbSrvPools = (context->hasServer) ? (context->hasClient ? context->clientPrimServer.size() : 0) : 1;
-    for (int p = 0; p < nbSrvPools; ++p)
+    std::set<CContextClient*>::iterator it;
+
+    for (it=clients.begin(); it!=clients.end(); ++it)
     {
-      CContextClient* client = (0 != context->clientPrimServer.size()) ? context->clientPrimServer[p] : context->client;
+      CContextClient* client = *it;
       int serverSize = client->serverSize;
 
@@ -2271,11 +2262,8 @@
 
     int ns, n, i, j, ind, nv, idx;
-    CContext* context = CContext::getCurrent();
-
-    // int nbSrvPools = (context->hasServer) ? context->clientPrimServer.size() : 1;
-    int nbSrvPools = (context->hasServer) ? (context->hasClient ? context->clientPrimServer.size() : 0) : 1;
-    for (int p = 0; p < nbSrvPools; ++p)
+    std::set<CContextClient*>::iterator it;
+    for (it=clients.begin(); it!=clients.end(); ++it)
     {
-      CContextClient* client = (0 != context->clientPrimServer.size()) ? context->clientPrimServer[p] : context->client;
+      CContextClient* client = *it;
       int serverSize = client->serverSize;
 
@@ -2368,11 +2356,9 @@
   {
     int ns, n, i, j, ind, nv, idx;
-    CContext* context = CContext::getCurrent();
-
-    // int nbSrvPools = (context->hasServer) ? context->clientPrimServer.size() : 1;
-    int nbSrvPools = (context->hasServer) ? (context->hasClient ? context->clientPrimServer.size() : 0) : 1;
-    for (int p = 0; p < nbSrvPools; ++p)
+    std::set<CContextClient*>::iterator it;
+    for (it=clients.begin(); it!=clients.end(); ++it)
     {
-      CContextClient* client = (0 != context->clientPrimServer.size()) ? context->clientPrimServer[p] : context->client;
+      CContextClient* client = *it;
+
       int serverSize = client->serverSize;
 
@@ -3128,4 +3114,9 @@
   }
 
+  void CDomain::setContextClient(CContextClient* contextClient)
+  {
+    clients.insert(contextClient);
+  }
+
   /*!
     Parse children nodes of a domain in xml file.
