Index: XIOS/trunk/src/client_client_dht_template.hpp
===================================================================
--- XIOS/trunk/src/client_client_dht_template.hpp	(revision 829)
+++ XIOS/trunk/src/client_client_dht_template.hpp	(revision 830)
@@ -16,5 +16,4 @@
 #include "policy.hpp"
 #include <boost/unordered_map.hpp>
-//#include "utils.hpp"
 #include "dht_data_types.hpp"
 
@@ -39,5 +38,4 @@
 
   public:
-    /** Default constructor */
     CClientClientDHTTemplate(const Index2InfoTypeMap& indexInfoInitMap,
                              const MPI_Comm& clientIntraComm,
@@ -46,5 +44,5 @@
     void computeIndexInfoMapping(const CArray<size_t,1>& indices);
 
-    const Index2InfoTypeMap& getInfoIndexMap() const {return infoIndexMapping_; }
+    const Index2InfoTypeMap& getInfoIndexMap() const {return indexToInfoMappingLevel_; }
 
     /** Default destructor */
@@ -74,10 +72,10 @@
                                      const int recvNbIndexCount,
                                      int& countIndexServer,
-                                     std::map<int, unsigned char*>& indexServerBuffBegin,
+                                     std::map<int, unsigned char*>& infoBuffBegin,
                                      std::map<int, MPI_Request>& requestRecvIndexServer,
                                      const MPI_Comm& intraComm);
 
-    // Send server index to clients
-    void sendInfoToClients(int clientDestRank, std::vector<InfoType>& indexServer,
+    // Send information to clients
+    void sendInfoToClients(int clientDestRank, unsigned char* info, int infoSize,
                            const MPI_Comm& clientIntraComm, std::list<MPI_Request>& requestSendIndexServer);
 
@@ -99,9 +97,6 @@
     Index2InfoTypeMap index2InfoMapping_;
 
-    //! A temporary mapping of index to the corresponding information in each level of hierarchy
+    //! A mapping of index to the corresponding information in each level of hierarchy
     Index2InfoTypeMap indexToInfoMappingLevel_;
-
-    //! Data (information) corresponding to global index
-    Index2InfoTypeMap infoIndexMapping_;
 
     //! intracommuntion of clients
Index: XIOS/trunk/src/client_client_dht_template_impl.hpp
===================================================================
--- XIOS/trunk/src/client_client_dht_template_impl.hpp	(revision 829)
+++ XIOS/trunk/src/client_client_dht_template_impl.hpp	(revision 830)
@@ -23,6 +23,6 @@
 template<typename T, typename H>
 CClientClientDHTTemplate<T,H>::CClientClientDHTTemplate(const boost::unordered_map<size_t,T>& indexInfoMap,
-                                                      const MPI_Comm& clientIntraComm,
-                                                      int hierarLvl)
+                                                        const MPI_Comm& clientIntraComm,
+                                                        int hierarLvl)
   : index2InfoMapping_(), indexToInfoMappingLevel_()
 {
@@ -46,11 +46,4 @@
   int lvl = this->commLevel_.size() - 1;
   computeIndexInfoMappingLevel(indices, this->commLevel_[lvl], lvl);
-  size_t size = indices.numElements();
-  for (size_t idx = 0; idx < size; ++idx)
-  {
-    T& info = indexToInfoMappingLevel_[indices(idx)];
-//    infoIndexMapping_[info].push_back(indices(idx));
-    infoIndexMapping_[indices(idx)] = info;
-  }
 }
 
@@ -130,9 +123,8 @@
   int nbIndexReceivedFromOthers = nbIndexToSend;
   if (0 != nbIndexReceivedFromOthers)
-    recvBuffInfo = new unsigned char[nbIndexReceivedFromOthers*infoTypeSize];
+    recvBuffInfo = new unsigned char[nbIndexReceivedFromOthers*ProcessDHTElement<InfoType>::typeSize()];
 
   std::map<int, MPI_Request>::iterator itRequest;
   std::vector<int> demandAlreadyReceived, repondAlreadyReceived;
-
 
   int countIndex = 0;  // Counting of buffer for receiving index
@@ -195,16 +187,19 @@
 
   std::map<int, std::vector<InfoType> > client2ClientInfo;
+  std::vector<unsigned char*> infoToSend(src2Index.size());
   std::list<MPI_Request> sendInfoRequest;
-  std::map<int, std::vector<size_t> >::iterator itbSrc2Idx = src2Index.begin(), itSrc2Idx,
+  std::map<int, std::vector<size_t> >::iterator itSrc2Idx = src2Index.begin(),
                                                 iteSrc2Idx = src2Index.end();
