From cc0691cd887a71cde0d9d34cf7077825226dc9a7 Mon Sep 17 00:00:00 2001
From: "hanouvit@vz" <vithanousek@seznam.cz>
Date: Wed, 23 Aug 2017 16:08:02 +0200
Subject: [PATCH] Allow user to hint/force distribution of 2D grid between
 nodes.

---
 src/TNL/Meshes/DistributedGrid.h      | 20 ++++++++++++++------
 tests/mpi/MeshFunctionEvauateTest.cpp |  5 +++--
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/TNL/Meshes/DistributedGrid.h b/src/TNL/Meshes/DistributedGrid.h
index efb0f5f4a0..2347202f0f 100644
--- a/src/TNL/Meshes/DistributedGrid.h
+++ b/src/TNL/Meshes/DistributedGrid.h
@@ -23,7 +23,7 @@ namespace Meshes {
           typename Real >*/
 
 template<typename GridType,
-        int meshDimensions= GridType::meshDimension>    
+        int meshDimensions= GridType::getMeshDimension()>    
 class DistributedGrid
 {
 
@@ -86,7 +86,7 @@ class DistributedGrid <GridType,1>
      
    public:
        //compute everithing 
-       DistributedGrid(GridType globalGrid)
+       DistributedGrid(GridType globalGrid, int *distribution=NULL)
        {
            
            //fuj
@@ -229,7 +229,7 @@ class DistributedGrid <GridType,2>
      
    public:
        //compute everithing 
-       DistributedGrid(GridType globalGrid)
+       DistributedGrid(GridType globalGrid,int *distribution=NULL)
        {
            
            //fuj
@@ -239,7 +239,7 @@ class DistributedGrid <GridType,2>
            for (int i=0;i<8;i++)
                 neighbors[i]=-1;
            
-           Dimensions= GridType::meshDimension;
+           Dimensions= GridType::getMeshDimension();
            GlobalGrid=globalGrid;
            //Detect MPI and number of process
            mpiInUse=false;
@@ -270,8 +270,16 @@ class DistributedGrid <GridType,2>
            {
                //With MPI
                //compute node distribution
-               procsdistr[0]=0;
-               procsdistr[1]=0;
+               if(distribution!=NULL)
+               {
+                  procsdistr[0]=distribution[0];
+                  procsdistr[1]=distribution[1];
+               }
+               else
+               {
+                  procsdistr[0]=0;
+                  procsdistr[1]=0;
+               }
                MPI_Dims_create(nproc, 2, procsdistr);
                myproccoord[0]=rank%procsdistr[0]; // CO je X a co Y? --x je 0 a je to sloupec
                myproccoord[1]=rank/procsdistr[0];        
diff --git a/tests/mpi/MeshFunctionEvauateTest.cpp b/tests/mpi/MeshFunctionEvauateTest.cpp
index 7ab5a7f6ad..a80bbd2283 100644
--- a/tests/mpi/MeshFunctionEvauateTest.cpp
+++ b/tests/mpi/MeshFunctionEvauateTest.cpp
@@ -18,7 +18,7 @@ using namespace std;
 
 #include <TNL/Timer.h>
 
-//#define OUTPUT 
+#define OUTPUT 
 
 #include "Functions.h"
 
@@ -73,7 +73,8 @@ int main ( int argc, char *argv[])
  globalGrid.setDimensions(size,size);
  globalGrid.setDomain(globalOrigin,globalProportions);
  
- DistributedGrid<MeshType> distrgrid(globalGrid); 
+ int distr[2]={0,1};
+ DistributedGrid<MeshType> distrgrid(globalGrid, distr); 
   
  SharedPointer<MeshType> gridptr;
  SharedPointer<MeshFunctionType> meshFunctionptr;
-- 
GitLab