CheckerPartitioner.cc 3.31 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


#include "parallel/CheckerPartitioner.h"
#include "Traverse.h"


namespace AMDiS {
Thomas Witkowski's avatar
Thomas Witkowski committed
18
  
19 20 21 22
  void CheckerPartitioner::createInitialPartitioning()
  {
    FUNCNAME("CheckerPartitioner::createInitialPartitioning()");

Thomas Witkowski's avatar
Thomas Witkowski committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
    // In one of the stripes mode, we have to check if the number of macro
    // elements with together with the number of nodes.
    if (mode == 1 || mode == 2 || mode == 3) {
      int elCounter = 0;
      TraverseStack stack;
      ElInfo *elInfo = stack.traverseFirst(mesh, 0, Mesh::CALL_EL_LEVEL);
      while (elInfo) {
	elCounter++;
	elInfo = stack.traverseNext(elInfo);
      }
      
      if (mesh->getDim() == 2)
	TEST_EXIT(elCounter == 2 * mpiSize * mpiSize)
	  ("The number of macro elements is %d, but must be %d for %d number of nodes!",
	   elCounter, 2 * mpiSize * mpiSize, mpiSize);
38

Thomas Witkowski's avatar
Thomas Witkowski committed
39 40 41 42
      if (mesh->getDim() == 3)
	TEST_EXIT(elCounter == 6 * static_cast<int>(pow(mpiSize, 1.5)))
	  ("The number of macro elements is %d, but must be %d for %d number of nodes!",
	   elCounter, 6 * static_cast<int>(pow(mpiSize, 1.5)), mpiSize);
43

Thomas Witkowski's avatar
Thomas Witkowski committed
44
    }
Thomas Witkowski's avatar
Blub  
Thomas Witkowski committed
45 46 47 48 49

    if (multilevel) {
      TEST_EXIT(MPI::COMM_WORLD.Get_size() == 16)
	("Multilevel partitioning is implemented for 16 nodes only!\n");
    }
Thomas Witkowski's avatar
Thomas Witkowski committed
50 51
    
    int dim = mesh->getDim();
52 53 54 55 56
    TraverseStack stack;
    ElInfo *elInfo = stack.traverseFirst(mesh, 0, Mesh::CALL_EL_LEVEL);
    while (elInfo) {
      Element *el = elInfo->getElement();
      int elIndex = el->getIndex();
Thomas Witkowski's avatar
Thomas Witkowski committed
57 58 59 60 61
      int boxIndex = elIndex / (dim == 2 ? 2 : 6);
      int elInRank = -1;

      switch (mode) {
      case 0:
Thomas Witkowski's avatar
Blub  
Thomas Witkowski committed
62 63 64 65 66 67 68
	if (!multilevel) {
	  elInRank = boxIndex;	
	} else {
	  TEST_EXIT_DBG(boxIndex >= 0 && boxIndex <= 15)("Wrong box index!\n");
	  int rs[16] = {0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15};
	  elInRank = rs[boxIndex];
	}
Thomas Witkowski's avatar
Thomas Witkowski committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
	break;

      case 1:
	// x-slices

	{
	  if (dim == 2)
	    elInRank = elIndex / (2 * mpiSize);
	  
	  if (dim == 3) {
	    int boxSliceY = 
	      (boxIndex % mpiSize) / static_cast<int>(sqrt(mpiSize));
	    int boxSliceZ = boxIndex / mpiSize;
	    elInRank = boxSliceY * static_cast<int>(sqrt(mpiSize)) + boxSliceZ;
	  }
	}

	break;

      case 2:
	// y-slices
90

Thomas Witkowski's avatar
Thomas Witkowski committed
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
	{
	  if (dim == 2)
	    elInRank = (elIndex % (2 * mpiSize)) / 2;
	  
	  if (dim == 3) {
	    int boxSliceX = 
	      (boxIndex % mpiSize) % static_cast<int>(sqrt(mpiSize));
	    int boxSliceZ = boxIndex / mpiSize;
	    elInRank = boxSliceX * static_cast<int>(sqrt(mpiSize)) + boxSliceZ;
	  }
	}

	break;

      case 3:
	// z-slices

	{
	  int boxSliceX = (boxIndex % mpiSize) % static_cast<int>(sqrt(mpiSize));
	  int boxSliceY = (boxIndex % mpiSize) / static_cast<int>(sqrt(mpiSize));

	  elInRank = boxSliceX * static_cast<int>(sqrt(mpiSize)) + boxSliceY;
	}

	break;

      default:
	ERROR_EXIT("Mode %d does not exists for checker based mesh partitioning!\n", 
		   mode);
      }

      TEST_EXIT_DBG(elInRank >= 0)("Should not happen!\n");
      TEST_EXIT_DBG(elInRank < mpiSize)("Should not happen!\n");
      
125 126
      elementInRank[elIndex] = (elInRank == mpiRank);
      partitionMap[elIndex] = elInRank;	
Thomas Witkowski's avatar
Thomas Witkowski committed
127
      
128 129 130 131 132
      elInfo = stack.traverseNext(elInfo);
    }
  }

}