00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef ZOLTANIFACE_H
00014 #define ZOLTANIFACE_H
00015 #include <set>
00016 #include <vector>
00017 #include <algorithm>
00018
00019 #include "zoltan.h"
00020 #include "mpi.h"
00021
00022
00023
00024
00025 namespace parallel {
00026 typedef struct PointSetContS {
00027 std::vector<double> _coordinate;
00028 std::vector<int> _globalID;
00029 } PointSetCont;
00030 }
00031
00032
00033
00034 namespace parallel{
00035
00036 struct Zoltan_Struct* zoltanIfaceInit(const MPI_Comm& comm);
00037
00038
00039 template<typename Iterator>
00040 bool zoltanIfacePartition (struct Zoltan_Struct *lb,
00041 PointSetCont *pointSet,
00042 Iterator insElements);
00043
00044
00045 void zoltanFinalize(struct Zoltan_Struct *lb);
00046
00047 extern "C" {
00048
00049 int callBackNumElems(void *data, int *ierr);
00050 void callBackElemList(void *data, int num_gid_entries, int num_lid_entries,
00051 ZOLTAN_ID_PTR global_id, ZOLTAN_ID_PTR local_id,
00052 int wgt_dim, float *obj_wgts, int *ierr);
00053 void callBackCoords(void *data, int num_gid_entries, int num_lid_entries,
00054 ZOLTAN_ID_PTR global_id,ZOLTAN_ID_PTR local_id,
00055 double *geom_vec, int *ierr);
00056 int callBackDimension(void *data, int *ierr);
00057
00058 typedef void (*zoltan_cft)();
00059 }
00060 }
00061
00062
00063
00064
00065 template<typename Iterator>
00066 bool parallel::zoltanIfacePartition (struct Zoltan_Struct *lb,
00067 PointSetCont *pointSet,
00068 Iterator insElements)
00069 {
00070
00071 Zoltan_Set_Fn(lb, ZOLTAN_NUM_GEOM_FN_TYPE,
00072 reinterpret_cast<zoltan_cft>(callBackDimension), pointSet);
00073 Zoltan_Set_Fn(lb, ZOLTAN_GEOM_FN_TYPE,
00074 reinterpret_cast<zoltan_cft>(callBackCoords), pointSet);
00075 Zoltan_Set_Fn(lb, ZOLTAN_NUM_OBJ_FN_TYPE,
00076 reinterpret_cast<zoltan_cft>(callBackNumElems), pointSet);
00077 Zoltan_Set_Fn(lb, ZOLTAN_OBJ_LIST_FN_TYPE,
00078 reinterpret_cast<zoltan_cft>(callBackElemList), pointSet);
00079
00080
00081 ZOLTAN_ID_PTR imp_global_ids, exp_global_ids, imp_local_ids, exp_local_ids;
00082 int changes, num_imp, num_exp, *imp_procs, *exp_procs;
00083 int num_gid_entries, num_lid_entries;
00084 Zoltan_LB_Balance(lb, &changes, &num_gid_entries, &num_lid_entries,
00085 &num_imp, &imp_global_ids, &imp_local_ids, &imp_procs,
00086 &num_exp, &exp_global_ids, &exp_local_ids, &exp_procs);
00087
00088
00089 if (!changes) {
00090 std::copy(pointSet->_globalID.begin(), pointSet->_globalID.end(),
00091 insElements);
00092 return false;
00093 }
00094
00095
00096
00097 std::vector<int> current(pointSet->_globalID);
00098 std::sort(current.begin(), current.end());
00099
00100
00101 std::vector<int> exported(exp_global_ids, exp_global_ids+num_exp);
00102 std::sort(exported.begin(), exported.end());
00103
00104 std::set<int> tmpSet;
00105 std::insert_iterator<std::set<int> > insTmpSet(tmpSet, tmpSet.begin());
00106 std::set_difference(current.begin(), current.end(),
00107 exported.begin(), exported.end(), insTmpSet );
00108
00109 std::vector<int> imported(imp_global_ids, imp_global_ids+num_imp);
00110 std::sort(imported.begin(), imported.end());
00111
00112 std::set_union(tmpSet.begin(), tmpSet.end(),
00113 imported.begin(), imported.end(), insElements);
00114
00115 return true;
00116 }
00117
00118 #endif