From 6cd937203c91fe67e4b6738707c97ea982d68b14 Mon Sep 17 00:00:00 2001
From: Timo Koch <timo.koch@iws.uni-stuttgart.de>
Date: Wed, 10 Aug 2016 18:49:38 +0200
Subject: [PATCH] [gridcreator] Fix gmsh grids for parallel alugrid runs

Dune-alugrid needs the gmsh reader to only fill the grid factory on rank 0.
See mergerequest !14 https://gitlab.dune-project.org/core/dune-grid/merge_requests/14.
This is different e.g. for UG that needs the grid on all processes.
---
 dumux/io/gridcreator.hh | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/dumux/io/gridcreator.hh b/dumux/io/gridcreator.hh
index e9546a3994..d27b9bf0fa 100644
--- a/dumux/io/gridcreator.hh
+++ b/dumux/io/gridcreator.hh
@@ -254,11 +254,27 @@ protected:
             if(domainMarkers)
             {
                 enableGmshDomainMarkers_ = true;
-                gridPtr() = std::shared_ptr<Grid>(Dune::GmshReader<Grid>::read(fileName, boundaryMarkers_, elementMarkers_, verbose, boundarySegments));
+                if (Dune::MPIHelper::getCollectiveCommunication().rank() == 0)
+                {
+                    gridPtr() = std::shared_ptr<Grid>(Dune::GmshReader<Grid>::read(fileName, boundaryMarkers_, elementMarkers_, verbose, boundarySegments));
+                }
+                else
+                {
+                    Dune::GridFactory<Grid> factory;
+                    gridPtr() = std::shared_ptr<Grid>(factory.createGrid());
+                }
             }
             else
             {
-                gridPtr() = std::shared_ptr<Grid>(Dune::GmshReader<Grid>::read(fileName, verbose, boundarySegments));
+                if (Dune::MPIHelper::getCollectiveCommunication().rank() == 0)
+                {
+                    gridPtr() = std::shared_ptr<Grid>(Dune::GmshReader<Grid>::read(fileName, verbose, boundarySegments));
+                }
+                else
+                {
+                    Dune::GridFactory<Grid> factory;
+                    gridPtr() = std::shared_ptr<Grid>(factory.createGrid());
+                }
             }
         }
     }
-- 
GitLab