Psi4
threaded_storage.h
Go to the documentation of this file.
1 /*
2  * @BEGIN LICENSE
3  *
4  * Psi4: an open-source quantum chemistry software package
5  *
6  * Copyright (c) 2007-2017 The Psi4 Developers.
7  *
8  * The copyrights for code used from other parties are included in
9  * the corresponding files.
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  *
25  * @END LICENSE
26  */
27 
28 #if !defined(psi_src_lib_libparallel_threaded_storage)
29 #define psi_src_lib_libparallel_threaded_storage
30 
31 #include <vector>
32 
33 namespace psi {
34 
35 template<typename T>
37 {
38  std::vector<T> storage_;
39 
40 public:
41 
42  threaded_storage(const T& value = T())
43  : storage_(Process::environment.get_n_threads(), value)
44  { }
45 
46  void initialize(const T& value) {
47  storage_.clear();
48  for (int i=0; i<Process::environment.get_n_threads(); ++i) {
49  storage_.push_back(value);
50  }
51  }
52 
53  T& operator*() {
54  return storage_[0];
55  }
56 
57  const T& operator[](size_t ind) const {
58  return storage_[ind];
59  }
60  T& operator[](size_t ind) {
61  return storage_[ind];
62  }
63 };
64 
65 }
66 
67 #endif
Definition: pointgrp.h:105
Definition: process.h:53
T & operator[](size_t ind)
Definition: threaded_storage.h:60
static Environment environment
Definition: process.h:138
value void initialize(const T &value)
Definition: threaded_storage.h:46
T & operator*()
Definition: threaded_storage.h:53
const T & operator[](size_t ind) const
Definition: threaded_storage.h:57
Definition: threaded_storage.h:36
int get_n_threads() const
Number of threads per process.
Definition: process.cc:185
Definition: PsiFileImpl.h:39
std::vector< T > storage_
Definition: threaded_storage.h:38