escript Revision_
Pattern.h
Go to the documentation of this file.
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
37namespace paso {
38
39struct Pattern;
40typedef boost::shared_ptr<Pattern> Pattern_ptr;
41typedef boost::shared_ptr<const Pattern> const_Pattern_ptr;
42
43struct 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
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
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
134 // Number of cols [CSR]
136 // number of non-zeros
138 // ptr[n] to ptr[n+1] lists indices (in index) of non-zeros in row n
140 // Non-major indices of non-zeros (in CSR this will be col numbers)
142 // pointer to main diagonal entry
144 // number of colors
146 // coloring index: inputs with the same color are not connected
148 // row indices in harwell-boeing format
150 // col indices in harwell-boeing format
152};
153
154
155} // namespace paso
156
157#endif // __PASO_PATTERN_H__
158
#define MATRIX_FORMAT_BLK1
Definition: Paso.h:63
#define MATRIX_FORMAT_OFFSET1
Definition: Paso.h:64
PasoException exception class.
Definition: PasoException.h:34
index_t dim_t
Definition: DataTypes.h:66
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:61
Definition: BiCGStab.cpp:25
boost::shared_ptr< Pattern > Pattern_ptr
Definition: Pattern.h:40
boost::shared_ptr< const Pattern > const_Pattern_ptr
Definition: Pattern.h:41
#define PASO_DLL_API
Definition: paso/src/system_dep.h:29
Definition: escriptcore/src/IndexList.h:29
Definition: Pattern.h:44
dim_t numInput
Definition: Pattern.h:135
index_t * hb_col
Definition: Pattern.h:151
index_t * hb_row
Definition: Pattern.h:149
int type
Definition: Pattern.h:131
dim_t getNumColors()
Definition: Pattern.h:81
index_t * coloring
Definition: Pattern.h:147
index_t * ptr
Definition: Pattern.h:139
dim_t len
Definition: Pattern.h:137
bool isEmpty() const
Definition: Pattern.h:76
void csrToHB()
Definition: Pattern.h:107
dim_t maxDeg() const
Definition: Pattern.h:88
dim_t numOutput
Definition: Pattern.h:133
index_t * index
Definition: Pattern.h:141
dim_t numColors
Definition: Pattern.h:145
index_t * main_iptr
Definition: Pattern.h:143