Index: XIOS/dev/dev_trunk_omp/src/node/domain.cpp
===================================================================
--- XIOS/dev/dev_trunk_omp/src/node/domain.cpp	(revision 1601)
+++ XIOS/dev/dev_trunk_omp/src/node/domain.cpp	(revision 1646)
@@ -19,5 +19,7 @@
 #include "client_server_mapping_distributed.hpp"
 
+#ifdef _usingEP
 using namespace ep_lib;
+#endif
 
 #include <algorithm>
@@ -60,17 +62,22 @@
 
    void CDomain::assignMesh(const StdString meshName, const int nvertex)
+   TRY
    {
      mesh = CMesh::getMesh(meshName, nvertex);
    }
+   CATCH_DUMP_ATTR
 
    CDomain* CDomain::createDomain()
+   TRY
    {
      CDomain* domain = CDomainGroup::get("domain_definition")->createChild();
      return domain;
    }
+   CATCH
 
    std::map<StdString, ETranformationType> *CDomain::transformationMapList_ptr = 0;
 
    bool CDomain::initializeTransformationMap(std::map<StdString, ETranformationType>& m)
+   TRY
    {
      m["zoom_domain"] = TRANS_ZOOM_DOMAIN;
@@ -82,6 +89,8 @@
      m["extract_domain"] = TRANS_EXTRACT_DOMAIN;
    }
+   CATCH
 
    bool CDomain::initializeTransformationMap()
+   TRY
    {
      CDomain::transformationMapList_ptr = new std::map<StdString, ETranformationType>();
@@ -94,10 +103,12 @@
      (*CDomain::transformationMapList_ptr)["extract_domain"] = TRANS_EXTRACT_DOMAIN;
    }
+   CATCH
 
    const std::set<StdString> & CDomain::getRelFiles(void) const
+   TRY
    {
       return (this->relFiles);
    }
-
+   CATCH
 
    /*!
@@ -106,4 +117,5 @@
    */
    int CDomain::getNumberWrittenIndexes(ep_lib::MPI_Comm writtenCom)
+   TRY
    {
      int writtenSize;
@@ -111,4 +123,5 @@
      return numberWrittenIndexes_[writtenSize];
    }
+   CATCH_DUMP_ATTR
 
    /*!
@@ -117,4 +130,5 @@
    */
    int CDomain::getTotalNumberWrittenIndexes(ep_lib::MPI_Comm writtenCom)
+   TRY
    {
      int writtenSize;
@@ -122,4 +136,5 @@
      return totalNumberWrittenIndexes_[writtenSize];
    }
+   CATCH_DUMP_ATTR
 
    /*!
@@ -128,4 +143,5 @@
    */
    int CDomain::getOffsetWrittenIndexes(ep_lib::MPI_Comm writtenCom)
+   TRY
    {
      int writtenSize;
@@ -133,6 +149,8 @@
      return offsetWrittenIndexes_[writtenSize];
    }
+   CATCH_DUMP_ATTR
 
    CArray<int, 1>& CDomain::getCompressedIndexToWriteOnServer(ep_lib::MPI_Comm writtenCom)
+   TRY
    {
      int writtenSize;
@@ -140,4 +158,5 @@
      return compressedIndexToWriteOnServer[writtenSize];
    }
+   CATCH_DUMP_ATTR
 
    //----------------------------------------------------------------
@@ -149,4 +168,5 @@
     */
    std::map<int, StdSize> CDomain::getAttributesBufferSize(CContextClient* client, bool bufferForWriting /*= false*/)
+   TRY
    {
 
@@ -176,10 +196,4 @@
        // size estimation for sendIndex (and sendArea which is always smaller or equal)
        size_t sizeIndexEvent = 2 * sizeof(size_t) + 2 * CArray<int,1>::size(idxCount);
-       // if (isCompressible_)
-       // {
-       //   std::map<int, std::vector<int> >::const_iterator itWritten = indWrittenSrv_.find(rank);
-       //   size_t writtenIdxCount = (itWritten != itWrittenIndexEnd) ? itWritten->second.size() : 0;
-       //   sizeIndexEvent += CArray<int,1>::size(writtenIdxCount);
-       // }
 
        // size estimation for sendLonLat
@@ -195,27 +209,35 @@
      return attributesSizes;
    }
+   CATCH_DUMP_ATTR
 
    //----------------------------------------------------------------
 
    bool CDomain::isEmpty(void) const
+   TRY
    {
      return ((this->i_index.isEmpty()) || (0 == this->i_index.numElements()));
    }
+   CATCH
 
    //----------------------------------------------------------------
 
    bool CDomain::IsWritten(const StdString & filename) const
