Skip to content
Snippets Groups Projects
gitter_pll_sti.cc 44.6 KiB
Newer Older
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 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
  // (c) bernhard schupp 1997 - 1998

  // $Source$
  // $Revision$
  // $Name$
  // $State$
  // $Date$
  
/* $Id$
 * $Log$
 * Revision 1.1  2005/03/23 14:58:33  robertk
 * all additional files for parallel version of ALU3dGrid.
 *
 * Revision 1.6  2005/03/18 20:05:17  robertk
 * Added backup and restore for XDRStream, does not work right now.
 *
 * Revision 1.5  2004/11/25 18:49:34  robertk
 * removed duneAdaptm which is now in gitter_dune_pll_impl.*
 *
 * Revision 1.4  2004/11/02 18:55:30  robertk
 * Moved all changed with dune... to seperated gitter_dune_* files.
 *
 * Revision 1.3  2004/10/28 18:58:21  robertk
 * new method duneLoadBalance( GatherScatterType & ) which represents the dune
 * data.
 *
 * Revision 1.2  2004/10/28 18:00:22  robertk
 * duneAdapt and duneLoadBalance added.
 *
 * Revision 1.1  2004/10/25 16:41:20  robertk
 * Parallel grid implementations.
 *
 * Revision 1.6  2002/04/19 15:36:07  wesenber
 * modifications required for IBM VisualAge C++ Version 5.0
 *
 * Revision 1.5  2001/12/10 13:34:59  wesenber
 * parameter ``filePath'' for backup(), backupCMode(), and restore() added
 *
 ***/

#ifndef _GITTER_PLL_STI_CC_
#define _GITTER_PLL_STI_CC_

#ifdef IBM_XLC
  #define _ANSI_HEADER
#endif

#include <assert.h>
#include <time.h>
#include <stdio.h>
#include <sys/types.h>
#include <malloc.h>

#ifdef _ANSI_HEADER
  using namespace std;
  #include <iostream>
  #include <fstream>
  #include <strstream>
  #include <iterator>
  #include <functional>
  #include <algorithm>
  #include <numeric>
#else
  #include <iostream.h>
  #include <fstream.h>
  #include <strstream.h>
  #include <iterator.h>
  #include <function.h>
  #include <algo.h>
#endif

#include "gitter_pll_sti.h"

#ifndef WALK_H_INCLUDED
#include "walk.h"
#endif

int __STATIC_myrank = -1 ;
int __STATIC_turn   = -1 ;
int __STATIC_phase  = -1 ;

pair < IteratorSTI < GitterPll :: vertex_STI > *, IteratorSTI < GitterPll :: vertex_STI > *> GitterPll :: 
  iteratorTT (const GitterPll :: vertex_STI *, int l) {

  vector < IteratorSTI < vertex_STI > * > _iterators_inner, _iterators_outer ;

  _iterators_inner.push_back (new AccessIteratorTT < vertex_STI > :: InnerHandle (containerPll (), l)) ;
  _iterators_outer.push_back (new AccessIteratorTT < vertex_STI > :: OuterHandle (containerPll (), l)) ;
  {
    AccessIteratorTT < hedge_STI > :: InnerHandle mie (containerPll (), l) ;
    AccessIteratorTT < hedge_STI > :: OuterHandle moe (containerPll (), l) ;
    Insert < AccessIteratorTT < hedge_STI > :: InnerHandle, 
  TreeIterator < hedge_STI, has_int_vertex < hedge_STI > > > lie (mie) ;
    Insert < AccessIteratorTT < hedge_STI > :: OuterHandle, 
  TreeIterator < hedge_STI, has_int_vertex < hedge_STI > > > loe (moe) ;
    _iterators_inner.push_back (new Wrapper < Insert < AccessIteratorTT < hedge_STI > :: InnerHandle, 
  TreeIterator < hedge_STI, has_int_vertex < hedge_STI > > >, InternalVertex > (lie)) ;
    _iterators_outer.push_back (new Wrapper < Insert < AccessIteratorTT < hedge_STI > :: OuterHandle,
  TreeIterator < hedge_STI, has_int_vertex < hedge_STI > > >, InternalVertex > (loe)) ;
  }
  {
    AccessIteratorTT < hface_STI > :: InnerHandle mfi (containerPll (), l) ;
    AccessIteratorTT < hface_STI > :: OuterHandle mfo (containerPll (), l) ;
    {
      Insert < AccessIteratorTT < hface_STI > :: InnerHandle, 
  TreeIterator < hface_STI, has_int_vertex < hface_STI > > > lfi (mfi) ;
      Insert < AccessIteratorTT < hface_STI > :: OuterHandle, 
  TreeIterator < hface_STI, has_int_vertex < hface_STI > > > lfo (mfo) ;
      _iterators_inner.push_back (new Wrapper < Insert < AccessIteratorTT < hface_STI > :: InnerHandle,
  TreeIterator < hface_STI, has_int_vertex < hface_STI > > >, InternalVertex > (lfi)) ;
      _iterators_outer.push_back (new Wrapper < Insert < AccessIteratorTT < hface_STI > :: OuterHandle,
  TreeIterator < hface_STI, has_int_vertex < hface_STI > > >, InternalVertex > (lfo)) ;
    }
    {
      Insert < AccessIteratorTT < hface_STI > :: InnerHandle, 
  TreeIterator < hface_STI, has_int_edge < hface_STI > > > lfi (mfi) ;
      Insert < AccessIteratorTT < hface_STI > :: OuterHandle, 
  TreeIterator < hface_STI, has_int_edge < hface_STI > > > lfo (mfo) ;
      Wrapper < Insert < AccessIteratorTT < hface_STI > :: InnerHandle, 
  TreeIterator < hface_STI, has_int_edge < hface_STI > > >, InternalEdge > dlfi (lfi) ;
      Wrapper < Insert < AccessIteratorTT < hface_STI > :: OuterHandle,
  TreeIterator < hface_STI, has_int_edge < hface_STI > > >, InternalEdge > dlfo (lfo) ;
      Insert < Wrapper < Insert < AccessIteratorTT < hface_STI > :: InnerHandle, 
  TreeIterator < hface_STI, has_int_edge < hface_STI > > >, InternalEdge >,
  TreeIterator < hedge_STI, has_int_vertex < hedge_STI > > > vdlfi (dlfi) ;
      Insert < Wrapper < Insert < AccessIteratorTT < hface_STI > :: OuterHandle,
  TreeIterator < hface_STI, has_int_edge < hface_STI > > >, InternalEdge >,
  TreeIterator < hedge_STI, has_int_vertex < hedge_STI > > > vdlfo (dlfo) ;
      _iterators_inner.push_back (new Wrapper < Insert < Wrapper < 
  Insert < AccessIteratorTT < hface_STI > :: InnerHandle, 
  TreeIterator < hface_STI, has_int_edge < hface_STI > > >, InternalEdge >,
  TreeIterator < hedge_STI, has_int_vertex < hedge_STI > > >, InternalVertex > (vdlfi)) ;
      _iterators_outer.push_back (new Wrapper < 
  Insert < Wrapper < Insert < AccessIteratorTT < hface_STI > :: OuterHandle,
  TreeIterator < hface_STI, has_int_edge < hface_STI > > >, InternalEdge >,
  TreeIterator < hedge_STI, has_int_vertex < hedge_STI > > >, InternalVertex > (vdlfo)) ;
    }
  }
  return pair < IteratorSTI < vertex_STI > *, IteratorSTI < vertex_STI > * > 
  (new VectorAlign < vertex_STI > (_iterators_inner), new VectorAlign < vertex_STI > (_iterators_outer)) ;
}

