ViennaCL - The Vienna Computing Library  1.5.2
viennacl/linalg/host_based/misc_operations.hpp
Go to the documentation of this file.
00001 #ifndef VIENNACL_LINALG_HOST_BASED_MISC_OPERATIONS_HPP_
00002 #define VIENNACL_LINALG_HOST_BASED_MISC_OPERATIONS_HPP_
00003 
00004 /* =========================================================================
00005    Copyright (c) 2010-2014, Institute for Microelectronics,
00006                             Institute for Analysis and Scientific Computing,
00007                             TU Wien.
00008    Portions of this software are copyright by UChicago Argonne, LLC.
00009 
00010                             -----------------
00011                   ViennaCL - The Vienna Computing Library
00012                             -----------------
00013 
00014    Project Head:    Karl Rupp                   rupp@iue.tuwien.ac.at
00015 
00016    (A list of authors and contributors can be found in the PDF manual)
00017 
00018    License:         MIT (X11), see file LICENSE in the base directory
00019 ============================================================================= */
00020 
00025 #include <list>
00026 
00027 #include "viennacl/forwards.h"
00028 #include "viennacl/scalar.hpp"
00029 #include "viennacl/vector.hpp"
00030 #include "viennacl/tools/tools.hpp"
00031 #include "viennacl/linalg/host_based/common.hpp"
00032 
00033 namespace viennacl
00034 {
00035   namespace linalg
00036   {
00037     namespace host_based
00038     {
00039       namespace detail
00040       {
00041         template <typename ScalarType>
00042         void level_scheduling_substitute(vector<ScalarType> & vec,
00043                                      viennacl::backend::mem_handle const & row_index_array,
00044                                      viennacl::backend::mem_handle const & row_buffer,
00045                                      viennacl::backend::mem_handle const & col_buffer,
00046                                      viennacl::backend::mem_handle const & element_buffer,
00047                                      vcl_size_t num_rows
00048                                     )
00049         {
00050           ScalarType * vec_buf = viennacl::linalg::host_based::detail::extract_raw_pointer<ScalarType>(vec.handle());
00051 
00052           unsigned int const * elim_row_index  = viennacl::linalg::host_based::detail::extract_raw_pointer<unsigned int>(row_index_array);
00053           unsigned int const * elim_row_buffer = viennacl::linalg::host_based::detail::extract_raw_pointer<unsigned int>(row_buffer);
00054           unsigned int const * elim_col_buffer = viennacl::linalg::host_based::detail::extract_raw_pointer<unsigned int>(col_buffer);
00055           ScalarType   const * elim_elements   = viennacl::linalg::host_based::detail::extract_raw_pointer<ScalarType>(element_buffer);
00056 
00057 #ifdef VIENNACL_WITH_OPENMP
00058           #pragma omp parallel for
00059 #endif
00060           for (long row=0; row < static_cast<long>(num_rows); ++row)
00061           {
00062             unsigned int eq_row = elim_row_index[row];
00063             ScalarType vec_entry = vec_buf[eq_row];
00064             unsigned int row_end = elim_row_buffer[row+1];
00065 
00066             for (vcl_size_t j = elim_row_buffer[row]; j < row_end; ++j)
00067               vec_entry -= vec_buf[elim_col_buffer[j]] * elim_elements[j];
00068 
00069             vec_buf[eq_row] = vec_entry;
00070           }
00071 
00072         }
00073       }
00074 
00075     } // namespace host_based
00076   } //namespace linalg
00077 } //namespace viennacl
00078 
00079 
00080 #endif