+   TRY
    {
       return (this->relFiles.find(filename) != this->relFiles.end());
    }
+   CATCH
 
    bool CDomain::isWrittenCompressed(const StdString& filename) const
+   TRY
    {
       return (this->relFilesCompressed.find(filename) != this->relFilesCompressed.end());
    }
+   CATCH
 
    //----------------------------------------------------------------
 
    bool CDomain::isDistributed(void) const
+   TRY
    {
       bool distributed =  !((!ni.isEmpty() && (ni == ni_glo) && !nj.isEmpty() && (nj == nj_glo)) ||
@@ -225,4 +247,5 @@
       return distributed;
    }
+   CATCH
 
    //----------------------------------------------------------------
@@ -234,17 +257,23 @@
     */
    bool CDomain::isCompressible(void) const
+   TRY
    {
       return isCompressible_;
    }
+   CATCH
 
    void CDomain::addRelFile(const StdString & filename)
+   TRY
    {
       this->relFiles.insert(filename);
    }
+   CATCH_DUMP_ATTR
 
    void CDomain::addRelFileCompressed(const StdString& filename)
+   TRY
    {
       this->relFilesCompressed.insert(filename);
    }
+   CATCH_DUMP_ATTR
 
    StdString CDomain::GetName(void)   { return (StdString("domain")); }
@@ -259,4 +288,5 @@
    */
    bool CDomain::distributionAttributesHaveValue() const
+   TRY
    {
       bool hasValues = true;
@@ -270,4 +300,5 @@
       return hasValues;
    }
+   CATCH
 
    /*!
@@ -279,4 +310,5 @@
    */
    void CDomain::redistribute(int nbLocalDomain)
+   TRY
    {
      if (this->isRedistributed_) return;
@@ -441,4 +473,5 @@
      checkDomain();
    }
+   CATCH_DUMP_ATTR
 
    /*!
@@ -446,4 +479,5 @@
    */
    void CDomain::fillInLonLat()
+   TRY
    {
      switch (type)
@@ -463,6 +497,6 @@
      }
      completeLonLatClient() ;
-
-   }
+   }
+   CATCH_DUMP_ATTR
 
    /*!
@@ -472,4 +506,5 @@
    */
    void CDomain::fillInRectilinearLonLat()
+   TRY
    {
      if (!lonvalue_rectilinear_read_from_file.isEmpty() && lonvalue_2d.isEmpty() && lonvalue_1d.isEmpty())
@@ -540,4 +575,5 @@
      }
    }
+   CATCH_DUMP_ATTR
 
     /*
@@ -546,4 +582,5 @@
     */
    void CDomain::fillInCurvilinearLonLat()
+   TRY
    {
      if (!lonvalue_curvilinear_read_from_file.isEmpty() && lonvalue_2d.isEmpty() && lonvalue_1d.isEmpty())
@@ -588,6 +625,6 @@
        bounds_latvalue_curvilinear_read_from_file.free();
      }
-
-   }
+   }
+   CATCH_DUMP_ATTR
 
     /*
@@ -596,4 +633,5 @@
     */
    void CDomain::fillInUnstructuredLonLat()
+   TRY
    {
      if (i_index.isEmpty())
@@ -647,4 +685,5 @@
      }
    }
+   CATCH_DUMP_ATTR
 
   /*
@@ -652,4 +691,5 @@
   */
    void CDomain::AllgatherRectilinearLonLat(CArray<double,1>& lon, CArray<double,1>& lat, CArray<double,1>& lon_g, CArray<double,1>& lat_g)
+   TRY
    {
      CContext* context = CContext::getCurrent();
@@ -683,8 +723,10 @@
       delete[] nj_g ;
    }
+   CATCH_DUMP_ATTR
 
    void CDomain::fillInRectilinearBoundLonLat(CArray<double,1>& lon, CArray<double,1>& lat,
                                               CArray<double,2>& boundsLon, CArray<double,2>& boundsLat)
-   {
+   TRY
+  {
      int i,j,k;
 
@@ -785,4 +827,5 @@
       }
    }
+   CATCH_DUMP_ATTR
 
    /*
@@ -790,4 +833,5 @@
    */
    void CDomain::checkDomain(void)
+   TRY
    {
      if (type.isEmpty())
@@ -881,4 +925,5 @@
      }
    }
+   CATCH_DUMP_ATTR
 
    size_t CDomain::getGlobalWrittenSize(void)
@@ -890,4 +935,5 @@
    // Check validity of local domain on using the combination of 3 parameters: ibegin, ni and i_index
    void CDomain::checkLocalIDomain(void)
+   TRY
    {
       // If ibegin and ni are provided then we use them to check the validity of local domain
@@ -948,7 +994,9 @@
       }
    }
