From e9865fa66a75fee66e8d2396652e9e18c1f836e3 Mon Sep 17 00:00:00 2001
From: Matteo Cicuttin <datafl4sh@toxicnet.eu>
Date: Thu, 26 Aug 2021 12:00:32 +0200
Subject: [PATCH] Fixed edge cases when Comm_size = 1, fixed compilation
 without MPI.

---
 include/gmsh_io.h      | 5 ++++-
 src/maxwell_cpu.cpp    | 2 +-
 src/maxwell_solver.cpp | 8 ++++----
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/include/gmsh_io.h b/include/gmsh_io.h
index 8d63a75..fd7f5c8 100644
--- a/include/gmsh_io.h
+++ b/include/gmsh_io.h
@@ -198,7 +198,10 @@ public:
 
     int entity_rank(int tag) const
     {
-        return partition_inverse_map.at(tag)-1;
+        if (num_partitions > 1)
+            return partition_inverse_map.at(tag)-1;
+        
+        return 0;
     }
 
     entity&         entity_world_lookup(int);
diff --git a/src/maxwell_cpu.cpp b/src/maxwell_cpu.cpp
index 942b9cd..0491151 100644
--- a/src/maxwell_cpu.cpp
+++ b/src/maxwell_cpu.cpp
@@ -635,7 +635,6 @@ gather_field(const model& mod, maxwell::field& in, maxwell::field& out,
         }
     }
 }
-#endif
 
 void
 export_fields_to_silo_2(const model& mod, maxwell::solver_state& state,
@@ -691,6 +690,7 @@ export_fields_to_silo_2(const model& mod, maxwell::solver_state& state,
         gather_field(mod, state.emf_next, dummy, 0, MPI_COMM_WORLD);
     }
 }
+#endif /* USE_MPI */
 
 void
 export_fields_to_silo(const model& mod, const maxwell::solver_state& state,
diff --git a/src/maxwell_solver.cpp b/src/maxwell_solver.cpp
index 9653c9b..a4d7480 100644
--- a/src/maxwell_solver.cpp
+++ b/src/maxwell_solver.cpp
@@ -221,12 +221,12 @@ void test_it(const model& mod, State& state, maxwell::parameter_loader& mpl)
         do_sources(mod, state, mpl);
         
 #ifdef USE_MPI
-        //int rank;
-        //MPI_Comm_rank(MPI_COMM_WORLD, &rank);
-        //if (rank == 0)
-#endif /* USE_MPI */
             if ( (silo_output_rate != 0) and (i%silo_output_rate == 0) )
                 export_fields_to_silo_2(mod, state, mpl);
+#else
+            if ( (silo_output_rate != 0) and (i%silo_output_rate == 0) )
+                export_fields_to_silo(mod, state, mpl);
+#endif /* USE_MPI */
 
         swap(state, mpl);
 
-- 
GitLab