CheckerPartitioner.cc 2.96 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
45
46
    }
    
    int dim = mesh->getDim();
47
48
49
50
51
    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
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
      int boxIndex = elIndex / (dim == 2 ? 2 : 6);
      int elInRank = -1;

      switch (mode) {
      case 0:
	elInRank = boxIndex;
	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
79

Thomas Witkowski's avatar
Thomas Witkowski committed
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
	{
	  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");
      
114
115
      elementInRank[elIndex] = (elInRank == mpiRank);
      partitionMap[elIndex] = elInRank;	
Thomas Witkowski's avatar
Thomas Witkowski committed
116
      
117
118
119
120
121
      elInfo = stack.traverseNext(elInfo);
    }
  }

}