+   CATCH_DUMP_ATTR
 
    // Check validity of local domain on using the combination of 3 parameters: jbegin, nj and j_index
    void CDomain::checkLocalJDomain(void)
+   TRY
    {
     // If jbegin and nj are provided then we use them to check the validity of local domain
@@ -999,8 +1047,10 @@
      }
    }
+   CATCH_DUMP_ATTR
 
    //----------------------------------------------------------------
 
    void CDomain::checkMask(void)
+   TRY
    {
       if (!mask_1d.isEmpty() && !mask_2d.isEmpty())
@@ -1048,8 +1098,10 @@
      }
    }
+   CATCH_DUMP_ATTR
 
    //----------------------------------------------------------------
 
    void CDomain::checkDomainData(void)
+   TRY
    {
       if (data_dim.isEmpty())
@@ -1091,9 +1143,12 @@
       }
    }
+   CATCH_DUMP_ATTR
 
    //----------------------------------------------------------------
 
    void CDomain::checkCompression(void)
-   {
+   TRY
+   {
+     int i,j,ind;
       if (!data_i_index.isEmpty())
       {
@@ -1116,4 +1171,23 @@
                    << "'data_j_index' must be defined when 'data_i_index' is set and 'data_dim' is 2.");
           }
+          for (int k=0; k<data_i_index.numElements(); ++k)
+          {
+            i = data_i_index(k)+data_ibegin ;
+            j = data_j_index(k)+data_jbegin ;
+            if (i>=0 && i<ni && j>=0 && j<nj)
+            {
+              ind=j*ni+i ;
+              if (!domainMask(ind))
+              {
+                data_i_index(k) = -1;
+                data_j_index(k) = -1;
+              }
+            }
+            else
+            {
+              data_i_index(k) = -1;
+              data_j_index(k) = -1;
+            }
+          }
         }
         else // (1 == data_dim)
@@ -1122,5 +1196,17 @@
           {
             data_j_index.resize(data_ni);
-            for (int j = 0; j < data_ni; ++j) data_j_index(j) = 0;
+            data_j_index = 0;
+          }
+          for (int k=0; k<data_i_index.numElements(); ++k)
+          {
+            i=data_i_index(k)+data_ibegin ;
+            if (i>=0 && i < domainMask.size())
+            {
+              if (!domainMask(i)) data_i_index(k) = -1;
+            }
+            else
+              data_i_index(k) = -1;
+
+            if (!domainMask(i)) data_i_index(k) = -1;
           }
         }
@@ -1137,9 +1223,18 @@
           data_i_index.resize(data_ni);
           data_j_index.resize(data_ni);
-
-          for (int i = 0; i < data_ni; ++i)
+          data_j_index = 0;
+
+          for (int k = 0; k < data_ni; ++k)
           {
-            data_i_index(i) = i;
-            data_j_index(i) = 0;
+            i=k+data_ibegin ;
+            if (i>=0 && i < domainMask.size())
+            {
+              if (domainMask(i))
+                data_i_index(k) = k;
+              else
+                data_i_index(k) = -1;
+            }
+            else
+              data_i_index(k) = -1;
           }
         }
@@ -1150,10 +1245,29 @@
           data_j_index.resize(dsize);
 
-          for(int count = 0, j = 0; j < data_nj; ++j)
+          for(int count = 0, kj = 0; kj < data_nj; ++kj)
           {
-            for(int i = 0; i < data_ni; ++i, ++count)
+            for(int ki = 0; ki < data_ni; ++ki, ++count)
             {
-              data_i_index(count) = i;
-              data_j_index(count) = j;
+              i = ki + data_ibegin;
+              j = kj + data_jbegin;
+              ind=j*ni+i ;
+              if (i>=0 && i<ni && j>=0 && j<nj)
+              {
+                if (domainMask(ind))
+                {
+                  data_i_index(count) = ki;
+                  data_j_index(count) = kj;
+                }
+                else
+                {
+                  data_i_index(count) = -1;
+                  data_j_index(count) = -1;
+                }
+              }
+              else
+              {
+                data_i_index(count) = -1;
+                data_j_index(count) = -1;
+              }
             }
           }
@@ -1161,7 +1275,9 @@
       }
    }
+   CATCH_DUMP_ATTR
 
    //----------------------------------------------------------------
    void CDomain::computeLocalMask(void)
+   TRY
    {
      localMask.resize(i_index.numElements()) ;
@@ -1195,10 +1311,13 @@
      }
    }
+   CATCH_DUMP_ATTR
 
    void CDomain::checkEligibilityForCompressedOutput(void)
