escript  Revision_
Pattern.h
Go to the documentation of this file.
00001 
00002 /*****************************************************************************
00003 *
00004 * Copyright (c) 2003-2014 by University of Queensland
00005 * http://www.uq.edu.au
00006 *
00007 * Primary Business: Queensland, Australia
00008 * Licensed under the Open Software License version 3.0
00009 * http://www.opensource.org/licenses/osl-3.0.php
00010 *
00011 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
00012 * Development 2012-2013 by School of Earth Sciences
00013 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
00014 *
00015 *****************************************************************************/
00016 
00017 
00018 /****************************************************************************/
00019 
00020 /*   Paso: CSC/CSR sparse matrix pattern                                    */
00021 
00022 /****************************************************************************/
00023 
00024 /*   Author: Lutz Gross, l.gross@uq.edu.au */
00025 
00026 /****************************************************************************/
00027 
00028 #ifndef __PASO_PATTERN_H__
00029 #define __PASO_PATTERN_H__
00030 
00031 #include "Paso.h"
00032 #include "esysUtils/IndexList.h"
00033 
00034 namespace paso {
00035 
00036 struct Pattern;
00037 typedef boost::shared_ptr<Pattern> Pattern_ptr;
00038 typedef boost::shared_ptr<const Pattern> const_Pattern_ptr;
00039 
00040 PASO_DLL_API
00041 struct Pattern : boost::enable_shared_from_this<Pattern>
00042 {
00043     Pattern(int type, dim_t numOutput, dim_t numInput, index_t* ptr,
00044             index_t* index);
00045 
00046     ~Pattern();
00047 
00048     Pattern_ptr unrollBlocks(int newType, dim_t outputBlockSize,
00049                              dim_t inputBlockSize);
00050 
00051     Pattern_ptr getSubpattern(dim_t newNumRows, dim_t newNumCols,
00052                               const index_t* rowList,
00053                               const index_t* newColIndex) const;
00054 
00056     void mis(index_t* mis_marker) const;
00057 
00058     void reduceBandwidth(index_t* oldToNew);
00059 
00060     Pattern_ptr multiply(int type, const_Pattern_ptr other) const;
00061 
00062     Pattern_ptr binop(int type, const_Pattern_ptr other) const;
00063 
00064     index_t* borrowMainDiagonalPointer();
00065 
00066     static Pattern_ptr fromIndexListArray(dim_t n0, dim_t n,
00067             const esysUtils::IndexListArray& index_list_array,
00068             index_t range_min, index_t range_max, index_t index_offset);
00069 
00070     index_t* borrowColoringPointer();
00071 
00072     dim_t getBandwidth(index_t* label) const;
00073 
00074     inline bool isEmpty() const
00075     {
00076         return (!ptr && !index);
00077     }
00078 
00079     inline dim_t getNumColors()
00080     {
00081         // make sure numColors is defined
00082         borrowColoringPointer();
00083         return numColors;
00084     }
00085 
00086     inline dim_t maxDeg() const
00087     {
00088         dim_t deg = 0;
00089 #pragma omp parallel
00090         {
00091             dim_t loc_deg=0;
00092 #pragma omp for
00093             for (dim_t i = 0; i < numInput; ++i) {
00094                 loc_deg=std::max(loc_deg, ptr[i+1]-ptr[i]);
00095             }
00096 #pragma omp critical
00097             {
00098                 deg = std::max(deg, loc_deg);
00099             }
00100         }
00101         return deg;
00102     }
00103 
00104 
00105     int type;
00106     // Number of rows in the ptr array [CSR] / number of cols for CSC
00107     dim_t numOutput;
00108     // Number of cols [CSR]
00109     dim_t numInput;
00110     // number of non-zeros
00111     dim_t len;
00112     // ptr[n] to ptr[n+1] lists indices (in index) of non-zeros in row n
00113     index_t* ptr;
00114     // Non-major indices of non-zeros (in CSR this will be col numbers)
00115     index_t* index;
00116     // pointer to main diagonal entry
00117     index_t* main_iptr;
00118     // number of colors
00119     dim_t numColors;
00120     // coloring index: inputs with the same color are not connected
00121     index_t* coloring;
00122 };
00123 
00124 
00125 } // namespace paso
00126 
00127 #endif // __PASO_PATTERN_H__
00128