ParallelDomainVec.cc 2.94 KB
Newer Older
1
#include "boost/lexical_cast.hpp"
2
3
4
#include "ParallelDomainVec.h"
#include "ProblemVec.h"
#include "ProblemInstat.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
5
#include "SystemVector.h"
6
#include "Serializer.h"
7
8
9

namespace AMDiS {

10
11
  using boost::lexical_cast;

12
  ParallelDomainVec::ParallelDomainVec(ProblemVec *problem,
13
				       ProblemInstatVec *problemInstat)
14
    : ParallelDomainBase(problem, 
15
16
17
18
19
20
21
22
23
24
			 problemInstat, 
			 problem->getFESpace(0),
			 problem->getRefinementManager(0)),
      probVec(problem)
  {
    FUNCNAME("ParallelDomainVec::ParallelDomainVec()");

    info = probVec->getInfo();
    nComponents = probVec->getNumComponents();

25
26
    // Test if all fe spaces are equal. Yet, different fe spaces are not supported for
    // domain parallelization.
27
28
29
30
    const FiniteElemSpace *fe = probVec->getFESpace(0);
    for (int i = 0; i < nComponents; i++)
      TEST_EXIT(fe == probVec->getFESpace(i))
	("Parallelization does not supported different FE spaces!\n");
31
32
33
34
35
36

    // Create parallel serialization file writer, if needed.
    int writeSerialization = 0;
    GET_PARAMETER(0, name + "->output->write serialization", "%d", &writeSerialization);
    if (writeSerialization)
      problem->getFileWriterList().push_back(new Serializer<ParallelDomainVec>(this));
37
38
39
40
41
42
43
44
45
46
47
48

    int readSerialization = 0;
    GET_PARAMETER(0, name + "->input->read serialization", "%d", &readSerialization);
    if (readSerialization) {
      std::string filename = "";
      GET_PARAMETER(0, name + "->input->serialization filename", &filename);
      filename += ".p" + lexical_cast<std::string>(mpiRank);
      MSG("Start serialization with %s\n", filename.c_str());
      std::ifstream in(filename.c_str());
      deserialize(in);
      in.close();
    }
49
50
51
52
53
54
55
56
57
  }


  void ParallelDomainVec::initParallelization(AdaptInfo *adaptInfo)
  {
    FUNCNAME("ParallelDomainVec::initParallelization()");

    ParallelDomainBase::initParallelization(adaptInfo);

Thomas Witkowski's avatar
Thomas Witkowski committed
58
    for (int i = 0; i < nComponents; i++) {
59
      for (int j = 0; j < nComponents; j++)
60
61
62
63
64
 	if (probVec->getSystemMatrix(i, j))
 	  probVec->getSystemMatrix(i, j)->setRankDofs(isRankDof);

      TEST_EXIT_DBG(probVec->getRHS()->getDOFVector(i))("No rhs vector!\n");
      TEST_EXIT_DBG(probVec->getSolution()->getDOFVector(i))("No solution vector!\n");
Thomas Witkowski's avatar
Thomas Witkowski committed
65
66
67
68

      probVec->getRHS()->getDOFVector(i)->setRankDofs(isRankDof);
      probVec->getSolution()->getDOFVector(i)->setRankDofs(isRankDof);
    }
69
70
  }

71

72
73
74
75
76
77
78
79
80
81
  void ParallelDomainVec::solve()
  {
    FUNCNAME("ParallelDomainVec::solve()");

#ifdef _OPENMP
    double wtime = omp_get_wtime();
#endif
    clock_t first = clock();

    fillPetscMatrix(probVec->getSystemMatrix(), probVec->getRHS());      
82
    solvePetscMatrix(*(probVec->getSolution()));
83
84
85
86
87
88
89
90

#ifdef _OPENMP
    INFO(info, 8)("solution of discrete system needed %.5f seconds system time / %.5f seconds wallclock time\n",
		   TIME_USED(first, clock()),
		   omp_get_wtime() - wtime);
#else
    INFO(info, 8)("solution of discrete system needed %.5f seconds\n",
		   TIME_USED(first, clock()));
91
#endif    
92
93
94
  }

}