Index: /XIOS/dev/branch_yushan_merged/extern/remap/src/intersect.cpp
===================================================================
--- /XIOS/dev/branch_yushan_merged/extern/remap/src/intersect.cpp	(revision 1152)
+++ /XIOS/dev/branch_yushan_merged/extern/remap/src/intersect.cpp	(revision 1153)
@@ -57,19 +57,20 @@
     {
       // share a full edge ? be carefull at the orientation
-      /*
-      if(squaredist(a.vertex[i], b.vertex[j]) > 1e-10*1e-10 ||
-         squaredist(a.vertex[(i+1)%a.n], b.vertex[(j+1)%b.n]) > 1e-10*1e-10 )
-      {      
-        printf("A : squaredist(a.vertex[%d], b.vertex[%d]) = %.10e  %d\n", 
-                i, j, squaredist(a.vertex[i], b.vertex[j]), 
-                squaredist(a.vertex[i], b.vertex[j]) > 1e-10*1e-10 ? true : false);
-        printf("B : squaredist(a.vertex[%d], b.vertex[%d]) = %.10e  %d\n", 
-                (i+1)%a.n, (j+1)%b.n, squaredist(a.vertex[(i+1)%a.n], b.vertex[(j+1)%b.n]),
-                squaredist(a.vertex[(i+1)%a.n], b.vertex[(j+1)%b.n]) > 1e-10*1e-10 ? true : false);
+      
+      //if(squaredist(a.vertex[i], b.vertex[j]) > 1e-10*1e-10 ||
+      //   squaredist(a.vertex[(i+1)%a.n], b.vertex[(j+1)%b.n]) > 1e-10*1e-10 )
+      //{      
+        //printf("A : squaredist(a.vertex[%d], b.vertex[%d]) = %.10e  %d\n", 
+        //        i, j, squaredist(a.vertex[i], b.vertex[j]), 
+        //        squaredist(a.vertex[i], b.vertex[j]) > 1e-10*1e-10 ? true : false);
+        //printf("B : squaredist(a.vertex[%d], b.vertex[%d]) = %.10e  %d\n", 
+        //        (i+1)%a.n, (j+1)%b.n, squaredist(a.vertex[(i+1)%a.n], b.vertex[(j+1)%b.n]),
+        //        squaredist(a.vertex[(i+1)%a.n], b.vertex[(j+1)%b.n]) > 1e-10*1e-10 ? true : false);
 
         assert(squaredist(a.vertex[ i       ], b.vertex[ j       ]) > 1e-10*1e-10 ||
                squaredist(a.vertex[(i+1)%a.n], b.vertex[(j+1)%b.n]) > 1e-10*1e-10);
-        exit(0);
-      }*/
+        
+      //}
+
       if (   squaredist(a.vertex[ i       ], b.vertex[ j           ]) < 1e-10*1e-10 &&
              squaredist(a.vertex[(i+1)%a.n], b.vertex[(j+b.n-1)%b.n]) < 1e-10*1e-10)
Index: /XIOS/dev/branch_yushan_merged/extern/remap/src/mapper.cpp
===================================================================
--- /XIOS/dev/branch_yushan_merged/extern/remap/src/mapper.cpp	(revision 1152)
+++ /XIOS/dev/branch_yushan_merged/extern/remap/src/mapper.cpp	(revision 1153)
@@ -303,12 +303,12 @@
             MPI_Issend(sendValue[rank], nbRecvElement[rank], MPI_DOUBLE, rank, 0, communicator, &sendRequest[nbSendRequest]);
             nbSendRequest++;
-            MPI_Issend(sendArea[rank], nbRecvElement[rank], MPI_DOUBLE, rank, 0, communicator, &sendRequest[nbSendRequest]);
+            MPI_Issend(sendArea[rank], nbRecvElement[rank], MPI_DOUBLE, rank, 1, communicator, &sendRequest[nbSendRequest]);
             nbSendRequest++;
             if (order == 2)
             {
                 MPI_Issend(sendGrad[rank], 3*nbRecvElement[rank]*(NMAX+1),
-                        MPI_DOUBLE, rank, 0, communicator, &sendRequest[nbSendRequest]);
+                        MPI_DOUBLE, rank, 2, communicator, &sendRequest[nbSendRequest]);
                 nbSendRequest++;
-                MPI_Issend(sendNeighIds[rank], 4*nbRecvElement[rank]*(NMAX+1), MPI_INT, rank, 0, communicator, &sendRequest[nbSendRequest]);
+                MPI_Issend(sendNeighIds[rank], 4*nbRecvElement[rank]*(NMAX+1), MPI_INT, rank, 3, communicator, &sendRequest[nbSendRequest]);
                 //ym  --> attention taille GloId
                 nbSendRequest++;
@@ -316,5 +316,5 @@
             else
             {
-                MPI_Issend(sendNeighIds[rank], 4*nbRecvElement[rank], MPI_INT, rank, 0, communicator, &sendRequest[nbSendRequest]);
+                MPI_Issend(sendNeighIds[rank], 4*nbRecvElement[rank], MPI_INT, rank, 4, communicator, &sendRequest[nbSendRequest]);
                 //ym  --> attention taille GloId
                 nbSendRequest++;                
@@ -325,12 +325,12 @@
             MPI_Irecv(recvValue[rank],  nbSendElement[rank], MPI_DOUBLE, rank, 0, communicator, &recvRequest[nbRecvRequest]);
             nbRecvRequest++;
-            MPI_Irecv(recvArea[rank],  nbSendElement[rank], MPI_DOUBLE, rank, 0, communicator, &recvRequest[nbRecvRequest]);
+            MPI_Irecv(recvArea[rank],  nbSendElement[rank], MPI_DOUBLE, rank, 1, communicator, &recvRequest[nbRecvRequest]);
             nbRecvRequest++;
             if (order == 2)
             {
                 MPI_Irecv(recvGrad[rank], 3*nbSendElement[rank]*(NMAX+1),
-                        MPI_DOUBLE, rank, 0, communicator, &recvRequest[nbRecvRequest]);
+                        MPI_DOUBLE, rank, 2, communicator, &recvRequest[nbRecvRequest]);
                 nbRecvRequest++;
-                MPI_Irecv(recvNeighIds[rank], 4*nbSendElement[rank]*(NMAX+1), MPI_INT, rank, 0, communicator, &recvRequest[nbRecvRequest]);
+                MPI_Irecv(recvNeighIds[rank], 4*nbSendElement[rank]*(NMAX+1), MPI_INT, rank, 3, communicator, &recvRequest[nbRecvRequest]);
                 //ym  --> attention taille GloId
                 nbRecvRequest++;
@@ -338,5 +338,5 @@
             else
             {
-                MPI_Irecv(recvNeighIds[rank], 4*nbSendElement[rank], MPI_INT, rank, 0, communicator, &recvRequest[nbRecvRequest]);
+                MPI_Irecv(recvNeighIds[rank], 4*nbSendElement[rank], MPI_INT, rank, 4, communicator, &recvRequest[nbRecvRequest]);
                 //ym  --> attention taille GloId
                 nbRecvRequest++;
Index: /XIOS/dev/branch_yushan_merged/extern/remap/src/node.hpp
===================================================================
--- /XIOS/dev/branch_yushan_merged/extern/remap/src/node.hpp	(revision 1152)
+++ /XIOS/dev/branch_yushan_merged/extern/remap/src/node.hpp	(revision 1153)
@@ -15,6 +15,6 @@
 struct Circle
 {
-	Coord centre;
-	double radius;
+  Coord centre;
+  double radius;
 };
 
@@ -116,21 +116,21 @@
 struct Node
 {
-	int level; /* FIXME leafs are 0 and root is max level? */
-	int leafCount; /* number of leafs that are descendants of this node (the elements in it's cycle) */
-	Coord centre;
-	double radius;
-	NodePtr parent, ref;
-	std::vector<NodePtr> child;
-	std::list<NodePtr> intersectors;
-	bool reinserted;
-	int updateCount;  // double var;
-	CBasicTree* tree;
-	void *data;
-	int route;
+  int level; /* FIXME leafs are 0 and root is max level? */
+  int leafCount; /* number of leafs that are descendants of this node (the elements in it's cycle) */
+  Coord centre;
+  double radius;
+  NodePtr parent, ref;
+  std::vector<NodePtr> child;
+  std::list<NodePtr> intersectors;
+  bool reinserted;
+  int updateCount;  // double var;
+  CBasicTree* tree;
+  void *data;
+  int route;
   bool toDelete ;
 
-	Node() : level(0), leafCount(1), centre(ORIGIN), radius(0), reinserted(false), updateCount(0), toDelete(false) {}
-	Node(const Coord& centre, double radius, void *data)
-		: level(0), leafCount(1), centre(centre), radius(radius), reinserted(false), updateCount(0), data(data), toDelete(false) {}
+  Node() : level(0), leafCount(1), centre(ORIGIN), radius(0), reinserted(false), updateCount(0), toDelete(false) {}
+  Node(const Coord& centre, double radius, void *data)
+    : level(0), leafCount(1), centre(centre), radius(radius), reinserted(false), updateCount(0), data(data), toDelete(false) {}
 
 //#ifdef DEBUG
@@ -178,26 +178,26 @@
 //#endif
 
-	void move(const NodePtr node);
-	void remove(const NodePtr node);
-	void inflate(const NodePtr node);
-	void update();
+  void move(const NodePtr node);
+  void remove(const NodePtr node);
+  void inflate(const NodePtr node);
+  void update();
   void output(std::ostream& flux, int level, int color) ;
-	NodePtr closest(std::vector<NodePtr>& list, int n = CLOSEST);
-	NodePtr farthest(std::vector<NodePtr>& list);
-	void findClosest(int level, NodePtr src, double& minDist, NodePtr &closest);
-
-	void search(NodePtr node);
-	bool centreInside(Node &node);
-	bool intersects(NodePtr node);
-	bool isInside(Node &node);
-	int incluCheck();
+  NodePtr closest(std::vector<NodePtr>& list, int n = CLOSEST);
+  NodePtr farthest(std::vector<NodePtr>& list);
+  void findClosest(int level, NodePtr src, double& minDist, NodePtr &closest);
+
+  void search(NodePtr node);
+  bool centreInside(Node &node);
+  bool intersects(NodePtr node);
+  bool isInside(Node &node);
+  int incluCheck();
   void checkParent(void) ;
-	void printChildren();
-	void assignRoute(std::vector<int>::iterator& rank, int level);
-	void assignCircleAndPropagateUp(Coord *centres, double *radia, int level);
-	void printLevel(int level);
-	void routeNode(NodePtr node, int level);
-	void routingIntersecting(std::vector<Node>* routingList, NodePtr node);
-	void routeIntersection(std::vector<int>& routes, NodePtr node);
+  void printChildren();
+  void assignRoute(std::vector<int>::iterator& rank, int level);
+  void assignCircleAndPropagateUp(Coord *centres, double *radia, int level);
+  void printLevel(int level);
+  void routeNode(NodePtr node, int level);
+  void routingIntersecting(std::vector<Node>* routingList, NodePtr node);
+  void routeIntersection(std::vector<int>& routes, NodePtr node);
   void getNodeLevel(int level,std::list<NodePtr>& NodeList) ;
   bool removeDeletedNodes(int assignLevel) ;
Index: /XIOS/dev/branch_yushan_merged/extern/src_ep_dev/ep_wait.cpp
===================================================================
--- /XIOS/dev/branch_yushan_merged/extern/src_ep_dev/ep_wait.cpp	(revision 1152)
+++ /XIOS/dev/branch_yushan_merged/extern/src_ep_dev/ep_wait.cpp	(revision 1153)
@@ -58,7 +58,18 @@
     if(request->type == 3)
     {
-      ::MPI_Request mpi_request = static_cast< ::MPI_Request >(request->mpi_request);
+      ::MPI_Request *mpi_request = static_cast< ::MPI_Request* >(&(request->mpi_request));
       ::MPI_Status mpi_status;
-      ::MPI_Wait(&mpi_request, &mpi_status);
+      ::MPI_Errhandler_set(MPI_COMM_WORLD_STD, MPI_ERRORS_RETURN);
+      int error_code = ::MPI_Wait(mpi_request, &mpi_status);
+      if (error_code != MPI_SUCCESS) {
+      
+         char error_string[BUFSIZ];
+         int length_of_error_string, error_class;
+      
+         ::MPI_Error_class(error_code, &error_class);
+         ::MPI_Error_string(error_class, error_string, &length_of_error_string);
+         printf("%s\n", error_string);
+      }
+      
 
       status->mpi_status = new ::MPI_Status(mpi_status);
@@ -81,6 +92,7 @@
   int MPI_Waitall(int count, MPI_Request *array_of_requests, MPI_Status *array_of_statuses)
   {
-    int dest_rank;
-    MPI_Comm_rank(MPI_COMM_WORLD, &dest_rank);
+    //int dest_rank;
+    //MPI_Comm_rank(MPI_COMM_WORLD, &dest_rank);
+    //printf("proc %d enters waitall\n", dest_rank);
 
     int finished = 0;
@@ -100,7 +112,7 @@
           if(array_of_requests[i].type != 2) // isend or imrecv
           {      
-            //MPI_Wait(&array_of_requests[i], &array_of_statuses[i]);
-            int tested=false;
-            while(!tested) MPI_Test(&array_of_requests[i], &tested, &array_of_statuses[i]);
+            MPI_Wait(&array_of_requests[i], &array_of_statuses[i]);
+            //int tested=false;
+            //while(!tested) MPI_Test(&array_of_requests[i], &tested, &array_of_statuses[i]);
             finished++;
             finished_index[i] = true;
@@ -127,4 +139,5 @@
       }    
     }
+    //printf("proc %d exits waitall\n", dest_rank);
     return MPI_SUCCESS;
   }  /* end of mpi_waitall*/
Index: /XIOS/dev/branch_yushan_merged/src/io/netCdfInterface.cpp
===================================================================
--- /XIOS/dev/branch_yushan_merged/src/io/netCdfInterface.cpp	(revision 1152)
+++ /XIOS/dev/branch_yushan_merged/src/io/netCdfInterface.cpp	(revision 1153)
@@ -75,5 +75,8 @@
 int CNetCdfInterface::open(const StdString& fileName, int oMode, int& ncId)
 {
-  int status = nc_open(fileName.c_str(), oMode, &ncId);
+  int status = NC_NOERR;
+  #pragma omp critical (_netcdf)
+  status = nc_open(fileName.c_str(), oMode, &ncId);
+  
   if (NC_NOERR != status)
   {
@@ -105,5 +108,5 @@
   int status;
   #pragma omp critical (_netcdf)
-  status = xios::nc_open_par(fileName.c_str(), oMode, comm, info, &ncId);
+  status = xios::nc_open_par(fileName.c_str(), oMode, comm, info, &ncId); // nc_open
   if (NC_NOERR != status)
   {
@@ -129,6 +132,6 @@
 {
   int status = NC_NOERR;
-  //#pragma omp critical (_netcdf)
-  #pragma omp master
+  #pragma omp critical (_netcdf)
+  //#pragma omp master
   {
   status = nc_close(ncId);
Index: /XIOS/dev/branch_yushan_merged/src/node/field.cpp
===================================================================
--- /XIOS/dev/branch_yushan_merged/src/node/field.cpp	(revision 1152)
+++ /XIOS/dev/branch_yushan_merged/src/node/field.cpp	(revision 1153)
@@ -713,9 +713,9 @@
      if (context->hasClient)
      {
-       MPI_Barrier(context->client->intraComm);
-       printf("Proc %d enters function\n", myRank);
+       //MPI_Barrier(context->client->intraComm);
+       //printf("Proc %d enters function\n", myRank);
        solveTransformedGrid();
-       MPI_Barrier(context->client->intraComm);
-       printf("Proc %d exits function\n", myRank);
+       //MPI_Barrier(context->client->intraComm);
+       //printf("Proc %d exits function\n", myRank);
      }
 
Index: /XIOS/dev/branch_yushan_merged/src/node/file.cpp
===================================================================
--- /XIOS/dev/branch_yushan_merged/src/node/file.cpp	(revision 1152)
+++ /XIOS/dev/branch_yushan_merged/src/node/file.cpp	(revision 1153)
@@ -578,4 +578,8 @@
       bool isCollective = par_access.isEmpty() || par_access == par_access_attr::collective;
 
+      #ifdef _usingEP
+      if(omp_get_num_threads() != 1 ) multifile = true;
+      #endif
+
       if (isOpen) data_out->closeFile();
       if (time_counter_name.isEmpty()) data_in = shared_ptr<CDataInput>(new CNc4DataInput(oss.str(), static_cast< ::MPI_Comm >(fileComm.mpi_comm), multifile, isCollective));
@@ -609,9 +613,11 @@
 
      // It would probably be better to call initFile() somehow
+     
      MPI_Comm_dup(client->intraComm, &fileComm);
      if (time_counter_name.isEmpty()) time_counter_name = "time_counter";
 
-     //#pragma omp critical (_checkFile)
-     checkFile();
+     //#pragma omp critical (_readAttributesOfEnabledFieldsInReadMode_)
+     //{
+     checkFile(); // calls nc_open
 
      for (int idx = 0; idx < enabledFields.size(); ++idx)
@@ -627,6 +633,11 @@
 
         // Read necessary value from file
-        this->data_in->readFieldAttributesValues(enabledFields[idx]);
-
+        #pragma omp critical (_func)
+        {
+          //checkFile();
+          this->data_in->readFieldAttributesValues(enabledFields[idx]);
+          //close();
+        }
+        
         // Fill attributes for base reference
         enabledFields[idx]->solveGridDomainAxisBaseRef();
@@ -634,5 +645,9 @@
 
      // Now everything is ok, close it
-     //close();
+     close();
+     //}
+     
+     //if (fileComm != MPI_COMM_NULL) MPI_Comm_free(&fileComm);
+     
    }
 
Index: /XIOS/dev/branch_yushan_merged/src/test/test_remap_omp.f90
===================================================================
--- /XIOS/dev/branch_yushan_merged/src/test/test_remap_omp.f90	(revision 1152)
+++ /XIOS/dev/branch_yushan_merged/src/test/test_remap_omp.f90	(revision 1153)
@@ -52,5 +52,5 @@
   if(rank < size-2) then
 
-  !$omp parallel default(firstprivate) 
+  !$omp parallel default(firstprivate) firstprivate(dtime)
 
 !!! XIOS Initialization (get the local communicator)
@@ -59,4 +59,7 @@
   CALL MPI_COMM_RANK(comm,rank,ierr)
   CALL MPI_COMM_SIZE(comm,size,ierr)
+  
+  rank = rank*omp_get_num_threads() + omp_get_thread_num()
+  size = size*omp_get_num_threads()
 
   
@@ -202,6 +205,46 @@
 
   CALL xios_close_context_definition()
+
+  CALL xios_get_domain_attr("src_domain_regular_read", ni=src_tmp_ni, nj=src_tmp_nj)
+  ALLOCATE(tmp_field_0(src_tmp_ni*src_tmp_nj))
+
+  CALL xios_get_axis_attr("src_axis_curvilinear_read", n=src_tmp_n)
+  CALL xios_get_domain_attr("src_domain_curvilinear_read", ni=src_tmp_ni, nj=src_tmp_nj)
+  ALLOCATE(tmp_field_1(src_tmp_ni*src_tmp_nj*src_tmp_n))
+
+  CALL xios_get_domain_attr("src_domain_unstructured_read", ni=src_tmp_ni, nj=src_tmp_nj)
+  ALLOCATE(tmp_field_2(src_tmp_ni*src_tmp_nj))
+  
+  CALL xios_recv_field("src_field_regular", tmp_field_0)
+  CALL xios_recv_field("src_field_curvilinear", tmp_field_1)
+  CALL xios_recv_field("src_field_unstructured", tmp_field_2)
+
+  DO ts=1,10
+    CALL xios_update_calendar(ts)
+    CALL xios_send_field("src_field_2D",src_field_2D)
+    
+    DO i=1,src_ni
+      src_field_2D_clone(i) = src_field_2D(i)
+      IF ((23.5 * ts < src_lat(i)) .AND. (src_lat(i) < 65.5 *ts) .AND. (0 < src_lon(i)) .AND. (src_lon(i) < 30*ts)) THEN      
+        src_field_2D_clone(i) = missing_value    
+      ENDIF
+    ENDDO
+
+    CALL xios_send_field("src_field_2D_clone",src_field_2D_clone)
+    CALL xios_send_field("src_field_3D",src_field_3D)
+    CALL xios_send_field("src_field_3D_clone",src_field_3D)
+    CALL xios_send_field("src_field_4D",src_field_4D)
+    CALL xios_send_field("src_field_3D_pression",src_field_pression)
+    CALL xios_send_field("tmp_field_0",tmp_field_0)
+    CALL xios_send_field("tmp_field_1",tmp_field_1)
+    CALL xios_send_field("tmp_field_2",tmp_field_2)
+    CALL wait_us(5000) ;
+   ENDDO
   
   CALL xios_context_finalize()
+
+  DEALLOCATE(src_lon, src_lat, src_boundslon,src_boundslat, src_field_2D)
+  DEALLOCATE(dst_lon, dst_lat, dst_boundslon,dst_boundslat)
+  DEALLOCATE(tmp_field_0, tmp_field_1, tmp_field_2)
   
   CALL xios_finalize()
Index: /XIOS/dev/branch_yushan_merged/src/transformation/Functions/reduction.cpp
===================================================================
--- /XIOS/dev/branch_yushan_merged/src/transformation/Functions/reduction.cpp	(revision 1152)
+++ /XIOS/dev/branch_yushan_merged/src/transformation/Functions/reduction.cpp	(revision 1153)
@@ -50,4 +50,6 @@
   (*CReductionAlgorithm::ReductionOperations_ptr)["average"] = TRANS_REDUCE_AVERAGE;
   CAverageReductionAlgorithm::registerTrans();
+
+  printf("*CReductionAlgorithm::ReductionOperations_ptr = %p\t %p\n", *CReductionAlgorithm::ReductionOperations_ptr, &(*CReductionAlgorithm::ReductionOperations_ptr));
 }
 
Index: /XIOS/dev/branch_yushan_merged/src/transformation/scalar_algorithm_reduce_axis.cpp
===================================================================
--- /XIOS/dev/branch_yushan_merged/src/transformation/scalar_algorithm_reduce_axis.cpp	(revision 1152)
+++ /XIOS/dev/branch_yushan_merged/src/transformation/scalar_algorithm_reduce_axis.cpp	(revision 1153)
@@ -75,9 +75,10 @@
   }
   
-  if ((*CReductionAlgorithm::ReductionOperations_ptr).end() == (*CReductionAlgorithm::ReductionOperations_ptr).find(op))
-    ERROR("CScalarAlgorithmReduceAxis::CScalarAlgorithmReduceAxis(CAxis* axisDestination, CAxis* axisSource, CReduceAxisToScalar* algo)",
-       << "Operation '" << op << "' not found. Please make sure to use a supported one"
-       << "Axis source " <<axisSource->getId() << std::endl
-       << "Scalar destination " << scalarDestination->getId());
+  //if ((*CReductionAlgorithm::ReductionOperations_ptr).end() == (*CReductionAlgorithm::ReductionOperations_ptr).find(op))
+  //  if ((CReductionAlgorithm::ReductionOperations_ptr)->end() == (CReductionAlgorithm::ReductionOperations_ptr)->find(op))
+  //  ERROR("CScalarAlgorithmReduceAxis::CScalarAlgorithmReduceAxis(CAxis* axisDestination, CAxis* axisSource, CReduceAxisToScalar* algo)",
+  //     << "Operation '" << op << "' not found. Please make sure to use a supported one"
+  //     << "Axis source " <<axisSource->getId() << std::endl
+  //     << "Scalar destination " << scalarDestination->getId());
 
   reduction_ = CReductionAlgorithm::createOperation((*CReductionAlgorithm::ReductionOperations_ptr)[op]);
