From 47dbf5d3a03051b044c87a3647deac83c6d2a8bf Mon Sep 17 00:00:00 2001
From: Michael Kuron <mkuron@icp.uni-stuttgart.de>
Date: Tue, 14 Jan 2020 14:57:00 +0100
Subject: [PATCH] SerialDataHandling: synchronization_function for tensor
 fields

---
 pystencils/datahandling/serial_datahandling.py | 2 --
 pystencils/gpucuda/periodicity.py              | 9 +++++----
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/pystencils/datahandling/serial_datahandling.py b/pystencils/datahandling/serial_datahandling.py
index 12c9b6f3d..be586488d 100644
--- a/pystencils/datahandling/serial_datahandling.py
+++ b/pystencils/datahandling/serial_datahandling.py
@@ -307,8 +307,6 @@ class SerialDataHandling(DataHandling):
                 values_per_cell = (1, )
             if len(values_per_cell) == 1:
                 values_per_cell = values_per_cell[0]
-            else:
-                raise NotImplementedError("Synchronization of this field is not supported: " + name)
 
             if len(filtered_stencil) > 0:
                 if target == 'cpu':
diff --git a/pystencils/gpucuda/periodicity.py b/pystencils/gpucuda/periodicity.py
index 080ef44eb..8bb0109be 100644
--- a/pystencils/gpucuda/periodicity.py
+++ b/pystencils/gpucuda/periodicity.py
@@ -1,4 +1,5 @@
 import numpy as np
+from itertools import product
 
 import pystencils.gpucuda
 import pystencils.opencl
@@ -9,8 +10,6 @@ from pystencils.slicing import get_periodic_boundary_src_dst_slices, normalize_s
 
 def create_copy_kernel(domain_size, from_slice, to_slice, index_dimensions=0, index_dim_shape=1, dtype=np.float64):
     """Copies a rectangular part of an array to another non-overlapping part"""
-    if index_dimensions not in (0, 1):
-        raise NotImplementedError("Works only for one or zero index coordinates")
 
     f = Field.create_generic("pdfs", len(domain_size), index_dimensions=index_dimensions, dtype=dtype)
     normalized_from_slice = normalize_slice(from_slice, f.spatial_shape)
@@ -21,8 +20,10 @@ def create_copy_kernel(domain_size, from_slice, to_slice, index_dimensions=0, in
         "Slices have to have same size"
 
     update_eqs = []
-    for i in range(index_dim_shape):
-        eq = Assignment(f(i), f[tuple(offset)](i))
+    if index_dimensions < 2:
+        index_dim_shape = [index_dim_shape]
+    for i in product(*[range(d) for d in index_dim_shape]):
+        eq = Assignment(f(*i), f[tuple(offset)](*i))
         update_eqs.append(eq)
 
     ast = create_cuda_kernel(update_eqs, iteration_slice=to_slice, skip_independence_check=True)
-- 
GitLab