Index: XIOS/dev/XIOS_DEV_CMIP6/src/node/field.cpp
===================================================================
--- XIOS/dev/XIOS_DEV_CMIP6/src/node/field.cpp	(revision 1293)
+++ XIOS/dev/XIOS_DEV_CMIP6/src/node/field.cpp	(revision 1294)
@@ -951,7 +951,10 @@
      {
         if (!instantDataFilter)
+//          instantDataFilter = clientSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid, false, NoneDu, false,
+//                                                                                                      detectMissingValues, defaultValue));
           instantDataFilter = clientSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid,true));
 
-             // If the field data is to be read by the client or/and written to a file
+
+       // If the field data is to be read by the client or/and written to a file
        if (enableOutput && !storeFilter && !fileWriterFilter)
        {
@@ -966,4 +969,6 @@
      {
        if (!instantDataFilter)
+//         instantDataFilter = clientSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid, false, NoneDu, false,
+//                                                                                                     detectMissingValues, defaultValue));
          instantDataFilter = clientSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid, true));
 
@@ -1502,4 +1507,15 @@
    }
 
+   void CField::setContextClient(CContextClient* contextClient)
+   {
+     client = contextClient;
+     grid->setContextClient(contextClient);
+   }
+
+   CContextClient* CField::getContextClient()
+   {
+     return client;
+   }
+
    void CField::sendAddAllVariables(CContextClient* client)
    {
Index: XIOS/dev/XIOS_DEV_CMIP6/src/node/field.hpp
===================================================================
--- XIOS/dev/XIOS_DEV_CMIP6/src/node/field.hpp	(revision 1293)
+++ XIOS/dev/XIOS_DEV_CMIP6/src/node/field.hpp	(revision 1294)
@@ -102,4 +102,7 @@
          std::map<int, StdSize> getGridAttributesBufferSize(CContextClient* client);
          std::map<int, StdSize> getGridDataBufferSize(CContextClient* client); // Grid data buffer size for each connection of contextclient
+
+         void setContextClient(CContextClient* newContextClient);
+         CContextClient* getContextClient();
 
        public:
@@ -236,4 +239,6 @@
 
       private:
+         CContextClient* client;
+
          bool areAllReferenceSolved;
          bool isReferenceSolved;
Index: XIOS/dev/XIOS_DEV_CMIP6/src/node/file.cpp
===================================================================
--- XIOS/dev/XIOS_DEV_CMIP6/src/node/file.cpp	(revision 1293)
+++ XIOS/dev/XIOS_DEV_CMIP6/src/node/file.cpp	(revision 1294)
@@ -944,4 +944,9 @@
    {
      client = newContextClient;
+     size_t size = this->enabledFields.size();
+     for (size_t i = 0; i < size; ++i)
+     {
+       this->enabledFields[i]->setContextClient(newContextClient);
+     }
    }
 
Index: XIOS/dev/XIOS_DEV_CMIP6/src/node/grid.cpp
===================================================================
--- XIOS/dev/XIOS_DEV_CMIP6/src/node/grid.cpp	(revision 1293)
+++ XIOS/dev/XIOS_DEV_CMIP6/src/node/grid.cpp	(revision 1294)
@@ -36,4 +36,5 @@
       , gridSrc_(), hasTransform_(false), isGenerated_(false), order_(), globalIndexOnServer_()
       , computedWrittenIndex_(false)
+      , clients()
    {
      setVirtualDomainGroup(CDomainGroup::create(getId() + "_virtual_domain_group"));
@@ -55,4 +56,5 @@
       , gridSrc_(), hasTransform_(false), isGenerated_(false), order_(), globalIndexOnServer_()
       , computedWrittenIndex_(false)
+      , clients()
    {
      setVirtualDomainGroup(CDomainGroup::create(getId() + "_virtual_domain_group"));
@@ -643,5 +645,4 @@
         } 
       }
-
    }
 
@@ -649,8 +650,8 @@
 
    /*
-     Compute the global index and its local index on taking account of mask, data index.
-     These global index then will be used to compute the connection of this client to other clients in the different group
+     Compute the global index and its local index taking account mask and data index.
+     These global indexes will be used to compute the connection of this client (sender) to its servers (receivers)
      (via function computeConnectedClient)
-     These global index also corresponding to data sent to other clients (if any)
+     These global indexes also correspond to data sent to servers (if any)
    */
    void CGrid::computeClientIndex()
