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 file is part of Psi4.
12  *
13  * Psi4 is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU Lesser General Public License as published by
15  * the Free Software Foundation, version 3.
16  *
17  * Psi4 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 Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License along
23  * with Psi4; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  *
26  * @END LICENSE
27  */
28 
29 #ifndef _psi_src_lib_libparallel_local_h_
30 #define _psi_src_lib_libparallel_local_h_
31 
32 #include "parallel.h"
33 #include "libparallel.h"
34 #include <cstring>
35 #include <string>
36 #ifdef _OPENMP
37 #include <omp.h>
38 #endif
39 
40 namespace psi {
41 
42 class LocalCommWrapper:public Parallel<LocalCommWrapper> {
43  private:
44  template <typename type>
45  void bcastImpl(const type* /*data*/,
46  const int /*nelem*/,
47  const int /*broadcaster*/,
48  const std::string& /*CommName*/="None") const
49  {}
50 
51  template <typename T>
52  void bcastImpl(T& data,const int broadcaster,
53  const std::string&Comm="NONE") const {
54  UNUSED(data);
55  UNUSED(broadcaster);
56  UNUSED(Comm);
57  }
58  template<typename type>
59  void AllReduceImpl(const type* localdata,const int nelem,
60  type* target,
61  const MPIOperation& operation,
62  const std::string& Name){
63  UNUSED(operation);
64  UNUSED(Name);
65  memcpy(target,localdata,nelem);
66  }
67  template<typename T>
68  void IrecvImpl(const int source, const int tag, T* message,
69  const int length)const{
70  UNUSED(source);
71  UNUSED(tag);
72  UNUSED(message);
73  UNUSED(length);
74  }
75  template<typename T>
76  void recvImpl(const int source, const int tag, T* message,
77  const int length)const{
78  UNUSED(source);
79  UNUSED(tag);
80  UNUSED(message);
81  UNUSED(length);
82  }
83  template<typename T>
84  void IsendImpl(const int source, const int tag, T* message,
85  const int length)const{
86  UNUSED(source);
87  UNUSED(tag);
88  UNUSED(message);
89  UNUSED(length);
90  }
91  template<typename T>
92  void sendImpl(const int source, const int tag, T* message,
93  const int length)const{
94  UNUSED(source);
95  UNUSED(tag);
96  UNUSED(message);
97  UNUSED(length);
98  }
99  template <typename type>
100  void all_gatherImpl(const type* localdata,
101  const int nelem,
102  type* target,
103  const std::string& /*CommName*/="NONE") const
104  {
105  if (localdata!=target)
106  std::memcpy(const_cast<type*>(localdata), target,
107  sizeof(type)*nelem);
108  }
109  template <typename type>
110  void gatherImpl(const type* localdata, const int nelem, type* target,
111  const int Root,const std::string& CommName="NONE") const {
112  UNUSED(Root);
113  UNUSED(CommName);
114  if (localdata!=target)
115  std::memcpy(const_cast<type*>(localdata), target,
116  sizeof(type)*nelem);
117  }
118  friend class Parallel<LocalCommWrapper> ;
119  public:
120  LocalCommWrapper(const int &/*argc*/, char **/*argv*/) {
121  //The next three lines are what the old local comm did
122  //the code breaks if I do not include them
123  //The way I understand this is that the number of openmp threads
124  //is getting hard-coded to 1, and somewhere in the code people are
125  //counting on this behavior...
126 #ifdef _OPENMP
127  omp_set_nested(0);
128 #endif
129  if (Process::environment("OMP_NUM_THREADS")=="")
131  }
132 };
133 // End of LocalCommWrapper class
134 
135 }// End of namespace psi
136 
137 #endif // End of _psi_src_lib_libparallel_local_h_
void set_n_threads(int nthread)
Definition: process.cc:86
void sendImpl(const int source, const int tag, T *message, const int length) const
Definition: libparallel/local.h:92
void gatherImpl(const type *localdata, const int nelem, type *target, const int Root, const std::string &CommName="NONE") const
Definition: libparallel/local.h:110
void AllReduceImpl(const type *localdata, const int nelem, type *target, const MPIOperation &operation, const std::string &Name)
Definition: libparallel/local.h:59
MPIOperation
The supported operations for MPI reduce-like fxns.
Definition: libparallel.h:33
static Environment environment
Definition: process.h:138
Definition: libparallel/local.h:42
void bcastImpl(T &data, const int broadcaster, const std::string &Comm="NONE") const
Definition: libparallel/local.h:52
void IsendImpl(const int source, const int tag, T *message, const int length) const
Definition: libparallel/local.h:84
Definition: parallel.h:54
LocalCommWrapper(const int &, char **)
Definition: libparallel/local.h:120
void all_gatherImpl(const type *localdata, const int nelem, type *target, const std::string &="NONE") const
Definition: libparallel/local.h:100
void recvImpl(const int source, const int tag, T *message, const int length) const
Definition: libparallel/local.h:76
void bcastImpl(const type *, const int, const int, const std::string &="None") const
Definition: libparallel/local.h:45
#define UNUSED(expr)
Definition: parallel.h:48
Definition: PsiFileImpl.h:40
void IrecvImpl(const int source, const int tag, T *message, const int length) const
Definition: libparallel/local.h:68