Index: XIOS/dev/branch_yushan/bld.cfg
===================================================================
--- XIOS/dev/branch_yushan/bld.cfg	(revision 1058)
+++ XIOS/dev/branch_yushan/bld.cfg	(revision 1060)
@@ -36,5 +36,5 @@
 #test_remap.exe
 #bld::target test_new_features.exe test_unstruct_complete.exe 
-bld::target test_client.exe test_complete.exe
+bld::target test_client.exe #test_complete.exe
 bld::exe_dep
 
Index: XIOS/dev/branch_yushan/extern/src_ep_dev/ep_create.cpp
===================================================================
--- XIOS/dev/branch_yushan/extern/src_ep_dev/ep_create.cpp	(revision 1058)
+++ XIOS/dev/branch_yushan/extern/src_ep_dev/ep_create.cpp	(revision 1060)
@@ -185,5 +185,5 @@
     }
 
-    printf("ep_lib::MPI_Comm_create_endpoints()       OK from void*\n");
+    //printf("ep_lib::MPI_Comm_create_endpoints()       OK from void*\n");
 
     return 0;
Index: XIOS/dev/branch_yushan/extern/src_ep_dev/ep_fortran.cpp
===================================================================
--- XIOS/dev/branch_yushan/extern/src_ep_dev/ep_fortran.cpp	(revision 1058)
+++ XIOS/dev/branch_yushan/extern/src_ep_dev/ep_fortran.cpp	(revision 1060)
@@ -32,5 +32,5 @@
     {
       fc_comm_map.insert(std::make_pair( std::make_pair( fint, omp_get_thread_num()) , comm));
-      printf("EP_Comm_c2f : MAP insert: %d, %d, %p\n", fint, omp_get_thread_num(), &comm);
+      //printf("EP_Comm_c2f : MAP insert: %d, %d, %p\n", fint, omp_get_thread_num(), &comm);
     }
     
@@ -52,5 +52,5 @@
       MPI_Comm comm_ptr;
       comm_ptr =  it->second;
-      printf("EP_Comm_f2c : MAP find: %d, %d, %p\n", it->first.first, it->first.second, &comm_ptr);
+      //printf("EP_Comm_f2c : MAP find: %d, %d, %p\n", it->first.first, it->first.second, &comm_ptr);
       return  comm_ptr;
     }
