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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5933 - (show annotations)
Wed Feb 17 23:53:30 2016 UTC (22 months ago) by caltinay
File size: 3961 byte(s)
sync with trunk.

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: Merged solver for AMG */
21
22 /****************************************************************************/
23
24 /* Author: lgao@uq.edu.au, l.gross@uq.edu.au */
25
26 /****************************************************************************/
27
28 #include "MergedSolver.h"
29 #include "Options.h"
30 #include "Preconditioner.h"
31 #include "PasoUtil.h"
32 #include "UMFPACK.h"
33 #include "MKL.h"
34
35 namespace paso {
36
37 MergedSolver::MergedSolver(const_SystemMatrix_ptr M, const Options* options)
38 {
39 const index_t rank = M->mpi_info->rank;
40 const index_t size = M->mpi_info->size;
41 const dim_t global_n = M->getGlobalNumRows();
42 const dim_t n_block = M->mainBlock->row_block_size;
43 const dim_t* dist = M->pattern->input_distribution->first_component;
44
45 SparseMatrix_ptr M_temp(M->mergeSystemMatrix());
46
47 mpi_info = M->mpi_info;
48 reordering = options->reordering;
49 refinements = options->coarse_matrix_refinements;
50 //verbose = options->verbose;
51 verbose = false;
52 sweeps = options->pre_sweeps+options->post_sweeps;
53
54 // First, gather x and b into rank 0
55 b = new double[global_n*n_block];
56 x = new double[global_n*n_block];
57 counts = new int[size];
58 offset = new int[size];
59
60 #pragma omp parallel for
61 for (dim_t i=0; i<size; i++) {
62 const dim_t p = dist[i];
63 counts[i] = (dist[i+1] - p)*n_block;
64 offset[i] = p*n_block;
65 }
66
67 if (rank == 0) {
68 #ifdef MKL
69 A = M_temp->unroll(MATRIX_FORMAT_BLK1 + MATRIX_FORMAT_OFFSET1);
70 A->solver_package = PASO_MKL;
71 #elif defined USE_UMFPACK
72 A = M_temp->unroll(MATRIX_FORMAT_BLK1 + MATRIX_FORMAT_CSC);
73 A->solver_package = PASO_UMFPACK;
74 #else
75 A->solver_p = Preconditioner_LocalSmoother_alloc(A,
76 (options->smoother == PASO_JACOBI), verbose);
77 A->solver_package = PASO_SMOOTHER;
78 #endif
79 }
80 }
81
82 MergedSolver::~MergedSolver()
83 {
84 delete[] x;
85 delete[] b;
86 delete[] counts;
87 delete[] offset;
88 }
89
90 void MergedSolver::solve(double* local_x, const double* local_b)
91 {
92 const index_t rank = mpi_info->rank;
93 const dim_t count = counts[rank];
94
95 #ifdef ESYS_MPI
96 MPI_Gatherv(const_cast<double*>(local_b), count, MPI_DOUBLE, b, counts,
97 offset, MPI_DOUBLE, 0, mpi_info->comm);
98 #else
99 #pragma omp parallel for
100 for (dim_t i=0; i<count; i++) {
101 b[i] = local_b[i];
102 x[i] = local_x[i];
103 }
104 #endif
105 if (rank == 0) {
106 switch (A->solver_package) {
107 case PASO_MKL:
108 MKL_solve(A, x, b, reordering, refinements, verbose);
109 break;
110 case PASO_UMFPACK:
111 UMFPACK_solve(A, x, b, refinements, verbose);
112 break;
113 case PASO_SMOOTHER:
114 Preconditioner_LocalSmoother_solve(A, reinterpret_cast<Preconditioner_LocalSmoother*>(A->solver_p), x, b, sweeps, false);
115 break;
116 }
117 }
118 #ifdef ESYS_MPI
119 // now we need to distribute the solution to all ranks
120 MPI_Scatterv(x, counts, offset, MPI_DOUBLE, local_x, count, MPI_DOUBLE,
121 0, mpi_info->comm);
122 #else
123 #pragma omp parallel for
124 for (dim_t i=0; i<count; i++)
125 local_x[i] = x[i];
126 #endif
127 }
128
129 } // namespace paso
130

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26