SkelCL
SkelCL is a high level multi GPU skeleton library developed at the university of Münster, Germany.
 All Classes Namespaces Files Functions Variables Typedefs Groups
Significances.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (c) 2011-2012 The SkelCL Team as listed in CREDITS.txt *
3  * http://skelcl.uni-muenster.de *
4  * *
5  * This file is part of SkelCL. *
6  * SkelCL is available under multiple licenses. *
7  * The different licenses are subject to terms and condition as provided *
8  * in the files specifying the license. See "LICENSE.txt" for details *
9  * *
10  *****************************************************************************
11  * *
12  * SkelCL is free software: you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation, either version 3 of the License, or *
15  * (at your option) any later version. See "LICENSE-gpl.txt" for details. *
16  * *
17  * SkelCL is distributed in the hope that it will be useful, *
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20  * GNU General Public License for more details. *
21  * *
22  *****************************************************************************
23  * *
24  * For non-commercial academic use see the license specified in the file *
25  * "LICENSE-academic.txt". *
26  * *
27  *****************************************************************************
28  * *
29  * If you are interested in other licensing models, including a commercial- *
30  * license, please contact the author at michel.steuwer@uni-muenster.de *
31  * *
32  *****************************************************************************/
33 
39 
40 #include <initializer_list>
41 #include <numeric>
42 #include <vector>
43 
44 #include <pvsutil/Assert.h>
45 
46 #include "SkelCL/detail/Device.h"
47 
48 #include "SkelCL/detail/Significances.h"
49 
50 namespace skelcl {
51 
52 namespace detail {
53 
54 Significances::Significances(size_t deviceCount)
55  : _values(deviceCount)
56 {
57  const value_type one = 1.0;
58  auto amount = one / deviceCount;
59  auto rest = one;
60  for(auto& value : _values) {
61  value = amount;
62  rest -= amount;
63  }
64  _values[deviceCount-1] += rest;
65 
66 #ifndef NDEBUG // in debug build only (to prevent unused variable warning)
67  const value_type zero = 0.0;
68  const value_type epsilon = static_cast<value_type>(1.0e-10);
69  ASSERT( std::accumulate( _values.cbegin(), _values.cend(), zero )
70  - one < epsilon );
71 #endif
72 }
73 
74 Significances::Significances(std::initializer_list<value_type> significances)
75  : _values( significances.begin(), significances.end() )
76 {
77 #ifndef NDEBUG // in debug build only (to prevent unused variable warning)
78  const value_type zero = 0.0;
79  const value_type one = 1.0;
80  const value_type epsilon = static_cast<value_type>(1.0e-10);
81  ASSERT( std::accumulate( _values.cbegin(), _values.cend(), zero )
82  - one < epsilon );
83 #endif
84 }
85 
86 bool Significances::operator==(const Significances& rhs) const
87 {
88  return _values == rhs._values;
89 }
90 
91 void Significances::setSignificances(std::initializer_list<value_type>
92  significances)
93 {
94  _values.assign( significances.begin(), significances.end() );
95 #ifndef NDEBUG // in debug build only (to prevent unused variable warning)
96  const value_type zero = 0.0;
97  const value_type one = 1.0;
98  const value_type epsilon = static_cast<value_type>(1.0e-10);
99  ASSERT( std::accumulate( _values.cbegin(), _values.cend(), zero )
100  - one < epsilon );
101 #endif
102 }
103 
104 Significances::value_type
105  Significances::getSignificance(const Device::id_type device) const
106 {
107  return _values[device];
108 }
109 
110 size_t Significances::size() const
111 {
112  return _values.size();
113 }
114 
115 } // namespace detail
116 
117 } // namespace skelcl
SKELCL_DLL detail::DeviceID device(size_t dID)
Creates an OpenCL device ID to be used as parameter of the init(detail::PlatformID, detail::DeviceID) function.
Definition: SkelCL.cpp:76