188 MPI_Comm_rank(mpicomm_, &myrank);
189 MPI_Comm_size(mpicomm_, &commsize);
194 std::vector<IntersectionData> dummy(1);
195 intersections_.swap(dummy);
198 std::vector<Dune::FieldVector<ctype, dimworld> > patch0coords;
199 std::vector<unsigned int> patch0entities;
200 std::vector<Dune::GeometryType> patch0types;
201 std::vector<Dune::FieldVector<ctype,dimworld> > patch1coords;
202 std::vector<unsigned int> patch1entities;
203 std::vector<Dune::GeometryType> patch1types;
211 extractGrid(*patch0_, patch0coords, patch0entities, patch0types);
212 extractGrid(*patch1_, patch1coords, patch1entities, patch1types);
214 std::cout <<
">>>> rank " << myrank <<
" coords: "
215 << patch0coords.size() <<
" and " << patch1coords.size() << std::endl;
216 std::cout <<
">>>> rank " << myrank <<
" entities: "
217 << patch0entities.size() <<
" and " << patch1entities.size() << std::endl;
218 std::cout <<
">>>> rank " << myrank <<
" types: "
219 << patch0types.size() <<
" and " << patch1types.size() << std::endl;
222 const char prefix[] =
"GridGlue::Builder::build() : ";
223 char patch0surf[256];
224 sprintf(patch0surf,
"/tmp/vtk-patch0-test-%i", myrank);
225 char patch1surf[256];
226 sprintf(patch1surf,
"/tmp/vtk-patch1-test-%i", myrank);
243 patch0_is_.beginResize();
244 patch1_is_.beginResize();
249 if (patch0entities.size() > 0 && patch1entities.size() > 0)
250 mergePatches(patch0coords, patch0entities, patch0types, myrank,
251 patch1coords, patch1entities, patch1types, myrank);
253#ifdef CALL_MERGER_TWICE
254 if (patch0entities.size() > 0 && patch1entities.size() > 0)
255 mergePatches(patch0coords, patch0entities, patch0types, myrank,
256 patch1coords, patch1entities, patch1types, myrank);
263 MPI_Status mpi_status;
265#ifdef DEBUG_GRIDGLUE_PARALLELMERGE
266 std::cout << myrank <<
" Comm Size" << commsize << std::endl;
272 PatchSizes patchSizes (patch0coords, patch0entities, patch0types,
273 patch1coords, patch1entities, patch1types);
275#ifdef DEBUG_GRIDGLUE_PARALLELMERGE
276 std::cout << myrank <<
" Start Communication" << std::endl;
280 PatchSizes maxPatchSizes;
281 mpi_result = MPI_Allreduce(&patchSizes, &maxPatchSizes,
282 6, MPI_UNSIGNED, MPI_MAX, MPI_COMM_WORLD);
284#ifdef DEBUG_GRIDGLUE_PARALLELMERGE
285 std::cout << myrank <<
" maxPatchSizes " <<
"done" << std::endl;
292 std::vector<Dune::FieldVector<ctype, dimworld> > remotePatch0coords ( maxPatchSizes.patch0coords );
293 std::vector<unsigned int> remotePatch0entities ( maxPatchSizes.patch0entities );
294 std::vector<Dune::GeometryType> remotePatch0types ( maxPatchSizes.patch0types );
295 std::vector<Dune::FieldVector<ctype,dimworld> > remotePatch1coords ( maxPatchSizes.patch1coords );
296 std::vector<unsigned int> remotePatch1entities ( maxPatchSizes.patch1entities );
297 std::vector<Dune::GeometryType> remotePatch1types ( maxPatchSizes.patch1types );
300 remotePatch0coords.clear();
301 std::copy(patch0coords.begin(), patch0coords.end(), std::back_inserter(remotePatch0coords));
302 remotePatch0entities.clear();
303 std::copy(patch0entities.begin(), patch0entities.end(), std::back_inserter(remotePatch0entities));
304 remotePatch0types.clear();
305 std::copy(patch0types.begin(), patch0types.end(), std::back_inserter(remotePatch0types));
307 remotePatch1coords.clear();
308 std::copy(patch1coords.begin(), patch1coords.end(), std::back_inserter(remotePatch1coords));
309 remotePatch1entities.clear();
310 std::copy(patch1entities.begin(), patch1entities.end(), std::back_inserter(remotePatch1entities));
311 remotePatch1types.clear();
312 std::copy(patch1types.begin(), patch1types.end(), std::back_inserter(remotePatch1types));
315 std::vector<Dune::FieldVector<ctype, dimworld> > tmpPatchCoords ( maxPatchSizes.maxCoords() );
316 std::vector<unsigned int> tmpPatchEntities ( maxPatchSizes.maxEntities() );
317 std::vector<Dune::GeometryType> tmpPatchTypes ( maxPatchSizes.maxTypes() );
320 for (
int i=1; i<commsize; i++)
322 int remoterank = (myrank - i + commsize) % commsize;
323 int rightrank = (myrank + 1 + commsize) % commsize;
324 int leftrank = (myrank - 1 + commsize) % commsize;
331 MPI_Sendrecv_replace(
332 &patchSizes, 6, MPI_UNSIGNED,
333 rightrank, MPITypeInfo<unsigned int>::tag,
334 leftrank, MPITypeInfo<unsigned int>::tag,
335 mpicomm_, &mpi_status);
339#ifdef DEBUG_GRIDGLUE_PARALLELMERGE
340 std::cout << myrank <<
" patchSizes " <<
"done" << std::endl;
346#ifdef DEBUG_GRIDGLUE_PARALLELMERGE
347 std::cout << myrank <<
" patch0coords" << std::endl;
349 MPI_SendVectorInRing(
350 remotePatch0coords, tmpPatchCoords, patchSizes.patch0coords,
351 rightrank, leftrank, mpicomm_);
354#ifdef DEBUG_GRIDGLUE_PARALLELMERGE
355 std::cout << myrank <<
" patch0entities" << std::endl;
357 MPI_SendVectorInRing(
358 remotePatch0entities, tmpPatchEntities, patchSizes.patch0entities,
359 rightrank, leftrank, mpicomm_);
362#ifdef DEBUG_GRIDGLUE_PARALLELMERGE
363 std::cout << myrank <<
" patch0types" << std::endl;
365 MPI_SendVectorInRing(
366 remotePatch0types, tmpPatchTypes, patchSizes.patch0types,
367 rightrank, leftrank, mpicomm_);
370#ifdef DEBUG_GRIDGLUE_PARALLELMERGE
371 std::cout << myrank <<
" patch1coords" << std::endl;
373 MPI_SendVectorInRing(
374 remotePatch1coords, tmpPatchCoords, patchSizes.patch1coords,
375 rightrank, leftrank, mpicomm_);
378#ifdef DEBUG_GRIDGLUE_PARALLELMERGE
379 std::cout << myrank <<
" patch1entities" << std::endl;
381 MPI_SendVectorInRing(
382 remotePatch1entities, tmpPatchEntities, patchSizes.patch1entities,
383 rightrank, leftrank, mpicomm_);
386#ifdef DEBUG_GRIDGLUE_PARALLELMERGE
387 std::cout << myrank <<
" patch1types" << std::endl;
389 MPI_SendVectorInRing(
390 remotePatch1types, tmpPatchTypes, patchSizes.patch1types,
391 rightrank, leftrank, mpicomm_);
396 if (remotePatch1entities.size() > 0 && patch0entities.size() > 0)
397 mergePatches(patch0coords, patch0entities, patch0types, myrank,
398 remotePatch1coords, remotePatch1entities, remotePatch1types, remoterank);
399 if (remotePatch0entities.size() > 0 && patch1entities.size() > 0)
400 mergePatches(remotePatch0coords, remotePatch0entities, remotePatch0types, remoterank,
401 patch1coords, patch1entities, patch1types, myrank);
403 std::cout <<
"Sync processes" << std::endl;
404 MPI_Barrier(mpicomm_);
405 std::cout <<
"...done" << std::endl;
412 patch0_is_.endResize();
413 patch1_is_.endResize();
416 remoteIndices_.setIncludeSelf(
true);
417#warning add list of neighbors ...
418 remoteIndices_.setIndexSets(patch0_is_, patch1_is_, mpicomm_) ;
419 remoteIndices_.rebuild<
true>();
422#ifdef DEBUG_GRIDGLUE_PARALLELMERGE
423 for (
auto it = remoteIndices_.begin(); it != remoteIndices_.end(); it++)
425 std::cout << myrank <<
"\tri-list\t" << it->first << std::endl;
426 for (
auto xit = it->second.first->begin(); xit != it->second.first->end(); ++xit)
427 std::cout << myrank <<
"\tri-list 1 \t" << it->first <<
"\t" << *xit << std::endl;
428 for (
auto xit = it->second.second->begin(); xit != it->second.second->end(); ++xit)
429 std::cout << myrank <<
"\tri-list 2 \t" << it->first <<
"\t" << *xit << std::endl;
450 const std::vector<Dune::FieldVector<ctype,dimworld> >& patch0coords,
451 const std::vector<unsigned int>& patch0entities,
452 const std::vector<Dune::GeometryType>& patch0types,
453 const int patch0rank,
454 const std::vector<Dune::FieldVector<ctype,dimworld> >& patch1coords,
455 const std::vector<unsigned int>& patch1entities,
456 const std::vector<Dune::GeometryType>& patch1types,
457 const int patch1rank)
465 MPI_Comm_rank(mpicomm_, &myrank);
466 MPI_Comm_size(mpicomm_, &commsize);
470 const bool patch0local = (myrank == patch0rank);
471 const bool patch1local = (myrank == patch1rank);
474 const unsigned int offset = intersections_.size()-1;
477 <<
" GridGlue::mergePatches : rank " << patch0rank <<
" / " << patch1rank << std::endl;
480 merger_->build(patch0coords, patch0entities, patch0types,
481 patch1coords, patch1entities, patch1types);
484 intersections_.resize(merger_->nSimplices() + offset + 1);
485 for (
unsigned int i = 0; i < merger_->nSimplices(); ++i)
488 intersections_[offset+i] = data;
491 index__sz = intersections_.size() - 1;
494 <<
" GridGlue::mergePatches : "
495 <<
"The number of remote intersections is " << intersections_.size()-1 << std::endl;
508 assert(Dune::RESIZE == patch0_is_.state());
509 assert(Dune::RESIZE == patch1_is_.state());
511 for (
unsigned int i = 0; i < merger_->nSimplices(); i++)
513#warning only handle the newest intersections / merger info
515 GlobalId gid(patch0rank, patch1rank, i);
518 Dune::PartitionType ptype = patch0_->element(it.
grid0indices_[0]).partitionType();
519 patch0_is_.add (gid, LocalIndex(offset+i, ptype) );
523 Dune::PartitionType ptype = patch1_->element(it.
grid1indices_[0]).partitionType();
524 patch1_is_.add (gid, LocalIndex(offset+i, ptype) );