Ignore:
Timestamp:
01/23/19 10:31:44 (5 years ago)
Author:
yushan
Message:

dev on ADA. add flag switch _usingEP/_usingMPI

Location:
XIOS/dev/branch_openmp/extern
Files:
46 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/branch_openmp/extern/remap/src/cputime.cpp

    r1328 r1642  
    11#include "mpi.hpp" 
    2 using namespace ep_lib; 
    32 
    43namespace sphereRemap { 
  • XIOS/dev/branch_openmp/extern/remap/src/elt.hpp

    r1328 r1642  
    4848        int n; /* number of vertices */ 
    4949        double area; 
     50  double given_area ; 
    5051        Coord x; /* barycentre */ 
    5152}; 
     
    8081                n    = rhs.n; 
    8182                area = rhs.area; 
     83                given_area = rhs.given_area; 
    8284                x    = rhs.x; 
    8385                val  = rhs.val; 
  • XIOS/dev/branch_openmp/extern/remap/src/gridRemap.cpp

    r1335 r1642  
    1111 
    1212CRemapGrid srcGrid; 
    13 #pragma omp threadprivate(srcGrid) 
    14  
    1513CRemapGrid tgtGrid; 
    16 #pragma omp threadprivate(tgtGrid) 
    1714 
    1815} 
  • XIOS/dev/branch_openmp/extern/remap/src/gridRemap.hpp

    r1460 r1642  
    1414Coord readPole(std::istream&); 
    1515 
    16 //extern CRemapGrid srcGrid; 
    17 //extern CRemapGrid tgtGrid; 
     16extern CRemapGrid srcGrid; 
     17extern CRemapGrid tgtGrid; 
    1818 
    1919} 
  • XIOS/dev/branch_openmp/extern/remap/src/intersect.cpp

    r1335 r1642  
    1414 
    1515namespace sphereRemap { 
    16  
    17 extern CRemapGrid srcGrid; 
    18 #pragma omp threadprivate(srcGrid) 
    19  
    20 extern CRemapGrid tgtGrid; 
    21 #pragma omp threadprivate(tgtGrid) 
    2216 
    2317using namespace std; 
  • XIOS/dev/branch_openmp/extern/remap/src/intersection_ym.cpp

    r1335 r1642  
    88#include <stdlib.h> 
    99#include <limits> 
     10#include <array> 
     11#include <cstdint>  
     12#include "earcut.hpp" 
     13#include <fstream>  
     14 
    1015 
    1116#define epsilon 1e-3  // epsilon distance ratio over side lenght for approximate small circle by great circle 
     
    1419namespace sphereRemap { 
    1520 
    16 extern CRemapGrid srcGrid; 
    17 #pragma omp threadprivate(srcGrid) 
    18  
    19 extern CRemapGrid tgtGrid; 
    20 #pragma omp threadprivate(tgtGrid) 
    21  
    22  
    2321using namespace std; 
    2422using namespace ClipperLib ; 
     23         
    2524 
    2625double intersect_ym(Elt *a, Elt *b) 
    2726{ 
     27 
     28  using N = uint32_t; 
     29  using Point = array<double, 2>; 
     30  vector<Point> vect_points; 
     31  vector< vector<Point> > polyline; 
    2832 
    2933// transform small circle into piece of great circle if necessary 
     
    5256  double cos_alpha; 
    5357 
     58  /// vector<p2t::Point*> polyline; 
    5459  for(int n=0; n<na;n++) 
    5560  { 
     
    5863    a_gno[n].y=scalarprod(dstPolygon[n],Oy)/cos_alpha ; 
    5964    a_gno[n].z=scalarprod(dstPolygon[n],Oz)/cos_alpha ; // must be equal to 1 
    60   } 
     65 
     66    vect_points.push_back( array<double, 2>() ); 
     67    vect_points[n][0] = a_gno[n].x; 
     68    vect_points[n][1] = a_gno[n].y; 
     69 
     70  } 
     71 
     72  polyline.push_back(vect_points); 
     73  vector<N> indices_a_gno = mapbox::earcut<N>(polyline); 
     74   
     75  double area_a_gno=0 ; 
     76  for(int i=0;i<indices_a_gno.size()/3;++i) 
     77    { 
     78      Coord x0 = Ox * polyline[0][indices_a_gno[3*i]][0] + Oy* polyline[0][indices_a_gno[3*i]][1] + Oz ; 
     79      Coord x1 = Ox * polyline[0][indices_a_gno[3*i+1]][0] + Oy* polyline[0][indices_a_gno[3*i+1]][1] + Oz ; 
     80      Coord x2 = Ox * polyline[0][indices_a_gno[3*i+2]][0] + Oy* polyline[0][indices_a_gno[3*i+2]][1] + Oz ; 
     81      area_a_gno+=triarea(x0 * (1./norm(x0)),x1* (1./norm(x1)), x2* (1./norm(x2))) ; 
     82    } 
     83 
     84  vect_points.clear(); 
     85  polyline.clear(); 
     86  indices_a_gno.clear(); 
     87 
     88  
    6189 
    6290  for(int n=0; n<nb;n++) 
     
    6694    b_gno[n].y=scalarprod(srcPolygon[n],Oy)/cos_alpha ; 
    6795    b_gno[n].z=scalarprod(srcPolygon[n],Oz)/cos_alpha ; // must be equal to 1 
    68   } 
    69  
     96 
     97    vect_points.push_back( array<double, 2>() ); 
     98    vect_points[n][0] = b_gno[n].x; 
     99    vect_points[n][1] = b_gno[n].y; 
     100  } 
     101 
     102 
     103  polyline.push_back(vect_points); 
     104  vector<N> indices_b_gno = mapbox::earcut<N>(polyline); 
     105 
     106  double area_b_gno=0 ; 
     107  for(int i=0;i<indices_b_gno.size()/3;++i) 
     108    { 
     109      Coord x0 = Ox * polyline[0][indices_b_gno[3*i]][0] + Oy* polyline[0][indices_b_gno[3*i]][1] + Oz ; 
     110      Coord x1 = Ox * polyline[0][indices_b_gno[3*i+1]][0] + Oy* polyline[0][indices_b_gno[3*i+1]][1] + Oz ; 
     111      Coord x2 = Ox * polyline[0][indices_b_gno[3*i+2]][0] + Oy* polyline[0][indices_b_gno[3*i+2]][1] + Oz ; 
     112      area_b_gno+=triarea(x0 * (1./norm(x0)),x1* (1./norm(x1)), x2* (1./norm(x2))) ; 
     113    } 
     114 
     115  vect_points.clear(); 
     116  polyline.clear(); 
     117  indices_b_gno.clear(); 
    70118 
    71119 
     
    116164  clip.AddPaths(dst, ptClip, true); 
    117165  clip.Execute(ctIntersection, intersection); 
    118  
     166  
    119167  double area=0 ; 
    120168 
    121169  for(int ni=0;ni<intersection.size(); ni++) 
    122170  { 
    123     // go back into real coordinate on the sphere 
    124171    Coord* intersectPolygon=new Coord[intersection[ni].size()] ; 
    125172    for(int n=0; n < intersection[ni].size(); n++) 
    126173    { 
    127       double x=intersection[ni][n].X/xscale+xoffset ; 
    128       double y=intersection[ni][n].Y/yscale+yoffset ; 
    129  
    130       intersectPolygon[n]=Ox*x+Oy*y+Oz ; 
    131       intersectPolygon[n]=intersectPolygon[n]*(1./norm(intersectPolygon[n])) ; 
    132     } 
    133  
    134 // remove redondants vertex 
    135     int nv=0 ; 
     174      intersectPolygon[n].x=intersection[ni][n].X/xscale+xoffset ; 
     175      intersectPolygon[n].y=intersection[ni][n].Y/yscale+yoffset ; 
     176    } 
     177     
     178 
     179    int nv=0; 
     180 
    136181    for(int n=0; n < intersection[ni].size(); n++) 
    137182    { 
    138       if (norm(intersectPolygon[n]-intersectPolygon[(n+1)%intersection[ni].size()])>fusion_vertex) 
     183       double dx=intersectPolygon[n].x-intersectPolygon[(n+1)%intersection[ni].size()].x ; 
     184       double dy=intersectPolygon[n].y-intersectPolygon[(n+1)%intersection[ni].size()].y ; 
     185      
     186       if (dx*dx+dy*dy>fusion_vertex*fusion_vertex) 
     187       { 
     188          intersectPolygon[nv]=intersectPolygon[n] ; 
     189 
     190          vect_points.push_back( array<double, 2>() ); 
     191          vect_points[nv][0] = intersectPolygon[n].x; 
     192          vect_points[nv][1] = intersectPolygon[n].y; 
     193 
     194          nv++ ; 
     195       } 
     196       
     197 
     198    } 
     199 
     200    polyline.push_back(vect_points); 
     201    vect_points.clear(); 
     202 
     203    if (nv>2) 
     204    { 
     205  
     206      vector<N> indices = mapbox::earcut<N>(polyline); 
     207 
     208      double area2=0 ; 
     209      for(int i=0;i<indices.size()/3;++i) 
    139210      { 
    140         intersectPolygon[nv]=intersectPolygon[n] ; 
    141         nv++ ; 
     211          Coord x0 = Ox * polyline[0][indices[3*i]][0] + Oy* polyline[0][indices[3*i]][1] + Oz ; 
     212          Coord x1 = Ox * polyline[0][indices[3*i+1]][0] + Oy* polyline[0][indices[3*i+1]][1] + Oz ; 
     213          Coord x2 = Ox * polyline[0][indices[3*i+2]][0] + Oy* polyline[0][indices[3*i+2]][1] + Oz ; 
     214          area2+=triarea(x0 * (1./norm(x0)),x1* (1./norm(x1)), x2* (1./norm(x2))) ; 
    142215      } 
    143     } 
    144  
    145  
    146     if (nv>2) 
    147     { 
     216 
     217      polyline.clear(); 
     218 
     219      for(int n=0; n < nv; n++) 
     220      { 
     221        intersectPolygon[n] = Ox*intersectPolygon[n].x+Oy*intersectPolygon[n].y+Oz; 
     222        intersectPolygon[n] = intersectPolygon[n]*(1./norm(intersectPolygon[n])) ; 
     223      } 
     224 
     225 
    148226//     assign intersection to source and destination polygons 
    149227       Polyg *is = new Polyg; 
    150228       is->x = exact_barycentre(intersectPolygon,nv); 
    151        is->area = polygonarea(intersectPolygon,nv) ; 
     229//       is->area = polygonarea(intersectPolygon,nv) ; 
     230       is->area = area2 ; 
     231 
    152232//        if (is->area < 1e-12) cout<<"Small intersection : "<<is->area<<endl ; 
    153233       if (is->area==0.) delete is ; 
     
    168248  delete[] b_gno ; 
    169249  return area ; 
     250 
    170251} 
     252 
     253 
    171254 
    172255void createGreatCirclePolygon(const Elt& element, const Coord& pole, vector<Coord>& coordinates) 
  • XIOS/dev/branch_openmp/extern/remap/src/libmapper.cpp

    r1335 r1642  
    1515#include "cputime.hpp" // cputime 
    1616 
    17 using namespace ep_lib; 
    18  
    1917using namespace sphereRemap ; 
    2018 
     
    2220   and deallocated during the second step (computing the weights) */ 
    2321Mapper *mapper; 
    24 #pragma omp threadprivate(mapper) 
     22 
    2523 
    2624/** xxx_bounds_yyy is of length n_vert_per_cell_xxx*n_cell_xxx 
     
    4341        assert(n_cell_dst >= 4); 
    4442        assert(1 <= order && order <= 2); 
    45  
    46   mapper = new Mapper(MPI_COMM_WORLD); 
     43  double* src_area=NULL ; 
     44  double* dst_area=NULL ; 
     45  mapper = new Mapper(EP_COMM_WORLD); 
    4746  mapper->setVerbosity(PROGRESS) ; 
    48   mapper->setSourceMesh(src_bounds_lon, src_bounds_lat, n_vert_per_cell_src, n_cell_src, src_pole ) ; 
    49   mapper->setTargetMesh(dst_bounds_lon, dst_bounds_lat, n_vert_per_cell_dst, n_cell_dst, dst_pole ) ; 
     47  mapper->setSourceMesh(src_bounds_lon, src_bounds_lat, src_area, n_vert_per_cell_src, n_cell_src, src_pole ) ; 
     48  mapper->setTargetMesh(dst_bounds_lon, dst_bounds_lat, dst_area, n_vert_per_cell_dst, n_cell_dst, dst_pole ) ; 
    5049 
    5150/* 
  • XIOS/dev/branch_openmp/extern/remap/src/mapper.cpp

    r1545 r1642  
    1212 
    1313#include "mapper.hpp" 
    14 using namespace ep_lib; 
    1514 
    1615namespace sphereRemap { 
    17  
    18 extern CRemapGrid srcGrid; 
    19 #pragma omp threadprivate(srcGrid) 
    20  
    21 extern CRemapGrid tgtGrid; 
    22 #pragma omp threadprivate(tgtGrid) 
    23  
    2416 
    2517/* A subdivition of an array into N sub-arays 
     
    3527 
    3628 
    37 void Mapper::setSourceMesh(const double* boundsLon, const double* boundsLat, int nVertex, int nbCells, const double* pole, const long int* globalId) 
     29void Mapper::setSourceMesh(const double* boundsLon, const double* boundsLat, const double* area, int nVertex, int nbCells, const double* pole, const long int* globalId) 
    3830{ 
    3931  srcGrid.pole = Coord(pole[0], pole[1], pole[2]); 
    4032 
    4133  int mpiRank, mpiSize; 
    42   MPI_Comm_rank(communicator, &mpiRank); 
    43   MPI_Comm_size(communicator, &mpiSize); 
     34  ep_lib::MPI_Comm_rank(communicator, &mpiRank); 
     35  ep_lib::MPI_Comm_size(communicator, &mpiSize); 
    4436 
    4537  sourceElements.reserve(nbCells); 
     
    5143    long int offset ; 
    5244    long int nb=nbCells ; 
    53     MPI_Scan(&nb,&offset,1,MPI_LONG,MPI_SUM,communicator) ; 
     45    ep_lib::MPI_Scan(&nb,&offset,1,EP_LONG,EP_SUM,communicator) ; 
    5446    offset=offset-nb ; 
    5547    for(int i=0;i<nbCells;i++) sourceGlobalId[i]=offset+i ; 
     
    6759    sourceMesh.push_back(Node(elt.x, cptRadius(elt), &sourceElements.back())); 
    6860    cptEltGeom(sourceElements[i], Coord(pole[0], pole[1], pole[2])); 
    69   } 
    70  
    71 } 
    72  
    73 void Mapper::setTargetMesh(const double* boundsLon, const double* boundsLat, int nVertex, int nbCells, const double* pole, const long int* globalId) 
     61    if (area!=NULL) sourceElements[i].given_area=area[i] ; 
     62    else sourceElements[i].given_area=sourceElements[i].area ; 
     63  } 
     64 
     65} 
     66 
     67void Mapper::setTargetMesh(const double* boundsLon, const double* boundsLat, const double* area, int nVertex, int nbCells, const double* pole, const long int* globalId) 
    7468{ 
    7569  tgtGrid.pole = Coord(pole[0], pole[1], pole[2]); 
    7670 
    7771  int mpiRank, mpiSize; 
    78   MPI_Comm_rank(communicator, &mpiRank); 
    79   MPI_Comm_size(communicator, &mpiSize); 
     72  ep_lib::MPI_Comm_rank(communicator, &mpiRank); 
     73  ep_lib::MPI_Comm_size(communicator, &mpiSize); 
    8074 
    8175  targetElements.reserve(nbCells); 
     
    8781    long int offset ; 
    8882    long int nb=nbCells ; 
    89     MPI_Scan(&nb,&offset,1,MPI_LONG,MPI_SUM,communicator) ; 
     83    ep_lib::MPI_Scan(&nb,&offset,1,EP_LONG,EP_SUM,communicator) ; 
    9084    offset=offset-nb ; 
    9185    for(int i=0;i<nbCells;i++) targetGlobalId[i]=offset+i ; 
     
    10094    targetMesh.push_back(Node(elt.x, cptRadius(elt), &sourceElements.back())); 
    10195    cptEltGeom(targetElements[i], Coord(pole[0], pole[1], pole[2])); 
     96    if (area!=NULL) targetElements[i].given_area=area[i] ; 
     97    else targetElements[i].given_area=targetElements[i].area ; 
    10298  } 
    10399 
     
    121117  vector<double> timings; 
    122118  int mpiSize, mpiRank; 
    123   MPI_Comm_size(communicator, &mpiSize); 
    124   MPI_Comm_rank(communicator, &mpiRank); 
     119  ep_lib::MPI_Comm_size(communicator, &mpiSize); 
     120  ep_lib::MPI_Comm_rank(communicator, &mpiRank); 
    125121 
    126122  this->buildSSTree(sourceMesh, targetMesh); 
     
    132128 
    133129  tic = cputime(); 
    134   if (interpOrder == 2)  
    135   { 
     130  if (interpOrder == 2) { 
    136131    if (mpiRank == 0 && verbose) cout << "Computing grads ..." << endl; 
    137132    buildMeshTopology(); 
     
    142137  /* Prepare computation of weights */ 
    143138  /* compute number of intersections which for the first order case 
    144      corresponds to the number of edges in the remap matrix */ 
     139           corresponds to the number of edges in the remap matrix */ 
    145140  int nIntersections = 0; 
    146141  for (int j = 0; j < targetElements.size(); j++) 
     
    178173{ 
    179174  int mpiSize, mpiRank; 
    180   MPI_Comm_size(communicator, &mpiSize); 
    181   MPI_Comm_rank(communicator, &mpiRank); 
     175  ep_lib::MPI_Comm_size(communicator, &mpiSize); 
     176  ep_lib::MPI_Comm_rank(communicator, &mpiRank); 
    182177 
    183178  /* create list of intersections (super mesh elements) for each rank */ 
     
    187182    Elt& e = elements[j]; 
    188183    for (list<Polyg *>::iterator it = e.is.begin(); it != e.is.end(); it++) 
    189     { 
    190184      elementList[(*it)->id.rank].insert(pair<int, Polyg *>((*it)->id.ind, *it)); 
    191     } 
    192185  } 
    193186 
     
    196189  double **recvValue = new double*[mpiSize]; 
    197190  double **recvArea = new double*[mpiSize]; 
     191  double **recvGivenArea = new double*[mpiSize]; 
    198192  Coord **recvGrad = new Coord*[mpiSize]; 
    199193  GloId **recvNeighIds = new GloId*[mpiSize]; /* ids of the of the source neighbours which also contribute through gradient */ 
     
    218212      recvValue[rank]   = new double[nbSendElement[rank]]; 
    219213      recvArea[rank]    = new double[nbSendElement[rank]]; 
     214      recvGivenArea[rank] = new double[nbSendElement[rank]]; 
    220215      if (order == 2) 
    221216      { 
     
    240235  /* communicate sizes of source elements to be sent (index lists and later values and gradients) */ 
    241236  int *nbRecvElement = new int[mpiSize]; 
    242   MPI_Alltoall(nbSendElement, 1, MPI_INT, nbRecvElement, 1, MPI_INT, communicator); 
    243    
     237  ep_lib::MPI_Alltoall(nbSendElement, 1, EP_INT, nbRecvElement, 1, EP_INT, communicator); 
    244238 
    245239  /* communicate indices of source elements on other ranks whoes value and gradient we need (since intersection) */ 
     
    249243  double **sendValue = new double*[mpiSize]; 
    250244  double **sendArea = new double*[mpiSize]; 
     245  double **sendGivenArea = new double*[mpiSize]; 
    251246  Coord **sendGrad = new Coord*[mpiSize]; 
    252247  GloId **sendNeighIds = new GloId*[mpiSize]; 
    253   MPI_Request *sendRequest = new MPI_Request[4*mpiSize]; 
    254   MPI_Request *recvRequest = new MPI_Request[4*mpiSize]; 
     248  ep_lib::MPI_Request *sendRequest = new ep_lib::MPI_Request[5*mpiSize]; 
     249  ep_lib::MPI_Request *recvRequest = new ep_lib::MPI_Request[5*mpiSize]; 
    255250  for (int rank = 0; rank < mpiSize; rank++) 
    256251  { 
    257252    if (nbSendElement[rank] > 0) 
    258253    { 
    259       MPI_Issend(sendElement[rank], nbSendElement[rank], MPI_INT, rank, 0, communicator, &sendRequest[nbSendRequest]); 
     254      ep_lib::MPI_Issend(sendElement[rank], nbSendElement[rank], EP_INT, rank, 0, communicator, &sendRequest[nbSendRequest]); 
    260255      nbSendRequest++; 
    261256    } 
     
    266261      sendValue[rank]   = new double[nbRecvElement[rank]]; 
    267262      sendArea[rank]   = new double[nbRecvElement[rank]]; 
     263      sendGivenArea[rank] = new double[nbRecvElement[rank]]; 
    268264      if (order == 2) 
    269265      { 
     
    275271        sendNeighIds[rank] = new GloId[nbRecvElement[rank]]; 
    276272      } 
    277       MPI_Irecv(recvElement[rank], nbRecvElement[rank], MPI_INT, rank, 0, communicator, &recvRequest[nbRecvRequest]); 
     273      ep_lib::MPI_Irecv(recvElement[rank], nbRecvElement[rank], EP_INT, rank, 0, communicator, &recvRequest[nbRecvRequest]); 
    278274      nbRecvRequest++; 
    279275    } 
    280276  } 
    281   MPI_Status *status = new MPI_Status[4*mpiSize]; 
    282  
    283   MPI_Waitall(nbSendRequest, sendRequest, status); 
    284   MPI_Waitall(nbRecvRequest, recvRequest, status); 
     277  ep_lib::MPI_Status *status = new ep_lib::MPI_Status[5*mpiSize]; 
     278   
     279  ep_lib::MPI_Waitall(nbSendRequest, sendRequest, status); 
     280        ep_lib::MPI_Waitall(nbRecvRequest, recvRequest, status); 
    285281 
    286282  /* for all indices that have been received from requesting ranks: pack values and gradients, then send */ 
     
    296292        sendValue[rank][j] = sstree.localElements[recvElement[rank][j]].val; 
    297293        sendArea[rank][j] = sstree.localElements[recvElement[rank][j]].area; 
     294        sendGivenArea[rank][j] = sstree.localElements[recvElement[rank][j]].given_area; 
    298295        if (order == 2) 
    299296        { 
    300297          sendGrad[rank][jj] = sstree.localElements[recvElement[rank][j]].grad; 
     298//          cout<<"grad  "<<jj<<"  "<<recvElement[rank][j]<<"  "<<sendGrad[rank][jj]<<" "<<sstree.localElements[recvElement[rank][j]].grad<<endl ; 
    301299          sendNeighIds[rank][jj] = sstree.localElements[recvElement[rank][j]].src_id; 
    302300          jj++; 
     
    304302          { 
    305303            sendGrad[rank][jj] = sstree.localElements[recvElement[rank][j]].gradNeigh[i]; 
     304//            cout<<"grad  "<<jj<<"  "<<sendGrad[rank][jj]<<" "<<sstree.localElements[recvElement[rank][j]].grad<<endl ; 
    306305            sendNeighIds[rank][jj] = sstree.localElements[recvElement[rank][j]].neighId[i]; 
    307                                                 jj++; 
    308                                         } 
    309                                 } 
    310                                 else 
    311                                         sendNeighIds[rank][j] = sstree.localElements[recvElement[rank][j]].src_id; 
    312                         } 
    313                         MPI_Issend(sendValue[rank],  nbRecvElement[rank], MPI_DOUBLE, rank, 0, communicator, &sendRequest[nbSendRequest]); 
    314                         nbSendRequest++; 
    315                         MPI_Issend(sendArea[rank],  nbRecvElement[rank], MPI_DOUBLE, rank, 1, communicator, &sendRequest[nbSendRequest]); 
    316                         nbSendRequest++; 
    317                         if (order == 2) 
    318                         { 
    319                                 MPI_Issend(sendGrad[rank], 3*nbRecvElement[rank]*(NMAX+1), 
    320                                                                 MPI_DOUBLE, rank, 2, communicator, &sendRequest[nbSendRequest]); 
    321                                 nbSendRequest++; 
    322                                 MPI_Issend(sendNeighIds[rank], 4*nbRecvElement[rank]*(NMAX+1), MPI_INT, rank, 3, communicator, &sendRequest[nbSendRequest]); 
     306            jj++; 
     307          } 
     308        } 
     309        else 
     310          sendNeighIds[rank][j] = sstree.localElements[recvElement[rank][j]].src_id; 
     311      } 
     312      ep_lib::MPI_Issend(sendValue[rank],  nbRecvElement[rank], EP_DOUBLE, rank, 0, communicator, &sendRequest[nbSendRequest]); 
     313      nbSendRequest++; 
     314      ep_lib::MPI_Issend(sendArea[rank],  nbRecvElement[rank], EP_DOUBLE, rank, 0, communicator, &sendRequest[nbSendRequest]); 
     315      nbSendRequest++; 
     316      ep_lib::MPI_Issend(sendGivenArea[rank],  nbRecvElement[rank], EP_DOUBLE, rank, 0, communicator, &sendRequest[nbSendRequest]); 
     317      nbSendRequest++; 
     318      if (order == 2) 
     319      { 
     320        ep_lib::MPI_Issend(sendGrad[rank], 3*nbRecvElement[rank]*(NMAX+1), EP_DOUBLE, rank, 0, communicator, &sendRequest[nbSendRequest]); 
     321        nbSendRequest++; 
     322        ep_lib::MPI_Issend(sendNeighIds[rank], 4*nbRecvElement[rank]*(NMAX+1), EP_INT, rank, 0, communicator, &sendRequest[nbSendRequest]); 
    323323//ym  --> attention taille GloId 
    324                                 nbSendRequest++; 
    325                         } 
    326                         else 
    327                         { 
    328                                 MPI_Issend(sendNeighIds[rank], 4*nbRecvElement[rank], MPI_INT, rank, 4, communicator, &sendRequest[nbSendRequest]); 
     324        nbSendRequest++; 
     325      } 
     326      else 
     327      { 
     328        ep_lib::MPI_Issend(sendNeighIds[rank], 4*nbRecvElement[rank], EP_INT, rank, 0, communicator, &sendRequest[nbSendRequest]); 
    329329//ym  --> attention taille GloId 
    330                                 nbSendRequest++; 
    331                         } 
    332                 } 
    333                 if (nbSendElement[rank] > 0) 
    334                 { 
    335                         MPI_Irecv(recvValue[rank],  nbSendElement[rank], MPI_DOUBLE, rank, 0, communicator, &recvRequest[nbRecvRequest]); 
    336                         nbRecvRequest++; 
    337                         MPI_Irecv(recvArea[rank],  nbSendElement[rank], MPI_DOUBLE, rank, 1, communicator, &recvRequest[nbRecvRequest]); 
    338                         nbRecvRequest++; 
    339                         if (order == 2) 
    340                         { 
    341                                 MPI_Irecv(recvGrad[rank], 3*nbSendElement[rank]*(NMAX+1), 
    342                                                 MPI_DOUBLE, rank, 2, communicator, &recvRequest[nbRecvRequest]); 
    343                                 nbRecvRequest++; 
    344                                 MPI_Irecv(recvNeighIds[rank], 4*nbSendElement[rank]*(NMAX+1), MPI_INT, rank, 3, communicator, &recvRequest[nbRecvRequest]); 
    345 //ym  --> attention taille GloId 
    346                                 nbRecvRequest++; 
    347                         } 
    348                         else 
    349                         { 
    350                                 MPI_Irecv(recvNeighIds[rank], 4*nbSendElement[rank], MPI_INT, rank, 4, communicator, &recvRequest[nbRecvRequest]); 
     330        nbSendRequest++; 
     331      } 
     332    } 
     333    if (nbSendElement[rank] > 0) 
     334    { 
     335      ep_lib::MPI_Irecv(recvValue[rank],  nbSendElement[rank], EP_DOUBLE, rank, 0, communicator, &recvRequest[nbRecvRequest]); 
     336      nbRecvRequest++; 
     337      ep_lib::MPI_Irecv(recvArea[rank],  nbSendElement[rank], EP_DOUBLE, rank, 0, communicator, &recvRequest[nbRecvRequest]); 
     338      nbRecvRequest++; 
     339      ep_lib::MPI_Irecv(recvGivenArea[rank],  nbSendElement[rank], EP_DOUBLE, rank, 0, communicator, &recvRequest[nbRecvRequest]); 
     340      nbRecvRequest++; 
     341      if (order == 2) 
     342      { 
     343        ep_lib::MPI_Irecv(recvGrad[rank], 3*nbSendElement[rank]*(NMAX+1), 
     344            EP_DOUBLE, rank, 0, communicator, &recvRequest[nbRecvRequest]); 
     345        nbRecvRequest++; 
     346        ep_lib::MPI_Irecv(recvNeighIds[rank], 4*nbSendElement[rank]*(NMAX+1), EP_INT, rank, 0, communicator, &recvRequest[nbRecvRequest]); 
    351347//ym  --> attention taille GloId 
    352348        nbRecvRequest++; 
    353349      } 
     350      else 
     351      { 
     352        ep_lib::MPI_Irecv(recvNeighIds[rank], 4*nbSendElement[rank], EP_INT, rank, 0, communicator, &recvRequest[nbRecvRequest]); 
     353//ym  --> attention taille GloId 
     354        nbRecvRequest++; 
     355      } 
    354356    } 
    355357  } 
    356358         
    357   MPI_Waitall(nbSendRequest, sendRequest, status); 
    358   MPI_Waitall(nbRecvRequest, recvRequest, status); 
    359          
     359        ep_lib::MPI_Waitall(nbSendRequest, sendRequest, status); 
     360  ep_lib::MPI_Waitall(nbRecvRequest, recvRequest, status); 
     361   
    360362 
    361363  /* now that all values and gradients are available use them to computed interpolated values on target 
    362     and also to compute weights */ 
     364     and also to compute weights */ 
    363365  int i = 0; 
    364366  for (int j = 0; j < nbElements; j++) 
     
    367369 
    368370    /* since for the 2nd order case source grid elements can contribute to a destination grid element over several "paths" 
    369     (step1: gradient is computed using neighbours on same grid, step2: intersection uses several elements on other grid) 
    370     accumulate them so that there is only one final weight between two elements */ 
     371       (step1: gradient is computed using neighbours on same grid, step2: intersection uses several elements on other grid) 
     372       accumulate them so that there is only one final weight between two elements */ 
    371373    map<GloId,double> wgt_map; 
    372374 
     
    380382      double fk = recvValue[rank][n1]; 
    381383      double srcArea = recvArea[rank][n1]; 
     384      double srcGivenArea = recvGivenArea[rank][n1]; 
    382385      double w = (*it)->area; 
    383386      if (quantity) w/=srcArea ; 
     387      else w=w*srcGivenArea/srcArea*e.area/e.given_area ; 
    384388 
    385389      /* first order: src value times weight (weight = supermesh area), later divide by target area */ 
     
    402406    double renorm=0; 
    403407    if (renormalize)  
    404       for (map<GloId,double>::iterator it = wgt_map.begin(); it != wgt_map.end(); it++) renorm+=it->second / e.area; 
     408    { 
     409      if (quantity) for (map<GloId,double>::iterator it = wgt_map.begin(); it != wgt_map.end(); it++) renorm+=it->second ; 
     410      else for (map<GloId,double>::iterator it = wgt_map.begin(); it != wgt_map.end(); it++) renorm+=it->second / e.area; 
     411    } 
    405412    else renorm=1. ; 
    406413 
     
    417424    } 
    418425  } 
    419          
    420         //MPI_Barrier(communicator); 
    421426 
    422427  /* free all memory allocated in this function */ 
     
    428433      delete[] recvValue[rank]; 
    429434      delete[] recvArea[rank]; 
     435      delete[] recvGivenArea[rank]; 
    430436      if (order == 2) 
    431437      { 
     
    439445      delete[] sendValue[rank]; 
    440446      delete[] sendArea[rank]; 
     447      delete[] sendGivenArea[rank]; 
    441448      if (order == 2) 
    442449        delete[] sendGrad[rank]; 
     
    463470void Mapper::computeGrads() 
    464471{ 
    465         /* array of pointers to collect local elements and elements received from other cpu */ 
    466         vector<Elt*> globalElements(sstree.nbLocalElements + nbNeighbourElements); 
    467         int index = 0; 
    468         for (int i = 0; i < sstree.nbLocalElements; i++, index++) 
    469                 globalElements[index] = &(sstree.localElements[i]); 
    470         for (int i = 0; i < nbNeighbourElements; i++, index++) 
    471                 globalElements[index] = &neighbourElements[i]; 
    472  
    473         update_baryc(sstree.localElements, sstree.nbLocalElements); 
    474         computeGradients(&globalElements[0], sstree.nbLocalElements); 
     472  /* array of pointers to collect local elements and elements received from other cpu */ 
     473  vector<Elt*> globalElements(sstree.nbLocalElements + nbNeighbourElements); 
     474  int index = 0; 
     475  for (int i = 0; i < sstree.nbLocalElements; i++, index++) 
     476    globalElements[index] = &(sstree.localElements[i]); 
     477  for (int i = 0; i < nbNeighbourElements; i++, index++) 
     478    globalElements[index] = &neighbourElements[i]; 
     479 
     480  update_baryc(sstree.localElements, sstree.nbLocalElements); 
     481  computeGradients(&globalElements[0], sstree.nbLocalElements); 
    475482} 
    476483 
     
    479486void Mapper::buildMeshTopology() 
    480487{ 
    481         int mpiSize, mpiRank; 
    482         MPI_Comm_size(communicator, &mpiSize); 
    483         MPI_Comm_rank(communicator, &mpiRank); 
    484  
    485         vector<Node> *routingList = new vector<Node>[mpiSize]; 
    486         vector<vector<int> > routes(sstree.localTree.leafs.size()); 
    487  
    488         sstree.routeIntersections(routes, sstree.localTree.leafs); 
    489  
    490         for (int i = 0; i < routes.size(); ++i) 
    491                 for (int k = 0; k < routes[i].size(); ++k) 
    492                         routingList[routes[i][k]].push_back(sstree.localTree.leafs[i]); 
    493         routingList[mpiRank].clear(); 
    494  
    495  
    496         CMPIRouting mpiRoute(communicator); 
    497         mpiRoute.init(routes); 
    498         int nRecv = mpiRoute.getTotalSourceElement(); 
    499  
    500         int *nbSendNode = new int[mpiSize]; 
    501         int *nbRecvNode = new int[mpiSize]; 
    502         int *sendMessageSize = new int[mpiSize]; 
    503         int *recvMessageSize = new int[mpiSize]; 
    504  
    505         for (int rank = 0; rank < mpiSize; rank++) 
    506         { 
    507                 nbSendNode[rank] = routingList[rank].size(); 
    508                 sendMessageSize[rank] = 0; 
    509                 for (size_t j = 0; j < routingList[rank].size(); j++) 
    510                 { 
    511                         Elt *elt = (Elt *) (routingList[rank][j].data); 
    512                         sendMessageSize[rank] += packedPolygonSize(*elt); 
    513                 } 
    514         } 
    515  
    516         MPI_Alltoall(nbSendNode, 1, MPI_INT, nbRecvNode, 1, MPI_INT, communicator); 
    517         MPI_Alltoall(sendMessageSize, 1, MPI_INT, recvMessageSize, 1, MPI_INT, communicator); 
    518  
    519         char **sendBuffer = new char*[mpiSize]; 
    520         char **recvBuffer = new char*[mpiSize]; 
    521         int *pos = new int[mpiSize]; 
    522  
    523         for (int rank = 0; rank < mpiSize; rank++) 
    524         { 
    525                 if (nbSendNode[rank] > 0) sendBuffer[rank] = new char[sendMessageSize[rank]]; 
    526                 if (nbRecvNode[rank] > 0) recvBuffer[rank] = new char[recvMessageSize[rank]]; 
    527         } 
    528  
    529         for (int rank = 0; rank < mpiSize; rank++) 
    530         { 
    531                 pos[rank] = 0; 
    532                 for (size_t j = 0; j < routingList[rank].size(); j++) 
    533                 { 
    534                         Elt *elt = (Elt *) (routingList[rank][j].data); 
    535                         packPolygon(*elt, sendBuffer[rank], pos[rank]); 
    536                 } 
    537         } 
    538         delete [] routingList; 
    539  
    540  
    541         int nbSendRequest = 0; 
    542         int nbRecvRequest = 0; 
    543         MPI_Request *sendRequest = new MPI_Request[mpiSize]; 
    544         MPI_Request *recvRequest = new MPI_Request[mpiSize]; 
    545         MPI_Status  *status      = new MPI_Status[mpiSize]; 
    546  
    547         for (int rank = 0; rank < mpiSize; rank++) 
    548         { 
    549                 if (nbSendNode[rank] > 0) 
    550                 { 
    551                         MPI_Issend(sendBuffer[rank], sendMessageSize[rank], MPI_CHAR, rank, 0, communicator, &sendRequest[nbSendRequest]); 
    552                         nbSendRequest++; 
    553                 } 
    554                 if (nbRecvNode[rank] > 0) 
    555                 { 
    556                         MPI_Irecv(recvBuffer[rank], recvMessageSize[rank], MPI_CHAR, rank, 0, communicator, &recvRequest[nbRecvRequest]); 
    557                         nbRecvRequest++; 
    558                 } 
    559         } 
    560  
    561         MPI_Waitall(nbRecvRequest, recvRequest, status); 
    562         MPI_Waitall(nbSendRequest, sendRequest, status); 
    563  
    564         for (int rank = 0; rank < mpiSize; rank++) 
    565                 if (nbSendNode[rank] > 0) delete [] sendBuffer[rank]; 
    566         delete [] sendBuffer; 
    567  
    568         char **sendBuffer2 = new char*[mpiSize]; 
    569         char **recvBuffer2 = new char*[mpiSize]; 
    570  
    571         for (int rank = 0; rank < mpiSize; rank++) 
    572         { 
    573                 nbSendNode[rank] = 0; 
    574                 sendMessageSize[rank] = 0; 
    575  
    576                 if (nbRecvNode[rank] > 0) 
    577                 { 
    578                         set<NodePtr> neighbourList; 
    579                         pos[rank] = 0; 
    580                         for (int j = 0; j < nbRecvNode[rank]; j++) 
    581                         { 
    582                                 Elt elt; 
    583                                 unpackPolygon(elt, recvBuffer[rank], pos[rank]); 
    584                                 Node node(elt.x, cptRadius(elt), &elt); 
    585                                 findNeighbour(sstree.localTree.root, &node, neighbourList); 
    586                         } 
    587                         nbSendNode[rank] = neighbourList.size(); 
    588                         for (set<NodePtr>::iterator it = neighbourList.begin(); it != neighbourList.end(); it++) 
    589                         { 
    590                                 Elt *elt = (Elt *) ((*it)->data); 
    591                                 sendMessageSize[rank] += packedPolygonSize(*elt); 
    592                         } 
    593  
    594                         sendBuffer2[rank] = new char[sendMessageSize[rank]]; 
    595                         pos[rank] = 0; 
    596  
    597                         for (set<NodePtr>::iterator it = neighbourList.begin(); it != neighbourList.end(); it++) 
    598                         { 
    599                                 Elt *elt = (Elt *) ((*it)->data); 
    600                                 packPolygon(*elt, sendBuffer2[rank], pos[rank]); 
    601                         } 
    602                 } 
    603         } 
    604         for (int rank = 0; rank < mpiSize; rank++) 
    605                 if (nbRecvNode[rank] > 0) delete [] recvBuffer[rank]; 
    606         delete [] recvBuffer; 
    607  
    608  
    609         MPI_Barrier(communicator); 
    610         MPI_Alltoall(nbSendNode, 1, MPI_INT, nbRecvNode, 1, MPI_INT, communicator); 
    611         MPI_Alltoall(sendMessageSize, 1, MPI_INT, recvMessageSize, 1, MPI_INT, communicator); 
    612  
    613         for (int rank = 0; rank < mpiSize; rank++) 
    614                 if (nbRecvNode[rank] > 0) recvBuffer2[rank] = new char[recvMessageSize[rank]]; 
    615  
    616         nbSendRequest = 0; 
    617         nbRecvRequest = 0; 
    618  
    619         for (int rank = 0; rank < mpiSize; rank++) 
    620         { 
    621                 if (nbSendNode[rank] > 0) 
    622                 { 
    623                         MPI_Issend(sendBuffer2[rank], sendMessageSize[rank], MPI_CHAR, rank, 0, communicator, &sendRequest[nbSendRequest]); 
    624                         nbSendRequest++; 
    625                 } 
    626                 if (nbRecvNode[rank] > 0) 
    627                 { 
    628                         MPI_Irecv(recvBuffer2[rank], recvMessageSize[rank], MPI_CHAR, rank, 0, communicator, &recvRequest[nbRecvRequest]); 
    629                         nbRecvRequest++; 
    630                 } 
    631         } 
    632  
    633         MPI_Waitall(nbRecvRequest, recvRequest, status); 
    634         MPI_Waitall(nbSendRequest, sendRequest, status); 
    635  
    636         int nbNeighbourNodes = 0; 
    637         for (int rank = 0; rank < mpiSize; rank++) 
    638                 nbNeighbourNodes += nbRecvNode[rank]; 
    639  
    640         neighbourElements = new Elt[nbNeighbourNodes]; 
    641         nbNeighbourElements = nbNeighbourNodes; 
    642  
    643         int index = 0; 
    644         for (int rank = 0; rank < mpiSize; rank++) 
    645         { 
    646                 pos[rank] = 0; 
    647                 for (int j = 0; j < nbRecvNode[rank]; j++) 
    648                 { 
    649                         unpackPolygon(neighbourElements[index], recvBuffer2[rank], pos[rank]); 
    650                         neighbourElements[index].id.ind = sstree.localTree.leafs.size() + index; 
    651                         index++; 
    652                 } 
    653         } 
    654         for (int rank = 0; rank < mpiSize; rank++) 
    655         { 
    656                 if (nbRecvNode[rank] > 0) delete [] recvBuffer2[rank]; 
    657                 if (nbSendNode[rank] > 0) delete [] sendBuffer2[rank]; 
    658         } 
    659         delete [] recvBuffer2; 
    660         delete [] sendBuffer2; 
    661         delete [] sendMessageSize; 
    662         delete [] recvMessageSize; 
    663         delete [] nbSendNode; 
    664         delete [] nbRecvNode; 
    665         delete [] sendRequest; 
    666         delete [] recvRequest; 
    667         delete [] status; 
    668         delete [] pos; 
    669  
    670         /* re-compute on received elements to avoid having to send this information */ 
    671         neighbourNodes.resize(nbNeighbourNodes); 
    672         setCirclesAndLinks(neighbourElements, neighbourNodes); 
    673         cptAllEltsGeom(neighbourElements, nbNeighbourNodes, srcGrid.pole); 
    674  
    675         /* the local SS tree must include nodes from other cpus if they are potential 
     488  int mpiSize, mpiRank; 
     489  ep_lib::MPI_Comm_size(communicator, &mpiSize); 
     490  ep_lib::MPI_Comm_rank(communicator, &mpiRank); 
     491 
     492  vector<Node> *routingList = new vector<Node>[mpiSize]; 
     493  vector<vector<int> > routes(sstree.localTree.leafs.size()); 
     494 
     495  sstree.routeIntersections(routes, sstree.localTree.leafs); 
     496 
     497  for (int i = 0; i < routes.size(); ++i) 
     498    for (int k = 0; k < routes[i].size(); ++k) 
     499      routingList[routes[i][k]].push_back(sstree.localTree.leafs[i]); 
     500  routingList[mpiRank].clear(); 
     501 
     502 
     503  CMPIRouting mpiRoute(communicator); 
     504  mpiRoute.init(routes); 
     505  int nRecv = mpiRoute.getTotalSourceElement(); 
     506// cout << mpiRank << " NRECV " << nRecv << "(" << routes.size() << ")"<< endl; 
     507 
     508  int *nbSendNode = new int[mpiSize]; 
     509  int *nbRecvNode = new int[mpiSize]; 
     510  int *sendMessageSize = new int[mpiSize]; 
     511  int *recvMessageSize = new int[mpiSize]; 
     512 
     513  for (int rank = 0; rank < mpiSize; rank++) 
     514  { 
     515    nbSendNode[rank] = routingList[rank].size(); 
     516    sendMessageSize[rank] = 0; 
     517    for (size_t j = 0; j < routingList[rank].size(); j++) 
     518    { 
     519      Elt *elt = (Elt *) (routingList[rank][j].data); 
     520      sendMessageSize[rank] += packedPolygonSize(*elt); 
     521    } 
     522  } 
     523 
     524  ep_lib::MPI_Alltoall(nbSendNode, 1, EP_INT, nbRecvNode, 1, EP_INT, communicator); 
     525  ep_lib::MPI_Alltoall(sendMessageSize, 1, EP_INT, recvMessageSize, 1, EP_INT, communicator); 
     526 
     527  char **sendBuffer = new char*[mpiSize]; 
     528  char **recvBuffer = new char*[mpiSize]; 
     529  int *pos = new int[mpiSize]; 
     530 
     531  for (int rank = 0; rank < mpiSize; rank++) 
     532  { 
     533    if (nbSendNode[rank] > 0) sendBuffer[rank] = new char[sendMessageSize[rank]]; 
     534    if (nbRecvNode[rank] > 0) recvBuffer[rank] = new char[recvMessageSize[rank]]; 
     535  } 
     536 
     537  for (int rank = 0; rank < mpiSize; rank++) 
     538  { 
     539    pos[rank] = 0; 
     540    for (size_t j = 0; j < routingList[rank].size(); j++) 
     541    { 
     542      Elt *elt = (Elt *) (routingList[rank][j].data); 
     543      packPolygon(*elt, sendBuffer[rank], pos[rank]); 
     544    } 
     545  } 
     546  delete [] routingList; 
     547 
     548 
     549  int nbSendRequest = 0; 
     550  int nbRecvRequest = 0; 
     551  ep_lib::MPI_Request *sendRequest = new ep_lib::MPI_Request[mpiSize]; 
     552  ep_lib::MPI_Request *recvRequest = new ep_lib::MPI_Request[mpiSize]; 
     553  ep_lib::MPI_Status  *status      = new ep_lib::MPI_Status[mpiSize]; 
     554 
     555  for (int rank = 0; rank < mpiSize; rank++) 
     556  { 
     557    if (nbSendNode[rank] > 0) 
     558    { 
     559      ep_lib::MPI_Issend(sendBuffer[rank], sendMessageSize[rank], EP_CHAR, rank, 0, communicator, &sendRequest[nbSendRequest]); 
     560      nbSendRequest++; 
     561    } 
     562    if (nbRecvNode[rank] > 0) 
     563    { 
     564      ep_lib::MPI_Irecv(recvBuffer[rank], recvMessageSize[rank], EP_CHAR, rank, 0, communicator, &recvRequest[nbRecvRequest]); 
     565      nbRecvRequest++; 
     566    } 
     567  } 
     568 
     569  ep_lib::MPI_Waitall(nbRecvRequest, recvRequest, status); 
     570  ep_lib::MPI_Waitall(nbSendRequest, sendRequest, status); 
     571 
     572  for (int rank = 0; rank < mpiSize; rank++) 
     573    if (nbSendNode[rank] > 0) delete [] sendBuffer[rank]; 
     574  delete [] sendBuffer; 
     575 
     576  char **sendBuffer2 = new char*[mpiSize]; 
     577  char **recvBuffer2 = new char*[mpiSize]; 
     578 
     579  for (int rank = 0; rank < mpiSize; rank++) 
     580  { 
     581    nbSendNode[rank] = 0; 
     582    sendMessageSize[rank] = 0; 
     583 
     584    if (nbRecvNode[rank] > 0) 
     585    { 
     586      set<NodePtr> neighbourList; 
     587      pos[rank] = 0; 
     588      for (int j = 0; j < nbRecvNode[rank]; j++) 
     589      { 
     590        Elt elt; 
     591        unpackPolygon(elt, recvBuffer[rank], pos[rank]); 
     592        Node node(elt.x, cptRadius(elt), &elt); 
     593        findNeighbour(sstree.localTree.root, &node, neighbourList); 
     594      } 
     595      nbSendNode[rank] = neighbourList.size(); 
     596      for (set<NodePtr>::iterator it = neighbourList.begin(); it != neighbourList.end(); it++) 
     597      { 
     598        Elt *elt = (Elt *) ((*it)->data); 
     599        sendMessageSize[rank] += packedPolygonSize(*elt); 
     600      } 
     601 
     602      sendBuffer2[rank] = new char[sendMessageSize[rank]]; 
     603      pos[rank] = 0; 
     604 
     605      for (set<NodePtr>::iterator it = neighbourList.begin(); it != neighbourList.end(); it++) 
     606      { 
     607        Elt *elt = (Elt *) ((*it)->data); 
     608        packPolygon(*elt, sendBuffer2[rank], pos[rank]); 
     609      } 
     610    } 
     611  } 
     612  for (int rank = 0; rank < mpiSize; rank++) 
     613    if (nbRecvNode[rank] > 0) delete [] recvBuffer[rank]; 
     614  delete [] recvBuffer; 
     615 
     616 
     617  ep_lib::MPI_Barrier(communicator); 
     618  ep_lib::MPI_Alltoall(nbSendNode, 1, EP_INT, nbRecvNode, 1, EP_INT, communicator); 
     619  ep_lib::MPI_Alltoall(sendMessageSize, 1, EP_INT, recvMessageSize, 1, EP_INT, communicator); 
     620 
     621  for (int rank = 0; rank < mpiSize; rank++) 
     622    if (nbRecvNode[rank] > 0) recvBuffer2[rank] = new char[recvMessageSize[rank]]; 
     623 
     624  nbSendRequest = 0; 
     625  nbRecvRequest = 0; 
     626 
     627  for (int rank = 0; rank < mpiSize; rank++) 
     628  { 
     629    if (nbSendNode[rank] > 0) 
     630    { 
     631      ep_lib::MPI_Issend(sendBuffer2[rank], sendMessageSize[rank], EP_CHAR, rank, 0, communicator, &sendRequest[nbSendRequest]); 
     632      nbSendRequest++; 
     633    } 
     634    if (nbRecvNode[rank] > 0) 
     635    { 
     636      ep_lib::MPI_Irecv(recvBuffer2[rank], recvMessageSize[rank], EP_CHAR, rank, 0, communicator, &recvRequest[nbRecvRequest]); 
     637      nbRecvRequest++; 
     638    } 
     639  } 
     640 
     641  ep_lib::MPI_Waitall(nbRecvRequest, recvRequest, status); 
     642  ep_lib::MPI_Waitall(nbSendRequest, sendRequest, status); 
     643 
     644  int nbNeighbourNodes = 0; 
     645  for (int rank = 0; rank < mpiSize; rank++) 
     646    nbNeighbourNodes += nbRecvNode[rank]; 
     647 
     648  neighbourElements = new Elt[nbNeighbourNodes]; 
     649  nbNeighbourElements = nbNeighbourNodes; 
     650 
     651  int index = 0; 
     652  for (int rank = 0; rank < mpiSize; rank++) 
     653  { 
     654    pos[rank] = 0; 
     655    for (int j = 0; j < nbRecvNode[rank]; j++) 
     656    { 
     657      unpackPolygon(neighbourElements[index], recvBuffer2[rank], pos[rank]); 
     658      neighbourElements[index].id.ind = sstree.localTree.leafs.size() + index; 
     659      index++; 
     660    } 
     661  } 
     662  for (int rank = 0; rank < mpiSize; rank++) 
     663  { 
     664    if (nbRecvNode[rank] > 0) delete [] recvBuffer2[rank]; 
     665    if (nbSendNode[rank] > 0) delete [] sendBuffer2[rank]; 
     666  } 
     667  delete [] recvBuffer2; 
     668  delete [] sendBuffer2; 
     669  delete [] sendMessageSize; 
     670  delete [] recvMessageSize; 
     671  delete [] nbSendNode; 
     672  delete [] nbRecvNode; 
     673  delete [] sendRequest; 
     674  delete [] recvRequest; 
     675  delete [] status; 
     676  delete [] pos; 
     677 
     678  /* re-compute on received elements to avoid having to send this information */ 
     679  neighbourNodes.resize(nbNeighbourNodes); 
     680  setCirclesAndLinks(neighbourElements, neighbourNodes); 
     681  cptAllEltsGeom(neighbourElements, nbNeighbourNodes, srcGrid.pole); 
     682 
     683  /* the local SS tree must include nodes from other cpus if they are potential 
    676684           intersector of a local node */ 
    677         sstree.localTree.insertNodes(neighbourNodes); 
    678  
    679         /* for every local element, 
     685  sstree.localTree.insertNodes(neighbourNodes); 
     686 
     687  /* for every local element, 
    680688           use the SS-tree to find all elements (including neighbourElements) 
    681689           who are potential neighbours because their circles intersect, 
    682            then check all canditates for common edges to build up connectivity information 
    683         */ 
    684         for (int j = 0; j < sstree.localTree.leafs.size(); j++) 
    685         { 
    686                 Node& node = sstree.localTree.leafs[j]; 
    687  
    688                 /* find all leafs whoes circles that intersect node's circle and save into node->intersectors */ 
    689                 node.search(sstree.localTree.root); 
    690  
    691                 Elt *elt = (Elt *)(node.data); 
    692  
    693                 for (int i = 0; i < elt->n; i++) elt->neighbour[i] = NOT_FOUND; 
    694  
    695                 /* for element `elt` loop through all nodes in the SS-tree 
     690     then check all canditates for common edges to build up connectivity information 
     691  */ 
     692  for (int j = 0; j < sstree.localTree.leafs.size(); j++) 
     693  { 
     694    Node& node = sstree.localTree.leafs[j]; 
     695 
     696    /* find all leafs whoes circles that intersect node's circle and save into node->intersectors */ 
     697    node.search(sstree.localTree.root); 
     698 
     699    Elt *elt = (Elt *)(node.data); 
     700 
     701    for (int i = 0; i < elt->n; i++) elt->neighbour[i] = NOT_FOUND; 
     702 
     703    /* for element `elt` loop through all nodes in the SS-tree 
    696704                   whoes circles intersect with the circle around `elt` (the SS intersectors) 
    697705                   and check if they are neighbours in the sense that the two elements share an edge. 
    698706                   If they do, save this information for elt */ 
    699                 for (list<NodePtr>::iterator it = (node.intersectors).begin(); it != (node.intersectors).end(); ++it) 
    700                 { 
    701                         Elt *elt2 = (Elt *)((*it)->data); 
    702                         set_neighbour(*elt, *elt2); 
    703                 } 
     707    for (list<NodePtr>::iterator it = (node.intersectors).begin(); it != (node.intersectors).end(); ++it) 
     708    { 
     709      Elt *elt2 = (Elt *)((*it)->data); 
     710      set_neighbour(*elt, *elt2); 
     711    } 
    704712 
    705713/* 
    706                 for (int i = 0; i < elt->n; i++) 
    707                 { 
    708                         if (elt->neighbour[i] == NOT_FOUND) 
    709                                 error_exit("neighbour not found"); 
    710                 } 
     714    for (int i = 0; i < elt->n; i++) 
     715    { 
     716      if (elt->neighbour[i] == NOT_FOUND) 
     717        error_exit("neighbour not found"); 
     718    } 
    711719*/ 
    712         } 
     720  } 
    713721} 
    714722 
     
    716724void Mapper::computeIntersection(Elt *elements, int nbElements) 
    717725{ 
    718         int mpiSize, mpiRank; 
    719         MPI_Comm_size(communicator, &mpiSize); 
    720         MPI_Comm_rank(communicator, &mpiRank); 
    721  
    722         MPI_Barrier(communicator); 
    723  
    724         vector<Node> *routingList = new vector<Node>[mpiSize]; 
    725  
    726         vector<Node> routeNodes;  routeNodes.reserve(nbElements); 
    727         for (int j = 0; j < nbElements; j++) 
    728         { 
    729                 elements[j].id.ind = j; 
    730                 elements[j].id.rank = mpiRank; 
    731                 routeNodes.push_back(Node(elements[j].x, cptRadius(elements[j]), &elements[j])); 
    732         } 
    733  
    734         vector<vector<int> > routes(routeNodes.size()); 
    735         sstree.routeIntersections(routes, routeNodes); 
    736         for (int i = 0; i < routes.size(); ++i) 
    737                 for (int k = 0; k < routes[i].size(); ++k) 
    738                         routingList[routes[i][k]].push_back(routeNodes[i]); 
    739  
    740         if (verbose >= 2) 
    741         { 
    742                 cout << " --> rank  " << mpiRank << " nbElements " << nbElements << " : "; 
    743                 for (int rank = 0; rank < mpiSize; rank++) 
    744                         cout << routingList[rank].size() << "   "; 
    745                 cout << endl; 
    746         } 
    747         MPI_Barrier(communicator); 
    748  
    749         int *nbSendNode = new int[mpiSize]; 
    750         int *nbRecvNode = new int[mpiSize]; 
    751         int *sentMessageSize = new int[mpiSize]; 
    752         int *recvMessageSize = new int[mpiSize]; 
    753  
    754         for (int rank = 0; rank < mpiSize; rank++) 
    755         { 
    756                 nbSendNode[rank] = routingList[rank].size(); 
    757                 sentMessageSize[rank] = 0; 
    758                 for (size_t j = 0; j < routingList[rank].size(); j++) 
    759                 { 
    760                         Elt *elt = (Elt *) (routingList[rank][j].data); 
    761                         sentMessageSize[rank] += packedPolygonSize(*elt); 
    762                 } 
    763         } 
    764  
    765         MPI_Alltoall(nbSendNode, 1, MPI_INT, nbRecvNode, 1, MPI_INT, communicator); 
    766         MPI_Alltoall(sentMessageSize, 1, MPI_INT, recvMessageSize, 1, MPI_INT, communicator); 
    767  
    768         int total = 0; 
    769  
    770         for (int rank = 0; rank < mpiSize; rank++) 
    771         { 
    772                 total = total + nbRecvNode[rank]; 
    773         } 
    774  
    775         if (verbose >= 2) cout << "---> rank " << mpiRank << " : compute intersection : total received nodes  " << total << endl; 
    776         char **sendBuffer = new char*[mpiSize]; 
    777         char **recvBuffer = new char*[mpiSize]; 
    778         int *pos = new int[mpiSize]; 
    779  
    780         for (int rank = 0; rank < mpiSize; rank++) 
    781         { 
    782                 if (nbSendNode[rank] > 0) sendBuffer[rank] = new char[sentMessageSize[rank]]; 
    783                 if (nbRecvNode[rank] > 0) recvBuffer[rank] = new char[recvMessageSize[rank]]; 
    784         } 
    785  
    786         for (int rank = 0; rank < mpiSize; rank++) 
    787         { 
    788                 pos[rank] = 0; 
    789                 for (size_t j = 0; j < routingList[rank].size(); j++) 
    790                 { 
    791                         Elt* elt = (Elt *) (routingList[rank][j].data); 
    792                         packPolygon(*elt, sendBuffer[rank], pos[rank]); 
    793                 } 
    794         } 
    795         delete [] routingList; 
    796  
    797         int nbSendRequest = 0; 
    798         int nbRecvRequest = 0; 
    799         MPI_Request *sendRequest = new MPI_Request[mpiSize]; 
    800         MPI_Request *recvRequest = new MPI_Request[mpiSize]; 
    801         MPI_Status   *status = new MPI_Status[mpiSize]; 
    802  
    803         for (int rank = 0; rank < mpiSize; rank++) 
    804         { 
    805                 if (nbSendNode[rank] > 0) 
    806                 { 
    807                         MPI_Issend(sendBuffer[rank], sentMessageSize[rank], MPI_CHAR, rank, 0, communicator, &sendRequest[nbSendRequest]); 
    808                         nbSendRequest++; 
    809                 } 
    810                 if (nbRecvNode[rank] > 0) 
    811                 { 
    812                         MPI_Irecv(recvBuffer[rank], recvMessageSize[rank], MPI_CHAR, rank, 0, communicator, &recvRequest[nbRecvRequest]); 
    813                         nbRecvRequest++; 
    814                 } 
    815         } 
    816  
    817         MPI_Waitall(nbRecvRequest, recvRequest, status); 
    818         MPI_Waitall(nbSendRequest, sendRequest, status); 
    819         char **sendBuffer2 = new char*[mpiSize]; 
    820         char **recvBuffer2 = new char*[mpiSize]; 
    821  
    822         double tic = cputime(); 
    823         for (int rank = 0; rank < mpiSize; rank++) 
    824         { 
    825                 sentMessageSize[rank] = 0; 
    826  
    827                 if (nbRecvNode[rank] > 0) 
    828                 { 
    829                         Elt *recvElt = new Elt[nbRecvNode[rank]]; 
    830                         pos[rank] = 0; 
    831                         for (int j = 0; j < nbRecvNode[rank]; j++) 
    832                         { 
    833                                 unpackPolygon(recvElt[j], recvBuffer[rank], pos[rank]); 
    834                                 cptEltGeom(recvElt[j], tgtGrid.pole); 
    835                                 Node recvNode(recvElt[j].x, cptRadius(recvElt[j]), &recvElt[j]); 
    836                                 recvNode.search(sstree.localTree.root); 
    837                                 /* for a node holding an element of the target, loop throught candidates for intersecting source */ 
    838                                 for (list<NodePtr>::iterator it = (recvNode.intersectors).begin(); it != (recvNode.intersectors).end(); ++it) 
    839                                 { 
    840                                         Elt *elt2 = (Elt *) ((*it)->data); 
    841                                         /* recvElt is target, elt2 is source */ 
    842 //                                      intersect(&recvElt[j], elt2); 
    843                                         intersect_ym(&recvElt[j], elt2); 
    844                                 } 
    845  
    846                                 if (recvElt[j].is.size() > 0) sentMessageSize[rank] += packIntersectionSize(recvElt[j]); 
    847  
    848                                 // here recvNode goes out of scope 
    849                         } 
    850  
    851                         if (sentMessageSize[rank] > 0) 
    852                         { 
    853                                 sentMessageSize[rank] += sizeof(int); 
    854                                 sendBuffer2[rank] = new char[sentMessageSize[rank]]; 
    855                                 *((int *) sendBuffer2[rank]) = 0; 
    856                                 pos[rank] = sizeof(int); 
    857                                 for (int j = 0; j < nbRecvNode[rank]; j++) 
    858                                 { 
    859                                         packIntersection(recvElt[j], sendBuffer2[rank], pos[rank]); 
    860                                         //FIXME should be deleted: recvElt[j].delete_intersections(); // intersection areas have been packed to buffer and won't be used any more 
    861                                 } 
    862                         } 
    863                         delete [] recvElt; 
    864  
    865                 } 
    866         } 
    867         delete [] pos; 
    868  
    869         for (int rank = 0; rank < mpiSize; rank++) 
    870         { 
    871                 if (nbSendNode[rank] > 0) delete [] sendBuffer[rank]; 
    872                 if (nbRecvNode[rank] > 0) delete [] recvBuffer[rank]; 
    873                 nbSendNode[rank] = 0; 
    874         } 
    875  
    876         if (verbose >= 2) cout << "Rank " << mpiRank << "  Compute (internal) intersection " << cputime() - tic << " s" << endl; 
    877         MPI_Alltoall(sentMessageSize, 1, MPI_INT, recvMessageSize, 1, MPI_INT, communicator); 
    878  
    879         for (int rank = 0; rank < mpiSize; rank++) 
    880                 if (recvMessageSize[rank] > 0) 
    881                         recvBuffer2[rank] = new char[recvMessageSize[rank]]; 
    882  
    883         nbSendRequest = 0; 
    884         nbRecvRequest = 0; 
    885  
    886         for (int rank = 0; rank < mpiSize; rank++) 
    887         { 
    888                 if (sentMessageSize[rank] > 0) 
    889                 { 
    890                         MPI_Issend(sendBuffer2[rank], sentMessageSize[rank], MPI_CHAR, rank, 0, communicator, &sendRequest[nbSendRequest]); 
    891                         nbSendRequest++; 
    892                 } 
    893                 if (recvMessageSize[rank] > 0) 
    894                 { 
    895                         MPI_Irecv(recvBuffer2[rank], recvMessageSize[rank], MPI_CHAR, rank, 0, communicator, &recvRequest[nbRecvRequest]); 
    896                         nbRecvRequest++; 
    897                 } 
    898         } 
    899  
    900         MPI_Waitall(nbRecvRequest, recvRequest, status); 
    901         MPI_Waitall(nbSendRequest, sendRequest, status); 
    902  
    903         delete [] sendRequest; 
    904         delete [] recvRequest; 
    905         delete [] status; 
    906         for (int rank = 0; rank < mpiSize; rank++) 
    907         { 
    908                 if (nbRecvNode[rank] > 0) 
    909                 { 
    910                         if (sentMessageSize[rank] > 0) 
    911                                 delete [] sendBuffer2[rank]; 
    912                 } 
    913  
    914                 if (recvMessageSize[rank] > 0) 
    915                 { 
    916                         unpackIntersection(elements, recvBuffer2[rank]); 
    917                         delete [] recvBuffer2[rank]; 
    918                 } 
    919         } 
    920         delete [] sendBuffer2; 
    921         delete [] recvBuffer2; 
    922         delete [] sendBuffer; 
    923         delete [] recvBuffer; 
    924  
    925         delete [] nbSendNode; 
    926         delete [] nbRecvNode; 
    927         delete [] sentMessageSize; 
    928         delete [] recvMessageSize; 
     726  int mpiSize, mpiRank; 
     727  ep_lib::MPI_Comm_size(communicator, &mpiSize); 
     728  ep_lib::MPI_Comm_rank(communicator, &mpiRank); 
     729 
     730  ep_lib::MPI_Barrier(communicator); 
     731 
     732  vector<Node> *routingList = new vector<Node>[mpiSize]; 
     733 
     734  vector<Node> routeNodes;  routeNodes.reserve(nbElements); 
     735  for (int j = 0; j < nbElements; j++) 
     736  { 
     737    elements[j].id.ind = j; 
     738    elements[j].id.rank = mpiRank; 
     739    routeNodes.push_back(Node(elements[j].x, cptRadius(elements[j]), &elements[j])); 
     740  } 
     741 
     742  vector<vector<int> > routes(routeNodes.size()); 
     743  sstree.routeIntersections(routes, routeNodes); 
     744  for (int i = 0; i < routes.size(); ++i) 
     745    for (int k = 0; k < routes[i].size(); ++k) 
     746      routingList[routes[i][k]].push_back(routeNodes[i]); 
     747 
     748  if (verbose >= 2) 
     749  { 
     750    cout << " --> rank  " << mpiRank << " nbElements " << nbElements << " : "; 
     751    for (int rank = 0; rank < mpiSize; rank++) 
     752      cout << routingList[rank].size() << "   "; 
     753    cout << endl; 
     754  } 
     755  ep_lib::MPI_Barrier(communicator); 
     756 
     757  int *nbSendNode = new int[mpiSize]; 
     758  int *nbRecvNode = new int[mpiSize]; 
     759  int *sentMessageSize = new int[mpiSize]; 
     760  int *recvMessageSize = new int[mpiSize]; 
     761 
     762  for (int rank = 0; rank < mpiSize; rank++) 
     763  { 
     764    nbSendNode[rank] = routingList[rank].size(); 
     765    sentMessageSize[rank] = 0; 
     766    for (size_t j = 0; j < routingList[rank].size(); j++) 
     767    { 
     768      Elt *elt = (Elt *) (routingList[rank][j].data); 
     769      sentMessageSize[rank] += packedPolygonSize(*elt); 
     770    } 
     771  } 
     772 
     773  ep_lib::MPI_Alltoall(nbSendNode, 1, EP_INT, nbRecvNode, 1, EP_INT, communicator); 
     774  ep_lib::MPI_Alltoall(sentMessageSize, 1, EP_INT, recvMessageSize, 1, EP_INT, communicator); 
     775 
     776  int total = 0; 
     777 
     778  for (int rank = 0; rank < mpiSize; rank++) 
     779  { 
     780    total = total + nbRecvNode[rank]; 
     781  } 
     782 
     783  if (verbose >= 2) cout << "---> rank " << mpiRank << " : compute intersection : total received nodes  " << total << endl; 
     784  char **sendBuffer = new char*[mpiSize]; 
     785  char **recvBuffer = new char*[mpiSize]; 
     786  int *pos = new int[mpiSize]; 
     787 
     788  for (int rank = 0; rank < mpiSize; rank++) 
     789  { 
     790    if (nbSendNode[rank] > 0) sendBuffer[rank] = new char[sentMessageSize[rank]]; 
     791    if (nbRecvNode[rank] > 0) recvBuffer[rank] = new char[recvMessageSize[rank]]; 
     792  } 
     793 
     794  for (int rank = 0; rank < mpiSize; rank++) 
     795  { 
     796    pos[rank] = 0; 
     797    for (size_t j = 0; j < routingList[rank].size(); j++) 
     798    { 
     799      Elt* elt = (Elt *) (routingList[rank][j].data); 
     800      packPolygon(*elt, sendBuffer[rank], pos[rank]); 
     801    } 
     802  } 
     803  delete [] routingList; 
     804 
     805  int nbSendRequest = 0; 
     806  int nbRecvRequest = 0; 
     807  ep_lib::MPI_Request *sendRequest = new ep_lib::MPI_Request[mpiSize]; 
     808  ep_lib::MPI_Request *recvRequest = new ep_lib::MPI_Request[mpiSize]; 
     809  ep_lib::MPI_Status   *status = new ep_lib::MPI_Status[mpiSize]; 
     810 
     811  for (int rank = 0; rank < mpiSize; rank++) 
     812  { 
     813    if (nbSendNode[rank] > 0) 
     814    { 
     815      ep_lib::MPI_Issend(sendBuffer[rank], sentMessageSize[rank], EP_CHAR, rank, 0, communicator, &sendRequest[nbSendRequest]); 
     816      nbSendRequest++; 
     817    } 
     818    if (nbRecvNode[rank] > 0) 
     819    { 
     820      ep_lib::MPI_Irecv(recvBuffer[rank], recvMessageSize[rank], EP_CHAR, rank, 0, communicator, &recvRequest[nbRecvRequest]); 
     821      nbRecvRequest++; 
     822    } 
     823  } 
     824 
     825  ep_lib::MPI_Waitall(nbRecvRequest, recvRequest, status); 
     826  ep_lib::MPI_Waitall(nbSendRequest, sendRequest, status); 
     827  char **sendBuffer2 = new char*[mpiSize]; 
     828  char **recvBuffer2 = new char*[mpiSize]; 
     829 
     830  double tic = cputime(); 
     831  for (int rank = 0; rank < mpiSize; rank++) 
     832  { 
     833    sentMessageSize[rank] = 0; 
     834 
     835    if (nbRecvNode[rank] > 0) 
     836    { 
     837      Elt *recvElt = new Elt[nbRecvNode[rank]]; 
     838      pos[rank] = 0; 
     839      for (int j = 0; j < nbRecvNode[rank]; j++) 
     840      { 
     841        unpackPolygon(recvElt[j], recvBuffer[rank], pos[rank]); 
     842        cptEltGeom(recvElt[j], tgtGrid.pole); 
     843        Node recvNode(recvElt[j].x, cptRadius(recvElt[j]), &recvElt[j]); 
     844        recvNode.search(sstree.localTree.root); 
     845        /* for a node holding an element of the target, loop throught candidates for intersecting source */ 
     846        for (list<NodePtr>::iterator it = (recvNode.intersectors).begin(); it != (recvNode.intersectors).end(); ++it) 
     847        { 
     848          Elt *elt2 = (Elt *) ((*it)->data); 
     849          /* recvElt is target, elt2 is source */ 
     850//          intersect(&recvElt[j], elt2); 
     851          intersect_ym(&recvElt[j], elt2); 
     852        } 
     853 
     854        if (recvElt[j].is.size() > 0) sentMessageSize[rank] += packIntersectionSize(recvElt[j]); 
     855 
     856        // here recvNode goes out of scope 
     857      } 
     858 
     859      if (sentMessageSize[rank] > 0) 
     860      { 
     861        sentMessageSize[rank] += sizeof(int); 
     862        sendBuffer2[rank] = new char[sentMessageSize[rank]]; 
     863        *((int *) sendBuffer2[rank]) = 0; 
     864        pos[rank] = sizeof(int); 
     865        for (int j = 0; j < nbRecvNode[rank]; j++) 
     866        { 
     867          packIntersection(recvElt[j], sendBuffer2[rank], pos[rank]); 
     868          //FIXME should be deleted: recvElt[j].delete_intersections(); // intersection areas have been packed to buffer and won't be used any more 
     869        } 
     870      } 
     871      delete [] recvElt; 
     872 
     873    } 
     874  } 
     875  delete [] pos; 
     876 
     877  for (int rank = 0; rank < mpiSize; rank++) 
     878  { 
     879    if (nbSendNode[rank] > 0) delete [] sendBuffer[rank]; 
     880    if (nbRecvNode[rank] > 0) delete [] recvBuffer[rank]; 
     881    nbSendNode[rank] = 0; 
     882  } 
     883 
     884  if (verbose >= 2) cout << "Rank " << mpiRank << "  Compute (internal) intersection " << cputime() - tic << " s" << endl; 
     885  ep_lib::MPI_Alltoall(sentMessageSize, 1, EP_INT, recvMessageSize, 1, EP_INT, communicator); 
     886 
     887  for (int rank = 0; rank < mpiSize; rank++) 
     888    if (recvMessageSize[rank] > 0) 
     889      recvBuffer2[rank] = new char[recvMessageSize[rank]]; 
     890 
     891  nbSendRequest = 0; 
     892  nbRecvRequest = 0; 
     893 
     894  for (int rank = 0; rank < mpiSize; rank++) 
     895  { 
     896    if (sentMessageSize[rank] > 0) 
     897    { 
     898      ep_lib::MPI_Issend(sendBuffer2[rank], sentMessageSize[rank], EP_CHAR, rank, 0, communicator, &sendRequest[nbSendRequest]); 
     899      nbSendRequest++; 
     900    } 
     901    if (recvMessageSize[rank] > 0) 
     902    { 
     903      ep_lib::MPI_Irecv(recvBuffer2[rank], recvMessageSize[rank], EP_CHAR, rank, 0, communicator, &recvRequest[nbRecvRequest]); 
     904      nbRecvRequest++; 
     905    } 
     906  } 
     907 
     908  ep_lib::MPI_Waitall(nbRecvRequest, recvRequest, status); 
     909  ep_lib::MPI_Waitall(nbSendRequest, sendRequest, status); 
     910 
     911  delete [] sendRequest; 
     912  delete [] recvRequest; 
     913  delete [] status; 
     914  for (int rank = 0; rank < mpiSize; rank++) 
     915  { 
     916    if (nbRecvNode[rank] > 0) 
     917    { 
     918      if (sentMessageSize[rank] > 0) 
     919        delete [] sendBuffer2[rank]; 
     920    } 
     921 
     922    if (recvMessageSize[rank] > 0) 
     923    { 
     924      unpackIntersection(elements, recvBuffer2[rank]); 
     925      delete [] recvBuffer2[rank]; 
     926    } 
     927  } 
     928  delete [] sendBuffer2; 
     929  delete [] recvBuffer2; 
     930  delete [] sendBuffer; 
     931  delete [] recvBuffer; 
     932 
     933  delete [] nbSendNode; 
     934  delete [] nbRecvNode; 
     935  delete [] sentMessageSize; 
     936  delete [] recvMessageSize; 
    929937} 
    930938 
    931939Mapper::~Mapper() 
    932940{ 
    933         delete [] remapMatrix; 
    934         delete [] srcAddress; 
    935         delete [] srcRank; 
    936         delete [] dstAddress; 
    937         if (neighbourElements) delete [] neighbourElements; 
    938 } 
    939  
    940 } 
     941  delete [] remapMatrix; 
     942  delete [] srcAddress; 
     943  delete [] srcRank; 
     944  delete [] dstAddress; 
     945  if (neighbourElements) delete [] neighbourElements; 
     946} 
     947 
     948} 
  • XIOS/dev/branch_openmp/extern/remap/src/mapper.hpp

    r1538 r1642  
    1818{ 
    1919public: 
    20        Mapper(ep_lib::MPI_Comm comm) : communicator(comm), verbose(SILENT), neighbourElements(NULL), sstree(comm) {} 
    21  
     20       Mapper(ep_lib::MPI_Comm comm=EP_COMM_WORLD) : communicator(comm), verbose(SILENT), neighbourElements(NULL), sstree(comm) {} 
    2221       ~Mapper(); 
    2322       void setVerbosity(verbosity v) {verbose=v ;} 
    2423 
    25        void setSourceMesh(const double* boundsLon, const double* boundsLat, int nVertex, int nbCells, const double* pole, const long int* globalId=NULL) ; 
    26        void setTargetMesh(const double* boundsLon, const double* boundsLat, int nVertex, int nbCells, const double* pole, const long int* globalId=NULL) ; 
     24       void setSourceMesh(const double* boundsLon, const double* boundsLat, const double* area, int nVertex, int nbCells, const double* pole, const long int* globalId=NULL) ; 
     25       void setTargetMesh(const double* boundsLon, const double* boundsLat, const double* area, int nVertex, int nbCells, const double* pole, const long int* globalId=NULL) ; 
    2726       void setSourceValue(const double* val) ; 
    2827       void getTargetValue(double* val) ; 
  • XIOS/dev/branch_openmp/extern/remap/src/meshutil.cpp

    r877 r1642  
    22#include "elt.hpp" 
    33#include "polyg.hpp" 
     4#include "intersection_ym.hpp" 
     5#include "earcut.hpp" 
     6#include <vector> 
    47 
    58namespace sphereRemap { 
    69 
    710using namespace std; 
     11 
     12double computePolygoneArea(Elt& a, const Coord &pole) 
     13{ 
     14  using N = uint32_t; 
     15  using Point = array<double, 2>; 
     16  vector<Point> vect_points; 
     17  vector< vector<Point> > polyline; 
     18   
     19  vector<Coord> dstPolygon ; 
     20  createGreatCirclePolygon(a, pole, dstPolygon) ; 
     21 
     22  int na=dstPolygon.size() ; 
     23  Coord *a_gno   = new Coord[na]; 
     24   
     25  Coord OC=barycentre(a.vertex,a.n) ; 
     26  Coord Oz=OC ; 
     27  Coord Ox=crossprod(Coord(0,0,1),Oz) ; 
     28// choose Ox not too small to avoid rounding error 
     29  if (norm(Ox)< 0.1) Ox=crossprod(Coord(0,1,0),Oz) ; 
     30  Ox=Ox*(1./norm(Ox)) ; 
     31  Coord Oy=crossprod(Oz,Ox) ; 
     32  double cos_alpha; 
     33 
     34  for(int n=0; n<na;n++) 
     35  { 
     36    cos_alpha=scalarprod(OC,dstPolygon[n]) ; 
     37    a_gno[n].x=scalarprod(dstPolygon[n],Ox)/cos_alpha ; 
     38    a_gno[n].y=scalarprod(dstPolygon[n],Oy)/cos_alpha ; 
     39    a_gno[n].z=scalarprod(dstPolygon[n],Oz)/cos_alpha ; // must be equal to 1 
     40 
     41    vect_points.push_back( array<double, 2>() ); 
     42    vect_points[n][0] = a_gno[n].x; 
     43    vect_points[n][1] = a_gno[n].y; 
     44 
     45  } 
     46 
     47  polyline.push_back(vect_points); 
     48  vector<N> indices_a_gno = mapbox::earcut<N>(polyline); 
     49   
     50  double area_a_gno=0 ; 
     51  for(int i=0;i<indices_a_gno.size()/3;++i) 
     52    { 
     53      Coord x0 = Ox * polyline[0][indices_a_gno[3*i]][0] + Oy* polyline[0][indices_a_gno[3*i]][1] + Oz ; 
     54      Coord x1 = Ox * polyline[0][indices_a_gno[3*i+1]][0] + Oy* polyline[0][indices_a_gno[3*i+1]][1] + Oz ; 
     55      Coord x2 = Ox * polyline[0][indices_a_gno[3*i+2]][0] + Oy* polyline[0][indices_a_gno[3*i+2]][1] + Oz ; 
     56      area_a_gno+=triarea(x0 * (1./norm(x0)),x1* (1./norm(x1)), x2* (1./norm(x2))) ; 
     57    } 
     58 
     59  vect_points.clear(); 
     60  polyline.clear(); 
     61  indices_a_gno.clear(); 
     62  return area_a_gno ; 
     63} 
     64 
    865 
    966void cptEltGeom(Elt& elt, const Coord &pole) 
     
    1471  elt.area = airbar(elt.n, elt.vertex, elt.edge, elt.d, pole, gg); 
    1572  elt.x = gg; 
    16 } 
     73// overwrite area computation  
     74 
     75  elt.area =  computePolygoneArea(elt, pole) ; 
     76} 
     77 
    1778 
    1879void cptAllEltsGeom(Elt *elt, int N, const Coord &pole) 
     
    133194  { 
    134195    for (int i = 0; i < elts[j]->n; i++)  
    135       if ( elts[j]->neighbour[i]== NOT_FOUND) neighbours[i]=NULL ; 
     196      if ( elts[j]->neighbour[i]== NOT_FOUND) neighbours[i]=NULL ; // no neighbour 
     197      else if (elts[elts[j]->neighbour[i]]->is.size() == 0) neighbours[i]=NULL ; // neighbour has none supermesh cell  
    136198      else  neighbours[i] = elts[elts[j]->neighbour[i]]; 
    137199 
  • XIOS/dev/branch_openmp/extern/remap/src/mpi_cascade.cpp

    r1328 r1642  
    11#include "mpi_cascade.hpp" 
    22#include <iostream> 
    3 using namespace ep_lib; 
    43 
    54namespace sphereRemap { 
    65 
    7 CMPICascade::CMPICascade(int nodes_per_level, MPI_Comm comm) 
     6CMPICascade::CMPICascade(int nodes_per_level, ep_lib::MPI_Comm comm) 
    87{ 
    98        int remaining_levels; 
    10         MPI_Comm intraComm; 
     9        ep_lib::MPI_Comm intraComm; 
    1110        int l = 0; // current level 
    1211        do { 
     
    1615                level[l].p_grp_size = level[l].size/level[l].group_size; 
    1716         
    18                 MPI_Comm_split(comm, level[l].colour(), level[l].key(), &intraComm); 
    19                 MPI_Comm_split(comm, level[l].p_colour(), level[l].p_key(), &(level[l].pg_comm)); 
     17                ep_lib::MPI_Comm_split(comm, level[l].colour(), level[l].key(), &intraComm); 
     18                ep_lib::MPI_Comm_split(comm, level[l].p_colour(), level[l].p_key(), &(level[l].pg_comm)); 
    2019                comm = intraComm; 
    2120                l++; 
  • XIOS/dev/branch_openmp/extern/remap/src/mpi_cascade.hpp

    r1538 r1642  
    1212{ 
    1313public: 
    14   CCascadeLevel(ep_lib::MPI_Comm comm) : comm(comm) 
    15   { 
    16     ep_lib::MPI_Comm_size(comm, &size); 
    17     ep_lib::MPI_Comm_rank(comm, &rank); 
    18   } 
    19   int colour() const { return rank % group_size; }; 
    20   int key() const { return p_colour() + rank/(p_grp_size*group_size)*p_grp_size; } 
     14        CCascadeLevel(ep_lib::MPI_Comm comm) : comm(comm) 
     15        { 
     16                ep_lib::MPI_Comm_size(comm, &size); 
     17                ep_lib::MPI_Comm_rank(comm, &rank); 
     18        } 
     19        int colour() const { return rank % group_size; }; 
     20        int key() const { return p_colour() + rank/(p_grp_size*group_size)*p_grp_size; } 
    2121 
    22   // perpendicular group 
    23   int p_colour() const { return (rank%group_size + rank/group_size) % p_grp_size; } 
    24   int p_key() const { return colour() + rank/(p_grp_size*group_size)*group_size; } 
     22        // perpendicular group 
     23        int p_colour() const { return (rank%group_size + rank/group_size) % p_grp_size; } 
     24        int p_key() const { return colour() + rank/(p_grp_size*group_size)*group_size; } 
    2525 
    26   ep_lib::MPI_Comm comm, pg_comm; 
    27   int rank; 
    28   int size; 
    29   int group_size; // group_size and p_grp_size are interchanged?? FIXME 
    30   int p_grp_size; 
     26        ep_lib::MPI_Comm comm, pg_comm; 
     27        int rank; 
     28        int size; 
     29        int group_size; // group_size and p_grp_size are interchanged?? FIXME 
     30        int p_grp_size; 
    3131}; 
    3232 
     
    3434{ 
    3535public: 
    36   CMPICascade(int nodes_per_level, ep_lib::MPI_Comm comm); 
     36        //  
     37        CMPICascade(int nodes_per_level, ep_lib::MPI_Comm comm); 
    3738 
    38   int num_levels; 
    39   std::vector<CCascadeLevel> level; 
     39        int num_levels; 
     40        std::vector<CCascadeLevel> level; 
    4041}; 
    4142 
  • XIOS/dev/branch_openmp/extern/remap/src/mpi_routing.cpp

    r1362 r1642  
    55#include "timerRemap.hpp" 
    66#include <iostream> 
    7 using namespace ep_lib; 
    87 
    98namespace sphereRemap { 
     
    1110const int verbose = 0; 
    1211 
    13 CMPIRouting::CMPIRouting(MPI_Comm comm) : communicator(comm) 
    14 { 
    15         MPI_Comm_rank(comm, &mpiRank); 
    16         MPI_Comm_size(comm, &mpiSize); 
     12CMPIRouting::CMPIRouting(ep_lib::MPI_Comm comm) : communicator(comm) 
     13{ 
     14        ep_lib::MPI_Comm_rank(comm, &mpiRank); 
     15        ep_lib::MPI_Comm_size(comm, &mpiSize); 
    1716} 
    1817 
     
    2019    but message lengths are *known* to receiver */ 
    2120template <typename T> 
    22 void alltoalls_known(const vector<vector<T> >& send, vector<vector<T> >& recv, const vector<int>& ranks, MPI_Comm communicator) 
    23 { 
    24         vector<MPI_Request> request(ranks.size() * 2); 
    25         vector<MPI_Status>  status(ranks.size() * 2); 
     21void alltoalls_known(const vector<vector<T> >& send, vector<vector<T> >& recv, const vector<int>& ranks, ep_lib::MPI_Comm communicator) 
     22{ 
     23        vector<ep_lib::MPI_Request> request(ranks.size() * 2); 
     24        vector<ep_lib::MPI_Status>  status(ranks.size() * 2); 
    2625 
    2726        // communicate data 
     
    2928        for (int i = 0; i < ranks.size(); i++) 
    3029                if (recv[i].size()) 
    31                         MPI_Irecv(&recv[i][0], recv[i].size()*sizeof(T), MPI_CHAR, ranks[i], 0, communicator, &request[nbRequest++]); 
     30                        ep_lib::MPI_Irecv(&recv[i][0], recv[i].size()*sizeof(T), EP_CHAR, ranks[i], 0, communicator, &request[nbRequest++]); 
    3231        for (int i = 0; i < ranks.size(); i++) 
    3332                if (send[i].size()) 
    34                         MPI_Isend((void *) &send[i][0], send[i].size()*sizeof(T), MPI_CHAR, ranks[i], 0, communicator, &request[nbRequest++]); 
    35         MPI_Waitall(nbRequest, &request[0], &status[0]); 
     33                        ep_lib::MPI_Isend((void *) &send[i][0], send[i].size()*sizeof(T), EP_CHAR, ranks[i], 0, communicator, &request[nbRequest++]); 
     34        ep_lib::MPI_Waitall(nbRequest, &request[0], &status[0]); 
    3635} 
    3736 
     
    3938    but message lengths are *unknown* to receiver */ 
    4039template <typename T> 
    41 void alltoalls_unknown(const vector<vector<T> >& send, vector<vector<T> >& recv, const vector<int>& ranks, MPI_Comm communicator) 
    42 { 
    43         vector<MPI_Request> request(ranks.size() * 2); 
    44         vector<MPI_Status>  status(ranks.size() * 2); 
     40void alltoalls_unknown(const vector<vector<T> >& send, vector<vector<T> >& recv, const vector<int>& ranks, ep_lib::MPI_Comm communicator) 
     41{ 
     42        vector<ep_lib::MPI_Request> request(ranks.size() * 2); 
     43        vector<ep_lib::MPI_Status>  status(ranks.size() * 2); 
    4544 
    4645        // communicate sizes 
     
    5150                sendSizes[i] = send[i].size(); 
    5251        for (int i = 0; i < ranks.size(); i++) 
    53                 MPI_Irecv(&recvSizes[i], 1, MPI_INT, ranks[i], 0, communicator, &request[nbRequest++]); 
     52                ep_lib::MPI_Irecv(&recvSizes[i], 1, EP_INT, ranks[i], 0, communicator, &request[nbRequest++]); 
    5453        for (int i = 0; i < ranks.size(); i++) 
    55                 MPI_Isend(&sendSizes[i], 1, MPI_INT, ranks[i], 0, communicator, &request[nbRequest++]); 
    56         MPI_Waitall(nbRequest, &request[0], &status[0]); 
     54                ep_lib::MPI_Isend(&sendSizes[i], 1, EP_INT, ranks[i], 0, communicator, &request[nbRequest++]); 
     55        ep_lib::MPI_Waitall(nbRequest, &request[0], &status[0]); 
    5756 
    5857        // allocate 
     
    119118        CTimer::get("CMPIRouting::init(reduce_scatter)").reset(); 
    120119        CTimer::get("CMPIRouting::init(reduce_scatter)").resume(); 
    121         MPI_Reduce_scatter(toSend, &nbSource, recvCount, MPI_INT, MPI_SUM, communicator); 
     120        ep_lib::MPI_Reduce_scatter(toSend, &nbSource, recvCount, EP_INT, EP_SUM, communicator); 
    122121        CTimer::get("CMPIRouting::init(reduce_scatter)").suspend(); 
    123122        CTimer::get("CMPIRouting::init(reduce_scatter)").print(); 
    124123 
    125         MPI_Alloc_mem(nbTarget *sizeof(int), MPI_INFO_NULL, &targetRank); 
    126         MPI_Alloc_mem(nbSource *sizeof(int), MPI_INFO_NULL, &sourceRank); 
     124        ep_lib::MPI_Alloc_mem(nbTarget *sizeof(int), EP_INFO_NULL, &targetRank); 
     125        ep_lib::MPI_Alloc_mem(nbSource *sizeof(int), EP_INFO_NULL, &sourceRank); 
    127126 
    128127        targetRankToIndex = new int[mpiSize]; 
     
    138137        } 
    139138 
    140         MPI_Barrier(communicator); 
     139        ep_lib::MPI_Barrier(communicator); 
    141140        CTimer::get("CMPIRouting::init(get_source)").reset(); 
    142141        CTimer::get("CMPIRouting::init(get_source)").resume(); 
    143142 
    144         MPI_Request *request = new MPI_Request[nbSource + nbTarget]; 
    145         MPI_Status  *status = new MPI_Status[nbSource + nbTarget]; 
     143        ep_lib::MPI_Request *request = new ep_lib::MPI_Request[nbSource + nbTarget]; 
     144        ep_lib::MPI_Status  *status = new ep_lib::MPI_Status[nbSource + nbTarget]; 
    146145 
    147146        int indexRequest = 0; 
     
    151150        for (int i = 0; i < nbSource; i++) 
    152151        { 
    153                 #ifdef _usingEP 
    154                 MPI_Irecv(&sourceRank[i], 1, MPI_INT, -2, 0, communicator, &request[indexRequest++]); 
    155                 #else 
    156                 MPI_Irecv(&sourceRank[i], 1, MPI_INT, MPI_ANY_SOURCE, 0, communicator, &request[indexRequest++]); 
     152                #ifdef _usingMPI 
     153                ep_lib::MPI_Irecv(&sourceRank[i], 1, EP_INT, MPI_ANY_SOURCE, 0, communicator, &request[indexRequest]); 
     154                #elif _usingEP 
     155                ep_lib::MPI_Irecv(&sourceRank[i], 1, EP_INT, -2, 0, communicator, &request[indexRequest]); 
    157156                #endif 
     157                indexRequest++; 
    158158        } 
    159159        MPI_Barrier(communicator); 
    160160        for (int i = 0; i < nbTarget; i++) 
    161161        { 
    162                 MPI_Isend(&mpiRank, 1, MPI_INT, targetRank[i], 0, communicator, &request[indexRequest++]); 
     162                ep_lib::MPI_Isend(&mpiRank, 1, EP_INT, targetRank[i], 0, communicator, &request[indexRequest]); 
     163                indexRequest++; 
    163164        } 
    164165        MPI_Waitall(indexRequest, request, status); 
     
    173174        for (int i = 0; i < nbSource; i++) 
    174175        { 
    175                 #ifdef _usingEP 
    176                 MPI_Irecv(&sourceRank[i], 1, MPI_INT, -2, 0, communicator, &request[indexRequest]); 
    177                 #else 
    178                 MPI_Irecv(&sourceRank[i], 1, MPI_INT, MPI_ANY_SOURCE, 0, communicator, &request[indexRequest]); 
     176                #ifdef _usingMPI 
     177                ep_lib::MPI_Irecv(&sourceRank[i], 1, EP_INT, MPI_ANY_SOURCE, 0, communicator, &request[indexRequest]); 
     178                #elif _usingEP 
     179                ep_lib::MPI_Irecv(&sourceRank[i], 1, EP_INT, -2, 0, communicator, &request[indexRequest]); 
    179180                #endif 
    180                 indexRequest++; 
    181         } 
    182  
    183         for (int i = 0; i < nbTarget; i++) 
    184         { 
    185                 MPI_Isend(&mpiRank, 1, MPI_INT, targetRank[i], 0, communicator, &request[indexRequest]); 
     181                indexRequest++; 
     182        } 
     183 
     184        for (int i = 0; i < nbTarget; i++) 
     185        { 
     186                ep_lib::MPI_Isend(&mpiRank, 1, EP_INT, targetRank[i], 0, communicator, &request[indexRequest]); 
    186187                indexRequest++; 
    187188        } 
     
    208209        for (int i = 0; i < nbSource; i++) 
    209210        { 
    210                 MPI_Irecv(&nbSourceElement[i], 1, MPI_INT, sourceRank[i], 0, communicator, &request[indexRequest]); 
     211                ep_lib::MPI_Irecv(&nbSourceElement[i], 1, EP_INT, sourceRank[i], 0, communicator, &request[indexRequest]); 
    211212                indexRequest++; 
    212213        } 
     
    215216        { 
    216217                totalTargetElement += nbTargetElement[i]; 
    217                 MPI_Isend(&nbTargetElement[i], 1, MPI_INT, targetRank[i], 0, communicator, &request[indexRequest]); 
     218                ep_lib::MPI_Isend(&nbTargetElement[i], 1, EP_INT, targetRank[i], 0, communicator, &request[indexRequest]); 
    218219                indexRequest++; 
    219220        } 
     
    283284 
    284285 
    285         MPI_Request* request=new MPI_Request[nbSource+nbTarget]; 
    286         MPI_Status*  status=new MPI_Status[nbSource+nbTarget]; 
     286        ep_lib::MPI_Request* request=new ep_lib::MPI_Request[nbSource+nbTarget]; 
     287        ep_lib::MPI_Status*  status=new ep_lib::MPI_Status[nbSource+nbTarget]; 
    287288        int indexRequest=0; 
    288289 
    289         MPI_Barrier(communicator); 
     290        ep_lib::MPI_Barrier(communicator); 
    290291        CTimer::get("CMPIRouting::transferToTarget").reset(); 
    291292        CTimer::get("CMPIRouting::transferToTarget").resume(); 
     
    293294        for(int i=0; i<nbSource; i++) 
    294295        { 
    295                 MPI_Irecv(sourceBuffer[i],nbSourceElement[i]*sizeof(T),MPI_CHAR, sourceRank[i], 0, communicator, &request[indexRequest]); 
     296                ep_lib::MPI_Irecv(sourceBuffer[i],nbSourceElement[i]*sizeof(T),EP_CHAR, sourceRank[i], 0, communicator, &request[indexRequest]); 
    296297                indexRequest++; 
    297298        } 
     
    299300        for(int i=0;i<nbTarget; i++) 
    300301        { 
    301                 MPI_Isend(targetBuffer[i],nbTargetElement[i]*sizeof(T), MPI_CHAR, targetRank[i], 0, communicator, &request[indexRequest]); 
    302                 indexRequest++; 
    303         } 
    304  
    305         MPI_Waitall(indexRequest,request,status); 
     302                ep_lib::MPI_Isend(targetBuffer[i],nbTargetElement[i]*sizeof(T), EP_CHAR, targetRank[i], 0, communicator, &request[indexRequest]); 
     303                indexRequest++; 
     304        } 
     305 
     306        ep_lib::MPI_Waitall(indexRequest,request,status); 
    306307 
    307308        CTimer::get("CMPIRouting::transferToTarget").suspend(); 
    308309        CTimer::get("CMPIRouting::transferToTarget").print(); 
    309         MPI_Barrier(communicator); 
     310        ep_lib::MPI_Barrier(communicator); 
    310311 
    311312        // unpack the data 
     
    347348        } 
    348349 
    349         MPI_Request *request = new MPI_Request[nbSource + nbTarget]; 
    350         MPI_Status  *status = new MPI_Status[nbSource + nbTarget]; 
     350        ep_lib::MPI_Request *request = new ep_lib::MPI_Request[nbSource + nbTarget]; 
     351        ep_lib::MPI_Status  *status = new ep_lib::MPI_Status[nbSource + nbTarget]; 
    351352        int indexRequest = 0; 
    352353 
    353         MPI_Barrier(communicator); 
     354        ep_lib::MPI_Barrier(communicator); 
    354355        CTimer::get("CMPIRouting::transferToTarget(messageSize)").reset(); 
    355356        CTimer::get("CMPIRouting::transferToTarget(messageSize)").resume(); 
     
    357358        for(int i=0; i<nbSource; i++) 
    358359        { 
    359                 MPI_Irecv(&sourceMessageSize[i],1,MPI_INT, sourceRank[i], 0, communicator, &request[indexRequest]); 
     360                ep_lib::MPI_Irecv(&sourceMessageSize[i],1,EP_INT, sourceRank[i], 0, communicator, &request[indexRequest]); 
    360361                indexRequest++; 
    361362        } 
     
    363364        for(int i=0; i<nbTarget; i++) 
    364365        { 
    365                 MPI_Isend(&targetMessageSize[i],1, MPI_INT, targetRank[i], 0, communicator, &request[indexRequest]); 
    366                 indexRequest++; 
    367         } 
    368  
    369         MPI_Waitall(indexRequest,request,status); 
    370  
    371         MPI_Barrier(communicator); 
     366                ep_lib::MPI_Isend(&targetMessageSize[i],1, EP_INT, targetRank[i], 0, communicator, &request[indexRequest]); 
     367                indexRequest++; 
     368        } 
     369 
     370        ep_lib::MPI_Waitall(indexRequest,request,status); 
     371 
     372        ep_lib::MPI_Barrier(communicator); 
    372373        CTimer::get("CMPIRouting::transferToTarget(messageSize)").suspend(); 
    373374        CTimer::get("CMPIRouting::transferToTarget(messageSize)").print(); 
     
    402403        for(int i=0; i<nbSource; i++) 
    403404        { 
    404                 MPI_Irecv(sourceBuffer[i],sourceMessageSize[i],MPI_CHAR, sourceRank[i], 0, communicator, &request[indexRequest]); 
     405                ep_lib::MPI_Irecv(sourceBuffer[i],sourceMessageSize[i],EP_CHAR, sourceRank[i], 0, communicator, &request[indexRequest]); 
    405406                indexRequest++; 
    406407        } 
     
    408409        for(int i=0;i<nbTarget; i++) 
    409410        { 
    410                 MPI_Isend(targetBuffer[i],targetMessageSize[i], MPI_CHAR, targetRank[i], 0, communicator, &request[indexRequest]); 
     411                ep_lib::MPI_Isend(targetBuffer[i],targetMessageSize[i], EP_CHAR, targetRank[i], 0, communicator, &request[indexRequest]); 
    411412                indexRequest++; 
    412413        } 
     
    467468        } 
    468469 
    469         MPI_Request* request=new MPI_Request[nbSource+nbTarget]; 
    470         MPI_Status*  status=new MPI_Status[nbSource+nbTarget]; 
     470        ep_lib::MPI_Request* request=new ep_lib::MPI_Request[nbSource+nbTarget]; 
     471        ep_lib::MPI_Status*  status=new ep_lib::MPI_Status[nbSource+nbTarget]; 
    471472        int indexRequest=0; 
    472473 
    473474        for(int i=0; i<nbSource; i++) 
    474475        { 
    475                 MPI_Isend(sourceBuffer[i],nbSourceElement[i]*sizeof(T),MPI_CHAR, sourceRank[i], 0, communicator, &request[indexRequest]); 
     476                ep_lib::MPI_Isend(sourceBuffer[i],nbSourceElement[i]*sizeof(T),EP_CHAR, sourceRank[i], 0, communicator, &request[indexRequest]); 
    476477                indexRequest++; 
    477478        } 
     
    479480        for(int i=0;i<nbTarget; i++) 
    480481        { 
    481                 MPI_Irecv(targetBuffer[i],nbTargetElement[i]*sizeof(T), MPI_CHAR, targetRank[i], 0, communicator, &request[indexRequest]); 
    482                 indexRequest++; 
    483         } 
    484  
    485         MPI_Waitall(indexRequest,request,status); 
     482                ep_lib::MPI_Irecv(targetBuffer[i],nbTargetElement[i]*sizeof(T), EP_CHAR, targetRank[i], 0, communicator, &request[indexRequest]); 
     483                indexRequest++; 
     484        } 
     485 
     486        ep_lib::MPI_Waitall(indexRequest,request,status); 
    486487 
    487488        // unpack the data 
     
    523524        } 
    524525 
    525         MPI_Request *request = new MPI_Request[nbSource + nbTarget]; 
    526         MPI_Status  *status = new MPI_Status[nbSource + nbTarget]; 
     526        ep_lib::MPI_Request *request = new ep_lib::MPI_Request[nbSource + nbTarget]; 
     527        ep_lib::MPI_Status  *status = new ep_lib::MPI_Status[nbSource + nbTarget]; 
    527528        int indexRequest = 0; 
    528529        for (int i = 0; i < nbSource; i++) 
    529530        { 
    530                 MPI_Isend(&sourceMessageSize[i], 1, MPI_INT, sourceRank[i], 0, communicator, &request[indexRequest]); 
    531                 indexRequest++; 
    532         } 
    533         for (int i = 0; i < nbTarget; i++) 
    534         { 
    535                 MPI_Irecv(&targetMessageSize[i], 1, MPI_INT, targetRank[i], 0, communicator, &request[indexRequest]); 
    536                 indexRequest++; 
    537         } 
    538         MPI_Waitall(indexRequest, request, status); 
     531                ep_lib::MPI_Isend(&sourceMessageSize[i], 1, EP_INT, sourceRank[i], 0, communicator, &request[indexRequest]); 
     532                indexRequest++; 
     533        } 
     534        for (int i = 0; i < nbTarget; i++) 
     535        { 
     536                ep_lib::MPI_Irecv(&targetMessageSize[i], 1, EP_INT, targetRank[i], 0, communicator, &request[indexRequest]); 
     537                indexRequest++; 
     538        } 
     539        ep_lib::MPI_Waitall(indexRequest, request, status); 
    539540 
    540541        for (int i = 0; i < nbTarget; i++) 
     
    564565        for (int i = 0; i < nbSource; i++) 
    565566        { 
    566                 MPI_Isend(sourceBuffer[i], sourceMessageSize[i], MPI_CHAR, sourceRank[i], 0, communicator, &request[indexRequest]); 
    567                 indexRequest++; 
    568         } 
    569         for (int i = 0; i < nbTarget; i++) 
    570         { 
    571                 MPI_Irecv(targetBuffer[i], targetMessageSize[i], MPI_CHAR, targetRank[i], 0, communicator, &request[indexRequest]); 
    572                 indexRequest++; 
    573         } 
    574         MPI_Waitall(indexRequest, request, status); 
     567                ep_lib::MPI_Isend(sourceBuffer[i], sourceMessageSize[i], EP_CHAR, sourceRank[i], 0, communicator, &request[indexRequest]); 
     568                indexRequest++; 
     569        } 
     570        for (int i = 0; i < nbTarget; i++) 
     571        { 
     572                ep_lib::MPI_Irecv(targetBuffer[i], targetMessageSize[i], EP_CHAR, targetRank[i], 0, communicator, &request[indexRequest]); 
     573                indexRequest++; 
     574        } 
     575        ep_lib::MPI_Waitall(indexRequest, request, status); 
    575576 
    576577        // unpack the data 
     
    612613 
    613614template void alltoalls_unknown(const std::vector<std::vector<NES> >& send, std::vector<std::vector<NES> >& recv, 
    614                                 const std::vector<int>& ranks, MPI_Comm communicator); 
     615                                const std::vector<int>& ranks, ep_lib::MPI_Comm communicator); 
    615616 
    616617template void alltoalls_known(const std::vector<std::vector<int> >& send, std::vector<std::vector<int> >& recv, 
    617                               const std::vector<int>& ranks, MPI_Comm communicator); 
    618  
    619 } 
     618                              const std::vector<int>& ranks, ep_lib::MPI_Comm communicator); 
     619 
     620} 
  • XIOS/dev/branch_openmp/extern/remap/src/parallel_tree.cpp

    r1545 r1642  
    1212 
    1313#include "parallel_tree.hpp" 
    14 using namespace ep_lib; 
    1514 
    1615namespace sphereRemap { 
    17  
    18 extern CRemapGrid srcGrid; 
    19 #pragma omp threadprivate(srcGrid) 
    20  
    21 extern CRemapGrid tgtGrid; 
    22 #pragma omp threadprivate(tgtGrid) 
    2316 
    2417static const int assignLevel = 2; 
     
    121114} 
    122115 
    123 CParallelTree::CParallelTree(MPI_Comm comm) : communicator(comm), cascade(MIN_NODE_SZ*MIN_NODE_SZ*2, comm) 
    124 { 
    125   treeCascade.reserve(cascade.num_levels); 
    126   for (int lev = 0; lev < cascade.num_levels; lev++) 
    127     treeCascade.push_back(CSampleTree(cascade.level[lev].group_size, assignLevel)); 
     116//CParallelTree::CParallelTree(MPI_Comm comm) : communicator(comm), cascade(MIN_NODE_SZ*MIN_NODE_SZ, comm) 
     117CParallelTree::CParallelTree(ep_lib::MPI_Comm comm) : communicator(comm), cascade(MAX_NODE_SZ*MAX_NODE_SZ*2, comm) 
     118{ 
     119        treeCascade.reserve(cascade.num_levels); 
     120        for (int lev = 0; lev < cascade.num_levels; lev++) 
     121                treeCascade.push_back(CSampleTree(cascade.level[lev].group_size, assignLevel)); 
    128122} 
    129123 
     
    157151 
    158152        int nrecv; // global number of samples  THIS WILL BE THE NUMBER OF LEAFS IN THE SAMPLE TREE 
    159         MPI_Allreduce(&n, &nrecv, 1, MPI_INT, MPI_SUM, comm.comm); // => size of sample tree does not depend on keepNodes! 
    160  
     153        ep_lib::MPI_Allreduce(&n, &nrecv, 1, EP_INT, EP_SUM, comm.comm); // => size of sample tree does not depend on keepNodes! 
    161154        double ratio = blocSize / (1.0 * nrecv); 
    162155        int nsend = ratio * n + 1; // nsend = n_local_samples / n_global_samples * blocksize + 1 = blocksize/comm.size 
     
    164157 
    165158        int *counts = new int[comm.size]; 
    166         MPI_Allgather(&nsend, 1, MPI_INT, counts, 1, MPI_INT, comm.comm); 
     159        ep_lib::MPI_Allgather(&nsend, 1, EP_INT, counts, 1, EP_INT, comm.comm); 
    167160 
    168161        nrecv = 0; 
     
    190183        /* each process needs the sample elements from all processes */ 
    191184        double *recvBuffer = new double[nrecv*4]; 
    192         MPI_Allgatherv(sendBuffer, 4 * nsend, MPI_DOUBLE, recvBuffer, counts, displs, MPI_DOUBLE, comm.comm); 
     185        ep_lib::MPI_Allgatherv(sendBuffer, 4 * nsend, EP_DOUBLE, recvBuffer, counts, displs, EP_DOUBLE, comm.comm); 
    193186        delete[] sendBuffer; 
    194187        delete[] counts; 
     
    248241         << "   node size : "<<node.size()<<"   bloc size : "<<blocSize<<"  total number of leaf : "<<tree.leafs.size()<<endl ; 
    249242/* 
    250         MPI_Allreduce(&ok, &allok, 1, MPI_INT, MPI_PROD, communicator); 
     243        MPI_Allreduce(&ok, &allok, 1, EP_INT, MPI_PROD, communicator); 
    251244        if (!allok) { 
    252245                MPI_Finalize(); 
     
    254247        } 
    255248*/ 
    256     MPI_Abort(MPI_COMM_WORLD,-1) ; 
     249    ep_lib::MPI_Abort(EP_COMM_WORLD,-1) ; 
    257250  } 
    258251/* 
     
    272265{ 
    273266        CMPIRouting MPIRoute(communicator); 
    274         MPI_Barrier(communicator); 
     267        ep_lib::MPI_Barrier(communicator); 
    275268        CTimer::get("buildLocalTree(initRoute)").resume(); 
    276269        MPIRoute.init(route); 
     
    297290 
    298291        int mpiRank; 
    299         MPI_Comm_rank(communicator, &mpiRank); 
     292        ep_lib::MPI_Comm_rank(communicator, &mpiRank); 
    300293        localTree.leafs.reserve(nbLocalElements); 
    301294        for (int i = 0; i < nbLocalElements; i++) 
     
    323316  nb1=node.size() ; nb2=node2.size() ; 
    324317  nb=nb1+nb2 ; 
    325   MPI_Allreduce(&nb, &nbTot, 1, MPI_LONG, MPI_SUM, communicator) ; 
     318  ep_lib::MPI_Allreduce(&nb, &nbTot, 1, EP_LONG, EP_SUM, communicator) ; 
    326319  int commSize ; 
    327   MPI_Comm_size(communicator,&commSize) ; 
     320  ep_lib::MPI_Comm_size(communicator,&commSize) ; 
    328321   
    329322        // make multiple of two 
     
    508501        // gather circles on this level of the cascade 
    509502        int pg_size; 
    510         MPI_Comm_size(cascade.level[level].pg_comm, &pg_size); 
     503        ep_lib::MPI_Comm_size(cascade.level[level].pg_comm, &pg_size); 
    511504        vector<Coord> allRootCentres(pg_size); 
    512505        vector<double> allRootRadia(pg_size); 
    513         MPI_Allgather(&rootCentre, 3, MPI_DOUBLE, &allRootCentres[0], 3, MPI_DOUBLE, cascade.level[level].pg_comm); 
    514         MPI_Allgather(&rootRadius, 1, MPI_DOUBLE, &allRootRadia[0],   1, MPI_DOUBLE, cascade.level[level].pg_comm); 
     506        ep_lib::MPI_Allgather(&rootCentre, 3, EP_DOUBLE, &allRootCentres[0], 3, EP_DOUBLE, cascade.level[level].pg_comm); 
     507        ep_lib::MPI_Allgather(&rootRadius, 1, EP_DOUBLE, &allRootRadia[0],   1, EP_DOUBLE, cascade.level[level].pg_comm); 
    515508 
    516509        // now allRootsRadia and allRootCentres must be inserted into second levels of us and propagated to root 
  • XIOS/dev/branch_openmp/extern/remap/src/parallel_tree.hpp

    r1460 r1642  
    1212{ 
    1313public: 
    14   CParallelTree(ep_lib::MPI_Comm comm); 
    15   ~CParallelTree(); 
     14        CParallelTree(ep_lib::MPI_Comm comm); 
     15        ~CParallelTree(); 
    1616 
    17   void build(vector<Node>& node, vector<Node>& node2); 
     17        void build(vector<Node>& node, vector<Node>& node2); 
    1818 
    19   void routeNodes(vector<int>& route, vector<Node>& nodes, int level = 0); 
    20   void routeIntersections(vector<vector<int> >& route, vector<Node>& nodes, int level = 0); 
     19        void routeNodes(vector<int>& route, vector<Node>& nodes, int level = 0); 
     20        void routeIntersections(vector<vector<int> >& route, vector<Node>& nodes, int level = 0); 
    2121 
    22   int nbLocalElements; 
    23   Elt* localElements; 
     22        int nbLocalElements; 
     23        Elt* localElements; 
    2424 
    25   CTree localTree; 
     25        CTree localTree; 
    2626 
    2727private: 
    28   void updateCirclesForRouting(Coord rootCentre, double rootRadius, int level = 0); 
    29   void buildSampleTreeCascade(vector<Node>& sampleNodes, int level = 0); 
    30   void buildLocalTree(const vector<Node>& node, const vector<int>& route); 
    31   void buildRouteTree(); 
     28        void updateCirclesForRouting(Coord rootCentre, double rootRadius, int level = 0); 
     29        void buildSampleTreeCascade(vector<Node>& sampleNodes, int level = 0); 
     30        void buildLocalTree(const vector<Node>& node, const vector<int>& route); 
     31        void buildRouteTree(); 
    3232 
    33   //CSampleTree sampleTree; 
    34   vector<CSampleTree> treeCascade; // first for sample tree, then for routing tree 
    35   CMPICascade cascade; 
     33        //CSampleTree sampleTree; 
     34        vector<CSampleTree> treeCascade; // first for sample tree, then for routing tree 
     35        CMPICascade cascade; 
    3636  ep_lib::MPI_Comm communicator ; 
    3737 
  • XIOS/dev/branch_openmp/extern/remap/src/polyg.cpp

    r1328 r1642  
    2020void orient(int N, Coord *vertex, Coord *edge, double *d, const Coord &g) 
    2121{ 
    22         Coord ga = vertex[0] - g; 
    23         Coord gb = vertex[1] - g; 
    24         Coord vertical = crossprod(ga, gb); 
    25         if (N > 2 && scalarprod(g, vertical) < 0)  // (GAxGB).G 
    26         { 
    27                 for (int i = 0; i < N/2; i++) 
    28                         swap(vertex[i], vertex[N-1-i]); 
    29  
    30                 for (int i = 0; i < (N-1)/2; i++) 
    31                 { 
    32                         swap(edge[N-2-i], edge[i]); 
    33                         swap(d[i], d[N-2-i]); 
    34                 } 
    35         } 
     22  Coord ga = vertex[0] - g; 
     23  Coord gb = vertex[1] - g; 
     24  Coord vertical = crossprod(ga, gb); 
     25  if (N > 2 && scalarprod(g, vertical) < 0)  // (GAxGB).G 
     26  { 
     27    for (int i = 0; i < N/2; i++) 
     28      swap(vertex[i], vertex[N-1-i]); 
     29 
     30    for (int i = 0; i < (N-1)/2; i++) 
     31    { 
     32      swap(edge[N-2-i], edge[i]); 
     33      swap(d[i], d[N-2-i]); 
     34    } 
     35  } 
    3636} 
    3737 
     
    3939void normals(Coord *x, int n, Coord *a) 
    4040{ 
    41         for (int i = 0; i<n; i++) 
    42                 a[i] = crossprod(x[(i+1)%n], x[i]); 
     41  for (int i = 0; i<n; i++) 
     42    a[i] = crossprod(x[(i+1)%n], x[i]); 
    4343} 
    4444 
    4545Coord barycentre(const Coord *x, int n) 
    4646{ 
    47         if (n == 0) return ORIGIN; 
    48         Coord bc = ORIGIN; 
    49         for (int i = 0; i < n; i++) 
    50                 bc = bc + x[i]; 
    51         /* both distances can be equal down to roundoff when norm(bc) < mashineepsilon  
    52            which can occur when weighted with tiny area */ 
    53  
    54         assert(squaredist(bc, proj(bc)) <= squaredist(bc, proj(bc * (-1.0)))); 
    55         //if (squaredist(bc, proj(bc)) > squaredist(bc, proj(bc * (-1.0)))) return proj(bc * (-1.0)); 
    56  
    57         return proj(bc); 
     47  if (n == 0) return ORIGIN; 
     48  Coord bc = ORIGIN; 
     49  for (int i = 0; i < n; i++) 
     50    bc = bc + x[i]; 
     51  /* both distances can be equal down to roundoff when norm(bc) < mashineepsilon  
     52     which can occur when weighted with tiny area */ 
     53 
     54  assert(squaredist(bc, proj(bc)) <= squaredist(bc, proj(bc * (-1.0)))); 
     55  //if (squaredist(bc, proj(bc)) > squaredist(bc, proj(bc * (-1.0)))) return proj(bc * (-1.0)); 
     56 
     57  return proj(bc); 
    5858} 
    5959 
     
    6262static Coord tetrah_side_diff_centre(Coord a, Coord b) 
    6363{ 
    64         Coord n = crossprod(a,b); 
     64  Coord n = crossprod(a,b); 
    6565        double sinc2 = n.x*n.x + n.y*n.y + n.z*n.z; 
    66         assert(sinc2 < 1.0 + EPS); 
     66  assert(sinc2 < 1.0 + EPS); 
    6767 
    6868        // exact: u = asin(sinc)/sinc - 1; asin(sinc) = geodesic length of arc ab 
    69         // approx: 
     69  // approx: 
    7070        // double u = sinc2/6. + (3./40.)*sinc2*sinc2; 
    7171 
    72         // exact   
    73         if (sinc2 > 1.0 - EPS) /* if round-off leads to sinc > 1 asin produces NaN */ 
    74                 return n * (M_PI_2 - 1); 
    75         double sinc = sqrt(sinc2); 
     72  // exact   
     73  if (sinc2 > 1.0 - EPS) /* if round-off leads to sinc > 1 asin produces NaN */ 
     74    return n * (M_PI_2 - 1); 
     75  double sinc = sqrt(sinc2); 
    7676        double u = asin(sinc)/sinc - 1; 
    7777 
     
    8282Coord gc_normalintegral(const Coord *x, int n) 
    8383{ 
    84         Coord m = barycentre(x, n); 
    85         Coord bc = crossprod(x[n-1]-m, x[0]-m) + tetrah_side_diff_centre(x[n-1], x[0]); 
    86         for (int i = 1; i < n; i++) 
    87                 bc = bc + crossprod(x[i-1]-m, x[i]-m) + tetrah_side_diff_centre(x[i-1], x[i]); 
    88         return bc*0.5; 
     84  Coord m = barycentre(x, n); 
     85  Coord bc = crossprod(x[n-1]-m, x[0]-m) + tetrah_side_diff_centre(x[n-1], x[0]); 
     86  for (int i = 1; i < n; i++) 
     87    bc = bc + crossprod(x[i-1]-m, x[i]-m) + tetrah_side_diff_centre(x[i-1], x[i]); 
     88  return bc*0.5; 
    8989} 
    9090 
    9191Coord exact_barycentre(const Coord *x, int n) 
    9292{ 
    93         if (n >= 3) 
    94         { 
    95                 return  proj(gc_normalintegral(x, n)); 
    96         } 
    97         else if (n == 0) return ORIGIN; 
    98         else if (n == 2) return midpoint(x[0], x[1]); 
    99         else if (n == 1) return x[0]; 
     93  if (n >= 3) 
     94  { 
     95    return  proj(gc_normalintegral(x, n)); 
     96  } 
     97  else if (n == 0) return ORIGIN; 
     98  else if (n == 2) return midpoint(x[0], x[1]); 
     99  else if (n == 1) return x[0]; 
    100100} 
    101101 
    102102Coord sc_gc_moon_normalintegral(Coord a, Coord b, Coord pole) 
    103103{ 
    104         double hemisphere = (a.z > 0) ? 1: -1; 
    105  
    106         double lat = hemisphere * (M_PI_2 - acos(a.z)); 
    107         double lon1 = atan2(a.y, a.x); 
    108         double lon2 = atan2(b.y, b.x); 
    109         double lon_diff = lon2 - lon1; 
    110  
    111         // wraparound at lon=-pi=pi 
    112         if (lon_diff < -M_PI) lon_diff += 2.0*M_PI; 
    113         else if (lon_diff > M_PI) lon_diff -= 2.0*M_PI; 
    114  
    115         // integral of the normal over the surface bound by great arcs a-pole and b-pole and small arc a-b  
    116         Coord sc_normalintegral = Coord(0.5*(sin(lon2)-sin(lon1))*(M_PI_2 - lat - 0.5*sin(2.0*lat)), 
    117                                         0.5*(cos(lon1)-cos(lon2))*(M_PI_2 - lat - 0.5*sin(2.0*lat)), 
    118                                         hemisphere * lon_diff * 0.25 * (cos(2.0*lat) + 1.0)); 
    119         Coord p = Coord(0,0,hemisphere); // TODO assumes north pole is (0,0,1) 
    120         Coord t[] = {a, b, p}; 
    121         if (hemisphere < 0) swap(t[0], t[1]); 
    122         return (sc_normalintegral - gc_normalintegral(t, 3)) * hemisphere; 
    123 } 
    124  
    125  
    126 double triarea(Coord& A, Coord& B, Coord& C) 
    127 { 
    128         double a = ds(B, C); 
    129         double b = ds(C, A); 
    130         double c = ds(A, B); 
    131         double s = 0.5 * (a + b + c); 
    132         double t = tan(0.5*s) * tan(0.5*(s - a)) * tan(0.5*(s - b)) * tan(0.5*(s - c)); 
    133 //      assert(t >= 0); 
    134   if (t<1e-20) return 0. ; 
    135         return 4 * atan(sqrt(t)); 
     104  double hemisphere = (a.z > 0) ? 1: -1; 
     105 
     106  double lat = hemisphere * (M_PI_2 - acos(a.z)); 
     107  double lon1 = atan2(a.y, a.x); 
     108  double lon2 = atan2(b.y, b.x); 
     109  double lon_diff = lon2 - lon1; 
     110 
     111  // wraparound at lon=-pi=pi 
     112  if (lon_diff < -M_PI) lon_diff += 2.0*M_PI; 
     113  else if (lon_diff > M_PI) lon_diff -= 2.0*M_PI; 
     114 
     115  // integral of the normal over the surface bound by great arcs a-pole and b-pole and small arc a-b  
     116  Coord sc_normalintegral = Coord(0.5*(sin(lon2)-sin(lon1))*(M_PI_2 - lat - 0.5*sin(2.0*lat)), 
     117                                  0.5*(cos(lon1)-cos(lon2))*(M_PI_2 - lat - 0.5*sin(2.0*lat)), 
     118                                  hemisphere * lon_diff * 0.25 * (cos(2.0*lat) + 1.0)); 
     119  Coord p = Coord(0,0,hemisphere); // TODO assumes north pole is (0,0,1) 
     120  Coord t[] = {a, b, p}; 
     121  if (hemisphere < 0) swap(t[0], t[1]); 
     122  return (sc_normalintegral - gc_normalintegral(t, 3)) * hemisphere; 
     123} 
     124 
     125 
     126double triarea(const Coord& A, const Coord& B, const Coord& C) 
     127{ 
     128  double a = ds(B, C); 
     129  double b = ds(C, A); 
     130  double c = ds(A, B); 
     131  double tmp ; 
     132 
     133  if (a<b) { tmp=a ; a=b ; b=tmp ; } 
     134  if (c > a) { tmp=a ; a=c ; c=b, b=tmp;  } 
     135  else if (c > b) { tmp=c ; c=b ; b=tmp ; } 
     136   
     137  double s = 0.5 * (a + b + c); 
     138  double t = tan(0.25*(a+(b+c))) * tan(0.25*(c-(a-b))) * tan(0.25*( c + (a-b) )) * tan(0.25*( a + (b - c))); 
     139  if (t>0) return 4 * atan(sqrt(t)); 
     140  else 
     141  { 
     142    std::cout<<"double triarea(const Coord& A, const Coord& B, const Coord& C) : t < 0 !!! t="<<t<<endl ; 
     143    return 0 ; 
     144  } 
    136145} 
    137146 
     
    142151double alun(double b, double d) 
    143152{ 
    144         double a  = acos(d); 
    145         assert(b <= 2 * a); 
    146         double s  = a + 0.5 * b; 
    147         double t = tan(0.5 * s) * tan(0.5 * (s - a)) * tan(0.5 * (s - a)) * tan(0.5 * (s - b)); 
    148         double r  = sqrt(1 - d*d); 
    149         double p  = 2 * asin(sin(0.5*b) / r); 
    150         return p*(1 - d) - 4*atan(sqrt(t)); 
     153  double a  = acos(d); 
     154  assert(b <= 2 * a); 
     155  double s  = a + 0.5 * b; 
     156  double t = tan(0.5 * s) * tan(0.5 * (s - a)) * tan(0.5 * (s - a)) * tan(0.5 * (s - b)); 
     157  double r  = sqrt(1 - d*d); 
     158  double p  = 2 * asin(sin(0.5*b) / r); 
     159  return p*(1 - d) - 4*atan(sqrt(t)); 
    151160} 
    152161 
     
    160169double airbar(int N, const Coord *x, const Coord *c, double *d, const Coord& pole, Coord& gg) 
    161170{ 
    162         if (N < 3) 
    163           return 0; /* polygons with less than three vertices have zero area */ 
    164         Coord t[3]; 
    165         t[0] = barycentre(x, N); 
    166         Coord *g = new Coord[N]; 
    167         double area = 0; 
    168         Coord gg_exact = gc_normalintegral(x, N); 
    169         for (int i = 0; i < N; i++) 
    170         { 
    171                 /* for "spherical circle segment" sum triangular part and "small moon" and => account for small circle */ 
    172                 int ii = (i + 1) % N; 
    173                 t[1] = x[i]; 
    174                 t[2] = x[ii]; 
     171  if (N < 3) 
     172    return 0; /* polygons with less then three vertices have zero area */ 
     173  Coord t[3]; 
     174  t[0] = barycentre(x, N); 
     175  Coord *g = new Coord[N]; 
     176  double area = 0; 
     177  Coord gg_exact = gc_normalintegral(x, N); 
     178  for (int i = 0; i < N; i++) 
     179  { 
     180    /* for "spherical circle segment" sum triangular part and "small moon" and => account for small circle */ 
     181    int ii = (i + 1) % N; 
     182    t[1] = x[i]; 
     183    t[2] = x[ii]; 
    175184                double sc=scalarprod(crossprod(t[1] - t[0], t[2] - t[0]), t[0]) ; 
    176                 assert(sc >= -1e-10); // Error: tri a l'env (wrong orientation) 
    177                 double area_gc = triarea(t[0], t[1], t[2]); 
    178                 double area_sc_gc_moon = 0; 
    179                 if (d[i]) /* handle small circle case */ 
    180                 { 
    181                         Coord m = midpoint(t[1], t[2]); 
    182                         double mext = scalarprod(m, c[i]) - d[i]; 
    183                         char sgl = (mext > 0) ? -1 : 1; 
    184                         area_sc_gc_moon = sgl * alun(arcdist(t[1], t[2]), fabs(scalarprod(t[1], pole))); 
    185                         gg_exact = gg_exact + sc_gc_moon_normalintegral(t[1], t[2], pole); 
    186                 } 
    187                 area += area_gc + area_sc_gc_moon; /* for "spherical circle segment" sum triangular part (at) and "small moon" and => account for small circle */ 
    188                 g[i] = barycentre(t, 3) * (area_gc + area_sc_gc_moon); 
    189         } 
    190         gg = barycentre(g, N); 
    191         gg_exact = proj(gg_exact); 
    192         delete[] g; 
    193         gg = gg_exact; 
    194         return area; 
     185    assert(sc >= -1e-10); // Error: tri a l'env (wrong orientation) 
     186    double area_gc = triarea(t[0], t[1], t[2]); 
     187    double area_sc_gc_moon = 0; 
     188    if (d[i]) /* handle small circle case */ 
     189    { 
     190      Coord m = midpoint(t[1], t[2]); 
     191      double mext = scalarprod(m, c[i]) - d[i]; 
     192      char sgl = (mext > 0) ? -1 : 1; 
     193      area_sc_gc_moon = sgl * alun(arcdist(t[1], t[2]), fabs(scalarprod(t[1], pole))); 
     194      gg_exact = gg_exact + sc_gc_moon_normalintegral(t[1], t[2], pole); 
     195    } 
     196    area += area_gc + area_sc_gc_moon; /* for "spherical circle segment" sum triangular part (at) and "small moon" and => account for small circle */ 
     197    g[i] = barycentre(t, 3) * (area_gc + area_sc_gc_moon); 
     198  } 
     199  gg = barycentre(g, N); 
     200  gg_exact = proj(gg_exact); 
     201  delete[] g; 
     202  gg = gg_exact; 
     203  return area; 
    195204} 
    196205 
    197206double polygonarea(Coord *vertices, int N) 
    198207{ 
    199         assert(N >= 3); 
    200  
    201         /* compute polygon area as sum of triangles */ 
    202         Coord centre = barycentre(vertices, N); 
    203         double area = 0; 
    204         for (int i = 0; i < N; i++) 
    205                 area += triarea(centre, vertices[i], vertices[(i+1)%N]); 
    206         return area; 
     208  assert(N >= 3); 
     209 
     210  /* compute polygon area as sum of triangles */ 
     211  Coord centre = barycentre(vertices, N); 
     212  double area = 0; 
     213  for (int i = 0; i < N; i++) 
     214    area += triarea(centre, vertices[i], vertices[(i+1)%N]); 
     215  return area; 
    207216} 
    208217 
    209218int packedPolygonSize(const Elt& e) 
    210219{ 
    211         return sizeof(e.id) + sizeof(e.src_id) + sizeof(e.x) + sizeof(e.val) + 
    212                sizeof(e.n) + e.n*(sizeof(double)+sizeof(Coord)); 
     220  return sizeof(e.id) + sizeof(e.src_id) + sizeof(e.x) + sizeof(e.val)  + sizeof(e.given_area)+ 
     221         sizeof(e.n) + e.n*(sizeof(double)+sizeof(Coord)); 
    213222} 
    214223 
    215224void packPolygon(const Elt& e, char *buffer, int& pos)  
    216225{ 
    217         *((GloId *) &(buffer[pos])) = e.id; 
    218         pos += sizeof(e.id); 
    219         *((GloId *) &(buffer[pos])) = e.src_id; 
    220         pos += sizeof(e.src_id); 
    221  
    222         *((Coord *) &(buffer[pos])) = e.x; 
    223         pos += sizeof(e.x); 
    224  
    225         *((double*) &(buffer[pos])) = e.val; 
    226         pos += sizeof(e.val); 
    227  
    228         *((int *) & (buffer[pos])) = e.n; 
    229         pos += sizeof(e.n); 
    230  
    231         for (int i = 0; i < e.n; i++) 
    232         { 
    233                 *((double *) & (buffer[pos])) = e.d[i]; 
    234                 pos += sizeof(e.d[i]); 
    235  
    236                 *((Coord *) &(buffer[pos])) = e.vertex[i]; 
    237                 pos += sizeof(e.vertex[i]); 
    238         }  
     226  *((GloId *) &(buffer[pos])) = e.id; 
     227  pos += sizeof(e.id); 
     228  *((GloId *) &(buffer[pos])) = e.src_id; 
     229  pos += sizeof(e.src_id); 
     230 
     231  *((Coord *) &(buffer[pos])) = e.x; 
     232  pos += sizeof(e.x); 
     233 
     234  *((double*) &(buffer[pos])) = e.val; 
     235  pos += sizeof(e.val); 
     236 
     237  *((double*) &(buffer[pos])) = e.given_area; 
     238  pos += sizeof(e.val); 
     239 
     240  *((int *) & (buffer[pos])) = e.n; 
     241  pos += sizeof(e.n); 
     242 
     243  for (int i = 0; i < e.n; i++) 
     244  { 
     245    *((double *) & (buffer[pos])) = e.d[i]; 
     246    pos += sizeof(e.d[i]); 
     247 
     248    *((Coord *) &(buffer[pos])) = e.vertex[i]; 
     249    pos += sizeof(e.vertex[i]); 
     250  }  
    239251 
    240252} 
     
    242254void unpackPolygon(Elt& e, const char *buffer, int& pos)  
    243255{ 
    244         e.id = *((GloId *) &(buffer[pos])); 
    245         pos += sizeof(e.id); 
    246         e.src_id = *((GloId *) &(buffer[pos])); 
    247         pos += sizeof(e.src_id); 
    248  
    249         e.x = *((Coord *) & (buffer[pos]) ); 
    250         pos += sizeof(e.x); 
    251  
    252         e.val = *((double *) & (buffer[pos])); 
    253         pos += sizeof(double); 
    254  
    255         e.n = *((int *) & (buffer[pos])); 
    256         pos += sizeof(int); 
    257  
    258         for (int i = 0; i < e.n; i++) 
    259         { 
    260                 e.d[i] = *((double *) & (buffer[pos])); 
    261                 pos += sizeof(double); 
    262  
    263                 e.vertex[i] = *((Coord *) & (buffer[pos])); 
    264                 pos += sizeof(Coord); 
    265         } 
     256  e.id = *((GloId *) &(buffer[pos])); 
     257  pos += sizeof(e.id); 
     258  e.src_id = *((GloId *) &(buffer[pos])); 
     259  pos += sizeof(e.src_id); 
     260 
     261  e.x = *((Coord *) & (buffer[pos]) ); 
     262  pos += sizeof(e.x); 
     263 
     264  e.val = *((double *) & (buffer[pos])); 
     265  pos += sizeof(double); 
     266 
     267  e.given_area = *((double *) & (buffer[pos])); 
     268  pos += sizeof(double); 
     269 
     270  e.n = *((int *) & (buffer[pos])); 
     271  pos += sizeof(int); 
     272 
     273  for (int i = 0; i < e.n; i++) 
     274  { 
     275    e.d[i] = *((double *) & (buffer[pos])); 
     276    pos += sizeof(double); 
     277 
     278    e.vertex[i] = *((Coord *) & (buffer[pos])); 
     279    pos += sizeof(Coord); 
     280  } 
    266281} 
    267282 
    268283int packIntersectionSize(const Elt& elt)  
    269284{ 
    270         return elt.is.size() * (2*sizeof(int)+ sizeof(GloId) + 5*sizeof(double)); 
     285  return elt.is.size() * (2*sizeof(int)+ sizeof(GloId) + 5*sizeof(double)); 
    271286} 
    272287 
     
    274289{ 
    275290  for (list<Polyg *>::const_iterator it = e.is.begin(); it != e.is.end(); ++it) 
    276         { 
    277                 *((int *) &(buffer[0])) += 1; 
    278  
    279                 *((int *) &(buffer[pos])) = e.id.ind; 
    280                 pos += sizeof(int); 
     291  { 
     292    *((int *) &(buffer[0])) += 1; 
     293 
     294    *((int *) &(buffer[pos])) = e.id.ind; 
     295    pos += sizeof(int); 
    281296 
    282297    *((double *) &(buffer[pos])) = e.area; 
    283298    pos += sizeof(double); 
    284299 
    285                 *((GloId *) &(buffer[pos])) = (*it)->id; 
    286                 pos += sizeof(GloId); 
     300 
     301    *((GloId *) &(buffer[pos])) = (*it)->id; 
     302    pos += sizeof(GloId); 
    287303   
    288                 *((int *) &(buffer[pos])) = (*it)->n; 
    289                 pos += sizeof(int); 
    290                 *((double *) &(buffer[pos])) = (*it)->area; 
    291                 pos += sizeof(double); 
    292  
    293                 *((Coord *) &(buffer[pos])) = (*it)->x; 
    294                 pos += sizeof(Coord); 
    295         } 
     304    *((int *) &(buffer[pos])) = (*it)->n; 
     305    pos += sizeof(int); 
     306    *((double *) &(buffer[pos])) = (*it)->area; 
     307    pos += sizeof(double); 
     308 
     309    *((Coord *) &(buffer[pos])) = (*it)->x; 
     310    pos += sizeof(Coord); 
     311  } 
    296312} 
    297313 
    298314void unpackIntersection(Elt* e, const char* buffer)  
    299315{ 
    300         int ind; 
    301         int pos = 0; 
     316  int ind; 
     317  int pos = 0; 
    302318   
    303         int n = *((int *) & (buffer[pos])); 
    304         pos += sizeof(int); 
    305         for (int i = 0; i < n; i++) 
    306         { 
    307                 ind = *((int*) &(buffer[pos])); 
    308                 pos+=sizeof(int); 
    309  
    310                 Elt& elt= e[ind]; 
     319  int n = *((int *) & (buffer[pos])); 
     320  pos += sizeof(int); 
     321  for (int i = 0; i < n; i++) 
     322  { 
     323    ind = *((int*) &(buffer[pos])); 
     324    pos+=sizeof(int); 
     325 
     326    Elt& elt= e[ind]; 
    311327 
    312328    elt.area=*((double *) & (buffer[pos])); 
    313                 pos += sizeof(double); 
    314  
    315                 Polyg *polygon = new Polyg; 
    316  
    317                 polygon->id =  *((GloId *) & (buffer[pos])); 
    318                 pos += sizeof(GloId); 
    319  
    320                 polygon->n =  *((int *) & (buffer[pos])); 
    321                 pos += sizeof(int); 
    322  
    323                 polygon->area =  *((double *) & (buffer[pos])); 
    324                 pos += sizeof(double); 
    325  
    326                 polygon->x = *((Coord *) & (buffer[pos])); 
    327                 pos += sizeof(Coord); 
    328  
    329                 elt.is.push_back(polygon); 
    330         } 
    331 } 
    332  
    333 } 
     329    pos += sizeof(double); 
     330 
     331 
     332    Polyg *polygon = new Polyg; 
     333 
     334    polygon->id =  *((GloId *) & (buffer[pos])); 
     335    pos += sizeof(GloId); 
     336 
     337    polygon->n =  *((int *) & (buffer[pos])); 
     338    pos += sizeof(int); 
     339 
     340    polygon->area =  *((double *) & (buffer[pos])); 
     341    pos += sizeof(double); 
     342 
     343    polygon->x = *((Coord *) & (buffer[pos])); 
     344    pos += sizeof(Coord); 
     345 
     346    elt.is.push_back(polygon); 
     347  } 
     348} 
     349 
     350} 
  • XIOS/dev/branch_openmp/extern/remap/src/polyg.hpp

    r688 r1642  
    2323void unpackIntersection(Elt *e, const char *buffer); 
    2424int packIntersectionSize(const Elt& e); 
     25double triarea( const Coord& A, const Coord& B, const Coord& C) ; 
    2526 
    2627} 
  • XIOS/dev/branch_openmp/extern/remap/src/timerRemap.cpp

    r1328 r1642  
    44#include <map> 
    55#include <iostream> 
    6 using namespace ep_lib; 
    76 
    87namespace sphereRemap { 
     
    109using namespace std; 
    1110 
    12 //map<string,CTimer*> CTimer::allTimer; 
    13 map<string,CTimer*> *CTimer::allTimer_ptr = 0; 
     11map<string,CTimer*> CTimer::allTimer; 
    1412 
    1513CTimer::CTimer(const string& name_) : name(name_) 
     
    5856{ 
    5957        map<string,CTimer*>::iterator it; 
    60         if(allTimer_ptr == 0) allTimer_ptr = new map<string,CTimer*>; 
    61         //it=allTimer.find(name); 
    62         it=allTimer_ptr->find(name); 
    63         //if (it==allTimer.end()) it=allTimer.insert(pair<string,CTimer*>(name,new CTimer(name))).first; 
    64         if (it==allTimer_ptr->end()) it=allTimer_ptr->insert(pair<string,CTimer*>(name,new CTimer(name))).first; 
     58        it=allTimer.find(name); 
     59        if (it==allTimer.end()) it=allTimer.insert(pair<string,CTimer*>(name,new CTimer(name))).first; 
    6560        return *(it->second); 
    6661} 
  • XIOS/dev/branch_openmp/extern/remap/src/timerRemap.hpp

    r1334 r1642  
    2626    double getCumulatedTime(void); 
    2727    void print(void); 
    28     //static map<string,CTimer*> allTimer; 
    29     static map<string,CTimer*> *allTimer_ptr; 
    30     #pragma omp threadprivate(allTimer_ptr) 
     28    static map<string,CTimer*> allTimer; 
    3129    static double getTime(void); 
    3230    static CTimer& get(string name); 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allgather.cpp

    r1539 r1642  
    9292      int local_sendcount = num_ep * count; 
    9393 
    94       ::MPI_Allgather(&local_sendcount, 1, to_mpi_type(MPI_INT), mpi_recvcounts, 1, to_mpi_type(MPI_INT), to_mpi_comm(comm->mpi_comm)); 
     94      ::MPI_Allgather(&local_sendcount, 1, to_mpi_type(EP_INT), mpi_recvcounts, 1, to_mpi_type(EP_INT), to_mpi_comm(comm->mpi_comm)); 
    9595 
    9696      mpi_displs[0] = 0; 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allgatherv.cpp

    r1539 r1642  
    5656    vector<int>local_displs(num_ep, 0); 
    5757 
    58     MPI_Gather_local(&sendcount, 1, MPI_INT, local_recvcounts.data(), 0, comm); 
     58    MPI_Gather_local(&sendcount, 1, EP_INT, local_recvcounts.data(), 0, comm); 
    5959    for(int i=1; i<num_ep; i++) local_displs[i] = local_displs[i-1] + local_recvcounts[i-1];  
    6060 
     
    7575 
    7676      int local_sendcount = std::accumulate(local_recvcounts.begin(), local_recvcounts.end(), 0); 
    77       ::MPI_Allgather(&local_sendcount, 1, to_mpi_type(MPI_INT), mpi_recvcounts.data(), 1, to_mpi_type(MPI_INT), to_mpi_comm(comm->mpi_comm)); 
     77      ::MPI_Allgather(&local_sendcount, 1, to_mpi_type(EP_INT), mpi_recvcounts.data(), 1, to_mpi_type(EP_INT), to_mpi_comm(comm->mpi_comm)); 
    7878 
    7979      for(int i=1; i<mpi_size; i++) 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allocate.cpp

    r1539 r1642  
    3333 
    3434    int num_ep_max; 
    35     MPI_Allreduce(&num_ep, &num_ep_max, 1, MPI_INT, MPI_MAX, comm); 
     35    MPI_Allreduce(&num_ep, &num_ep_max, 1, EP_INT, MPI_MAX, comm); 
    3636 
    3737    assert(num_ep_max > 1); 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_create.cpp

    r1539 r1642  
    7373    } 
    7474 
    75     ::MPI_Allgather(&num_ep, 1, to_mpi_type(MPI_INT), &recv_num_ep[0], 1, to_mpi_type(MPI_INT), mpi_base_comm); 
     75    ::MPI_Allgather(&num_ep, 1, to_mpi_type(EP_INT), &recv_num_ep[0], 1, to_mpi_type(EP_INT), mpi_base_comm); 
    7676 
    7777 
     
    124124      for(int j=0; j<recv_num_ep[i]; j++) 
    125125      { 
    126         out_comm_hdls[0]->ep_rank_map->insert(std::pair< int, std::pair<int,int> >(ind, j, i)); 
     126        //out_comm_hdls[0]->ep_rank_map->insert(std::pair< int, std::pair<int,int> >(ind, j, i)); 
     127        (*(out_comm_hdls[0]->ep_rank_map))[ind] = std::make_pair(j,i);//->insert(std::pair< int, std::pair<int,int> >(ind, j, i)); 
    127128        ind++; 
    128129      } 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_declaration.cpp

    r1520 r1642  
    44 
    55::MPI_Comm MPI_COMM_WORLD_STD = MPI_COMM_WORLD; 
    6 #undef MPI_COMM_WORLD 
     6//#undef MPI_COMM_WORLD 
    77 
    88 
    99::MPI_Comm MPI_COMM_NULL_STD = MPI_COMM_NULL; 
    10 #undef MPI_COMM_NULL 
     10//#undef MPI_COMM_NULL 
    1111 
    1212 
    1313::MPI_Request MPI_REQUEST_NULL_STD = MPI_REQUEST_NULL; 
    14 #undef MPI_REQUEST_NULL 
     14//#undef MPI_REQUEST_NULL 
    1515 
    1616::MPI_Info MPI_INFO_NULL_STD = MPI_INFO_NULL; 
    17 #undef MPI_INFO_NULL 
     17//#undef MPI_INFO_NULL 
    1818 
    1919::MPI_Datatype MPI_INT_STD = MPI_INT; 
     
    2626::MPI_Datatype MPI_UINT64_T_STD = MPI_UINT64_T; 
    2727::MPI_Datatype MPI_LONG_LONG_INT_STD = MPI_LONG_LONG_INT; 
    28  
     28::MPI_Datatype MPI_LONG_LONG_STD = MPI_LONG_LONG; 
     29/* 
    2930#undef MPI_INT 
    3031#undef MPI_FLOAT 
     
    3637#undef MPI_UINT64_T 
    3738#undef MPI_LONG_LONG_INT 
    38  
     39*/ 
    3940 
    4041::MPI_Op MPI_SUM_STD = MPI_SUM; 
     
    4344::MPI_Op MPI_LOR_STD = MPI_LOR; 
    4445::MPI_Op MPI_REPLACE_STD = MPI_REPLACE; 
    45  
     46/* 
    4647#undef MPI_SUM 
    4748#undef MPI_MAX 
     
    4950#undef MPI_LOR 
    5051#undef MPI_REPLACE 
    51  
     52*/ 
    5253 
    5354// _STD defined in ep_type.cpp 
     
    6263extern ::MPI_Datatype MPI_UINT64_T_STD; 
    6364extern ::MPI_Datatype MPI_LONG_LONG_INT_STD; 
     65extern ::MPI_Datatype MPI_LONG_LONG_STD; 
     66 
    6467 
    6568 
     
    7780extern ::MPI_Info MPI_INFO_NULL_STD; 
    7881 
    79 ep_lib::MPI_Datatype MPI_INT = &MPI_INT_STD; 
    80 ep_lib::MPI_Datatype MPI_FLOAT = &MPI_FLOAT_STD; 
    81 ep_lib::MPI_Datatype MPI_DOUBLE = &MPI_DOUBLE_STD; 
    82 ep_lib::MPI_Datatype MPI_CHAR = &MPI_CHAR_STD; 
    83 ep_lib::MPI_Datatype MPI_LONG = &MPI_LONG_STD; 
    84 ep_lib::MPI_Datatype MPI_UNSIGNED_LONG = &MPI_UNSIGNED_LONG_STD; 
    85 ep_lib::MPI_Datatype MPI_UNSIGNED_CHAR = &MPI_UNSIGNED_CHAR_STD; 
    86 ep_lib::MPI_Datatype MPI_UINT64_T = &MPI_UINT64_T_STD; 
    87 ep_lib::MPI_Datatype MPI_LONG_LONG_INT = &MPI_LONG_LONG_INT_STD; 
    88  
    89  
    90 ep_lib::MPI_Op MPI_SUM = &MPI_SUM_STD; 
    91 ep_lib::MPI_Op MPI_MAX = &MPI_MAX_STD; 
    92 ep_lib::MPI_Op MPI_MIN = &MPI_MIN_STD; 
    93 ep_lib::MPI_Op MPI_LOR = &MPI_LOR_STD; 
    94 ep_lib::MPI_Op MPI_REPLACE = &MPI_REPLACE_STD; 
    95  
    96 ep_lib::ep_comm EP_COMM_WORLD(&MPI_COMM_WORLD_STD); 
    97 ep_lib::ep_comm EP_COMM_NULL(&MPI_COMM_NULL_STD); 
    98  
    99 ep_lib::MPI_Comm MPI_COMM_WORLD = &EP_COMM_WORLD; 
    100 ep_lib::MPI_Comm MPI_COMM_NULL = &EP_COMM_NULL; 
    101  
    102 //ep_lib::ep_status EP_STATUS_IGNORE(&MPI_STATUS_IGNORE_STD); 
    103 ep_lib::ep_request EP_REQUEST_NULL(&MPI_REQUEST_NULL_STD); 
    104 ep_lib::ep_info EP_INFO_NULL(&MPI_INFO_NULL_STD); 
    105  
    106 //ep_lib::MPI_Status MPI_STATUS_IGNORE = &EP_STATUS_IGNORE; 
    107 ep_lib::MPI_Request MPI_REQUEST_NULL = &EP_REQUEST_NULL; 
    108 ep_lib::MPI_Info MPI_INFO_NULL = &EP_INFO_NULL; 
     82ep_lib::MPI_Datatype EP_INT = &MPI_INT_STD; 
     83ep_lib::MPI_Datatype EP_FLOAT = &MPI_FLOAT_STD; 
     84ep_lib::MPI_Datatype EP_DOUBLE = &MPI_DOUBLE_STD; 
     85ep_lib::MPI_Datatype EP_CHAR = &MPI_CHAR_STD; 
     86ep_lib::MPI_Datatype EP_LONG = &MPI_LONG_STD; 
     87ep_lib::MPI_Datatype EP_UNSIGNED_LONG = &MPI_UNSIGNED_LONG_STD; 
     88ep_lib::MPI_Datatype EP_UNSIGNED_CHAR = &MPI_UNSIGNED_CHAR_STD; 
     89ep_lib::MPI_Datatype EP_UINT64_T = &MPI_UINT64_T_STD; 
     90ep_lib::MPI_Datatype EP_LONG_LONG_INT = &MPI_LONG_LONG_INT_STD; 
     91ep_lib::MPI_Datatype EP_LONG_LONG = &MPI_LONG_LONG_STD; 
    10992 
    11093 
    11194 
     95ep_lib::MPI_Op EP_SUM = &MPI_SUM_STD; 
     96ep_lib::MPI_Op EP_MAX = &MPI_MAX_STD; 
     97ep_lib::MPI_Op EP_MIN = &MPI_MIN_STD; 
     98ep_lib::MPI_Op EP_LOR = &MPI_LOR_STD; 
     99ep_lib::MPI_Op EP_REPLACE = &MPI_REPLACE_STD; 
     100 
     101ep_lib::ep_comm EP_COMM_WORLD_t(&MPI_COMM_WORLD_STD); 
     102ep_lib::ep_comm EP_COMM_NULL_t(&MPI_COMM_NULL_STD); 
     103 
     104ep_lib::MPI_Comm EP_COMM_WORLD = &EP_COMM_WORLD_t; 
     105ep_lib::MPI_Comm EP_COMM_NULL = &EP_COMM_NULL_t; 
     106 
     107//ep_lib::ep_status EP_STATUS_IGNORE(&MPI_STATUS_IGNORE_STD); 
     108ep_lib::ep_request EP_REQUEST_NULL_t(&MPI_REQUEST_NULL_STD); 
     109ep_lib::ep_info EP_INFO_NULL_t(&MPI_INFO_NULL_STD); 
     110 
     111//ep_lib::MPI_Status MPI_STATUS_IGNORE = &EP_STATUS_IGNORE; 
     112ep_lib::MPI_Request EP_REQUEST_NULL = &EP_REQUEST_NULL_t; 
     113ep_lib::MPI_Info EP_INFO_NULL = &EP_INFO_NULL_t; 
     114 
     115 
     116 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_declaration.hpp

    r1520 r1642  
    11#ifndef EP_DECLARATION_HPP_INCLUDED 
    22#define EP_DECLARATION_HPP_INCLUDED 
    3  
     3/* 
    44#undef MPI_INT 
    55#undef MPI_FLOAT 
     
    1818#undef MPI_REPLACE 
    1919 
    20 #undef MPI_COMM_WORLD 
     20//#undef MPI_COMM_WORLD 
    2121#undef MPI_COMM_NULL 
    2222 
     
    2424#undef MPI_STATUS_IGNORE 
    2525#undef MPI_INFO_NULL 
     26*/ 
     27extern ep_lib::MPI_Datatype EP_INT; 
     28extern ep_lib::MPI_Datatype EP_FLOAT; 
     29extern ep_lib::MPI_Datatype EP_DOUBLE; 
     30extern ep_lib::MPI_Datatype EP_CHAR; 
     31extern ep_lib::MPI_Datatype EP_LONG; 
     32extern ep_lib::MPI_Datatype EP_UNSIGNED_LONG; 
     33extern ep_lib::MPI_Datatype EP_UNSIGNED_CHAR; 
     34extern ep_lib::MPI_Datatype EP_UINT64_T; 
     35extern ep_lib::MPI_Datatype EP_LONG_LONG_INT; 
     36extern ep_lib::MPI_Datatype EP_LONG_LONG; 
    2637 
    27 extern ep_lib::MPI_Datatype MPI_INT; 
    28 extern ep_lib::MPI_Datatype MPI_FLOAT; 
    29 extern ep_lib::MPI_Datatype MPI_DOUBLE; 
    30 extern ep_lib::MPI_Datatype MPI_CHAR; 
    31 extern ep_lib::MPI_Datatype MPI_LONG; 
    32 extern ep_lib::MPI_Datatype MPI_UNSIGNED_LONG; 
    33 extern ep_lib::MPI_Datatype MPI_UNSIGNED_CHAR; 
    34 extern ep_lib::MPI_Datatype MPI_UINT64_T; 
    35 extern ep_lib::MPI_Datatype MPI_LONG_LONG_INT; 
    3638 
    37 extern ep_lib::MPI_Op MPI_SUM; 
    38 extern ep_lib::MPI_Op MPI_MAX; 
    39 extern ep_lib::MPI_Op MPI_MIN; 
    40 extern ep_lib::MPI_Op MPI_LOR; 
    41 extern ep_lib::MPI_Op MPI_REPLACE; 
     39extern ep_lib::MPI_Op EP_SUM; 
     40extern ep_lib::MPI_Op EP_MAX; 
     41extern ep_lib::MPI_Op EP_MIN; 
     42extern ep_lib::MPI_Op EP_LOR; 
     43extern ep_lib::MPI_Op EP_REPLACE; 
    4244 
    43 extern ep_lib::MPI_Comm MPI_COMM_WORLD; 
    44 extern ep_lib::MPI_Comm MPI_COMM_NULL; 
     45extern ep_lib::MPI_Comm EP_COMM_WORLD; 
     46extern ep_lib::MPI_Comm EP_COMM_NULL; 
    4547 
    46 extern ep_lib::MPI_Status MPI_STATUS_IGNORE; 
    47 extern ep_lib::MPI_Request MPI_REQUEST_NULL; 
    48 extern ep_lib::MPI_Info MPI_INFO_NULL; 
    49  
     48extern ep_lib::MPI_Status EP_STATUS_IGNORE; 
     49extern ep_lib::MPI_Request EP_REQUEST_NULL; 
     50extern ep_lib::MPI_Info EP_INFO_NULL; 
    5051 
    5152#endif // EP_DECLARATION_HPP_INCLUDED 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_exscan.cpp

    r1540 r1642  
    7878    MPI_Barrier_local(comm); 
    7979 
    80     if(op == MPI_SUM) 
    81     { 
    82       if(datatype == MPI_INT ) 
     80    if(op == EP_SUM) 
     81    { 
     82      if(datatype == EP_INT ) 
    8383      { 
    8484        assert(datasize == sizeof(int)); 
     
    8787      } 
    8888      
    89       else if(datatype == MPI_FLOAT ) 
     89      else if(datatype == EP_FLOAT ) 
    9090      { 
    9191        assert(datasize == sizeof(float)); 
     
    9595       
    9696 
    97       else if(datatype == MPI_DOUBLE ) 
     97      else if(datatype == EP_DOUBLE ) 
    9898      { 
    9999        assert(datasize == sizeof(double)); 
     
    102102      } 
    103103 
    104       else if(datatype == MPI_CHAR ) 
     104      else if(datatype == EP_CHAR ) 
    105105      { 
    106106        assert(datasize == sizeof(char)); 
     
    109109      } 
    110110 
    111       else if(datatype == MPI_LONG ) 
     111      else if(datatype == EP_LONG ) 
    112112      { 
    113113        assert(datasize == sizeof(long)); 
     
    116116      } 
    117117 
    118       else if(datatype == MPI_UNSIGNED_LONG ) 
     118      else if(datatype == EP_UNSIGNED_LONG ) 
    119119      { 
    120120        assert(datasize == sizeof(unsigned long)); 
     
    123123      } 
    124124       
    125       else if(datatype == MPI_LONG_LONG_INT ) 
     125      else if(datatype == EP_LONG_LONG_INT ) 
    126126      { 
    127127        assert(datasize == sizeof(long long int)); 
     
    139139    } 
    140140 
    141     else if(op == MPI_MAX) 
    142     { 
    143       if(datatype == MPI_INT ) 
     141    else if(op == EP_MAX) 
     142    { 
     143      if(datatype == EP_INT ) 
    144144      { 
    145145        assert(datasize == sizeof(int)); 
     
    148148      } 
    149149 
    150       else if(datatype == MPI_FLOAT ) 
     150      else if(datatype == EP_FLOAT ) 
    151151      { 
    152152        assert(datasize == sizeof(float)); 
     
    155155      } 
    156156 
    157       else if(datatype == MPI_DOUBLE ) 
     157      else if(datatype == EP_DOUBLE ) 
    158158      { 
    159159        assert(datasize == sizeof(double)); 
     
    162162      } 
    163163 
    164       else if(datatype == MPI_CHAR ) 
     164      else if(datatype == EP_CHAR ) 
    165165      { 
    166166        assert(datasize == sizeof(char)); 
     
    169169      } 
    170170 
    171       else if(datatype == MPI_LONG ) 
     171      else if(datatype == EP_LONG ) 
    172172      { 
    173173        assert(datasize == sizeof(long)); 
     
    176176      } 
    177177 
    178       else if(datatype == MPI_UNSIGNED_LONG ) 
     178      else if(datatype == EP_UNSIGNED_LONG ) 
    179179      { 
    180180        assert(datasize == sizeof(unsigned long)); 
     
    183183      } 
    184184      
    185       else if(datatype == MPI_LONG_LONG_INT ) 
     185      else if(datatype == EP_LONG_LONG_INT ) 
    186186      { 
    187187        assert(datasize == sizeof(long long int)); 
     
    197197    } 
    198198 
    199     else if(op == MPI_MIN) 
    200     { 
    201       if(datatype == MPI_INT ) 
     199    else if(op == EP_MIN) 
     200    { 
     201      if(datatype == EP_INT ) 
    202202      { 
    203203        assert(datasize == sizeof(int)); 
     
    206206      } 
    207207 
    208       else if(datatype == MPI_FLOAT ) 
     208      else if(datatype == EP_FLOAT ) 
    209209      { 
    210210        assert(datasize == sizeof(float)); 
     
    213213      } 
    214214 
    215       else if(datatype == MPI_DOUBLE ) 
     215      else if(datatype == EP_DOUBLE ) 
    216216      { 
    217217        assert(datasize == sizeof(double)); 
     
    220220      } 
    221221 
    222       else if(datatype == MPI_CHAR ) 
     222      else if(datatype == EP_CHAR ) 
    223223      { 
    224224        assert(datasize == sizeof(char)); 
     
    227227      } 
    228228 
    229       else if(datatype == MPI_LONG ) 
     229      else if(datatype == EP_LONG ) 
    230230      { 
    231231        assert(datasize == sizeof(long)); 
     
    234234      } 
    235235 
    236       else if(datatype == MPI_UNSIGNED_LONG ) 
     236      else if(datatype == EP_UNSIGNED_LONG ) 
    237237      { 
    238238        assert(datasize == sizeof(unsigned long)); 
     
    241241      } 
    242242 
    243       else if(datatype == MPI_LONG_LONG_INT ) 
     243      else if(datatype == EP_LONG_LONG_INT ) 
    244244      { 
    245245        assert(datasize == sizeof(long long int)); 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_finalize.cpp

    r1539 r1642  
    99  int MPI_Finalize() 
    1010  { 
    11     #pragma omp master 
     11    //pragma omp master 
    1212    { 
    1313      printf("calling EP Finalize\n"); 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_fortran.cpp

    r1520 r1642  
    88 
    99 
    10 namespace ep_lib 
    11 { 
     10//namespace ep_lib 
     11//{ 
    1212 
    13   void* EP_Comm_c2f(MPI_Comm comm) 
     13  void* EP_Comm_c2f(ep_lib::MPI_Comm comm) 
    1414  { 
    1515    Debug("MPI_Comm_c2f"); 
    16     void* fint = new ::MPI_Fint; 
     16    void* fint = new MPI_Fint; 
    1717    #ifdef _intelmpi 
    18     *static_cast< ::MPI_Fint*>(fint) = (::MPI_Fint)(to_mpi_comm(comm->mpi_comm)); 
     18    //*static_cast< ::MPI_Fint*>(fint) = (::MPI_Fint)(to_mpi_comm(comm->mpi_comm)); 
     19    *static_cast< MPI_Fint*>(fint) = MPI_Comm_c2f(to_mpi_comm(comm->mpi_comm)); 
    1920    #elif _openmpi 
    20     *static_cast< ::MPI_Fint*>(fint) = MPI_Comm_c2f(to_mpi_comm(comm->mpi_comm)); 
     21    *static_cast< MPI_Fint*>(fint) = MPI_Comm_c2f(to_mpi_comm(comm->mpi_comm)); 
    2122    #endif 
    2223     
    23     std::map<std::pair< ::MPI_Fint, int>, MPI_Comm > ::iterator it; 
     24    std::map<std::pair< MPI_Fint, int>, ep_lib::MPI_Comm > ::iterator it; 
    2425     
    2526    #pragma omp critical (fc_comm_map) 
    2627    { 
    27       it = fc_comm_map.find(std::make_pair(*static_cast< ::MPI_Fint*>(fint), omp_get_thread_num())); 
    28       if(it == fc_comm_map.end()) 
     28      it = ep_lib::fc_comm_map.find(std::make_pair(*static_cast< MPI_Fint*>(fint), omp_get_thread_num())); 
     29      if(it == ep_lib::fc_comm_map.end()) 
    2930      { 
    30         fc_comm_map.insert(std::make_pair( std::make_pair( *static_cast< ::MPI_Fint*>(fint), omp_get_thread_num()) , comm)); 
    31         printf("EP_Comm_c2f : MAP %p insert: %d, %d, %p\n", &fc_comm_map, *static_cast< ::MPI_Fint*>(fint), omp_get_thread_num(), comm->ep_comm_ptr); 
     31        ep_lib::fc_comm_map.insert(std::make_pair( std::make_pair( *static_cast< MPI_Fint*>(fint), omp_get_thread_num()) , comm)); 
     32        printf("EP_Comm_c2f : MAP %p insert: %d, %d, %p\n", &(ep_lib::fc_comm_map), *static_cast< MPI_Fint*>(fint), omp_get_thread_num(), comm->ep_comm_ptr); 
    3233      } 
    3334    } 
     
    3839  } 
    3940 
    40   MPI_Comm EP_Comm_f2c(void* comm) 
     41  ep_lib::MPI_Comm EP_Comm_f2c(void* comm) 
    4142  { 
    4243    Debug("MPI_Comm_f2c"); 
    4344     
    4445     
    45     std::map<std::pair< ::MPI_Fint, int>, MPI_Comm > ::iterator it; 
     46    std::map<std::pair< MPI_Fint, int>, ep_lib::MPI_Comm > ::iterator it; 
    4647     
    4748    #pragma omp critical (fc_comm_map) 
    48     it = fc_comm_map.find(std::make_pair(*static_cast< ::MPI_Fint*>(comm), omp_get_thread_num())); 
     49    it = ep_lib::fc_comm_map.find(std::make_pair(*static_cast< MPI_Fint*>(comm), omp_get_thread_num())); 
    4950     
    50     if(it != fc_comm_map.end()) 
     51    if(it != ep_lib::fc_comm_map.end()) 
    5152    { 
    52       MPI_Comm comm_ptr; 
     53      ep_lib::MPI_Comm comm_ptr; 
    5354      comm_ptr = it->second; 
    54       printf("EP_Comm_f2c : MAP %p find: %d, %d, %p\n", &fc_comm_map, it->first.first, it->first.second, comm_ptr->ep_comm_ptr); 
     55      printf("EP_Comm_f2c : MAP %p find: %d, %d, %p\n", &(ep_lib::fc_comm_map), it->first.first, it->first.second, comm_ptr->ep_comm_ptr); 
    5556      return  comm_ptr; 
    5657    } 
     
    5859       
    5960     
     61    MPI_Comm *base_comm = new MPI_Comm; 
    6062    #ifdef _intelmpi 
    61     ::MPI_Comm *base_comm = new ::MPI_Comm; 
    62     *base_comm = (::MPI_Comm)(*static_cast< ::MPI_Fint*>(comm)); 
     63    *base_comm = (MPI_Comm)(*static_cast< MPI_Fint*>(comm)); 
    6364    #elif _openmpi 
    64     ::MPI_Comm *base_comm = ::MPI_Comm_f2c(*static_cast< ::MPI_Fint*>(comm)); 
     65    *base_comm = MPI_Comm_f2c(*static_cast< MPI_Fint*>(comm)); 
    6566    #endif 
    6667 
    67     if(*base_comm != to_mpi_comm(MPI_COMM_NULL->mpi_comm)) 
     68    if(*base_comm != to_mpi_comm(EP_COMM_NULL->mpi_comm)) 
    6869    { 
    6970      if(omp_get_thread_num() == 0) 
    7071      { 
    7172        int num_ep = omp_get_num_threads(); 
    72         MPI_Comm *new_comm; 
    73         MPI_Info info; 
    74         MPI_Comm_create_endpoints(base_comm, num_ep, info, new_comm); 
    75         passage = new_comm; 
     73        ep_lib::MPI_Comm *new_comm; 
     74        ep_lib::MPI_Info info; 
     75        ep_lib::MPI_Comm_create_endpoints(base_comm, num_ep, info, new_comm); 
     76        ep_lib::passage = new_comm; 
    7677      } 
    7778      #pragma omp barrier 
    7879 
    79       MPI_Comm return_comm = passage[omp_get_thread_num()]; 
     80      ep_lib::MPI_Comm return_comm = ep_lib::passage[omp_get_thread_num()]; 
    8081      return return_comm; 
    8182         
    8283    } 
    83     return MPI_COMM_NULL; 
     84    return EP_COMM_NULL; 
    8485 
    8586  } 
    8687 
    87 } 
     88//} 
    8889 
    8990 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_gatherv.cpp

    r1539 r1642  
    8787    } 
    8888 
    89     MPI_Bcast(recvcounts, ep_size, MPI_INT, root, comm); 
    90     MPI_Bcast(displs, ep_size, MPI_INT, root, comm); 
     89    MPI_Bcast(recvcounts, ep_size, EP_INT, root, comm); 
     90    MPI_Bcast(displs, ep_size, EP_INT, root, comm); 
    9191 
    92     if(mpi_rank == root_mpi_rank) MPI_Gather_local(&sendcount, 1, MPI_INT, local_recvcounts.data(), root_ep_loc, comm); 
    93     else                          MPI_Gather_local(&sendcount, 1, MPI_INT, local_recvcounts.data(), 0, comm); 
     92    if(mpi_rank == root_mpi_rank) MPI_Gather_local(&sendcount, 1, EP_INT, local_recvcounts.data(), root_ep_loc, comm); 
     93    else                          MPI_Gather_local(&sendcount, 1, EP_INT, local_recvcounts.data(), 0, comm); 
    9494 
    9595 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm.cpp

    r1556 r1642  
    3333    } 
    3434     
    35     MPI_Bcast(mpi_rank_of_leader, 2, MPI_INT, local_leader, local_comm); 
     35    MPI_Bcast(mpi_rank_of_leader, 2, EP_INT, local_leader, local_comm); 
    3636     
    3737    if(mpi_rank_of_leader[0] != mpi_rank_of_leader[1]) 
     
    8686      MPI_Comm_rank(peer_comm, &local_leader_rank_in_peer); 
    8787      ::MPI_Comm_rank(to_mpi_comm(peer_comm->mpi_comm), &local_leader_rank_in_peer_mpi); 
    88       ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD->mpi_comm), &local_leader_rank_in_world); 
     88      ::MPI_Comm_rank(to_mpi_comm(EP_COMM_WORLD->mpi_comm), &local_leader_rank_in_world); 
    8989 
    9090      send_quadruple[0] = ep_size; 
     
    9999      if(remote_leader > local_leader_rank_in_peer) 
    100100      { 
    101         MPI_Isend(send_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request); 
     101        MPI_Isend(send_quadruple, 4, EP_INT, remote_leader, tag, peer_comm, &request); 
    102102        MPI_Wait(&request, &status); 
    103103        
    104         MPI_Irecv(recv_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request); 
     104        MPI_Irecv(recv_quadruple, 4, EP_INT, remote_leader, tag, peer_comm, &request); 
    105105        MPI_Wait(&request, &status); 
    106106      } 
    107107      else 
    108108      { 
    109         MPI_Irecv(recv_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request); 
     109        MPI_Irecv(recv_quadruple, 4, EP_INT, remote_leader, tag, peer_comm, &request); 
    110110        MPI_Wait(&request, &status); 
    111111           
    112         MPI_Isend(send_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request); 
     112        MPI_Isend(send_quadruple, 4, EP_INT, remote_leader, tag, peer_comm, &request); 
    113113        MPI_Wait(&request, &status); 
    114114      } 
     
    123123    } 
    124124 
    125     MPI_Bcast(send_quadruple, 4, MPI_INT, local_leader, local_comm); 
    126     MPI_Bcast(recv_quadruple, 4, MPI_INT, local_leader, local_comm); 
     125    MPI_Bcast(send_quadruple, 4, EP_INT, local_leader, local_comm); 
     126    MPI_Bcast(recv_quadruple, 4, EP_INT, local_leader, local_comm); 
    127127 
    128128    if(!is_local_leader) 
     
    152152 
    153153    int rank_in_world; 
    154     ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD->mpi_comm), &rank_in_world); 
     154    ::MPI_Comm_rank(to_mpi_comm(EP_COMM_WORLD->mpi_comm), &rank_in_world); 
    155155 
    156156    int *ranks_in_world_local  = new int[ep_size]; 
    157157    int *ranks_in_world_remote = new int[remote_ep_size]; 
    158158 
    159     MPI_Allgather(&rank_in_world, 1, MPI_INT, ranks_in_world_local, 1, MPI_INT, local_comm); 
     159    MPI_Allgather(&rank_in_world, 1, EP_INT, ranks_in_world_local, 1, EP_INT, local_comm); 
    160160 
    161161    if(is_local_leader) 
     
    166166      if(remote_leader > local_leader_rank_in_peer) 
    167167      { 
    168         MPI_Isend(ranks_in_world_local,  ep_size, MPI_INT, remote_leader, tag, peer_comm, &request); 
     168        MPI_Isend(ranks_in_world_local,  ep_size, EP_INT, remote_leader, tag, peer_comm, &request); 
    169169        MPI_Wait(&request, &status); 
    170170        
    171         MPI_Irecv(ranks_in_world_remote, remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request); 
     171        MPI_Irecv(ranks_in_world_remote, remote_ep_size, EP_INT, remote_leader, tag, peer_comm, &request); 
    172172        MPI_Wait(&request, &status); 
    173173      } 
    174174      else 
    175175      { 
    176         MPI_Irecv(ranks_in_world_remote, remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request); 
     176        MPI_Irecv(ranks_in_world_remote, remote_ep_size, EP_INT, remote_leader, tag, peer_comm, &request); 
    177177        MPI_Wait(&request, &status); 
    178178           
    179         MPI_Isend(ranks_in_world_local,  ep_size, MPI_INT, remote_leader, tag, peer_comm, &request); 
     179        MPI_Isend(ranks_in_world_local,  ep_size, EP_INT, remote_leader, tag, peer_comm, &request); 
    180180        MPI_Wait(&request, &status); 
    181181      } 
     
    185185    } 
    186186 
    187     MPI_Bcast(ranks_in_world_remote, remote_ep_size, MPI_INT, local_leader, local_comm); 
     187    MPI_Bcast(ranks_in_world_remote, remote_ep_size, EP_INT, local_leader, local_comm); 
    188188 
    189189#ifdef _showinfo 
     
    313313      int *mpi_rank_list = new int[mpi_size]; 
    314314 
    315       ::MPI_Allgather(&ownership, 1, to_mpi_type(MPI_INT), ownership_list, 1, to_mpi_type(MPI_INT), to_mpi_comm(local_comm->mpi_comm)); 
    316       ::MPI_Allgather(&mpi_rank,  1, to_mpi_type(MPI_INT), mpi_rank_list,  1, to_mpi_type(MPI_INT), to_mpi_comm(local_comm->mpi_comm)); 
     315      ::MPI_Allgather(&ownership, 1, to_mpi_type(EP_INT), ownership_list, 1, to_mpi_type(EP_INT), to_mpi_comm(local_comm->mpi_comm)); 
     316      ::MPI_Allgather(&mpi_rank,  1, to_mpi_type(EP_INT), mpi_rank_list,  1, to_mpi_type(EP_INT), to_mpi_comm(local_comm->mpi_comm)); 
    317317 
    318318       
     
    347347      } 
    348348 
    349       ::MPI_Bcast(&local_leader_rank_in_extracted_comm, 1, to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, to_mpi_comm(local_comm->mpi_comm)); 
     349      ::MPI_Bcast(&local_leader_rank_in_extracted_comm, 1, to_mpi_type(EP_INT), local_comm->ep_rank_map->at(local_leader).second, to_mpi_comm(local_comm->mpi_comm)); 
    350350 
    351351      ::MPI_Comm *intracomm = new ::MPI_Comm; 
    352       bool is_real_involved = ownership && extracted_comm != to_mpi_comm(MPI_COMM_NULL->mpi_comm); 
     352      bool is_real_involved = ownership && extracted_comm != to_mpi_comm(EP_COMM_NULL->mpi_comm); 
    353353 
    354354      if(is_real_involved) 
     
    489489    int *remote_rank_info = new int[2*remote_ep_size]; 
    490490 
    491     MPI_Allgather(rank_info, 2, MPI_INT, local_rank_info, 2, MPI_INT, local_comm); 
     491    MPI_Allgather(rank_info, 2, EP_INT, local_rank_info, 2, EP_INT, local_comm); 
    492492 
    493493    if(is_local_leader) 
     
    498498      if(priority) 
    499499      { 
    500         MPI_Isend(local_rank_info, 2*ep_size, MPI_INT, remote_leader, tag, peer_comm, &request); 
     500        MPI_Isend(local_rank_info, 2*ep_size, EP_INT, remote_leader, tag, peer_comm, &request); 
    501501        MPI_Wait(&request, &status); 
    502502        
    503         MPI_Irecv(remote_rank_info, 2*remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request); 
     503        MPI_Irecv(remote_rank_info, 2*remote_ep_size, EP_INT, remote_leader, tag, peer_comm, &request); 
    504504        MPI_Wait(&request, &status); 
    505505      } 
    506506      else 
    507507      { 
    508         MPI_Irecv(remote_rank_info, 2*remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request); 
    509         MPI_Wait(&request, &status); 
    510            
    511         MPI_Isend(local_rank_info, 2*ep_size, MPI_INT, remote_leader, tag, peer_comm, &request); 
    512         MPI_Wait(&request, &status); 
    513       } 
    514     } 
    515  
    516     MPI_Bcast(remote_rank_info, 2*remote_ep_size, MPI_INT, local_leader, local_comm); 
     508        MPI_Irecv(remote_rank_info, 2*remote_ep_size, EP_INT, remote_leader, tag, peer_comm, &request); 
     509        MPI_Wait(&request, &status); 
     510         
     511        MPI_Isend(local_rank_info, 2*ep_size, EP_INT, remote_leader, tag, peer_comm, &request); 
     512        MPI_Wait(&request, &status); 
     513      } 
     514    } 
     515 
     516    MPI_Bcast(remote_rank_info, 2*remote_ep_size, EP_INT, local_leader, local_comm); 
    517517 
    518518    for(int i=0; i<remote_ep_size; i++) 
     
    537537    } 
    538538    */ 
    539      
     539   //MPI_Barrier(*newintercomm);  
     540   //MPI_Barrier(*newintercomm);  
     541   //MPI_Barrier(*newintercomm);  
    540542  
    541543  } 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib.cpp

    r1540 r1642  
    131131  bool valid_type(MPI_Datatype datatype) 
    132132  { 
    133     if(   datatype == MPI_INT  
    134        || datatype == MPI_FLOAT 
    135        || datatype == MPI_DOUBLE  
    136        || datatype == MPI_CHAR  
    137        || datatype == MPI_LONG  
    138        || datatype == MPI_UNSIGNED_LONG 
    139        || datatype == MPI_LONG_LONG) 
     133    if(   datatype == EP_INT  
     134       || datatype == EP_FLOAT 
     135       || datatype == EP_DOUBLE  
     136       || datatype == EP_CHAR  
     137       || datatype == EP_LONG  
     138       || datatype == EP_UNSIGNED_LONG 
     139       || datatype == EP_LONG_LONG) 
    140140    { 
    141141      return true; 
     
    148148  bool valid_op(MPI_Op op) 
    149149  { 
    150     if(   op == MPI_MAX  
    151        || op == MPI_MIN 
    152        || op == MPI_SUM 
    153        || op == MPI_LOR) 
     150    if(   op == EP_MAX  
     151       || op == EP_MIN 
     152       || op == EP_SUM 
     153       || op == EP_LOR) 
    154154    { 
    155155      return true; 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib.hpp

    r1539 r1642  
    5151  int MPI_Imrecv(void *buf, int count, MPI_Datatype datatype, MPI_Message *message, MPI_Request *request); 
    5252 
     53  int my_recv  (void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status); 
     54  int my_irecv (void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request *request); 
    5355 
    5456  int MPI_Test(MPI_Request *request, int *flag, MPI_Status *status); 
    5557  int MPI_Testall(int count, MPI_Request *array_of_requests, int *flag, MPI_Status *array_of_statuses); 
    5658 
     59  int my_test(MPI_Request *request, int *flag, MPI_Status *status); 
     60  int my_testall(int count, MPI_Request *array_of_requests, int *flag, MPI_Status *array_of_statuses); 
     61   
    5762  int MPI_Wait(MPI_Request *request, MPI_Status *status); 
    5863  int MPI_Waitall(int count, MPI_Request *array_of_requests, MPI_Status *array_of_statuses); 
    5964 
     65  int my_wait(MPI_Request *request, MPI_Status *status); 
     66  int my_waitall(int count, MPI_Request *array_of_requests, MPI_Status *array_of_statuses); 
    6067 
    6168  int MPI_Iprobe(int source, int tag, MPI_Comm comm, int *flag, MPI_Status *status); 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_fortran.hpp

    r1369 r1642  
    44#include "ep_type.hpp" 
    55 
    6 namespace ep_lib 
    7 { 
     6//namespace ep_lib 
     7//{ 
    88 
    9   void* EP_Comm_c2f(MPI_Comm comm); 
    10   MPI_Comm EP_Comm_f2c(void* comm); 
    11 } 
     9  void* EP_Comm_c2f(ep_lib::MPI_Comm comm); 
     10  ep_lib::MPI_Comm EP_Comm_f2c(void* comm); 
     11//} 
    1212 
    1313 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_merge.cpp

    r1539 r1642  
    3636    int sum_high; 
    3737     
    38     MPI_Allreduce(&int_high, &sum_high, 1, MPI_INT, MPI_SUM, *newintracomm); 
     38    MPI_Allreduce(&int_high, &sum_high, 1, EP_INT, EP_SUM, *newintracomm); 
    3939 
    4040    if(sum_high==0 || sum_high==ep_size+remote_ep_size) 
     
    5555 
    5656     
    57     MPI_Allgather(my_triple, 3, MPI_INT, my_triple_list, 3, MPI_INT, *newintracomm);  
     57    MPI_Allgather(my_triple, 3, EP_INT, my_triple_list, 3, EP_INT, *newintracomm);  
    5858 
    5959 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_message.cpp

    r1539 r1642  
    147147    { 
    148148      Debug("Message probing for intracomm\n"); 
    149       
     149/*      
    150150      #pragma omp critical (_mpi_call) 
    151151      { 
     
    158158      } 
    159159 
    160        
     160*/     
     161      ::MPI_Improbe(MPI_ANY_SOURCE, MPI_ANY_TAG, to_mpi_comm(comm->mpi_comm), &flag, &message, &status);       
     162 
    161163      if(flag) 
    162164      { 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_mpi.hpp

    r1520 r1642  
    11#ifndef EP_MPI_HPP_INCLUDED 
    22#define EP_MPI_HPP_INCLUDED 
    3  
     3#ifdef _usingEP 
    44#include "ep_type.hpp" 
    5  
     5#endif 
    66MPI_Datatype to_mpi_type(ep_lib::MPI_Datatype type); 
    77MPI_Op       to_mpi_op(ep_lib::MPI_Op op); 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_probe.cpp

    r1539 r1642  
    6868    *flag = false; 
    6969     
    70     Message_Check(comm); 
    71  
    72     #pragma omp flush 
    73  
    7470    #pragma omp critical (_query) 
    7571    for(Message_list::iterator it = comm->ep_comm_ptr->message_queue->begin(); it!= comm->ep_comm_ptr->message_queue->end(); ++it) 
     
    9894      } 
    9995    } 
     96    if(*flag) return 0; 
     97     
     98    Message_Check(comm); 
     99 
     100    #pragma omp flush 
     101 
     102    #pragma omp critical (_query) 
     103    for(Message_list::iterator it = comm->ep_comm_ptr->message_queue->begin(); it!= comm->ep_comm_ptr->message_queue->end(); ++it) 
     104    { 
     105      bool src_matched = src<0? true: (*it)->ep_src == src; 
     106      bool tag_matched = tag<0? true: (*it)->ep_tag == tag; 
     107       
     108      if(src_matched && tag_matched)         
     109      { 
     110        Debug("find message\n"); 
     111          
     112        status->mpi_status = new ::MPI_Status(*static_cast< ::MPI_Status*>((*it)->mpi_status)); 
     113        status->ep_src = (*it)->ep_src; 
     114        status->ep_tag = (*it)->ep_tag; 
     115         
     116        if(comm->is_intercomm) 
     117        { 
     118          for(INTER_RANK_MAP::iterator iter = comm->inter_rank_map->begin(); iter != comm->inter_rank_map->end(); iter++) 
     119          { 
     120            if(iter->second == (*it)->ep_src) status->ep_src=iter->first; 
     121          } 
     122        } 
     123 
     124        *flag = true; 
     125        break; 
     126      } 
     127    } 
     128    if(*flag) return 0; 
    100129  } 
    101130 
     
    129158    *flag = false; 
    130159     
    131     Message_Check(comm); 
    132      
    133     #pragma omp flush 
    134  
    135160    #pragma omp critical (_query) 
    136161    if(! comm->ep_comm_ptr->message_queue->empty()) 
     
    179204      } 
    180205    } 
     206 
     207    if(*flag) return 0; 
     208    
     209    Message_Check(comm); 
     210     
     211    #pragma omp flush 
     212 
     213    #pragma omp critical (_query) 
     214    if(! comm->ep_comm_ptr->message_queue->empty()) 
     215    { 
     216      for(Message_list::iterator it = comm->ep_comm_ptr->message_queue->begin(); it!= comm->ep_comm_ptr->message_queue->end(); ++it) 
     217      { 
     218                                           
     219        bool src_matched = src<0? true: (*it)->ep_src == src; 
     220        bool tag_matched = tag<0? true: (*it)->ep_tag == tag; 
     221         
     222        if(src_matched && tag_matched) 
     223        { 
     224          *flag = true; 
     225 
     226          status->mpi_status = new ::MPI_Status(*static_cast< ::MPI_Status*>((*it)->mpi_status)); 
     227          memcheck("new "<< status->mpi_status << " : in ep_lib::MPI_Improbe, status->mpi_status = new ::MPI_Status"); 
     228          status->ep_src = (*it)->ep_src; 
     229          status->ep_tag = (*it)->ep_tag; 
     230 
     231          (*message)->mpi_message = new ::MPI_Message(*static_cast< ::MPI_Message*>((*it)->mpi_message)); 
     232          memcheck("new "<< (*message)->mpi_message <<" : in ep_lib::MPI_Improbe, (*message)->mpi_message = new ::MPI_Message"); 
     233          (*message)->ep_src = (*it)->ep_src; 
     234          (*message)->ep_tag = (*it)->ep_tag; 
     235                                       
     236 
     237          #pragma omp critical (_query2) 
     238          {               
     239            memcheck("delete "<< (*it)->mpi_message <<" : in ep_lib::Message_Check, delete (*it)->mpi_message"); 
     240            memcheck("delete "<< (*it)->mpi_status <<" : in ep_lib::Message_Check, delete (*it)->mpi_status"); 
     241            memcheck("delete "<< (*it) <<" : in ep_lib::Message_Check, delete (*it)"); 
     242             
     243             
     244            delete (*it)->mpi_message;      
     245            delete (*it)->mpi_status;  
     246            delete *it; 
     247             
     248                        
     249            comm->ep_comm_ptr->message_queue->erase(it); 
     250            memcheck("message_queue["<<mpi_rank<<","<<ep_rank_loc<<"]->size = "<<comm->ep_comm_ptr->message_queue->size()); 
     251            #pragma omp flush 
     252          } 
     253           
     254          break; 
     255        } 
     256 
     257      } 
     258    } 
     259 
     260    if(*flag) return 0; 
     261 
    181262  } 
    182263 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_recv.cpp

    r1539 r1642  
    2222  int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status) 
    2323  { 
    24  
    2524    if(!comm->is_ep) return MPI_Recv_mpi(buf, count, datatype, src, tag, comm, status); 
    2625     
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_reduce.cpp

    r1540 r1642  
    8080      memcpy(recvbuf, comm->my_buffer->void_buffer[0], datasize * count); 
    8181 
    82       if(op == MPI_MAX) 
    83       { 
    84         if(datatype == MPI_INT) 
     82      if(op == EP_MAX) 
     83      { 
     84        if(datatype == EP_INT) 
    8585        { 
    8686          assert(datasize == sizeof(int)); 
     
    9696        } 
    9797 
    98         else if(datatype == MPI_DOUBLE) 
     98        else if(datatype == EP_DOUBLE) 
    9999        { 
    100100          assert(datasize == sizeof(double)); 
     
    103103        } 
    104104 
    105         else if(datatype == MPI_CHAR) 
     105        else if(datatype == EP_CHAR) 
    106106        { 
    107107          assert(datasize == sizeof(char)); 
     
    110110        } 
    111111 
    112         else if(datatype == MPI_LONG) 
     112        else if(datatype == EP_LONG) 
    113113        { 
    114114          assert(datasize == sizeof(long)); 
     
    117117        } 
    118118 
    119         else if(datatype == MPI_UNSIGNED_LONG) 
     119        else if(datatype == EP_UNSIGNED_LONG) 
    120120        { 
    121121          assert(datasize == sizeof(unsigned long)); 
     
    124124        } 
    125125 
    126         else if(datatype == MPI_LONG_LONG_INT) 
     126        else if(datatype == EP_LONG_LONG_INT) 
    127127        { 
    128128          assert(datasize == sizeof(long long)); 
     
    139139      } 
    140140 
    141       else if(op == MPI_MIN) 
    142       { 
    143         if(datatype ==MPI_INT) 
     141      else if(op == EP_MIN) 
     142      { 
     143        if(datatype ==EP_INT) 
    144144        { 
    145145          assert(datasize == sizeof(int)); 
     
    155155        } 
    156156 
    157         else if(datatype == MPI_DOUBLE) 
     157        else if(datatype == EP_DOUBLE) 
    158158        { 
    159159          assert(datasize == sizeof(double)); 
     
    162162        } 
    163163 
    164         else if(datatype == MPI_CHAR) 
     164        else if(datatype == EP_CHAR) 
    165165        { 
    166166          assert(datasize == sizeof(char)); 
     
    169169        } 
    170170 
    171         else if(datatype == MPI_LONG) 
     171        else if(datatype == EP_LONG) 
    172172        { 
    173173          assert(datasize == sizeof(long)); 
     
    176176        } 
    177177 
    178         else if(datatype == MPI_UNSIGNED_LONG) 
     178        else if(datatype == EP_UNSIGNED_LONG) 
    179179        { 
    180180          assert(datasize == sizeof(unsigned long)); 
     
    183183        } 
    184184 
    185         else if(datatype == MPI_LONG_LONG_INT) 
     185        else if(datatype == EP_LONG_LONG_INT) 
    186186        { 
    187187          assert(datasize == sizeof(long long)); 
     
    199199 
    200200 
    201       else if(op == MPI_SUM) 
    202       { 
    203         if(datatype==MPI_INT) 
     201      else if(op == EP_SUM) 
     202      { 
     203        if(datatype==EP_INT) 
    204204        { 
    205205          assert(datasize == sizeof(int)); 
     
    215215        } 
    216216 
    217         else if(datatype == MPI_DOUBLE) 
     217        else if(datatype == EP_DOUBLE) 
    218218        { 
    219219          assert(datasize == sizeof(double)); 
     
    222222        } 
    223223 
    224         else if(datatype == MPI_CHAR) 
     224        else if(datatype == EP_CHAR) 
    225225        { 
    226226          assert(datasize == sizeof(char)); 
     
    229229        } 
    230230 
    231         else if(datatype == MPI_LONG) 
     231        else if(datatype == EP_LONG) 
    232232        { 
    233233          assert(datasize == sizeof(long)); 
     
    236236        } 
    237237 
    238         else if(datatype ==MPI_UNSIGNED_LONG) 
     238        else if(datatype ==EP_UNSIGNED_LONG) 
    239239        { 
    240240          assert(datasize == sizeof(unsigned long)); 
     
    243243        } 
    244244         
    245         else if(datatype ==MPI_LONG_LONG_INT) 
     245        else if(datatype ==EP_LONG_LONG_INT) 
    246246        { 
    247247          assert(datasize == sizeof(long long)); 
     
    258258      } 
    259259 
    260       else if(op == MPI_LOR) 
    261       { 
    262         if(datatype != MPI_INT) 
     260      else if(op == EP_LOR) 
     261      { 
     262        if(datatype != EP_INT) 
    263263          printf("datatype Error, must be MPI_INT\n"); 
    264264        else 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_reduce_scatter.cpp

    r1539 r1642  
    6161 
    6262    int my_recvcount = recvcounts[ep_rank]; 
    63     MPI_Gather_local(&my_recvcount, 1, MPI_INT, local_recvcounts.data(), 0, comm); 
    64     MPI_Bcast_local(local_recvcounts.data(), num_ep, MPI_INT, 0, comm); 
     63    MPI_Gather_local(&my_recvcount, 1, EP_INT, local_recvcounts.data(), 0, comm); 
     64    MPI_Bcast_local(local_recvcounts.data(), num_ep, EP_INT, 0, comm); 
    6565 
    6666    int my_displs = std::accumulate(recvcounts, recvcounts+ep_rank, 0); 
    67     MPI_Gather_local(&my_displs, 1, MPI_INT, local_displs.data(), 0, comm); 
    68     MPI_Bcast_local(local_displs.data(), num_ep, MPI_INT, 0, comm); 
     67    MPI_Gather_local(&my_displs, 1, EP_INT, local_displs.data(), 0, comm); 
     68    MPI_Bcast_local(local_displs.data(), num_ep, EP_INT, 0, comm); 
    6969 
    7070     
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_scan.cpp

    r1540 r1642  
    6060    if(ep_rank_loc == 0 && mpi_rank != 0) 
    6161    { 
    62       if(op == MPI_SUM) 
    63       { 
    64         if(datatype == MPI_INT) 
     62      if(op == EP_SUM) 
     63      { 
     64        if(datatype == EP_INT) 
    6565        { 
    6666          assert(datasize == sizeof(int)); 
     
    6868        } 
    6969           
    70         else if(datatype == MPI_FLOAT) 
     70        else if(datatype == EP_FLOAT) 
    7171        { 
    7272          assert( datasize == sizeof(float)); 
     
    7474        }  
    7575              
    76         else if(datatype == MPI_DOUBLE ) 
     76        else if(datatype == EP_DOUBLE ) 
    7777        { 
    7878          assert( datasize == sizeof(double)); 
     
    8080        } 
    8181       
    82         else if(datatype == MPI_CHAR) 
     82        else if(datatype == EP_CHAR) 
    8383        { 
    8484          assert( datasize == sizeof(char)); 
     
    8686        }  
    8787           
    88         else if(datatype == MPI_LONG) 
     88        else if(datatype == EP_LONG) 
    8989        { 
    9090          assert( datasize == sizeof(long)); 
     
    9393           
    9494             
    95         else if(datatype == MPI_UNSIGNED_LONG) 
     95        else if(datatype == EP_UNSIGNED_LONG) 
    9696        { 
    9797          assert(datasize == sizeof(unsigned long)); 
     
    9999        } 
    100100         
    101         else if(datatype == MPI_LONG_LONG_INT) 
     101        else if(datatype == EP_LONG_LONG_INT) 
    102102        { 
    103103          assert(datasize == sizeof(long long int)); 
     
    112112      } 
    113113 
    114       else if(op == MPI_MAX) 
    115       { 
    116         if(datatype == MPI_INT) 
     114      else if(op == EP_MAX) 
     115      { 
     116        if(datatype == EP_INT) 
    117117        { 
    118118          assert( datasize == sizeof(int)); 
     
    120120        }  
    121121           
    122         else if(datatype == MPI_FLOAT ) 
     122        else if(datatype == EP_FLOAT ) 
    123123        { 
    124124          assert( datasize == sizeof(float)); 
     
    126126        } 
    127127 
    128         else if(datatype == MPI_DOUBLE ) 
     128        else if(datatype == EP_DOUBLE ) 
    129129        { 
    130130          assert( datasize == sizeof(double)); 
     
    132132        } 
    133133       
    134         else if(datatype == MPI_CHAR ) 
     134        else if(datatype == EP_CHAR ) 
    135135        { 
    136136          assert(datasize == sizeof(char)); 
     
    138138        } 
    139139       
    140         else if(datatype == MPI_LONG) 
     140        else if(datatype == EP_LONG) 
    141141        { 
    142142          assert( datasize == sizeof(long)); 
     
    144144        }  
    145145             
    146         else if(datatype == MPI_UNSIGNED_LONG) 
     146        else if(datatype == EP_UNSIGNED_LONG) 
    147147        { 
    148148          assert( datasize == sizeof(unsigned long)); 
     
    150150        }  
    151151             
    152         else if(datatype == MPI_LONG_LONG_INT) 
     152        else if(datatype == EP_LONG_LONG_INT) 
    153153        { 
    154154          assert(datasize == sizeof(long long int)); 
     
    163163      } 
    164164 
    165       else if(op == MPI_MIN) 
    166       { 
    167         if(datatype == MPI_INT ) 
     165      else if(op == EP_MIN) 
     166      { 
     167        if(datatype == EP_INT ) 
    168168        { 
    169169          assert (datasize == sizeof(int)); 
     
    171171        } 
    172172           
    173         else if(datatype == MPI_FLOAT ) 
     173        else if(datatype == EP_FLOAT ) 
    174174        { 
    175175          assert( datasize == sizeof(float)); 
     
    177177        } 
    178178              
    179         else if(datatype == MPI_DOUBLE ) 
     179        else if(datatype == EP_DOUBLE ) 
    180180        { 
    181181          assert( datasize == sizeof(double)); 
     
    183183        } 
    184184       
    185         else if(datatype == MPI_CHAR ) 
     185        else if(datatype == EP_CHAR ) 
    186186        { 
    187187          assert( datasize == sizeof(char)); 
     
    189189        } 
    190190       
    191         else if(datatype == MPI_LONG ) 
     191        else if(datatype == EP_LONG ) 
    192192        {  
    193193          assert( datasize == sizeof(long)); 
     
    195195        } 
    196196             
    197         else if(datatype == MPI_UNSIGNED_LONG ) 
     197        else if(datatype == EP_UNSIGNED_LONG ) 
    198198        { 
    199199          assert( datasize == sizeof(unsigned long)); 
     
    201201        } 
    202202             
    203         else if(datatype == MPI_LONG_LONG_INT) 
     203        else if(datatype == EP_LONG_LONG_INT) 
    204204        { 
    205205          assert(datasize == sizeof(long long int)); 
     
    235235 
    236236 
    237     if(op == MPI_SUM) 
    238     { 
    239       if(datatype == MPI_INT ) 
     237    if(op == EP_SUM) 
     238    { 
     239      if(datatype == EP_INT ) 
    240240      { 
    241241        assert (datasize == sizeof(int)); 
     
    244244      } 
    245245      
    246       else if(datatype == MPI_FLOAT ) 
     246      else if(datatype == EP_FLOAT ) 
    247247      { 
    248248        assert(datasize == sizeof(float)); 
     
    252252       
    253253 
    254       else if(datatype == MPI_DOUBLE ) 
     254      else if(datatype == EP_DOUBLE ) 
    255255      { 
    256256        assert(datasize == sizeof(double)); 
     
    259259      } 
    260260 
    261       else if(datatype == MPI_CHAR ) 
     261      else if(datatype == EP_CHAR ) 
    262262      { 
    263263        assert(datasize == sizeof(char)); 
     
    266266      } 
    267267 
    268       else if(datatype == MPI_LONG ) 
     268      else if(datatype == EP_LONG ) 
    269269      { 
    270270        assert(datasize == sizeof(long)); 
     
    273273      } 
    274274 
    275       else if(datatype == MPI_UNSIGNED_LONG ) 
     275      else if(datatype == EP_UNSIGNED_LONG ) 
    276276      { 
    277277        assert(datasize == sizeof(unsigned long)); 
     
    280280      } 
    281281       
    282       else if(datatype == MPI_LONG_LONG_INT ) 
     282      else if(datatype == EP_LONG_LONG_INT ) 
    283283      { 
    284284        assert(datasize == sizeof(long long int)); 
     
    296296    } 
    297297 
    298     else if(op == MPI_MAX) 
    299     { 
    300       if(datatype == MPI_INT) 
     298    else if(op == EP_MAX) 
     299    { 
     300      if(datatype == EP_INT) 
    301301      { 
    302302        assert(datasize == sizeof(int)); 
     
    305305      } 
    306306 
    307       else if(datatype == MPI_FLOAT ) 
     307      else if(datatype == EP_FLOAT ) 
    308308      { 
    309309        assert(datasize == sizeof(float)); 
     
    312312      } 
    313313 
    314       else if(datatype == MPI_DOUBLE ) 
     314      else if(datatype == EP_DOUBLE ) 
    315315      { 
    316316        assert(datasize == sizeof(double)); 
     
    319319      } 
    320320 
    321       else if(datatype == MPI_CHAR ) 
     321      else if(datatype == EP_CHAR ) 
    322322      { 
    323323        assert(datasize == sizeof(char)); 
     
    326326      } 
    327327 
    328       else if(datatype == MPI_LONG ) 
     328      else if(datatype == EP_LONG ) 
    329329      { 
    330330        assert(datasize == sizeof(long)); 
     
    333333      } 
    334334 
    335       else if(datatype == MPI_UNSIGNED_LONG ) 
     335      else if(datatype == EP_UNSIGNED_LONG ) 
    336336      { 
    337337        assert(datasize == sizeof(unsigned long)); 
     
    340340      } 
    341341      
    342       else if(datatype == MPI_LONG_LONG_INT ) 
     342      else if(datatype == EP_LONG_LONG_INT ) 
    343343      { 
    344344        assert(datasize == sizeof(long long int)); 
     
    355355    } 
    356356 
    357     else if(op == MPI_MIN) 
    358     { 
    359       if(datatype == MPI_INT ) 
     357    else if(op == EP_MIN) 
     358    { 
     359      if(datatype == EP_INT ) 
    360360      { 
    361361        assert(datasize == sizeof(int)); 
     
    364364      } 
    365365 
    366       else if(datatype == MPI_FLOAT ) 
     366      else if(datatype == EP_FLOAT ) 
    367367      { 
    368368        assert(datasize == sizeof(float)); 
     
    371371      } 
    372372 
    373       else if(datatype == MPI_DOUBLE ) 
     373      else if(datatype == EP_DOUBLE ) 
    374374      { 
    375375        assert(datasize == sizeof(double)); 
     
    378378      } 
    379379 
    380       else if(datatype == MPI_CHAR ) 
     380      else if(datatype == EP_CHAR ) 
    381381      { 
    382382        assert(datasize == sizeof(char)); 
     
    385385      } 
    386386 
    387       else if(datatype == MPI_LONG ) 
     387      else if(datatype == EP_LONG ) 
    388388      { 
    389389        assert(datasize == sizeof(long)); 
     
    392392      } 
    393393 
    394       else if(datatype == MPI_UNSIGNED_LONG ) 
     394      else if(datatype == EP_UNSIGNED_LONG ) 
    395395      { 
    396396        assert(datasize == sizeof(unsigned long)); 
     
    399399      } 
    400400 
    401       else if(datatype == MPI_LONG_LONG_INT ) 
     401      else if(datatype == EP_LONG_LONG_INT ) 
    402402      { 
    403403        assert(datasize == sizeof(long long int)); 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_scatter.cpp

    r1539 r1642  
    7373    std::vector<int>ranks(ep_size); 
    7474 
    75     if(mpi_rank == root_mpi_rank) MPI_Gather_local(&ep_rank, 1, MPI_INT, local_ranks.data(), root_ep_loc, comm); 
    76     else                          MPI_Gather_local(&ep_rank, 1, MPI_INT, local_ranks.data(), 0, comm); 
     75    if(mpi_rank == root_mpi_rank) MPI_Gather_local(&ep_rank, 1, EP_INT, local_ranks.data(), root_ep_loc, comm); 
     76    else                          MPI_Gather_local(&ep_rank, 1, EP_INT, local_ranks.data(), 0, comm); 
    7777 
    7878 
     
    9191        displs[i] = displs[i-1] + recvcounts[i-1]; 
    9292 
    93       ::MPI_Gatherv(local_ranks.data(), num_ep, to_mpi_type(MPI_INT), ranks.data(), recvcounts.data(), displs.data(), to_mpi_type(MPI_INT), root_mpi_rank, to_mpi_comm(comm->mpi_comm)); 
     93      ::MPI_Gatherv(local_ranks.data(), num_ep, to_mpi_type(EP_INT), ranks.data(), recvcounts.data(), displs.data(), to_mpi_type(EP_INT), root_mpi_rank, to_mpi_comm(comm->mpi_comm)); 
    9494    } 
    9595 
     
    109109    { 
    110110      int local_sendcount = num_ep * count; 
    111       ::MPI_Gather(&local_sendcount, 1, to_mpi_type(MPI_INT), recvcounts.data(), 1, to_mpi_type(MPI_INT), root_mpi_rank, to_mpi_comm(comm->mpi_comm)); 
     111      ::MPI_Gather(&local_sendcount, 1, to_mpi_type(EP_INT), recvcounts.data(), 1, to_mpi_type(EP_INT), root_mpi_rank, to_mpi_comm(comm->mpi_comm)); 
    112112       
    113113      if(is_root) for(int i=1; i<mpi_size; i++) displs[i] = displs[i-1] + recvcounts[i-1]; 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_scatterv.cpp

    r1539 r1642  
    7676    std::vector<int>ranks(ep_size); 
    7777 
    78     if(mpi_rank == root_mpi_rank) MPI_Gather_local(&ep_rank, 1, MPI_INT, local_ranks.data(), root_ep_loc, comm); 
    79     else                          MPI_Gather_local(&ep_rank, 1, MPI_INT, local_ranks.data(), 0, comm); 
     78    if(mpi_rank == root_mpi_rank) MPI_Gather_local(&ep_rank, 1, EP_INT, local_ranks.data(), root_ep_loc, comm); 
     79    else                          MPI_Gather_local(&ep_rank, 1, EP_INT, local_ranks.data(), 0, comm); 
    8080 
    8181 
     
    9494        my_displs[i] = my_displs[i-1] + recvcounts[i-1]; 
    9595 
    96       ::MPI_Gatherv(local_ranks.data(), num_ep, to_mpi_type(MPI_INT), ranks.data(), recvcounts.data(), my_displs.data(), to_mpi_type(MPI_INT), root_mpi_rank, to_mpi_comm(comm->mpi_comm)); 
     96      ::MPI_Gatherv(local_ranks.data(), num_ep, to_mpi_type(EP_INT), ranks.data(), recvcounts.data(), my_displs.data(), to_mpi_type(EP_INT), root_mpi_rank, to_mpi_comm(comm->mpi_comm)); 
    9797    } 
    9898 
     
    112112    void* local_sendbuf; 
    113113    int local_sendcount; 
    114     if(mpi_rank == root_mpi_rank) MPI_Reduce_local(&recvcount, &local_sendcount, 1, MPI_INT, MPI_SUM, root_ep_loc, comm); 
    115     else                          MPI_Reduce_local(&recvcount, &local_sendcount, 1, MPI_INT, MPI_SUM, 0, comm); 
     114    if(mpi_rank == root_mpi_rank) MPI_Reduce_local(&recvcount, &local_sendcount, 1, EP_INT, EP_SUM, root_ep_loc, comm); 
     115    else                          MPI_Reduce_local(&recvcount, &local_sendcount, 1, EP_INT, EP_SUM, 0, comm); 
    116116 
    117117    if(is_master)  
     
    119119      local_sendbuf = new void*[datasize * local_sendcount]; 
    120120  
    121       ::MPI_Gather(&local_sendcount, 1, to_mpi_type(MPI_INT), recvcounts.data(), 1, to_mpi_type(MPI_INT), root_mpi_rank, to_mpi_comm(comm->mpi_comm)); 
     121      ::MPI_Gather(&local_sendcount, 1, to_mpi_type(EP_INT), recvcounts.data(), 1, to_mpi_type(EP_INT), root_mpi_rank, to_mpi_comm(comm->mpi_comm)); 
    122122 
    123123      if(is_root) for(int i=1; i<mpi_size; i++) my_displs[i] = my_displs[i-1] + recvcounts[i-1]; 
     
    129129    std::vector<int>local_displs(num_ep, 0); 
    130130 
    131     MPI_Gather_local(&recvcount, 1, MPI_INT, local_sendcounts.data(), 0, comm); 
    132     MPI_Bcast_local(local_sendcounts.data(), num_ep, MPI_INT, 0, comm); 
     131    MPI_Gather_local(&recvcount, 1, EP_INT, local_sendcounts.data(), 0, comm); 
     132    MPI_Bcast_local(local_sendcounts.data(), num_ep, EP_INT, 0, comm); 
    133133    for(int i=1; i<num_ep; i++) 
    134134      local_displs[i] = local_displs[i-1] + local_sendcounts[i-1]; 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_split.cpp

    r1539 r1642  
    5454    vector<int> all_color_loc(num_ep); 
    5555 
    56     MPI_Allgather(&color, 1, MPI_INT, all_color.data(), 1, MPI_INT, comm); 
    57     MPI_Allgather_local(&color, 1, MPI_INT, all_color_loc.data(), comm); 
     56    MPI_Allgather(&color, 1, EP_INT, all_color.data(), 1, EP_INT, comm); 
     57    MPI_Allgather_local(&color, 1, EP_INT, all_color_loc.data(), comm); 
    5858 
    5959    list<int> color_list(all_color.begin(), all_color.end()); 
     
    106106     
    107107 
    108     MPI_Allgather(&key, 1, MPI_INT, all_key.data(),1, MPI_INT, comm); 
    109     MPI_Allgather_local(&key, 1, MPI_INT, all_key_loc.data(), comm); 
     108    MPI_Allgather(&key, 1, EP_INT, all_key.data(),1, EP_INT, comm); 
     109    MPI_Allgather_local(&key, 1, EP_INT, all_key_loc.data(), comm); 
    110110     
    111111    vector<int> all_ep_rank(ep_size); 
     
    115115    vector<int> colored_ep_rank_loc[num_color]; 
    116116     
    117     MPI_Allgather(&ep_rank, 1, MPI_INT, all_ep_rank.data(),1, MPI_INT, comm); 
    118     MPI_Allgather_local(&ep_rank, 1, MPI_INT, all_ep_rank_loc.data(), comm); 
     117    MPI_Allgather(&ep_rank, 1, EP_INT, all_ep_rank.data(),1, EP_INT, comm); 
     118    MPI_Allgather_local(&ep_rank, 1, EP_INT, all_ep_rank_loc.data(), comm); 
    119119 
    120120    for(int i=0; i<num_ep; i++) 
     
    270270        if(new_ep_rank_loc == 0) my_triple_vector_recv.resize(3*new_ep_size); 
    271271         
    272         MPI_Gather_local(my_triple, 3, MPI_INT, my_triple_vector.data(), 0, *newcomm); 
     272        MPI_Gather_local(my_triple, 3, EP_INT, my_triple_vector.data(), 0, *newcomm); 
    273273         
    274274        if(new_ep_rank_loc == 0) 
     
    277277          int *displs = new int[new_mpi_size]; 
    278278          int new_num_epx3 = new_num_ep * 3; 
    279           ::MPI_Allgather(&new_num_epx3, 1, to_mpi_type(MPI_INT), recvcounts, 1, to_mpi_type(MPI_INT), to_mpi_comm((*newcomm)->mpi_comm)); 
     279          ::MPI_Allgather(&new_num_epx3, 1, to_mpi_type(EP_INT), recvcounts, 1, to_mpi_type(EP_INT), to_mpi_comm((*newcomm)->mpi_comm)); 
    280280          displs[0]=0; 
    281281          for(int i=1; i<new_mpi_size; i++) 
    282282            displs[i] = displs[i-1] + recvcounts[i-1]; 
    283283              
    284           ::MPI_Allgatherv(my_triple_vector.data(), 3*new_num_ep, to_mpi_type(MPI_INT), my_triple_vector_recv.data(), recvcounts, displs, to_mpi_type(MPI_INT), to_mpi_comm((*newcomm)->mpi_comm)); 
     284          ::MPI_Allgatherv(my_triple_vector.data(), 3*new_num_ep, to_mpi_type(EP_INT), my_triple_vector_recv.data(), recvcounts, displs, to_mpi_type(EP_INT), to_mpi_comm((*newcomm)->mpi_comm)); 
    285285           
    286286          for(int i=0; i<new_ep_size; i++) 
    287287          { 
    288             (*newcomm)->ep_comm_ptr->comm_list[0]->ep_rank_map->insert(std::pair< int, std::pair<int,int> >(my_triple_vector_recv[3*i], my_triple_vector_recv[3*i+1], my_triple_vector_recv[3*i+2])); 
     288            //(*newcomm)->ep_comm_ptr->comm_list[0]->ep_rank_map->insert(std::pair< int, std::pair<int,int> >(my_triple_vector_recv[3*i], my_triple_vector_recv[3*i+1], my_triple_vector_recv[3*i+2])); 
     289            (*((*newcomm)->ep_comm_ptr->comm_list[0]->ep_rank_map)) [ my_triple_vector_recv[3*i] ] = std::make_pair(my_triple_vector_recv[3*i+1], my_triple_vector_recv[3*i+2]); 
    289290          } 
    290291           
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_type.hpp

    r1539 r1642  
    6868     
    6969    MPI_Fint() {} 
    70     MPI_Fint(void* fint); 
     70    MPI_Fint(void* fint) {mpi_fint = fint;}; 
    7171                                  
    7272  }; 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_win.cpp

    r1521 r1642  
    2121 
    2222    int num_ep_max; 
    23     MPI_Allreduce(&num_ep, &num_ep_max, 1, MPI_INT, MPI_MAX, comm); 
     23    MPI_Allreduce(&num_ep, &num_ep_max, 1, EP_INT, EP_MAX, comm); 
    2424 
    2525    assert(num_ep_max > 1); 
     
    8888     
    8989    int num_ep_max; 
    90     MPI_Allreduce(&num_ep, &num_ep_max, 1, MPI_INT, MPI_MAX, (*win)->comm); 
     90    MPI_Allreduce(&num_ep, &num_ep_max, 1, EP_INT, EP_MAX, (*win)->comm); 
    9191 
    9292    //printf("rank_loc = %d, thread_num = %d, num_ep_max = %d\n", rank_loc, omp_get_thread_num(), num_ep_max); 
     
    139139     
    140140    int num_ep_max; 
    141     MPI_Allreduce(&num_ep, &num_ep_max, 1, MPI_INT, MPI_MAX, win->comm); 
     141    MPI_Allreduce(&num_ep, &num_ep_max, 1, EP_INT, EP_MAX, win->comm); 
    142142 
    143143    if(num_ep == 1) 
Note: See TracChangeset for help on using the changeset viewer.