ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/devel_omp/src/parallel/ForceMatrixDecomposition.cpp
Revision: 1549
Committed: Wed Apr 27 18:38:15 2011 UTC (14 years ago) by gezelter
Original Path: branches/development/src/parallel/ForceMatrixDecomposition.cpp
File size: 9011 byte(s)
Log Message:
a few more tweaks   We're getting somewhat closer to deleting fortran.

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 1549 #include "parallel/ForceMatrixDecomposition.hpp"
42 gezelter 1539 #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 1549 void ForceMatrixDecomposition::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 1549 AtomCommIntRow = new Communicator<Row,int>(nLocal);
61     AtomCommRealRow = new Communicator<Row,RealType>(nLocal);
62     AtomCommVectorRow = new Communicator<Row,Vector3d>(nLocal);
63     AtomCommMatrixRow = new Communicator<Row,Mat3x3d>(nLocal);
64 chuckv 1538
65 gezelter 1549 AtomCommIntColumn = new Communicator<Column,int>(nLocal);
66     AtomCommRealColumn = new Communicator<Column,RealType>(nLocal);
67     AtomCommVectorColumn = new Communicator<Column,Vector3d>(nLocal);
68     AtomCommMatrixColumn = new Communicator<Column,Mat3x3d>(nLocal);
69 chuckv 1538
70 gezelter 1549 cgCommIntRow = new Communicator<Row,int>(nGroups);
71     cgCommVectorRow = new Communicator<Row,Vector3d>(nGroups);
72     cgCommIntColumn = new Communicator<Column,int>(nGroups);
73     cgCommVectorColumn = new Communicator<Column,Vector3d>(nGroups);
74 gezelter 1541
75 gezelter 1549 int nAtomsInRow = AtomCommIntRow->getSize();
76     int nAtomsInCol = AtomCommIntColumn->getSize();
77     int nGroupsInRow = cgCommIntRow->getSize();
78     int nGroupsInCol = cgCommIntColumn->getSize();
79    
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 1549
87 gezelter 1544 // gather the information for atomtype IDs (atids):
88 gezelter 1547 vector<int> identsLocal = info_->getIdentArray();
89     identsRow.reserve(nAtomsInRow);
90     identsCol.reserve(nAtomsInCol);
91 gezelter 1549
92     AtomCommIntRow->gather(identsLocal, identsRow);
93     AtomCommIntColumn->gather(identsLocal, identsCol);
94    
95     AtomLocalToGlobal = info_->getGlobalAtomIndices();
96     AtomCommIntRow->gather(AtomLocalToGlobal, AtomRowToGlobal);
97     AtomCommIntColumn->gather(AtomLocalToGlobal, AtomColToGlobal);
98    
99     cgLocalToGlobal = info_->getGlobalGroupIndices();
100     cgCommIntRow->gather(cgLocalToGlobal, cgRowToGlobal);
101     cgCommIntColumn->gather(cgLocalToGlobal, cgColToGlobal);
102 gezelter 1541
103 gezelter 1544 // still need:
104     // topoDist
105     // exclude
106 chuckv 1538 #endif
107 gezelter 1539 }
108    
109 chuckv 1538
110    
111 gezelter 1549 void ForceMatrixDecomposition::distributeData() {
112 chuckv 1538 #ifdef IS_MPI
113 gezelter 1539 Snapshot* snap = sman_->getCurrentSnapshot();
114 gezelter 1540
115 gezelter 1539 // gather up the atomic positions
116 gezelter 1549 AtomCommVectorRow->gather(snap->atomData.position,
117 gezelter 1539 snap->atomIData.position);
118 gezelter 1549 AtomCommVectorColumn->gather(snap->atomData.position,
119 gezelter 1540 snap->atomJData.position);
120 gezelter 1539
121     // gather up the cutoff group positions
122 gezelter 1549 cgCommVectorRow->gather(snap->cgData.position,
123 gezelter 1540 snap->cgIData.position);
124 gezelter 1549 cgCommVectorColumn->gather(snap->cgData.position,
125 gezelter 1540 snap->cgJData.position);
126 gezelter 1539
127     // if needed, gather the atomic rotation matrices
128     if (snap->atomData.getStorageLayout() & DataStorage::dslAmat) {
129 gezelter 1549 AtomCommMatrixRow->gather(snap->atomData.aMat,
130 gezelter 1540 snap->atomIData.aMat);
131 gezelter 1549 AtomCommMatrixColumn->gather(snap->atomData.aMat,
132 gezelter 1540 snap->atomJData.aMat);
133 gezelter 1539 }
134    
135     // if needed, gather the atomic eletrostatic frames
136     if (snap->atomData.getStorageLayout() & DataStorage::dslElectroFrame) {
137 gezelter 1549 AtomCommMatrixRow->gather(snap->atomData.electroFrame,
138 gezelter 1540 snap->atomIData.electroFrame);
139 gezelter 1549 AtomCommMatrixColumn->gather(snap->atomData.electroFrame,
140 gezelter 1540 snap->atomJData.electroFrame);
141 gezelter 1539 }
142     #endif
143     }
144    
145 gezelter 1549 void ForceMatrixDecomposition::collectIntermediateData() {
146 gezelter 1539 #ifdef IS_MPI
147     Snapshot* snap = sman_->getCurrentSnapshot();
148    
149     if (snap->atomData.getStorageLayout() & DataStorage::dslDensity) {
150 gezelter 1541
151 gezelter 1549 AtomCommRealRow->scatter(snap->atomIData.density,
152 gezelter 1540 snap->atomData.density);
153 gezelter 1541
154     int n = snap->atomData.density.size();
155     std::vector<RealType> rho_tmp(n, 0.0);
156 gezelter 1549 AtomCommRealColumn->scatter(snap->atomJData.density, rho_tmp);
157 gezelter 1539 for (int i = 0; i < n; i++)
158     snap->atomData.density[i] += rho_tmp[i];
159     }
160 chuckv 1538 #endif
161 gezelter 1539 }
162    
163 gezelter 1549 void ForceMatrixDecomposition::distributeIntermediateData() {
164 chuckv 1538 #ifdef IS_MPI
165 gezelter 1539 Snapshot* snap = sman_->getCurrentSnapshot();
166     if (snap->atomData.getStorageLayout() & DataStorage::dslFunctional) {
167 gezelter 1549 AtomCommRealRow->gather(snap->atomData.functional,
168 gezelter 1540 snap->atomIData.functional);
169 gezelter 1549 AtomCommRealColumn->gather(snap->atomData.functional,
170 gezelter 1540 snap->atomJData.functional);
171 gezelter 1539 }
172    
173     if (snap->atomData.getStorageLayout() & DataStorage::dslFunctionalDerivative) {
174 gezelter 1549 AtomCommRealRow->gather(snap->atomData.functionalDerivative,
175 gezelter 1540 snap->atomIData.functionalDerivative);
176 gezelter 1549 AtomCommRealColumn->gather(snap->atomData.functionalDerivative,
177 gezelter 1540 snap->atomJData.functionalDerivative);
178 gezelter 1539 }
179 chuckv 1538 #endif
180     }
181 gezelter 1539
182    
183 gezelter 1549 void ForceMatrixDecomposition::collectData() {
184 gezelter 1539 #ifdef IS_MPI
185 gezelter 1540 Snapshot* snap = sman_->getCurrentSnapshot();
186    
187 gezelter 1541 int n = snap->atomData.force.size();
188 gezelter 1544 vector<Vector3d> frc_tmp(n, V3Zero);
189 gezelter 1541
190 gezelter 1549 AtomCommVectorRow->scatter(snap->atomIData.force, frc_tmp);
191 gezelter 1541 for (int i = 0; i < n; i++) {
192 gezelter 1540 snap->atomData.force[i] += frc_tmp[i];
193 gezelter 1541 frc_tmp[i] = 0.0;
194     }
195 gezelter 1540
196 gezelter 1549 AtomCommVectorColumn->scatter(snap->atomJData.force, frc_tmp);
197 gezelter 1540 for (int i = 0; i < n; i++)
198     snap->atomData.force[i] += frc_tmp[i];
199    
200    
201     if (snap->atomData.getStorageLayout() & DataStorage::dslTorque) {
202 gezelter 1541
203     int nt = snap->atomData.force.size();
204 gezelter 1544 vector<Vector3d> trq_tmp(nt, V3Zero);
205 gezelter 1541
206 gezelter 1549 AtomCommVectorRow->scatter(snap->atomIData.torque, trq_tmp);
207 gezelter 1541 for (int i = 0; i < n; i++) {
208 gezelter 1540 snap->atomData.torque[i] += trq_tmp[i];
209 gezelter 1541 trq_tmp[i] = 0.0;
210     }
211 gezelter 1540
212 gezelter 1549 AtomCommVectorColumn->scatter(snap->atomJData.torque, trq_tmp);
213 gezelter 1540 for (int i = 0; i < n; i++)
214     snap->atomData.torque[i] += trq_tmp[i];
215     }
216    
217 gezelter 1544 int nLocal = snap->getNumberOfAtoms();
218    
219     vector<vector<RealType> > pot_temp(N_INTERACTION_FAMILIES,
220     vector<RealType> (nLocal, 0.0));
221 gezelter 1540
222 gezelter 1544 for (int i = 0; i < N_INTERACTION_FAMILIES; i++) {
223 gezelter 1549 AtomCommRealRow->scatter(pot_row[i], pot_temp[i]);
224 gezelter 1541 for (int ii = 0; ii < pot_temp[i].size(); ii++ ) {
225     pot_local[i] += pot_temp[i][ii];
226     }
227     }
228 gezelter 1539 #endif
229 chuckv 1538 }
230    
231 gezelter 1539 } //end namespace OpenMD