pair < IteratorSTI < GitterPll :: hedge_STI > *, IteratorSTI < GitterPll :: hedge_STI > * > GitterPll ::
  iteratorTT (const GitterPll :: hedge_STI *, int l) {
  AccessIteratorTT < hedge_STI > :: InnerHandle mdi (containerPll (), l) ;
  AccessIteratorTT < hedge_STI > :: OuterHandle mdo (containerPll (), l) ;

  Insert < AccessIteratorTT < hedge_STI > :: InnerHandle, TreeIterator < hedge_STI, is_leaf < hedge_STI > > > ei (mdi) ;  
  Insert < AccessIteratorTT < hedge_STI > :: OuterHandle, TreeIterator < hedge_STI, is_leaf < hedge_STI > > > eo (mdo) ;
  
  AccessIteratorTT < hface_STI > :: InnerHandle mfi (containerPll (), l) ;
  AccessIteratorTT < hface_STI > :: OuterHandle mfo (containerPll (), l) ;

  Insert < AccessIteratorTT < hface_STI > :: InnerHandle, TreeIterator < hface_STI, has_int_edge < hface_STI > > > fimi (mfi) ;
  Insert < AccessIteratorTT < hface_STI > :: OuterHandle, TreeIterator < hface_STI, has_int_edge < hface_STI > > > fimo (mfo) ;

  Wrapper < Insert < AccessIteratorTT < hface_STI > :: InnerHandle, 
  TreeIterator < hface_STI, has_int_edge < hface_STI > > >, InternalEdge > dfimi (fimi) ;
  Wrapper < Insert < AccessIteratorTT < hface_STI > :: OuterHandle,
  TreeIterator < hface_STI, has_int_edge < hface_STI > > >, InternalEdge > dfimo (fimo) ;

  Insert < Wrapper < Insert < AccessIteratorTT < hface_STI > :: InnerHandle, 
  TreeIterator < hface_STI, has_int_edge < hface_STI > > >, InternalEdge >, 
  TreeIterator < hedge_STI, is_leaf < hedge_STI > > > eifi (dfimi) ;

  Insert < Wrapper < Insert < AccessIteratorTT < hface_STI > :: OuterHandle,
  TreeIterator < hface_STI, has_int_edge < hface_STI > > >, InternalEdge >,
  TreeIterator < hedge_STI, is_leaf < hedge_STI > > > eifo (dfimo) ;

  return pair < IteratorSTI < hedge_STI > *, IteratorSTI < hedge_STI > * > 
    (new AlignIterator < Insert < AccessIteratorTT < hedge_STI > :: InnerHandle, TreeIterator < hedge_STI, is_leaf < hedge_STI > > >,
  Insert < Wrapper < Insert < AccessIteratorTT < hface_STI > :: InnerHandle, 
  TreeIterator < hface_STI, has_int_edge < hface_STI > > >, InternalEdge >, 
  TreeIterator < hedge_STI, is_leaf < hedge_STI > > >, hedge_STI > (ei,eifi),
     new AlignIterator < Insert < AccessIteratorTT < hedge_STI > :: OuterHandle, TreeIterator < hedge_STI, is_leaf < hedge_STI > > >,
  Insert < Wrapper < Insert < AccessIteratorTT < hface_STI > :: OuterHandle,
  TreeIterator < hface_STI, has_int_edge < hface_STI > > >, InternalEdge >,
  TreeIterator < hedge_STI, is_leaf < hedge_STI > > >, hedge_STI > (eo, eifo)) ;
}

pair < IteratorSTI < GitterPll :: hface_STI > *, IteratorSTI < GitterPll :: hface_STI > *> 
  GitterPll :: iteratorTT (const GitterPll :: hface_STI *, int l) {
  AccessIteratorTT < hface_STI > :: InnerHandle mif (containerPll (), l) ;
  AccessIteratorTT < hface_STI > :: OuterHandle mof (containerPll (), l) ;
  return pair < IteratorSTI < hface_STI > *, IteratorSTI < hface_STI > * >
  (new Insert < AccessIteratorTT < hface_STI > :: InnerHandle, TreeIterator < hface_STI, is_leaf < hface_STI > > > (mif),
   new Insert < AccessIteratorTT < hface_STI > :: OuterHandle, TreeIterator < hface_STI, is_leaf < hface_STI > > > (mof)) ;
}

void GitterPll :: printSizeTT () {
  cout << "\n GitterPll :: printSizeTT () \n\n" ;
  mpAccess ().printLinkage (cout) ;
  cout << endl ;
  { for (int l = 0 ; l < mpAccess ().nlinks () ; l ++ ) {
    LeafIteratorTT < vertex_STI > w (*this, l) ;
    cout << "me: " << mpAccess ().myrank () << " link: " << l << " vertices: [inner|outer] " << w.inner ().size () << " " << w.outer ().size () << endl ;
  }}
  { for (int l = 0 ; l < mpAccess ().nlinks () ; l ++ ) {
    LeafIteratorTT < hedge_STI > w (*this, l) ;
    cout << "me: " << mpAccess ().myrank () << " link: " << l << " kanten:   [inner|outer] " << w.inner ().size () << " " << w.outer ().size () << endl ;
  }}
  { for (int l = 0 ; l < mpAccess ().nlinks () ; l ++ ) {
    LeafIteratorTT < hface_STI > w (*this, l) ;
    cout << "me: " << mpAccess ().myrank () << " link: " << l << " fl\"achen: [inner|outer] " << w.inner ().size () << " " << w.outer ().size () << endl ;
  }}
  return ;
}

void GitterPll :: printsize () {
  const int me = mpAccess ().myrank (), np = mpAccess ().psize (), nl = mpAccess ().nlinks () ;
  
  if (debugOption (10)) Gitter :: printsize () ;
  vector < int > n ;
  {
    int sum = 0 ;
    for (int i = 0 ; i < nl ; i ++)
      sum += LeafIteratorTT < vertex_STI > (*this, i).outer ().size () ;
    n.push_back (LeafIterator < vertex_STI > (*this)->size() - sum) ;
  }
  {
    int sum = 0 ;
    for (int i = 0 ; i < nl ; i ++)
      sum += LeafIteratorTT < hedge_STI > (*this, i).outer ().size () ;
    n.push_back (LeafIterator < hedge_STI > (*this)->size() - sum) ;
  }
  int sumCutFaces = 0 ;
  {
    int sum = 0 ;
    for (int i = 0 ; i < nl ; i ++) {
      LeafIteratorTT < hface_STI > w (*this, i) ;
      sum += w.outer ().size () ;
      sumCutFaces += w.outer ().size () ;
      sumCutFaces += w.inner ().size () ;
    }
    n.push_back (LeafIterator < hface_STI > (*this)->size() - sum) ;
  }
  n.push_back (LeafIterator < helement_STI > (*this)->size()) ;
  n.push_back (LeafIterator < hbndseg_STI > (*this)->size() - sumCutFaces) ;
  vector < vector < int > > in = mpAccess ().gcollect (n) ;
  assert (in.size () == np) ;
  if (me == 0) {
    int nv = 0, nd = 0, nf = 0, ne = 0, nb = 0 ;
    for (int i = 0 ; i < np ; i ++ ) {
      nv += (in [i])[0] ;
      nd += (in [i])[1] ;
      nf += (in [i])[2] ;
      ne += (in [i])[3] ;
      nb += (in [i])[4] ;
    }
    cout << "\n GitterPll :: printSize () : \n\n" ;
    cout << " - Elemente ......... "  << ne << "\n" ;
    cout << " - R\"ander .......... " << nb << "\n" ;
    cout << " - Fl\"achen ......... " << nf << "\n" ;
    cout << " - Kanten ........... "  << nd << "\n" ;
    cout << " - Vertices ......... "  << nv << "\n" ;
    cout << endl ;
  }
  return ;
}

