|
dune-pdelab 2.10-git
|
Loading...
Searching...
No Matches
recipe-communication.cc
See explanation at Communication in parallel programs
// -*- tab-width: 4; indent-tabs-mode: nil -*-
// always include the config file
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
// C++ includes
#include<math.h>
#include<iostream>
// dune-common includes
#include<dune/common/parallel/mpihelper.hh>
#include<dune/common/parametertreeparser.hh>
#include<dune/common/timer.hh>
// dune-geometry includes
#include<dune/geometry/referenceelements.hh>
#include<dune/geometry/quadraturerules.hh>
// dune-grid includes
#include<dune/grid/onedgrid.hh>
#include<dune/grid/yaspgrid.hh>
#include<dune/grid/utility/structuredgridfactory.hh>
#include<dune/grid/io/file/vtk/vtkwriter.hh>
#include<dune/grid/io/file/gmshreader.hh>
#if HAVE_DUNE_UGGRID
#include<dune/grid/uggrid.hh>
#endif
#if HAVE_DUNE_ALUGRID
#include<dune/alugrid/grid.hh>
#include<dune/alugrid/dgf.hh>
#include<dune/grid/io/file/dgfparser/dgfparser.hh>
#endif
#include <dune/pdelab.hh>
#ifndef COMMUNICATE_HH
#define COMMUNICATE_HH
template <typename GV>
using RF = int; // RangeField
FEM fem(gv);
GFS gfs(gv,fem);
Z z(gfs);
// [Define DataHandle]
DH dh(gfs,z);
// Create collective communication object
// [Collective communication object]
auto comm = gv.comm();
// [Get rank]
// Store the 100^rank or rank of the current processor as data for each element.
for(auto& v : native(z)){
v = 1;
++size;
for(int j=0 ; j<myrank; ++j)
// v *= 1000; // makes it easy to see which ranks communicated ths entity
v += 1; // makes VTK outputs readable
}
// Different communication types for DataHandles:
//
// InteriorBorder_InteriorBorder_Interface: send/receive interior and border entities
// InteriorBorder_All_Interface: send interior and border, receive all entities
// Overlap_OverlapFront_Interface: send overlap, receive overlap and front entities
// Overlap_All_Interface: send overlap, receive all entities
// All_All_Interface: send all and receive all entities
// [Communication type]
switch (communicationType){
case 1: gv.communicate(dh, Dune::InteriorBorder_InteriorBorder_Interface ,Dune::ForwardCommunication); break;
case 3: gv.communicate(dh, Dune::Overlap_OverlapFront_Interface ,Dune::ForwardCommunication); break;
}
// Calculate the sum of the data vector on this rank
int sum = z.one_norm();
// If we are on rank 0 print the results.
if (myrank==0){
std::cout << "Each process stores values equal to 1000 powered to its rank, or only rank." << std::endl;
std::cout << "The sum shows how many entities are communicated and from which ranks they are." << std::endl;
std::cout << "The size of the data vector is equal to the number of all entities of this processor." << std::endl;
}
// Find the maximal and total sum on all ranks:
int globmax{0};
int globsum{0};
// [Collective communication]
globmax = comm.max(sum);
globsum = comm.sum(sum);
if (myrank==0){
}
// Make a grid function out of z
ZDGF zdgf(gfs,z);
// prepare VTK writer and write the file,
int subsampling{1};
VTKWRITER vtkwriter(gv,Dune::refinementIntervals(subsampling));
vtkwriter.write(filename,Dune::VTK::appendedraw);
}
#endif
//===============================================================
// Main program with grid setup
//===============================================================
{
// Maybe initialize Mpi
helper = Dune::MPIHelper::instance(argc, argv);
else
std::cout << "Parallel code run on "
// read ini file
const int overlap = 2;
const int refinement = 0;
// Create 2D YaspGrid
typedef Grid::ctype DF;
Dune::FieldVector<DF,dim> L{1.,1.};
std::shared_ptr<Grid> gridp = std::shared_ptr<Grid>(new Grid(L,N,B,overlap));//,Dune::MPIHelper::getCommunication()));
gridp->refineOptions(false); // keep overlap in cells
gridp->globalRefine(refinement);
typedef Grid::LeafGridView GV;
GV gv=gridp->leafGridView();
int communicationType = 1;
communicate(gv,communicationType);
}
int main(int argc, char **argv)
void communicate(CC &cc)
RefinementIntervals refinementIntervals(int intervals)
int size() const
static constexpr size_type N()
typename impl::BackendVectorSelector< GridFunctionSpace, FieldType >::Type Vector
alias of the return type of BackendVectorSelector
Definition backend/interface.hh:106
std::enable_if< std::is_base_of< impl::WrapperBase, T >::value, Native< T > & >::type native(T &t)
Definition backend/interface.hh:192
ForwardCommunication
InteriorBorder_All_Interface
All_All_Interface
Overlap_All_Interface
Overlap_OverlapFront_Interface
InteriorBorder_InteriorBorder_Interface
appendedraw
T max(const T &in) const
int rank() const
T sum(const T &in) const
int size() const
static constexpr bool isFake
static DUNE_EXPORT MPIHelper & instance(int &argc, char **&argv)
Definition istl/descriptors.hh:48
wrap a GridFunction so it can be used with the VTKWriter from dune-grid.
Definition vtkexport.hh:25
Definition noconstraints.hh:20
Definition qkfem.hh:20
Definition genericdatahandle.hh:667
convert a grid function space and a coefficient vector into a grid function
Definition gridfunctionspaceutilities.hh:76
T endl(T... args)
T to_string(T... args)
Legal Statements / Impressum | Hosted by TU Dresden & Uni Heidelberg | Generated by
1.9.8