# | Line 36 | Line 36 | |
---|---|---|
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). |
39 | > | * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 | > | * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 | */ | |
42 | #include "parallel/ForceMatrixDecomposition.hpp" | |
43 | #include "math/SquareMatrix3.hpp" | |
# | Line 53 | Line 54 | namespace OpenMD { | |
54 | // surrounding cells (not just the 14 upper triangular blocks that | |
55 | // are used when the processor can see all pairs) | |
56 | #ifdef IS_MPI | |
57 | < | cellOffsets_.push_back( Vector3i(-1, 0, 0) ); |
57 | < | cellOffsets_.push_back( Vector3i(-1,-1, 0) ); |
58 | < | cellOffsets_.push_back( Vector3i( 0,-1, 0) ); |
59 | < | cellOffsets_.push_back( Vector3i( 1,-1, 0) ); |
60 | < | cellOffsets_.push_back( Vector3i( 0, 0,-1) ); |
61 | < | cellOffsets_.push_back( Vector3i(-1, 0, 1) ); |
57 | > | cellOffsets_.clear(); |
58 | cellOffsets_.push_back( Vector3i(-1,-1,-1) ); | |
59 | cellOffsets_.push_back( Vector3i( 0,-1,-1) ); | |
60 | < | cellOffsets_.push_back( Vector3i( 1,-1,-1) ); |
60 | > | cellOffsets_.push_back( Vector3i( 1,-1,-1) ); |
61 | > | cellOffsets_.push_back( Vector3i(-1, 0,-1) ); |
62 | > | cellOffsets_.push_back( Vector3i( 0, 0,-1) ); |
63 | cellOffsets_.push_back( Vector3i( 1, 0,-1) ); | |
66 | – | cellOffsets_.push_back( Vector3i( 1, 1,-1) ); |
67 | – | cellOffsets_.push_back( Vector3i( 0, 1,-1) ); |
64 | cellOffsets_.push_back( Vector3i(-1, 1,-1) ); | |
65 | + | cellOffsets_.push_back( Vector3i( 0, 1,-1) ); |
66 | + | cellOffsets_.push_back( Vector3i( 1, 1,-1) ); |
67 | + | cellOffsets_.push_back( Vector3i(-1,-1, 0) ); |
68 | + | cellOffsets_.push_back( Vector3i( 0,-1, 0) ); |
69 | + | cellOffsets_.push_back( Vector3i( 1,-1, 0) ); |
70 | + | cellOffsets_.push_back( Vector3i(-1, 0, 0) ); |
71 | + | cellOffsets_.push_back( Vector3i( 0, 0, 0) ); |
72 | + | cellOffsets_.push_back( Vector3i( 1, 0, 0) ); |
73 | + | cellOffsets_.push_back( Vector3i(-1, 1, 0) ); |
74 | + | cellOffsets_.push_back( Vector3i( 0, 1, 0) ); |
75 | + | cellOffsets_.push_back( Vector3i( 1, 1, 0) ); |
76 | + | cellOffsets_.push_back( Vector3i(-1,-1, 1) ); |
77 | + | cellOffsets_.push_back( Vector3i( 0,-1, 1) ); |
78 | + | cellOffsets_.push_back( Vector3i( 1,-1, 1) ); |
79 | + | cellOffsets_.push_back( Vector3i(-1, 0, 1) ); |
80 | + | cellOffsets_.push_back( Vector3i( 0, 0, 1) ); |
81 | + | cellOffsets_.push_back( Vector3i( 1, 0, 1) ); |
82 | + | cellOffsets_.push_back( Vector3i(-1, 1, 1) ); |
83 | + | cellOffsets_.push_back( Vector3i( 0, 1, 1) ); |
84 | + | cellOffsets_.push_back( Vector3i( 1, 1, 1) ); |
85 | #endif | |
86 | } | |
87 | ||
# | Line 79 | Line 95 | namespace OpenMD { | |
95 | storageLayout_ = sman_->getStorageLayout(); | |
96 | ff_ = info_->getForceField(); | |
97 | nLocal_ = snap_->getNumberOfAtoms(); | |
98 | < | |
98 | > | |
99 | nGroups_ = info_->getNLocalCutoffGroups(); | |
100 | // gather the information for atomtype IDs (atids): | |
101 | idents = info_->getIdentArray(); | |
# | Line 93 | Line 109 | namespace OpenMD { | |
109 | PairList* oneTwo = info_->getOneTwoInteractions(); | |
110 | PairList* oneThree = info_->getOneThreeInteractions(); | |
111 | PairList* oneFour = info_->getOneFourInteractions(); | |
112 | < | |
112 | > | |
113 | > | if (needVelocities_) |
114 | > | snap_->cgData.setStorageLayout(DataStorage::dslPosition | |
115 | > | DataStorage::dslVelocity); |
116 | > | else |
117 | > | snap_->cgData.setStorageLayout(DataStorage::dslPosition); |
118 | > | |
119 | #ifdef IS_MPI | |
120 | ||
121 | MPI::Intracomm row = rowComm.getComm(); | |
# | Line 129 | Line 151 | namespace OpenMD { | |
151 | cgRowData.resize(nGroupsInRow_); | |
152 | cgRowData.setStorageLayout(DataStorage::dslPosition); | |
153 | cgColData.resize(nGroupsInCol_); | |
154 | < | cgColData.setStorageLayout(DataStorage::dslPosition); |
155 | < | |
154 | > | if (needVelocities_) |
155 | > | // we only need column velocities if we need them. |
156 | > | cgColData.setStorageLayout(DataStorage::dslPosition | |
157 | > | DataStorage::dslVelocity); |
158 | > | else |
159 | > | cgColData.setStorageLayout(DataStorage::dslPosition); |
160 | > | |
161 | identsRow.resize(nAtomsInRow_); | |
162 | identsCol.resize(nAtomsInCol_); | |
163 | ||
# | Line 154 | Line 181 | namespace OpenMD { | |
181 | AtomPlanIntRow->gather(AtomLocalToGlobal, AtomRowToGlobal); | |
182 | AtomPlanIntColumn->gather(AtomLocalToGlobal, AtomColToGlobal); | |
183 | ||
157 | – | cerr << "Atoms in Local:\n"; |
158 | – | for (int i = 0; i < AtomLocalToGlobal.size(); i++) { |
159 | – | cerr << "i =\t" << i << "\t localAt =\t" << AtomLocalToGlobal[i] << "\n"; |
160 | – | } |
161 | – | cerr << "Atoms in Row:\n"; |
162 | – | for (int i = 0; i < AtomRowToGlobal.size(); i++) { |
163 | – | cerr << "i =\t" << i << "\t rowAt =\t" << AtomRowToGlobal[i] << "\n"; |
164 | – | } |
165 | – | cerr << "Atoms in Col:\n"; |
166 | – | for (int i = 0; i < AtomColToGlobal.size(); i++) { |
167 | – | cerr << "i =\t" << i << "\t colAt =\t" << AtomColToGlobal[i] << "\n"; |
168 | – | } |
169 | – | |
184 | cgRowToGlobal.resize(nGroupsInRow_); | |
185 | cgColToGlobal.resize(nGroupsInCol_); | |
186 | cgPlanIntRow->gather(cgLocalToGlobal, cgRowToGlobal); | |
187 | cgPlanIntColumn->gather(cgLocalToGlobal, cgColToGlobal); | |
188 | ||
175 | – | cerr << "Gruops in Local:\n"; |
176 | – | for (int i = 0; i < cgLocalToGlobal.size(); i++) { |
177 | – | cerr << "i =\t" << i << "\t localCG =\t" << cgLocalToGlobal[i] << "\n"; |
178 | – | } |
179 | – | cerr << "Groups in Row:\n"; |
180 | – | for (int i = 0; i < cgRowToGlobal.size(); i++) { |
181 | – | cerr << "i =\t" << i << "\t rowCG =\t" << cgRowToGlobal[i] << "\n"; |
182 | – | } |
183 | – | cerr << "Groups in Col:\n"; |
184 | – | for (int i = 0; i < cgColToGlobal.size(); i++) { |
185 | – | cerr << "i =\t" << i << "\t colCG =\t" << cgColToGlobal[i] << "\n"; |
186 | – | } |
187 | – | |
188 | – | |
189 | massFactorsRow.resize(nAtomsInRow_); | |
190 | massFactorsCol.resize(nAtomsInCol_); | |
191 | AtomPlanRealRow->gather(massFactors, massFactorsRow); | |
# | Line 245 | Line 245 | namespace OpenMD { | |
245 | } | |
246 | } | |
247 | ||
248 | < | #endif |
249 | < | |
250 | < | // allocate memory for the parallel objects |
251 | < | atypesLocal.resize(nLocal_); |
252 | < | |
253 | < | for (int i = 0; i < nLocal_; i++) |
254 | < | atypesLocal[i] = ff_->getAtomType(idents[i]); |
255 | < | |
256 | < | groupList_.clear(); |
257 | < | groupList_.resize(nGroups_); |
258 | < | for (int i = 0; i < nGroups_; i++) { |
259 | < | int gid = cgLocalToGlobal[i]; |
260 | < | for (int j = 0; j < nLocal_; j++) { |
261 | < | int aid = AtomLocalToGlobal[j]; |
262 | < | if (globalGroupMembership[aid] == gid) { |
263 | < | groupList_[i].push_back(j); |
264 | < | } |
265 | < | } |
266 | < | } |
267 | < | |
248 | > | #else |
249 | excludesForAtom.clear(); | |
250 | excludesForAtom.resize(nLocal_); | |
251 | toposForAtom.clear(); | |
# | Line 297 | Line 278 | namespace OpenMD { | |
278 | } | |
279 | } | |
280 | } | |
281 | < | |
281 | > | #endif |
282 | > | |
283 | > | // allocate memory for the parallel objects |
284 | > | atypesLocal.resize(nLocal_); |
285 | > | |
286 | > | for (int i = 0; i < nLocal_; i++) |
287 | > | atypesLocal[i] = ff_->getAtomType(idents[i]); |
288 | > | |
289 | > | groupList_.clear(); |
290 | > | groupList_.resize(nGroups_); |
291 | > | for (int i = 0; i < nGroups_; i++) { |
292 | > | int gid = cgLocalToGlobal[i]; |
293 | > | for (int j = 0; j < nLocal_; j++) { |
294 | > | int aid = AtomLocalToGlobal[j]; |
295 | > | if (globalGroupMembership[aid] == gid) { |
296 | > | groupList_[i].push_back(j); |
297 | > | } |
298 | > | } |
299 | > | } |
300 | > | |
301 | > | |
302 | createGtypeCutoffMap(); | |
303 | ||
304 | } | |
# | Line 535 | Line 536 | namespace OpenMD { | |
536 | atomColData.skippedCharge.end(), 0.0); | |
537 | } | |
538 | ||
539 | + | if (storageLayout_ & DataStorage::dslFlucQForce) { |
540 | + | fill(atomRowData.flucQFrc.begin(), |
541 | + | atomRowData.flucQFrc.end(), 0.0); |
542 | + | fill(atomColData.flucQFrc.begin(), |
543 | + | atomColData.flucQFrc.end(), 0.0); |
544 | + | } |
545 | + | |
546 | + | if (storageLayout_ & DataStorage::dslElectricField) { |
547 | + | fill(atomRowData.electricField.begin(), |
548 | + | atomRowData.electricField.end(), V3Zero); |
549 | + | fill(atomColData.electricField.begin(), |
550 | + | atomColData.electricField.end(), V3Zero); |
551 | + | } |
552 | + | |
553 | + | if (storageLayout_ & DataStorage::dslFlucQForce) { |
554 | + | fill(atomRowData.flucQFrc.begin(), atomRowData.flucQFrc.end(), |
555 | + | 0.0); |
556 | + | fill(atomColData.flucQFrc.begin(), atomColData.flucQFrc.end(), |
557 | + | 0.0); |
558 | + | } |
559 | + | |
560 | #endif | |
561 | // even in parallel, we need to zero out the local arrays: | |
562 | ||
# | Line 547 | Line 569 | namespace OpenMD { | |
569 | fill(snap_->atomData.density.begin(), | |
570 | snap_->atomData.density.end(), 0.0); | |
571 | } | |
572 | + | |
573 | if (storageLayout_ & DataStorage::dslFunctional) { | |
574 | fill(snap_->atomData.functional.begin(), | |
575 | snap_->atomData.functional.end(), 0.0); | |
576 | } | |
577 | + | |
578 | if (storageLayout_ & DataStorage::dslFunctionalDerivative) { | |
579 | fill(snap_->atomData.functionalDerivative.begin(), | |
580 | snap_->atomData.functionalDerivative.end(), 0.0); | |
581 | } | |
582 | + | |
583 | if (storageLayout_ & DataStorage::dslSkippedCharge) { | |
584 | fill(snap_->atomData.skippedCharge.begin(), | |
585 | snap_->atomData.skippedCharge.end(), 0.0); | |
586 | } | |
587 | < | |
587 | > | |
588 | > | if (storageLayout_ & DataStorage::dslElectricField) { |
589 | > | fill(snap_->atomData.electricField.begin(), |
590 | > | snap_->atomData.electricField.end(), V3Zero); |
591 | > | } |
592 | } | |
593 | ||
594 | ||
# | Line 576 | Line 605 | namespace OpenMD { | |
605 | ||
606 | // gather up the cutoff group positions | |
607 | ||
579 | – | cerr << "before gather\n"; |
580 | – | for (int i = 0; i < snap_->cgData.position.size(); i++) { |
581 | – | cerr << "cgpos = " << snap_->cgData.position[i] << "\n"; |
582 | – | } |
583 | – | |
608 | cgPlanVectorRow->gather(snap_->cgData.position, | |
609 | cgRowData.position); | |
610 | ||
587 | – | cerr << "after gather\n"; |
588 | – | for (int i = 0; i < cgRowData.position.size(); i++) { |
589 | – | cerr << "cgRpos = " << cgRowData.position[i] << "\n"; |
590 | – | } |
591 | – | |
611 | cgPlanVectorColumn->gather(snap_->cgData.position, | |
612 | cgColData.position); | |
613 | < | for (int i = 0; i < cgColData.position.size(); i++) { |
614 | < | cerr << "cgCpos = " << cgColData.position[i] << "\n"; |
613 | > | |
614 | > | |
615 | > | |
616 | > | if (needVelocities_) { |
617 | > | // gather up the atomic velocities |
618 | > | AtomPlanVectorColumn->gather(snap_->atomData.velocity, |
619 | > | atomColData.velocity); |
620 | > | |
621 | > | cgPlanVectorColumn->gather(snap_->cgData.velocity, |
622 | > | cgColData.velocity); |
623 | } | |
624 | ||
625 | ||
# | Line 612 | Line 639 | namespace OpenMD { | |
639 | atomColData.electroFrame); | |
640 | } | |
641 | ||
642 | + | // if needed, gather the atomic fluctuating charge values |
643 | + | if (storageLayout_ & DataStorage::dslFlucQPosition) { |
644 | + | AtomPlanRealRow->gather(snap_->atomData.flucQPos, |
645 | + | atomRowData.flucQPos); |
646 | + | AtomPlanRealColumn->gather(snap_->atomData.flucQPos, |
647 | + | atomColData.flucQPos); |
648 | + | } |
649 | + | |
650 | #endif | |
651 | } | |
652 | ||
# | Line 634 | Line 669 | namespace OpenMD { | |
669 | for (int i = 0; i < n; i++) | |
670 | snap_->atomData.density[i] += rho_tmp[i]; | |
671 | } | |
672 | + | |
673 | + | if (storageLayout_ & DataStorage::dslElectricField) { |
674 | + | |
675 | + | AtomPlanVectorRow->scatter(atomRowData.electricField, |
676 | + | snap_->atomData.electricField); |
677 | + | |
678 | + | int n = snap_->atomData.electricField.size(); |
679 | + | vector<Vector3d> field_tmp(n, V3Zero); |
680 | + | AtomPlanVectorColumn->scatter(atomColData.electricField, field_tmp); |
681 | + | for (int i = 0; i < n; i++) |
682 | + | snap_->atomData.electricField[i] += field_tmp[i]; |
683 | + | } |
684 | #endif | |
685 | } | |
686 | ||
# | Line 708 | Line 755 | namespace OpenMD { | |
755 | } | |
756 | ||
757 | AtomPlanRealColumn->scatter(atomColData.skippedCharge, skch_tmp); | |
758 | < | for (int i = 0; i < ns; i++) |
758 | > | for (int i = 0; i < ns; i++) |
759 | snap_->atomData.skippedCharge[i] += skch_tmp[i]; | |
760 | + | |
761 | } | |
762 | ||
763 | + | if (storageLayout_ & DataStorage::dslFlucQForce) { |
764 | + | |
765 | + | int nq = snap_->atomData.flucQFrc.size(); |
766 | + | vector<RealType> fqfrc_tmp(nq, 0.0); |
767 | + | |
768 | + | AtomPlanRealRow->scatter(atomRowData.flucQFrc, fqfrc_tmp); |
769 | + | for (int i = 0; i < nq; i++) { |
770 | + | snap_->atomData.flucQFrc[i] += fqfrc_tmp[i]; |
771 | + | fqfrc_tmp[i] = 0.0; |
772 | + | } |
773 | + | |
774 | + | AtomPlanRealColumn->scatter(atomColData.flucQFrc, fqfrc_tmp); |
775 | + | for (int i = 0; i < nq; i++) |
776 | + | snap_->atomData.flucQFrc[i] += fqfrc_tmp[i]; |
777 | + | |
778 | + | } |
779 | + | |
780 | nLocal_ = snap_->getNumberOfAtoms(); | |
781 | ||
782 | vector<potVec> pot_temp(nLocal_, | |
# | Line 723 | Line 788 | namespace OpenMD { | |
788 | ||
789 | for (int ii = 0; ii < pot_temp.size(); ii++ ) | |
790 | pairwisePot += pot_temp[ii]; | |
791 | < | |
791 | > | |
792 | > | if (storageLayout_ & DataStorage::dslParticlePot) { |
793 | > | // This is the pairwise contribution to the particle pot. The |
794 | > | // embedding contribution is added in each of the low level |
795 | > | // non-bonded routines. In single processor, this is done in |
796 | > | // unpackInteractionData, not in collectData. |
797 | > | for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) { |
798 | > | for (int i = 0; i < nLocal_; i++) { |
799 | > | // factor of two is because the total potential terms are divided |
800 | > | // by 2 in parallel due to row/ column scatter |
801 | > | snap_->atomData.particlePot[i] += 2.0 * pot_temp[i](ii); |
802 | > | } |
803 | > | } |
804 | > | } |
805 | > | |
806 | fill(pot_temp.begin(), pot_temp.end(), | |
807 | Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); | |
808 | ||
# | Line 731 | Line 810 | namespace OpenMD { | |
810 | ||
811 | for (int ii = 0; ii < pot_temp.size(); ii++ ) | |
812 | pairwisePot += pot_temp[ii]; | |
813 | + | |
814 | + | if (storageLayout_ & DataStorage::dslParticlePot) { |
815 | + | // This is the pairwise contribution to the particle pot. The |
816 | + | // embedding contribution is added in each of the low level |
817 | + | // non-bonded routines. In single processor, this is done in |
818 | + | // unpackInteractionData, not in collectData. |
819 | + | for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) { |
820 | + | for (int i = 0; i < nLocal_; i++) { |
821 | + | // factor of two is because the total potential terms are divided |
822 | + | // by 2 in parallel due to row/ column scatter |
823 | + | snap_->atomData.particlePot[i] += 2.0 * pot_temp[i](ii); |
824 | + | } |
825 | + | } |
826 | + | } |
827 | + | |
828 | + | if (storageLayout_ & DataStorage::dslParticlePot) { |
829 | + | int npp = snap_->atomData.particlePot.size(); |
830 | + | vector<RealType> ppot_temp(npp, 0.0); |
831 | + | |
832 | + | // This is the direct or embedding contribution to the particle |
833 | + | // pot. |
834 | + | |
835 | + | AtomPlanRealRow->scatter(atomRowData.particlePot, ppot_temp); |
836 | + | for (int i = 0; i < npp; i++) { |
837 | + | snap_->atomData.particlePot[i] += ppot_temp[i]; |
838 | + | } |
839 | + | |
840 | + | fill(ppot_temp.begin(), ppot_temp.end(), 0.0); |
841 | + | |
842 | + | AtomPlanRealColumn->scatter(atomColData.particlePot, ppot_temp); |
843 | + | for (int i = 0; i < npp; i++) { |
844 | + | snap_->atomData.particlePot[i] += ppot_temp[i]; |
845 | + | } |
846 | + | } |
847 | + | |
848 | + | for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) { |
849 | + | RealType ploc1 = pairwisePot[ii]; |
850 | + | RealType ploc2 = 0.0; |
851 | + | MPI::COMM_WORLD.Allreduce(&ploc1, &ploc2, 1, MPI::REALTYPE, MPI::SUM); |
852 | + | pairwisePot[ii] = ploc2; |
853 | + | } |
854 | + | |
855 | + | for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) { |
856 | + | RealType ploc1 = embeddingPot[ii]; |
857 | + | RealType ploc2 = 0.0; |
858 | + | MPI::COMM_WORLD.Allreduce(&ploc1, &ploc2, 1, MPI::REALTYPE, MPI::SUM); |
859 | + | embeddingPot[ii] = ploc2; |
860 | + | } |
861 | + | |
862 | + | // Here be dragons. |
863 | + | MPI::Intracomm col = colComm.getComm(); |
864 | + | |
865 | + | col.Allreduce(MPI::IN_PLACE, |
866 | + | &snap_->frameData.conductiveHeatFlux[0], 3, |
867 | + | MPI::REALTYPE, MPI::SUM); |
868 | + | |
869 | + | |
870 | #endif | |
871 | ||
736 | – | cerr << "pairwisePot = " << pairwisePot << "\n"; |
872 | } | |
873 | ||
874 | int ForceMatrixDecomposition::getNAtomsInRow() { | |
# | Line 768 | Line 903 | namespace OpenMD { | |
903 | ||
904 | #ifdef IS_MPI | |
905 | d = cgColData.position[cg2] - cgRowData.position[cg1]; | |
771 | – | cerr << "cg1 = " << cg1 << "\tcg1p = " << cgRowData.position[cg1] << "\n"; |
772 | – | cerr << "cg2 = " << cg2 << "\tcg2p = " << cgColData.position[cg2] << "\n"; |
906 | #else | |
907 | d = snap_->cgData.position[cg2] - snap_->cgData.position[cg1]; | |
775 | – | cerr << "cg1 = " << cg1 << "\tcg1p = " << snap_->cgData.position[cg1] << "\n"; |
776 | – | cerr << "cg2 = " << cg2 << "\tcg2p = " << snap_->cgData.position[cg2] << "\n"; |
908 | #endif | |
909 | ||
910 | snap_->wrapVector(d); | |
911 | return d; | |
912 | } | |
913 | ||
914 | + | Vector3d ForceMatrixDecomposition::getGroupVelocityColumn(int cg2){ |
915 | + | #ifdef IS_MPI |
916 | + | return cgColData.velocity[cg2]; |
917 | + | #else |
918 | + | return snap_->cgData.velocity[cg2]; |
919 | + | #endif |
920 | + | } |
921 | ||
922 | + | Vector3d ForceMatrixDecomposition::getAtomVelocityColumn(int atom2){ |
923 | + | #ifdef IS_MPI |
924 | + | return atomColData.velocity[atom2]; |
925 | + | #else |
926 | + | return snap_->atomData.velocity[atom2]; |
927 | + | #endif |
928 | + | } |
929 | + | |
930 | + | |
931 | Vector3d ForceMatrixDecomposition::getAtomToGroupVectorRow(int atom1, int cg1){ | |
932 | ||
933 | Vector3d d; | |
# | Line 848 | Line 995 | namespace OpenMD { | |
995 | */ | |
996 | bool ForceMatrixDecomposition::skipAtomPair(int atom1, int atom2) { | |
997 | int unique_id_1, unique_id_2; | |
998 | < | |
852 | < | |
853 | < | cerr << "sap with atom1, atom2 =\t" << atom1 << "\t" << atom2 << "\n"; |
998 | > | |
999 | #ifdef IS_MPI | |
1000 | // in MPI, we have to look up the unique IDs for each atom | |
1001 | unique_id_1 = AtomRowToGlobal[atom1]; | |
1002 | unique_id_2 = AtomColToGlobal[atom2]; | |
1003 | + | #else |
1004 | + | unique_id_1 = AtomLocalToGlobal[atom1]; |
1005 | + | unique_id_2 = AtomLocalToGlobal[atom2]; |
1006 | + | #endif |
1007 | ||
859 | – | cerr << "sap with uid1, uid2 =\t" << unique_id_1 << "\t" << unique_id_2 << "\n"; |
860 | – | // this situation should only arise in MPI simulations |
1008 | if (unique_id_1 == unique_id_2) return true; | |
1009 | < | |
1009 | > | |
1010 | > | #ifdef IS_MPI |
1011 | // this prevents us from doing the pair on multiple processors | |
1012 | if (unique_id_1 < unique_id_2) { | |
1013 | if ((unique_id_1 + unique_id_2) % 2 == 0) return true; | |
1014 | } else { | |
1015 | < | if ((unique_id_1 + unique_id_2) % 2 == 1) return true; |
1015 | > | if ((unique_id_1 + unique_id_2) % 2 == 1) return true; |
1016 | } | |
1017 | #endif | |
1018 | + | |
1019 | return false; | |
1020 | } | |
1021 | ||
# | Line 880 | Line 1029 | namespace OpenMD { | |
1029 | * field) must still be handled for these pairs. | |
1030 | */ | |
1031 | bool ForceMatrixDecomposition::excludeAtomPair(int atom1, int atom2) { | |
1032 | < | int unique_id_2; |
1033 | < | #ifdef IS_MPI |
1034 | < | // in MPI, we have to look up the unique IDs for the row atom. |
886 | < | unique_id_2 = AtomColToGlobal[atom2]; |
887 | < | #else |
888 | < | // in the normal loop, the atom numbers are unique |
889 | < | unique_id_2 = atom2; |
890 | < | #endif |
1032 | > | |
1033 | > | // excludesForAtom was constructed to use row/column indices in the MPI |
1034 | > | // version, and to use local IDs in the non-MPI version: |
1035 | ||
1036 | for (vector<int>::iterator i = excludesForAtom[atom1].begin(); | |
1037 | i != excludesForAtom[atom1].end(); ++i) { | |
1038 | < | if ( (*i) == unique_id_2 ) return true; |
1038 | > | if ( (*i) == atom2 ) return true; |
1039 | } | |
1040 | ||
1041 | return false; | |
# | Line 965 | Line 1109 | namespace OpenMD { | |
1109 | idat.skippedCharge2 = &(atomColData.skippedCharge[atom2]); | |
1110 | } | |
1111 | ||
1112 | + | if (storageLayout_ & DataStorage::dslFlucQPosition) { |
1113 | + | idat.flucQ1 = &(atomRowData.flucQPos[atom1]); |
1114 | + | idat.flucQ2 = &(atomColData.flucQPos[atom2]); |
1115 | + | } |
1116 | + | |
1117 | #else | |
1118 | + | |
1119 | ||
1120 | + | // cerr << "atoms = " << atom1 << " " << atom2 << "\n"; |
1121 | + | // cerr << "pos1 = " << snap_->atomData.position[atom1] << "\n"; |
1122 | + | // cerr << "pos2 = " << snap_->atomData.position[atom2] << "\n"; |
1123 | + | |
1124 | idat.atypes = make_pair( atypesLocal[atom1], atypesLocal[atom2]); | |
1125 | //idat.atypes = make_pair( ff_->getAtomType(idents[atom1]), | |
1126 | // ff_->getAtomType(idents[atom2]) ); | |
# | Line 1010 | Line 1164 | namespace OpenMD { | |
1164 | idat.skippedCharge1 = &(snap_->atomData.skippedCharge[atom1]); | |
1165 | idat.skippedCharge2 = &(snap_->atomData.skippedCharge[atom2]); | |
1166 | } | |
1167 | + | |
1168 | + | if (storageLayout_ & DataStorage::dslFlucQPosition) { |
1169 | + | idat.flucQ1 = &(snap_->atomData.flucQPos[atom1]); |
1170 | + | idat.flucQ2 = &(snap_->atomData.flucQPos[atom2]); |
1171 | + | } |
1172 | + | |
1173 | #endif | |
1174 | } | |
1175 | ||
1176 | ||
1177 | void ForceMatrixDecomposition::unpackInteractionData(InteractionData &idat, int atom1, int atom2) { | |
1178 | #ifdef IS_MPI | |
1179 | < | pot_row[atom1] += 0.5 * *(idat.pot); |
1180 | < | pot_col[atom2] += 0.5 * *(idat.pot); |
1179 | > | pot_row[atom1] += RealType(0.5) * *(idat.pot); |
1180 | > | pot_col[atom2] += RealType(0.5) * *(idat.pot); |
1181 | ||
1182 | atomRowData.force[atom1] += *(idat.f1); | |
1183 | atomColData.force[atom2] -= *(idat.f1); | |
1184 | + | |
1185 | + | if (storageLayout_ & DataStorage::dslFlucQForce) { |
1186 | + | atomRowData.flucQFrc[atom1] -= *(idat.dVdFQ1); |
1187 | + | atomColData.flucQFrc[atom2] -= *(idat.dVdFQ2); |
1188 | + | } |
1189 | + | |
1190 | + | if (storageLayout_ & DataStorage::dslElectricField) { |
1191 | + | atomRowData.electricField[atom1] += *(idat.eField1); |
1192 | + | atomColData.electricField[atom2] += *(idat.eField2); |
1193 | + | } |
1194 | + | |
1195 | #else | |
1196 | pairwisePot += *(idat.pot); | |
1197 | ||
1198 | snap_->atomData.force[atom1] += *(idat.f1); | |
1199 | snap_->atomData.force[atom2] -= *(idat.f1); | |
1200 | + | |
1201 | + | if (idat.doParticlePot) { |
1202 | + | // This is the pairwise contribution to the particle pot. The |
1203 | + | // embedding contribution is added in each of the low level |
1204 | + | // non-bonded routines. In parallel, this calculation is done |
1205 | + | // in collectData, not in unpackInteractionData. |
1206 | + | snap_->atomData.particlePot[atom1] += *(idat.vpair) * *(idat.sw); |
1207 | + | snap_->atomData.particlePot[atom2] += *(idat.vpair) * *(idat.sw); |
1208 | + | } |
1209 | + | |
1210 | + | if (storageLayout_ & DataStorage::dslFlucQForce) { |
1211 | + | snap_->atomData.flucQFrc[atom1] -= *(idat.dVdFQ1); |
1212 | + | snap_->atomData.flucQFrc[atom2] -= *(idat.dVdFQ2); |
1213 | + | } |
1214 | + | |
1215 | + | if (storageLayout_ & DataStorage::dslElectricField) { |
1216 | + | snap_->atomData.electricField[atom1] += *(idat.eField1); |
1217 | + | snap_->atomData.electricField[atom2] += *(idat.eField2); |
1218 | + | } |
1219 | + | |
1220 | #endif | |
1221 | ||
1222 | } | |
# | Line 1131 | Line 1322 | namespace OpenMD { | |
1322 | // add this cutoff group to the list of groups in this cell; | |
1323 | cellListCol_[cellIndex].push_back(i); | |
1324 | } | |
1325 | + | |
1326 | #else | |
1327 | for (int i = 0; i < nGroups_; i++) { | |
1328 | rs = snap_->cgData.position[i]; | |
# | Line 1156 | Line 1348 | namespace OpenMD { | |
1348 | // add this cutoff group to the list of groups in this cell; | |
1349 | cellList_[cellIndex].push_back(i); | |
1350 | } | |
1351 | + | |
1352 | #endif | |
1353 | ||
1354 | for (int m1z = 0; m1z < nCells_.z(); m1z++) { | |
# | Line 1168 | Line 1361 | namespace OpenMD { | |
1361 | os != cellOffsets_.end(); ++os) { | |
1362 | ||
1363 | Vector3i m2v = m1v + (*os); | |
1364 | < | |
1364 | > | |
1365 | > | |
1366 | if (m2v.x() >= nCells_.x()) { | |
1367 | m2v.x() = 0; | |
1368 | } else if (m2v.x() < 0) { | |
# | Line 1186 | Line 1380 | namespace OpenMD { | |
1380 | } else if (m2v.z() < 0) { | |
1381 | m2v.z() = nCells_.z() - 1; | |
1382 | } | |
1383 | < | |
1383 | > | |
1384 | int m2 = Vlinear (m2v, nCells_); | |
1385 | ||
1386 | #ifdef IS_MPI | |
# | Line 1195 | Line 1389 | namespace OpenMD { | |
1389 | for (vector<int>::iterator j2 = cellListCol_[m2].begin(); | |
1390 | j2 != cellListCol_[m2].end(); ++j2) { | |
1391 | ||
1392 | < | // In parallel, we need to visit *all* pairs of row & |
1393 | < | // column indicies and will truncate later on. |
1392 | > | // In parallel, we need to visit *all* pairs of row |
1393 | > | // & column indicies and will divide labor in the |
1394 | > | // force evaluation later. |
1395 | dr = cgColData.position[(*j2)] - cgRowData.position[(*j1)]; | |
1396 | snap_->wrapVector(dr); | |
1397 | cuts = getGroupCutoffs( (*j1), (*j2) ); | |
# | Line 1206 | Line 1401 | namespace OpenMD { | |
1401 | } | |
1402 | } | |
1403 | #else | |
1209 | – | |
1404 | for (vector<int>::iterator j1 = cellList_[m1].begin(); | |
1405 | j1 != cellList_[m1].end(); ++j1) { | |
1406 | for (vector<int>::iterator j2 = cellList_[m2].begin(); | |
1407 | j2 != cellList_[m2].end(); ++j2) { | |
1408 | < | |
1408 | > | |
1409 | // Always do this if we're in different cells or if | |
1410 | < | // we're in the same cell and the global index of the |
1411 | < | // j2 cutoff group is less than the j1 cutoff group |
1412 | < | |
1413 | < | if (m2 != m1 || (*j2) < (*j1)) { |
1410 | > | // we're in the same cell and the global index of |
1411 | > | // the j2 cutoff group is greater than or equal to |
1412 | > | // the j1 cutoff group. Note that Rappaport's code |
1413 | > | // has a "less than" conditional here, but that |
1414 | > | // deals with atom-by-atom computation. OpenMD |
1415 | > | // allows atoms within a single cutoff group to |
1416 | > | // interact with each other. |
1417 | > | |
1418 | > | |
1419 | > | |
1420 | > | if (m2 != m1 || (*j2) >= (*j1) ) { |
1421 | > | |
1422 | dr = snap_->cgData.position[(*j2)] - snap_->cgData.position[(*j1)]; | |
1423 | snap_->wrapVector(dr); | |
1424 | cuts = getGroupCutoffs( (*j1), (*j2) ); | |
# | Line 1235 | Line 1437 | namespace OpenMD { | |
1437 | // branch to do all cutoff group pairs | |
1438 | #ifdef IS_MPI | |
1439 | for (int j1 = 0; j1 < nGroupsInRow_; j1++) { | |
1440 | < | for (int j2 = 0; j2 < nGroupsInCol_; j2++) { |
1440 | > | for (int j2 = 0; j2 < nGroupsInCol_; j2++) { |
1441 | dr = cgColData.position[j2] - cgRowData.position[j1]; | |
1442 | snap_->wrapVector(dr); | |
1443 | cuts = getGroupCutoffs( j1, j2 ); | |
# | Line 1243 | Line 1445 | namespace OpenMD { | |
1445 | neighborList.push_back(make_pair(j1, j2)); | |
1446 | } | |
1447 | } | |
1448 | < | } |
1448 | > | } |
1449 | #else | |
1450 | < | for (int j1 = 0; j1 < nGroups_ - 1; j1++) { |
1451 | < | for (int j2 = j1 + 1; j2 < nGroups_; j2++) { |
1450 | > | // include all groups here. |
1451 | > | for (int j1 = 0; j1 < nGroups_; j1++) { |
1452 | > | // include self group interactions j2 == j1 |
1453 | > | for (int j2 = j1; j2 < nGroups_; j2++) { |
1454 | dr = snap_->cgData.position[j2] - snap_->cgData.position[j1]; | |
1455 | snap_->wrapVector(dr); | |
1456 | cuts = getGroupCutoffs( j1, j2 ); | |
1457 | if (dr.lengthSquare() < cuts.third) { | |
1458 | neighborList.push_back(make_pair(j1, j2)); | |
1459 | } | |
1460 | < | } |
1461 | < | } |
1460 | > | } |
1461 | > | } |
1462 | #endif | |
1463 | } | |
1464 |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |