ConditionalEstimator.cc 3.25 KB
Newer Older
1
2
3
4
5
6
7
8
9
#include "ConditionalEstimator.h"
#include "ElInfo.h"
#include "PartitionElementData.h"
#include "Element.h"
#include "Traverse.h"
#include "mpi.h"

namespace AMDiS {

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  ConditionalEstimator::ConditionalEstimator(Estimator* decorated)
    : decoratedEstimator_(decorated),
      elementCount_(0), 
      row_(decorated ? decorated->getRow() : 0)	
  {
    FUNCNAME("ConditionalEstimator::ConditionalEstimator(Estimator* decorated)");
    
    if (decorated!=NULL) {
      name = decorated->getName();
      int swap;
      int retVal = 
	Parameters::getGlobalParameter(0, name + "->estimate outer", "%d", &swap);

      if (retVal > 0)
	estimateOut = (bool)swap;
      else
	estimateOut = false;
    }
  }

30
31
  double ConditionalEstimator::estimate(double ts) 
  {
32
    if (decoratedEstimator_) {
33
34
35
36
37
38
39
40
41
42

      double partition_sum = 0.0;
      elementCount_ = 0;
      decoratedEstimator_->init(ts);

      mesh = decoratedEstimator_->getMesh();
      traverseFlag = decoratedEstimator_->getTraverseFlag();

      TraverseStack stack;
      ElInfo *elInfo = stack.traverseFirst(mesh, -1, traverseFlag);
43
      while (elInfo) {
44
45
46
	PartitionElementData *elData = dynamic_cast<PartitionElementData*>
	  (elInfo->getElement()->getElementData(PARTITION_ED));

47
	TEST_EXIT_DBG(elInfo->getElement()->isLeaf())("element not leaf\n");
48
	TEST_EXIT_DBG(elData)("no partition data on leaf element %d (rank %d)\n", 
49
50
			      elInfo->getElement()->getIndex(),
			      MPI::COMM_WORLD.Get_rank());
51
52
53
54

	PartitionStatus status = elData->getPartitionStatus();
      
	if (status == IN || status == OVERLAP || (estimateOut && status==OUT)) 
55
	  decoratedEstimator_->estimateElement(elInfo);
56
57
58
	else   
	  elInfo->getElement()->setMark(0);

59
60
61
62
	elInfo = stack.traverseNext(elInfo);
      }

      elInfo = stack.traverseFirst(mesh, -1, traverseFlag);
63
      while (elInfo) {
64
65
66
67
	PartitionElementData *elData = dynamic_cast<PartitionElementData*>
	  (elInfo->getElement()->getElementData(PARTITION_ED));
	PartitionStatus status = elData->getPartitionStatus();
	if (status == IN || status==OVERLAP || (estimateOut && status==OUT)) {
68
69
	  elementCount_++;
	  partition_sum += elInfo->getElement()->getEstimation(row_);
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
	elInfo = stack.traverseNext(elInfo);
      }

      // !!! test !!!
      double total_sum = 0.0;
      MPI::COMM_WORLD.Allreduce(&partition_sum,
				&total_sum,
				1,
				MPI_DOUBLE,
				MPI_SUM);

      decoratedEstimator_->setErrorSum(total_sum);

      double total_max = 0.0;
      est_max = decoratedEstimator_->getErrorMax();
      MPI::COMM_WORLD.Allreduce(&est_max,
				&total_max,
				1,
				MPI_DOUBLE,
				MPI_MAX);

      decoratedEstimator_->setErrorMax(total_max);
    
      decoratedEstimator_->exit();

      est_sum = decoratedEstimator_->getErrorSum();
      est_max = decoratedEstimator_->getErrorMax();

      // !!! test !!!
#if 0
      decoratedEstimator_->exit();

      est_sum = sqrt(partition_sum); //decoratedEstimator_->getErrorSum();
      est_t_sum = decoratedEstimator_->getTimeEst();
      est_max = decoratedEstimator_->getErrorMax();
#endif

      //   MSG("rank %d , estimate %e (total %e) elements %d (total %d)\n", 
      //       MPI::COMM_WORLD.Get_rank(), est_sum, total_sum,
      //       elementCount_,
      //       mesh->getNumberOfLeaves());

      return est_sum;
    } else {
      return 0.0;
    }
  }

}