| 60 |
|
#include "io/ForceFieldOptions.hpp" |
| 61 |
|
#include "UseTheForce/ForceField.hpp" |
| 62 |
|
#include "nonbonded/SwitchingFunction.hpp" |
| 63 |
+ |
#ifdef IS_MPI |
| 64 |
+ |
#include <mpi.h> |
| 65 |
+ |
#endif |
| 66 |
|
|
| 67 |
|
using namespace std; |
| 68 |
|
namespace OpenMD { |
| 697 |
|
Atom* atom; |
| 698 |
|
set<AtomType*> atomTypes; |
| 699 |
|
|
| 700 |
< |
for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { |
| 701 |
< |
for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
| 700 |
> |
for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { |
| 701 |
> |
for(atom = mol->beginAtom(ai); atom != NULL; |
| 702 |
> |
atom = mol->nextAtom(ai)) { |
| 703 |
|
atomTypes.insert(atom->getAtomType()); |
| 704 |
|
} |
| 705 |
|
} |
| 706 |
< |
|
| 706 |
> |
|
| 707 |
|
#ifdef IS_MPI |
| 708 |
|
|
| 709 |
|
// loop over the found atom types on this processor, and add their |
| 710 |
|
// numerical idents to a vector: |
| 711 |
< |
|
| 711 |
> |
|
| 712 |
|
vector<int> foundTypes; |
| 713 |
|
set<AtomType*>::iterator i; |
| 714 |
|
for (i = atomTypes.begin(); i != atomTypes.end(); ++i) |
| 717 |
|
// count_local holds the number of found types on this processor |
| 718 |
|
int count_local = foundTypes.size(); |
| 719 |
|
|
| 720 |
< |
// count holds the total number of found types on all processors |
| 717 |
< |
// (some will be redundant with the ones found locally): |
| 718 |
< |
int count; |
| 719 |
< |
MPI::COMM_WORLD.Allreduce(&count_local, &count, 1, MPI::INT, MPI::SUM); |
| 720 |
> |
int nproc = MPI::COMM_WORLD.Get_size(); |
| 721 |
|
|
| 722 |
< |
// create a vector to hold the globally found types, and resize it: |
| 723 |
< |
vector<int> ftGlobal; |
| 724 |
< |
ftGlobal.resize(count); |
| 725 |
< |
vector<int> counts; |
| 722 |
> |
// we need arrays to hold the counts and displacement vectors for |
| 723 |
> |
// all processors |
| 724 |
> |
vector<int> counts(nproc, 0); |
| 725 |
> |
vector<int> disps(nproc, 0); |
| 726 |
|
|
| 727 |
< |
int nproc = MPI::COMM_WORLD.Get_size(); |
| 728 |
< |
counts.resize(nproc); |
| 729 |
< |
vector<int> disps; |
| 730 |
< |
disps.resize(nproc); |
| 727 |
> |
// fill the counts array |
| 728 |
> |
MPI::COMM_WORLD.Allgather(&count_local, 1, MPI::INT, &counts[0], |
| 729 |
> |
1, MPI::INT); |
| 730 |
> |
|
| 731 |
> |
// use the processor counts to compute the displacement array |
| 732 |
> |
disps[0] = 0; |
| 733 |
> |
int totalCount = counts[0]; |
| 734 |
> |
for (int iproc = 1; iproc < nproc; iproc++) { |
| 735 |
> |
disps[iproc] = disps[iproc-1] + counts[iproc-1]; |
| 736 |
> |
totalCount += counts[iproc]; |
| 737 |
> |
} |
| 738 |
|
|
| 739 |
< |
// now spray out the foundTypes to all the other processors: |
| 739 |
> |
// we need a (possibly redundant) set of all found types: |
| 740 |
> |
vector<int> ftGlobal(totalCount); |
| 741 |
|
|
| 742 |
+ |
// now spray out the foundTypes to all the other processors: |
| 743 |
|
MPI::COMM_WORLD.Allgatherv(&foundTypes[0], count_local, MPI::INT, |
| 744 |
< |
&ftGlobal[0], &counts[0], &disps[0], MPI::INT); |
| 744 |
> |
&ftGlobal[0], &counts[0], &disps[0], |
| 745 |
> |
MPI::INT); |
| 746 |
|
|
| 747 |
+ |
vector<int>::iterator j; |
| 748 |
+ |
|
| 749 |
|
// foundIdents is a stl set, so inserting an already found ident |
| 750 |
|
// will have no effect. |
| 751 |
|
set<int> foundIdents; |
| 752 |
< |
vector<int>::iterator j; |
| 752 |
> |
|
| 753 |
|
for (j = ftGlobal.begin(); j != ftGlobal.end(); ++j) |
| 754 |
|
foundIdents.insert((*j)); |
| 755 |
|
|
| 756 |
|
// now iterate over the foundIdents and get the actual atom types |
| 757 |
|
// that correspond to these: |
| 758 |
|
set<int>::iterator it; |
| 759 |
< |
for (it = foundIdents.begin(); it != foundIdents.end(); ++it) |
| 759 |
> |
for (it = foundIdents.begin(); it != foundIdents.end(); ++it) |
| 760 |
|
atomTypes.insert( forceField_->getAtomType((*it)) ); |
| 761 |
|
|
| 762 |
|
#endif |
| 763 |
< |
|
| 763 |
> |
|
| 764 |
|
return atomTypes; |
| 765 |
|
} |
| 766 |
|
|
| 772 |
|
if ( simParams_->getAccumulateBoxDipole() ) { |
| 773 |
|
calcBoxDipole_ = true; |
| 774 |
|
} |
| 775 |
< |
|
| 775 |
> |
|
| 776 |
|
set<AtomType*>::iterator i; |
| 777 |
|
set<AtomType*> atomTypes; |
| 778 |
|
atomTypes = getSimulatedAtomTypes(); |
| 785 |
|
usesMetallic |= (*i)->isMetal(); |
| 786 |
|
usesDirectional |= (*i)->isDirectional(); |
| 787 |
|
} |
| 788 |
< |
|
| 788 |
> |
|
| 789 |
|
#ifdef IS_MPI |
| 790 |
|
int temp; |
| 791 |
|
temp = usesDirectional; |
| 792 |
|
MPI_Allreduce(&temp, &usesDirectionalAtoms_, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
| 793 |
< |
|
| 793 |
> |
|
| 794 |
|
temp = usesMetallic; |
| 795 |
|
MPI_Allreduce(&temp, &usesMetallicAtoms_, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
| 796 |
< |
|
| 796 |
> |
|
| 797 |
|
temp = usesElectrostatic; |
| 798 |
|
MPI_Allreduce(&temp, &usesElectrostaticAtoms_, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
| 799 |
+ |
#else |
| 800 |
+ |
|
| 801 |
+ |
usesDirectionalAtoms_ = usesDirectional; |
| 802 |
+ |
usesMetallicAtoms_ = usesMetallic; |
| 803 |
+ |
usesElectrostaticAtoms_ = usesElectrostatic; |
| 804 |
+ |
|
| 805 |
|
#endif |
| 806 |
+ |
|
| 807 |
+ |
requiresPrepair_ = usesMetallicAtoms_ ? true : false; |
| 808 |
+ |
requiresSkipCorrection_ = usesElectrostaticAtoms_ ? true : false; |
| 809 |
+ |
requiresSelfCorrection_ = usesElectrostaticAtoms_ ? true : false; |
| 810 |
|
} |
| 811 |
|
|
| 812 |
|
|