From 641007a2906d4932c5b124d9bd95651fb4fc7fec Mon Sep 17 00:00:00 2001
From: Incardona Pietro <incardon@mpi-cbg.de>
Date: Sat, 20 Feb 2021 09:44:11 +0100
Subject: [PATCH] Adding mantainer for DEB

---
 CMakeLists.txt                                |  2 +
 src/Grid/grid_dist_id.hpp                     | 24 +++++-
 ...grid_dist_id_HDF5_chckpnt_restart_test.cpp | 79 +++++++++++++++++++
 3 files changed, 103 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index fd50d12ce..c63bebf3f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -274,6 +274,8 @@ if (CPACK_RUN_INSTALL_DEPENDENCIES)
 	set(CPACK_PACKAGING_INSTALL_PREFIX /usr/local/openfpm)
 	set(CPACK_PACKAGE_HOMEPAGE_URL http://openfpm.mpi-cbg.de)
 	set(CPACK_RPM_PACKAGE_AUTOREQPROV NO)
+	set(CPACK_PACKAGE_CONTACT incardon@mpi-cbg.de)
+	set(CPACK_DEBIAN_PACKAGE_MAINTAINER Pietro Incardona)
 
 	install(FILES $ENV{DEP_PACKING}/openfpm_vars
               	DESTINATION openfpm_vars
diff --git a/src/Grid/grid_dist_id.hpp b/src/Grid/grid_dist_id.hpp
index c20900ffc..538268f48 100644
--- a/src/Grid/grid_dist_id.hpp
+++ b/src/Grid/grid_dist_id.hpp
@@ -3102,8 +3102,28 @@ public:
 		}
 		else
 		{
-			loc_grid.swap(loc_grid_old);
-			gdb_ext_old.swap(gdb_ext);
+			for (int i = 0 ; i < gdb_ext_old.size() ; i++)
+			{
+					auto & lg = loc_grid_old.get(i);
+					auto it_src = lg.getIterator(gdb_ext_old.get(i).Dbox.getKP1(),gdb_ext_old.get(i).Dbox.getKP2());
+					auto & dg = loc_grid.get(0);
+
+					grid_key_dx<dim> orig;
+					for (int j = 0 ; j < dim ; j++)
+					{
+							orig.set_d(j,gdb_ext_old.get(i).origin.get(j) + gdb_ext_old.get(i).Dbox.getKP1().get(j));
+					}
+
+					while (it_src.isNext())
+					{
+							auto key = it_src.get();
+							auto key_dst = key + orig;
+
+							dg.get_o(key_dst) = lg.get_o(key);
+
+							++it_src;
+					}
+			}
 		}
 	}
 
diff --git a/src/Grid/tests/grid_dist_id_HDF5_chckpnt_restart_test.cpp b/src/Grid/tests/grid_dist_id_HDF5_chckpnt_restart_test.cpp
index 9ed95ba85..c976aa1d7 100644
--- a/src/Grid/tests/grid_dist_id_HDF5_chckpnt_restart_test.cpp
+++ b/src/Grid/tests/grid_dist_id_HDF5_chckpnt_restart_test.cpp
@@ -145,6 +145,85 @@ BOOST_AUTO_TEST_CASE( grid_dist_id_hdf5_load_test )
 }
 
 
+BOOST_AUTO_TEST_CASE( grid_dist_id_hdf5_copy_test )
+{
+
+	// Input data
+	size_t k = 2400;
+
+	float ghost_part = 0.0;
+
+	// Domain
+	Box<2,float> domain({0.0,0.0},{1.0,1.0});
+
+	Vcluster<> & v_cl = create_vcluster();
+
+	// Skip this test on big scale
+	if (v_cl.getProcessingUnits() >= 32)
+		return;
+
+	// grid size
+	size_t sz[2];
+	sz[0] = k;
+	sz[1] = k;
+
+	// Ghost
+	Ghost<2,float> g(ghost_part);
+
+	// Distributed grid with id decomposition
+	grid_dist_id<2, float, aggregate<float>, CartDecomposition<2,float>> g_dist(sz,domain,g);
+	grid_dist_id<2, float, aggregate<float>, CartDecomposition<2,float>> g_dist_copy(g_dist.getDecomposition(),sz,g);
+
+	g_dist.load("test_data/test_data_three.h5");
+
+	// Copy
+
+	auto dom_sc = g_dist.getDomainIterator();
+    auto dom_ds = g_dist_copy.getDomainIterator();
+    while (dom_sc.isNext())
+    {
+        auto key_sc = dom_sc.get();
+        auto key_ds = dom_ds.get();
+        g_dist_copy.template get<0>(key_ds) = g_dist.template get<0>(key_sc);
+        ++dom_sc;
+        ++dom_ds;
+    }
+
+
+	auto it = g_dist_copy.getDomainIterator();
+
+	size_t count = 0;
+
+	bool match = true;
+	while (it.isNext())
+	{
+		//key
+		auto key = it.get();
+
+		//BOOST_CHECK_CLOSE(g_dist.template get<0>(key),1,0.0001);
+		//std::cout << "Element: " << g_dist.template get<0>(key) << std::endl;
+
+		auto keyg = g_dist_copy.getGKey(key);
+
+		match &= g_dist_copy.template get<0>(key) == keyg.get(0);
+
+		++it;
+		count++;
+	}
+
+	openfpm::vector<size_t> count_total;
+	v_cl.allGather(count,count_total);
+	v_cl.execute();
+
+	size_t sum = 0;
+
+	for (size_t i = 0; i < count_total.size(); i++)
+		sum += count_total.get(i);
+
+	BOOST_REQUIRE_EQUAL(sum, (size_t)k*k);
+	BOOST_REQUIRE_EQUAL(match,true);
+}
+
 BOOST_AUTO_TEST_CASE( grid_dist_id_hdf5_load_test_diff_proc )
 {
 
-- 
GitLab