From eea55236d4f444c70c62c3f9a8c58f90fc4a9d4c Mon Sep 17 00:00:00 2001 From: Emma Rothwell Date: Tue, 12 Dec 2023 16:52:11 +0000 Subject: [PATCH 01/11] removed serial case in lgmap. --- pyop2/types/dataset.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pyop2/types/dataset.py b/pyop2/types/dataset.py index 8d3ba0472..e9bf5bf98 100644 --- a/pyop2/types/dataset.py +++ b/pyop2/types/dataset.py @@ -113,12 +113,8 @@ def lgmap(self): indices for this :class:`DataSet`. """ lgmap = PETSc.LGMap() - if self.comm.size == 1: - lgmap.create(indices=np.arange(self.size, dtype=dtypes.IntType), - bsize=self.cdim, comm=self.comm) - else: - lgmap.create(indices=self.halo.local_to_global_numbering, - bsize=self.cdim, comm=self.comm) + lgmap.create(indices=self.halo.local_to_global_numbering, + bsize=self.cdim, comm=self.comm) return lgmap @utils.cached_property From 1b386a4112ccac8ff0b47c819bf72f33f15222a4 Mon Sep 17 00:00:00 2001 From: Emma Rothwell Date: Fri, 5 Jan 2024 10:39:58 +0000 Subject: [PATCH 02/11] Added constrained_size to Set and creation of matrix. --- pyop2/types/set.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pyop2/types/set.py b/pyop2/types/set.py index 32fb01844..0f6bb50de 100644 --- a/pyop2/types/set.py +++ b/pyop2/types/set.py @@ -64,7 +64,7 @@ def _wrapper_cache_key_(self): @utils.validate_type(('size', (numbers.Integral, tuple, list, np.ndarray), ex.SizeTypeError), ('name', str, ex.NameTypeError)) - def __init__(self, size, name=None, halo=None, comm=None): + def __init__(self, size, name=None, halo=None, comm=None, constrained_nodes=0): self.comm = mpi.internal_comm(comm, self) if isinstance(size, numbers.Integral): size = [size] * 3 @@ -75,6 +75,8 @@ def __init__(self, size, name=None, halo=None, comm=None): self._name = name or "set_#x%x" % id(self) self._halo = halo self._partition_size = 1024 + self._constrained_size = constrained_nodes + # A cache of objects built on top of this set self._cache = {} @@ -88,6 +90,10 @@ def core_size(self): """Core set size. Owned elements not touching halo elements.""" return self._sizes[Set._CORE_SIZE] + @utils.cached_property + def constrained_size(self): + return self._constrained_size + @utils.cached_property def size(self): """Set size, owned elements.""" From 17c20a796c93e14ac21e51b61b10b5558e8a6462 Mon Sep 17 00:00:00 2001 From: Emma Rothwell Date: Wed, 10 Jan 2024 10:22:51 +0000 Subject: [PATCH 03/11] layout_vec includes constrained case. --- pyop2/types/dataset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyop2/types/dataset.py b/pyop2/types/dataset.py index e9bf5bf98..8a2188ee8 100644 --- a/pyop2/types/dataset.py +++ b/pyop2/types/dataset.py @@ -179,7 +179,7 @@ def local_ises(self): def layout_vec(self): """A PETSc Vec compatible with the dof layout of this DataSet.""" vec = PETSc.Vec().create(comm=self.comm) - size = (self.size * self.cdim, None) + size = (self.size * self.cdim - self.set.constrained_size, None) vec.setSizes(size, bsize=self.cdim) vec.setUp() return vec From 3b28acbc900cbd192cf98dbdfb49a8d5e2adb7db Mon Sep 17 00:00:00 2001 From: Emma Rothwell Date: Thu, 25 Jan 2024 11:04:13 +0000 Subject: [PATCH 04/11] Put serial case back in for DataSet --- pyop2/types/dataset.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pyop2/types/dataset.py b/pyop2/types/dataset.py index 8a2188ee8..13ad7904f 100644 --- a/pyop2/types/dataset.py +++ b/pyop2/types/dataset.py @@ -113,8 +113,12 @@ def lgmap(self): indices for this :class:`DataSet`. """ lgmap = PETSc.LGMap() - lgmap.create(indices=self.halo.local_to_global_numbering, - bsize=self.cdim, comm=self.comm) + if self.comm.size == 1 and self.halo is None: + lgmap.create(indices=np.arange(self.size, dtype=dtypes.IntType), + bsize=self.cdim, comm=self.comm) + else: + lgmap.create(indices=self.halo.local_to_global_numbering, + bsize=self.cdim, comm=self.comm) return lgmap @utils.cached_property From acbbec98ed2a9829012c4d9d2a0654d2bff1db08 Mon Sep 17 00:00:00 2001 From: Emma Rothwell Date: Sun, 28 Jan 2024 17:02:58 +0000 Subject: [PATCH 05/11] global kernel _cache_key contains form signature --- pyop2/global_kernel.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyop2/global_kernel.py b/pyop2/global_kernel.py index 536d717e9..d49a2a5de 100644 --- a/pyop2/global_kernel.py +++ b/pyop2/global_kernel.py @@ -293,7 +293,8 @@ def __init__(self, local_kernel, arguments, *, constant_layers=False, subset=False, iteration_region=None, - pass_layer_arg=False): + pass_layer_arg=False, + form_signature=None): if self._initialized: return @@ -328,6 +329,7 @@ def __init__(self, local_kernel, arguments, *, self._subset = subset self._iteration_region = iteration_region self._pass_layer_arg = pass_layer_arg + self._form_signature = form_signature # Cache for stashing the compiled code self._func_cache = {} From cd6e8b02cb0603ff180f36bef0b8bc728984576c Mon Sep 17 00:00:00 2001 From: Emma Rothwell Date: Tue, 20 Feb 2024 11:58:05 +0000 Subject: [PATCH 06/11] adding constrained size for mixed sets. --- pyop2/types/set.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pyop2/types/set.py b/pyop2/types/set.py index 0f6bb50de..a520c4757 100644 --- a/pyop2/types/set.py +++ b/pyop2/types/set.py @@ -594,6 +594,11 @@ def core_size(self): """Core set size. Owned elements not touching halo elements.""" return sum(s.core_size for s in self._sets) + @utils.cached_property + def constrained_size(self): + """Set size, owned elements.""" + return sum(s.constrained_size for s in self._sets) + @utils.cached_property def size(self): """Set size, owned elements.""" From f990aab2356abccef709d387b649d0216c667b47 Mon Sep 17 00:00:00 2001 From: Emma Rothwell Date: Mon, 26 Feb 2024 13:48:54 +0000 Subject: [PATCH 07/11] add constrained size in lgmap for mixeddataset --- pyop2/types/dataset.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pyop2/types/dataset.py b/pyop2/types/dataset.py index 13ad7904f..c1b651da6 100644 --- a/pyop2/types/dataset.py +++ b/pyop2/types/dataset.py @@ -183,7 +183,7 @@ def local_ises(self): def layout_vec(self): """A PETSc Vec compatible with the dof layout of this DataSet.""" vec = PETSc.Vec().create(comm=self.comm) - size = (self.size * self.cdim - self.set.constrained_size, None) + size = ((self.size - self.set.constrained_size) * self.cdim , None) vec.setSizes(size, bsize=self.cdim) vec.setUp() return vec @@ -449,8 +449,8 @@ def lgmap(self): indices for this :class:`MixedDataSet`. """ lgmap = PETSc.LGMap() - if self.comm.size == 1: - size = sum(s.size * s.cdim for s in self) + if self.comm.size == 1 and self.halo is None: + size = sum((s.size - s.constrained_size) * s.cdim for s in self) lgmap.create(indices=np.arange(size, dtype=dtypes.IntType), bsize=1, comm=self.comm) return lgmap @@ -479,7 +479,7 @@ def lgmap(self): # current field offset. idx_size = sum(s.total_size*s.cdim for s in self) indices = np.full(idx_size, -1, dtype=dtypes.IntType) - owned_sz = np.array([sum(s.size * s.cdim for s in self)], + owned_sz = np.array([sum((s.size - s.constrained_size) * s.cdim for s in self)], dtype=dtypes.IntType) field_offset = np.empty_like(owned_sz) self.comm.Scan(owned_sz, field_offset) @@ -493,7 +493,7 @@ def lgmap(self): current_offsets = np.zeros(self.comm.size + 1, dtype=dtypes.IntType) for s in self: idx = indices[start:start + s.total_size * s.cdim] - owned_sz[0] = s.size * s.cdim + owned_sz[0] = (s.size - s.set.constrained_size) * s.cdim self.comm.Scan(owned_sz, field_offset) self.comm.Allgather(field_offset, current_offsets[1:]) # Find the ranks each entry in the l2g belongs to From d3eec814c2796c237e5c0d6533c08a5a6b9dd0f6 Mon Sep 17 00:00:00 2001 From: Emma Rothwell Date: Wed, 6 Mar 2024 11:28:30 +0000 Subject: [PATCH 08/11] apply pr suggestions for naming things --- pyop2/global_kernel.py | 4 ++-- pyop2/types/set.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pyop2/global_kernel.py b/pyop2/global_kernel.py index d49a2a5de..9b2f1df7b 100644 --- a/pyop2/global_kernel.py +++ b/pyop2/global_kernel.py @@ -294,7 +294,7 @@ def __init__(self, local_kernel, arguments, *, subset=False, iteration_region=None, pass_layer_arg=False, - form_signature=None): + signature=None): if self._initialized: return @@ -329,7 +329,7 @@ def __init__(self, local_kernel, arguments, *, self._subset = subset self._iteration_region = iteration_region self._pass_layer_arg = pass_layer_arg - self._form_signature = form_signature + self.signature = signature # Cache for stashing the compiled code self._func_cache = {} diff --git a/pyop2/types/set.py b/pyop2/types/set.py index a520c4757..f47235dc6 100644 --- a/pyop2/types/set.py +++ b/pyop2/types/set.py @@ -64,7 +64,7 @@ def _wrapper_cache_key_(self): @utils.validate_type(('size', (numbers.Integral, tuple, list, np.ndarray), ex.SizeTypeError), ('name', str, ex.NameTypeError)) - def __init__(self, size, name=None, halo=None, comm=None, constrained_nodes=0): + def __init__(self, size, name=None, halo=None, comm=None, constrained_size=0): self.comm = mpi.internal_comm(comm, self) if isinstance(size, numbers.Integral): size = [size] * 3 @@ -75,7 +75,7 @@ def __init__(self, size, name=None, halo=None, comm=None, constrained_nodes=0): self._name = name or "set_#x%x" % id(self) self._halo = halo self._partition_size = 1024 - self._constrained_size = constrained_nodes + self._constrained_size = constrained_size # A cache of objects built on top of this set self._cache = {} From 7c64679789d5c0ae33eb926ba8e832fd88d171c2 Mon Sep 17 00:00:00 2001 From: Emma Rothwell Date: Sun, 21 Apr 2024 21:25:39 +0100 Subject: [PATCH 09/11] remove whitespace --- pyop2/types/dataset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyop2/types/dataset.py b/pyop2/types/dataset.py index c1b651da6..3b4f4bfd8 100644 --- a/pyop2/types/dataset.py +++ b/pyop2/types/dataset.py @@ -183,7 +183,7 @@ def local_ises(self): def layout_vec(self): """A PETSc Vec compatible with the dof layout of this DataSet.""" vec = PETSc.Vec().create(comm=self.comm) - size = ((self.size - self.set.constrained_size) * self.cdim , None) + size = ((self.size - self.set.constrained_size) * self.cdim, None) vec.setSizes(size, bsize=self.cdim) vec.setUp() return vec From 4e1bb3caf7debe387420ad40ad7b22997a8b6466 Mon Sep 17 00:00:00 2001 From: Emma Rothwell Date: Tue, 23 Apr 2024 15:18:15 +0100 Subject: [PATCH 10/11] remove signature from global kernel. --- pyop2/global_kernel.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pyop2/global_kernel.py b/pyop2/global_kernel.py index 9b2f1df7b..536d717e9 100644 --- a/pyop2/global_kernel.py +++ b/pyop2/global_kernel.py @@ -293,8 +293,7 @@ def __init__(self, local_kernel, arguments, *, constant_layers=False, subset=False, iteration_region=None, - pass_layer_arg=False, - signature=None): + pass_layer_arg=False): if self._initialized: return @@ -329,7 +328,6 @@ def __init__(self, local_kernel, arguments, *, self._subset = subset self._iteration_region = iteration_region self._pass_layer_arg = pass_layer_arg - self.signature = signature # Cache for stashing the compiled code self._func_cache = {} From 8fa2ff3a5d0eb8ac79978eb67490e00870a68e5f Mon Sep 17 00:00:00 2001 From: emmarothwell1 <97527188+emmarothwell1@users.noreply.github.com> Date: Thu, 25 Apr 2024 15:28:56 +0100 Subject: [PATCH 11/11] Update pyop2/types/set.py --- pyop2/types/set.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyop2/types/set.py b/pyop2/types/set.py index f47235dc6..f10c93404 100644 --- a/pyop2/types/set.py +++ b/pyop2/types/set.py @@ -596,7 +596,7 @@ def core_size(self): @utils.cached_property def constrained_size(self): - """Set size, owned elements.""" + """Set size, owned constrained elements.""" return sum(s.constrained_size for s in self._sets) @utils.cached_property