Index: XIOS/dev/branch_yushan/extern/src_ep_dev/ep_intercomm.cpp
===================================================================
--- XIOS/dev/branch_yushan/extern/src_ep_dev/ep_intercomm.cpp	(revision 1058)
+++ XIOS/dev/branch_yushan/extern/src_ep_dev/ep_intercomm.cpp	(revision 1060)
@@ -56,5 +56,5 @@
       if( leader_ranks[1] * leader_ranks[4] == 1)
       {
-        if(ep_rank == local_leader) printf("calling MPI_Intercomm_create_unique_leader\n");
+        if(ep_rank == local_leader) Debug("calling MPI_Intercomm_create_unique_leader\n");
         local_comm.ep_comm_ptr->comm_label = -99;
 
@@ -64,5 +64,5 @@
       {
         // change leader
-        if(ep_rank == local_leader) printf("calling MPI_Intercomm_create_from_world\n");
+        if(ep_rank == local_leader) Debug("calling MPI_Intercomm_create_from_world\n");
 
         int new_local_leader;
@@ -179,5 +179,5 @@
     }
 
-    if(ep_rank == local_leader) printf("calling MPI_Intercomm_create_kernel\n");
+    if(ep_rank == local_leader) Debug("calling MPI_Intercomm_create_kernel\n");
 
     return MPI_Intercomm_create_kernel(local_comm, local_leader, peer_comm, remote_leader, tag, newintercomm);
Index: XIOS/dev/branch_yushan/extern/src_ep_dev/ep_lib.cpp
===================================================================
--- XIOS/dev/branch_yushan/extern/src_ep_dev/ep_lib.cpp	(revision 1058)
+++ XIOS/dev/branch_yushan/extern/src_ep_dev/ep_lib.cpp	(revision 1060)
@@ -52,5 +52,5 @@
       if(  comm.ep_comm_ptr->intercomm->remote_rank_map->at(i).first  == inter_rank  )
       {
-        printf("get_ep_rank for intercomm, ep_rank_loc = %d, mpi_rank = %d => ep_src = %d\n", ep_rank_loc, mpi_rank, i);
+        //printf("get_ep_rank for intercomm, ep_rank_loc = %d, mpi_rank = %d => ep_src = %d\n", ep_rank_loc, mpi_rank, i);
         return i;
       }
Index: XIOS/dev/branch_yushan/extern/src_ep_dev/ep_probe.cpp
===================================================================
--- XIOS/dev/branch_yushan/extern/src_ep_dev/ep_probe.cpp	(revision 1058)
+++ XIOS/dev/branch_yushan/extern/src_ep_dev/ep_probe.cpp	(revision 1060)
@@ -36,7 +36,7 @@
 
     #pragma omp critical (_query)
-    if(comm.ep_comm_ptr->message_queue->size() > 0)
+    if(!comm.ep_comm_ptr->message_queue->empty())
     {
-      for(Message_list::iterator it = comm.ep_comm_ptr->message_queue->begin(); it!= comm.ep_comm_ptr->message_queue->end(); it++)
+      for(Message_list::iterator it = comm.ep_comm_ptr->message_queue->begin(); it!= comm.ep_comm_ptr->message_queue->end(); ++it)
       {
         bool src_matched = src<0? true: it->ep_src == src;
@@ -107,7 +107,7 @@
 
     #pragma omp critical (_query)
-    if(comm.ep_comm_ptr->message_queue->size() > 0)
+    if(! comm.ep_comm_ptr->message_queue->empty())
     {
-      for(Message_list::iterator it = comm.ep_comm_ptr->message_queue->begin(); it!= comm.ep_comm_ptr->message_queue->end(); it++)
+      for(Message_list::iterator it = comm.ep_comm_ptr->message_queue->begin(); it!= comm.ep_comm_ptr->message_queue->end(); ++it)
       {
         bool src_matched = src<0? true: it->ep_src == src;
Index: XIOS/dev/branch_yushan/inputs/iodef.xml
===================================================================
--- XIOS/dev/branch_yushan/inputs/iodef.xml	(revision 1058)
+++ XIOS/dev/branch_yushan/inputs/iodef.xml	(revision 1060)
@@ -12,5 +12,5 @@
 
 
-   <file_definition type="one_file" par_access="collective" output_freq="6h" output_level="10" enabled=".TRUE.">
+   <file_definition type="multiple_file" par_access="collective" output_freq="6h" output_level="10" enabled=".TRUE.">
      <file id="output" name="output">
         <field field_ref="field_A_zoom" name="field_A" />
Index: XIOS/dev/branch_yushan/src/client.cpp
===================================================================
--- XIOS/dev/branch_yushan/src/client.cpp	(revision 1058)
+++ XIOS/dev/branch_yushan/src/client.cpp	(revision 1060)
@@ -24,5 +24,5 @@
     StdOFStream CClient::m_errorStream;
 
-    void CClient::initialize(const string& codeId,MPI_Comm& localComm,MPI_Comm& returnComm)
+    void CClient::initialize(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm)
     {
       int initialized ;
@@ -161,8 +161,5 @@
 
       if (!CXios::isServer)
-      {
-      
-        
-        
+      {      
         int size,rank,globalRank ;
         size_t message_size ;
@@ -191,5 +188,5 @@
         delete [] buff ;
         
-        printf("====== Client: begin context_init \n");
+        //printf("====== Client: begin context_init \n");
       
 
@@ -197,18 +194,18 @@
         info(10)<<"Register new Context : "<<id<<endl ;
         
-        cout<<"Register new Context : "<<id<<endl ;
+        //cout<<"Register new Context : "<<id<<endl ;
               
 
-        MPI_Comm inter ;
-        MPI_Intercomm_merge(contextInterComm,0,&inter) ;
-        MPI_Barrier(inter) ;
+        // MPI_Comm inter ;
+        // MPI_Intercomm_merge(contextInterComm,0,&inter) ;
+        // MPI_Barrier(inter) ;
         
         
         context->initClient(contextComm,contextInterComm) ;
         
-        printf("====== Client: context_init OK\n");
+        //printf("====== Client: context_init OK\n");
 
         contextInterComms.push_back(contextInterComm);
-        MPI_Comm_free(&inter);
+        // MPI_Comm_free(&inter);
       }
       else
@@ -252,4 +249,5 @@
       for (std::list<MPI_Comm>::iterator it = contextInterComms.begin(); it != contextInterComms.end(); it++)
         MPI_Comm_free(&(*it));
+      
       MPI_Comm_free(&interComm);
       MPI_Comm_free(&intraComm);
Index: XIOS/dev/branch_yushan/src/context_client.cpp
===================================================================
--- XIOS/dev/branch_yushan/src/context_client.cpp	(revision 1058)
+++ XIOS/dev/branch_yushan/src/context_client.cpp	(revision 1060)
@@ -199,4 +199,5 @@
       map<int,CClientBuffer*>::iterator itBuff;
       bool pending = false;
+      if(! buffers.empty())
       for (itBuff = buffers.begin(); itBuff != buffers.end(); itBuff++) pending |= itBuff->second->checkBuffer();
       return pending;
@@ -307,5 +308,5 @@
        checkBuffers();
        stop = false;
-       for (itBuff = buffers.begin(); itBuff != buffers.end(); itBuff++) stop |= itBuff->second->hasPendingRequest();
+       for (itBuff = buffers.begin(); itBuff != buffers.end(); ++itBuff) stop |= itBuff->second->hasPendingRequest();
      }
      CTimer::get("Blocking time").suspend();
Index: XIOS/dev/branch_yushan/src/context_server.cpp
===================================================================
--- XIOS/dev/branch_yushan/src/context_server.cpp	(revision 1058)
+++ XIOS/dev/branch_yushan/src/context_server.cpp	(revision 1060)
@@ -122,5 +122,5 @@
 
     //printf("enter checkPendingRequest\n");
-
+    if(!pendingRequest.empty())
     for(it=pendingRequest.begin();it!=pendingRequest.end();it++)
     {
Index: XIOS/dev/branch_yushan/src/cxios.cpp
===================================================================
--- XIOS/dev/branch_yushan/src/cxios.cpp	(revision 1058)
+++ XIOS/dev/branch_yushan/src/cxios.cpp	(revision 1060)
@@ -33,7 +33,5 @@
   //! Parse configuration file and create some objects from it
   void CXios::initialize()
-  {
-    
-    
+  {    
     set_new_handler(noMemory);
     parseFile(rootFile);
@@ -85,5 +83,6 @@
     int tmp_size;
     MPI_Comm_size(globalComm, &tmp_size);
-    printf("globalcomm size = %d\n", tmp_size);
+    if(isClient) printf("Client : globalcomm size = %d\n", tmp_size);
+    if(isServer) printf("Server : globalcomm size = %d\n", tmp_size);
 
     
@@ -176,4 +175,5 @@
     // Initialize all aspects MPI
     CServer::initialize();
+    
     if (CServer::getRank()==0) globalRegistry = new CRegistry(CServer::intraComm) ;
     
@@ -193,5 +193,5 @@
     CServer::eventLoop();
     
-    printf("server eventloop OK\n");
+    printf("server start finalize \n");
 
     // Finalize
Index: XIOS/dev/branch_yushan/src/interface/c/icdata.cpp
===================================================================
--- XIOS/dev/branch_yushan/src/interface/c/icdata.cpp	(revision 1058)
+++ XIOS/dev/branch_yushan/src/interface/c/icdata.cpp	(revision 1060)
@@ -63,5 +63,5 @@
       int initialized;
       MPI_Initialized(&initialized);
-      //if (initialized) local_comm.mpi_comm = MPI_Comm_f2c(*f_local_comm);
+
       if (initialized) local_comm = ep_lib::EP_Comm_f2c(static_cast< int >(*f_local_comm));
       else local_comm = MPI_COMM_NULL;
@@ -73,5 +73,5 @@
       *f_return_comm = ep_lib::EP_Comm_c2f(return_comm);
 
-      printf("in icdata.cpp, f_return_comm = %d\n", *f_return_comm);
+      //printf("in icdata.cpp, f_return_comm = %d\n", *f_return_comm);
 
       CTimer::get("XIOS init").suspend();
@@ -91,5 +91,5 @@
      CClient::registerContext(str, comm);
      
-     printf("icdata.cpp: client register context OK\n");
+     //printf("icdata.cpp: client register context OK\n");
      
      CTimer::get("XIOS init context").suspend();
@@ -128,8 +128,7 @@
      
      CContext* context = CContext::getCurrent();
-     //printf("CContext* context = CContext::getCurrent();\n");
      context->finalize();
      
-     //printf("client context_finalize OK\n");
+     printf("client context_finalize OK\n");
      
      CTimer::get("XIOS context finalize").suspend();
Index: XIOS/dev/branch_yushan/src/node/context.cpp
===================================================================
--- XIOS/dev/branch_yushan/src/node/context.cpp	(revision 1058)
+++ XIOS/dev/branch_yushan/src/node/context.cpp	(revision 1060)
@@ -369,5 +369,4 @@
           closeAllFile();
           registryOut->hierarchicalGatherRegistry() ;
-          //registryOut->gatherRegistry() ;
           if (server->intraCommRank==0) CXios::globalRegistry->mergeRegistry(*registryOut) ;
         }
Index: XIOS/dev/branch_yushan/src/server.cpp
===================================================================
--- XIOS/dev/branch_yushan/src/server.cpp	(revision 1058)
+++ XIOS/dev/branch_yushan/src/server.cpp	(revision 1060)
@@ -32,7 +32,16 @@
     void CServer::initialize(void)
     {
+      // int initialized ;
+      // MPI_Initialized(&initialized) ;
+      // if (initialized) is_MPI_Initialized=true ;
+      // else is_MPI_Initialized=false ;
+
       // Not using OASIS
       if (!CXios::usingOasis)
       {
+        // if (!is_MPI_Initialized)
+        // {
+        //   MPI_Init(NULL, NULL);
+        // }
 
         CTimer::get("XIOS").resume() ;
@@ -79,5 +88,5 @@
 
          serverLeader=leaders[hashServer] ;
-         for(it=leaders.begin();it!=leaders.end();it++)
+         for(it=leaders.begin();it!=leaders.end();++it)
          {
            if (it->first!=hashServer)
@@ -92,5 +101,5 @@
              MPI_Intercomm_create(intraComm,0,CXios::globalComm,clientLeader,0,&newComm) ;
              interComm.push_back(newComm) ;
-             printf("after inter create, interComm.size = %lu\n", interComm.size());
+             //printf("after inter create, interComm.size = %lu\n", interComm.size());
            }
          }
@@ -131,5 +140,4 @@
       }
 
-//      int rank;
       MPI_Comm_rank(intraComm,&rank) ;
       if (rank==0) isRoot=true;
@@ -147,8 +155,8 @@
       
 
-      for (std::list<MPI_Comm>::iterator it = contextInterComms.begin(); it != contextInterComms.end(); it++)
+      for (std::list<MPI_Comm>::iterator it = contextInterComms.begin(); it != contextInterComms.end(); ++it)
         MPI_Comm_free(&(*it));
 
-      for (std::list<MPI_Comm>::iterator it = interComm.begin(); it != interComm.end(); it++)
+      for (std::list<MPI_Comm>::iterator it = interComm.begin(); it != interComm.end(); ++it)
         MPI_Comm_free(&(*it));
 
@@ -214,5 +222,5 @@
            {
               MPI_Recv(&msg,1,MPI_INT,0,0,*it,&status) ;
-              printf(" CServer : Receive client finalize\n");
+              printf(" CServer : Receive finalize sign from client 0\n");
               info(20)<<" CServer : Receive client finalize"<<endl ;
 
@@ -410,7 +418,7 @@
        MPI_Intercomm_create(intraComm,0,CXios::globalComm,leaderRank,10+leaderRank,&contextIntercomm);
 
-       MPI_Comm inter;
-       MPI_Intercomm_merge(contextIntercomm,1,&inter);
-       MPI_Barrier(inter);
+       // MPI_Comm inter;
+       // MPI_Intercomm_merge(contextIntercomm,1,&inter);
+       // MPI_Barrier(inter);
        
 
@@ -424,7 +432,7 @@
        
        
-       MPI_Comm_free(&inter);
-       
-       printf(" ****   server: register context OK\n");
+       // MPI_Comm_free(&inter);
+       
+       //printf(" ****   server: register context OK\n");
      }
 
Index: XIOS/dev/branch_yushan/src/xios_server.f90
===================================================================
--- XIOS/dev/branch_yushan/src/xios_server.f90	(revision 1058)
+++ XIOS/dev/branch_yushan/src/xios_server.f90	(revision 1060)
@@ -1,8 +1,11 @@
 PROGRAM server_main
   USE xios
+  USE mod_wait
   IMPLICIT NONE
   INCLUDE "mpif.h"
   INTEGER :: ierr
-  
+    
+    CALL MPI_INIT(ierr)
+    CALL init_wait
     CALL xios_init_server
 
