/[escript]/trunk/paso/src/Pattern.h
ViewVC logotype

Contents of /trunk/paso/src/Pattern.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7011 - (show annotations)
Wed Jul 22 04:13:34 2020 UTC (9 months, 2 weeks ago) by uqaeller
File MIME type: text/plain
File size: 4525 byte(s)
Prototype for the builtin MUMPS solver.


1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2020 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
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-2017 by Centre for Geoscience Computing (GeoComp)
14 * Development from 2019 by School of Earth and Environmental Sciences
15 **
16 *****************************************************************************/
17
18
19 /****************************************************************************/
20
21 /* Paso: CSC/CSR sparse matrix pattern */
22
23 /****************************************************************************/
24
25 /* Author: Lutz Gross, l.gross@uq.edu.au */
26
27 /****************************************************************************/
28
29 #ifndef __PASO_PATTERN_H__
30 #define __PASO_PATTERN_H__
31
32 #include "Paso.h"
33 #include "PasoException.h"
34
35 #include <escript/IndexList.h>
36
37 namespace paso {
38
39 struct Pattern;
40 typedef boost::shared_ptr<Pattern> Pattern_ptr;
41 typedef boost::shared_ptr<const Pattern> const_Pattern_ptr;
42
43 struct PASO_DLL_API Pattern : boost::enable_shared_from_this<Pattern>
44 {
45 Pattern(int type, dim_t numOutput, dim_t numInput, index_t* ptr,
46 index_t* index);
47
48 ~Pattern();
49
50 Pattern_ptr unrollBlocks(int newType, dim_t outputBlockSize,
51 dim_t inputBlockSize);
52
53 Pattern_ptr getSubpattern(dim_t newNumRows, dim_t newNumCols,
54 const index_t* rowList,
55 const index_t* newColIndex) const;
56
57 /// Searches for a maximal independent set MIS in the matrix pattern
58 void mis(index_t* mis_marker) const;
59
60 void reduceBandwidth(index_t* oldToNew);
61
62 Pattern_ptr multiply(int type, const_Pattern_ptr other) const;
63
64 Pattern_ptr binop(int type, const_Pattern_ptr other) const;
65
66 index_t* borrowMainDiagonalPointer();
67
68 static Pattern_ptr fromIndexListArray(dim_t n0, dim_t n,
69 const escript::IndexList* index_list_array,
70 index_t range_min, index_t range_max, index_t index_offset);
71
72 index_t* borrowColoringPointer();
73
74 dim_t getBandwidth(index_t* label) const;
75
76 inline bool isEmpty() const
77 {
78 return (!ptr && !index);
79 }
80
81 inline dim_t getNumColors()
82 {
83 // make sure numColors is defined
84 borrowColoringPointer();
85 return numColors;
86 }
87
88 inline dim_t maxDeg() const
89 {
90 dim_t deg = 0;
91 #pragma omp parallel
92 {
93 dim_t loc_deg=0;
94 #pragma omp for
95 for (dim_t i = 0; i < numInput; ++i) {
96 loc_deg=std::max(loc_deg, ptr[i+1]-ptr[i]);
97 }
98 #pragma omp critical
99 {
100 deg = std::max(deg, loc_deg);
101 }
102 }
103 return deg;
104 }
105
106 // convert csr row ptr and col indices to harwell-boeing format
107 inline void csrToHB()
108 {
109 // TODO: add openmp
110 if (! (type & (MATRIX_FORMAT_OFFSET1 + MATRIX_FORMAT_BLK1)) ) {
111 throw PasoException(
112 "Paso: Harwell-Boeing format requires CSR format with index offset 1 and block size 1.");
113 }
114
115 if ( !(hb_row == NULL && hb_col == NULL) ) {
116 return;
117 }
118
119 hb_row = new index_t[len];
120 hb_col = new index_t[len];
121 for (dim_t i=0, k=0; i<numOutput; i++)
122 {
123 for (dim_t j=ptr[i]; j<ptr[i+1]; j++, k++)
124 {
125 hb_row[k] = i+1;
126 hb_col[k] = index[j-1];
127 }
128 }
129 }
130
131 int type;
132 // Number of rows in the ptr array [CSR] / number of cols for CSC
133 dim_t numOutput;
134 // Number of cols [CSR]
135 dim_t numInput;
136 // number of non-zeros
137 dim_t len;
138 // ptr[n] to ptr[n+1] lists indices (in index) of non-zeros in row n
139 index_t* ptr;
140 // Non-major indices of non-zeros (in CSR this will be col numbers)
141 index_t* index;
142 // pointer to main diagonal entry
143 index_t* main_iptr;
144 // number of colors
145 dim_t numColors;
146 // coloring index: inputs with the same color are not connected
147 index_t* coloring;
148 // row indices in harwell-boeing format
149 index_t* hb_row;
150 // col indices in harwell-boeing format
151 index_t* hb_col;
152 };
153
154
155 } // namespace paso
156
157 #endif // __PASO_PATTERN_H__
158

  ViewVC Help
Powered by ViewVC 1.1.26