20 #define GRAPH_OUTPUT 0
38 virtual void setValue(
const F Value);
50 virtual std::ostream&
info(std::ostream& os)
const;
62 <<
"," << this->Neighbours_
63 <<
"," << this->Weight_
64 <<
"," << this->Domain_ <<
")" ;
70 return Value.
info(os);
84 virtual void addVertex(
const F Value,
const int Weight = 1);
85 virtual void addEdge(
const F Value1,
const F Value2);
91 virtual Sequence<int> GetMetisSubdomains(
const int NbParts = 2)
const;
98 virtual std::ostream&
info(std::ostream& os)
const;
108 = this->Vertexes_.begin(); i != this->Vertexes_.end(); ++i, ++n)
109 os <<
"Point " << n <<
"(value " << i->getValue() <<
") belongs to graph " << i->getDomain() << std::endl;
117 return Value.
info(os);
123 this->Value_ = Value;
129 this->Weight_ = Weight;
135 this->Weight_ += Weight;
141 this->Neighbours_ = Neighbours;
147 if ( this->Neighbours_.exist(Value) )
149 this->Neighbours_.push_back(Value);
155 if ( this->Neighbours_.exist(Value) )
157 this->Neighbours_.push_back(Value);
158 this->Weight_ += Weight;
164 this->Domain_ = Domain;
170 this->Neighbours_.clear();
182 return this->Weight_;
188 return this->Neighbours_;
194 return this->Domain_;
208 = this->Vertexes_.begin(); i != this->Vertexes_.end(); ++i)
209 if (i->getValue() == Value)
213 this->Vertexes_.push_back(VValue);
227 bool Value1NotDone =
true, Value2NotDone =
true;
229 = this->Vertexes_.begin();
230 i != this->Vertexes_.end() && (Value1NotDone || Value2NotDone); ++i)
232 if (i->getValue() == Value1)
234 Value1NotDone =
false;
235 i->addNeighbour(Value2);
237 if (i->getValue() == Value2)
239 Value2NotDone =
false;
240 i->addNeighbour(Value1);
258 bool Value1NotDone =
true, Value2NotDone =
true;
260 = this->Vertexes_.begin();
261 i != this->Vertexes_.end() && (Value1NotDone || Value2NotDone); ++i)
263 if (i->getValue() == Value1)
265 Value1NotDone =
false;
266 i->addWeightedNeighbour(Value2, Weight);
268 if (i->getValue() == Value2)
270 Value2NotDone =
false;
271 i->addWeightedNeighbour(Value1, Weight);
283 = this->Vertexes_.begin(); i != this->Vertexes_.end(); ++i)
285 Result = Result + i->getNeighbours();
296 Cumuled.push_back(0);
298 TempCNeighbours.clear();
302 = this->Vertexes_.begin(); i != this->Vertexes_.end(); ++i, ++n)
304 TempCNeighbours = TempCNeighbours + i->getNeighbours();
305 cml += i->getNeighbours().size();
306 Cumuled.push_back(cml);
308 Weights.push_back(i->getWeight());
313 for(
typename std::vector<F>::const_iterator i
314 = TempCNeighbours.begin(); i != TempCNeighbours.end(); ++i)
319 typename std::vector<GraphVertex<F> >::const_iterator j = this->Vertexes_.begin();
320 for(; (j != this->Vertexes_.end()) && (*i != j->getValue()); ++j,
322 CNeighbours.push_back(n);
325 TempCNeighbours.clear();
335 Subdomains.resize(this->Vertexes_.size());
339 this->GetCompressedFormat(Cumuled, CNeighbours, Weights);
341 idx_t nvtxs = idx_t(Cumuled.size()-1);
343 idx_t *xadj =
new idx_t[Cumuled.size()];
346 for(
typename std::vector<int>::const_iterator i
347 = Cumuled.begin(); i != Cumuled.end(); ++i, ++n)
352 idx_t * vsize = NULL;
354 idx_t * adjncy =
new idx_t[CNeighbours.size()];
356 for(
typename std::vector<int>::const_iterator i
357 = CNeighbours.begin(); i != CNeighbours.end(); ++i, ++n)
362 idx_t * vwgt =
new idx_t[Weights.size()];
364 for(
typename std::vector<int>::const_iterator i
365 = Weights.begin(); i != Weights.end(); ++i, ++n)
370 idx_t *adjwgt = NULL;
371 idx_t nparts = idx_t(NbParts);
372 real_t *tpwgts = NULL, *ubvec= NULL;
375 int vertex_size = this->Vertexes_.size();
376 idx_t* part =
new idx_t[vertex_size];
378 int result = METIS_PartGraphKway( &nvtxs, &ncon, xadj, adjncy, vwgt,
379 vsize, adjwgt, &nparts, tpwgts,
380 ubvec, options, &objval, part);
382 conceptsAssert3(result==METIS_OK, Assertion(),
"Partition graph failed");
384 int mpisize; MPI_Comm_size(MPI_COMM_WORLD, &mpisize);
385 int mpirank; MPI_Comm_rank(MPI_COMM_WORLD, &mpirank);
386 DEBUGL(
GRAPH_OUTPUT,
"Converting vector of size " << vertex_size <<
" on process " << mpirank);
387 int* mpipart =
new int[vertex_size];
388 for(n=0 ; n < vertex_size ; n++)
390 mpipart[n] = int(part[n]);
395 MPI_Barrier(MPI_COMM_WORLD);
396 MPI_Bcast(mpipart, vertex_size, MPI_INT, 0, MPI_COMM_WORLD);
397 MPI_Barrier(MPI_COMM_WORLD);
403 for(
typename std::vector<int>::iterator i
404 = Subdomains.begin(); i!= Subdomains.end(); ++i, ++n)
433 assert(Subdomains.size() == this->Vertexes_.size());
434 typename std::vector<GraphVertex<F> >::iterator iv =
435 this->Vertexes_.begin();
436 typename std::vector<int>::const_iterator i = Subdomains.begin();
437 for( ; i!=Subdomains.end(); ++iv, ++i)
451 Subdomains.resize(this->Vertexes_.size());
452 for(
typename std::vector<int>::iterator i
453 = Subdomains.begin(); i!= Subdomains.end(); ++i)
455 this->SetSubdomains(Subdomains);
461 this->SetSubdomains(this->GetMetisSubdomains(NbParts));
467 Subdomains.resize(this->Vertexes_.size());
469 for(
typename std::vector<int>::iterator i
470 = Subdomains.begin(); i!= Subdomains.end(); ++i, ++n)
471 *i = (n * NbParts) / this->Vertexes_.size();
472 this->SetSubdomains(Subdomains);
482 ListVertexes.clear();
483 typename std::vector<GraphVertex<F> >::const_iterator iv =
484 this->Vertexes_.begin();
485 for ( ; iv != this->Vertexes_.end(); ++iv)
487 if ( iv->getDomain() == Part )
489 ListVertexes.push_back(iv->getValue());
499 ListVertexes.clear();
500 typename std::vector<GraphVertex<F> >::const_iterator iv =
501 this->Vertexes_.begin();
502 for ( ; iv != this->Vertexes_.end(); ++iv)
504 if ( iv->getDomain() == Part )
505 ListVertexes.push_back(
true);
507 ListVertexes.push_back(
false);