00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef POINTSETPARTITIONER_H
00015 #define POINTSETPARTITIONER_H
00016
00017 #include "ZoltanIface.h"
00018 #include <mpi.h>
00019
00020 #include <vector>
00021 #include <set>
00022 #include <cassert>
00023 #include <cstdlib>
00024
00025
00026 namespace parallel {
00027 class PointSetPartitioner;
00028 }
00029
00030 struct Zoltan_Struct;
00031
00032
00033
00034 class parallel::PointSetPartitioner {
00035 public:
00036 template <typename InIter>
00037 PointSetPartitioner(const MPI_Comm& comm, const InIter& itb, const InIter& ite);
00038 ~PointSetPartitioner();
00039
00040 template<typename OutPointIter>
00041 void partitionPointIDs(OutPointIter mypoints) const;
00042
00043
00044
00045
00046 private:
00047
00048
00049
00050 private:
00051 PointSetPartitioner(const PointSetPartitioner &);
00052 const PointSetPartitioner & operator=(const PointSetPartitioner &);
00053
00054 private:
00055 PointSetCont *_pointSet;
00056 Zoltan_Struct *_zoltan;
00057
00058 };
00059
00060
00061
00062
00063 template <typename InIter>
00064 parallel::PointSetPartitioner::PointSetPartitioner(const MPI_Comm& comm,
00065 const InIter& itb,
00066 const InIter& ite)
00067 {
00068
00069 _zoltan = parallel::zoltanIfaceInit(comm);
00070 assert(_zoltan != NULL);
00071
00072
00073 _pointSet = new parallel::PointSetCont;
00074 assert(_pointSet != NULL);
00075
00076 int myrank;
00077 MPI_Comm_rank(comm, &myrank);
00078
00079 assert(_pointSet->_coordinate.size()==0);
00080 assert(ite-itb>0);
00081
00082 if (!myrank) {
00083 _pointSet->_coordinate.reserve(ite-itb);
00084 std::copy(itb, ite, std::back_inserter(_pointSet->_coordinate));
00085 _pointSet->_globalID.reserve(ite-itb);
00086 int numElements = (ite-itb)/3;
00087 for(int i=0; i<numElements; ++i) _pointSet->_globalID.push_back(i);
00088 }
00089 }
00090
00091
00092
00093 template<typename OutPointIter>
00094 void parallel::PointSetPartitioner::partitionPointIDs(OutPointIter myPoints) const
00095 {
00096
00097
00098
00099
00100 std::set<int> newPointSet;
00101 std::insert_iterator< std::set<int> >
00102 insElements(newPointSet, newPointSet.begin());
00103 zoltanIfacePartition(_zoltan, _pointSet, insElements);
00104
00105
00106 std::copy(newPointSet.begin(), newPointSet.end(), myPoints);
00107
00108 return;
00109 }
00110
00111 #endif
00112