-  for (itSrc2Idx = itbSrc2Idx; itSrc2Idx != iteSrc2Idx; ++itSrc2Idx)
+  for (int i=0; itSrc2Idx != iteSrc2Idx; ++itSrc2Idx, ++i)
   {
     int clientSourceRank = itSrc2Idx->first;
     std::vector<size_t>& srcIdx = itSrc2Idx->second;
+    infoToSend[i] = new unsigned char [srcIdx.size()*ProcessDHTElement<InfoType>::typeSize()];
+    int infoIndex = 0;
     for (int idx = 0; idx < srcIdx.size(); ++idx)
     {
-      client2ClientInfo[clientSourceRank].push_back(indexToInfoMappingLevel_[srcIdx[idx]]);
-    }
-    sendInfoToClients(clientSourceRank, client2ClientInfo[clientSourceRank], commLevel, sendInfoRequest);
+      ProcessDHTElement<InfoType>::packElement(indexToInfoMappingLevel_[srcIdx[idx]], infoToSend[i], infoIndex);
+    }
+    sendInfoToClients(clientSourceRank, infoToSend[i], infoIndex, commLevel, sendInfoRequest);
   }
 
@@ -240,10 +235,8 @@
         unsigned char* beginBuff = infoBuffBegin[clientSourceRank];
         std::vector<size_t>& indexTmp = client2ClientIndex[clientSourceRank];
-        TypeToBytes<InfoType> u;
+        int infoIndex = 0;
         for (int i = 0; i < actualCountInfo; ++i)
         {
-          unsigned char* tmpBeginBuff = beginBuff+i*infoTypeSize;
-          for (size_t idx = 0; idx < infoTypeSize; ++idx) u.bytes[idx] = *(tmpBeginBuff+idx);
-          indexToInfoMapping[indexTmp[i]] = u.value;
+          ProcessDHTElement<InfoType>::unpackElement(indexToInfoMapping[indexTmp[i]], beginBuff, infoIndex);
         }
         nbSendBuffInfoReceived += actualCountInfo;
@@ -260,4 +253,5 @@
   if (0 != maxNbIndexDemandedFromOthers) delete [] recvBuffIndex;
   if (0 != nbIndexReceivedFromOthers) delete [] recvBuffInfo;
+  for (int idx = 0; idx < infoToSend.size(); ++idx) delete [] infoToSend[idx];
   delete [] sendBuff;
   delete [] recvBuff;
@@ -346,5 +340,5 @@
   int recvNbIndexCount = recvNbIndexBuff[clientRank];
   unsigned long* recvIndexBuff = new unsigned long[recvNbIndexCount];
-  unsigned char* recvInfoBuff = new unsigned char[recvNbIndexCount*infoTypeSize];
+  unsigned char* recvInfoBuff = new unsigned char[recvNbIndexCount*ProcessDHTElement<InfoType>::typeSize()];
 
   // If a client holds information about index and the corresponding which don't belong to it,
@@ -356,8 +350,31 @@
   for (; itIndex != iteIndex; ++itIndex)
     sendIndexToClients(itIndex->first, itIndex->second, commLevel, sendRequest);
-  typename std::map<int, std::vector<InfoType> >::iterator itInfo  = client2ClientInfo.begin(),
+  typename std::map<int, std::vector<InfoType> >::iterator itbInfo = client2ClientInfo.begin(), itInfo,
                                                            iteInfo = client2ClientInfo.end();
-  for (; itInfo != iteInfo; ++itInfo)
-    sendInfoToClients(itInfo->first, itInfo->second, commLevel, sendRequest);
+
+  std::vector<int> infoSizeToSend(client2ClientInfo.size(),0);
+  std::vector<unsigned char*> infoToSend(client2ClientInfo.size());
+  itInfo = itbInfo;
+  for (int idx = 0; itInfo != iteInfo; ++itInfo, ++idx)
+  {
+    const std::vector<InfoType>& infoVec = itInfo->second;
+    int infoVecSize = infoVec.size();
+    std::vector<int> infoIndex(infoVecSize);
+    for (int i = 0; i < infoVecSize; ++i)
+    {
+      infoIndex[i] = infoSizeToSend[idx];
+      ProcessDHTElement<InfoType>::packElement(infoVec[i], NULL, infoSizeToSend[idx]);
+    }
+
+    infoToSend[idx] = new unsigned char[infoSizeToSend[idx]];
+    infoSizeToSend[idx] = 0;
+    for (int i = 0; i < infoVecSize; ++i)
+    {
+      ProcessDHTElement<InfoType>::packElement(infoVec[i], infoToSend[idx], infoSizeToSend[idx]);
+    }
+
+    sendInfoToClients(itInfo->first, infoToSend[idx], infoSizeToSend[idx], commLevel, sendRequest);
+  }
+
 
   std::map<int, MPI_Request>::iterator itRequestIndex, itRequestInfo;
