47 |
|
using namespace std; |
48 |
|
namespace OpenMD { |
49 |
|
|
50 |
+ |
ForceMatrixDecomposition::ForceMatrixDecomposition(SimInfo* info, InteractionManager* iMan) : ForceDecomposition(info, iMan) { |
51 |
+ |
|
52 |
+ |
// In a parallel computation, row and colum scans must visit all |
53 |
+ |
// surrounding cells (not just the 14 upper triangular blocks that |
54 |
+ |
// are used when the processor can see all pairs) |
55 |
+ |
#ifdef IS_MPI |
56 |
+ |
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) ); |
62 |
+ |
cellOffsets_.push_back( Vector3i(-1,-1,-1) ); |
63 |
+ |
cellOffsets_.push_back( Vector3i( 0,-1,-1) ); |
64 |
+ |
cellOffsets_.push_back( Vector3i( 1,-1,-1) ); |
65 |
+ |
cellOffsets_.push_back( Vector3i( 1, 0,-1) ); |
66 |
+ |
cellOffsets_.push_back( Vector3i( 1, 1,-1) ); |
67 |
+ |
cellOffsets_.push_back( Vector3i( 0, 1,-1) ); |
68 |
+ |
cellOffsets_.push_back( Vector3i(-1, 1,-1) ); |
69 |
+ |
#endif |
70 |
+ |
} |
71 |
+ |
|
72 |
+ |
|
73 |
|
/** |
74 |
|
* distributeInitialData is essentially a copy of the older fortran |
75 |
|
* SimulationSetup |
76 |
|
*/ |
54 |
– |
|
77 |
|
void ForceMatrixDecomposition::distributeInitialData() { |
78 |
|
snap_ = sman_->getCurrentSnapshot(); |
79 |
|
storageLayout_ = sman_->getStorageLayout(); |
96 |
|
|
97 |
|
#ifdef IS_MPI |
98 |
|
|
99 |
< |
AtomCommIntRow = new Communicator<Row,int>(nLocal_); |
100 |
< |
AtomCommRealRow = new Communicator<Row,RealType>(nLocal_); |
79 |
< |
AtomCommVectorRow = new Communicator<Row,Vector3d>(nLocal_); |
80 |
< |
AtomCommMatrixRow = new Communicator<Row,Mat3x3d>(nLocal_); |
81 |
< |
AtomCommPotRow = new Communicator<Row,potVec>(nLocal_); |
99 |
> |
MPI::Intracomm row = rowComm.getComm(); |
100 |
> |
MPI::Intracomm col = colComm.getComm(); |
101 |
|
|
102 |
< |
AtomCommIntColumn = new Communicator<Column,int>(nLocal_); |
103 |
< |
AtomCommRealColumn = new Communicator<Column,RealType>(nLocal_); |
104 |
< |
AtomCommVectorColumn = new Communicator<Column,Vector3d>(nLocal_); |
105 |
< |
AtomCommMatrixColumn = new Communicator<Column,Mat3x3d>(nLocal_); |
106 |
< |
AtomCommPotColumn = new Communicator<Column,potVec>(nLocal_); |
102 |
> |
AtomPlanIntRow = new Plan<int>(row, nLocal_); |
103 |
> |
AtomPlanRealRow = new Plan<RealType>(row, nLocal_); |
104 |
> |
AtomPlanVectorRow = new Plan<Vector3d>(row, nLocal_); |
105 |
> |
AtomPlanMatrixRow = new Plan<Mat3x3d>(row, nLocal_); |
106 |
> |
AtomPlanPotRow = new Plan<potVec>(row, nLocal_); |
107 |
|
|
108 |
< |
cgCommIntRow = new Communicator<Row,int>(nGroups_); |
109 |
< |
cgCommVectorRow = new Communicator<Row,Vector3d>(nGroups_); |
110 |
< |
cgCommIntColumn = new Communicator<Column,int>(nGroups_); |
111 |
< |
cgCommVectorColumn = new Communicator<Column,Vector3d>(nGroups_); |
108 |
> |
AtomPlanIntColumn = new Plan<int>(col, nLocal_); |
109 |
> |
AtomPlanRealColumn = new Plan<RealType>(col, nLocal_); |
110 |
> |
AtomPlanVectorColumn = new Plan<Vector3d>(col, nLocal_); |
111 |
> |
AtomPlanMatrixColumn = new Plan<Mat3x3d>(col, nLocal_); |
112 |
> |
AtomPlanPotColumn = new Plan<potVec>(col, nLocal_); |
113 |
|
|
114 |
< |
nAtomsInRow_ = AtomCommIntRow->getSize(); |
115 |
< |
nAtomsInCol_ = AtomCommIntColumn->getSize(); |
116 |
< |
nGroupsInRow_ = cgCommIntRow->getSize(); |
117 |
< |
nGroupsInCol_ = cgCommIntColumn->getSize(); |
114 |
> |
cgPlanIntRow = new Plan<int>(row, nGroups_); |
115 |
> |
cgPlanVectorRow = new Plan<Vector3d>(row, nGroups_); |
116 |
> |
cgPlanIntColumn = new Plan<int>(col, nGroups_); |
117 |
> |
cgPlanVectorColumn = new Plan<Vector3d>(col, nGroups_); |
118 |
|
|
119 |
+ |
nAtomsInRow_ = AtomPlanIntRow->getSize(); |
120 |
+ |
nAtomsInCol_ = AtomPlanIntColumn->getSize(); |
121 |
+ |
nGroupsInRow_ = cgPlanIntRow->getSize(); |
122 |
+ |
nGroupsInCol_ = cgPlanIntColumn->getSize(); |
123 |
+ |
|
124 |
|
// Modify the data storage objects with the correct layouts and sizes: |
125 |
|
atomRowData.resize(nAtomsInRow_); |
126 |
|
atomRowData.setStorageLayout(storageLayout_); |
134 |
|
identsRow.resize(nAtomsInRow_); |
135 |
|
identsCol.resize(nAtomsInCol_); |
136 |
|
|
137 |
< |
AtomCommIntRow->gather(idents, identsRow); |
138 |
< |
AtomCommIntColumn->gather(idents, identsCol); |
137 |
> |
AtomPlanIntRow->gather(idents, identsRow); |
138 |
> |
AtomPlanIntColumn->gather(idents, identsCol); |
139 |
|
|
140 |
|
// allocate memory for the parallel objects |
141 |
|
atypesRow.resize(nAtomsInRow_); |
151 |
|
|
152 |
|
AtomRowToGlobal.resize(nAtomsInRow_); |
153 |
|
AtomColToGlobal.resize(nAtomsInCol_); |
154 |
< |
AtomCommIntRow->gather(AtomLocalToGlobal, AtomRowToGlobal); |
155 |
< |
AtomCommIntColumn->gather(AtomLocalToGlobal, AtomColToGlobal); |
156 |
< |
|
154 |
> |
AtomPlanIntRow->gather(AtomLocalToGlobal, AtomRowToGlobal); |
155 |
> |
AtomPlanIntColumn->gather(AtomLocalToGlobal, AtomColToGlobal); |
156 |
> |
|
157 |
|
cgRowToGlobal.resize(nGroupsInRow_); |
158 |
|
cgColToGlobal.resize(nGroupsInCol_); |
159 |
< |
cgCommIntRow->gather(cgLocalToGlobal, cgRowToGlobal); |
160 |
< |
cgCommIntColumn->gather(cgLocalToGlobal, cgColToGlobal); |
159 |
> |
cgPlanIntRow->gather(cgLocalToGlobal, cgRowToGlobal); |
160 |
> |
cgPlanIntColumn->gather(cgLocalToGlobal, cgColToGlobal); |
161 |
|
|
162 |
|
massFactorsRow.resize(nAtomsInRow_); |
163 |
|
massFactorsCol.resize(nAtomsInCol_); |
164 |
< |
AtomCommRealRow->gather(massFactors, massFactorsRow); |
165 |
< |
AtomCommRealColumn->gather(massFactors, massFactorsCol); |
164 |
> |
AtomPlanRealRow->gather(massFactors, massFactorsRow); |
165 |
> |
AtomPlanRealColumn->gather(massFactors, massFactorsCol); |
166 |
|
|
167 |
|
groupListRow_.clear(); |
168 |
|
groupListRow_.resize(nGroupsInRow_); |
542 |
|
#ifdef IS_MPI |
543 |
|
|
544 |
|
// gather up the atomic positions |
545 |
< |
AtomCommVectorRow->gather(snap_->atomData.position, |
545 |
> |
AtomPlanVectorRow->gather(snap_->atomData.position, |
546 |
|
atomRowData.position); |
547 |
< |
AtomCommVectorColumn->gather(snap_->atomData.position, |
547 |
> |
AtomPlanVectorColumn->gather(snap_->atomData.position, |
548 |
|
atomColData.position); |
549 |
|
|
550 |
|
// gather up the cutoff group positions |
551 |
< |
cgCommVectorRow->gather(snap_->cgData.position, |
552 |
< |
cgRowData.position); |
553 |
< |
cgCommVectorColumn->gather(snap_->cgData.position, |
551 |
> |
|
552 |
> |
cgPlanVectorRow->gather(snap_->cgData.position, |
553 |
> |
cgRowData.position); |
554 |
> |
|
555 |
> |
cgPlanVectorColumn->gather(snap_->cgData.position, |
556 |
|
cgColData.position); |
557 |
+ |
|
558 |
|
|
559 |
|
// if needed, gather the atomic rotation matrices |
560 |
|
if (storageLayout_ & DataStorage::dslAmat) { |
561 |
< |
AtomCommMatrixRow->gather(snap_->atomData.aMat, |
561 |
> |
AtomPlanMatrixRow->gather(snap_->atomData.aMat, |
562 |
|
atomRowData.aMat); |
563 |
< |
AtomCommMatrixColumn->gather(snap_->atomData.aMat, |
563 |
> |
AtomPlanMatrixColumn->gather(snap_->atomData.aMat, |
564 |
|
atomColData.aMat); |
565 |
|
} |
566 |
|
|
567 |
|
// if needed, gather the atomic eletrostatic frames |
568 |
|
if (storageLayout_ & DataStorage::dslElectroFrame) { |
569 |
< |
AtomCommMatrixRow->gather(snap_->atomData.electroFrame, |
569 |
> |
AtomPlanMatrixRow->gather(snap_->atomData.electroFrame, |
570 |
|
atomRowData.electroFrame); |
571 |
< |
AtomCommMatrixColumn->gather(snap_->atomData.electroFrame, |
571 |
> |
AtomPlanMatrixColumn->gather(snap_->atomData.electroFrame, |
572 |
|
atomColData.electroFrame); |
573 |
|
} |
574 |
|
|
585 |
|
|
586 |
|
if (storageLayout_ & DataStorage::dslDensity) { |
587 |
|
|
588 |
< |
AtomCommRealRow->scatter(atomRowData.density, |
588 |
> |
AtomPlanRealRow->scatter(atomRowData.density, |
589 |
|
snap_->atomData.density); |
590 |
|
|
591 |
|
int n = snap_->atomData.density.size(); |
592 |
|
vector<RealType> rho_tmp(n, 0.0); |
593 |
< |
AtomCommRealColumn->scatter(atomColData.density, rho_tmp); |
593 |
> |
AtomPlanRealColumn->scatter(atomColData.density, rho_tmp); |
594 |
|
for (int i = 0; i < n; i++) |
595 |
|
snap_->atomData.density[i] += rho_tmp[i]; |
596 |
|
} |
606 |
|
storageLayout_ = sman_->getStorageLayout(); |
607 |
|
#ifdef IS_MPI |
608 |
|
if (storageLayout_ & DataStorage::dslFunctional) { |
609 |
< |
AtomCommRealRow->gather(snap_->atomData.functional, |
609 |
> |
AtomPlanRealRow->gather(snap_->atomData.functional, |
610 |
|
atomRowData.functional); |
611 |
< |
AtomCommRealColumn->gather(snap_->atomData.functional, |
611 |
> |
AtomPlanRealColumn->gather(snap_->atomData.functional, |
612 |
|
atomColData.functional); |
613 |
|
} |
614 |
|
|
615 |
|
if (storageLayout_ & DataStorage::dslFunctionalDerivative) { |
616 |
< |
AtomCommRealRow->gather(snap_->atomData.functionalDerivative, |
616 |
> |
AtomPlanRealRow->gather(snap_->atomData.functionalDerivative, |
617 |
|
atomRowData.functionalDerivative); |
618 |
< |
AtomCommRealColumn->gather(snap_->atomData.functionalDerivative, |
618 |
> |
AtomPlanRealColumn->gather(snap_->atomData.functionalDerivative, |
619 |
|
atomColData.functionalDerivative); |
620 |
|
} |
621 |
|
#endif |
629 |
|
int n = snap_->atomData.force.size(); |
630 |
|
vector<Vector3d> frc_tmp(n, V3Zero); |
631 |
|
|
632 |
< |
AtomCommVectorRow->scatter(atomRowData.force, frc_tmp); |
632 |
> |
AtomPlanVectorRow->scatter(atomRowData.force, frc_tmp); |
633 |
|
for (int i = 0; i < n; i++) { |
634 |
|
snap_->atomData.force[i] += frc_tmp[i]; |
635 |
|
frc_tmp[i] = 0.0; |
636 |
|
} |
637 |
|
|
638 |
< |
AtomCommVectorColumn->scatter(atomColData.force, frc_tmp); |
639 |
< |
for (int i = 0; i < n; i++) |
638 |
> |
AtomPlanVectorColumn->scatter(atomColData.force, frc_tmp); |
639 |
> |
for (int i = 0; i < n; i++) { |
640 |
|
snap_->atomData.force[i] += frc_tmp[i]; |
641 |
+ |
} |
642 |
|
|
643 |
|
if (storageLayout_ & DataStorage::dslTorque) { |
644 |
|
|
645 |
|
int nt = snap_->atomData.torque.size(); |
646 |
|
vector<Vector3d> trq_tmp(nt, V3Zero); |
647 |
|
|
648 |
< |
AtomCommVectorRow->scatter(atomRowData.torque, trq_tmp); |
648 |
> |
AtomPlanVectorRow->scatter(atomRowData.torque, trq_tmp); |
649 |
|
for (int i = 0; i < nt; i++) { |
650 |
|
snap_->atomData.torque[i] += trq_tmp[i]; |
651 |
|
trq_tmp[i] = 0.0; |
652 |
|
} |
653 |
|
|
654 |
< |
AtomCommVectorColumn->scatter(atomColData.torque, trq_tmp); |
654 |
> |
AtomPlanVectorColumn->scatter(atomColData.torque, trq_tmp); |
655 |
|
for (int i = 0; i < nt; i++) |
656 |
|
snap_->atomData.torque[i] += trq_tmp[i]; |
657 |
|
} |
661 |
|
int ns = snap_->atomData.skippedCharge.size(); |
662 |
|
vector<RealType> skch_tmp(ns, 0.0); |
663 |
|
|
664 |
< |
AtomCommRealRow->scatter(atomRowData.skippedCharge, skch_tmp); |
664 |
> |
AtomPlanRealRow->scatter(atomRowData.skippedCharge, skch_tmp); |
665 |
|
for (int i = 0; i < ns; i++) { |
666 |
|
snap_->atomData.skippedCharge[i] += skch_tmp[i]; |
667 |
|
skch_tmp[i] = 0.0; |
668 |
|
} |
669 |
|
|
670 |
< |
AtomCommRealColumn->scatter(atomColData.skippedCharge, skch_tmp); |
670 |
> |
AtomPlanRealColumn->scatter(atomColData.skippedCharge, skch_tmp); |
671 |
|
for (int i = 0; i < ns; i++) |
672 |
|
snap_->atomData.skippedCharge[i] += skch_tmp[i]; |
673 |
|
} |
679 |
|
|
680 |
|
// scatter/gather pot_row into the members of my column |
681 |
|
|
682 |
< |
AtomCommPotRow->scatter(pot_row, pot_temp); |
682 |
> |
AtomPlanPotRow->scatter(pot_row, pot_temp); |
683 |
|
|
684 |
|
for (int ii = 0; ii < pot_temp.size(); ii++ ) |
685 |
|
pairwisePot += pot_temp[ii]; |
687 |
|
fill(pot_temp.begin(), pot_temp.end(), |
688 |
|
Vector<RealType, N_INTERACTION_FAMILIES> (0.0)); |
689 |
|
|
690 |
< |
AtomCommPotColumn->scatter(pot_col, pot_temp); |
690 |
> |
AtomPlanPotColumn->scatter(pot_col, pot_temp); |
691 |
|
|
692 |
|
for (int ii = 0; ii < pot_temp.size(); ii++ ) |
693 |
|
pairwisePot += pot_temp[ii]; |
694 |
+ |
|
695 |
+ |
for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) { |
696 |
+ |
RealType ploc1 = pairwisePot[ii]; |
697 |
+ |
RealType ploc2 = 0.0; |
698 |
+ |
MPI::COMM_WORLD.Allreduce(&ploc1, &ploc2, 1, MPI::REALTYPE, MPI::SUM); |
699 |
+ |
pairwisePot[ii] = ploc2; |
700 |
+ |
} |
701 |
+ |
|
702 |
|
#endif |
703 |
|
|
704 |
|
} |
811 |
|
*/ |
812 |
|
bool ForceMatrixDecomposition::skipAtomPair(int atom1, int atom2) { |
813 |
|
int unique_id_1, unique_id_2; |
814 |
< |
|
814 |
> |
|
815 |
|
#ifdef IS_MPI |
816 |
|
// in MPI, we have to look up the unique IDs for each atom |
817 |
|
unique_id_1 = AtomRowToGlobal[atom1]; |
841 |
|
*/ |
842 |
|
bool ForceMatrixDecomposition::excludeAtomPair(int atom1, int atom2) { |
843 |
|
int unique_id_2; |
807 |
– |
|
844 |
|
#ifdef IS_MPI |
845 |
|
// in MPI, we have to look up the unique IDs for the row atom. |
846 |
|
unique_id_2 = AtomColToGlobal[atom2]; |
1067 |
|
// add this cutoff group to the list of groups in this cell; |
1068 |
|
cellListRow_[cellIndex].push_back(i); |
1069 |
|
} |
1034 |
– |
|
1070 |
|
for (int i = 0; i < nGroupsInCol_; i++) { |
1071 |
|
rs = cgColData.position[i]; |
1072 |
|
|
1111 |
|
whichCell.z() = nCells_.z() * scaled.z(); |
1112 |
|
|
1113 |
|
// find single index of this cell: |
1114 |
< |
cellIndex = Vlinear(whichCell, nCells_); |
1114 |
> |
cellIndex = Vlinear(whichCell, nCells_); |
1115 |
|
|
1116 |
|
// add this cutoff group to the list of groups in this cell; |
1117 |
|
cellList_[cellIndex].push_back(i); |
1155 |
|
for (vector<int>::iterator j2 = cellListCol_[m2].begin(); |
1156 |
|
j2 != cellListCol_[m2].end(); ++j2) { |
1157 |
|
|
1158 |
< |
// Always do this if we're in different cells or if |
1159 |
< |
// we're in the same cell and the global index of the |
1160 |
< |
// j2 cutoff group is less than the j1 cutoff group |
1161 |
< |
|
1162 |
< |
if (m2 != m1 || cgColToGlobal[(*j2)] < cgRowToGlobal[(*j1)]) { |
1163 |
< |
dr = cgColData.position[(*j2)] - cgRowData.position[(*j1)]; |
1164 |
< |
snap_->wrapVector(dr); |
1165 |
< |
cuts = getGroupCutoffs( (*j1), (*j2) ); |
1131 |
< |
if (dr.lengthSquare() < cuts.third) { |
1132 |
< |
neighborList.push_back(make_pair((*j1), (*j2))); |
1133 |
< |
} |
1134 |
< |
} |
1158 |
> |
// In parallel, we need to visit *all* pairs of row & |
1159 |
> |
// column indicies and will truncate later on. |
1160 |
> |
dr = cgColData.position[(*j2)] - cgRowData.position[(*j1)]; |
1161 |
> |
snap_->wrapVector(dr); |
1162 |
> |
cuts = getGroupCutoffs( (*j1), (*j2) ); |
1163 |
> |
if (dr.lengthSquare() < cuts.third) { |
1164 |
> |
neighborList.push_back(make_pair((*j1), (*j2))); |
1165 |
> |
} |
1166 |
|
} |
1167 |
|
} |
1168 |
|
#else |