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 
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 
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 
MATRIX_FORMAT_BLK1
#define MATRIX_FORMAT_BLK1
Definition: Paso.h:63
paso::Pattern::mis
void mis(index_t *mis_marker) const
Searches for a maximal independent set MIS in the matrix pattern.
Definition: Pattern_mis.cpp:48
paso::Pattern::unrollBlocks
Pattern_ptr unrollBlocks(int newType, dim_t outputBlockSize, dim_t inputBlockSize)
Definition: Pattern.cpp:249
PASO_DLL_API
#define PASO_DLL_API
Definition: paso/src/system_dep.h:29
paso::Pattern::csrToHB
void csrToHB()
Definition: Pattern.h:107
paso::Pattern::hb_row
index_t * hb_row
Definition: Pattern.h:149
escript::IndexList::toArray
void toArray(DataTypes::index_t *array, DataTypes::index_t range_min, DataTypes::index_t range_max, DataTypes::index_t index_offset) const
index list to array
Definition: escriptcore/src/IndexList.h:68
paso::Pattern::fromIndexListArray
static Pattern_ptr fromIndexListArray(dim_t n0, dim_t n, const escript::IndexList *index_list_array, index_t range_min, index_t range_max, index_t index_offset)
Definition: Pattern.cpp:105
paso::Pattern::hb_col
index_t * hb_col
Definition: Pattern.h:151
paso::util::cumsum
index_t cumsum(dim_t N, index_t *array)
calculates the cumulative sum in array and returns the total sum
Definition: PasoUtil.cpp:86
paso::Pattern::maxDeg
dim_t maxDeg() const
Definition: Pattern.h:88
paso::Pattern::numColors
dim_t numColors
Definition: Pattern.h:145
paso::Pattern::numInput
dim_t numInput
Definition: Pattern.h:135
paso::Pattern::borrowColoringPointer
index_t * borrowColoringPointer()
Definition: Pattern.cpp:166
paso::Pattern::numOutput
dim_t numOutput
Definition: Pattern.h:133
MATRIX_FORMAT_OFFSET1
#define MATRIX_FORMAT_OFFSET1
Definition: Paso.h:64
paso::Pattern::getNumColors
dim_t getNumColors()
Definition: Pattern.h:81
paso::Pattern
Definition: Pattern.h:44
escript::IndexList::count
DataTypes::dim_t count(DataTypes::index_t range_min, DataTypes::index_t range_max) const
counts the number of row indices in the IndexList in
Definition: escriptcore/src/IndexList.h:54
Paso.h
paso::util::comparIndex
int comparIndex(const void *index1, const void *index2)
this int-comparison function is used by qsort/bsearch in various places
Definition: PasoUtil.cpp:25
escript::DataTypes::dim_t
index_t dim_t
Definition: DataTypes.h:66
paso::Pattern::coloring
index_t * coloring
Definition: Pattern.h:147
paso::Pattern::binop
Pattern_ptr binop(int type, const_Pattern_ptr other) const
Definition: Pattern.cpp:333
paso::Pattern::multiply
Pattern_ptr multiply(int type, const_Pattern_ptr other) const
Definition: Pattern.cpp:311
paso::Pattern::index
index_t * index
Definition: Pattern.h:141
Pattern.h
paso::Pattern::len
dim_t len
Definition: Pattern.h:137
paso::Pattern::main_iptr
index_t * main_iptr
Definition: Pattern.h:143
paso::PasoException
PasoException exception class.
Definition: PasoException.h:34
paso::const_Pattern_ptr
boost::shared_ptr< const Pattern > const_Pattern_ptr
Definition: Pattern.h:41
paso::Pattern::getSubpattern
Pattern_ptr getSubpattern(dim_t newNumRows, dim_t newNumCols, const index_t *rowList, const index_t *newColIndex) const
Definition: Pattern.cpp:199
escript::DataTypes::index_t
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:61
PasoUtil.h
paso::Pattern::isEmpty
bool isEmpty() const
Definition: Pattern.h:76
PasoException.h
paso::Pattern_ptr
boost::shared_ptr< Pattern > Pattern_ptr
Definition: Pattern.h:39
paso::Pattern::type
int type
Definition: Pattern.h:131
escript::IndexList
Definition: escriptcore/src/IndexList.h:29
paso::util::isAny
bool isAny(dim_t N, const index_t *array, index_t value)
returns true if array contains value
Definition: PasoUtil.cpp:30
paso
Definition: BiCGStab.cpp:25
paso::Pattern::borrowMainDiagonalPointer
index_t * borrowMainDiagonalPointer()
Definition: Pattern.cpp:139
paso::Pattern::Pattern
Pattern(int type, dim_t numOutput, dim_t numInput, index_t *ptr, index_t *index)
Definition: Pattern.cpp:38
MATRIX_FORMAT_DEFAULT
#define MATRIX_FORMAT_DEFAULT
Definition: Paso.h:61
paso::Pattern::ptr
index_t * ptr
Definition: Pattern.h:139
paso::Pattern::~Pattern
~Pattern()
Definition: Pattern.cpp:94