#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include<math.h>
#include<iostream>
#include<dune/common/parallel/mpihelper.hh>
#include<dune/common/parametertreeparser.hh>
#include<dune/common/timer.hh>
#include<dune/geometry/referenceelements.hh>
#include<dune/geometry/quadraturerules.hh>
#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/vtk/subsamplingvtkwriter.hh>
#include<dune/grid/io/file/gmshreader.hh>
#if HAVE_UG
#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
#ifndef COMMUNICATE_HH
#define COMMUNICATE_HH
template <typename GV>
using RF = int;
FEM fem(gv);
GFS gfs(gv,fem);
Z z(gfs);
DH dh(gfs,z);
auto comm = gv.comm();
int myrank = comm.rank();
int size{0};
for(auto& v : native(z)){
v = 1;
++size;
for(int j=0 ; j<myrank; ++j)
v += 1;
}
switch (communicationType){
case 1: gv.communicate(dh, Dune::InteriorBorder_InteriorBorder_Interface ,Dune::ForwardCommunication); break;
case 2: gv.communicate(dh, Dune::InteriorBorder_All_Interface ,Dune::ForwardCommunication); break;
case 3: gv.communicate(dh, Dune::Overlap_OverlapFront_Interface ,Dune::ForwardCommunication); break;
case 4: gv.communicate(dh, Dune::Overlap_All_Interface ,Dune::ForwardCommunication); break;
default: gv.communicate(dh, Dune::All_All_Interface ,Dune::ForwardCommunication);
}
int sum = z.one_norm();
if (myrank==0){
std::cout << std::endl;
std::cout << "== Output for rank " << myrank << std::endl;
std::cout << std::endl;
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;
std::cout << std::endl;
std::cout << "Sum of the data vector: " << sum << std::endl;
std::cout << "Size of the data vector: " << size << std::endl;
}
int globmax{0};
int globsum{0};
globmax = comm.max(sum);
globsum = comm.sum(sum);
if (myrank==0){
std::cout << "Maximal sum on all ranks is " << globmax << std::endl;
std::cout << "Total sum on all ranks is " << globsum << std::endl;
}
ZDGF zdgf(gfs,z);
int subsampling{1};
VTKWRITER vtkwriter(gv,Dune::refinementIntervals(subsampling));
std::string filename="recipe-communication";
std::string outputname="commType_"+std::to_string(communicationType);
vtkwriter.addVertexData(std::shared_ptr<VTKF>(new VTKF(zdgf,outputname)));
vtkwriter.write(filename,Dune::VTK::appendedraw);
}
#endif
int main(
int argc,
char** argv)
{
try{
Dune::MPIHelper&
helper = Dune::MPIHelper::instance(argc, argv);
if(Dune::MPIHelper::isFake)
std::cout<< "This is a sequential program." << std::endl;
else
std::cout << "Parallel code run on "
<< helper.size() << " process(es)" << std::endl;
const int overlap = 2;
const int refinement = 0;
typedef Dune::YaspGrid<dim> Grid;
typedef Grid::ctype DF;
Dune::FieldVector<DF,dim> L{1.,1.};
std::array<int,dim> N{16,16};
std::bitset<dim> B(false);
std::shared_ptr<Grid> gridp = std::shared_ptr<Grid>(new Grid(L,N,B,overlap));
gridp->refineOptions(false);
gridp->globalRefine(refinement);
typedef Grid::LeafGridView GV;
GV gv=gridp->leafGridView();
int communicationType = 1;
}
catch (Dune::Exception &e){
std::cerr << "Dune reported error: " << e << std::endl;
return 1;
}
catch (...){
std::cerr << "Unknown exception thrown!" << std::endl;
return 1;
}
}
int main(int argc, char **argv)
Definition recipe-blocking.cc:42
void communicate(const GV &gv, int communicationType)
Definition recipe-communication.cc:123
static const int dim
Definition adaptivity.hh:84
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
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 genericdatahandle.hh:667
A grid function space.
Definition gridfunctionspace.hh:186
convert a grid function space and a coefficient vector into a grid function
Definition gridfunctionspaceutilities.hh:76