ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/parallel/ForceDecomposition.cpp
Revision: 1544
Committed: Fri Mar 18 19:31:52 2011 UTC (14 years, 1 month ago) by gezelter
File size: 8741 byte(s)
Log Message:
More modifications for paralllel rewrite

File Contents

# User Rev Content
1 gezelter 1539 /*
2     * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3 chuckv 1538 *
4     * The University of Notre Dame grants you ("Licensee") a
5     * non-exclusive, royalty free, license to use, modify and
6     * redistribute this software in source and binary code form, provided
7     * that the following conditions are met:
8     *
9     * 1. Redistributions of source code must retain the above copyright
10     * notice, this list of conditions and the following disclaimer.
11     *
12     * 2. Redistributions in binary form must reproduce the above copyright
13     * notice, this list of conditions and the following disclaimer in the
14     * documentation and/or other materials provided with the
15     * distribution.
16     *
17     * This software is provided "AS IS," without a warranty of any
18     * kind. All express or implied conditions, representations and
19     * warranties, including any implied warranty of merchantability,
20     * fitness for a particular purpose or non-infringement, are hereby
21     * excluded. The University of Notre Dame and its licensors shall not
22     * be liable for any damages suffered by licensee as a result of
23     * using, modifying or distributing the software or its
24     * derivatives. In no event will the University of Notre Dame or its
25     * licensors be liable for any lost revenue, profit or data, or for
26     * direct, indirect, special, consequential, incidental or punitive
27     * damages, however caused and regardless of the theory of liability,
28     * arising out of the use of or inability to use software, even if the
29     * University of Notre Dame has been advised of the possibility of
30     * such damages.
31     *
32     * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
33     * research, please cite the appropriate papers when you publish your
34     * work. Good starting points are:
35     *
36     * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
37     * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
38     * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).
39     * [4] Vardeman & Gezelter, in progress (2009).
40     */
41 gezelter 1539 #include "parallel/ForceDecomposition.hpp"
42     #include "math/SquareMatrix3.hpp"
43 gezelter 1544 #include "nonbonded/NonBondedInteraction.hpp"
44     #include "brains/SnapshotManager.hpp"
45 chuckv 1538
46 gezelter 1541 using namespace std;
47 gezelter 1539 namespace OpenMD {
48 chuckv 1538
49 gezelter 1544 /**
50     * distributeInitialData is essentially a copy of the older fortran
51     * SimulationSetup
52     */
53    
54 gezelter 1539 void ForceDecomposition::distributeInitialData() {
55 gezelter 1544 #ifdef IS_MPI
56 gezelter 1541 Snapshot* snap = sman_->getCurrentSnapshot();
57 gezelter 1544 int nLocal = snap->getNumberOfAtoms();
58 gezelter 1541 int nGroups = snap->getNumberOfCutoffGroups();
59 chuckv 1538
60 gezelter 1544 AtomCommIntI = new Communicator<Row,int>(nLocal);
61     AtomCommRealI = new Communicator<Row,RealType>(nLocal);
62     AtomCommVectorI = new Communicator<Row,Vector3d>(nLocal);
63     AtomCommMatrixI = new Communicator<Row,Mat3x3d>(nLocal);
64 chuckv 1538
65 gezelter 1544 AtomCommIntJ = new Communicator<Column,int>(nLocal);
66     AtomCommRealJ = new Communicator<Column,RealType>(nLocal);
67     AtomCommVectorJ = new Communicator<Column,Vector3d>(nLocal);
68     AtomCommMatrixJ = new Communicator<Column,Mat3x3d>(nLocal);
69 chuckv 1538
70 gezelter 1544 cgCommIntI = new Communicator<Row,int>(nGroups);
71 gezelter 1540 cgCommVectorI = new Communicator<Row,Vector3d>(nGroups);
72 gezelter 1544 cgCommIntJ = new Communicator<Column,int>(nGroups);
73 gezelter 1540 cgCommVectorJ = new Communicator<Column,Vector3d>(nGroups);
74 gezelter 1541
75 gezelter 1544 int nAtomsInRow = AtomCommIntI->getSize();
76     int nAtomsInCol = AtomCommIntJ->getSize();
77     int nGroupsInRow = cgCommIntI->getSize();
78     int nGroupsInCol = cgCommIntJ->getSize();
79 gezelter 1541
80 gezelter 1544 vector<vector<RealType> > pot_row(N_INTERACTION_FAMILIES,
81     vector<RealType> (nAtomsInRow, 0.0));
82     vector<vector<RealType> > pot_col(N_INTERACTION_FAMILIES,
83     vector<RealType> (nAtomsInCol, 0.0));
84    
85     vector<RealType> pot_local(N_INTERACTION_FAMILIES, 0.0);
86 gezelter 1541
87 gezelter 1544 // gather the information for atomtype IDs (atids):
88     AtomCommIntI->gather(info_->getIdentArray(), identsRow);
89     AtomCommIntJ->gather(info_->getIdentArray(), identsCol);
90 gezelter 1541
91 gezelter 1544 AtomLocalToGlobal = info_->getLocalToGlobalAtomIndex();
92     AtomCommIntI->gather(AtomLocalToGlobal, AtomRowToGlobal);
93     AtomCommIntJ->gather(AtomLocalToGlobal, AtomColToGlobal);
94    
95     cgLocalToGlobal = info_->getLocalToGlobalCutoffGroupIndex();
96     cgCommIntI->gather(cgLocalToGlobal, cgRowToGlobal);
97     cgCommIntJ->gather(cgLocalToGlobal, cgColToGlobal);
98    
99    
100    
101    
102    
103    
104     // still need:
105     // topoDist
106     // exclude
107 chuckv 1538 #endif
108 gezelter 1539 }
109    
110 chuckv 1538
111    
112 gezelter 1539 void ForceDecomposition::distributeData() {
113 chuckv 1538 #ifdef IS_MPI
114 gezelter 1539 Snapshot* snap = sman_->getCurrentSnapshot();
115 gezelter 1540
116 gezelter 1539 // gather up the atomic positions
117     AtomCommVectorI->gather(snap->atomData.position,
118     snap->atomIData.position);
119     AtomCommVectorJ->gather(snap->atomData.position,
120 gezelter 1540 snap->atomJData.position);
121 gezelter 1539
122     // gather up the cutoff group positions
123     cgCommVectorI->gather(snap->cgData.position,
124 gezelter 1540 snap->cgIData.position);
125 gezelter 1539 cgCommVectorJ->gather(snap->cgData.position,
126 gezelter 1540 snap->cgJData.position);
127 gezelter 1539
128     // if needed, gather the atomic rotation matrices
129     if (snap->atomData.getStorageLayout() & DataStorage::dslAmat) {
130     AtomCommMatrixI->gather(snap->atomData.aMat,
131 gezelter 1540 snap->atomIData.aMat);
132 gezelter 1539 AtomCommMatrixJ->gather(snap->atomData.aMat,
133 gezelter 1540 snap->atomJData.aMat);
134 gezelter 1539 }
135    
136     // if needed, gather the atomic eletrostatic frames
137     if (snap->atomData.getStorageLayout() & DataStorage::dslElectroFrame) {
138     AtomCommMatrixI->gather(snap->atomData.electroFrame,
139 gezelter 1540 snap->atomIData.electroFrame);
140 gezelter 1539 AtomCommMatrixJ->gather(snap->atomData.electroFrame,
141 gezelter 1540 snap->atomJData.electroFrame);
142 gezelter 1539 }
143     #endif
144     }
145    
146     void ForceDecomposition::collectIntermediateData() {
147     #ifdef IS_MPI
148     Snapshot* snap = sman_->getCurrentSnapshot();
149    
150     if (snap->atomData.getStorageLayout() & DataStorage::dslDensity) {
151 gezelter 1541
152 gezelter 1539 AtomCommRealI->scatter(snap->atomIData.density,
153 gezelter 1540 snap->atomData.density);
154 gezelter 1541
155     int n = snap->atomData.density.size();
156     std::vector<RealType> rho_tmp(n, 0.0);
157 gezelter 1539 AtomCommRealJ->scatter(snap->atomJData.density, rho_tmp);
158     for (int i = 0; i < n; i++)
159     snap->atomData.density[i] += rho_tmp[i];
160     }
161 chuckv 1538 #endif
162 gezelter 1539 }
163    
164     void ForceDecomposition::distributeIntermediateData() {
165 chuckv 1538 #ifdef IS_MPI
166 gezelter 1539 Snapshot* snap = sman_->getCurrentSnapshot();
167     if (snap->atomData.getStorageLayout() & DataStorage::dslFunctional) {
168     AtomCommRealI->gather(snap->atomData.functional,
169 gezelter 1540 snap->atomIData.functional);
170 gezelter 1539 AtomCommRealJ->gather(snap->atomData.functional,
171 gezelter 1540 snap->atomJData.functional);
172 gezelter 1539 }
173    
174     if (snap->atomData.getStorageLayout() & DataStorage::dslFunctionalDerivative) {
175     AtomCommRealI->gather(snap->atomData.functionalDerivative,
176 gezelter 1540 snap->atomIData.functionalDerivative);
177 gezelter 1539 AtomCommRealJ->gather(snap->atomData.functionalDerivative,
178 gezelter 1540 snap->atomJData.functionalDerivative);
179 gezelter 1539 }
180 chuckv 1538 #endif
181     }
182 gezelter 1539
183    
184     void ForceDecomposition::collectData() {
185     #ifdef IS_MPI
186 gezelter 1540 Snapshot* snap = sman_->getCurrentSnapshot();
187    
188 gezelter 1541 int n = snap->atomData.force.size();
189 gezelter 1544 vector<Vector3d> frc_tmp(n, V3Zero);
190 gezelter 1541
191 gezelter 1540 AtomCommVectorI->scatter(snap->atomIData.force, frc_tmp);
192 gezelter 1541 for (int i = 0; i < n; i++) {
193 gezelter 1540 snap->atomData.force[i] += frc_tmp[i];
194 gezelter 1541 frc_tmp[i] = 0.0;
195     }
196 gezelter 1540
197     AtomCommVectorJ->scatter(snap->atomJData.force, frc_tmp);
198     for (int i = 0; i < n; i++)
199     snap->atomData.force[i] += frc_tmp[i];
200    
201    
202     if (snap->atomData.getStorageLayout() & DataStorage::dslTorque) {
203 gezelter 1541
204     int nt = snap->atomData.force.size();
205 gezelter 1544 vector<Vector3d> trq_tmp(nt, V3Zero);
206 gezelter 1541
207 gezelter 1540 AtomCommVectorI->scatter(snap->atomIData.torque, trq_tmp);
208 gezelter 1541 for (int i = 0; i < n; i++) {
209 gezelter 1540 snap->atomData.torque[i] += trq_tmp[i];
210 gezelter 1541 trq_tmp[i] = 0.0;
211     }
212 gezelter 1540
213     AtomCommVectorJ->scatter(snap->atomJData.torque, trq_tmp);
214     for (int i = 0; i < n; i++)
215     snap->atomData.torque[i] += trq_tmp[i];
216     }
217    
218 gezelter 1544 int nLocal = snap->getNumberOfAtoms();
219    
220     vector<vector<RealType> > pot_temp(N_INTERACTION_FAMILIES,
221     vector<RealType> (nLocal, 0.0));
222 gezelter 1540
223 gezelter 1544 for (int i = 0; i < N_INTERACTION_FAMILIES; i++) {
224 gezelter 1541 AtomCommRealI->scatter(pot_row[i], pot_temp[i]);
225     for (int ii = 0; ii < pot_temp[i].size(); ii++ ) {
226     pot_local[i] += pot_temp[i][ii];
227     }
228     }
229 gezelter 1539 #endif
230 chuckv 1538 }
231    
232 gezelter 1539 } //end namespace OpenMD