| 43 |  | * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). | 
| 44 |  | * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). | 
| 45 |  | * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). | 
| 46 | < | * [4]  Vardeman & Gezelter, in progress (2009). | 
| 46 | > | * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010). | 
| 47 | > | * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). | 
| 48 |  | */ | 
| 49 |  |  | 
| 50 |  | #ifndef PARALLEL_COMMUNICATOR_HPP | 
| 104 |  | }; | 
| 105 |  |  | 
| 106 |  |  | 
| 107 | < | template<communicatorType D, typename T> | 
| 107 | > | template<communicatorType D> | 
| 108 |  | class Communicator { | 
| 109 |  | public: | 
| 110 |  |  | 
| 111 | < | Communicator<D, T>(int nObjects) { | 
| 111 | > | Communicator<D>() { | 
| 112 |  |  | 
| 113 |  | int nProc = MPI::COMM_WORLD.Get_size(); | 
| 114 |  | int myRank = MPI::COMM_WORLD.Get_rank(); | 
| 115 | < |  | 
| 115 | > |  | 
| 116 |  | int nColumnsMax = (int) sqrt(RealType(nProc)); | 
| 117 |  |  | 
| 118 |  | int nColumns; | 
| 134 |  | case Global: | 
| 135 |  | myComm = MPI::COMM_WORLD.Split(myRank, 0); | 
| 136 |  | } | 
| 136 | – |  | 
| 137 | – | int nCommProcs = myComm.Get_size(); | 
| 137 |  |  | 
| 138 | < | counts.reserve(nCommProcs); | 
| 139 | < | displacements.reserve(nCommProcs); | 
| 138 | > | } | 
| 139 | > |  | 
| 140 | > | MPI::Intracomm getComm() { return myComm; } | 
| 141 | > |  | 
| 142 | > | private: | 
| 143 | > | int rowIndex_; | 
| 144 | > | int columnIndex_; | 
| 145 | > | MPI::Intracomm myComm; | 
| 146 | > | }; | 
| 147 | > |  | 
| 148 |  |  | 
| 149 | + | template<typename T> | 
| 150 | + | class Plan { | 
| 151 | + | public: | 
| 152 | + |  | 
| 153 | + | Plan<T>(MPI::Intracomm comm, int nObjects) { | 
| 154 | + | myComm = comm; | 
| 155 | + | int nCommProcs = myComm.Get_size(); | 
| 156 | + |  | 
| 157 | + | counts.resize(nCommProcs, 0); | 
| 158 | + | displacements.resize(nCommProcs, 0); | 
| 159 | + |  | 
| 160 |  | planSize_ = MPITraits<T>::Length() * nObjects; | 
| 161 | < |  | 
| 161 | > |  | 
| 162 |  | myComm.Allgather(&planSize_, 1, MPI::INT, &counts[0], 1, MPI::INT); | 
| 163 | < |  | 
| 163 | > |  | 
| 164 |  | displacements[0] = 0; | 
| 165 |  | for (int i = 1; i < nCommProcs; i++) { | 
| 166 |  | displacements[i] = displacements[i-1] + counts[i-1]; | 
| 149 | – | size_ += counts[i-1]; | 
| 167 |  | } | 
| 168 |  |  | 
| 169 |  | size_ = 0; | 
| 175 |  |  | 
| 176 |  | void gather(vector<T>& v1, vector<T>& v2) { | 
| 177 |  |  | 
| 178 | + | // an assert would be helpful here to make sure the vectors are the | 
| 179 | + | // correct geometry | 
| 180 | + |  | 
| 181 |  | myComm.Allgatherv(&v1[0], | 
| 182 |  | planSize_, | 
| 183 |  | MPITraits<T>::Type(), | 
| 185 |  | &counts[0], | 
| 186 |  | &displacements[0], | 
| 187 |  | MPITraits<T>::Type()); | 
| 188 | < | } | 
| 188 | > | } | 
| 189 |  |  | 
| 170 | – |  | 
| 171 | – |  | 
| 190 |  | void scatter(vector<T>& v1, vector<T>& v2) { | 
| 191 | < |  | 
| 191 | > | // an assert would be helpful here to make sure the vectors are the | 
| 192 | > | // correct geometry | 
| 193 | > |  | 
| 194 |  | myComm.Reduce_scatter(&v1[0], &v2[0], &counts[0], | 
| 195 |  | MPITraits<T>::Type(), MPI::SUM); | 
| 196 |  | } | 
| 201 |  |  | 
| 202 |  | private: | 
| 203 |  | int planSize_;     ///< how many are on local proc | 
| 184 | – | int rowIndex_; | 
| 185 | – | int columnIndex_; | 
| 204 |  | int size_; | 
| 205 |  | vector<int> counts; | 
| 206 |  | vector<int> displacements; |