From d6aa53632983422ca493f384a00e8beec2cabaf7 Mon Sep 17 00:00:00 2001
From: Matteo Cicuttin <datafl4sh@toxicnet.eu>
Date: Mon, 7 Jun 2021 18:15:23 +0000
Subject: [PATCH] Small performance optimization.

---
 include/maxwell_interface.h | 12 ++++++------
 src/maxwell_cpu.cpp         |  2 +-
 src/maxwell_gpu.cpp         |  8 ++++----
 src/maxwell_solver.cpp      |  2 +-
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/include/maxwell_interface.h b/include/maxwell_interface.h
index f5485d5..2e7af8a 100644
--- a/include/maxwell_interface.h
+++ b/include/maxwell_interface.h
@@ -295,11 +295,11 @@ struct solver_state_gpu
     device_vector<double>               Jy_src_gpu_buf;
     device_vector<double>               Jz_src_gpu_buf;
 
-    field_gpu                           bndsrcs;
-    field_gpu                           bndsrcs_buf;
+    field_gpu                           bndsrcs;        /* Not compressed */
+    field_gpu                           bndsrcs_buf;    /* Compressed */
 
-    field                               bndsrcs_decomp_cpu;
-    pinned_field                        bndsrcs_cpu;
+    field                               bndsrcs_decomp_cpu; /* Not compressed */
+    pinned_field                        bndsrcs_cpu;        /* Compressed */
 
     std::vector<size_t>                 bndsrcs_decomp_table_cpu;
     device_vector<size_t>               bndsrcs_decomp_table;
@@ -317,7 +317,7 @@ void export_fields_to_silo(const model&, const solver_state&, const parameter_lo
 void timestep(solver_state&, const parameter_loader&, time_integrator_type);
 void prepare_sources(const model&, maxwell::solver_state&, maxwell::parameter_loader&);
 void do_sources(const model&, maxwell::solver_state&, maxwell::parameter_loader&);
-void swap(maxwell::solver_state&);
+void swap(maxwell::solver_state&, const parameter_loader&);
 
 #ifdef ENABLE_GPU_SOLVER
 void init_from_model(const model&, solver_state_gpu&);
@@ -327,7 +327,7 @@ void export_fields_to_silo(const model&, const solver_state_gpu&, const paramete
 void timestep(solver_state_gpu&, const parameter_loader&, time_integrator_type);
 void prepare_sources(const model&, maxwell::solver_state_gpu&, maxwell::parameter_loader&);
 void do_sources(const model&, maxwell::solver_state_gpu&, maxwell::parameter_loader&);
-void swap(maxwell::solver_state_gpu&);
+void swap(maxwell::solver_state_gpu&, const parameter_loader&);
 #endif /* ENABLE_GPU_SOLVER */
 
 void init_boundary_conditions(const model&, const parameter_loader&, vecxd&);
diff --git a/src/maxwell_cpu.cpp b/src/maxwell_cpu.cpp
index 4adfdec..f826dbb 100644
--- a/src/maxwell_cpu.cpp
+++ b/src/maxwell_cpu.cpp
@@ -585,7 +585,7 @@ prepare_sources(const model& mod, maxwell::solver_state& state,
 }
 
 void
-swap(maxwell::solver_state& state)
+swap(maxwell::solver_state& state, const parameter_loader&)
 {
     std::swap(state.emf_curr, state.emf_next);
 }
diff --git a/src/maxwell_gpu.cpp b/src/maxwell_gpu.cpp
index df24090..390cbbc 100644
--- a/src/maxwell_gpu.cpp
+++ b/src/maxwell_gpu.cpp
@@ -540,13 +540,13 @@ do_sources(const model& mod, maxwell::solver_state_gpu& state,
 }
 
 void
-swap(solver_state_gpu& state)
+swap(solver_state_gpu& state, const parameter_loader& mpl)
 {
     checkGPU( gpuDeviceSynchronize() );
 
-    //auto be = mpl.boundary_sources_enabled();
-    //auto ie = mpl.interface_sources_enabled()
-    //if ( be or ie )
+    auto be = mpl.boundary_sources_enabled();
+    auto ie = mpl.interface_sources_enabled();
+    if ( be or ie )
         decompress_bndsrc(state, state.bndsrcs_buf, state.bndsrcs);
     
     std::swap(state.Jx_src_gpu, state.Jx_src_gpu_buf);
diff --git a/src/maxwell_solver.cpp b/src/maxwell_solver.cpp
index 78c09f6..fcd32d4 100644
--- a/src/maxwell_solver.cpp
+++ b/src/maxwell_solver.cpp
@@ -100,7 +100,7 @@ void test_it(const model& mod, State& state, maxwell::parameter_loader& mpl)
         if (i%silo_output_rate == 0)
             export_fields_to_silo(mod, state, mpl);
 
-        swap(state);
+        swap(state, mpl);
 
         if (i%cycle_print_rate == 0)
         {
-- 
GitLab