+   TRY
    {
      // We don't check if the mask or the indexes are valid here, just if they have been defined at this point.
      isCompressible_ = !mask_1d.isEmpty() || !mask_2d.isEmpty() || !data_i_index.isEmpty();
    }
+   CATCH_DUMP_ATTR
 
    //----------------------------------------------------------------
@@ -1209,4 +1328,5 @@
    */
    void CDomain::completeLonLatClient(void)
+   TRY
    {
      bool lonlatValueExisted = (0 != lonvalue.numElements()) || (0 != latvalue.numElements());
@@ -1322,4 +1442,5 @@
      }
    }
+   CATCH_DUMP_ATTR
 
    /*
@@ -1327,4 +1448,5 @@
    */
    void CDomain::convertLonLatValue(void)
+   TRY
    {
      bool lonlatValueExisted = (0 != lonvalue.numElements()) || (0 != latvalue.numElements());
@@ -1424,7 +1546,8 @@
      }
    }
-
+   CATCH_DUMP_ATTR
 
    void CDomain::checkBounds(void)
+   TRY
    {
      bool hasBoundValues = (0 != bounds_lonvalue.numElements()) || (0 != bounds_latvalue.numElements());
@@ -1518,6 +1641,8 @@
      }
    }
+   CATCH_DUMP_ATTR
 
    void CDomain::checkArea(void)
+   TRY
    {
      bool hasAreaValue = (!areavalue.isEmpty() && 0 != areavalue.numElements());
@@ -1547,6 +1672,8 @@
      }
    }
+   CATCH_DUMP_ATTR
 
    void CDomain::checkLonLat()
+   TRY
    {
      if (!hasLonLat) hasLonLat = (!latvalue_1d.isEmpty() && !lonvalue_1d.isEmpty()) ||
@@ -1608,6 +1735,8 @@
      }
    }
+   CATCH_DUMP_ATTR
 
    void CDomain::checkAttributesOnClientAfterTransformation()
+   TRY
    {
      CContext* context=CContext::getCurrent() ;
@@ -1624,4 +1753,5 @@
      this->isClientAfterTransformationChecked = true;
    }
+   CATCH_DUMP_ATTR
 
    //----------------------------------------------------------------
@@ -1629,4 +1759,5 @@
    // This function only checks all attributes of current domain
    void CDomain::checkAttributesOnClient()
+   TRY
    {
      if (this->isClientChecked) return;
@@ -1654,7 +1785,9 @@
       this->isClientChecked = true;
    }
+   CATCH_DUMP_ATTR
 
    // Send all checked attributes to server
    void CDomain::sendCheckedAttributes()
+   TRY
    {
      if (!this->isClientChecked) checkAttributesOnClient();
@@ -1669,6 +1802,8 @@
      this->isChecked = true;
    }
+   CATCH_DUMP_ATTR
 
    void CDomain::checkAttributes(void)
+   TRY
    {
       if (this->isChecked) return;
@@ -1700,4 +1835,5 @@
       this->isChecked = true;
    }
+   CATCH_DUMP_ATTR
 
   /*!
@@ -1708,4 +1844,5 @@
   */
   void CDomain::computeConnectedClients()
+  TRY
   {
     CContext* context=CContext::getCurrent() ;
@@ -1806,4 +1943,29 @@
             connectedServerRank_[nbServer].push_back(client->clientRank % client->serverSize);
 
+          // Now check if all servers have data to receive. If not, master client will send empty data.
+          // This ensures that all servers will participate in collective calls upon receiving even if they have no date to receive.
+          std::vector<int> counts (clientSize);
+          std::vector<int> displs (clientSize);
+          displs[0] = 0;
+          int localCount = connectedServerRank_[nbServer].size() ;
+          ep_lib::MPI_Gather(&localCount, 1, MPI_INT, &counts[0], 1, MPI_INT, 0, client->intraComm) ;
+          for (int i = 0; i < clientSize-1; ++i)
+          {
+            displs[i+1] = displs[i] + counts[i];
+          }
+          std::vector<int> allConnectedServers(displs[clientSize-1]+counts[clientSize-1]);
+
+          ep_lib::MPI_Gatherv(&(connectedServerRank_[nbServer])[0], localCount, MPI_INT, &allConnectedServers[0], &counts[0], &displs[0], MPI_INT, 0, client->intraComm);
+
+
+          if ((allConnectedServers.size() != nbServer) && (rank == 0))
+          {
+            std::vector<bool> isSrvConnected (nbServer, false);
+            for (int i = 0; i < allConnectedServers.size(); ++i) isSrvConnected[allConnectedServers[i]] = true;
+            for (int i = 0; i < nbServer; ++i)
+            {
+              if (!isSrvConnected[i]) connectedServerRank_[nbServer].push_back(i);
+            }
+          }
           nbSenders[nbServer] = clientServerMap->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_[nbServer]);
           delete clientServerMap;
