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

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

Parent Directory Parent Directory | Revision Log Revision Log


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


1 ksteube 1313
2 jfenwick 3981 /*****************************************************************************
3 ksteube 1811 *
4 uqaeller 6939 * Copyright (c) 2003-2020 by The University of Queensland
5 jfenwick 3981 * http://www.uq.edu.au
6 ksteube 1811 *
7     * Primary Business: Queensland, Australia
8 jfenwick 6112 * Licensed under the Apache License, version 2.0
9     * http://www.apache.org/licenses/LICENSE-2.0
10 ksteube 1811 *
11 jfenwick 3981 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 jfenwick 4657 * Development 2012-2013 by School of Earth Sciences
13 uqaeller 6939 * Development from 2014-2017 by Centre for Geoscience Computing (GeoComp)
14     * Development from 2019 by School of Earth and Environmental Sciences
15     **
16 jfenwick 3981 *****************************************************************************/
17 ksteube 1313
18 ksteube 1811
19 caltinay 4803 /****************************************************************************/
20 ksteube 1313
21 caltinay 4819 /* Paso: CSC/CSR sparse matrix pattern */
22 ksteube 1313
23 caltinay 4803 /****************************************************************************/
24 ksteube 1313
25 jfenwick 2608 /* Author: Lutz Gross, l.gross@uq.edu.au */
26 ksteube 1313
27 caltinay 4803 /****************************************************************************/
28 ksteube 1313
29 caltinay 4803 #ifndef __PASO_PATTERN_H__
30     #define __PASO_PATTERN_H__
31 ksteube 1313
32 gross 3312 #include "Paso.h"
33 uqaeller 7011 #include "PasoException.h"
34 ksteube 1313
35 caltinay 6001 #include <escript/IndexList.h>
36    
37 caltinay 4803 namespace paso {
38 ksteube 1313
39 caltinay 4819 struct Pattern;
40     typedef boost::shared_ptr<Pattern> Pattern_ptr;
41     typedef boost::shared_ptr<const Pattern> const_Pattern_ptr;
42    
43 uqaeller 7011 struct PASO_DLL_API Pattern : boost::enable_shared_from_this<Pattern>
44 caltinay 4803 {
45 caltinay 4819 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 caltinay 6001 const escript::IndexList* index_list_array,
70 caltinay 4819 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 caltinay 4869 loc_deg=std::max(loc_deg, ptr[i+1]-ptr[i]);
97 caltinay 4819 }
98     #pragma omp critical
99     {
100 caltinay 4869 deg = std::max(deg, loc_deg);
101 caltinay 4819 }
102     }
103     return deg;
104     }
105    
106 uqaeller 7011 // 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 caltinay 4819
115 uqaeller 7011 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 caltinay 4803 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 caltinay 4819 index_t* main_iptr;
144 caltinay 4803 // number of colors
145     dim_t numColors;
146     // coloring index: inputs with the same color are not connected
147     index_t* coloring;
148 uqaeller 7011 // row indices in harwell-boeing format
149     index_t* hb_row;
150     // col indices in harwell-boeing format
151     index_t* hb_col;
152 caltinay 4803 };
153 ksteube 1313
154 phornby 2071
155 caltinay 4803 } // namespace paso
156 phornby 2071
157 caltinay 4803 #endif // __PASO_PATTERN_H__
158    

  ViewVC Help
Powered by ViewVC 1.1.26