Index: XIOS/dev/branch_openmp/bld.cfg
===================================================================
--- XIOS/dev/branch_openmp/bld.cfg	(revision 1467)
+++ XIOS/dev/branch_openmp/bld.cfg	(revision 1468)
@@ -33,13 +33,13 @@
 bld::target libxios.a 
 #bld::target generate_fortran_interface.exe 
-bld::target xios_server.exe 
+#bld::target xios_server.exe 
 #bld::target test_regular.exe
 #bld::target test_expand_domain.exe
 #bld::target test_new_features.exe 
-bld::target test_unstruct_complete.exe 
-#bld::target test_omp.exe 
+#bld::target test_unstruct_complete.exe 
+bld::target test_omp.exe 
 bld::target test_complete_omp.exe 
-bld::target test_remap.exe 
-bld::target test_remap_ref.exe 
+#bld::target test_remap.exe 
+#bld::target test_remap_ref.exe 
 bld::target test_remap_omp.exe 
 #bld::target test_unstruct_omp.exe
@@ -50,5 +50,5 @@
 #bld::target test_xios2_cmip6.exe
 #bld::target test_connectivity_expand.exe
-bld::target toy_cmip6.exe
+#bld::target toy_cmip6.exe
 bld::target toy_cmip6_omp.exe
 bld::exe_dep
Index: XIOS/dev/branch_openmp/extern/remap/src/mapper.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/remap/src/mapper.cpp	(revision 1467)
+++ XIOS/dev/branch_openmp/extern/remap/src/mapper.cpp	(revision 1468)
@@ -29,7 +29,7 @@
 void cptOffsetsFromLengths(const int *lengths, int *offsets, int sz)
 {
-	offsets[0] = 0;
-	for (int i = 1; i < sz; i++)
-		offsets[i] = offsets[i-1] + lengths[i-1];
+  offsets[0] = 0;
+  for (int i = 1; i < sz; i++)
+    offsets[i] = offsets[i-1] + lengths[i-1];
 }
 
@@ -39,10 +39,10 @@
   srcGrid.pole = Coord(pole[0], pole[1], pole[2]);
 
-	int mpiRank, mpiSize;
-	MPI_Comm_rank(communicator, &mpiRank);
-	MPI_Comm_size(communicator, &mpiSize);
-
-	sourceElements.reserve(nbCells);
-	sourceMesh.reserve(nbCells);
+  int mpiRank, mpiSize;
+  MPI_Comm_rank(communicator, &mpiRank);
+  MPI_Comm_size(communicator, &mpiSize);
+
+  sourceElements.reserve(nbCells);
+  sourceMesh.reserve(nbCells);
   sourceGlobalId.resize(nbCells) ;
 
@@ -57,15 +57,15 @@
   else sourceGlobalId.assign(globalId,globalId+nbCells);
 
-	for (int i = 0; i < nbCells; i++)
-	{
-		int offs = i*nVertex;
-		Elt elt(boundsLon + offs, boundsLat + offs, nVertex);
-		elt.src_id.rank = mpiRank;
-		elt.src_id.ind = i;
+  for (int i = 0; i < nbCells; i++)
+  {
+    int offs = i*nVertex;
+    Elt elt(boundsLon + offs, boundsLat + offs, nVertex);
+    elt.src_id.rank = mpiRank;
+    elt.src_id.ind = i;
     elt.src_id.globalId = sourceGlobalId[i];
-		sourceElements.push_back(elt);
-		sourceMesh.push_back(Node(elt.x, cptRadius(elt), &sourceElements.back()));
-		cptEltGeom(sourceElements[i], Coord(pole[0], pole[1], pole[2]));
-	}
+    sourceElements.push_back(elt);
+    sourceMesh.push_back(Node(elt.x, cptRadius(elt), &sourceElements.back()));
+    cptEltGeom(sourceElements[i], Coord(pole[0], pole[1], pole[2]));
+  }
 
 }
@@ -75,10 +75,10 @@
   tgtGrid.pole = Coord(pole[0], pole[1], pole[2]);
 
-	int mpiRank, mpiSize;
-	MPI_Comm_rank(communicator, &mpiRank);
-	MPI_Comm_size(communicator, &mpiSize);
-
-	targetElements.reserve(nbCells);
-	targetMesh.reserve(nbCells);
+  int mpiRank, mpiSize;
+  MPI_Comm_rank(communicator, &mpiRank);
+  MPI_Comm_size(communicator, &mpiSize);
+
+  targetElements.reserve(nbCells);
+  targetMesh.reserve(nbCells);
 
   targetGlobalId.resize(nbCells) ;