@@ -1812,4 +1974,5 @@
     }
   }
+  CATCH_DUMP_ATTR
 
    /*!
@@ -1819,4 +1982,5 @@
    */
    void CDomain::computeWrittenIndex()
+   TRY
    {  
       if (computedWrittenIndex_) return;
@@ -1840,16 +2004,5 @@
                                        itSrve = writtenGlobalIndex.end(), itSrv;
 
-//      for (itSrv = itSrvb; itSrv != itSrve; ++itSrv)
-//      {
-//        indGlo = *itSrv;
-//        if (ite != globalLocalIndexMap_.find(indGlo))
-//        {
-//          ++nbWritten;
-//        }
-//      }
-
-//      localIndexToWriteOnServer.resize(nbWritten);
       localIndexToWriteOnServer.resize(writtenGlobalIndex.numElements());
-
       nbWritten = 0;
       for (itSrv = itSrvb; itSrv != itSrve; ++itSrv)
@@ -1859,60 +2012,16 @@
         {
           localIndexToWriteOnServer(nbWritten) = globalLocalIndexMap_[indGlo];
-          ++nbWritten;
         }
         else
         {
-          localIndexToWriteOnServer(nbWritten) = 0;
-          ++nbWritten;
-        }
-      }
-      
-      // if (isCompressible())
-      // {
-      //   nbWritten = 0;
-      //   std::unordered_map<size_t,size_t> localGlobalIndexMap;
-      //   for (itSrv = itSrvb; itSrv != itSrve; ++itSrv)
-      //   {
-      //     indGlo = *itSrv;
-      //     if (ite != globalLocalIndexMap_.find(indGlo))
-      //     {
-      //       localGlobalIndexMap[localIndexToWriteOnServer(nbWritten)] = indGlo;
-      //       ++nbWritten;
-      //     }                 
-      //   }
-
-      //   nbWritten = 0;
-      //   for (int idx = 0; idx < data_i_index.numElements(); ++idx)
-      //   {
-      //     if (localGlobalIndexMap.end() != localGlobalIndexMap.find(data_i_index(idx)))
-      //     {
-      //       ++nbWritten;
-      //     }
-      //   }
-
-      //   compressedIndexToWriteOnServer.resize(nbWritten);
-      //   nbWritten = 0;
-      //   for (int idx = 0; idx < data_i_index.numElements(); ++idx)
-      //   {
-      //     if (localGlobalIndexMap.end() != localGlobalIndexMap.find(data_i_index(idx)))
-      //     {
-      //       compressedIndexToWriteOnServer(nbWritten) = localGlobalIndexMap[data_i_index(idx)];
-      //       ++nbWritten;
-      //     }
-      //   }
-
-      //   numberWrittenIndexes_ = nbWritten;
-      //   if (isDistributed())
-      //   {            
-      //     MPI_Allreduce(&numberWrittenIndexes_, &totalNumberWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm);
-      //     MPI_Scan(&numberWrittenIndexes_, &offsetWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm);
-      //     offsetWrittenIndexes_ -= numberWrittenIndexes_;
-      //   }
-      //   else
-      //     totalNumberWrittenIndexes_ = numberWrittenIndexes_;
-      // }      
-   }
+          localIndexToWriteOnServer(nbWritten) = -1;
+        }
+        ++nbWritten;
+      }
+   }
+   CATCH_DUMP_ATTR
 
   void CDomain::computeWrittenCompressedIndex(ep_lib::MPI_Comm writtenComm)
+  TRY
   {
     int writtenCommSize;
@@ -1982,4 +2091,5 @@
       }
   }
+  CATCH_DUMP_ATTR
 
   /*!
@@ -1988,17 +2098,18 @@
   */
   void CDomain::sendAttributes()
+  TRY
   {
     sendDistributionAttributes();
     sendIndex();       
-    sendMask();
     sendLonLat();
     sendArea();    
     sendDataIndex();
   }
-
+  CATCH
   /*!
     Send global index from client to connected client(s)
   */
   void CDomain::sendIndex()
+  TRY
   {
     int ns, n, i, j, ind, nv, idx;
@@ -2043,4 +2154,5 @@
     }
   }
+  CATCH_DUMP_ATTR
 
   /*!
@@ -2050,4 +2162,5 @@
   */
   void CDomain::sendDistributionAttributes(void)
+  TRY
   {
     std::list<CContextClient*>::iterator it;
@@ -2096,48 +2209,5 @@
     }
   }