@@ -1347,10 +1348,10 @@
   {
     CContext* context = CContext::getCurrent();
-    int nbSrvPools = (context->hasServer) ? (context->hasClient ? context->clientPrimServer.size() : 0) : 1;
     storeIndex_toSrv.clear();
-
-    for (int p = 0; p < nbSrvPools; ++p)
-    {
-      CContextClient* client = context->hasServer ? context->clientPrimServer[p] : context->client;
+    std::set<CContextClient*>::iterator it;
+
+    for (it=clients.begin(); it!=clients.end(); ++it)
+    {
+      CContextClient* client = *it;
       int receiverSize = client->serverSize;
 
@@ -1412,9 +1413,10 @@
   {
     CContext* context = CContext::getCurrent();
-    int nbSrvPools = (context->clientPrimServer.size() == 0) ? 1 : context->clientPrimServer.size();
     storeIndex_toSrv.clear();
-    for (int p = 0; p < nbSrvPools; ++p)
-    {
-      CContextClient* client = (context->clientPrimServer.size() == 0) ? context->client : context->clientPrimServer[p];
+    std::set<CContextClient*>::iterator it;
+
+    for (it=clients.begin(); it!=clients.end(); ++it)
+    {
+      CContextClient* client = *it;
       int receiverSize = client->serverSize;
 
@@ -2502,4 +2504,9 @@
   }
 
+  void CGrid::setContextClient(CContextClient* contextClient)
+  {
+    clients.insert(contextClient);
+  }
+
   /*!
     Parse a grid, for now, it contains only domain, axis and scalar
Index: XIOS/dev/XIOS_DEV_CMIP6/src/node/grid.hpp
===================================================================
--- XIOS/dev/XIOS_DEV_CMIP6/src/node/grid.hpp	(revision 1293)
+++ XIOS/dev/XIOS_DEV_CMIP6/src/node/grid.hpp	(revision 1294)
@@ -161,4 +161,6 @@
          void sendIndex(void);
          void sendIndexScalarGrid();
+
+         void setContextClient(CContextClient* contextClient);
 
          void computeDomConServer();
@@ -215,21 +217,32 @@
          map<int, CArray<int, 1> > storeIndex_fromSrv; // Support, for now, reading with level-1 server
 
-
-         map<int, CArray<size_t, 1> > outIndexFromClient, compressedOutIndexFromClient, outGlobalIndexFromClient;
-
-         // A client receives global index from other clients (via recvIndex)
-         // then does mapping these index into local index of STORE_CLIENTINDEX
-         // In this way, store_clientIndex can be used as an input of a source filter
-         // Maybe we need a flag to determine whether a client wants to write. TODO
+         map<int, CArray<size_t, 1> > outIndexFromClient;  // Deprecated
+
+         map<int, CArray<size_t, 1> > compressedOutIndexFromClient;
+
+/** Map storing received indexes. Key = sender rank, value = index array. */
+         map<int, CArray<size_t, 1> > outGlobalIndexFromClient;
+
+// Manh Ha's comment: " A client receives global index from other clients (via recvIndex)
+// then does mapping these index into local index of STORE_CLIENTINDEX
+// In this way, store_clientIndex can be used as an input of a source filter
+// Maybe we need a flag to determine whether a client wants to write. TODO "
+
+/** Map storing received data. Key = sender rank, value = data array.
+ *  The map is created in CGrid::computeClientIndex and filled upon receiving data in CField::recvUpdateData() */
          map<int, CArray<size_t, 1> > outLocalIndexStoreOnClient; 
 
-/** Indexes calculated based on server distribution (serverDistribution_). They are used for writing data into a file. */
+/** Indexes calculated based on server-like distribution.
+ *  They are used for writing/reading data and only calculated for server level that does the writing/reading.
+ *  Along with localIndexToWriteOnClient, these indexes are used to correctly place incoming data. */
          CArray<size_t,1> localIndexToWriteOnServer;
 
-/** Indexes calculated based on client distribution (clientDistribution_). They are not used at all.
-    They should be the same as localIndexToWriteOnServer and potentially can be used as an additional check.*/
+/** Indexes calculated based on client-like distribution.
+ *  They are used for writing/reading data and only calculated for server level that does the writing/reading.
+ *  Along with localIndexToWriteOnServer, these indexes are used to correctly place incoming data. */
          CArray<size_t,1> localIndexToWriteOnClient;
 
          CArray<size_t,1> indexFromClients;
+
          void checkMask(void);
          void createMask(void);
@@ -289,7 +302,11 @@
 
       private:
-         bool isChecked;
-         bool isDomainAxisChecked;
-         bool isIndexSent;
+
+/** Clients that have to send a grid. There can be multiple clients in case of secondary server, otherwise only one client. */
+        std::set<CContextClient*> clients;
+
+        bool isChecked;
+        bool isDomainAxisChecked;
+        bool isIndexSent;
 
         CDomainGroup* vDomainGroup_;
@@ -299,8 +316,8 @@
         bool isAxisListSet, isDomListSet, isScalarListSet;
 
-/** Distribution calculated in computeClientIndex() based on the knowledge of the entire grid */
+/** Client-like distribution calculated based on the knowledge of the entire grid */
         CDistributionClient* clientDistribution_;
 
-/** Distribution calculated upon receiving indexes */
+/** Server-like distribution calculated upon receiving indexes */
         CDistributionServer* serverDistribution_;
 
@@ -345,4 +362,5 @@
    void CGrid::inputField(const CArray<double,n>& field, CArray<double,1>& stored) const
    {
+//#ifdef __XIOS_DEBUG
       if (this->getDataSize() != field.numElements())
          ERROR("void CGrid::inputField(const  CArray<double,n>& field, CArray<double,1>& stored) const",
@@ -351,4 +369,5 @@
                 << "The data array does not have the right size! "
                 << "Grid = " << this->GetName())
+//#endif
       this->storeField_arr(field.dataFirst(), stored);
    }
@@ -357,4 +376,5 @@
    void CGrid::outputField(const CArray<double,1>& stored, CArray<double,n>& field) const
    {
+//#ifdef __XIOS_DEBUG
       if (this->getDataSize() != field.numElements())
          ERROR("void CGrid::outputField(const CArray<double,1>& stored, CArray<double,n>& field) const",
@@ -363,4 +383,5 @@
                 << "The ouput array does not have the right size! "
                 << "Grid = " << this->GetName())
+//#endif
       this->restoreField_arr(stored, field.dataFirst());
    }
