Index: XIOS/dev/branch_openmp/src/client.cpp
===================================================================
--- XIOS/dev/branch_openmp/src/client.cpp	(revision 1374)
+++ XIOS/dev/branch_openmp/src/client.cpp	(revision 1460)
@@ -22,5 +22,5 @@
     int CClient::serverLeader ;
     bool CClient::is_MPI_Initialized ;
-    int CClient::rank = INVALID_RANK;
+    int CClient::rank_ = INVALID_RANK;
     StdOFStream CClient::m_infoStream;
     StdOFStream CClient::m_errorStream;
@@ -28,5 +28,16 @@
     StdOFStream CClient::array_infoStream[16];
 
-    void CClient::initialize(const string& codeId,MPI_Comm& localComm,MPI_Comm& returnComm)
+    MPI_Comm& CClient::getInterComm(void)   { return (interComm); }
+
+///---------------------------------------------------------------
+/*!
+ * \fn void CClient::initialize(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm)
+ * Function creates intraComm (CClient::intraComm) for client group with id=codeId and interComm (CClient::interComm) between client and server groups.
+ * \param [in] codeId identity of context.
+ * \param [in/out] localComm local communicator.
+ * \param [in/out] returnComm (intra)communicator of client group.
+ */
+
+    void CClient::initialize(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm)
     {
       int initialized ;
@@ -34,9 +45,10 @@
       if (initialized) is_MPI_Initialized=true ;
       else is_MPI_Initialized=false ;
+      int rank ;
 
 // don't use OASIS
       if (!CXios::usingOasis)
       {
-// localComm doesn't given
+// localComm isn't given
         if (localComm == MPI_COMM_NULL)
         {
@@ -58,5 +70,5 @@
 
           MPI_Comm_size(CXios::globalComm,&size) ;
-          MPI_Comm_rank(CXios::globalComm,&rank);
+          MPI_Comm_rank(CXios::globalComm,&rank_);
 
           hashAll=new unsigned long[size] ;
@@ -88,7 +100,6 @@
           }
 
-          myColor=colors[hashClient] ;
-
-          MPI_Comm_split(CXios::globalComm,myColor,rank,&intraComm) ;
+          myColor=colors[hashClient];
+          MPI_Comm_split(CXios::globalComm,myColor,rank_,&intraComm) ;
 
           if (CXios::usingServer)
@@ -96,5 +107,4 @@
             int clientLeader=leaders[hashClient] ;
             serverLeader=leaders[hashServer] ;
-
             int intraCommSize, intraCommRank ;
             MPI_Comm_size(intraComm,&intraCommSize) ;
@@ -102,8 +112,9 @@
             #pragma omp critical (_output)
             {
-              info(50)<<"intercommCreate::client "<<rank<<" intraCommSize : "<<intraCommSize
-                      <<" intraCommRank :"<<intraCommRank<<"  serverLeader "<< serverLeader<<endl ;
-            }
-            MPI_Intercomm_create(intraComm,0,CXios::globalComm,serverLeader,0,&interComm) ;
+              info(50)<<"intercommCreate::client "<<rank_<<" intraCommSize : "<<intraCommSize
+                   <<" intraCommRank :"<<intraCommRank<<"  clientLeader "<< serverLeader<<endl ;
+            } 
+            MPI_Intercomm_create(intraComm, 0, CXios::globalComm, serverLeader, 0, &interComm) ;
+            //rank_ = intraCommRank;
           }
           else
@@ -128,7 +139,7 @@
       }
       // using OASIS
-/*      else
-      {
-        // localComm doesn't given
+      else
+      {
+        // localComm isn't given
         if (localComm == MPI_COMM_NULL)
         {
@@ -144,19 +155,25 @@
         {
           MPI_Status status ;
-          MPI_Comm_rank(intraComm,&rank) ;
+          MPI_Comm_rank(intraComm,&rank_) ;
 
           oasis_get_intercomm(interComm,CXios::xiosCodeId) ;
-          if (rank==0) MPI_Recv(&serverLeader,1, MPI_INT, 0, 0, interComm, &status) ;
+          if (rank_==0) MPI_Recv(&serverLeader,1, MPI_INT, 0, 0, interComm, &status) ;
           MPI_Bcast(&serverLeader,1,MPI_INT,0,intraComm) ;
-
         }
         else MPI_Comm_dup(intraComm,&interComm) ;
       }
-*/
+
       MPI_Comm_dup(intraComm,&returnComm) ;
     }
 
