This file is indexed.

/usr/include/trilinos/Kokkos_Vector.hpp is in libtrilinos-kokkos-dev 12.4.2-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/*
//@HEADER
// ************************************************************************
// 
//                        Kokkos v. 2.0
//              Copyright (2014) Sandia Corporation
// 
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
// 
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact  H. Carter Edwards (hcedwar@sandia.gov)
// 
// ************************************************************************
//@HEADER
*/

#ifndef KOKKOS_VECTOR_HPP
#define KOKKOS_VECTOR_HPP

#include <Kokkos_Core_fwd.hpp>
#include <Kokkos_DualView.hpp>

/* Drop in replacement for std::vector based on Kokkos::DualView
 * Most functions only work on the host (it will not compile if called from device kernel)
 *
 */
  namespace Kokkos {

template< class Scalar, class Arg1Type = void>
class vector : public DualView<Scalar*,LayoutLeft,Arg1Type> {

  typedef Scalar value_type;
  typedef Scalar* pointer;
  typedef const Scalar* const_pointer;
  typedef Scalar* reference;
  typedef const Scalar* const_reference;
  typedef Scalar* iterator;
  typedef const Scalar* const_iterator;

private:
  size_t _size;
  typedef size_t size_type;
  float _extra_storage;
  typedef DualView<Scalar*,LayoutLeft,Arg1Type> DV;


public:
#ifdef KOKKOS_CUDA_USE_UVM
  KOKKOS_INLINE_FUNCTION Scalar& operator() (int i) const {return DV::h_view(i);};
  KOKKOS_INLINE_FUNCTION Scalar& operator[] (int i) const {return DV::h_view(i);};
#else
  inline Scalar& operator() (int i) const {return DV::h_view(i);};
  inline Scalar& operator[] (int i) const {return DV::h_view(i);};
#endif

  /* Member functions which behave like std::vector functions */

  vector():DV() {
    _size = 0;
    _extra_storage = 1.1;
    DV::modified_host() = 1;
  };


  vector(int n, Scalar val=Scalar()):DualView<Scalar*,LayoutLeft,Arg1Type>("Vector",size_t(n*(1.1))) {
    _size = n;
    _extra_storage = 1.1;
    DV::modified_host() = 1;

    assign(n,val);
  }


  void resize(size_t n) {
    if(n>=capacity())
      DV::resize(size_t (n*_extra_storage));
    _size = n;
  }

  void resize(size_t n, const Scalar& val) {
    assign(n,val);
  }

  void assign (size_t n, const Scalar& val) {

    /* Resize if necessary (behavour of std:vector) */

    if(n>capacity())
      DV::resize(size_t (n*_extra_storage));
    _size = n;

          /* Assign value either on host or on device */

    if( DV::modified_host() >= DV::modified_device() ) {
      set_functor_host f(DV::h_view,val);
      parallel_for(n,f);
      DV::t_host::execution_space::fence();
      DV::modified_host()++;
    } else {
      set_functor f(DV::d_view,val);
      parallel_for(n,f);
      DV::t_dev::execution_space::fence();
      DV::modified_device()++;
    }
  }

  void reserve(size_t n) {
    DV::resize(size_t (n*_extra_storage));
  }

  void push_back(Scalar val) {
    DV::modified_host()++;
    if(_size == capacity()) {
      size_t new_size = _size*_extra_storage;
      if(new_size == _size) new_size++;
      DV::resize(new_size);
    }

    DV::h_view(_size) = val;
    _size++;

  };

  void pop_back() {
    _size--;
  };

  void clear() {
    _size = 0;
  }

  size_type size() const {return _size;};
  size_type max_size() const {return 2000000000;}
  size_type capacity() const {return DV::capacity();};
  bool empty() const {return _size==0;};

  iterator begin() const {return &DV::h_view(0);};

  iterator end() const {return &DV::h_view(_size);};


  /* std::algorithms wich work originally with iterators, here they are implemented as member functions */

  size_t
  lower_bound (const size_t& start,
               const size_t& theEnd,
               const Scalar& comp_val) const
  {
    int lower = start; // FIXME (mfh 24 Apr 2014) narrowing conversion
    int upper = _size > theEnd? theEnd : _size-1; // FIXME (mfh 24 Apr 2014) narrowing conversion
    if (upper <= lower) {
      return theEnd;
    }

    Scalar lower_val = DV::h_view(lower);
    Scalar upper_val = DV::h_view(upper);
    size_t idx = (upper+lower)/2;
    Scalar val = DV::h_view(idx);
    if(val>upper_val) return upper;
    if(val<lower_val) return start;

    while(upper>lower) {
      if(comp_val>val) {
        lower = ++idx;
      } else {
        upper = idx;
      }
      idx = (upper+lower)/2;
      val = DV::h_view(idx);
    }
    return idx;
  }

  bool is_sorted() {
    for(int i=0;i<_size-1;i++) {
      if(DV::h_view(i)>DV::h_view(i+1)) return false;
    }
    return true;
  }

  iterator find(Scalar val) const {
    if(_size == 0) return end();

    int upper,lower,current;
    current = _size/2;
    upper = _size-1;
    lower = 0;

    if((val<DV::h_view(0)) || (val>DV::h_view(_size-1)) ) return end();

    while(upper>lower)
    {
      if(val>DV::h_view(current)) lower = current+1;
      else upper = current;
      current = (upper+lower)/2;
    }

    if(val==DV::h_view(current)) return &DV::h_view(current);
    else return end();
  }

  /* Additional functions for data management */

  void device_to_host(){
    deep_copy(DV::h_view,DV::d_view);
  }
  void host_to_device() const {
    deep_copy(DV::d_view,DV::h_view);
  }

  void on_host() {
    DV::modified_host() = DV::modified_device() + 1;
  }
  void on_device() {
    DV::modified_device() = DV::modified_host() + 1;
  }

  void set_overallocation(float extra) {
    _extra_storage = 1.0 + extra;
  }


public:
  struct set_functor {
    typedef typename DV::t_dev::execution_space execution_space;
    typename DV::t_dev _data;
    Scalar _val;

    set_functor(typename DV::t_dev data, Scalar val) :
      _data(data),_val(val) {}

    KOKKOS_INLINE_FUNCTION
    void operator() (const int &i) const {
      _data(i) = _val;
    }
  };

  struct set_functor_host {
    typedef typename DV::t_host::execution_space execution_space;
    typename DV::t_host _data;
    Scalar _val;

    set_functor_host(typename DV::t_host data, Scalar val) :
      _data(data),_val(val) {}

    KOKKOS_INLINE_FUNCTION
    void operator() (const int &i) const {
      _data(i) = _val;
    }
  };

};


}
#endif