void GitterPll :: fullIntegrityCheck () {
  const int nl = mpAccess ().nlinks (), me = mpAccess ().myrank () ;
  int start = clock () ;
  Gitter :: fullIntegrityCheck () ;
  containerPll().fullIntegrityCheck (mpAccess ()) ;
  if (debugOption (0)) {
    cout << "**INFO GitterPll :: fullIntegrityCheck () used: " << (float)((float)(clock() - start)/(float)(CLOCKS_PER_SEC)) << " sec." << endl ;
  }
  return ;
}

void GitterPll :: backupCMode (const char * path, const char * file) {
  assert (debugOption (20) ? (cout << "**INFO GitterPll :: backupCMode (const char * = \""
            << (path ? path : "null") << ",  const char * = \""
            << (file ? file : "null") << "\")" << endl, 1) : 1) ;
  char * extendedName = new char [strlen (file) + 20] ;
  sprintf (extendedName, "%s.%d", file, mpAccess ().myrank ()) ;
  Gitter :: backupCMode (path, extendedName) ;
  delete [] extendedName ;
  return ;
}

void GitterPll :: backupCMode (ostream & out) {
  assert (debugOption (20) ? (cout << "**INFO GitterPll :: backupCMode (ostream &)" << endl, 1) : 1) ;
  Gitter :: backupCMode (out) ;
  return ;
}

void GitterPll :: backup (const char * path, const char * file) {
  assert (debugOption (20) ? (cout << "**INFO GitterPll :: backup (const char * = \"" 
                   << (path ? path : "null") << ", const char * = \""
                 << (file ? file : "null") << "\")" << endl, 1) : 1) ;
  char * extendedName = new char [strlen (file) + 20] ;
  sprintf (extendedName, "%s.%d", file, mpAccess ().myrank ()) ;
  Gitter :: backup (path, extendedName) ;
  delete [] extendedName ;
  return ;
}

void GitterPll :: backup (ostream & out) {
  assert (debugOption (20) ? (cout << "**INFO GitterPll :: backup (ostream &)" << endl, 1) : 1) ;
  Gitter :: backup (out) ;
  return ;
}

void GitterPll :: backup (XDRstream_out & out) {
  assert (debugOption (20) ? (cout << "**INFO GitterPll :: backup (ostream &)" << endl, 1) : 1) ;
  Gitter :: backup (out) ;
  return ;
}

void GitterPll :: restore (const char * path, const char * file) {
  assert (debugOption (20) ? (cout << "**INFO GitterPll :: restore (const char * = \""
                 << path << ", const char * = \""
                 << file << "\")" << endl, 1) : 1) ;
  char * extendedName = new char [strlen (file) + 20] ;
  sprintf (extendedName, "%s.%d", file, mpAccess ().myrank ()) ;
  Gitter :: restore (path, extendedName) ;
  delete [] extendedName ;
  return ;
}

void GitterPll :: restore (istream & in) {
  assert (debugOption (20) ? (cout << "**INFO GitterPll :: restore (istream &)" << endl, 1) : 1) ;
  Gitter :: restore (in) ;
  return ;
}

void GitterPll :: restore (XDRstream_in & in) {
  assert (debugOption (20) ? (cout << "**INFO GitterPll :: restore (istream &)" << endl, 1) : 1) ;
  Gitter :: restore (in) ;
  return ;
}

pair < IteratorSTI < Gitter :: vertex_STI > *, IteratorSTI < Gitter :: vertex_STI > * >
  GitterPll :: MacroGitterPll :: iteratorTT (const vertex_STI *, int i) {
  assert (i < _vertexTT.size ()) ;
  return pair < IteratorSTI < vertex_STI > *, IteratorSTI < vertex_STI > * > 
  (new listSmartpointer__to__iteratorSTI < vertex_STI > (_vertexTT [i].first), 
         new listSmartpointer__to__iteratorSTI < vertex_STI > (_vertexTT [i].second)) ;
}

pair < IteratorSTI < Gitter :: vertex_STI > *, IteratorSTI < Gitter :: vertex_STI > * >
  GitterPll :: MacroGitterPll :: iteratorTT (const pair < IteratorSTI < vertex_STI > *, IteratorSTI < vertex_STI > * > & p, int) {
  return pair < IteratorSTI < vertex_STI > *, IteratorSTI < vertex_STI > * > 
  (new listSmartpointer__to__iteratorSTI < vertex_STI > (*(const listSmartpointer__to__iteratorSTI < vertex_STI > *)p.first),
         new listSmartpointer__to__iteratorSTI < vertex_STI > (*(const listSmartpointer__to__iteratorSTI < vertex_STI > *)p.second)) ;
}

pair < IteratorSTI < Gitter :: hedge_STI > *, IteratorSTI < Gitter :: hedge_STI > * >
  GitterPll :: MacroGitterPll :: iteratorTT (const hedge_STI *, int i) {
  assert (i < _hedgeTT.size ()) ;
  return pair < IteratorSTI < hedge_STI > *, IteratorSTI < hedge_STI > * > 
  (new listSmartpointer__to__iteratorSTI < hedge_STI > (_hedgeTT [i].first),
         new listSmartpointer__to__iteratorSTI < hedge_STI > (_hedgeTT [i].second)) ;
}

pair < IteratorSTI < Gitter :: hedge_STI > *, IteratorSTI < Gitter :: hedge_STI > * > 
  GitterPll :: MacroGitterPll :: iteratorTT (const pair < IteratorSTI < hedge_STI > *, IteratorSTI < hedge_STI > * > & p, int) {
  return pair < IteratorSTI < hedge_STI > *, IteratorSTI < hedge_STI > * > 
  (new listSmartpointer__to__iteratorSTI < hedge_STI > (*(const listSmartpointer__to__iteratorSTI < hedge_STI > *)p.first),
         new listSmartpointer__to__iteratorSTI < hedge_STI > (*(const listSmartpointer__to__iteratorSTI < hedge_STI > *)p.second)) ;
}