-
-  /*!
-    Send mask index from client to connected(s) clients    
-  */
-  void CDomain::sendMask()
-  {
-    int ns, n, i, j, ind, nv, idx;
-    std::list<CContextClient*>::iterator it;
-    for (it=clients.begin(); it!=clients.end(); ++it)
-    {
-      CContextClient* client = *it;
-      int serverSize = client->serverSize;
-
-      // send area for each connected server
-      CEventClient eventMask(getType(), EVENT_ID_MASK);
-
-      list<CMessage> list_msgsMask;
-      list<CArray<bool,1> > list_mask;
-
-      std::unordered_map<int, vector<size_t> >::const_iterator it, iteMap;
-      iteMap = indSrv_[serverSize].end();
-      for (int k = 0; k < connectedServerRank_[serverSize].size(); ++k)
-      {
-        int nbData = 0;
-        int rank = connectedServerRank_[serverSize][k];
-        it = indSrv_[serverSize].find(rank);
-        if (iteMap != it)
-          nbData = it->second.size();
-        list_mask.push_back(CArray<bool,1>(nbData));
-
-        const std::vector<size_t>& temp = it->second;
-        for (n = 0; n < nbData; ++n)
-        {
-          idx = static_cast<int>(it->second[n]);
-          list_mask.back()(n) = domainMask(globalLocalIndexMap_[idx]);
-        }
-
-        list_msgsMask.push_back(CMessage());
-        list_msgsMask.back() << this->getId() << list_mask.back();
-        eventMask.push(rank, nbSenders[serverSize][rank], list_msgsMask.back());
-      }
-      client->sendEvent(eventMask);
-    }
-  }
+  CATCH_DUMP_ATTR
 
   /*!
@@ -2145,4 +2215,5 @@
   */
   void CDomain::sendArea()
+  TRY
   {
     if (!hasArea) return;
@@ -2188,4 +2259,5 @@
     }
   }
+  CATCH_DUMP_ATTR
 
   /*!
@@ -2195,4 +2267,5 @@
   */
   void CDomain::sendLonLat()
+  TRY
   {
     if (!hasLonLat) return;
@@ -2283,4 +2356,5 @@
     }
   }
+  CATCH_DUMP_ATTR
 
   /*!
@@ -2291,4 +2365,5 @@
   */
   void CDomain::sendDataIndex()
+  TRY
   {
     int ns, n, i, j, ind, nv, idx;
@@ -2359,6 +2434,8 @@
     }
   }
+  CATCH
   
   bool CDomain::dispatchEvent(CEventServer& event)
+  TRY
   {
     if (SuperClass::dispatchEvent(event)) return true;
@@ -2373,8 +2450,4 @@
         case EVENT_ID_INDEX:
           recvIndex(event);
-          return true;
-          break;
-        case EVENT_ID_MASK:
-          recvMask(event);
           return true;
           break;
@@ -2402,4 +2475,5 @@
     }
   }
+  CATCH
 
   /*!
@@ -2408,4 +2482,5 @@
   */
   void CDomain::recvIndex(CEventServer& event)
+  TRY
   {
     string domainId;
@@ -2421,4 +2496,5 @@
     get(domainId)->recvIndex(rankBuffers);
   }
+  CATCH
 
   /*!
@@ -2428,4 +2504,5 @@
   */
   void CDomain::recvIndex(std::map<int, CBufferIn*>& rankBuffers)
+  TRY
   {
     int nbReceived = rankBuffers.size(), i, ind, index, type_int, iIndex, jIndex;
@@ -2466,15 +2543,8 @@
            jIndex = (jIndex < 0) ? 0 : jIndex;
            nbIndLoc = iIndex + ni * jIndex;
-           if (nbIndLoc < nbIndexGlobMax)
-           {
-             i_index(nbIndLoc) = index % ni_glo;
-             j_index(nbIndLoc) = index / ni_glo;
-             globalLocalIndexMap_[index] = nbIndLoc;  
-             ++nbIndGlob;
-           }
-           // i_index(nbIndGlob) = index % ni_glo;
-           // j_index(nbIndGlob) = index / ni_glo;
-           // globalLocalIndexMap_[index] = nbIndGlob;  
-           // ++nbIndGlob;
+           i_index(nbIndGlob) = index % ni_glo;
+           j_index(nbIndGlob) = index / ni_glo;
+           globalLocalIndexMap_[index] = nbIndGlob;
+           ++nbIndGlob;
          } 
       } 
@@ -2491,5 +2561,8 @@
       j_index.resizeAndPreserve(nbIndGlob);
     }
+
+    domainMask.resize(0); // Mask is not defined anymore on servers
   }
