PetscProblemStat.cc 3.63 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//
// 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 <vector>
#include <set>

16
#include "io/VtkWriter.h"
17
18
#include "parallel/PetscProblemStat.h"
#include "parallel/PetscSolver.h"
19
#include "parallel/MpiHelper.h"
20
#include "parallel/BddcMlSolver.h"
21
22
23
24
25
26

namespace AMDiS {

  using namespace std;


27
28
  PetscProblemStat::PetscProblemStat(string nameStr,
				     ProblemIterationInterface *problemIteration)
29
30
    : ParallelProblemStatBase(nameStr, problemIteration),
      deleteSolver(true)
31
32
33
  {
    FUNCNAME("PetscProblemStat::PetscProblemStat()");

34
35
    string tmp("");
    Parameters::get("parallel->solver", tmp);
36
    
37
    if (tmp == "petsc-schur") {
38
      petscSolver = new PetscSolverSchur();
39
    } else if (tmp == "petsc-feti") {
40
      petscSolver = new PetscSolverFeti();
41
    } else if (tmp == "petsc-block") {
42
      petscSolver = new PetscSolverGlobalBlockMatrix();
43
    } else if (tmp == "petsc" || tmp == "") {
44
      petscSolver = new PetscSolverGlobalMatrix();
45
    } else if (tmp == "bddcml") {
46
47
48
49
50
#ifdef HAVE_BDDC_ML
      petscSolver = new BddcMlSolver();
#else
      ERROR_EXIT("AMDiS was compiled without BDDC-ML support!\n");
#endif
51
    } else {
52
      ERROR_EXIT("No parallel solver %s available!\n", tmp.c_str());
53
    }
54
55
56
57

    tmp = "";
    Parameters::get(nameStr + "->solver->petsc prefix", tmp);
    petscSolver->setKspPrefix(tmp);    
58
59
60
  }


61
62
63
64
65
66
67
68
  PetscProblemStat::PetscProblemStat(string nameStr,
				     PetscSolver *solver)
    : ParallelProblemStatBase(nameStr, NULL),
      petscSolver(solver),
      deleteSolver(false)
  {}


69
70
71
72
73
74
75
76
77
78
  void PetscProblemStat::initialize(Flag initFlag, 
				    ProblemStatSeq* adoptProblem,
				    Flag adoptFlag)
  {
      ParallelProblemStatBase::initialize(initFlag, adoptProblem, adoptFlag);

      meshDistributor->setBoundaryDofRequirement(petscSolver->getBoundaryDofRequirement());
  }


79
80
81
  void PetscProblemStat::solve(AdaptInfo *adaptInfo,
			       bool createMatrixData,
			       bool storeMatrixData)
82
83
84
85
86
87
88
  {
    FUNCNAME("PetscProblemStat::solve()");

    TEST_EXIT(meshDistributor)("Should not happen!\n");

    double wtime = MPI::Wtime();

89
90
91
92
93
94
95
96
97
98
#if 0
    double vm, rss;
    processMemUsage(vm, rss);       
    MSG("STAGE 1\n");
    MSG("My memory usage is VM = %.1f MB    RSS = %.1f MB\n", vm, rss);    
    mpi::globalAdd(vm);
    mpi::globalAdd(rss);
    MSG("Overall memory usage is VM = %.1f MB    RSS = %.1f MB\n", vm, rss);
#endif

99
    if (createMatrixData) {
100
101
102
103
      petscSolver->setMeshDistributor(meshDistributor, 
				      meshDistributor->getMpiComm(),
				      PETSC_COMM_SELF);
      petscSolver->setDofMapping(&(meshDistributor->getDofMap()));
104
105
106
107
108
      petscSolver->fillPetscMatrix(systemMatrix);
    }

    petscSolver->fillPetscRhs(rhs);

109
110
111
112
113
114
115
116
117
#if 0
    processMemUsage(vm, rss);   
    MSG("STAGE 2\n");
    MSG("My memory usage is VM = %.1f MB    RSS = %.1f MB\n", vm, rss);    
    mpi::globalAdd(vm);
    mpi::globalAdd(rss);
    MSG("Overall memory usage is VM = %.1f MB    RSS = %.1f MB\n", vm, rss);
#endif

118
    petscSolver->solvePetscMatrix(*solution, adaptInfo);   
119

120
121
    petscSolver->destroyVectorData();

122
123
124
    if (!storeMatrixData)
      petscSolver->destroyMatrixData();

125
126
127
128
129
130
131
132
133
#if 0
    processMemUsage(vm, rss);   
    MSG("STAGE 3\n");
    MSG("My memory usage is VM = %.1f MB    RSS = %.1f MB\n", vm, rss);    
    mpi::globalAdd(vm);
    mpi::globalAdd(rss);
    MSG("Overall memory usage is VM = %.1f MB    RSS = %.1f MB\n", vm, rss);
#endif

134
135
136
137
138
    INFO(info, 8)("solution of discrete system needed %.5f seconds\n", 
		  MPI::Wtime() - wtime);
  }

}