pair < IteratorSTI < Gitter :: hface_STI > *, IteratorSTI < Gitter :: hface_STI > * >
  GitterPll :: MacroGitterPll :: iteratorTT (const hface_STI *, int i) {
  assert (i < _hfaceTT.size ()) ;
  return pair < IteratorSTI < hface_STI > *, IteratorSTI < hface_STI > * > 
  (new listSmartpointer__to__iteratorSTI < hface_STI > (_hfaceTT [i].first),
         new listSmartpointer__to__iteratorSTI < hface_STI > (_hfaceTT [i].second)) ;
}

pair < IteratorSTI < Gitter :: hface_STI > *, IteratorSTI < Gitter :: hface_STI > * > 
  GitterPll :: MacroGitterPll :: iteratorTT (const pair < IteratorSTI < hface_STI > *, IteratorSTI < hface_STI > * > & p, int) {
  return pair < IteratorSTI < hface_STI > *, IteratorSTI < hface_STI > * >
    (new listSmartpointer__to__iteratorSTI < hface_STI > (*(const listSmartpointer__to__iteratorSTI < hface_STI > *)p.first),
     new listSmartpointer__to__iteratorSTI < hface_STI > (*(const listSmartpointer__to__iteratorSTI < hface_STI > *)p.second)) ;
}

bool GitterPll :: refine () {
  cout << "refinepll \n";
  assert (debugOption (5) ? (cout << "**INFO GitterPll :: refine () " << endl, 1) : 1) ;
  const int nl = mpAccess ().nlinks (), start = clock () ;
  bool state = false ;
  vector < vector < hedge_STI * > > innerEdges (nl), outerEdges (nl) ;
  vector < vector < hface_STI * > > innerFaces (nl), outerFaces (nl) ;
  {
    // Erst die Zeiger auf alle Fl"achen und Kanten mit paralleler
  // Mehrdeutigkeit sichern, da die LeafIteratorTT < . > nach dem 
  // Verfeinern auf gitter nicht mehr stimmen werden. Die Technik
  // ist zul"assig, da keine mehrfache Verfeinerung entstehen kann.
  
    {for (int l = 0 ; l < nl ; l ++) {
      LeafIteratorTT < hface_STI > fw (*this,l) ;
      LeafIteratorTT < hedge_STI > dw (*this,l) ;
      for (fw.outer ().first () ; ! fw.outer().done () ; fw.outer ().next ())
        outerFaces [l].push_back (& fw.outer ().item ()) ;
      for (fw.inner ().first () ; ! fw.inner ().done () ; fw.inner ().next ())
        innerFaces [l].push_back (& fw.inner ().item ()) ;
      for (dw.outer ().first () ; ! dw.outer().done () ; dw.outer ().next ())
        outerEdges [l].push_back (& dw.outer ().item ()) ;
      for (dw.inner ().first () ; ! dw.inner ().done () ; dw.inner ().next ())
        innerEdges [l].push_back (& dw.inner ().item ()) ;
    }}
      // jetzt normal verfeinern und den Status der Verfeinerung
  // [unvollst"andige / vollst"andige Verfeinerung] sichern.
    
    __STATIC_phase = 1 ;
    
    state = Gitter :: refine () ;
       
  // Phase des Fl"achenausgleichs an den Schnittfl"achen des
  // verteilten Gitters. Weil dort im sequentiellen Fall pseudorekursive
  // Methodenaufrufe vorliegen k"onnen, muss solange iteriert werden,
  // bis die Situation global station"ar ist.
  
    __STATIC_phase = 2 ;
  
    bool repeat (false) ;
    _refineLoops = 0 ;
    do {
      repeat = false ;
      {
        vector < ObjectStream > osv (nl) ;
        try {
    for (int l = 0 ; l < nl ; l ++) {
            {for (vector < hface_STI * > :: const_iterator i = outerFaces [l].begin () ;
              i != outerFaces [l].end () ; (*i ++)->accessPllX ().accessOuterPllX ().first->getRefinementRequest (osv [l])) ; }
            {for (vector < hface_STI * > :: const_iterator i = innerFaces [l].begin () ;
              i != innerFaces [l].end () ; (*i ++)->accessPllX ().accessOuterPllX ().first->getRefinementRequest (osv [l])) ; }
          }
  } catch (Parallel :: AccessPllException) {
          cerr << "**FEHLER (FATAL) AccessPllException in " << __FILE__ << " " << __LINE__ << endl ; abort () ;
        }
  
        osv = mpAccess ().exchange (osv) ;
  
        try {
    for (int l = 0 ; l < nl ; l ++) {
            {for (vector < hface_STI * > :: const_iterator i = innerFaces [l].begin () ;
              i != innerFaces [l].end () ; repeat |= (*i ++)->accessPllX ().accessOuterPllX ().first->setRefinementRequest (osv [l])) ; }
            {for (vector < hface_STI * > :: const_iterator i = outerFaces [l].begin () ;
              i != outerFaces [l].end () ; repeat |= (*i ++)->accessPllX ().accessOuterPllX ().first->setRefinementRequest (osv [l])) ; }
          }
  } catch (Parallel :: AccessPllException) {
          cerr << "**FEHLER (FATAL) AccessPllException in " << __FILE__ << " " << __LINE__ << endl ; abort () ;
        }
      }

      _refineLoops ++ ;
    } while (mpAccess ().gmax (repeat ? 1 : 0)) ;

  // Jetzt noch die Kantensituation richtigstellen, es gen"ugt ein Durchlauf,
  // weil die Verfeinerung einer Kante keine Fernwirkungen hat. Vorsicht: Die
  // Kanten sind bez"uglich ihrer Identifikation sternf"ormig organisiert, d.h.
  // es muss die Verfeinerungsinformation einmal am Eigent"umer gesammelt und
  // dann wieder zur"ucktransportiert werden, eine einfache L"osung, wie bei
  // den Fl"achen (1/1 Beziehung) scheidet aus.

    __STATIC_phase = 3 ;

    {
      vector < ObjectStream > osv (nl) ;
      {for (int l = 0 ; l < nl ; l ++) 
        for (vector < hedge_STI * > :: const_iterator i = outerEdges [l].begin () ;
          i != outerEdges [l].end () ; (*i ++)->accessPllX ().getRefinementRequest (osv [l])) ;
      }
      osv = mpAccess ().exchange (osv) ;
      {for (int l = 0 ; l < nl ; l ++)
        for (vector < hedge_STI * > :: const_iterator i = innerEdges [l].begin () ;
          i != innerEdges [l].end () ; (*i ++)->accessPllX ().setRefinementRequest (osv [l])) ;
      }
    }   // ~vector < ObjectStream > ... 
    {
      vector < ObjectStream > osv (nl) ;
      {for (int l = 0 ; l < nl ; l ++)
        for (vector < hedge_STI * > :: const_iterator i = innerEdges [l].begin () ;
          i != innerEdges [l].end () ; (*i ++)->accessPllX ().getRefinementRequest (osv [l])) ;
      }
      osv = mpAccess ().exchange (osv) ;
      {for (int l = 0 ; l < nl ; l ++)
        for (vector < hedge_STI * > :: const_iterator i = outerEdges [l].begin () ;
          i != outerEdges [l].end () ; (*i ++)->accessPllX ().setRefinementRequest (osv [l])) ;
      }
    }   // ~vector < ObjectStream > ... 
  }
  
  __STATIC_phase = -1 ;
  
  return state ;
}

