vtf-logo

shells/parallel/PointSetPartitioner.h

Go to the documentation of this file.
00001 // -*- C++ -*- 
00002 //
00003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00004 //
00005 //                                   Fehmi Cirak
00006 //                        California Institute of Technology
00007 //                           (C) 2004 All Rights Reserved
00008 //
00009 // <LicenseText>
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 //  template<typename OutPointIter, typename OutMapIter>
00044 //  void partitionPointSet(OutPointIter mypoints, OutMapIter localGlobalNode); 
00045  
00046 private:        
00047 //    template<typename OutMapIter>
00048 //  localGlobaPointID(OutIter _localGlobalNode);
00049 
00050 private:    
00051     PointSetPartitioner(const PointSetPartitioner &);
00052     const PointSetPartitioner & operator=(const PointSetPartitioner &);
00053 
00054 private: 
00055     PointSetCont      *_pointSet;        // necessary for RCB
00056     Zoltan_Struct     *_zoltan;          // necessary 
00057                                          // for repartitioning
00058 };
00059 
00060 
00061 
00062 // templated methods
00063 template <typename InIter>
00064 parallel::PointSetPartitioner::PointSetPartitioner(const MPI_Comm& comm, 
00065                                                    const InIter& itb, 
00066                                                    const InIter& ite)    
00067 {    
00068     // initialize zoltan 
00069     _zoltan = parallel::zoltanIfaceInit(comm);
00070     assert(_zoltan != NULL);
00071         
00072     // assign all elements points to processor 0
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;   // 3 coordinates
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     // partition mesh with zoltan and return elements assigned to my processor
00097     // TODO: In the case of dynamic repartitioning it is necessary to update 
00098     // _pointSet->_coordinate[]
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     // global point ID's on this processor
00106     std::copy(newPointSet.begin(), newPointSet.end(), myPoints);
00107 
00108     return;
00109 }
00110 
00111 #endif
00112 

Generated on Fri Aug 24 13:00:24 2007 for SFC Thin-Shell Finite Element Solver by  doxygen 1.4.7