+  CATCH
 
   /*!
@@ -2498,4 +2571,5 @@
   */
   void CDomain::recvDistributionAttributes(CEventServer& event)
+  TRY
   {
     CBufferIn* buffer=event.subEvents.begin()->buffer;
@@ -2504,4 +2578,5 @@
     get(domainId)->recvDistributionAttributes(*buffer);
   }
+  CATCH
 
   /*!
@@ -2511,4 +2586,5 @@
   */
   void CDomain::recvDistributionAttributes(CBufferIn& buffer)
+  TRY
   {
     int ni_tmp, ibegin_tmp, nj_tmp, jbegin_tmp;
@@ -2526,74 +2602,5 @@
 
   }
-
-  /*!
-    Receive area event from clients(s)
-    \param[in] event event contain info about rank and associated area
-  */
-  void CDomain::recvMask(CEventServer& event)
-  {
-    string domainId;
-    std::map<int, CBufferIn*> rankBuffers;
-
-    list<CEventServer::SSubEvent>::iterator it;
-    for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it)
-    {      
-      CBufferIn* buffer = it->buffer;
-      *buffer >> domainId;
-      rankBuffers[it->rank] = buffer;     
-    }
-    get(domainId)->recvMask(rankBuffers);
-  }
-
-
-  /*!
-    Receive mask information from client(s)
-    \param[in] rankBuffers rank of sending client and the corresponding receive buffer  
-  */
-  void CDomain::recvMask(std::map<int, CBufferIn*>& rankBuffers)
-  {
-    int nbReceived = rankBuffers.size(), i, ind, index, lInd;
-    if (nbReceived != recvClientRanks_.size())
-      ERROR("void CDomain::recvMask(std::map<int, CBufferIn*>& rankBuffers)",
-           << "The number of sending clients is not correct."
-           << "Expected number: " << recvClientRanks_.size() << " but received " << nbReceived);
-
-    vector<CArray<bool,1> > recvMaskValue(nbReceived);      
-    for (i = 0; i < recvClientRanks_.size(); ++i)
-    {
-      int rank = recvClientRanks_[i];
-      CBufferIn& buffer = *(rankBuffers[rank]);      
-      buffer >> recvMaskValue[i];
-    }
-
-    int nbMaskInd = 0;
-    for (i = 0; i < nbReceived; ++i)
-    {
-      nbMaskInd += recvMaskValue[i].numElements();
-    }
-  
-    if (nbMaskInd != globalLocalIndexMap_.size())
-      info (0) << "If domain " << this->getDomainOutputName() <<" does not have overlapped regions between processes "
-               << "something must be wrong with mask index "<< std::endl;
-
-    nbMaskInd = globalLocalIndexMap_.size();
-    mask_1d.resize(nbMaskInd);
-    domainMask.resize(nbMaskInd);
-    mask_1d = false;
-    
-    for (i = 0; i < nbReceived; ++i)
-    {
-      CArray<int,1>& tmpInd = indGlob_[recvClientRanks_[i]];
-      CArray<bool,1>& tmp = recvMaskValue[i];
-      for (ind = 0; ind < tmp.numElements(); ++ind)
-      {
-        lInd = globalLocalIndexMap_[size_t(tmpInd(ind))];
-        if (!mask_1d(lInd)) // Only rewrite mask_1d if it's not true
-          mask_1d(lInd) = tmp(ind);
-      }
-    }
-    domainMask=mask_1d ;
-  }
-
+ CATCH_DUMP_ATTR
   /*!
     Receive longitude event from clients(s)
@@ -2601,4 +2608,5 @@
   */
   void CDomain::recvLon(CEventServer& event)
+  TRY
   {
     string domainId;
@@ -2614,4 +2622,5 @@
     get(domainId)->recvLon(rankBuffers);
   }
+  CATCH
 
   /*!
@@ -2620,4 +2629,5 @@
   */
   void CDomain::recvLon(std::map<int, CBufferIn*>& rankBuffers)
+  TRY
   {
     int nbReceived = rankBuffers.size(), i, ind, index, iindex, jindex, lInd;
@@ -2679,4 +2689,5 @@
     }
   }
+  CATCH_DUMP_ATTR
 
   /*!
@@ -2685,4 +2696,5 @@
   */
   void CDomain::recvLat(CEventServer& event)
+  TRY
   {
     string domainId;
@@ -2698,4 +2710,5 @@
     get(domainId)->recvLat(rankBuffers);
   }
+  CATCH
 
   /*!
@@ -2704,4 +2717,5 @@
   */
   void CDomain::recvLat(std::map<int, CBufferIn*>& rankBuffers)
