Mise à jour terminée. Pour connaître les apports de la version 13.8.4 par rapport à notre ancienne version vous pouvez lire les "Release Notes" suivantes :
https://about.gitlab.com/releases/2021/02/11/security-release-gitlab-13-8-4-released/
https://about.gitlab.com/releases/2021/02/05/gitlab-13-8-3-released/

dmesh_adapt_part.c 52.7 KB
Newer Older
PRUVOST Florent's avatar
PRUVOST Florent committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*  Copyright 2012-2017 Inria
** This file is part of the PaMPA software package for parallel
** mesh partitioning and adaptation.
**
** PaMPA is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** any later version.
**
** PaMPA is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** In this respect, the user's attention is drawn to the risks associated
** with loading, using, modifying and/or developing or reproducing the
** software by the user in light of its specific status of free software,
** that may mean that it is complicated to manipulate, and that also
** therefore means that it is reserved for developers and experienced
** professionals having in-depth computer knowledge. Users are therefore
** encouraged to load and test the software's suitability as regards
** their requirements in conditions enabling the security of their
** systems and/or data to be ensured and, more generally, to use and
** operate it in the same conditions as regards security.
**
** The fact that you are presently reading this means that you have had
** knowledge of the GPLv3 license and that you accept its terms.
*/
Cédric Lachat's avatar
Cédric Lachat committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256
/************************************************************/
//!
//!   \file        dmesh_adapt_part.c
//!
//!   \authors     Cedric Lachat
//!
//!
//!   \date        Version 1.0: from:  6 Dec 2012
//!                             to:   22 Sep 2017
//!
/************************************************************/

#define DMESH
#define DMESH_ADAPT
#ifdef PAMPA_TIME_CHECK2
#define PAMPA_TIME_CHECK
#endif /* PAMPA_TIME_CHECK2 */
//#define PAMPA_DEBUG_GRAPH
//#define PAMPA_DEBUG_DMESH_SAVE

#include "module.h"
#include "common.h"
#include "comm.h"
#include "dvalues.h"
#include "dmesh.h"
#include "values.h"
#include "mesh.h"
#include "smesh.h"
#include "pampa.h"
#include "pampa.h"
#include <math.h>

#include <ptscotch.h>
#include "dmesh_adapt.h"
#include "dmesh_adapt_common.h"
#include "dmesh_dgraph.h"
#include "dmesh_gather_induce_multiple.h"
#include "dmesh_rebuild.h"
#include "dmesh_allreduce.h"
#include "dmesh_zone_dist.h"


DMESHALLREDUCEMINMAXOP (3, 3)

typedef struct VertLoad_ {
  Gnum vertnum;
  Gnum loadval;
  Gnum edgenum;
} VertLoad;

/** XXX
 ** It returns:
 ** - 0   : on success.
 ** - !0  : on error.
 */

  int
