So-Bogus
A c++ sparse block matrix library aimed at Second Order cone problems
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Coloring.hpp
1 /*
2  * This file is part of bogus, a C++ sparse block matrix library.
3  *
4  * Copyright 2013 Gilles Daviet <gdaviet@gmail.com>
5  *
6  * This Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0. If a copy of the MPL was not distributed with this
8  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 */
10 
11 #ifndef BOGUS_COLORING_HPP
12 #define BOGUS_COLORING_HPP
13 
14 #include "../Block.fwd.hpp"
15 
16 namespace bogus {
17 
19 
20 struct Coloring {
22  std::vector< std::size_t > permutation ;
24  std::vector< std::ptrdiff_t > colors ;
25 
26  Coloring()
27  {}
28 
30  template < typename Derived >
31  void update( const bool enable, const BlockMatrixBase< Derived >& matrix ) ;
32 
33  std::size_t size() const { return permutation.size() ; }
34 
37  {
38 #ifndef BOGUS_DONT_PARALLELIZE
39 #pragma omp parallel for
40 #endif
41  for( std::ptrdiff_t i = 0 ; i < (std::ptrdiff_t) permutation.size() ; ++ i )
42  { permutation[i] = i ; }
43  }
44 
45 private:
46 
47  void reset( std::size_t n )
48  {
49  colors.clear() ;
50  colors.push_back( 0 ) ;
51  colors.push_back( n ) ;
52 
53  permutation.resize( n ) ;
55  }
56 
57  template < typename Derived >
58  void compute( const SparseBlockMatrixBase< Derived >& matrix ) ;
59 
60  template < typename Derived >
61  void compute( const BlockMatrixBase< Derived >& matrix ) ;
62 } ;
63 
64 }
65 
66 #endif
67 
Base class for dense and sparse block matrices, thought dense don&#39;t exist yet.
Definition: BlockMatrixBase.hpp:22
std::vector< std::ptrdiff_t > colors
Index of first row for each color.
Definition: Coloring.hpp:24
std::vector< std::size_t > permutation
Computed permuation so that each color is contiguous.
Definition: Coloring.hpp:22
void resetPermutation()
Sets the permutation to the identity. Keep the current colors.
Definition: Coloring.hpp:36
void update(const bool enable, const BlockMatrixBase< Derived > &matrix)
Computes a coloring for matrix, or simply reset it if enable is false.
Coloring algorithm to determine which rows of a matrix can be treated in parallel.
Definition: Coloring.hpp:20