ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/parallel/Communicator.hpp
(Generate patch)

Comparing branches/development/src/parallel/Communicator.hpp (file contents):
Revision 1549 by gezelter, Wed Apr 27 18:38:15 2011 UTC vs.
Revision 1551 by gezelter, Thu Apr 28 18:38:21 2011 UTC

# Line 53 | Line 53
53   #include <mpi.h>
54   #include "math/SquareMatrix3.hpp"
55  
56 + using namespace std;
57   namespace OpenMD{
58    
59   #ifdef IS_MPI
# Line 63 | Line 64 | namespace OpenMD{
64      Column = 2
65    };
66      
67 <  template<typename T>
68 <  struct MPITraits
69 <  {
70 <    static const MPI::Datatype datatype;
71 <    static const int dim;
67 >  template<class T>
68 >  class MPITraits {
69 >  public:
70 >    static MPI::Datatype Type();
71 >    static int Length() { return 1; };
72    };
73    
74 <  template<> const MPI::Datatype MPITraits<int>::datatype = MPI_INT;
75 <  template<> const int MPITraits<int>::dim = 1;
76 <  template<> const MPI::Datatype MPITraits<RealType>::datatype = MPI_REALTYPE;
77 <  template<> const int MPITraits<RealType>::dim = 1;
78 <  template<> const MPI::Datatype MPITraits<Vector3d>::datatype = MPI_REALTYPE;
79 <  template<> const int MPITraits<Vector3d>::dim = 3;
80 <  template<> const MPI::Datatype MPITraits<Mat3x3d>::datatype = MPI_REALTYPE;
81 <  template<> const int MPITraits<Mat3x3d>::dim = 9;
74 >  template<> inline MPI::Datatype MPITraits<int>::Type() { return MPI_INT; }
75 >  template<> inline MPI::Datatype MPITraits<RealType>::Type() { return MPI_REALTYPE; }
76 >
77 >  template<class T, unsigned int Dim>
78 >  class MPITraits< Vector<T, Dim> > {
79 >  public:
80 >    static MPI::Datatype Type() { return MPITraits<T>::Type(); }
81 >    static int Length() {return Dim;}
82 >  };
83 >
84 >  template<class T>
85 >  class MPITraits< Vector3<T> > {
86 >  public:
87 >    static MPI::Datatype Type() { return MPITraits<T>::Type(); }
88 >    static int Length() {return 3;}
89 >  };
90 >
91 >  template<class T, unsigned int Row, unsigned int Col>
92 >  class MPITraits< RectMatrix<T, Row, Col> > {
93 >  public:
94 >    static MPI::Datatype Type() { return MPITraits<T>::Type(); }
95 >    static int Length() {return Row * Col;}
96 >  };
97 >
98 >  template<class T>
99 >  class MPITraits< SquareMatrix3<T> > {
100 >  public:
101 >    static MPI::Datatype Type() { return MPITraits<T>::Type(); }
102 >    static int Length() {return 9;}
103 >  };
104    
105 +  
106    template<communicatorType D, typename T>
107    class Communicator {
108    public:
# Line 115 | Line 139 | namespace OpenMD{
139        counts.reserve(nCommProcs);
140        displacements.reserve(nCommProcs);
141  
142 <      planSize_ = MPITraits<T>::dim * nObjects;
142 >      planSize_ = MPITraits<T>::Length() * nObjects;
143  
144        myComm.Allgather(&planSize_, 1, MPI::INT, &counts[0], 1, MPI::INT);
145  
# Line 131 | Line 155 | namespace OpenMD{
155        }
156      }
157  
158 <
159 <    void gather(std::vector<T>& v1, std::vector<T>& v2) {
158 >    
159 >    void gather(vector<T>& v1, vector<T>& v2) {
160        
161        myComm.Allgatherv(&v1[0],
162                          planSize_,
163 <                        MPITraits<T>::datatype,
163 >                        MPITraits<T>::Type(),
164                          &v2[0],
165                          &counts[0],
166                          &displacements[0],
167 <                        MPITraits<T>::datatype);      
167 >                        MPITraits<T>::Type());      
168      }
145
169      
170 <  
171 <    void scatter(std::vector<T>& v1, std::vector<T>& v2) {
172 <
170 >    
171 >    
172 >    void scatter(vector<T>& v1, vector<T>& v2) {
173 >      
174        myComm.Reduce_scatter(&v1[0], &v2[0], &counts[0],
175 <                            MPITraits<T>::datatype, MPI::SUM);
175 >                            MPITraits<T>::Type(), MPI::SUM);
176      }
177 <
177 >    
178      int getSize() {
179        return size_;
180      }
# Line 160 | Line 184 | namespace OpenMD{
184      int rowIndex_;
185      int columnIndex_;
186      int size_;
187 <    std::vector<int> counts;
188 <    std::vector<int> displacements;
187 >    vector<int> counts;
188 >    vector<int> displacements;
189      MPI::Intracomm myComm;
190    };
191  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines