LAMA
|
00001 00033 #ifndef LAMA_OPENMP_CSR_UTILS_HPP_ 00034 #define LAMA_OPENMP_CSR_UTILS_HPP_ 00035 00036 // for dll_import 00037 #include <lama/config.hpp> 00038 00039 // others 00040 #include <lama/LAMATypes.hpp> 00041 #include <lama/SyncToken.hpp> 00042 00043 // logging 00044 #include <logging/logging.hpp> 00045 00046 namespace lama 00047 { 00048 00052 class LAMA_DLL_IMPORTEXPORT OpenMPCSRUtils 00053 { 00054 public: 00055 00060 static IndexType countNonEmptyRowsByOffsets( const IndexType offsets[], const IndexType numRows ); 00061 00064 static void setNonEmptyRowsByOffsets( IndexType rowIndexes[], const IndexType numNonEmptyRows, 00065 const IndexType offsets[], const IndexType numRows ); 00066 00082 static IndexType scan( IndexType array[], const IndexType numValues ); 00083 00086 static IndexType sizes2offsets( IndexType sizes[], const IndexType numRows ); 00087 00090 static void offsets2sizes( IndexType sizes[], const IndexType offsets[], const IndexType n ); 00091 00094 static void offsets2sizesGather( IndexType sizes[], const IndexType offsets[], 00095 const IndexType rowIndexes[], const IndexType numRows ); 00096 00099 static bool validOffsets( const IndexType array[], const IndexType n, const IndexType total ); 00100 00108 static bool hasDiagonalProperty( const IndexType numDiagonals, 00109 const IndexType csrIA[], 00110 const IndexType csrJA[] ); 00111 00118 template<typename ValueType> 00119 static void sortRowElements( IndexType csrJA[], 00120 ValueType csrValues[], 00121 const IndexType csrIA[], 00122 const IndexType numRows, 00123 const bool diagonalFlag ); 00124 00127 template <typename ValueType> 00128 static void convertCSR2CSC ( IndexType cscIA[], 00129 IndexType cscJA[], 00130 ValueType cscValues[], 00131 const IndexType csrIA[], 00132 const IndexType csrJA[], 00133 const ValueType csrValues[], 00134 IndexType numRows, IndexType numColumns, 00135 IndexType numValues ); 00136 00139 template <typename ValueType1, typename ValueType2> 00140 static void scaleRows ( ValueType1 csrValues[], 00141 const IndexType csrIA[], 00142 const IndexType numRows, 00143 const ValueType2 values[] ); 00144 00147 template <typename ValueType> 00148 static void normalGEMV( ValueType result[], 00149 const ValueType alpha, 00150 const ValueType x[], 00151 const ValueType beta, 00152 const ValueType y[], 00153 const IndexType numRows, 00154 const IndexType csrIA[], 00155 const IndexType csrJA[], 00156 const ValueType csrValues[], 00157 SyncToken* syncToken ); 00158 00161 template <typename ValueType> 00162 static void sparseGEMV( ValueType result[], 00163 const ValueType alpha, 00164 const ValueType x[], 00165 const IndexType numNonZeroRows, 00166 const IndexType rowIndexes[], 00167 const IndexType csrIA[], 00168 const IndexType csrJA[], 00169 const ValueType csrValues[], 00170 SyncToken* syncToken ); 00171 00174 template <typename ValueType> 00175 static void gemm( ValueType result[], 00176 const ValueType alpha, 00177 const ValueType x[], 00178 const ValueType beta, 00179 const ValueType y[], 00180 const IndexType m, 00181 const IndexType n, 00182 const IndexType p, 00183 const IndexType csrIA[], 00184 const IndexType csrJA[], 00185 const ValueType csrValues[], 00186 class SyncToken* syncToken ); 00187 00190 template <typename ValueType> 00191 static void jacobi( ValueType* const solution, 00192 const IndexType csrIA[], 00193 const IndexType csrJA[], 00194 const ValueType csrValues[], 00195 const ValueType rhs[], 00196 const ValueType oldSolution[], 00197 const ValueType omega, 00198 const IndexType numRows, 00199 SyncToken* syncToken ); 00200 00201 template<typename ValueType> 00202 static void jacobiHalo( 00203 ValueType solution[], 00204 const IndexType localIA[], 00205 const ValueType localValues[], 00206 const IndexType haloIA[], 00207 const IndexType haloJA[], 00208 const ValueType haloValues[], 00209 const IndexType haloRowIndexes[], 00210 const ValueType oldSolution[], 00211 const ValueType omega, 00212 const IndexType numNonEmptyRows ); 00213 00216 static void matrixAddSizes ( IndexType cSizes[], const IndexType numRows, 00217 const IndexType numColumns, bool diagonalProperty, 00218 const IndexType aIA[], const IndexType aJA[], 00219 const IndexType bIA[], const IndexType bJA[] ); 00220 00223 static void matrixMultiplySizes ( IndexType cSizes[], const IndexType numRows, 00224 const IndexType numColumns, bool diagonalProperty, 00225 const IndexType aIA[], const IndexType aJA[], 00226 const IndexType bIA[], const IndexType bJA[] ); 00227 00230 static void matrixMultiplyJA ( IndexType cJA[], const IndexType cIA[], 00231 const IndexType numRows, const IndexType numColumns, 00232 bool diagonalProperty, 00233 const IndexType aIA[], const IndexType aJA[], 00234 const IndexType bIA[], const IndexType bJA[] ); 00235 00238 template<typename ValueType> 00239 static void matrixAdd( IndexType cJA[], ValueType cValues[], const IndexType cIA[], 00240 const IndexType numRows, const IndexType numColumns, bool diagonalProperty, 00241 const ValueType alpha, 00242 const IndexType aIA[], const IndexType aJA[], const ValueType aValues[], 00243 const ValueType beta, 00244 const IndexType bIA[], const IndexType bJA[], const ValueType bValues[] ); 00245 00248 template<typename ValueType> 00249 static void matrixMultiply( ValueType cValues[], const IndexType cIA[], const IndexType cJA[], 00250 const IndexType numRows, const ValueType alpha, 00251 const IndexType aIA[], const IndexType aJA[], const ValueType aValues[], 00252 const IndexType bIA[], const IndexType bJA[], const ValueType bValues[] ); 00253 00256 template<typename ValueType> 00257 static ValueType absMaxDiffVal( IndexType numRows, bool sortedRows, 00258 const IndexType csrIA1[], const IndexType csrJA1[], const ValueType csrValues1[], 00259 const IndexType csrIA2[], const IndexType csrJA2[], const ValueType csrValues2[] ); 00260 00263 static void setInterface( struct CSRUtilsInterface& CSRUtils ); 00264 00265 protected: 00266 00267 LAMA_LOG_DECL_STATIC_LOGGER(logger); 00268 00269 private: 00270 00271 static IndexType scanSerial( IndexType array[], const IndexType numValues ); 00272 00273 static IndexType scanParallel( PartitionId numThreads, IndexType array[], const IndexType numValues ); 00274 00275 template <typename ValueType> 00276 static void normalGEMV( ValueType result[], 00277 const ValueType alpha, 00278 const ValueType x[], 00279 const ValueType beta, 00280 const ValueType y[], 00281 const IndexType numRows, 00282 const IndexType csrIA[], 00283 const IndexType csrJA[], 00284 const ValueType csrValues[] ); 00285 00286 template <typename ValueType> 00287 static void sparseGEMV( ValueType result[], 00288 const ValueType alpha, 00289 const ValueType x[], 00290 const IndexType numNonZeroRows, 00291 const IndexType rowIndexes[], 00292 const IndexType csrIA[], 00293 const IndexType csrJA[], 00294 const ValueType csrValues[] ); 00295 00296 template<typename ValueType> 00297 static ValueType absMaxDiffRowSorted( 00298 const IndexType n1, const IndexType csrJA1[], const ValueType csrValues1[], 00299 const IndexType n2, const IndexType csrJA2[], const ValueType csrValues2[] ); 00300 00301 template<typename ValueType> 00302 static ValueType absMaxDiffRowUnsorted( 00303 const IndexType n1, const IndexType csrJA1[], const ValueType csrValues1[], 00304 const IndexType n2, const IndexType csrJA2[], const ValueType csrValues2[] ); 00305 }; 00306 00307 } // namespace lama 00308 00309 #endif // LAMA_OPENMP_CSR_UTILS_HPP_