-
-    void CClient::registerContext(const string& id,MPI_Comm contextComm)
+///---------------------------------------------------------------
+/*!
+ * \fn void CClient::registerContext(const string& id, MPI_Comm contextComm)
+ * \brief Sends a request to create a context to server. Creates client/server contexts.
+ * \param [in] id id of context.
+ * \param [in] contextComm.
+ * Function is only called by client.
+ */
+    void CClient::registerContext(const string& id, MPI_Comm contextComm)
     {
       CContext::setCurrent(id) ;
@@ -165,5 +182,25 @@
       idServer += "_server";
 
-      if (!CXios::isServer)
+      if (CXios::isServer && !context->hasServer)
+      // Attached mode
+      {
+        MPI_Comm contextInterComm ;
+        MPI_Comm_dup(contextComm,&contextInterComm) ;
+        CContext* contextServer = CContext::create(idServer);
+
+        // Firstly, initialize context on client side
+        context->initClient(contextComm,contextInterComm, contextServer);
+
+        // Secondly, initialize context on server side
+        contextServer->initServer(contextComm,contextInterComm, context);
+
+        // Finally, we should return current context to context client
+        CContext::setCurrent(id);
+
+        //contextInterComms.push_back(contextInterComm);
+        if(contextInterComms_ptr == NULL) contextInterComms_ptr = new std::list<MPI_Comm>;
+        contextInterComms_ptr->push_back(contextInterComm);
+      }
+      else
       {
         int size,rank,globalRank ;
@@ -177,5 +214,4 @@
         if (rank!=0) globalRank=0 ;
 
-
         CMessage msg ;
         msg<<idServer<<size<<globalRank ;
@@ -189,14 +225,7 @@
         MPI_Send((void*)buff,buffer.count(),MPI_CHAR,serverLeader,1,CXios::globalComm) ;
 
-        delete [] buff ;
-
-        //MPI_Barrier(CXios::globalComm);
-
         MPI_Intercomm_create(contextComm,0,CXios::globalComm,serverLeader,10+globalRank,&contextInterComm) ;
         #pragma omp critical (_output)
-        {
-          info(10)<<"Register new Context : "<<id<<endl ;
-        }
-
+        info(10)<<"Register new Context : "<<id<<endl ;
         MPI_Comm inter ;
         MPI_Intercomm_merge(contextInterComm,0,&inter) ;
@@ -208,24 +237,8 @@
         if(contextInterComms_ptr == NULL) contextInterComms_ptr = new std::list<MPI_Comm>;
         contextInterComms_ptr->push_back(contextInterComm);
+
         MPI_Comm_free(&inter);
-      }
-      else
-      {
-        MPI_Comm contextInterComm ;
-        MPI_Comm_dup(contextComm,&contextInterComm) ;
-        CContext* contextServer = CContext::create(idServer);
-
-        // Firstly, initialize context on client side
-        context->initClient(contextComm,contextInterComm, contextServer);
-
-        // Secondly, initialize context on server side
-        contextServer->initServer(contextComm,contextInterComm, context);
-
-        // Finally, we should return current context to context client
-        CContext::setCurrent(id);
-
-        //contextInterComms.push_back(contextInterComm);
-        if(contextInterComms_ptr == NULL) contextInterComms_ptr = new std::list<MPI_Comm>;
-        contextInterComms_ptr->push_back(contextInterComm);
+        delete [] buff ;
+
       }
     }
@@ -264,7 +277,6 @@
       #pragma omp critical (_output)
       info(20) << "Client side context is finalized"<<endl ;
-      
-
-      /*#pragma omp critical (_output)
+
+      #pragma omp critical (_output)
       {
         report(0) <<" Performance report : Whole time from XIOS init and finalize: "<< CTimer::get("XIOS init/finalize").getCumulatedTime()<<" s"<<endl ;
@@ -273,13 +285,17 @@
         report(0)<< " Performance report : Ratio : "<< CTimer::get("Blocking time").getCumulatedTime()/CTimer::get("XIOS init/finalize").getCumulatedTime()*100.<<" %"<<endl ;
         report(0)<< " Performance report : This ratio must be close to zero. Otherwise it may be usefull to increase buffer size or numbers of server"<<endl ;
+//      report(0)<< " Memory report : Current buffer_size : "<<CXios::bufferSize<<endl ;
         report(0)<< " Memory report : Minimum buffer size required : " << CClientBuffer::maxRequestSize << " bytes" << endl ;
         report(0)<< " Memory report : increasing it by a factor will increase performance, depending of the volume of data wrote in file at each time step of the file"<<endl ;
         report(100)<<CTimer::getAllCumulatedTime()<<endl ;
-      }*/
+      }
    }
 
+    /*!
+    * Return global rank without oasis and current rank in model intraComm in case of oasis
+    */
    int CClient::getRank()
    {
-     return rank;
+     return rank_;
    }
 
@@ -297,4 +313,5 @@
       int numDigit = 0;
       int size = 0;
+      int rank;
       MPI_Comm_size(CXios::globalComm, &size);
       while (size)
@@ -304,5 +321,13 @@
       }
 
-      fileNameClient << fileName << "_" << std::setfill('0') << std::setw(numDigit) << getRank() << ext;
+      if (CXios::usingOasis)
+      {
+        MPI_Comm_rank(CXios::globalComm,&rank);
+        fileNameClient << fileName << "_" << std::setfill('0') << std::setw(numDigit) << rank << ext;
+      }
+      else
+        fileNameClient << fileName << "_" << std::setfill('0') << std::setw(numDigit) << getRank() << ext;
+
+
       fb->open(fileNameClient.str().c_str(), std::ios::out);
       if (!fb->is_open())
