/[escript]/branches/trilinos_from_5897/paso/src/solve.cpp
ViewVC logotype

Contents of /branches/trilinos_from_5897/paso/src/solve.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6058 - (show annotations)
Thu Mar 10 06:51:55 2016 UTC (3 years, 1 month ago) by caltinay
File size: 5413 byte(s)
added getPtr() to AbstractSystemMatrix so we can now use shared systemmatrix
pointers rather than circumventing them.

1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2016 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16
17
18 /****************************************************************************/
19
20 /* Paso: interface to the direct solvers */
21
22 /****************************************************************************/
23
24 /* Copyrights by ACcESS Australia 2003 */
25 /* Author: Lutz Gross, l.gross@uq.edu.au */
26
27 /****************************************************************************/
28
29 #include "Paso.h"
30 #include "Options.h"
31 #include "performance.h"
32 #include "Preconditioner.h"
33 #include "Solver.h"
34 #include "MKL.h"
35 #include "UMFPACK.h"
36
37 namespace paso {
38
39 void SystemMatrix::solve(double* out, double* in, Options* options) const
40 {
41 Performance pp;
42 index_t package;
43 if (getGlobalNumCols() != getGlobalNumRows()
44 || col_block_size != row_block_size) {
45 throw PasoException("solve: matrix has to be a square matrix.");
46 }
47 //options->show();
48 Performance_open(&pp, options->verbose);
49 package = Options::getPackage(options->method, options->package, options->symmetric, mpi_info);
50 SolverResult res = NoError;
51
52 switch (package) {
53 case PASO_PASO:
54 res = Solver(boost::const_pointer_cast<SystemMatrix>(
55 boost::dynamic_pointer_cast<const SystemMatrix>(getPtr())),
56 out, in, options, &pp);
57 solver_package = PASO_PASO;
58 break;
59
60 case PASO_MKL:
61 if (mpi_info->size > 1) {
62 throw PasoException("solve: MKL package does not support MPI.");
63 }
64 options->converged = false;
65 options->time = escript::gettime();
66 Performance_startMonitor(&pp, PERFORMANCE_ALL);
67 MKL_solve(mainBlock, out, in, options->reordering,
68 options->refinements, options->verbose);
69 solver_package = PASO_MKL;
70 Performance_stopMonitor(&pp, PERFORMANCE_ALL);
71 options->time = escript::gettime()-options->time;
72 options->set_up_time = 0;
73 options->residual_norm = 0.;
74 options->num_iter = 0;
75 options->converged = true;
76 break;
77
78 case PASO_UMFPACK:
79 if (mpi_info->size > 1) {
80 throw PasoException("solve: UMFPACK package does not support MPI.");
81 }
82 options->converged = false;
83 options->time = escript::gettime();
84 Performance_startMonitor(&pp, PERFORMANCE_ALL);
85 UMFPACK_solve(mainBlock, out, in, options->refinements, options->verbose);
86 solver_package = PASO_UMFPACK;
87 Performance_stopMonitor(&pp, PERFORMANCE_ALL);
88 options->time = escript::gettime()-options->time;
89 options->set_up_time = 0;
90 options->residual_norm = 0.;
91 options->num_iter = 0;
92 options->converged = true;
93 break;
94
95 default:
96 throw PasoException("solve: unknown package code");
97 break;
98 }
99
100 if (res == Divergence) {
101 // cancel divergence errors
102 if (options->accept_failed_convergence) {
103 if (options->verbose)
104 printf("paso: failed convergence error has been canceled as requested.\n");
105 } else {
106 throw PasoException("Solver: No improvement during iteration. Iterative solver gives up.");
107 }
108 } else if (res == MaxIterReached) {
109 // cancel divergence errors
110 if (options->accept_failed_convergence) {
111 if (options->verbose)
112 printf("paso: failed convergence error has been canceled as requested.\n");
113 } else {
114 throw PasoException("Solver: maximum number of iteration steps reached.\nReturned solution does not fulfil stopping criterion.");
115 }
116 } else if (res == InputError) {
117 throw PasoException("Solver: illegal dimension in iterative solver.");
118 } else if (res == NegativeNormError) {
119 throw PasoException("Solver: negative energy norm (try other solver or preconditioner).");
120 } else if (res == Breakdown) {
121 throw PasoException("Solver: fatal break down in iterative solver.");
122 } else if (res != NoError) {
123 throw PasoException("Solver: Generic error in solver.");
124 }
125 Performance_close(&pp, options->verbose);
126 }
127
128 void solve_free(SystemMatrix* in)
129 {
130 if (!in) return;
131
132 switch(in->solver_package) {
133 case PASO_PASO:
134 Solver_free(in);
135 break;
136
137 case PASO_SMOOTHER:
138 Preconditioner_Smoother_free((Preconditioner_Smoother*) in->solver_p);
139 break;
140
141 case PASO_MKL:
142 MKL_free(in->mainBlock.get());
143 break;
144
145 case PASO_UMFPACK:
146 UMFPACK_free(in->mainBlock.get());
147 break;
148 }
149 }
150
151 } // namespace paso
152

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision
svn:mergeinfo /branches/4.0fordebian/paso/src/solve.cpp:5567-5588 /branches/amg_from_3530/paso/src/solve.cpp:3531-3826 /branches/lapack2681/paso/src/solve.cpp:2682-2741 /branches/pasowrap/paso/src/solve.cpp:3661-3674 /branches/py3_attempt2/paso/src/solve.cpp:3871-3891 /branches/restext/paso/src/solve.cpp:2610-2624 /branches/ripleygmg_from_3668/paso/src/solve.cpp:3669-3791 /branches/stage3.0/paso/src/solve.cpp:2569-2590 /branches/symbolic_from_3470/paso/src/solve.cpp:3471-3974 /branches/symbolic_from_3470/ripley/test/python/paso/src/solve.cpp:3517-3974 /release/3.0/paso/src/solve.cpp:2591-2601 /release/4.0/paso/src/solve.cpp:5380-5406 /trunk/paso/src/solve.cpp:4257-4344,5898-6007 /trunk/ripley/test/python/paso/src/solve.cpp:3480-3515

  ViewVC Help
Powered by ViewVC 1.1.26