+  TRY
   {
     int nbReceived = rankBuffers.size(), i, ind, index, iindex, jindex, lInd;
@@ -2765,4 +2779,5 @@
     }
   }
+  CATCH_DUMP_ATTR
 
   /*!
@@ -2771,4 +2786,5 @@
   */
   void CDomain::recvArea(CEventServer& event)
+  TRY
   {
     string domainId;
@@ -2784,4 +2800,5 @@
     get(domainId)->recvArea(rankBuffers);
   }
+  CATCH
 
   /*!
@@ -2790,4 +2807,5 @@
   */
   void CDomain::recvArea(std::map<int, CBufferIn*>& rankBuffers)
+  TRY
   {
     int nbReceived = rankBuffers.size(), i, ind, index, lInd;
@@ -2835,4 +2853,5 @@
     }
   }
+  CATCH_DUMP_ATTR
 
   /*!
@@ -2844,4 +2863,5 @@
   */
   bool CDomain::isEqual(CDomain* obj)
+  TRY
   {
     vector<StdString> excludedAttr;
@@ -2866,4 +2886,5 @@
     return objEqual;
   }
+  CATCH_DUMP_ATTR
 
   /*!
@@ -2872,4 +2893,5 @@
   */
   void CDomain::recvDataIndex(CEventServer& event)
+  TRY
   {
     string domainId;
@@ -2885,4 +2907,5 @@
     get(domainId)->recvDataIndex(rankBuffers);
   }
+  CATCH
 
   /*!
@@ -2896,4 +2919,5 @@
   */
   void CDomain::recvDataIndex(std::map<int, CBufferIn*>& rankBuffers)
+  TRY
   {
     int nbReceived = rankBuffers.size(), i, ind, index, indexI, indexJ, type_int, lInd;    
@@ -2932,9 +2956,4 @@
          dataIIndex(lInd) = (-1 == dataIIndex(lInd)) ? tmpI(ind) : dataIIndex(lInd); // Only fill in dataIndex if there is no data
          dataJIndex(lInd) = (-1 == dataJIndex(lInd)) ? tmpJ(ind) : dataJIndex(lInd);  
-
-         if (!domainMask(lInd))   // Include mask info into data index on the RECEIVE getServerDimensionSizes
-         {
-           dataIIndex(lInd) = dataJIndex(lInd) = -1;
-         }
       } 
     }
@@ -2967,10 +2986,13 @@
     data_jbegin.setValue(0);
   }
+  CATCH_DUMP_ATTR
 
   CTransformation<CDomain>* CDomain::addTransformation(ETranformationType transType, const StdString& id)
+  TRY
   {
     transformationMap_.push_back(std::make_pair(transType, CTransformation<CDomain>::createTransformation(transType,id)));
     return transformationMap_.back().second;
   }
+  CATCH_DUMP_ATTR
 
   /*!
@@ -2979,7 +3001,9 @@
   */
   bool CDomain::hasTransformation()
+  TRY
   {
     return (!transformationMap_.empty());
   }
+  CATCH_DUMP_ATTR
 
   /*!
@@ -2988,7 +3012,9 @@
   */
   void CDomain::setTransformations(const TransMapTypes& domTrans)
+  TRY
   {
     transformationMap_ = domTrans;
   }
+  CATCH_DUMP_ATTR
 
   /*!
@@ -2997,9 +3023,12 @@
   */
   CDomain::TransMapTypes CDomain::getAllTransformations(void)
+  TRY
   {
     return transformationMap_;
   }
+  CATCH_DUMP_ATTR
 
   void CDomain::duplicateTransformation(CDomain* src)
+  TRY
   {
     if (src->hasTransformation())
@@ -3008,4 +3037,5 @@
     }
   }
+  CATCH_DUMP_ATTR
 
   /*!
@@ -3013,4 +3043,5 @@
    */
   void CDomain::solveInheritanceTransformation()
+  TRY
   {
     if (hasTransformation() || !hasDirectDomainReference())
@@ -3029,6 +3060,8 @@
         refDomains[i]->setTransformations(domain->getAllTransformations());
   }
+  CATCH_DUMP_ATTR
 
   void CDomain::setContextClient(CContextClient* contextClient)
+  TRY
   {
     if (clientsSet.find(contextClient)==clientsSet.end())
@@ -3038,4 +3071,5 @@
     }
   }
+  CATCH_DUMP_ATTR
 
   /*!
@@ -3045,4 +3079,5 @@
   */
   void CDomain::parse(xml::CXMLNode & node)
+  TRY
   {
     SuperClass::parse(node);
@@ -3076,4 +3111,5 @@
     }
   }
+  CATCH_DUMP_ATTR
    //----------------------------------------------------------------
 