@@ -424,10 +441,10 @@
       {
         int count = it->second;
-        TypeToBytes<InfoType> u;
+        InfoType infoValue;
+        int infoIndex = 0;
         for (int i = 0; i < count; ++i)
         {
-          unsigned char* tmpBeginBuff = infoBuffBegin[rank]+i*infoTypeSize;
-          for (size_t idx = 0; idx < infoTypeSize; ++idx) u.bytes[idx] = *(tmpBeginBuff+idx);
-          indexToInfoMapping.insert(std::make_pair<size_t,InfoType>(*(indexBuffBegin[rank]+i),u.value));
+          ProcessDHTElement<InfoType>::unpackElement(infoValue, infoBuffBegin[rank], infoIndex);
+          indexToInfoMapping.insert(std::make_pair<size_t,InfoType>(*(indexBuffBegin[rank]+i),infoValue));
         }
 
@@ -448,4 +465,5 @@
   }
 
+  for (int idx = 0; idx < infoToSend.size(); ++idx) delete [] infoToSend[idx];
   delete [] sendBuff;
   delete [] sendNbIndexBuff;
@@ -563,12 +581,11 @@
 */
 template<typename T, typename H>
-void CClientClientDHTTemplate<T,H>::sendInfoToClients(int clientDestRank, std::vector<T>& info,
-                                                      const MPI_Comm& clientIntraComm,
-                                                      std::list<MPI_Request>& requestSendInfo)
+void CClientClientDHTTemplate<T,H>::sendInfoToClients(int clientDestRank, unsigned char* info, int infoSize,
+                       const MPI_Comm& clientIntraComm, std::list<MPI_Request>& requestSendInfo)
 {
   MPI_Request request;
   requestSendInfo.push_back(request);
 
-  MPI_Isend(&(info)[0], info.size() * infoTypeSize, MPI_CHAR,
+  MPI_Isend(info, infoSize, MPI_CHAR,
             clientDestRank, MPI_DHT_INFO, clientIntraComm, &(requestSendInfo.back()));
 }
Index: XIOS/trunk/src/dht_data_types.hpp
===================================================================
--- XIOS/trunk/src/dht_data_types.hpp	(revision 830)
+++ XIOS/trunk/src/dht_data_types.hpp	(revision 830)
@@ -0,0 +1,89 @@
+/*!
+   \file dht_data_types.hpp
+   \author Ha NGUYEN
+   \since 17 Mars 2016
+   \date 17 Mars 2016
+
+   \brief Customized data type for dht
+ */
+
+#ifndef __XIOS_DHT_DATATYPES_HPP__
+#define __XIOS_DHT_DATATYPES_HPP__
+
+#include "utils.hpp"
+
+namespace xios
+{
+  typedef std::pair<int,int> PairIntInt;
+//struct PairIntInt
+//{
+////  PairIntInt(int f, int s) : first(f), second(s) {}
+////  PairIntInt(const PairIntInt& p)
+////  {
+////    this->first = p.first;
+////    this->second=p.second;
+////  }
+//
+//  int first;
+//  int second;
+//};
+
+template<typename T>
+struct ProcessDHTElement
+{
+  typedef T Type;
+  static int typeSize()
+  {
+    return sizeof(Type);
+  }
+
+  static void packElement(const T& inputElement, unsigned char* packedElement, int& index)
+  {
+    if (NULL == packedElement) index += sizeof(Type);
+    else
+    {
+      *(T *)(&packedElement[index]) = inputElement;
+      index+=sizeof(Type);
+    }
+  }
+
+  static void unpackElement(T& outputElement, unsigned char* unpackedElement, int& index)
+  {
+    outputElement = *(Type*)(&unpackedElement[index]);
+    index+=sizeof(Type);
+  }
+};
+
+template<>
+struct ProcessDHTElement<PairIntInt>
+{
+  typedef PairIntInt Type;
+  static int typeSize()
+  {
+    return (2*sizeof(int));
+  }
+
+  static void packElement(const PairIntInt& inputElement, unsigned char* packedElement, int& index)
+  {
+    if (NULL == packedElement) index +=(2*sizeof(int));
+    else
+    {
+      *(int *)(&packedElement[index]) = inputElement.first;
+      index+=sizeof(int);
+      *(int *)(&packedElement[index]) = inputElement.second;
+      index+=sizeof(int);
+    }
+  }
+
+  static void unpackElement(PairIntInt& outputElement, unsigned char* unpackedElement, int& index)
+  {
+    outputElement.first=*(int *)(&unpackedElement[index]);
+    index+=sizeof(int);
+    outputElement.second=*(int *)(&unpackedElement[index]);
+    index+=sizeof(int);
+  }
+};
+
+}
+
+#endif // __XIOS_DHT_DATATYPES_HPP__
