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; |
726 |
< |
|
727 |
< |
int nproc = MPI::COMM_WORLD.Get_size(); |
728 |
< |
counts.resize(nproc); |
729 |
< |
vector<int> disps; |
730 |
< |
disps.resize(nproc); |
731 |
< |
|
732 |
< |
// now spray out the foundTypes to all the other processors: |
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 |
> |
// 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 |
> |
// 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 |
|
|