@@ -93,12 +93,12 @@
   else targetGlobalId.assign(globalId,globalId+nbCells);
 
-	for (int i = 0; i < nbCells; i++)
-	{
-		int offs = i*nVertex;
-		Elt elt(boundsLon + offs, boundsLat + offs, nVertex);
-		targetElements.push_back(elt);
-		targetMesh.push_back(Node(elt.x, cptRadius(elt), &sourceElements.back()));
-		cptEltGeom(targetElements[i], Coord(pole[0], pole[1], pole[2]));
-	}
+  for (int i = 0; i < nbCells; i++)
+  {
+    int offs = i*nVertex;
+    Elt elt(boundsLon + offs, boundsLat + offs, nVertex);
+    targetElements.push_back(elt);
+    targetMesh.push_back(Node(elt.x, cptRadius(elt), &sourceElements.back()));
+    cptEltGeom(targetElements[i], Coord(pole[0], pole[1], pole[2]));
+  }
 
 
@@ -119,51 +119,52 @@
 vector<double> Mapper::computeWeights(int interpOrder, bool renormalize, bool quantity)
 {
-	vector<double> timings;
-	int mpiSize, mpiRank;
-	MPI_Comm_size(communicator, &mpiSize);
-	MPI_Comm_rank(communicator, &mpiRank);
+  vector<double> timings;
+  int mpiSize, mpiRank;
+  MPI_Comm_size(communicator, &mpiSize);
+  MPI_Comm_rank(communicator, &mpiRank);
 
   this->buildSSTree(sourceMesh, targetMesh);
 
-	if (mpiRank == 0 && verbose) cout << "Computing intersections ..." << endl;
-	double tic = cputime();
-	computeIntersection(&targetElements[0], targetElements.size());
-	timings.push_back(cputime() - tic);
-
-	tic = cputime();
-	if (interpOrder == 2) {
-		if (mpiRank == 0 && verbose) cout << "Computing grads ..." << endl;
-		buildMeshTopology();
-		computeGrads();
-	}
-	timings.push_back(cputime() - tic);
-
-	/* Prepare computation of weights */
-	/* compute number of intersections which for the first order case
-           corresponds to the number of edges in the remap matrix */
-	int nIntersections = 0;
-	for (int j = 0; j < targetElements.size(); j++)
-	{
-		Elt &elt = targetElements[j];
-		for (list<Polyg*>::iterator it = elt.is.begin(); it != elt.is.end(); it++)
-			nIntersections++;
-	}
-	/* overallocate for NMAX neighbours for each elements */
-	remapMatrix = new double[nIntersections*NMAX];
-	srcAddress = new int[nIntersections*NMAX];
-	srcRank = new int[nIntersections*NMAX];
-	dstAddress = new int[nIntersections*NMAX];
+  if (mpiRank == 0 && verbose) cout << "Computing intersections ..." << endl;
+  double tic = cputime();
+  computeIntersection(&targetElements[0], targetElements.size());
+  timings.push_back(cputime() - tic);
+
+  tic = cputime();
+  if (interpOrder == 2) 
+  {
+    if (mpiRank == 0 && verbose) cout << "Computing grads ..." << endl;
+    buildMeshTopology();
+    computeGrads();
+  }
+  timings.push_back(cputime() - tic);
+
+  /* Prepare computation of weights */
+  /* compute number of intersections which for the first order case
+     corresponds to the number of edges in the remap matrix */
+  int nIntersections = 0;
+  for (int j = 0; j < targetElements.size(); j++)
+  {
+    Elt &elt = targetElements[j];
+    for (list<Polyg*>::iterator it = elt.is.begin(); it != elt.is.end(); it++)
+      nIntersections++;
+  }
+  /* overallocate for NMAX neighbours for each elements */
+  remapMatrix = new double[nIntersections*NMAX];
+  srcAddress = new int[nIntersections*NMAX];
+  srcRank = new int[nIntersections*NMAX];
+  dstAddress = new int[nIntersections*NMAX];
   sourceWeightId =new long[nIntersections*NMAX];
   targetWeightId =new long[nIntersections*NMAX];
 
 
-	if (mpiRank == 0 && verbose) cout << "Remapping..." << endl;
-	tic = cputime();
-	nWeights = remap(&targetElements[0], targetElements.size(), interpOrder, renormalize, quantity);
-	timings.push_back(cputime() - tic);
+  if (mpiRank == 0 && verbose) cout << "Remapping..." << endl;
+  tic = cputime();
+  nWeights = remap(&targetElements[0], targetElements.size(), interpOrder, renormalize, quantity);
+  timings.push_back(cputime() - tic);
 
   for (int i = 0; i < targetElements.size(); i++) targetElements[i].delete_intersections();
 
-	return timings;
+  return timings;
 }
 
