Psi4
libparallel/local.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 #ifndef _psi_src_lib_libparallel_local_h_
29 #define _psi_src_lib_libparallel_local_h_
30 
31 #include "parallel.h"
32 #include "libparallel.h"
33 #include <cstring>
34 #include <string>
35 #ifdef _OPENMP
36 #include <omp.h>
37 #endif
38 
39 namespace psi {
40 
41 class LocalCommWrapper:public Parallel<LocalCommWrapper> {
42  private:
43  template <typename type>
44  void bcastImpl(const type* /*data*/,
45  const int /*nelem*/,
46  const int /*broadcaster*/,
47  const std::string& /*CommName*/="None") const
48  {}
49 
50  template <typename T>
51  void bcastImpl(T& data,const int broadcaster,
52  const std::string&Comm="NONE") const {
53  UNUSED(data);
54  UNUSED(broadcaster);
55  UNUSED(Comm);
56  }
57  template<typename type>
58  void AllReduceImpl(const type* localdata,const int nelem,
59  type* target,
60  const MPIOperation& operation,
61  const std::string& Name){
62  UNUSED(operation);
63  UNUSED(Name);
64  memcpy(target,localdata,nelem);
65  }
66  template<typename T>
67  void IrecvImpl(const int source, const int tag, T* message,
68  const int length)const{
69  UNUSED(source);
70  UNUSED(tag);
71  UNUSED(message);
72  UNUSED(length);
73  }
74  template<typename T>
75  void recvImpl(const int source, const int tag, T* message,
76  const int length)const{
77  UNUSED(source);
78  UNUSED(tag);
79  UNUSED(message);
80  UNUSED(length);
81  }
82  template<typename T>
83  void IsendImpl(const int source, const int tag, T* message,
84  const int length)const{
85  UNUSED(source);
86  UNUSED(tag);
87  UNUSED(message);
88  UNUSED(length);
89  }
90  template<typename T>
91  void sendImpl(const int source, const int tag, T* message,
92  const int length)const{
93  UNUSED(source);
94  UNUSED(tag);
95  UNUSED(message);
96  UNUSED(length);
97  }
98  template <typename type>
99  void all_gatherImpl(const type* localdata,
100  const int nelem,
101  type* target,
102  const std::string& /*CommName*/="NONE") const
103  {
104  if (localdata!=target)
105  std::memcpy(const_cast<type*>(localdata), target,
106  sizeof(type)*nelem);
107  }
108  template <typename type>
109  void gatherImpl(const type* localdata, const int nelem, type* target,
110  const int Root,const std::string& CommName="NONE") const {
111  UNUSED(Root);
112  UNUSED(CommName);
113  if (localdata!=target)
114  std::memcpy(const_cast<type*>(localdata), target,
115  sizeof(type)*nelem);
116  }
117  friend class Parallel<LocalCommWrapper> ;
118  public:
119  LocalCommWrapper(const int &/*argc*/, char **/*argv*/) {
120  //The next three lines are what the old local comm did
121  //the code breaks if I do not include them
122  //The way I understand this is that the number of openmp threads
123  //is getting hard-coded to 1, and somewhere in the code people are
124  //counting on this behavior...
125 #ifdef _OPENMP
126  omp_set_nested(0);
127 #endif
128  if (Process::environment("OMP_NUM_THREADS")=="")
130  }
131 };
132 // End of LocalCommWrapper class
133 
134 }// End of namespace psi
135 
136 #endif // End of _psi_src_lib_libparallel_local_h_
void set_n_threads(int nthread)
Definition: process.cc:85
void sendImpl(const int source, const int tag, T *message, const int length) const
Definition: libparallel/local.h:91
void gatherImpl(const type *localdata, const int nelem, type *target, const int Root, const std::string &CommName="NONE") const
Definition: libparallel/local.h:109
void AllReduceImpl(const type *localdata, const int nelem, type *target, const MPIOperation &operation, const std::string &Name)
Definition: libparallel/local.h:58
MPIOperation
The supported operations for MPI reduce-like fxns.
Definition: libparallel.h:32
static Environment environment
Definition: process.h:138
Definition: libparallel/local.h:41
void bcastImpl(T &data, const int broadcaster, const std::string &Comm="NONE") const
Definition: libparallel/local.h:51
void IsendImpl(const int source, const int tag, T *message, const int length) const
Definition: libparallel/local.h:83
Definition: parallel.h:53
LocalCommWrapper(const int &, char **)
Definition: libparallel/local.h:119
void all_gatherImpl(const type *localdata, const int nelem, type *target, const std::string &="NONE") const
Definition: libparallel/local.h:99
void recvImpl(const int source, const int tag, T *message, const int length) const
Definition: libparallel/local.h:75
void bcastImpl(const type *, const int, const int, const std::string &="None") const
Definition: libparallel/local.h:44
#define UNUSED(expr)
Definition: parallel.h:47
Definition: PsiFileImpl.h:39
void IrecvImpl(const int source, const int tag, T *message, const int length) const
Definition: libparallel/local.h:67