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 
34 #include <escript/IndexList.h>
35 
36 namespace paso {
37 
38 struct Pattern;
39 typedef boost::shared_ptr<Pattern> Pattern_ptr;
40 typedef boost::shared_ptr<const Pattern> const_Pattern_ptr;
41 
42 struct Pattern : boost::enable_shared_from_this<Pattern>
43 {
45  index_t* index);
46 
47  ~Pattern();
48 
49  Pattern_ptr unrollBlocks(int newType, dim_t outputBlockSize,
50  dim_t inputBlockSize);
51 
52  Pattern_ptr getSubpattern(dim_t newNumRows, dim_t newNumCols,
53  const index_t* rowList,
54  const index_t* newColIndex) const;
55 
57  void mis(index_t* mis_marker) const;
58 
59  void reduceBandwidth(index_t* oldToNew);
60 
61  Pattern_ptr multiply(int type, const_Pattern_ptr other) const;
62 
63  Pattern_ptr binop(int type, const_Pattern_ptr other) const;
64 
66 
68  const escript::IndexList* index_list_array,
69  index_t range_min, index_t range_max, index_t index_offset);
70 
72 
73  dim_t getBandwidth(index_t* label) const;
74 
75  inline bool isEmpty() const
76  {
77  return (!ptr && !index);
78  }
79 
80  inline dim_t getNumColors()
81  {
82  // make sure numColors is defined
84  return numColors;
85  }
86 
87  inline dim_t maxDeg() const
88  {
89  dim_t deg = 0;
90 #pragma omp parallel
91  {
92  dim_t loc_deg=0;
93 #pragma omp for
94  for (dim_t i = 0; i < numInput; ++i) {
95  loc_deg=std::max(loc_deg, ptr[i+1]-ptr[i]);
96  }
97 #pragma omp critical
98  {
99  deg = std::max(deg, loc_deg);
100  }
101  }
102  return deg;
103  }
104 
105 
106  int type;
107  // Number of rows in the ptr array [CSR] / number of cols for CSC
109  // Number of cols [CSR]
110  dim_t numInput;
111  // number of non-zeros
112  dim_t len;
113  // ptr[n] to ptr[n+1] lists indices (in index) of non-zeros in row n
114  index_t* ptr;
115  // Non-major indices of non-zeros (in CSR this will be col numbers)
116  index_t* index;
117  // pointer to main diagonal entry
119  // number of colors
121  // coloring index: inputs with the same color are not connected
123 };
124 
125 
126 } // namespace paso
127 
128 #endif // __PASO_PATTERN_H__
129 
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:61
paso::Pattern::unrollBlocks
Pattern_ptr unrollBlocks(int newType, dim_t outputBlockSize, dim_t inputBlockSize)
Definition: Pattern.cpp:245
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:67
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:101
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:112
paso::Pattern::maxDeg
dim_t maxDeg() const
Definition: Pattern.h:99
paso::Pattern::numColors
dim_t numColors
Definition: Pattern.h:132
paso::Pattern::numInput
dim_t numInput
Definition: Pattern.h:122
paso::Pattern::borrowColoringPointer
index_t * borrowColoringPointer()
Definition: Pattern.cpp:162
paso::Pattern::numOutput
dim_t numOutput
Definition: Pattern.h:120
MATRIX_FORMAT_OFFSET1
#define MATRIX_FORMAT_OFFSET1
Definition: Paso.h:64
paso::Pattern::getNumColors
dim_t getNumColors()
Definition: Pattern.h:92
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:53
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:51
escript::DataTypes::dim_t
index_t dim_t
Definition: DataTypes.h:90
paso::Pattern::coloring
index_t * coloring
Definition: Pattern.h:134
paso::Pattern::binop
Pattern_ptr binop(int type, const_Pattern_ptr other) const
Definition: Pattern.cpp:329
paso::Pattern::multiply
Pattern_ptr multiply(int type, const_Pattern_ptr other) const
Definition: Pattern.cpp:307
paso::Pattern::reduceBandwidth
void reduceBandwidth(index_t *oldToNew)
Definition: Pattern_reduceBandwidth.cpp:157
paso::Pattern::index
index_t * index
Definition: Pattern.h:128
Pattern.h
paso::Pattern::len
dim_t len
Definition: Pattern.h:124
paso::Pattern::main_iptr
index_t * main_iptr
Definition: Pattern.h:130
paso::PasoException
PasoException exception class.
Definition: PasoException.h:45
paso::const_Pattern_ptr
boost::shared_ptr< const Pattern > const_Pattern_ptr
Definition: Pattern.h:52
paso::Pattern::getSubpattern
Pattern_ptr getSubpattern(dim_t newNumRows, dim_t newNumCols, const index_t *rowList, const index_t *newColIndex) const
Definition: Pattern.cpp:195
escript::DataTypes::index_t
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:85
PasoUtil.h
paso::Pattern::isEmpty
bool isEmpty() const
Definition: Pattern.h:87
PasoException.h
paso::Pattern_ptr
boost::shared_ptr< Pattern > Pattern_ptr
Definition: Pattern.h:50
paso::Pattern::type
int type
Definition: Pattern.h:118
escript::IndexList
Definition: escriptcore/src/IndexList.h:28
paso::util::isAny
bool isAny(dim_t N, const index_t *array, index_t value)
returns true if array contains value
Definition: PasoUtil.cpp:56
paso
Definition: BiCGStab.cpp:26
paso::Pattern::borrowMainDiagonalPointer
index_t * borrowMainDiagonalPointer()
Definition: Pattern.cpp:135
paso::Pattern::getBandwidth
dim_t getBandwidth(index_t *label) const
Definition: Pattern_reduceBandwidth.cpp:55
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:126
paso::Pattern::~Pattern
~Pattern()
Definition: Pattern.cpp:92