void GitterPll :: coarse () {
  assert (debugOption (20) ? (cout << "**INFO GitterPll :: coarse () " << endl, 1) : 1) ;
  const int nl = mpAccess ().nlinks () ;
  
  {
    vector < vector < hedge_STI * > > innerEdges (nl), outerEdges (nl) ;
    vector < vector < hface_STI * > > innerFaces (nl), outerFaces (nl) ;
  
    for (int l = 0 ; l < nl ; l ++) {
    
  // Zun"achst werden f"ur alle Links die Zeiger auf Gitterojekte mit
  // Mehrdeutigkeit gesichert, die an der Wurzel einer potentiellen
  // Vergr"oberungsoperation sitzen -> es sind die Knoten in der Hierarchie,
  // deren Kinder alle Bl"atter sind. Genau diese Knoten sollen gegen"uber
  // der Vergr"oberung blockiert werden und dann die Vergr"oberung falls
  // sie zul"assig ist, sp"ater durchgef"uhrt werden (pending) ;
    
      AccessIteratorTT < hface_STI > :: InnerHandle mfwi (containerPll (),l) ;
      AccessIteratorTT < hface_STI > :: OuterHandle mfwo (containerPll (),l) ;
      AccessIteratorTT < hedge_STI > :: InnerHandle mdwi (containerPll (),l) ;
      AccessIteratorTT < hedge_STI > :: OuterHandle mdwo (containerPll (),l) ;
      
  // Die inneren und a"usseren Iteratoren der potentiell vergr"oberungsf"ahigen
  // Fl"achen "uber den Grobgitterfl"achen. In den Elementen passiert erstmal
  // nichts, solange nicht mit mehrfachen Grobgitterelementen gearbeitet wird.
      
      Insert < AccessIteratorTT < hface_STI > :: InnerHandle, 
        TreeIterator < hface_STI, childs_are_leafs < hface_STI > > > fwi (mfwi) ;
      Insert < AccessIteratorTT < hface_STI > :: OuterHandle, 
        TreeIterator < hface_STI, childs_are_leafs < hface_STI > > > fwo (mfwo) ;
      
  // Die inneren und a"usseren Iteratoren der potentiell vergr"oberungsf"ahigen
  // Kanten "uber den Grobgitterkanten.
      
      Insert < AccessIteratorTT < hedge_STI > :: InnerHandle, 
        TreeIterator < hedge_STI, childs_are_leafs < hedge_STI > > > dwi (mdwi) ;
      Insert < AccessIteratorTT < hedge_STI > :: OuterHandle, 
        TreeIterator < hedge_STI, childs_are_leafs < hedge_STI > > > dwo (mdwo) ;

  // Die inneren und a"usseren Iteratoren der potentiell vergr"oberungsf"ahigen
  // Kanten "uber den Grobgitterfl"achen. Diese Konstruktion wird beim Tetraeder-
  // gitter notwendig, weil dort keine Aussage der Form:
  //

      Insert < AccessIteratorTT < hface_STI > :: InnerHandle, 
        TreeIterator < hface_STI, has_int_edge < hface_STI > > > efi (mfwi) ;
      Insert < AccessIteratorTT < hface_STI > :: OuterHandle, 
        TreeIterator < hface_STI, has_int_edge < hface_STI > > > efo (mfwo) ;
      Wrapper < Insert < AccessIteratorTT < hface_STI > :: InnerHandle, 
        TreeIterator < hface_STI, has_int_edge < hface_STI > > >, InternalEdge > eifi (efi) ;
      Wrapper < Insert < AccessIteratorTT < hface_STI > :: OuterHandle, 
        TreeIterator < hface_STI, has_int_edge < hface_STI > > >, InternalEdge > eifo (efo) ;
      Insert < Wrapper < Insert < AccessIteratorTT < hface_STI > :: InnerHandle, 
        TreeIterator < hface_STI, has_int_edge < hface_STI > > >, InternalEdge >,
  TreeIterator < hedge_STI, childs_are_leafs < hedge_STI > > > dfi (eifi) ;
      Insert < Wrapper < Insert < AccessIteratorTT < hface_STI > :: OuterHandle, 
        TreeIterator < hface_STI, has_int_edge < hface_STI > > >, InternalEdge >,
  TreeIterator < hedge_STI, childs_are_leafs < hedge_STI > > > dfo (eifo) ;

  // Die 'item ()' Resultatwerte (Zeiger) werden in Vektoren gesichert, weil die
  // Kriterien die zur Erzeugung der Iteratoren angewendet wurden (Filter) nach
  // einer teilweisen Vergr"oberung nicht mehr g"ultig sein werden, d.h. die 
  // Iterationsobjekte "andern w"ahrend der Vergr"oberung ihre Eigenschaften.
  // Deshalb werden sie auch am Ende des Blocks aufgegeben. Der Vektor 'cache'
  // ist zul"assig, weil kein Objekt auf das eine Referenz im 'cache' vorliegt
  // beseitigt werden kann. Sie sind alle ein Niveau darunter.

      for (fwi.first () ; ! fwi.done () ; fwi.next ()) innerFaces [l].push_back (& fwi.item ()) ;
      for (fwo.first () ; ! fwo.done () ; fwo.next ()) outerFaces [l].push_back (& fwo.item ()) ;
      for (dwo.first () ; ! dwo.done () ; dwo.next ()) outerEdges [l].push_back (& dwo.item ()) ;
      for (dfo.first () ; ! dfo.done () ; dfo.next ()) outerEdges [l].push_back (& dfo.item ()) ;
      for (dwi.first () ; ! dwi.done () ; dwi.next ()) innerEdges [l].push_back (& dwi.item ()) ;
      for (dfi.first () ; ! dfi.done () ; dfi.next ()) innerEdges [l].push_back (& dfi.item ()) ;
    }
    try {
  // Erstmal alles was mehrdeutig ist, gegen die drohende Vergr"oberung sichern.
  // Danach werden sukzessive die Fl"achenlocks aufgehoben, getestet und
  // eventuell vergr"obert, dann das gleiche Spiel mit den Kanten.

      for (int l = 0 ; l < nl ; l ++) {
        {for (vector < hedge_STI * > :: iterator i = outerEdges [l].begin () ;
            i != outerEdges [l].end () ; (*i ++)->accessPllX ().lockAndTry ()) ; }
        {for (vector < hedge_STI * > :: iterator i = innerEdges [l].begin () ;
            i != innerEdges [l].end () ; (*i ++)->accessPllX ().lockAndTry ()) ; }
        {for (vector < hface_STI * > :: iterator i = outerFaces [l].begin () ;
            i != outerFaces [l].end () ; (*i ++)->accessPllX ().accessOuterPllX ().first->lockAndTry ()) ; }
        {for (vector < hface_STI * > :: iterator i = innerFaces [l].begin () ;
            i != innerFaces [l].end () ; (*i ++)->accessPllX ().accessOuterPllX ().first->lockAndTry ()) ; }
      }
      
        // Gitter :: coarse () ist elementorientiert, d.h. die Vergr"oberung auf Fl"achen und
  // Kanten wird nur durch Vermittlung eines sich vergr"obernden Knotens in der Element-
  // hierarchie angestossen. In allen gegen Vergr"oberung 'gelockten' Fl"achen und Kanten
  // wird die angeforderte Operation zur"uckgewiesen, um erst sp"ater von aussen nochmals
  // angestossen zu werden.
      
      __STATIC_phase = 4 ;
      
      Gitter :: coarse () ;
      
    } catch (Parallel :: AccessPllException) {
      cerr << "**FEHLER (FATAL) AccessPllException beim Vergr\"obern der Elementhierarchie oder\n" ;
      cerr << "  beim locken der Fl\"achen- bzw. Kantenb\"aume aufgetreten. In " << __FILE__ << " " << __LINE__ << endl ;
      abort () ;
    }
    try {
    
  // Phase des Fl"achenausgleichs des verteilten Vergr"oberungsalgorithmus
  // alle Schnittfl"achenpaare werden daraufhin untersucht, ob eine
  // Vergr"oberung in beiden Teilgittern durchgef"uhrt werden darf,
  // wenn ja, wird in beiden Teilgittern vergr"obert und der Vollzug
  // getestet.
  
      __STATIC_phase = 5 ;
    
      vector < vector < int > > clean (nl) ;
      {
        vector < vector < int > > inout (nl) ;
        {for (int l = 0 ; l < nl ; l ++)
          for (vector < hface_STI * > :: iterator i = outerFaces [l].begin () ; i != outerFaces [l].end () ; i ++)
            inout [l].push_back ((*i)->accessPllX ().accessOuterPllX ().first->lockAndTry ()) ;
        }
        inout = mpAccess ().exchange (inout) ;
        {for (int l = 0 ; l < nl ; l ++) {
          clean [l] = vector < int > (innerFaces [l].size (), long (true)) ;
    vector < int > :: iterator j = clean [l].begin (), k = inout [l].begin () ;
          for (vector < hface_STI * > :: iterator i = innerFaces [l].begin () ; i != innerFaces [l].end () ; i ++, j++, k++) {
      assert (j != clean [l].end ()) ; assert (k != inout [l].end ()) ;
      (*j) &= (*k) && (*i)->accessPllX ().accessOuterPllX ().first->lockAndTry () ;
    }
        }}
      }
      {
        vector < vector < int > > inout (nl) ;
        {for (int l = 0 ; l < nl ; l ++) {
          vector < int > :: iterator j = clean [l].begin () ;
    for (vector < hface_STI * > :: iterator i = innerFaces [l].begin () ; i != innerFaces [l].end () ; i ++, j++) {
      inout [l].push_back (*j) ;
      (*i)->accessPllX ().accessOuterPllX ().first->unlockAndResume (bool (*j)) ;
    }
        }}
      
        inout = mpAccess ().exchange (inout) ;
      
        {for (int l = 0 ; l < nl ; l ++) {
          vector < int > :: iterator j = inout [l].begin () ;
          for (vector < hface_STI * > :: iterator i = outerFaces [l].begin () ; i != outerFaces [l].end () ; i ++, j++) {
      assert (j != inout [l].end ()) ;
      (*i)->accessPllX ().accessOuterPllX ().first->unlockAndResume (bool (*j)) ;
    }
        }}
      }
    } catch (Parallel :: AccessPllException) {
      cerr << "**FEHLER (FATAL) AccessPllException beim Vergr\"obern der Fl\"achenb\"aume\n" ;
      cerr << "  aufgetreten. In " << __FILE__ << " " << __LINE__ << endl ;
      abort () ;
    }
    try {
    
  // Phase des Kantenausgleichs im parallelen Vergr"oberungsalgorithmus:
  
      __STATIC_phase  = 6 ;
    
  // Weil hier jede Kante nur eindeutig auftreten darf, muss sie in einem
  // map als Adresse hinterlegt werden, dann k"onnen die verschiedenen
  // Refcounts aus den verschiedenen Links tats"achlich global miteinander
  // abgemischt werden. Dazu werden zun"achst alle eigenen Kanten auf ihre
  // Vergr"oberbarkeit hin untersucht und dieser Zustand (true = vergr"oberbar
  // false = darf nicht vergr"obert werden) im map 'clean' hinterlegt. Dazu
  // kommt noch ein zweiter 'bool' Wert, der anzeigt ob die Kante schon ab-
  // schliessend vergr"obert wurde oder nicht. 
    
      map < hedge_STI *, pair < bool, bool >, less < hedge_STI * > > clean ;
      
      {for (int l = 0 ; l < nl ; l ++)
        for (vector < hedge_STI * > :: iterator i = innerEdges [l].begin () ; i != innerEdges [l].end () ; i ++)
    if (clean.find (*i) == clean.end ()) clean [*i] = pair < bool, bool > ((*i)->accessPllX ().lockAndTry (), true) ;
      }
      {
        vector < vector < int > > inout (nl) ;
        {for (int l = 0 ; l < nl ; l ++)
          for (vector < hedge_STI * > :: iterator i = outerEdges [l].begin () ; i != outerEdges [l].end () ; i ++)
            inout [l].push_back ((*i)->accessPllX ().lockAndTry ()) ;
  }
        inout = mpAccess ().exchange (inout) ;
        {for (int l = 0 ; l < nl ; l ++) {
    vector < int > :: const_iterator j = inout [l].begin () ;
          for (vector < hedge_STI * > :: iterator i = innerEdges [l].begin () ; i != innerEdges [l].end () ; i ++, j++) {
      assert (j != inout [l].end ()) ;
            assert (clean.find (*i) != clean.end ()) ;
            if (*j == false) clean [*i] = pair < bool, bool > (false, clean[*i].second) ; 
    }
        }}
      }
      {
        vector < vector < int > > inout (nl) ;
        {for (int l = 0 ; l < nl ; l ++) {
    for (vector < hedge_STI * > :: iterator i = innerEdges [l].begin () ; i != innerEdges [l].end () ; i ++) {
      assert (clean.find (*i) != clean.end ()) ;
      pair < bool, bool > & a = clean [*i] ;
      inout [l].push_back (a.first) ;
      if (a.second) {
  
  // Wenn wir hier sind, kann die Kante tats"achlich vergr"obert werden, genauer gesagt,
  // sie wird es auch und der R"uckgabewert testet den Vollzug der Aktion. Weil aber nur
  // einmal vergr"obert werden kann, und die Iteratoren 'innerEdges [l]' aber eventuell
  // mehrfach "uber eine Kante hinweglaufen, muss diese Vergr"oberung im map 'clean'
  // vermerkt werden. Dann wird kein zweiter Versuch unternommen.
  
        a.second = false ;
        bool b = (*i)->accessPllX ().unlockAndResume (a.first) ;
        assert (b == a.first) ;
      }
    }
        }}
        inout = mpAccess ().exchange (inout) ;
        {for (int l = 0 ; l < nl ; l ++) {
          vector < int > :: iterator j = inout [l].begin () ;
          for (vector < hedge_STI * > :: iterator i = outerEdges [l].begin () ; i != outerEdges [l].end () ; i ++, j++) {
      assert (j != inout [l].end ()) ;
      
  // Selbe Situation wie oben, aber der Eigent"umer der Kante hat mitgeteilt, dass sie
  // vergr"obert werden darf und auch wird auf allen Teilgebieten also auch hier. Der
  // Vollzug der Vergr"oberung wird durch den R"uckgabewert getestet.
      
      bool b = (*i)->accessPllX ().unlockAndResume (bool (*j)) ;
      assert (b == bool (*j)) ;
    }
        }}
      }
    } catch (Parallel :: AccessPllException) {
      cerr << "**FEHLER (FATAL) AccessPllException beim Vergr\"obern der Kantenb\"aume\n" ;
      cerr << "  aufgetreten. In " << __FILE__ << " " << __LINE__ << endl ;
      abort () ;
    }
  }
  
  __STATIC_phase = -1 ;
  
  return ;
}

