Skip to content

Commit

Permalink
Remove Context.from_global_dim_data...
Browse files Browse the repository at this point in the history
and fix tests to first make a Distribution object from a global_dim_data, then make a DistArray with the Distribution object.
  • Loading branch information
bgrant committed Apr 30, 2014
1 parent c7265ef commit 3211fed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 118 deletions.
111 changes: 0 additions & 111 deletions distarray/context.py
Expand Up @@ -228,117 +228,6 @@ def empty(self, shape, dtype=float, dist=None, grid_shape=None):
shape=shape, dist=dist,
grid_shape=grid_shape, dtype=dtype)

def from_global_dim_data(self, global_dim_data, dtype=float):
"""Make a DistArray from global dim_data structures.
Parameters
----------
global_dim_data : tuple of dict
A global dimension dictionary per dimension. See following `Note`
section.
dtype : numpy dtype, optional
dtype for underlying arrays
Returns
-------
result : DistArray
An empty DistArray of the specified size, dimensionality, and
distribution.
Note
----
The `global_dim_data` tuple is a simple, straightforward data structure
that allows full control over all aspects of a DistArray's distribution
information. It does not contain any of the array's *data*, only the
*metadata* needed to specify how the array is to be distributed. Each
dimension of the array is represented by corresponding dictionary in
the tuple, one per dimension. All dictionaries have a `dist_type` key
that specifies whether the array is block, cyclic, or unstructured.
The other keys in the dictionary are dependent on the `dist_type` key.
**Block**
* ``dist_type`` is ``'b'``.
* ``bounds`` is a sequence of integers, at least two elements.
The ``bounds`` sequence always starts with 0 and ends with the global
``size`` of the array. The other elements indicate the local array
global index boundaries, such that successive pairs of elements from
``bounds`` indicates the ``start`` and ``stop`` indices of the
corresponding local array.
* ``comm_padding`` integer, greater than or equal to zero.
* ``boundary_padding`` integer, greater than or equal to zero.
These integer values indicate the communication or boundary padding,
respectively, for the local arrays. Currently only a single value for
both ``boundary_padding`` and ``comm_padding`` is allowed for the
entire dimension.
**Cyclic**
* ``dist_type`` is ``'c'``
* ``proc_grid_size`` integer, greater than or equal to one.
The size of the process grid in this dimension. Equivalent to the
number of local arrays in this dimension and determines the number of
array sections.
* ``size`` integer, greater than or equal to zero.
The global size of the array in this dimension.
* ``block_size`` integer, optional. Greater than or equal to one.
If not present, equivalent to being present with value of one.
**Unstructured**
* ``dist_type`` is ``'u'``
* ``indices`` sequence of one-dimensional numpy integer arrays or
buffers.
The ``len(indices)`` is the number of local unstructured arrays in
this dimension.
To compute the global size of the array in this dimension, compute
``sum(len(ii) for ii in indices)``.
**Not-distributed**
The ``'n'`` distribution type is a convenience to specify that an array
is not distributed along this dimension.
* ``dist_type`` is ``'n'``
* ``size`` integer, greater than or equal to zero.
The global size of the array in this dimension.
"""
# global_dim_data is a sequence of dictionaries, one per dimension.
distribution = Distribution(self, global_dim_data)
dim_data_per_rank = distribution.get_dim_data_per_rank()

if len(self.targets) != len(dim_data_per_rank):
errmsg = "`dim_data_per_rank` must contain a dim_data for every rank."
raise TypeError(errmsg)

da_key = self._generate_key()
subs = ((da_key,) + self._key_and_push(dim_data_per_rank) +
(self._comm_key, self._comm_key) + self._key_and_push(dtype))

cmd = ('%s = distarray.local.LocalArray('
'distarray.local.maps.Distribution(%s[%s.Get_rank()], comm=%s),'
' dtype=%s)')
self._execute(cmd % subs)

return DistArray.from_localarrays(da_key, self)

def save_dnpy(self, name, da):
"""
Save a distributed array to files in the ``.dnpy`` format.
Expand Down
20 changes: 13 additions & 7 deletions distarray/tests/test_client.py
Expand Up @@ -109,9 +109,10 @@ def test_from_global_dim_data_irregular_block(self):
bounds = (0, 2, 3, 4, 10)
glb_dim_data = (
{'dist_type': 'b',
'bounds': bounds},
'bounds': bounds},
)
distarr = self.context.from_global_dim_data(glb_dim_data)
distribution = Distribution(self.context, glb_dim_data)
distarr = DistArray(distribution, dtype=int)
for i in range(global_size):
distarr[i] = i

Expand All @@ -128,7 +129,8 @@ def test_from_global_dim_data_1d(self):
'indices': list_of_indices,
},
)
distarr = self.context.from_global_dim_data(glb_dim_data)
distribution = Distribution(self.context, glb_dim_data)
distarr = DistArray(distribution, dtype=int)
for i in range(total_size):
distarr[i] = i
localarrays = distarr.get_localarrays()
Expand All @@ -152,7 +154,8 @@ def test_from_global_dim_data_bu(self):
'indices' : indices
},
)
distarr = self.context.from_global_dim_data(glb_dim_data)
distribution = Distribution(self.context, glb_dim_data)
distarr = DistArray(distribution, dtype=int)
for i in range(rows):
for j in range(cols):
distarr[i, j] = i*cols + j
Expand All @@ -175,7 +178,8 @@ def test_from_global_dim_data_bc(self):
'size': cols,
'block_size': 2,
},)
distarr = self.context.from_global_dim_data(global_dim_data)
distribution = Distribution(self.context, global_dim_data)
distarr = DistArray(distribution, dtype=int)
for i in range(rows):
for j in range(cols):
distarr[i, j] = i*cols + j
Expand All @@ -196,7 +200,8 @@ def test_from_global_dim_data_uu(self):
{'dist_type': 'u',
'indices' : col_indices},
)
distarr = self.context.from_global_dim_data(glb_dim_data)
distribution = Distribution(self.context, glb_dim_data)
distarr = DistArray(distribution, dtype=int)
for i in range(rows):
for j in range(cols):
distarr[i, j] = i*cols + j
Expand Down Expand Up @@ -282,7 +287,8 @@ def test_irregular_block_assignment(self):
'bounds': (0, 2, 6, 7, 9),
}
)
distarr = self.context.from_global_dim_data(global_dim_data)
distribution = Distribution(self.context, global_dim_data)
distarr = DistArray(distribution, dtype=int)
for i in range(global_shape[0]):
for j in range(global_shape[1]):
distarr[i, j] = i + j
Expand Down

0 comments on commit 3211fed

Please sign in to comment.