Index: XIOS3/trunk/src/cxios.cpp
===================================================================
--- XIOS3/trunk/src/cxios.cpp	(revision 2419)
+++ XIOS3/trunk/src/cxios.cpp	(revision 2420)
@@ -56,4 +56,5 @@
   bool CXios::checkSumRecv=false ;
   bool CXios::checkSumSend=false ;
+  bool CXios::logMemory=false ;
 
   CDaemonsManager*    CXios::daemonsManager_=nullptr ;
@@ -117,4 +118,6 @@
     checkSumSend = getin<bool>("checksum_send_fields", false);
     checkSumRecv = getin<bool>("checksum_recv_fields", false);
+    
+    logMemory = getin<bool>("log_memory", false);
 
     globalComm=MPI_COMM_WORLD ;
@@ -157,5 +160,5 @@
   void CXios::clientFinalize(void)
   {
-     CMemChecker::logMem("CXios::clientFinalize");
+     CMemChecker::logMem("CXios::clientFinalize", true);
 
      CClient::finalize() ;
Index: XIOS3/trunk/src/cxios.hpp
===================================================================
--- XIOS3/trunk/src/cxios.hpp	(revision 2419)
+++ XIOS3/trunk/src/cxios.hpp	(revision 2420)
@@ -68,4 +68,6 @@
      static bool checkSumRecv; //!< For debugging, compute a checksum of fields received by the model through the XIOS client
 
+     static bool logMemory; //!< Activate memory monitoring for all XIOS process
+    
      static const string defaultPoolId ;
      static const string defaultServerId ;
Index: XIOS3/trunk/src/mem_checker.cpp
===================================================================
--- XIOS3/trunk/src/mem_checker.cpp	(revision 2419)
+++ XIOS3/trunk/src/mem_checker.cpp	(revision 2420)
@@ -1,3 +1,4 @@
 #include "mem_checker.hpp"
+#include "cxios.hpp"
 #include "mpi.hpp"
 #include <string>
@@ -5,5 +6,4 @@
 #include <iostream>
 #include <sstream>
-#include <fstream>
 
 #include <fcntl.h>
@@ -20,5 +20,7 @@
   double CMemChecker::vsize_init_=0;
   double CMemChecker::time_init_=0;
-
+  std::ofstream CMemChecker::fout_;
+  int CMemChecker::flush_counter_=1;
+  
   CMemChecker::CMemChecker(const std::string& name) : name_(name) 
   { 
@@ -64,15 +66,6 @@
   void CMemChecker::logMem( std::string id, bool finalizeLog )
   {
-    // function get_xios_mem_data() {
-    //   return [
-    //        ...
-    //        [ "2000-01-01 01:00:10.XXX", "XIOS close context def", 1000],
-    //        [ "2000-01-01 01:00:11.XXX", "update timestep"       , 1000],
-    //        [ "2000-01-01 01:00:15.XXX", "send field"            , 2000],
-    //        ...
-    //   ];
-    // }
-    
-    std::ofstream fout;
+    if ( !CXios::logMemory ) return ;
+
     int rk = 0;
     MPI_Comm_rank( MPI_COMM_WORLD, &rk );
@@ -80,16 +73,22 @@
     double mem = getMemRSS();
     if (!mem) {
-      fout.open( logName );
-      fout << "time,event,memory" << std::endl;
-    }
-    else
-    {
-      fout.open( logName, std::ios_base::app );
+      fout_.open( logName );
+      fout_ << "time,event,memory" << std::endl;
     }
 
+    fout_.precision(4);
     // Time format : YYYY-MM-DD HH:MM:SS.XXX -> seconds * 1000.
-    fout << (MPI_Wtime()-time_init_)*1000. << "," << id << "," << mem/1000000. << std::endl;
+    fout_ << (MPI_Wtime()-time_init_) << "," << id << "," << mem/1000000. << std::endl;
 
-    fout.close();
+    if ((MPI_Wtime()-time_init_)>flush_counter_*600.)
+    {
+      fout_.flush();
+      flush_counter_++;
+    }
+    
+    if (finalizeLog)
+    {
+      fout_.close();
+    }
   }
 
Index: XIOS3/trunk/src/mem_checker.hpp
===================================================================
--- XIOS3/trunk/src/mem_checker.hpp	(revision 2419)
+++ XIOS3/trunk/src/mem_checker.hpp	(revision 2420)
@@ -4,4 +4,5 @@
 #include <string>
 #include <map>
+#include <fstream>
 
 namespace xios
@@ -39,4 +40,6 @@
       static double vsize_init_;
       static double time_init_;
+      static std::ofstream fout_;
+      static int flush_counter_;
   };
 }
Index: XIOS3/trunk/src/server.cpp
===================================================================
--- XIOS3/trunk/src/server.cpp	(revision 2419)
+++ XIOS3/trunk/src/server.cpp	(revision 2420)
@@ -434,5 +434,5 @@
       CXios::getMpiGarbageCollector().release() ; // release unfree MPI ressources
 
-      CMemChecker::logMem( "CServer::finalize" );
+      CMemChecker::logMem( "CServer::finalize", true );
       if (!is_MPI_Initialized)
       {