bool GitterPll :: adapt () {
  __STATIC_myrank = mpAccess ().myrank () ;
  __STATIC_turn ++ ;
  assert (debugOption (20) ? (cout << "**INFO GitterPll :: adapt ()" << endl, 1) : 1) ;
  assert (! iterators_attached ()) ;
  int start = clock () ;
  bool refined = refine () ;
  int lap = clock () ;
  coarse () ;
  int end = clock () ;
  if (debugOption (1)) {
    float u1 = (float)(lap - start)/(float)(CLOCKS_PER_SEC) ;
    float u2 = (float)(end - lap)/(float)(CLOCKS_PER_SEC) ;
    float u3 = (float)(end - start)/(float)(CLOCKS_PER_SEC) ;
    cout << "**INFO GitterPll :: adapt () [ref (loops)|cse|all] " << u1 << " ("
         << _refineLoops << ") " << u2 << " " << u3 << endl ;
  }
  notifyGridChanges () ;
  loadBalancerGridChangesNotify () ;
  return refined;
}

void GitterPll :: MacroGitterPll :: fullIntegrityCheck (MpAccessLocal & mpa) {
  const int nl = mpa.nlinks (), me = mpa.myrank () ;
  int start = clock () ;
  try {
    vector < vector < int > > inout (nl) ;

    {for (int l = 0 ; l < nl ; l ++) {
      AccessIteratorTT < hface_STI > :: InnerHandle w (*this,l) ;
      for ( w.first () ; ! w.done () ; w.next ()) {
        vector < int > i = w.item ().accessPllX ().checkParallelConnectivity () ;
        copy (i.begin (), i.end (), back_inserter (inout [l])) ;
      }
    }}
    inout = mpa.exchange (inout) ;
    {for (int l = 0 ; l < nl ; l ++) {
      vector < int > :: const_iterator pos = inout [l].begin () ;
      AccessIteratorTT < hface_STI > :: OuterHandle w (*this,l) ;
      for (w.first () ; ! w.done () ; w.next ()) {
        vector < int > t1 = w.item ().accessPllX ().checkParallelConnectivity () ;
        vector < int > t2 (t1.size (), 0) ;
        copy (pos, pos + t1.size (), t2.begin ()) ;
        pos += t1.size () ;
        if (t1 != t2) {
          cerr << "fehler an gebiet " << me << " : " ;
#ifdef IBM_XLC
          copy (t1.begin (), t1.end (), ostream_iterator < int > (cerr, "-")) ;
#elif defined(_SGI)
          copy (t1.begin (), t1.end (), ostream_iterator < int > (cerr, "-")) ;
#else
          copy (t1.begin (), t1.end (), ostream_iterator < int , char > (cerr, "-")) ;
#endif
    cerr << "\t" ;
#ifdef IBM_XLC
          copy (t2.begin (), t2.end (), ostream_iterator < int > (cerr, "-")) ;
#elif defined(_SGI)
          copy (t2.begin (), t2.end (), ostream_iterator < int > (cerr, "-")) ;
#else
          copy (t2.begin (), t2.end (), ostream_iterator < int , char > (cerr, "-")) ;
#endif
          cerr << endl ;
        }
      }
    }}
  } catch (Parallel ::  AccessPllException) {
    cerr << "**FEHLER (FATAL) Parallel :: AccessPllException entstanden in: " << __FILE__ << " " << __LINE__ << endl ;
  }
  return ;
}

