Index: XIOS/dev/dev_olga/src/node/context.cpp
===================================================================
--- XIOS/dev/dev_olga/src/node/context.cpp	(revision 1204)
+++ XIOS/dev/dev_olga/src/node/context.cpp	(revision 1208)
@@ -526,4 +526,7 @@
      checkGridEnabledFields();    
 
+     // Distribute files between secondary servers according to the data size
+     distributeFiles();
+
      // Buffer for primary server for connection to client will be allocated by default (to min size)
      if (CServer::serverLevel != 1)
@@ -815,18 +818,83 @@
                << getId() << "\" !");
 
-      // Assigning contextClient to each enabled file
-      if (hasClient)
-      {
-        for (int i = 0; i < enabledFiles.size(); ++i)
-        {
-          if (hasServer)
-          {
-            int srvId = i % clientPrimServer.size();
-            enabledFiles[i]->setContextClient(clientPrimServer[srvId]);
-          }
-          else
-            enabledFiles[i]->setContextClient(client);
-        }
-      }
+   }
+
+   void CContext::distributeFiles(void)
+   {
+     // If primary server
+     if (hasServer && hasClient)
+     {
+       // (1) Find all enabled files in write mode
+       for (int i = 0; i < this->enabledFiles.size(); ++i)
+       {
+         if (enabledFiles[i]->mode.isEmpty() || (!enabledFiles[i]->mode.isEmpty() && enabledFiles[i]->mode.getValue() == CFile::mode_attr::write ))
+          enabledWriteModeFiles.push_back(enabledFiles[i]);
+       }
+
+       // (2) Estimate the data volume for each file
+       int size = this->enabledWriteModeFiles.size();
+       std::vector<std::pair<StdSize, CFile*> > dataSizeMap;
+       for (size_t i = 0; i < size; ++i)
+       {
+         CFile* file = this->enabledWriteModeFiles[i];
+         StdSize dataSize;
+         std::vector<CField*> enabledFields = file->getEnabledFields();
+         size_t numEnabledFields = enabledFields.size();
+         for (size_t j = 0; j < numEnabledFields; ++j)
+         {
+           const std::vector<std::map<int, StdSize> > mapSize = enabledFields[j]->getGridDataBufferSize();
+           for (size_t c = 0; c < mapSize.size(); ++c)
+           {
+             std::map<int, StdSize>::const_iterator it = mapSize[c].begin(), itE = mapSize[c].end();
+             for (; it != itE; ++it)
+             {
+               dataSize += it->second;
+             }
+           }
+         }
+         CDuration outFreq = file->output_freq.getValue();
+         if (outFreq.timestep != 0.0)
+         {
+           outFreq = calendar->getTimeStep();
+         }
+         double outFreqSec = outFreq.second + 60.*(outFreq.minute + 60.*(outFreq.hour + 24.*(outFreq.day + outFreq.year*365.25) ) );
+         dataSize /= outFreqSec;
+         dataSizeMap.push_back(make_pair(dataSize,file));
+       }
+
+       // (3) Sort enabledWriteModeFiles
+       std::sort(dataSizeMap.begin(), dataSizeMap.end());
+       for (int i = 0; i < size; ++i)
+       {
+         enabledWriteModeFiles[i] = dataSizeMap[i].second;
+       }
+
+       // (4) Assign contextClient to each enabled file
+       int i,j;
+       for (i = 0, j=0; i < enabledFiles.size(); ++i)
+       {
+         if (enabledFiles[i]->mode.isEmpty() || (!enabledFiles[i]->mode.isEmpty() && enabledFiles[i]->mode.getValue() == CFile::mode_attr::write ))
+         {
+           int n = j / clientPrimServer.size();
+           int mod = j % clientPrimServer.size();
+           int poolId;
+           if (n % 2 == 0)
+             poolId =mod;
+           else
+             poolId = clientPrimServer.size()-1-mod;
+            enabledWriteModeFiles[j]->setContextClient(clientPrimServer[poolId]);
+           ++j;
+         }
+         else
+         {
+           enabledFiles[i]->setContextClient(client);
+         }
+       }
+     }
+     else
+     {
+       for (int i = 0; i < this->enabledFiles.size(); ++i)
+         enabledFiles[i]->setContextClient(client);
+     }
    }
 
Index: XIOS/dev/dev_olga/src/node/context.hpp
===================================================================
--- XIOS/dev/dev_olga/src/node/context.hpp	(revision 1204)
+++ XIOS/dev/dev_olga/src/node/context.hpp	(revision 1208)
@@ -136,4 +136,7 @@
          void setClientServerBuffer(CContextClient* contextClient);
 
+         // Estimate data size for each enabled file in write mode
+         void distributeFiles(void);
+
          // Send context close definition
          void sendCloseDefinition(void);
@@ -223,4 +226,6 @@
          // List of all enabled files in read mode (files on which fields are read)
          std::vector<CFile*> enabledReadModeFiles;
+         // List of all enabled files in write mode
+         std::vector<CFile*> enabledWriteModeFiles;
 
          // List of all enabled fields whose instant data is accessible from the public API
Index: XIOS/dev/dev_olga/src/server.cpp
===================================================================
--- XIOS/dev/dev_olga/src/server.cpp	(revision 1204)
+++ XIOS/dev/dev_olga/src/server.cpp	(revision 1208)
@@ -100,5 +100,5 @@
         for (i=0; i<srvRanks.size(); i++)
         {
-          if (i >= srvRanks.size()*CXios::ratioServer2/100)
+          if (i > srvRanks.size()*(100-CXios::ratioServer2)/100)
           {
             sndServerGlobalRanks.push_back(srvRanks[i]);