dmeshAdaptPart (
    Dmesh * const    srcmeshptr,              /**< mesh */
    PAMPA_AdaptInfo * const infoptr,
	Dmesh * const    dstmeshptr)
{
#ifdef PAMPA_DEBUG_ADAPT_SAVE3
  MPI_Comm comm1p;
#endif /* PAMPA_DEBUG_ADAPT_SAVE3 */
  Dmesh indmeshdat;
  Dmesh * orgmeshptr;
  SCOTCH_Dgraph dgrfdat;
  SCOTCH_Dgraph bgrfdat; /* Band graph */
  SCOTCH_Strat  strtdat; 
  Gnum * restrict rmshloctax;
  Gnum rmshlocnbr;
  Gnum rmshglbnbr;
  Gnum rmshlocnb2;
  Gnum rmshglbnb2;
  Gnum enodlocnbr;
  Gnum enodglbnbr;
  //Gnum rmshglbnb2;
  //Gnum rmshglbnb3;
  Gnum bvellocsum;
  Gnum bvelglbsum;
  Gnum baseval;
  Gnum vertlocmax;
  Gnum coarval;
  Gnum coarnbr;
  double coarrat;
  Gnum ballsi2;
  Gnum vertlocnum;
  Gnum vertlocnnd;
  Gnum dvrtlocnbr;
  Gnum emraval;
  Gnum switval;
  Gnum cvrtglbnbr;
  Gnum ibndval;
  int cheklocval;
  Gnum * restrict paroloctax;
  Gnum * restrict vmloloctab;
  Gnum * restrict cprcvrttab;
  Gnum * restrict srcprocvrttab;
  MPI_Comm proccomm;
#ifdef PAMPA_DEBUG_DMESH_SAVE
  static Gnum wmshcnt = 0;
#endif /* PAMPA_DEBUG_DMESH_SAVE */

  //rmshglbnb2 = 
  //  rmshglbnb3 = -1;
#ifdef PAMPA_INFO_ADAPT
  infoPrint ("*******************\n\nPart\n\n*******************");
#endif /* PAMPA_INFO_ADAPT */
  orgmeshptr = srcmeshptr;
  cheklocval = 0;
  coarnbr = 1;
  coarrat = 1;
  switval = 1;
  for (coarval = 1, ballsi2 = 1; ballsi2 < infoptr->ballsiz; coarval ++, ballsi2 <<= 1);

  baseval = orgmeshptr->baseval;
  proccomm = orgmeshptr->proccomm;
#ifdef PAMPA_DEBUG_ADAPT_SAVE3
  MPI_Comm_split(proccomm, orgmeshptr->proclocnum, 0, &comm1p);
#endif /* PAMPA_DEBUG_ADAPT_SAVE3 */

  CHECK_FERR (dmeshInit (&indmeshdat, proccomm), proccomm);
  CHECK_FERR (SCOTCH_stratInit (&strtdat), proccomm);
  CHECK_FERR (dmeshDgraphInit (orgmeshptr, &dgrfdat), proccomm);
  CHECK_FERR (SCOTCH_dgraphInit (&bgrfdat, orgmeshptr->proccomm), proccomm);
  CHECK_VERR (cheklocval, proccomm);

  infoptr->iitenum = 1;

  if (memAllocGroup ((void **) (void *)
          &cprcvrttab, (size_t) ((orgmeshptr->procglbnbr + 1) * sizeof (Gnum)),
        NULL) == NULL) {
    errorPrint ("Out of memory");
    cheklocval = 1;
  }
  CHECK_VERR (cheklocval, proccomm);

  cvrtglbnbr = 0;
  ibndval = infoptr->ibndval;
  while (1) {
  //while (infoptr->iitenum < 10) {
	Gnum dvrtlocbas;
	Gnum bvrtlocnbr;
	Gnum bvrtglbnbr;
	Gnum bvrtlocnum;
	Gnum bvrtlocnnd;
	Gnum bvrtgstnbr;
	Gnum bvrtgstmax;
	Gnum cvrtgstnbr;
	Gnum cvrtlocnbr;
	Gnum cvrtlocnum;
	Gnum cvrtlocnnd;
	Gnum edgelocnum;
	Gnum partlocidx;
	Gnum meshlocnbr;
	Gnum meshlocnum;
	Gnum fronlocidx;
        Gnum nodeent;
	int procngbnum;
  	Gnum * restrict srcpartloctax;
	Gnum * restrict bvlbloctax;
	Gnum * restrict rmshloctx2;
	Gnum * restrict bvelloctax;
	Gnum * restrict dvelloctax;
	double * restrict dvelloctx2;
	Gnum * restrict vnumgsttax;
	Gnum * restrict bnumgsttax;
	Gnum * restrict bvrtloctax;
	Gnum * restrict bvndloctax;
	Gnum * restrict bedggsttax;
	Gnum * restrict cvelloctab;
	Gnum * restrict parttax;
	VertLoad * restrict veloglbtax;
	Mesh * imshloctab;
	Mesh * omshloctab;

        nodeent = orgmeshptr->enttglbnbr - (1 - baseval); // XXX temporaire, récupérer la valeur de data passé en argument

	CHECK_FERR (dmeshValueData (orgmeshptr, baseval, PAMPA_TAG_REMESH, NULL, NULL, (void **) &rmshloctax), proccomm);
	rmshloctax -= baseval;
        CHECK_FERR (PAMPA_dmeshHaloValue ((PAMPA_Dmesh *) orgmeshptr, baseval, PAMPA_TAG_REMESH), proccomm);
      // XXX début temporaire
//#define PAMPA_DEBUG_DMESH_SAVE
      // XXX fin temporaire
#ifdef PAMPA_DEBUG_DMESH_SAVE
      //// XXX début temporaire
      //  if (infoptr->eitenum == 2)
      //// XXX fin temporaire
        {
          char s1[50];
          if (memAllocGroup ((void **) (void *)
                &vnumgsttax, (size_t) (orgmeshptr->enttloctax[baseval]->vgstlocnbr * sizeof (Gnum)),
                &parttax,    (size_t) (sizeof (Gnum)),
                NULL) == NULL) {
            errorPrint ("Out of memory");
            cheklocval = 1;
          }
          CHECK_VERR (cheklocval, proccomm);
          vnumgsttax -= baseval;
          parttax -= baseval;

          memSet (vnumgsttax + baseval, ~0, orgmeshptr->enttloctax[baseval]->vgstlocnbr * sizeof (Gnum));
          for (vertlocnum = baseval, vertlocnnd = orgmeshptr->enttloctax[baseval]->vertlocnbr + baseval; vertlocnum < vertlocnnd; vertlocnum ++)
            if (rmshloctax[vertlocnum] == PAMPA_TAG_VERT_REMESH)
              vnumgsttax[vertlocnum] = 0;
          //for (procngbnum = 0; procngbnum < orgmeshptr->procglbnbr; procngbnum ++) 
            parttax[baseval] = 0;

          imshloctab = NULL;
          meshlocnbr = -1; // FIXME l'allocation de imshloctab ne devrait pas être faite ici ?
          CHECK_FERR (dmeshGatherInduceMultiple (orgmeshptr, 0, 1, vnumgsttax, parttax + baseval, &meshlocnbr, &imshloctab), proccomm);
          if (meshlocnbr > 0) {
            sprintf (s1, "dmesh-adapt-rmsh1-%d-%d.mesh", infoptr->eitenum, infoptr->iitenum);
            CHECK_FERR (infoptr->EXT_meshSave((PAMPA_Mesh *) (imshloctab), 1, infoptr->dataptr, NULL, s1), proccomm);

            meshExit (imshloctab);
          }
          memFree (imshloctab);
          memFreeGroup (vnumgsttax + baseval);
        }
#endif /* PAMPA_DEBUG_DMESH_SAVE */
      // XXX début temporaire
//#undef PAMPA_DEBUG_DMESH_SAVE
      // XXX fin temporaire


	vertlocmax = orgmeshptr->enttloctax[baseval]->vertlocnbr + baseval - 1;
	for (rmshlocnbr = 0, vertlocnum = baseval; vertlocnum <= vertlocmax; vertlocnum ++) {
	  if (rmshloctax[vertlocnum] == PAMPA_TAG_VERT_REMESH)
		rmshlocnbr ++;
        }

  	if (commAllreduce (&rmshlocnbr, &rmshglbnbr, 1, GNUM_MPI, MPI_SUM, proccomm) != MPI_SUCCESS) {
      errorPrint ("communication error");
	  cheklocval = 1;
  	}
	CHECK_VERR (cheklocval, proccomm);
//#ifndef PAMPA_INFO_ADAPT
        if (orgmeshptr->proclocnum == 0) {
//#endif /* PAMPA_INFO_ADAPT */
        infoPrint ("-- Iteration number: %d", infoptr->iitenum);
        infoPrint ("Number of elements to be remeshed before growing band: %d", rmshglbnbr);
//#ifndef PAMPA_INFO_ADAPT
        }
//#endif /* PAMPA_INFO_ADAPT */
        //rmshglbnb3 = rmshglbnb2;
        //rmshglbnb2 = rmshglbnbr;

	//if ((rmshglbnbr == 0) || (infoptr->iitenum > 2)) {//CHANGER NB ITER ICI --- CECILE
	if (rmshglbnbr == 0) {
          CHECK_FERR (dmeshDgraphFree (&dgrfdat), proccomm);
	  break;
        }

	// XXX ne devrait-on pas faire cette alloc une bonne fois pour toutes les
	// itérations ?
  	if (memAllocGroup ((void **) (void *)
		  &rmshloctx2, (size_t) (orgmeshptr->enttloctax[baseval]->vgstlocnbr * sizeof (Gnum)),
		  &dvelloctax, (size_t) (orgmeshptr->enttloctax[baseval]->vertlocnbr * sizeof (Gnum)),
          NULL) == NULL) {
      errorPrint ("Out of memory");
      cheklocval = 1;
  	}
  	CHECK_VERR (cheklocval, proccomm);
  	rmshloctx2 -= baseval;
  	dvelloctax -= baseval;
        
        CHECK_FERR (dmeshValueData (orgmeshptr, baseval, PAMPA_TAG_WEIGHT, NULL, NULL, (void **) &dvelloctx2), proccomm);
        dvelloctx2 -= baseval;

        memCpy (rmshloctx2 + baseval, rmshloctax + baseval, orgmeshptr->enttloctax[baseval]->vertlocnbr * sizeof (Gnum));

        //if (infoptr->iitenum > 1) 
        CHECK_FERR (infoptr->EXT_dmeshBand ((PAMPA_Dmesh *) orgmeshptr, infoptr->dataptr, rmshloctx2 + baseval, ibndval), proccomm);

        for (rmshlocnb2 = 0, vertlocnum = baseval; vertlocnum <= vertlocmax; vertlocnum ++)
          //rmshlocnb2 += ceil (dvelloctx2[vertlocnum]);
          if (rmshloctx2[vertlocnum] == PAMPA_TAG_VERT_REMESH)
            rmshlocnb2 ++;

        if (commAllreduce (&rmshlocnb2, &rmshglbnb2, 1, GNUM_MPI, MPI_SUM, proccomm) != MPI_SUCCESS) {
          errorPrint ("communication error");
          cheklocval = 1;
        }
        CHECK_VERR (cheklocval, proccomm);

	////printf("loc %d\n",enodlocnbr);
        //CHECK_VDBG (cheklocval, proccomm);
        //if (commAllreduce (&enodlocnbr, &enodglbnbr, 1, GNUM_MPI, MPI_SUM, proccomm) != MPI_SUCCESS) {
        //  errorPrint ("communication error");
        //  cheklocval = 1;
        //}
        //CHECK_VERR (cheklocval, proccomm);

        //if (orgmeshptr->proclocnum == 0)
	//printf("npcible %d ntetra %d\n",enodglbnbr, rmshglbnbr);
        //cvrtglbnbr = ((rmshglbnbr / 6) > 10000) ? MAX((enodglbnbr - orgmeshptr->enttloctax[baseval]->vertglbnbr / 6) / 300000, rmshglbnbr / 6000000): 1;
        double cond, val1, val2;
        cond = 10000;
        //cond = 100;
        if (infoptr->iitenum > 2) 
          if ((infoptr->enodglbnbr / (orgmeshptr->enttloctax[baseval]->vertglbnbr / 6)) > 2)
            infoptr->enodglbnbr = MAX (orgmeshptr->enttloctax[baseval]->vertglbnbr / 3, infoptr->enodglbnbr / 2);
          else if ((1.1 * infoptr->enodglbnbr / (orgmeshptr->enttloctax[baseval]->vertglbnbr / 6)) > 1)
            infoptr->enodglbnbr =
              ((1.1 * orgmeshptr->enttloctax[baseval]->vertglbnbr / 6) > (0.8 * infoptr->enodglbnbr)) ?
              1.1 * orgmeshptr->enttloctax[baseval]->vertglbnbr / 6 :
              0.8 * infoptr->enodglbnbr;

        val1 = (1.0 * infoptr->enodglbnbr - (1.0 * orgmeshptr->enttloctax[baseval]->vertglbnbr - rmshglbnb2) / 6) / 250000;
        //val1 = (1.0 * infoptr->enodglbnbr - (1.0 * orgmeshptr->enttloctax[baseval]->vertglbnbr - rmshglbnb2) / 6) / 2500;
        val2 = 1.0 * rmshglbnb2 / 1000000;
        cvrtglbnbr = ((1.0 * rmshglbnb2 / 6) > cond) ? MAX(ceil(val1), ceil(val2)) : 1;
        // XXX tmp
        //if (infoptr->iitenum == 1)
        //cvrtglbnbr = 10 / infoptr->iitenum;
        //cvrtglbnbr = 2;
        // XXX fin tmp
        //if ((1.0 * rmshglbnb2 / cvrtglbnbr) < 10000) // XXX test à remettre pour éviter qu'il y ait moins de 10000 éléments par zone
        //  cvrtglbnbr /= ceil (1.0 * cvrtglbnbr * 10000 / rmshglbnb2);

        //}
        // XXX temporaire
        //if (infoptr->iitenum == 1)
        //  cvrtglbnbr = 4;
        //if (infoptr->iitenum == 2)
        //  cvrtglbnbr = coldglbnbr;
        //else if (infoptr->iitenum == 3)
        //  cvrtglbnbr = 1;
        //  XXX fin temporaire
        //if ((coldglbnbr == cvrtglbnbr) && (ibndval != 0) && (cvrtglbnbr != 1)) {
        //  ibndval = MAX(0, ibndval - 1);
        //  CHECK_FERR (dmeshDgraphFree (&dgrfdat), proccomm);
        //  memFree (hashtab);
        //  continue;
        //}
        //else if ((coldglbnbr == cvrtglbnbr) && (cvrtglbnbr == 1)) {
        //  CHECK_FERR (dmeshDgraphFree (&dgrfdat), proccomm);
        //  memFree (hashtab);
        //  break;
        //}
        if (infoptr->zonenb2 != ~0)
          cvrtglbnbr = infoptr->zonenb2;
        if (infoptr->iitenum >= 4) {
          cvrtglbnbr /= 2;
          infoptr->zonenb2 = cvrtglbnbr;
        }

        //cvrtglbnbr = ceil (1.0 * rmshglbnb2 / 25000);
        if (orgmeshptr->proclocnum == 0)
          infoPrint ("vertglb: " GNUMSTRING ", rmshglb: " GNUMSTRING ", rmshglb2: " GNUMSTRING ", enodglbnbr: " GNUMSTRING ", cond: %lf, val1: %lf, val2: %lf, cvrt:" GNUMSTRING "\n",
              orgmeshptr->enttloctax[baseval]->vertglbnbr,
              rmshglbnbr,
              rmshglbnb2,
              infoptr->enodglbnbr,
              cond,
              val1,
              val2,
              cvrtglbnbr);
                                                         
                                                         
#ifdef PAMPA_DEBUG_ADAPT
        if (0 != PAMPA_TAG_VERT_NOREMESH) {
          errorPrint ("PAMPA_TAG_VERT_NOREMESH is not 0");
          cheklocval = 1;
  	}
  	CHECK_VERR (cheklocval, proccomm);
#endif /* PAMPA_DEBUG_ADAPT */

#ifdef PAMPA_DEBUG_DMESH_SAVE
        {
          char s1[50];
          if (memAllocGroup ((void **) (void *)
                &vnumgsttax, (size_t) (orgmeshptr->enttloctax[baseval]->vgstlocnbr * sizeof (Gnum)),
                &parttax,    (size_t) (sizeof (Gnum)),
                NULL) == NULL) {
            errorPrint ("Out of memory");
            cheklocval = 1;
          }
          CHECK_VERR (cheklocval, proccomm);
          vnumgsttax -= baseval;
          parttax -= baseval;

          memSet (vnumgsttax + baseval, ~0, orgmeshptr->enttloctax[baseval]->vgstlocnbr * sizeof (Gnum));
          for (vertlocnum = baseval, vertlocnnd = orgmeshptr->enttloctax[baseval]->vertlocnbr + baseval; vertlocnum < vertlocnnd; vertlocnum ++)
            if (rmshloctx2[vertlocnum] == PAMPA_TAG_VERT_REMESH)
              vnumgsttax[vertlocnum] = 0;
          //for (procngbnum = 0; procngbnum < orgmeshptr->procglbnbr; procngbnum ++) 
            parttax[baseval] = 0;

          imshloctab = NULL;
          meshlocnbr = -1; // FIXME l'allocation de imshloctab ne devrait pas être faite ici ?
          CHECK_FERR (dmeshGatherInduceMultiple (orgmeshptr, 0, 1, vnumgsttax, parttax + baseval, &meshlocnbr, &imshloctab), proccomm);
          if (meshlocnbr > 0) {
            sprintf (s1, "dmesh-adapt-rmsh2-%d-%d.mesh", infoptr->eitenum, infoptr->iitenum);
            CHECK_FERR (infoptr->EXT_meshSave((PAMPA_Mesh *) (imshloctab), 1, infoptr->dataptr, NULL, s1), proccomm);

            meshExit (imshloctab);
          }
          memFree (imshloctab);
          memFreeGroup (vnumgsttax + baseval);
        }
#endif /* PAMPA_DEBUG_DMESH_SAVE */
      // XXX début temporaire
//#undef PAMPA_DEBUG_DMESH_SAVE
      // XXX fin temporaire

        for (vertlocnum = baseval; vertlocnum <= vertlocmax; vertlocnum ++) {
          dvelloctax[vertlocnum] = round(dvelloctx2[vertlocnum]);
        }

  	// 1) Identification des zones à remailler
  	// 	a) conversion du maillage en graphe uniquement pour les sommets qui ont un drapeau
        // XXX FIXME bonne idée d'utiliser DMESH_ENTT_MAIN_PART, cela évite de
        // calculer ensuite le graphe induit, mais faut-il encore avoir
        // l'ancienne numérotation (vlblloctax à rajouter dans dmeshDgraphBuild
        // pour DMESH_ENTT_MAIN_PART). En attendant, on continue comme avant...
  	//CHECK_FERR (dmeshDgraphBuild (orgmeshptr, DMESH_ENTT_MAIN_PART, rmshlocnbr, dvrtgsttax, dvelloctax, &dgrfdat, &dvrtlocbas), proccomm);
  	//CHECK_FERR (dmeshDgraphBuild (orgmeshptr, DMESH_ENTT_MAIN, ~0, NULL, dvelloctax, NULL, &dgrfdat, &dvrtlocbas), proccomm); // XXX pas de edlo ??
        // XXX temporaire pour éviter l'effet météorite dû aux poids sur les éléments
  	CHECK_FERR (dmeshDgraphBuild (orgmeshptr, DMESH_ENTT_MAIN, ~0, NULL, NULL, NULL, &dgrfdat, &dvrtlocbas), proccomm); // XXX pas de edlo ??
        // XXX fin temporaire
        CHECK_FERR (SCOTCH_dgraphGhst (&dgrfdat), proccomm);

#ifdef PAMPA_DEBUG_DGRAPH
  	char s[30];
  	sprintf(s, "dgrfdat-adapt-%d", orgmeshptr->proclocnum);
  	FILE *dgraph_file;
  	dgraph_file = fopen(s, "w");
  	SCOTCH_dgraphSave (&dgrfdat, dgraph_file);
  	fclose(dgraph_file);
#endif /* PAMPA_DEBUG_DGRAPH */

        //CHECK_VDBG (cheklocval, proccomm);
        //if (commAllreduce (&rmshlocnbr, &rmshglbnbr, 1, GNUM_MPI, MPI_SUM, proccomm) != MPI_SUCCESS) {
        //  errorPrint ("communication error");
        //  cheklocval = 1;
        //}
        //CHECK_VERR (cheklocval, proccomm);

  	// 	a bis) élargissement des zones avec un dgraphBand ok
  	//if (ibndval > 0) {
	//  CHECK_FERR (SCOTCH_dgraphBand (&dgrfdat, rmshlocnbr, fronloctax + baseval, ibndval, &bgrfdat), proccomm);
        //}
        //else {
          // 	b) sous-graphe induit des zones ok
        memCpy (rmshloctx2 + baseval, rmshloctax + baseval, orgmeshptr->enttloctax[baseval]->vertlocnbr * sizeof (Gnum));
        CHECK_FERR (SCOTCH_dgraphInducePart (&dgrfdat, rmshloctx2 + baseval, PAMPA_TAG_VERT_REMESH, rmshlocnbr, &bgrfdat), proccomm);
        //}
#ifdef PAMPA_DEBUG_ADAPT2
	CHECK_FERR (SCOTCH_dgraphCheck (&bgrfdat), proccomm);
#endif /* PAMPA_DEBUG_ADAPT2 */
	CHECK_FERR (SCOTCH_dgraphGhst (&bgrfdat), proccomm);
  	//SCOTCH_dgraphData (&bgrfdat, NULL, NULL, &bvrtlocnbr, NULL, &bvrtgstnbr, (SCOTCH_Num **) &bvrtloctax, (SCOTCH_Num **) &bvndloctax, NULL, (SCOTCH_Num **) NULL, NULL, NULL, NULL, NULL, (SCOTCH_Num **) &bedggsttax, NULL, NULL); 
  	SCOTCH_dgraphData (&bgrfdat, NULL, &bvrtglbnbr, &bvrtlocnbr, NULL, &bvrtgstnbr, (SCOTCH_Num **) &bvrtloctax, (SCOTCH_Num **) &bvndloctax, (SCOTCH_Num **) &bvelloctax, (SCOTCH_Num **) &bvlbloctax, NULL, NULL, NULL, NULL, (SCOTCH_Num **) &bedggsttax, NULL, NULL); 
	bvlbloctax -= baseval;
	bvelloctax -= baseval;
	bvrtloctax -= baseval;
	bvndloctax -= baseval;
	bedggsttax -= baseval;

        for (bvellocsum = bvrtlocnum = baseval, bvrtlocnnd = bvrtlocnbr + baseval; bvrtlocnum < bvrtlocnnd; bvrtlocnum ++) 
          bvellocsum += bvelloctax[bvrtlocnum];

  	CHECK_VDBG (cheklocval, proccomm);
  	if (commAllreduce (&bvellocsum, &bvelglbsum, 1, GNUM_MPI, MPI_SUM, proccomm) != MPI_SUCCESS) {
      errorPrint ("communication error");
	  cheklocval = 1;
  	}
	CHECK_VERR (cheklocval, proccomm);

        //if (switval == 1)
        //  cvrtglbnbr = (bvelglbsum > ballsiz) ? bvelglbsum / ballsiz : 1;
        //else
        //  cvrtglbnbr = (bvelglbsum > (2 * ballsiz)) ? bvelglbsum / (2 * ballsiz) : 1;
        //cvrtglbnbr = (bvelglbsum > ballsiz) ? bvelglbsum / ballsiz : 1;

        switval = 1 - switval;
#ifdef PAMPA_INFO_ADAPT
        //infoPrint ("dvelglbsum : %d, rmshglbnbr : %d, ballsiz : %d, cvrtglbnbr : %d", bvelglbsum, rmshglbnbr, ballsiz, cvrtglbnbr);
#else /* PAMPA_INFO_ADAPT */
        if (orgmeshptr->proclocnum == 0) {
          infoPrint ("estimated weight: %d, number of elements to be remeshed: %d, number of zones: %d", bvelglbsum, rmshglbnbr, cvrtglbnbr);
        }
#endif /* PAMPA_INFO_ADAPT */
  	// 	c) contraction du graphe des zones ok
  	if (memAllocGroup ((void **) (void *)
		  &bnumgsttax, (size_t) (bvrtgstnbr * sizeof (Gnum)),
                  // XXX supprimer ci-dessous « * 2 »
		  &cvelloctab, (size_t) (cvrtglbnbr * sizeof (Gnum)),
		  //&bvlbloctax, (size_t) (bvrtlocnbr * sizeof (Gnum)), 
		  &vnumgsttax, (size_t) (orgmeshptr->enttloctax[baseval]->vgstlocnbr * sizeof (Gnum)),
                  &parttax, (size_t) ((cvrtglbnbr + orgmeshptr->procglbnbr) * sizeof (Gnum)),
          NULL) == NULL) {
      errorPrint ("Out of memory");
      cheklocval = 1;
  	}
  	CHECK_VERR (cheklocval, proccomm);
  	bnumgsttax -= baseval;
  	vnumgsttax -= baseval;
        parttax -= baseval;
	//bvlbloctax -= baseval;
  	memSet (cvelloctab, 0, cvrtglbnbr * sizeof (Gnum));
  	memSet (vnumgsttax + baseval, ~0, orgmeshptr->enttloctax[baseval]->vertlocnbr * sizeof (Gnum));



	//if ((bvelglbsum > ballsiz) && (rmshglbnb2 != rmshglbnb3)) {

        if (cvrtglbnbr > 1) {
  	  //CHECK_FERR (dmeshAdapt2 (orgmeshptr, &bgrfdat, bnumgsttax, &cgrfdat, cprcvrttab, coarval - 1, coarnbr, coarrat), orgmeshptr->proccomm);
#ifdef PAMPA_DEBUG_ADAPT2
          CHECK_FERR (SCOTCH_dgraphCheck (&bgrfdat), proccomm);
#endif /* PAMPA_DEBUG_ADAPT2 */
//#define PAMPA_DEBUG_DGRAPH
#ifdef PAMPA_DEBUG_DGRAPH
          {
            char s[30];
            FILE *dgraph_file;
            errorPrint ("cvrtglbnbr: %d\n", cvrtglbnbr);
            sprintf(s, "dgrf-adapt-%d-%d.grf", infoptr->iitenum, orgmeshptr->proclocnum);
            dgraph_file = fopen(s, "w");
            SCOTCH_dgraphSave (&bgrfdat, dgraph_file);
            fclose(dgraph_file);



            Gnum tetentt, nodentt, i;
            PAMPA_Iterator it_nghb;
            double * coorloctax;

            tetentt = 0;
            nodentt = 1;
            CHECK_FERR (PAMPA_dmeshHaloValue ((PAMPA_Dmesh *) orgmeshptr, nodentt, PAMPA_TAG_GEOM), proccomm);
            dmeshValueData(orgmeshptr, nodentt, PAMPA_TAG_GEOM, NULL, NULL, (void **) &coorloctax);
            coorloctax -= 3 * baseval;

            sprintf(s, "dgrf-adapt-%d-%d.xyz", infoptr->iitenum, orgmeshptr->proclocnum);
            dgraph_file = fopen(s, "w");
            if (orgmeshptr->proclocnum == 0) {
              fprintf (dgraph_file, "3\n%d\n", orgmeshptr->enttloctax[baseval]->vertglbnbr);
            }

            //if (commAllgather (&bvrtlocnbr, 1, GNUM_MPI,
            //      vnbrloctab, 1, GNUM_MPI, orgmeshptr->proccomm) != MPI_SUCCESS) {
            //  errorPrint ("communication error");
            //  return     (1);
            //}

            //vertlocbas = 0;
            //for (procngbnum = 0; procngbnum < orgmeshptr->proclocnum ; procngbnum ++)
            //  vertlocbas += vnbrloctab[procngbnum];

            PAMPA_dmeshItInit((PAMPA_Dmesh *) orgmeshptr, tetentt, nodentt, &it_nghb);
            for (vertlocnum = baseval, vertlocnnd = bvrtlocnbr; vertlocnum < vertlocnnd; vertlocnum ++) {
              PAMPA_Num tetnum;
              double coorval[3];

              tetnum = bvlbloctax[vertlocnum] - dvrtlocbas;
              coorval[0] =
                coorval[1] =
                coorval[2] = 0.0;


              PAMPA_itStart(&it_nghb, tetnum);

              while (PAMPA_itHasMore(&it_nghb)) {
                PAMPA_Num nodenum;

                nodenum = PAMPA_itCurEnttVertNum(&it_nghb);
                for (i = 0; i < 3; i++)
                  coorval[i] += coorloctax[nodenum * 3 + i];
                PAMPA_itNext(&it_nghb);
              }

              //fprintf(dgraph_file, "%d", vertlocbas + tetnum);
              fprintf(dgraph_file, "%d", vertlocnum);
              for (i = 0; i < 3; i++)
                fprintf(dgraph_file, " %lf", coorval[i] / 4);
              fprintf(dgraph_file, "\n");

            }
            fclose (dgraph_file); 
          }
#endif /* PAMPA_DEBUG_DGRAPH */
//#undef PAMPA_DEBUG_DGRAPH
          //CHECK_FERR (SCOTCH_stratDgraphMap (&strtdat, "r{sep=q{strat=g},seq=r{sep=g}}"), orgmeshptr->proccomm);
          CHECK_FERR (SCOTCH_dgraphPart (&bgrfdat, cvrtglbnbr, &strtdat, bnumgsttax + baseval), orgmeshptr->proccomm);
          // XXX TODO vérifier que chaque zone ait le nombre minimum d'éléments
          // émettre un avertissement si moins que prévu

#ifdef PAMPA_DEBUG_ADAPT_PART
          {
            if (orgmeshptr->proclocnum == 0) {
              SCOTCH_Graph * graflvl;
              SCOTCH_Graph * grafptr;
              int tmpval;
              Gnum vertnbr;
              Gnum vertnum;
              Gnum vertnnd;
              Gnum colrnum;
              Gnum colrflg;
              Gnum * restrict finematetax;
              Gnum * restrict coarmulttax;
              int * restrict drcvcnttab;
              int * restrict drcvdsptab;

              if (memAllocGroup ((void **) (void *)
                    &drcvcnttab,  (size_t) (orgmeshptr->procglbnbr       * sizeof (int)),
                    &drcvdsptab,  (size_t) ((orgmeshptr->procglbnbr + 1) * sizeof (int)),
                    &parttax,     (size_t) (bvrtglbnbr                   * sizeof (Gnum)),
                    &parttx2,     (size_t) (MAX(cvrtglbnbr, bvrtglbnbr)  * sizeof (Gnum)),
                    &finematetax, (size_t) (bvrtglbnbr                   * sizeof (Gnum)),
                    &coarmulttax, (size_t) (bvrtglbnbr * 2               * sizeof (Gnum)),
                    NULL) == NULL) {
                errorPrint ("Out of memory");
                cheklocval = 1;
              }
              parttax -= baseval;
              parttx2 -= baseval;
              finematetax -= baseval;
              coarmulttax -= 2 * baseval;

              if ((grafptr = (SCOTCH_Graph *) memAlloc (sizeof (SCOTCH_Graph))) == NULL) {
                errorPrint  ("out of memory");
                cheklocval = 1;
              }
              CHECK_VDBG2 (cheklocval);

              CHECK_FDBG2 (SCOTCH_graphInit (grafptr));
              CHECK_FERR (SCOTCH_dgraphGather (&bgrfdat, grafptr), orgmeshptr->proccomm);

              tmpval = bvrtlocnbr;
              CHECK_FMPI (cheklocval, commGather (&tmpval, 1, MPI_INT,
                    drcvcnttab, 1, MPI_INT, 0, proccomm), proccomm);
              drcvdsptab[0] = 0;
              for (procngbnum = 0; procngbnum < orgmeshptr->procglbnbr; procngbnum ++) {
                drcvdsptab[procngbnum + 1] = drcvdsptab[procngbnum] + drcvcnttab[procngbnum];
              }

              CHECK_FMPI (cheklocval, commGatherv (bnumgsttax + baseval, bvrtlocnbr, GNUM_MPI,
                    parttax + baseval, drcvcnttab, drcvdsptab, GNUM_MPI, 0, proccomm), proccomm);

              do {
                Gnum coarvertnbr;
                Gnum * restrict verttax;
                Gnum * restrict vendtax;
                Gnum * restrict edgetax;

                if ((graflvl = (SCOTCH_Graph *) memAlloc (sizeof (SCOTCH_Graph))) == NULL) {
                  errorPrint  ("out of memory");
                  cheklocval = 1;
                }
                CHECK_VDBG2 (cheklocval);

                CHECK_FDBG2 (SCOTCH_graphInit (graflvl));
                SCOTCH_graphData (grafptr, NULL, &vertnbr, &verttax, &vendtax, NULL, NULL, NULL, &edgetax, NULL);
                verttax -= baseval;
                vendtax -= baseval;
                edgetax -= baseval;

                memSet (finematetax + baseval, ~0, vertnbr * sizeof (Gnum));
                for (colrflg = 0, coarvertnbr = vertnbr, vertnum = baseval, vertnnd = vertnbr + baseval;
                    vertnum < vertnnd; vertnum ++) {
                  Gnum edgenum;
                  Gnum edgennd;

                  if (finematetax[vertnum] == ~0)
                    for (edgenum = verttax[vertnum], edgennd = vendtax[vertnum]; edgenum < edgennd; edgenum ++)
                      if ((finematetax[edgetax[edgenum]] == ~0) && (parttax[vertnum] == parttax[edgetax[edgenum]])) {
                        if (colrflg == 0)
                          colrflg = 1;
                        finematetax[vertnum] = edgetax[edgenum];
                        finematetax[edgetax[edgenum]] = vertnum;
                        coarvertnbr --;
                        break;
                      }
                }
                for (vertnum = baseval, vertnnd = vertnbr + baseval; vertnum < vertnbr; vertnum ++) /* If there are still alone vertices */
                  if (finematetax[vertnum] == ~0)
                    finematetax[vertnum] = vertnum;
   
                CHECK_FDBG2 (SCOTCH_graphCoarsenBuild (grafptr, coarvertnbr, finematetax + baseval, graflvl, coarmulttax + 2 * baseval));

                for (vertnum = baseval, vertnnd = coarvertnbr + baseval; vertnum < vertnnd; vertnum ++)
                  parttx2[vertnum] = parttax[coarmulttax[vertnum << 1]];

                memCpy (parttax + baseval, parttx2 + baseval, coarvertnbr * sizeof (Gnum));
                SCOTCH_graphExit (grafptr);
                memFree (grafptr);
                grafptr = graflvl;
              } while (colrflg == 1);

              SCOTCH_graphSize (grafptr, &vertnbr, NULL);

              memSet (parttx2 + baseval, 0, cvrtglbnbr * sizeof (Gnum));
              parttx2 += baseval;
              for (vertnum = baseval, vertnnd = baseval + vertnbr; vertnum < vertnnd; vertnum ++) 
                parttx2[parttax[vertnum]] ++;


              for (colrflg = colrnum = 0; (colrnum < cvrtglbnbr) && (colrflg < 5); colrnum ++) // TRICK: start from 0 because it is a color
                if (parttx2[colrnum] != 1) {
                  colrflg ++;
                  errorPrint (GNUMSTRING "CC for color " GNUMSTRING, parttx2[colrnum], colrnum);
                }

              if (colrflg != 0)
                cheklocval = 1;

              SCOTCH_graphExit (grafptr);
              memFree (grafptr);
              memFreeGroup (drcvcnttab);

            }
            else { /* proclocnum != 0) */
              int tmpval;

              CHECK_FERR (SCOTCH_dgraphGather (&bgrfdat, NULL), orgmeshptr->proccomm);
              tmpval = bvrtlocnbr;
              CHECK_FMPI (cheklocval, commGather (&tmpval, 1, MPI_INT,
                    NULL, 0, MPI_INT, 0, proccomm), proccomm);
              CHECK_FMPI (cheklocval, commGatherv (bnumgsttax + baseval, bvrtlocnbr, GNUM_MPI,
                    NULL, NULL, NULL, GNUM_MPI, 0, proccomm), proccomm);
            }
          }
          CHECK_VERR (cheklocval, proccomm);
#endif /* PAMPA_DEBUG_ADAPT_PART */

          cprcvrttab[0] = 0;
          for (procngbnum = 0; procngbnum < orgmeshptr->procglbnbr; procngbnum ++)
            cprcvrttab[procngbnum + 1] = cprcvrttab[procngbnum] + DATASIZE(cvrtglbnbr, orgmeshptr->procglbnbr, procngbnum);
          cvrtlocnbr = cprcvrttab[orgmeshptr->proclocnum + 1] - cprcvrttab[orgmeshptr->proclocnum];



//#define PAMPA_DEBUG_DMESH_SAVE2
#ifdef PAMPA_DEBUG_DMESH_SAVE2
          {
            char s1[100];
            Gnum * vnumloctax;
            Gnum * vflgloctax;
            Gnum * vflgglbtax;
            Gnum parttab[1];

            parttab[0] = 0;

            if (memAllocGroup ((void **) (void *)
                  &vnumloctax, (size_t) (orgmeshptr->enttloctax[baseval]->vertlocnbr * sizeof (Gnum)),
                  &vflgloctax, (size_t) (bvrtlocnbr * sizeof (Gnum)),
                  &vflgglbtax, (size_t) (bvrtglbnbr * sizeof (Gnum)),
                  NULL) == NULL) {
              errorPrint ("Out of memory");
              cheklocval = 1;
            }
            CHECK_VERR (cheklocval, proccomm);
            vnumloctax -= baseval;
            vflgloctax -= baseval;
            vflgglbtax -= baseval;

            memSet (vnumloctax + baseval, ~0, orgmeshptr->enttloctax[baseval]->vertlocnbr * sizeof (Gnum));
            for (vertlocnum = baseval, vertlocnnd = bvrtlocnbr + baseval; vertlocnum < vertlocnnd; vertlocnum ++)
              if (rmshloctx2[bvlbloctax[vertlocnum] - dvrtlocbas] == PAMPA_TAG_VERT_REMESH) {
                vnumloctax[bvlbloctax[vertlocnum] - dvrtlocbas] = 0;
                vflgloctax[vertlocnum] = bnumgsttax[vertlocnum];
              }

            imshloctab = NULL;
            meshlocnbr = -1; // FIXME l'allocation de imshloctab ne devrait pas être faite ici ?
            CHECK_FERR (dmeshGatherInduceMultiple (orgmeshptr, 0, 1, vnumloctax, parttab - baseval, &meshlocnbr, &imshloctab), proccomm);
            sprintf (s1, "dmesh-adapt-part-%d.mesh", infoptr->iitenum);
            CHECK_FERR (dmeshAdaptGatherSave3 (orgmeshptr, bvrtlocnbr, vflgloctax, vflgglbtax), proccomm);
            if (meshlocnbr > 0) {
              CHECK_FERR (infoptr->EXT_meshSave((PAMPA_Mesh *) (imshloctab), 1, infoptr->dataptr, vflgglbtax + baseval, s1), proccomm);
              meshExit (imshloctab);
            }
            memFreeGroup (vnumloctax + baseval);

            memFree (imshloctab);
          }
#endif /* PAMPA_DEBUG_DMESH_SAVE2 */
//#undef PAMPA_DEBUG_DMESH_SAVE2
          // XXX pour enregistrer la partition, il faut ne garder que la partie
          // du maillage correspondand au graphe bgrfdat (cf. rmshloctx2)
//#ifdef PAMPA_DEBUG_DMESH_SAVE
//        char s1[50];
//        sprintf (s1, "dmesh-adapt-part-%d.mesh", wmshcnt);
//        CHECK_FERR (dmeshAdaptGatherSave2 (orgmeshptr, bnumgsttax, dataptr, s1), proccomm);
//#endif /* PAMPA_DEBUG_DMESH_SAVE */

          SCOTCH_stratExit (&strtdat);
          SCOTCH_stratInit (&strtdat);

	  CHECK_FERR (SCOTCH_dgraphHalo (&bgrfdat, bnumgsttax + baseval, GNUM_MPI), orgmeshptr->proccomm);

	  //CHECK_FERR (SCOTCH_dgraphGhst (&cgrfdat), proccomm);
	  //SCOTCH_dgraphData (&cgrfdat, NULL, &cvrtglbnbr, &cvrtlocnbr, NULL, &cvrtgstnbr, NULL, NULL, (SCOTCH_Num **) &cvelloctax, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	  //cvelloctax -= baseval;

//#define PAMPA_INFO_ADAPT
#ifdef PAMPA_INFO_ADAPT
          infoPrint ("-- Iteration number: %d", infoptr->iitenum);
          infoPrint ("Number of vertices to be remeshed : %d", rmshglbnbr);
          infoPrint ("Number of colors : %d", cvrtglbnbr);
          infoPrint ("Number of local colors : %d", cvrtlocnbr);
#endif /* PAMPA_INFO_ADAPT */
#undef PAMPA_INFO_ADAPT

	  bvrtgstmax = bvrtlocnbr + baseval - 1;
  	  // 	d) partitionnement des gros sommets ko
  	  //                 * partitionnement de graphes
  	  //                         * les gros sommets sont indépendants donc absence de relations
  	  SCOTCH_dgraphSize (&dgrfdat, NULL, &dvrtlocnbr, NULL, NULL);

	  //for (bvrtlocnum = dvrtlocnum = baseval, dvrtlocnnd = dvrtlocnbr + baseval; dvrtlocnum < dvrtlocnnd; dvrtlocnum ++)
	  //  if (rmshloctx2[dvrtlocnum] == PAMPA_TAG_VERT_REMESH)
	  //	bvlbloctax[bvrtlocnum ++] = dvrtlocnum + dvrtlocbas;

          memSet (vnumgsttax + baseval, ~0, orgmeshptr->enttloctax[baseval]->vertlocnbr * sizeof (Gnum));
  	  for (bvrtlocnum = baseval, bvrtlocnnd = bvrtlocnbr + baseval; bvrtlocnum < bvrtlocnnd; bvrtlocnum ++) {
		//if (cvelgsttax[bnumgsttax[bvrtlocnum]] > (ballsiz / 10))
                //FIXME peut-on faire un test sur les tailles de boule, le
                //problème est que bnumgsttax contient un sommet qui peut ne pas
                //être dans les ghst
            //if ((bnumgsttax[bvrtlocnum] < 0) || (bnumgsttax[bvrtlocnum] >= cvrtglbnbr)) {
            //  errorPrint ("color " GNUMSTRING " invalid, max is " GNUMSTRING, bnumgsttax[bvrtlocnum], cvrtglbnbr);
            //  return (1);
            //}
	  	  vnumgsttax[bvlbloctax[bvrtlocnum] - dvrtlocbas] = bnumgsttax[bvrtlocnum]; /* Propagate colors on elements */
                  // XXX temporaire YYY
                  if (bnumgsttax[bvrtlocnum] >= 0)
                    // XXX fin temporaire YYY
                  cvelloctab[bnumgsttax[bvrtlocnum]] += bvelloctax[bvrtlocnum];
          }

#ifdef PAMPA_DEBUG_ADAPT
	  for (vertlocnum = baseval, vertlocnnd = orgmeshptr->enttloctax[baseval]->vertlocnbr + baseval; vertlocnum < vertlocnnd; vertlocnum ++) {
            if ((vnumgsttax[vertlocnum] < ~0) || (vnumgsttax[vertlocnum] >= cvrtglbnbr)) {
              errorPrint ("Color " GNUMSTRING " invalid for vertex " GNUMSTRING, vnumgsttax[vertlocnum] , vertlocnum);
              return (1);
            }
          }
#endif /* PAMPA_DEBUG_ADAPT */

          CHECK_FERR (dmeshGrow ( orgmeshptr, baseval, vnumgsttax, cvrtglbnbr, nodeent, ibndval), orgmeshptr->proccomm); // XXX on fait des suppositions sur les entités, il faut passer par la bib externe
          
	  /////* First pass to remove elements which have neighbors with different color */
  	  //for (bvrtlocnum = baseval, bvrtlocnnd = bvrtlocnbr + baseval; bvrtlocnum < bvrtlocnnd; bvrtlocnum ++) {
	  //	Gnum cvrtlocnum;
          //      Gnum bedglocnum;
          //      Gnum bedglocnnd;
	  //	Gnum ucollocval; /* If undo coloring */

	  //	cvrtlocnum = bnumgsttax[bvrtlocnum];

	  //	for (ucollocval = 0, bedglocnum = bvrtloctax[bvrtlocnum], bedglocnnd = bvndloctax[bvrtlocnum]; bedglocnum < bedglocnnd; bedglocnum ++) /* Undo coloring on elements which are at the boundary */
	  //    if (bnumgsttax[bedggsttax[bedglocnum]] != cvrtlocnum) { /* If vertex and neighbor have different colors */
	  //    	ucollocval = 1;
	  //    	if (bedggsttax[bedglocnum] <= bvrtgstmax) 
	  //  	  vnumgsttax[bvlbloctax[bedggsttax[bedglocnum]] - dvrtlocbas] = ~0;
	  //    }
	  //	if (ucollocval == 1) { /* There are at least one neighbor with different color */
	  //    vnumgsttax[bvlbloctax[bvrtlocnum] - dvrtlocbas] = ~0;
	  //	  // FIXME il faudrait diminuer le cvelloctax pour cette couleur
	  //	}
	  //}
	  memFreeGroup (rmshloctx2 + baseval);

	  //CHECK_FERR (dmeshHaloSync (orgmeshptr, orgmeshptr->enttloctax[baseval], vnumgsttax + baseval, GNUM_MPI), orgmeshptr->proccomm);

	  //// FIXME temporarly disabled
	  ///* Second pass to remove elements which are isolated */
	  //for (vertlocnum = baseval, vertlocnnd = orgmeshptr->enttloctax[baseval]->vertlocnbr + baseval; vertlocnum < vertlocnnd; vertlocnum ++) {
	  //	Gnum ucollocval; /* If undo coloring */
	  //	Gnum vnumlocval;
	  //	Gnum edgelocnnd;
	  //	const DmeshEntity * enttlocptr = orgmeshptr->enttloctax[baseval];

	  //	vnumlocval = vnumgsttax[vertlocnum];

	  //	if (vnumlocval != ~0) {
	  //    for (ucollocval = 0, edgelocnum = enttlocptr->nghbloctax[baseval]->vindloctax[vertlocnum].vertlocidx,
	  //  	  edgelocnnd = enttlocptr->nghbloctax[baseval]->vindloctax[vertlocnum].vendlocidx;
	  //  	  ucollocval == 0 && edgelocnum < edgelocnnd; edgelocnum ++) {
	  //    	Gnum nghblocnum;

	  //    	nghblocnum = orgmeshptr->edgeloctax[edgelocnum];

	  //    	if (vnumgsttax[nghblocnum] == vnumlocval) /* If vertex and neighbor have same colors */
	  //    	  ucollocval = 1;
	  //    }
	  //	  if (ucollocval == 0) { /* If no neighbor with same color */
	  //    	vnumgsttax[vertlocnum] = ~0;
	  //	  	// FIXME il faudrait diminuer le cvelloctax pour cette couleur
	  //	  }
	  //	}
	  //}

          CHECK_FERR (dmeshZoneDist (orgmeshptr, infoptr, bvrtlocnbr, bnumgsttax, cvrtlocnbr, cvrtglbnbr, cprcvrttab, cvelloctab, parttax), orgmeshptr->proccomm); 
          SCOTCH_dgraphFree (&bgrfdat);
	}
	else {
	  memFreeGroup (rmshloctx2 + baseval);
#ifdef PAMPA_INFO_ADAPT
          infoPrint ("-- Iteration number: %d", infoptr->iitenum);
          infoPrint ("Number of vertices to be remeshed : %d", rmshglbnbr);
          infoPrint ("Last iteration");
#endif /* PAMPA_INFO_ADAPT */
	  memSet (bnumgsttax + baseval, 0, bvrtgstnbr * sizeof (Gnum));
  	  for (bvrtlocnum = baseval, bvrtlocnnd = bvrtlocnbr + baseval; bvrtlocnum < bvrtlocnnd; bvrtlocnum ++) 
	  	vnumgsttax[bvlbloctax[bvrtlocnum] - dvrtlocbas] = bnumgsttax[bvrtlocnum]; /* Propagate colors on elements */

          CHECK_FERR (dmeshGrow ( orgmeshptr, baseval, vnumgsttax, cvrtglbnbr, nodeent, ibndval), orgmeshptr->proccomm); // XXX on fait des suppositions sur les entités, il faut passer par la bib externe

  	  if ((parttax = (Gnum *) memAlloc (1 * sizeof (Gnum))) == NULL) {
      	errorPrint  ("out of memory");
      	cheklocval = 1;
  	  }
  	  CHECK_VERR (cheklocval, proccomm);
	  parttax -= baseval;
	  parttax[baseval] = 0; // FIXME pourquoi 0 ???
	  cvrtglbnbr = 1;
	}


  	// 2) Extraction des sous-maillages et envoie sur chaque proc ok
	meshlocnbr = -1;
	imshloctab = NULL;
  	CHECK_FERR_STR (dmeshGatherInduceMultiple2 (orgmeshptr, 1, infoptr, cvrtglbnbr, vnumgsttax, parttax, &meshlocnbr, &imshloctab), "extraction", proccomm);
        //CHECK_FERR (dmeshValueLink (orgmeshptr, (void **) &srcprocvrttab, PAMPA_VALUE_PRIVATE, NULL, NULL, GNUM_MPI, PAMPA_ENTT_VIRT_PROC, TAG_INT_PROCVRT), proccomm);
        //memCpy (srcprocvrttab, orgmeshptr->procvrttab, (orgmeshptr->procglbnbr + 1) * sizeof (Gnum));
        CHECK_FERR (dmeshValueData (orgmeshptr, PAMPA_ENTT_VIRT_VERT, PAMPA_TAG_STATUS, NULL, NULL, (void **) &srcpartloctax), proccomm);
        srcpartloctax -= baseval;

#ifdef PAMPA_INFO_ADAPT
        infoPrint ("dmeshInducePart, vertex number before: %d", orgmeshptr->vertlocnbr);
#endif /* PAMPA_INFO_ADAPT */
  	//CHECK_FERR_STR (dmeshInducePart (orgmeshptr, srcpartloctax, PAMPA_TAG_VERT_INTERNAL, &indmeshdat), "mesh induit", proccomm);
#ifdef PAMPA_INFO_ADAPT
        infoPrint ("dmeshInducePart, vertex number after: %d", indmeshdat.vertlocnbr);
#endif /* PAMPA_INFO_ADAPT */

        //orgmeshptr = &indmeshdat;

        //// XXX debut temporaire
        //if (orgmeshptr->proclocnum == 0) {
        //  PAMPA_Mesh m2;
        //  // Initialisation of PaMPA mesh structure
        //  CHECK_FERR(PAMPA_meshInit(&m2), proccomm);

        //  CHECK_FERR(PAMPA_dmeshGather (orgmeshptr, &m2), proccomm);

        //  CHECK_FERR(infoptr->EXT_meshSave(&m2, 1, dataptr, NULL, "apres_gather.mesh"), proccomm);

        //  // Finalisation of PaMPA mesh structure
        //  PAMPA_meshExit(&m2);
        //}
        //else {
        //  // Gather PaMPA mesh
        //  CHECK_FERR (PAMPA_dmeshGather (orgmeshptr, NULL), proccomm);
        //}
        //// XXX fin temporaire


#ifdef PAMPA_INFO_ADAPT
	infoPrint ("Number of received meshes : %d", meshlocnbr);
	infoPrint ("Number of local vertices in source distributed mesh : %d", orgmeshptr->vertlocnbr);
#endif /* PAMPA_INFO_ADAPT */

	memFreeGroup (bnumgsttax + baseval);
	if (cvrtglbnbr == 1)
	  memFree (parttax + baseval);

  	// 3) Remaillage des zones
  	// 	a) conversion pampa -> mmg ok
  	// 	b) remaillage ok
  	// 	c) conversion mmg -> pampa quasi ok
  	if ((omshloctab = (Mesh *) memAlloc (meshlocnbr * sizeof (Mesh))) == NULL) {
      errorPrint  ("out of memory");
      cheklocval = 1;
  	}
  	CHECK_VERR (cheklocval, proccomm);

        infoptr->cuntval = 0;

	//for (meshlocnum = 0; meshlocnum < meshlocnbr ; meshlocnum ++) { // XXX cette partie pourrait être parallélisé avec pthread
	for (meshlocnum = meshlocnbr - 1; meshlocnum >= 0 ; meshlocnum --) { // XXX cette partie pourrait être parallélisé avec pthread
          Gnum * restrict inbrtab;
          Gnum * restrict onbrtab;

#ifdef PAMPA_DEBUG_ADAPT2
	  //CHECK_FERR (meshCheck (imshloctab + meshlocnum), proccomm);
#endif /* PAMPA_DEBUG_ADAPT2 */
	  meshInit (omshloctab + meshlocnum);
#ifdef PAMPA_DEBUG_ADAPT_SAVE3
          {
            Dmesh tmshdat;
            char s[100];
            int rank;
            int size;
            File f;
            f.mode = "w";
            f.pntr = stdout;

            sprintf (s, "zone-%d-%d-%d-%d.bz2", infoptr->eitenum, infoptr->iitenum, orgmeshptr->proclocnum, meshlocnum);
            f.name = s;
            dmeshInit (&tmshdat, comm1p);
            MPI_Comm_rank (comm1p, &rank);
            MPI_Comm_size (comm1p, &size);

            infoPrint ("rank: %d, size: %d", rank, size);

            CHECK_FERR (dmeshScatter (&tmshdat, imshloctab + meshlocnum, infoptr->typenbr, infoptr->entttab, infoptr->tagtab, infoptr->typetab, (Gnum) 0), proccomm);
            CHECK_FERR (fileBlockOpen (&f, 1), proccomm);
            CHECK_FERR (dmeshSave (&tmshdat, f.pntr), proccomm);
            CHECK_FERR (fileBlockClose (&f, 1), proccomm);
            infoPrint ("file %s saved", s);

            dmeshExit (&tmshdat);
          }
#endif /* PAMPA_DEBUG_ADAPT_SAVE3 */

          infoPrint ("remeshing zone " GNUMSTRING, meshlocnum);
	  CHECK_FERR_STR (infoptr->EXT_meshAdapt ((PAMPA_Mesh *) (imshloctab + meshlocnum), (PAMPA_Mesh *) (omshloctab + meshlocnum), infoptr, 0), "remesh zone", proccomm); // FIXME remplacer le 0 par un drapeau
	  omshloctab[meshlocnum].idnum = imshloctab[meshlocnum].idnum;
          omshloctab[meshlocnum].procglbnbr = imshloctab[meshlocnum].procglbnbr;
          CHECK_FERR (meshValueData (imshloctab + meshlocnum, PAMPA_ENTT_VIRT_PROC, PAMPA_TAG_PART, NULL, NULL, (void **) &inbrtab), orgmeshptr->proccomm);
          if (meshValueData (omshloctab + meshlocnum, PAMPA_ENTT_VIRT_PROC, PAMPA_TAG_PART, NULL, NULL, (void **) &onbrtab) == 2) {
            CHECK_FERR (meshValueLink(omshloctab + meshlocnum, (void **) &onbrtab, PAMPA_VALUE_NONE, NULL, NULL, GNUM_MPI, PAMPA_ENTT_VIRT_PROC, PAMPA_TAG_PART), orgmeshptr->proccomm);
            memCpy (onbrtab, inbrtab, orgmeshptr->procglbnbr * sizeof (Gnum));
          }
          // FIXME : Et s'il y a d'autres valeurs associées, ne devrait-on pas
          // les recopier, sachant que :
          // 1) elles sont récupérées lors du rebuild
          // 2) pour les entt réelles, seule la routine PAMPA_remesh peut le faire
#ifdef PAMPA_DEBUG_ADAPT2
	  //CHECK_FERR (meshCheck (omshloctab + meshlocnum), proccomm);
#endif /* PAMPA_DEBUG_ADAPT2 */
	  meshExit (imshloctab + meshlocnum);
	}
	memFree (imshloctab);
	CHECK_VDBG (cheklocval, proccomm);


  	// 4) Reintegration des zones dans maillage distribué en cours
	CHECK_FERR_STR (dmeshRebuild (orgmeshptr, meshlocnbr, omshloctab), "reintegration", proccomm);

        if (infoptr->itdebug != NULL) {
        //if ((infoptr->itdebug != NULL) && (infoptr->iitenum == 5)) {
		//CHECK_FERR_STR (dmeshCheck (orgmeshptr), "check", proccomm);
		//if (orgmeshptr->proclocnum == 0)
		//	infoPrint ("apres le check");
          File f;
          char s[500];
	  //Dsmesh dmshdat;
	  infoPrint ("je passe la");
          sprintf (s, infoptr->itdebug, infoptr->eitenum, infoptr->iitenum);
          f.name = s;
          f.mode = "w";
          f.pntr = stdout;
          CHECK_FERR (fileBlockOpen (&f, 1), proccomm);
          CHECK_FERR (PAMPA_dmeshSaveAll (orgmeshptr, f.pntr), proccomm);
          fileBlockClose (&f, 1);
	  //MPI_Barrier (orgmeshptr->proccomm);
	  //MPI_Finalize ();
	  //exit (0);
	  //MPI_Barrier (orgmeshptr->proccomm);
	  //dsmeshInit (&dmshdat, orgmeshptr->proccomm);
	  //CHECK_FERR (dmesh2dsmesh(orgmeshptr, &dmshdat), proccomm);
	  //dsmeshExit (&dmshdat);
        }
#ifdef PAMPA_DEBUG_ADAPT2
	CHECK_FERR (dmeshCheck (orgmeshptr), proccomm);
#endif /* PAMPA_DEBUG_ADAPT2 */
        //// XXX debut temporaire
        //if (orgmeshptr->proclocnum == 0) {
        //  PAMPA_Mesh m2;
        //  // Initialisation of PaMPA mesh structure
        //  CHECK_FERR(PAMPA_meshInit(&m2), proccomm);

        //  CHECK_FERR(PAMPA_dmeshGather (orgmeshptr, &m2), proccomm);

        //  CHECK_FERR(infoptr->EXT_meshSave(&m2, 1, dataptr, NULL, "apres_rebuild.mesh"), proccomm);

        //  // Finalisation of PaMPA mesh structure
        //  PAMPA_meshExit(&m2);
        //}
        //else {
        //  // Gather PaMPA mesh
        //  CHECK_FERR (PAMPA_dmeshGather (orgmeshptr, NULL), proccomm);
        //}
        //// XXX fin temporaire

#ifdef PAMPA_INFO_ADAPT
	infoPrint ("Number of local vertices in destination distributed mesh : %d", orgmeshptr->vertlocnbr);
#endif /* PAMPA_INFO_ADAPT */

#ifdef PAMPA_DEBUG_DMESH_SAVE2
        {
          char s1[50];
          sprintf (s1, "dmesh-adapt-apres-%d", wmshcnt ++);
          CHECK_FERR (dmeshAdaptGatherSave (orgmeshptr, NULL, infoptr->EXT_meshSave, infoptr->dataptr, s1), proccomm);
        }
#endif /* PAMPA_DEBUG_DMESH_SAVE2 */
	for (meshlocnum = 0; meshlocnum < meshlocnbr ; meshlocnum ++) 
	  meshFree (omshloctab + meshlocnum);

	memFree (omshloctab);

//#ifdef PAMPA_DEBUG_DMESH_SAVE
//#ifndef PAMPA_DEBUG_DMESH_SAVE2
//        //char s1[50];
//#endif /* PAMPA_DEBUG_DMESH_SAVE2 */
//        //sprintf (s1, "dmesh-adapt-%d-%d", orgmeshptr->proclocnum, wmshcnt ++);
//        //CHECK_FERR (dmeshAdaptGatherSave (orgmeshptr, NULL, dataptr, s1), proccomm);
//        if (memAllocGroup ((void **) (void *)
//              &vnumgsttax, (size_t) (orgmeshptr->enttloctax[baseval]->vgstlocnbr * sizeof (Gnum)),
//              &parttax,    (size_t) (orgmeshptr->procglbnbr * sizeof (Gnum)),
//              NULL) == NULL) {
//          errorPrint ("Out of memory");
//          cheklocval = 1;
//        }
//        CHECK_VERR (cheklocval, proccomm);
//        vnumgsttax -= baseval;
//        parttax -= baseval;
//
//        for (vertlocnum = baseval, vertlocnnd = orgmeshptr->enttloctax[baseval]->vertlocnbr + baseval; vertlocnum < vertlocnnd; vertlocnum ++)
//          vnumgsttax[vertlocnum] = orgmeshptr->proclocnum;
//        for (procngbnum = 0; procngbnum < orgmeshptr->procglbnbr; procngbnum ++) 
//          parttax[procngbnum + baseval] = procngbnum;
//
//        imshloctab = NULL;
//        meshlocnbr = -1; // FIXME l'allocation de imshloctab ne devrait pas être faite ici ?
//        CHECK_FERR (dmeshGatherInduceMultiple (orgmeshptr, 0, orgmeshptr->procglbnbr, vnumgsttax, parttax, &meshlocnbr, &imshloctab), proccomm);
//        sprintf (s1, "dmsh-adapt-%d-%d.mesh", orgmeshptr->proclocnum, wmshcnt ++);
//        CHECK_FERR (infoptr->EXT_meshSave((PAMPA_Mesh *) (imshloctab), 1, dataptr, vnumgsttax + baseval, s1), proccomm);
//
//        meshExit (imshloctab);
//        memFree (imshloctab);
//        memFreeGroup (vnumgsttax + baseval);
//#endif /* PAMPA_DEBUG_DMESH_SAVE */


	CHECK_FERR (dmeshDgraphFree (&dgrfdat), proccomm);
        {
          Gnum vertmax;
          Gnum vertmin;
          if (commAllreduce (&orgmeshptr->vertlocnbr, &vertmax, 1, GNUM_MPI, MPI_MAX, proccomm) != MPI_SUCCESS) {
            errorPrint ("communication error");
            cheklocval = 1;
          }
          CHECK_VERR (cheklocval, proccomm);
          if (commAllreduce (&orgmeshptr->vertlocnbr, &vertmin, 1, GNUM_MPI, MPI_MIN, proccomm) != MPI_SUCCESS) {
            errorPrint ("communication error");
            cheklocval = 1;
          }
          CHECK_VERR (cheklocval, proccomm);

          if (orgmeshptr->proclocnum == 0)
            infoPrint ("vertmin: " GNUMSTRING ", vertmax: " GNUMSTRING, vertmin, vertmax);
          if (vertmax > (vertmin * 1.25)) {
            if (orgmeshptr->proclocnum == 0)
              infoPrint ("je rentre dedans");
            Dmesh orgmeshdat;
            PAMPA_Strat strtdt2;
            Gnum * partloctx2;
            CHECK_FERR (PAMPA_stratInit (&strtdt2), proccomm);
            CHECK_FERR (dmeshInit (&orgmeshdat, proccomm), proccomm);
            if ((partloctx2 = (Gnum *) memAlloc (orgmeshptr->vertlocnbr * sizeof (Gnum))) == NULL) {
              errorPrint  ("out of memory");
              cheklocval = 1;
            }
            CHECK_VERR (cheklocval, proccomm);
            partloctx2 -= baseval;

            CHECK_FERR_STR(dmeshMapElem(orgmeshptr, orgmeshptr->procglbnbr, NULL, &strtdt2, partloctx2), "part again", proccomm);
            CHECK_FERR(dmeshRedist(orgmeshptr, partloctx2, NULL, -1, -1, -1, &orgmeshdat), proccomm);
            memFree (partloctx2 + baseval);
            PAMPA_stratExit(&strtdt2);
            PAMPA_dmeshExit(orgmeshptr);
            *orgmeshptr = orgmeshdat;
#ifdef PAMPA_INFO_ADAPT
            infoPrint ("Number of local vertices in destination redistributed mesh : %d", orgmeshptr->vertlocnbr);
#endif /* PAMPA_INFO_ADAPT */
          }
        }

        infoptr->iitenum ++;
  }

  memFreeGroup (cprcvrttab);
  //CHECK_FERR_STR (dmeshDgraphBuild (orgmeshptr, DMESH_ENTT_ANY, ~0, NULL, NULL, &dgrfdat, NULL), "graphe final", proccomm);
  //SCOTCH_dgraphSize (&dgrfdat, NULL, &dvrtlocnbr, NULL, NULL);

  //if (memAllocGroup ((void **) (void *)
  //      	&paroloctax, (size_t) (dvrtlocnbr * sizeof (Gnum)),
  //      	&partloctax, (size_t) (dvrtlocnbr * sizeof (Gnum)),
  //      NULL) == NULL) {
  //  errorPrint ("Out of memory");
  //  cheklocval = 1;
  //}
  //CHECK_VERR (cheklocval, proccomm);
  //paroloctax -= baseval;
  //partloctax -= baseval;

  //for (vertlocnum = baseval, vertlocnnd = dvrtlocnbr + baseval; vertlocnum < vertlocnnd; vertlocnum ++)
  // 	paroloctax[vertlocnum] = orgmeshptr->proclocnum;

  //// 5) Repartitionnement
  //vmloloctab = NULL;
  //emraval = 1;
  //CHECK_FERR (SCOTCH_stratDgraphMap (&strtdat, "q{strat=m{asc=b{width=3,bnd=(d{pass=40,dif=1,rem=0}|)f{move=80,pass=-1,bal=0.01},org=f{move=80,pass=-1,bal=0.01}},low=r{job=t,bal=0.01,map=t,poli=S,sep=(m{asc=b{bnd=f{move=120,pass=-1,bal=0.01,type=b},org=f{move=120,pass=-1,bal=0.01,type=b},width=3},low=h{pass=10}f{move=120,pass=-1,bal=0.01,type=b},vert=120,rat=0.8}|m{asc=b{bnd=f{move=120,pass=-1,bal=0.01,type=b},org=f{move=120,pass=-1,bal=0.01,type=b},width=3},low=h{pass=10}f{move=120,pass=-1,bal=0.01,type=b},vert=120,rat=0.8})},vert=10000,rat=0.8,type=0}}"), proccomm);
  //CHECK_FERR (SCOTCH_dgraphRepart (&dgrfdat, orgmeshptr->procglbnbr, paroloctax + baseval, emraval, vmloloctab, &strtdat, partloctax + baseval), proccomm);

  dmeshDgraphExit (&dgrfdat);
  SCOTCH_dgraphExit (&bgrfdat);
  SCOTCH_stratExit (&strtdat);
  // 5 bis) Redistribution ok
  //CHECK_FERR (dmeshRedist (orgmeshptr, partloctax, NULL, -1, -1, -1, dstmeshptr), proccomm); // XXX peut-être utiliser un dsmeshRedist qui serait moins gourmand en mémoire à mon avis
  //memFreeGroup (paroloctax + baseval);
#ifdef PAMPA_DEBUG_ADAPT_SAVE3
  MPI_Comm_free (&comm1p);
#endif /* PAMPA_DEBUG_ADAPT_SAVE3 */

  CHECK_VDBG (cheklocval, proccomm);
  return (0);
}