void GitterPll :: exchangeDynamicState () {

  // Die Methode wird jedesmal aufgerufen, wenn sich der dynamische
  // Zustand des Gitters ge"andert hat: Verfeinerung und alle Situationen
  // die einer "Anderung des statischen Zustands entsprechen. Sie wird in
  // diesem Fall NACH dem Update des statischen Zustands aufgerufen, und
  // kann demnach von einem korrekten statischen Zustand ausgehen. F"ur
  // Methoden die noch h"aufigere Updates erfordern m"ussen diese in der
  // Regel hier eingeschleift werden.
  int mallocedsize;
{
  //struct mallinfo minfo = mallinfo();
  //cerr << "Anfang exchangeDynamicState(): Blocks allocated: " << (mallocedsize=(minfo.usmblks + minfo.uordblks)) << endl;
}
{
  const int nl = mpAccess ().nlinks () ;
  const int start = clock () ;
  try {
    vector < ObjectStream > osv (nl) ;
    {for (int l = 0 ; l < nl ; l ++) {
      LeafIteratorTT < hface_STI > w (*this,l) ;
      for (w.inner ().first () ; ! w.inner ().done () ; w.inner ().next ()) {
        pair < ElementPllXIF_t *, int > p = w.inner ().item ().accessPllX ().accessInnerPllX () ;
        p.first->writeDynamicState (osv [l], p.second) ;
      }
      for (w.outer ().first () ; ! w.outer ().done () ; w.outer ().next ()) {
        pair < ElementPllXIF_t *, int > p = w.outer ().item ().accessPllX ().accessInnerPllX () ;
        p.first->writeDynamicState (osv [l], p.second) ;
      }
    }}
    osv = mpAccess ().exchange (osv) ;
    {for (int l = 0 ; l < nl ; l ++ ) {
      LeafIteratorTT < hface_STI > w (*this,l) ;
      for (w.outer ().first () ; ! w.outer ().done () ; w.outer ().next ()) {
        pair < ElementPllXIF_t *, int > p = w.outer ().item ().accessPllX ().accessOuterPllX () ;
        p.first->readDynamicState (osv [l], p.second) ;
      }
      for (w.inner ().first () ; ! w.inner ().done () ; w.inner ().next ()) {
        pair < ElementPllXIF_t *, int > p = w.inner ().item ().accessPllX ().accessOuterPllX () ;
        p.first->readDynamicState (osv [l], p.second) ;
      }
    }}
  } catch (Parallel ::  AccessPllException) {
    cerr << "  FEHLER Parallel :: AccessPllException entstanden in: " << __FILE__ << " " << __LINE__ << endl ;
  }
  assert (debugOption (20) ? (cout << "**INFO GitterPll :: exchangeDynamicState () used " 
    << (float)(clock () - start)/(float)(CLOCKS_PER_SEC) << " sec. " << endl, 1) : 1 ) ;

}
{
  //struct mallinfo minfo = mallinfo();
  //cerr << "Ende exchangeDynamicState(): Blocks allocated: " << minfo.usmblks + minfo.uordblks << " "  
  //     << " Blocks used: " << minfo.usmblks + minfo.uordblks - mallocedsize << endl;
}

  return ;
}