@@ -176,130 +177,132 @@
 int Mapper::remap(Elt *elements, int nbElements, int order, bool renormalize, bool quantity)
 {
-	int mpiSize, mpiRank;
-	MPI_Comm_size(communicator, &mpiSize);
-	MPI_Comm_rank(communicator, &mpiRank);
-
-	/* create list of intersections (super mesh elements) for each rank */
-	multimap<int, Polyg *> *elementList = new multimap<int, Polyg *>[mpiSize];
-	for (int j = 0; j < nbElements; j++)
-	{
-		Elt& e = elements[j];
-		for (list<Polyg *>::iterator it = e.is.begin(); it != e.is.end(); it++)
-			elementList[(*it)->id.rank].insert(pair<int, Polyg *>((*it)->id.ind, *it));
-	}
-
-	int *nbSendElement = new int[mpiSize];
-	int **sendElement = new int*[mpiSize]; /* indices of elements required from other rank */
-	double **recvValue = new double*[mpiSize];
-	double **recvArea = new double*[mpiSize];
-	Coord **recvGrad = new Coord*[mpiSize];
-	GloId **recvNeighIds = new GloId*[mpiSize]; /* ids of the of the source neighbours which also contribute through gradient */
-	for (int rank = 0; rank < mpiSize; rank++)
-	{
-		/* get size for allocation */
-		int last = -1; /* compares unequal to any index */
-		int index = -1; /* increased to starting index 0 in first iteration */
-		for (multimap<int, Polyg *>::iterator it = elementList[rank].begin(); it != elementList[rank].end(); ++it)
-		{
-			if (last != it->first)
-				index++;
-			(it->second)->id.ind = index;
-			last = it->first;
-		}
-		nbSendElement[rank] = index + 1;
-
-		/* if size is non-zero allocate and collect indices of elements on other ranks that we intersect */
-		if (nbSendElement[rank] > 0)
-		{
-			sendElement[rank] = new int[nbSendElement[rank]];
-			recvValue[rank]   = new double[nbSendElement[rank]];
-			recvArea[rank]    = new double[nbSendElement[rank]];
-			if (order == 2)
-			{
-				recvNeighIds[rank] = new GloId[nbSendElement[rank]*(NMAX+1)];
-				recvGrad[rank]    = new Coord[nbSendElement[rank]*(NMAX+1)];
-			}
-			else
-				recvNeighIds[rank] = new GloId[nbSendElement[rank]];
-
-			last = -1;
-			index = -1;
-			for (multimap<int, Polyg *>::iterator it = elementList[rank].begin(); it != elementList[rank].end(); ++it)
-			{
-				if (last != it->first)
-					index++;
-				sendElement[rank][index] = it->first;
-				last = it->first;
-			}
-		}
-	}
-
-	/* communicate sizes of source elements to be sent (index lists and later values and gradients) */
-	int *nbRecvElement = new int[mpiSize];
-	MPI_Alltoall(nbSendElement, 1, MPI_INT, nbRecvElement, 1, MPI_INT, communicator);
-
-	/* communicate indices of source elements on other ranks whoes value and gradient we need (since intersection) */
-	int nbSendRequest = 0;
-	int nbRecvRequest = 0;
-	int **recvElement = new int*[mpiSize];
-	double **sendValue = new double*[mpiSize];
-	double **sendArea = new double*[mpiSize];
-	Coord **sendGrad = new Coord*[mpiSize];
-	GloId **sendNeighIds = new GloId*[mpiSize];
-	MPI_Request *sendRequest = new MPI_Request[4*mpiSize];
-	MPI_Request *recvRequest = new MPI_Request[4*mpiSize];
-	for (int rank = 0; rank < mpiSize; rank++)
-	{
-		if (nbSendElement[rank] > 0)
-		{
-			MPI_Issend(sendElement[rank], nbSendElement[rank], MPI_INT, rank, 0, communicator, &sendRequest[nbSendRequest]);
-			nbSendRequest++;
-		}
-
-		if (nbRecvElement[rank] > 0)
-		{
-			recvElement[rank] = new int[nbRecvElement[rank]];
-			sendValue[rank]   = new double[nbRecvElement[rank]];
-			sendArea[rank]   = new double[nbRecvElement[rank]];
-			if (order == 2)
-			{
-				sendNeighIds[rank] = new GloId[nbRecvElement[rank]*(NMAX+1)];
-				sendGrad[rank]    = new Coord[nbRecvElement[rank]*(NMAX+1)];
-			}
-			else
-			{
-				sendNeighIds[rank] = new GloId[nbRecvElement[rank]];
-			}
-			MPI_Irecv(recvElement[rank], nbRecvElement[rank], MPI_INT, rank, 0, communicator, &recvRequest[nbRecvRequest]);
-			nbRecvRequest++;
-		}
-	}
-	MPI_Status *status = new MPI_Status[4*mpiSize];
-	
-	MPI_Waitall(nbSendRequest, sendRequest, status);
-        MPI_Waitall(nbRecvRequest, recvRequest, status);
-
-	/* for all indices that have been received from requesting ranks: pack values and gradients, then send */
-	nbSendRequest = 0;
-	nbRecvRequest = 0;
-	for (int rank = 0; rank < mpiSize; rank++)
-	{
-		if (nbRecvElement[rank] > 0)
-		{
-			int jj = 0; // jj == j if no weight writing
-			for (int j = 0; j < nbRecvElement[rank]; j++)
-			{
-				sendValue[rank][j] = sstree.localElements[recvElement[rank][j]].val;
-				sendArea[rank][j] = sstree.localElements[recvElement[rank][j]].area;
-				if (order == 2)
-				{
-					sendGrad[rank][jj] = sstree.localElements[recvElement[rank][j]].grad;
-//          cout<<"grad  "<<jj<<"  "<<recvElement[rank][j]<<"  "<<sendGrad[rank][jj]<<" "<<sstree.localElements[recvElement[rank][j]].grad<<endl ;
-					sendNeighIds[rank][jj] = sstree.localElements[recvElement[rank][j]].src_id;
-					jj++;
-					for (int i = 0; i < NMAX; i++)
-					{
-						sendGrad[rank][jj] = sstree.localElements[recvElement[rank][j]].gradNeigh[i];
-//            cout<<"grad  "<<jj<<"  "<<sendGrad[rank][jj]<<" "<<sstree.localElements[recvElement[rank][j]].grad<<endl ;
+  int mpiSize, mpiRank;
+  MPI_Comm_size(communicator, &mpiSize);
+  MPI_Comm_rank(communicator, &mpiRank);
+
+  /* create list of intersections (super mesh elements) for each rank */
+  multimap<int, Polyg *> *elementList = new multimap<int, Polyg *>[mpiSize];
+  for (int j = 0; j < nbElements; j++)
+  {
+    Elt& e = elements[j];
+    for (list<Polyg *>::iterator it = e.is.begin(); it != e.is.end(); it++)
+    {
+      elementList[(*it)->id.rank].insert(pair<int, Polyg *>((*it)->id.ind, *it));
+    }
+  }
+
+  int *nbSendElement = new int[mpiSize];
+  int **sendElement = new int*[mpiSize]; /* indices of elements required from other rank */
+  double **recvValue = new double*[mpiSize];
+  double **recvArea = new double*[mpiSize];
+  Coord **recvGrad = new Coord*[mpiSize];
+  GloId **recvNeighIds = new GloId*[mpiSize]; /* ids of the of the source neighbours which also contribute through gradient */
+  for (int rank = 0; rank < mpiSize; rank++)
+  {
+    /* get size for allocation */
+    int last = -1; /* compares unequal to any index */
+    int index = -1; /* increased to starting index 0 in first iteration */
+    for (multimap<int, Polyg *>::iterator it = elementList[rank].begin(); it != elementList[rank].end(); ++it)
+    {
+      if (last != it->first)
+        index++;
+      (it->second)->id.ind = index;
+      last = it->first;
+    }
+    nbSendElement[rank] = index + 1;
+
+    /* if size is non-zero allocate and collect indices of elements on other ranks that we intersect */
+    if (nbSendElement[rank] > 0)
+    {
+      sendElement[rank] = new int[nbSendElement[rank]];
+      recvValue[rank]   = new double[nbSendElement[rank]];
+      recvArea[rank]    = new double[nbSendElement[rank]];
+      if (order == 2)
+      {
+        recvNeighIds[rank] = new GloId[nbSendElement[rank]*(NMAX+1)];
+        recvGrad[rank]    = new Coord[nbSendElement[rank]*(NMAX+1)];
+      }
+      else
+        recvNeighIds[rank] = new GloId[nbSendElement[rank]];
+
+      last = -1;
+      index = -1;
+      for (multimap<int, Polyg *>::iterator it = elementList[rank].begin(); it != elementList[rank].end(); ++it)
+      {
+        if (last != it->first)
+          index++;
+        sendElement[rank][index] = it->first;
+        last = it->first;
+      }
+    }
+  }
+
+  /* communicate sizes of source elements to be sent (index lists and later values and gradients) */
+  int *nbRecvElement = new int[mpiSize];
+  MPI_Alltoall(nbSendElement, 1, MPI_INT, nbRecvElement, 1, MPI_INT, communicator);
+  
+
+  /* communicate indices of source elements on other ranks whoes value and gradient we need (since intersection) */
+  int nbSendRequest = 0;
+  int nbRecvRequest = 0;
+  int **recvElement = new int*[mpiSize];
+  double **sendValue = new double*[mpiSize];
+  double **sendArea = new double*[mpiSize];
+  Coord **sendGrad = new Coord*[mpiSize];
+  GloId **sendNeighIds = new GloId*[mpiSize];
+  MPI_Request *sendRequest = new MPI_Request[4*mpiSize];
+  MPI_Request *recvRequest = new MPI_Request[4*mpiSize];
+  for (int rank = 0; rank < mpiSize; rank++)
+  {
+    if (nbSendElement[rank] > 0)
+    {
+      MPI_Issend(sendElement[rank], nbSendElement[rank], MPI_INT, rank, 0, communicator, &sendRequest[nbSendRequest]);
+      nbSendRequest++;
+    }
+
+    if (nbRecvElement[rank] > 0)
+    {
+      recvElement[rank] = new int[nbRecvElement[rank]];
+      sendValue[rank]   = new double[nbRecvElement[rank]];
+      sendArea[rank]   = new double[nbRecvElement[rank]];
+      if (order == 2)
+      {
+        sendNeighIds[rank] = new GloId[nbRecvElement[rank]*(NMAX+1)];
+        sendGrad[rank]    = new Coord[nbRecvElement[rank]*(NMAX+1)];
+      }
+      else
+      {
+        sendNeighIds[rank] = new GloId[nbRecvElement[rank]];
+      }
+      MPI_Irecv(recvElement[rank], nbRecvElement[rank], MPI_INT, rank, 0, communicator, &recvRequest[nbRecvRequest]);
+      nbRecvRequest++;
+    }
+  }
+
+  MPI_Status *status = new MPI_Status[4*mpiSize];
+
+  MPI_Waitall(nbSendRequest, sendRequest, status);
+  MPI_Waitall(nbRecvRequest, recvRequest, status);
+
+  /* for all indices that have been received from requesting ranks: pack values and gradients, then send */
+  nbSendRequest = 0;
+  nbRecvRequest = 0;
+  for (int rank = 0; rank < mpiSize; rank++)
+  {
+    if (nbRecvElement[rank] > 0)
+    {
+      int jj = 0; // jj == j if no weight writing
+      for (int j = 0; j < nbRecvElement[rank]; j++)
+      {
+        sendValue[rank][j] = sstree.localElements[recvElement[rank][j]].val;
+        sendArea[rank][j] = sstree.localElements[recvElement[rank][j]].area;
+        if (order == 2)
+        {
+          sendGrad[rank][jj] = sstree.localElements[recvElement[rank][j]].grad;
+          sendNeighIds[rank][jj] = sstree.localElements[recvElement[rank][j]].src_id;
+          jj++;
+          for (int i = 0; i < NMAX; i++)
+          {
+            sendGrad[rank][jj] = sstree.localElements[recvElement[rank][j]].gradNeigh[i];
             sendNeighIds[rank][jj] = sstree.localElements[recvElement[rank][j]].neighId[i];
 						jj++;
@@ -348,53 +351,53 @@
 				MPI_Irecv(recvNeighIds[rank], 4*nbSendElement[rank], MPI_INT, rank, 4, communicator, &recvRequest[nbRecvRequest]);
 //ym  --> attention taille GloId
-				nbRecvRequest++;
-			}
-		}
-	}
+        nbRecvRequest++;
+      }
+    }
+  }
         
-        MPI_Waitall(nbSendRequest, sendRequest, status);
-	MPI_Waitall(nbRecvRequest, recvRequest, status);
+  MPI_Waitall(nbSendRequest, sendRequest, status);
+  MPI_Waitall(nbRecvRequest, recvRequest, status);
 	
 
-	/* now that all values and gradients are available use them to computed interpolated values on target
-	   and also to compute weights */
-	int i = 0;
-	for (int j = 0; j < nbElements; j++)
-	{
-		Elt& e = elements[j];
-
-		/* since for the 2nd order case source grid elements can contribute to a destination grid element over several "paths"
-		   (step1: gradient is computed using neighbours on same grid, step2: intersection uses several elements on other grid)
-		   accumulate them so that there is only one final weight between two elements */
-		map<GloId,double> wgt_map;
-
-		/* for destination element `e` loop over all intersetions/the corresponding source elements */
-		for (list<Polyg *>::iterator it = e.is.begin(); it != e.is.end(); it++)
-		{
-			/* it is the intersection element, so it->x and it->area are barycentre and area of intersection element (super mesh)
-			but it->id is id of the source element that it intersects */
-			int n1 = (*it)->id.ind;
-			int rank = (*it)->id.rank;
-			double fk = recvValue[rank][n1];
-			double srcArea = recvArea[rank][n1];
-			double w = (*it)->area;
+  /* now that all values and gradients are available use them to computed interpolated values on target
+    and also to compute weights */
+  int i = 0;
+  for (int j = 0; j < nbElements; j++)
+  {
+    Elt& e = elements[j];
+
+    /* since for the 2nd order case source grid elements can contribute to a destination grid element over several "paths"
+    (step1: gradient is computed using neighbours on same grid, step2: intersection uses several elements on other grid)
+    accumulate them so that there is only one final weight between two elements */
+    map<GloId,double> wgt_map;
+
+    /* for destination element `e` loop over all intersetions/the corresponding source elements */
+    for (list<Polyg *>::iterator it = e.is.begin(); it != e.is.end(); it++)
+    {
+      /* it is the intersection element, so it->x and it->area are barycentre and area of intersection element (super mesh)
+      but it->id is id of the source element that it intersects */
+      int n1 = (*it)->id.ind;
+      int rank = (*it)->id.rank;
+      double fk = recvValue[rank][n1];
+      double srcArea = recvArea[rank][n1];
+      double w = (*it)->area;
       if (quantity) w/=srcArea ;
 
-			/* first order: src value times weight (weight = supermesh area), later divide by target area */
-			int kk = (order == 2) ? n1 * (NMAX + 1) : n1;
-			GloId neighID = recvNeighIds[rank][kk];
-			wgt_map[neighID] += w;
-
-			if (order == 2)
-			{
-				for (int k = 0; k < NMAX+1; k++)
-				{
-					int kk = n1 * (NMAX + 1) + k;
-					GloId neighID = recvNeighIds[rank][kk];
-					if (neighID.ind != -1)  wgt_map[neighID] += w * scalarprod(recvGrad[rank][kk], (*it)->x);
-				}
-
-			}
-		}
+      /* first order: src value times weight (weight = supermesh area), later divide by target area */
+      int kk = (order == 2) ? n1 * (NMAX + 1) : n1;
+      GloId neighID = recvNeighIds[rank][kk];
+      wgt_map[neighID] += w;
+
+      if (order == 2)
+      {
+        for (int k = 0; k < NMAX+1; k++)
+        {
+          int kk = n1 * (NMAX + 1) + k;
+          GloId neighID = recvNeighIds[rank][kk];
+          if (neighID.ind != -1)  wgt_map[neighID] += w * scalarprod(recvGrad[rank][kk], (*it)->x);
+        }
+
+      }
+    }
 
     double renorm=0;
@@ -404,57 +407,57 @@
 
     for (map<GloId,double>::iterator it = wgt_map.begin(); it != wgt_map.end(); it++)
-		{
+    {
       if (quantity)  this->remapMatrix[i] = (it->second ) / renorm;
-			else this->remapMatrix[i] = (it->second / e.area) / renorm;
-			this->srcAddress[i] = it->first.ind;
-			this->srcRank[i] = it->first.rank;
-			this->dstAddress[i] = j;
+      else this->remapMatrix[i] = (it->second / e.area) / renorm;
+      this->srcAddress[i] = it->first.ind;
+      this->srcRank[i] = it->first.rank;
+      this->dstAddress[i] = j;
       this->sourceWeightId[i]= it->first.globalId ;
       this->targetWeightId[i]= targetGlobalId[j] ;
-			i++;
-		}
-	}
+      i++;
+    }
+  }
         
         MPI_Barrier(communicator);
 
-	/* free all memory allocated in this function */
-	for (int rank = 0; rank < mpiSize; rank++)
-	{
-		if (nbSendElement[rank] > 0)
-		{
-			delete[] sendElement[rank];
-			delete[] recvValue[rank];
-			delete[] recvArea[rank];
-			if (order == 2)
-			{
-				delete[] recvGrad[rank];
-			}
-			delete[] recvNeighIds[rank];
-		}
-		if (nbRecvElement[rank] > 0)
-		{
-			delete[] recvElement[rank];
-			delete[] sendValue[rank];
-			delete[] sendArea[rank];
-			if (order == 2)
-				delete[] sendGrad[rank];
-			delete[] sendNeighIds[rank];
-		}
-	}
-	delete[] status;
-	delete[] sendRequest;
-	delete[] recvRequest;
-	delete[] elementList;
-	delete[] nbSendElement;
-	delete[] nbRecvElement;
-	delete[] sendElement;
-	delete[] recvElement;
-	delete[] sendValue;
-	delete[] recvValue;
-	delete[] sendGrad;
-	delete[] recvGrad;
-	delete[] sendNeighIds;
-	delete[] recvNeighIds;
-	return i;
+  /* free all memory allocated in this function */
+  for (int rank = 0; rank < mpiSize; rank++)
+  {
+    if (nbSendElement[rank] > 0)
+    {
+      delete[] sendElement[rank];
+      delete[] recvValue[rank];
+      delete[] recvArea[rank];
+      if (order == 2)
+      {
+        delete[] recvGrad[rank];
+      }
+      delete[] recvNeighIds[rank];
+    }
+    if (nbRecvElement[rank] > 0)
+    {
+      delete[] recvElement[rank];
+      delete[] sendValue[rank];
+      delete[] sendArea[rank];
+      if (order == 2)
+        delete[] sendGrad[rank];
+      delete[] sendNeighIds[rank];
+    }
+  }
+  delete[] status;
+  delete[] sendRequest;
+  delete[] recvRequest;
+  delete[] elementList;
+  delete[] nbSendElement;
+  delete[] nbRecvElement;
+  delete[] sendElement;
+  delete[] recvElement;
+  delete[] sendValue;
+  delete[] recvValue;
+  delete[] sendGrad;
+  delete[] recvGrad;
+  delete[] sendNeighIds;
+  delete[] recvNeighIds;
+  return i;
 }
 
@@ -495,5 +498,4 @@
 	mpiRoute.init(routes);
 	int nRecv = mpiRoute.getTotalSourceElement();
-// cout << mpiRank << " NRECV " << nRecv << "(" << routes.size() << ")"<< endl;
 
 	int *nbSendNode = new int[mpiSize];
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_dup.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_dup.cpp	(revision 1467)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_dup.cpp	(revision 1468)
@@ -94,7 +94,24 @@
         out_comm[i].ep_comm_ptr->intercomm->remote_rank_map = new RANK_MAP;
 
-        out_comm[i].ep_comm_ptr->intercomm->intercomm_rank_map = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->intercomm_rank_map;
-        out_comm[i].ep_comm_ptr->intercomm->local_rank_map = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->local_rank_map;
-        out_comm[i].ep_comm_ptr->intercomm->remote_rank_map = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->remote_rank_map;
+        int map_size = 0;
+        map_size = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->intercomm_rank_map->size();
+        out_comm[i].ep_comm_ptr->intercomm->intercomm_rank_map->resize(map_size);
+        for(int ii=0; ii<map_size; ii++)
+          out_comm[i].ep_comm_ptr->intercomm->intercomm_rank_map->at(ii) = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->intercomm_rank_map->at(ii);
+
+        map_size = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->local_rank_map->size();
+        out_comm[i].ep_comm_ptr->intercomm->local_rank_map->resize(map_size);
+        for(int ii=0; ii<map_size; ii++)
+          out_comm[i].ep_comm_ptr->intercomm->local_rank_map->at(ii) = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->local_rank_map->at(ii);
+
+        map_size = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->remote_rank_map->size();
+        out_comm[i].ep_comm_ptr->intercomm->remote_rank_map->resize(map_size);
+        for(int ii=0; ii<map_size; ii++)
+          out_comm[i].ep_comm_ptr->intercomm->remote_rank_map->at(ii) = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->remote_rank_map->at(ii);
+
+
+        //out_comm[i].ep_comm_ptr->intercomm->intercomm_rank_map = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->intercomm_rank_map;
+        //out_comm[i].ep_comm_ptr->intercomm->local_rank_map = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->local_rank_map;
+        //out_comm[i].ep_comm_ptr->intercomm->remote_rank_map = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->remote_rank_map;
 
         out_comm[i].ep_comm_ptr->intercomm->local_comm = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->local_comm;        
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_free.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_free.cpp	(revision 1467)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_free.cpp	(revision 1468)
@@ -9,5 +9,4 @@
   int MPI_Comm_free(MPI_Comm *comm)
   {
-
     if(! comm->is_ep)
     {
Index: XIOS/dev/branch_openmp/inputs/COMPLETE/iodef.xml
===================================================================
--- XIOS/dev/branch_openmp/inputs/COMPLETE/iodef.xml	(revision 1467)
+++ XIOS/dev/branch_openmp/inputs/COMPLETE/iodef.xml	(revision 1468)
@@ -12,4 +12,9 @@
             <variable id="buffer_size_factor" type="double">1.0</variable>
          </variable_group>
+       
+         <variable_group id="server">
+            <variable id="using_server2" type="bool">true</variable>
+            <variable id="ratio_server2" type="int">50</variable>
+         </variable_group>
 
         <variable_group id="parameters" >
Index: XIOS/dev/branch_openmp/inputs/REMAP/iodef.xml
===================================================================
--- XIOS/dev/branch_openmp/inputs/REMAP/iodef.xml	(revision 1467)
+++ XIOS/dev/branch_openmp/inputs/REMAP/iodef.xml	(revision 1468)
@@ -171,5 +171,5 @@
       <variable_definition>
          <variable_group id="server">
-            <variable id="using_server2" type="bool">false</variable>
+            <variable id="using_server2" type="bool">true</variable>
             <variable id="ratio_server2" type="int">50</variable>
          </variable_group>
Index: XIOS/dev/branch_openmp/inputs/TOY/iodef.xml
===================================================================
--- XIOS/dev/branch_openmp/inputs/TOY/iodef.xml	(revision 1467)
+++ XIOS/dev/branch_openmp/inputs/TOY/iodef.xml	(revision 1468)
@@ -10,5 +10,6 @@
     <variable_definition>
        <variable_group id="server">
-        <variable id="using_server2" type="bool">false</variable>
+        <variable id="using_server2" type="bool">true</variable>
+        <variable id="ratio_server2" type="int">50</variable>
       </variable_group>
      
Index: XIOS/dev/branch_openmp/inputs/iodef.xml
===================================================================
--- XIOS/dev/branch_openmp/inputs/iodef.xml	(revision 1467)
+++ XIOS/dev/branch_openmp/inputs/iodef.xml	(revision 1468)
@@ -59,5 +59,6 @@
 
         <variable_group id="parameters" >
-          <variable id="using_server" type="bool">false</variable>
+          <variable id="using_server2" type="bool">true</variable>
+          <variable id="ratio_server2" type="int">50</variable>
           <variable id="info_level" type="int">50</variable>
           <variable id="print_file" type="bool">true</variable>
Index: XIOS/dev/branch_openmp/src/node/context.cpp
===================================================================
--- XIOS/dev/branch_openmp/src/node/context.cpp	(revision 1467)
+++ XIOS/dev/branch_openmp/src/node/context.cpp	(revision 1468)
@@ -257,7 +257,8 @@
      
 
-     if (CServer::serverLevel != 1)
+     //if (CServer::serverLevel != 1)
+      if (CServer::serverLevel == 0)
       // initClient is called by client
-     {
+      {
        client = new CContextClient(this, intraComm, interComm, cxtServer);
        if (cxtServer) // Attached mode
@@ -289,5 +290,5 @@
        server = new CContextServer(this, intraCommServer, interCommServer);
      }
-     else
+     else if(CServer::serverLevel == 1)
      // initClient is called by primary server
      {
Index: XIOS/dev/branch_openmp/src/test/test_remap_omp.f90
===================================================================
--- XIOS/dev/branch_openmp/src/test/test_remap_omp.f90	(revision 1467)
+++ XIOS/dev/branch_openmp/src/test/test_remap_omp.f90	(revision 1468)
@@ -231,4 +231,7 @@
     !CALL xios_recv_field("src_field_curvilinear", tmp_field_1)
     !CALL xios_recv_field("src_field_unstructured", tmp_field_2)
+    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)
     CALL xios_update_calendar(ts)
     