void GitterPll :: exchangeStaticState () {

  // Die Methode wird jedesmal aufgerufen, wenn sich der statische
  // Zustand (d.h. der Zustand, der mit dem Makrogitter verbunden ist)
  // ge"andert hat: Makrogitteraufbau und Lastvertielung. Der statische
  // Zustand darf durch Verfeinerung und h"ohere Methoden nicht beeinflusst
  // sein.

  const int start = clock () ;
  try {
    const int nl = mpAccess ().nlinks () ;
    vector < ObjectStream > osv (nl) ;
    {for (int l = 0 ; l < nl ; l ++ ) {
      AccessIteratorTT < hface_STI > :: InnerHandle wi (containerPll (),l) ;
      AccessIteratorTT < hface_STI > :: OuterHandle wo (containerPll (),l) ;
      for (wi.first () ; ! wi.done () ; wi.next ()) {
        pair < ElementPllXIF_t *, int > p = wi.item ().accessPllX ().accessInnerPllX () ;
        p.first->writeStaticState (osv [l], p.second) ;
      }
      for (wo.first () ; ! wo.done () ; wo.next ()) {
        pair < ElementPllXIF_t *, int > p = wo.item ().accessPllX ().accessInnerPllX () ;
        p.first->writeStaticState (osv [l], p.second) ;
      }
    }}
    osv = mpAccess ().exchange (osv) ;
    {for (int l = 0 ; l < nl ; l ++) {
      AccessIteratorTT < hface_STI > :: InnerHandle wi (containerPll (),l) ;
      AccessIteratorTT < hface_STI > :: OuterHandle wo (containerPll (),l) ;
      for (wo.first () ; ! wo.done () ; wo.next ()) {
        pair < ElementPllXIF_t *, int > p = wo.item ().accessPllX ().accessOuterPllX () ;
        p.first->readStaticState (osv [l], p.second) ;
      }
      for (wi.first () ; ! wi.done () ; wi.next ()) {
        pair < ElementPllXIF_t *, int > p = wi.item ().accessPllX ().accessOuterPllX () ;
        p.first->readStaticState (osv [l], p.second) ;
      }
    }}
  } catch (Parallel ::  AccessPllException) {
    cerr << "  FEHLER Parallel :: AccessPllException entstanden in: " << __FILE__ << " " << __LINE__ << endl ;
  }
  assert (debugOption (20) ? (cout << "**INFO GitterPll :: exchangeStaticState () used " 
    << (float)(clock () - start)/(float)(CLOCKS_PER_SEC) << " sec. " << endl, 1) : 1 ) ;
  return ;
}

void GitterPll :: loadBalancerGridChangesNotify () {
  assert (debugOption (20) ? (cout << "**GitterPll :: loadBalancerGridChangesNotify () " << endl, 1) : 1) ;
  const int start = clock (), me = mpAccess ().myrank (), np = mpAccess ().psize () ;
  LoadBalancer :: DataBase db ;
  {
    AccessIterator < hface_STI > :: Handle w (containerPll ()) ;
    for (w.first () ; ! w.done () ; w.next ()) w.item ().accessPllX ().ldbUpdateGraphEdge (db) ;
  }
  {
    AccessIterator < helement_STI > :: Handle w (containerPll ()) ;
    for (w.first () ; ! w.done () ; w.next ()) w.item ().accessPllX ().ldbUpdateGraphVertex (db) ;
  }
  bool neu = false ;
  {
  // Kriterium, wann eine Lastneuverteilung vorzunehmen ist:
  // 
  // load  - eigene ElementLast
  // mean  - mittlere ElementLast
  // nload - Lastverh"altnis

  
    double load = db.accVertexLoad () ;
    vector < double > v (mpAccess ().gcollect (load)) ;
    double mean = accumulate (v.begin (), v.end (), 0.0) / double (np) ;

    for (vector < double > :: iterator i = v.begin () ; i != v.end () ; i ++)
      neu |= (*i > mean ? (*i > (_ldbOver * mean) ? true : false) : (*i < (_ldbUnder * mean) ? true : false)) ;
  }
  if (neu) {
    if (mpAccess ().gmax (_ldbMethod)) {
      repartitionMacroGrid (db) ;
      notifyMacroGridChanges () ;
    }
  }
  return ;
}

void GitterPll :: loadBalancerMacroGridChangesNotify () {

  // Diese Methode beschreibt die Reaktion des Lastverteilers bzw.
  // seiner Datengrundlage auf "Anderungen des Grobgitters, d.h.
  // auf "Anderungen in der Grobgitterverteilung, Gr"osse usw.

  assert (debugOption (20) ? (cout << "**INFO GitterPll :: loadBalancerMacroGridChangesNotify () " << endl, 1) : 1) ;
  int cnt = 0 ;
  AccessIterator < helement_STI > :: Handle w (containerPll ()) ;
  vector < int > sizes = mpAccess ().gcollect (w.size ()) ;
  for (int i = 0 ; i < mpAccess ().myrank () ; cnt += sizes [i++]) ;
  for (w.first () ; ! w.done () ; w.next ()) w.item ().accessPllX ().ldbVertexIndex () = cnt ++ ;
  return ;
}

void GitterPll :: notifyGridChanges () {
  assert (debugOption (20) ? (cout << "**INFO GitterPll :: notifyGridChanges () " << endl, 1) : 1 ) ;
  Gitter :: notifyGridChanges () ;
  exchangeDynamicState () ;
  return ;
}

void GitterPll :: notifyMacroGridChanges () {
  assert (debugOption (20) ? (cout << "**INFO GitterPll :: notifyMacroGridChanges () " << endl, 1) : 1 ) ;
  Gitter :: notifyMacroGridChanges () ;
  Gitter :: notifyGridChanges () ;
  containerPll ().identification (mpAccess ()) ;
  loadBalancerMacroGridChangesNotify () ;
  exchangeStaticState () ;
  exchangeDynamicState () ;
  return ;
}

GitterPll :: GitterPll () : _ldbOver (1.2), _ldbUnder (0.0), _ldbMethod (LoadBalancer :: DataBase :: METIS_PartGraphKway) {
  ifstream in ("lastverteilung.cfg") ;
  if (in) {
    int i ;
    in >> _ldbUnder ;
    in >> _ldbOver ;
    in >> i;
    _ldbMethod = (LoadBalancer :: DataBase :: method) i ;
  } else {
    cerr << "**WARNUNG (IGNORIERT) Datei < lastverteilung.cfg > konnte nicht ge\"offnet werden. Es werden die Standardwerte verwendet." << endl ;
  }
  cout << "**INFO GitterPll :: GitterPll () " << _ldbUnder << " < [Balance der Verteilung] < " << _ldbOver << ",\n" 
       << "       Methode zur Partitionierung \"" << LoadBalancer :: DataBase :: methodToString (_ldbMethod) << "\"" << endl ;
  return ;
}

#endif