Skip to content

Commit 36b1a0e

Browse files
committed
remove *_to_* methods; nothing was really pushed anyways...
1 parent f2ff331 commit 36b1a0e

File tree

4 files changed

+27
-68
lines changed

4 files changed

+27
-68
lines changed

Diff for: mpisppy/cylinders/cross_scen_spoke.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def make_eta_lb_cut(self):
137137
## this cut -- [ LB, -1, *0s ], i.e., -1*\eta + LB <= 0
138138
all_coefs[row_len*idx] = self._eta_lb_array[idx]
139139
all_coefs[row_len*idx+1] = -1
140-
self.spoke_to_hub(all_coefs, Field.CROSS_SCENARIO_CUT)
140+
self.put_send_buffer(all_coefs, Field.CROSS_SCENARIO_CUT)
141141

142142
def make_cut(self):
143143

@@ -295,7 +295,7 @@ def make_cut(self):
295295
all_coefs[row_len*idx:row_len*(idx+1)] = coef_dict[k]
296296
elif feas_cuts:
297297
all_coefs[row_len*idx:row_len*(idx+1)] = feas_cuts.pop()
298-
self.spoke_to_hub(all_coefs, Field.CROSS_SCENARIO_CUT)
298+
self.put_send_buffer(all_coefs, Field.CROSS_SCENARIO_CUT)
299299

300300
def main(self):
301301
# call main cut generation routine

Diff for: mpisppy/cylinders/hub.py

+6-40
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def extension_send_field(self, field: Field, buf: SendArray):
116116
Send the data in the SendArray `buf` which stores the Field `field`. This will make
117117
the data available to the spokes in this strata.
118118
"""
119-
return self.hub_to_spoke(buf, field)
119+
return self.put_send_buffer(buf, field)
120120

121121
def sync_extension_fields(self):
122122
"""
@@ -307,7 +307,7 @@ def send_boundsout(self):
307307
my_bounds = self.send_buffers[Field.BEST_OBJECTIVE_BOUNDS]
308308
self._populate_boundsout_cache(my_bounds.array())
309309
logging.debug("hub is sending bounds={}".format(my_bounds))
310-
self.hub_to_spoke(my_bounds, Field.BEST_OBJECTIVE_BOUNDS)
310+
self.put_send_buffer(my_bounds, Field.BEST_OBJECTIVE_BOUNDS)
311311
return
312312

313313
def register_receive_fields(self):
@@ -336,38 +336,6 @@ def register_send_fields(self):
336336

337337
return
338338

339-
340-
def hub_to_spoke(self, buf: SendArray, field: Field):
341-
""" Put the specified values into the specified locally-owned buffer
342-
for the spoke to pick up.
343-
344-
Notes:
345-
This automatically updates handles the write id.
346-
"""
347-
return self._hub_to_spoke(buf.array(), field, buf._next_write_id())
348-
349-
350-
def _hub_to_spoke(self, values: np.typing.NDArray, field: Field, write_id: int):
351-
""" Put the specified values into the specified locally-owned buffer
352-
for the spoke to pick up.
353-
354-
Notes:
355-
This automatically does the -1 indexing
356-
357-
This assumes that values contains a slot at the end for the
358-
write_id
359-
"""
360-
361-
if not isinstance(self.opt, APH):
362-
self.cylinder_comm.Barrier()
363-
## End if
364-
365-
values[-1] = write_id
366-
self.window.put(values, field)
367-
368-
return
369-
370-
371339
def hub_from_spoke(self,
372340
buf: RecvArray,
373341
spoke_num: int,
@@ -432,7 +400,7 @@ def send_terminate(self):
432400
processes (don't need to call them one at a time).
433401
"""
434402
self.send_buffers[Field.SHUTDOWN][0] = 1.0
435-
self.hub_to_spoke(self.send_buffers[Field.SHUTDOWN], Field.SHUTDOWN)
403+
self.put_send_buffer(self.send_buffers[Field.SHUTDOWN], Field.SHUTDOWN)
436404
return
437405

438406

@@ -541,8 +509,7 @@ def send_nonants(self):
541509
ci += 1
542510
logging.debug("hub is sending X nonants={}".format(nonant_send_buffer))
543511

544-
# self.hub_to_spoke(nonant_send_buffer.array(), Field.NONANT, nonant_send_buffer.next_write_id())
545-
self.hub_to_spoke(nonant_send_buffer, Field.NONANT)
512+
self.put_send_buffer(nonant_send_buffer, Field.NONANT)
546513

547514
return
548515

@@ -554,8 +521,7 @@ def send_ws(self):
554521
self.opt._populate_W_cache(my_ws.array(), padding=1)
555522
logging.debug("hub is sending Ws={}".format(my_ws.array()))
556523

557-
# self.hub_to_spoke(my_ws.array(), Field.DUALS, my_ws.next_write_id())
558-
self.hub_to_spoke(my_ws, Field.DUALS)
524+
self.put_send_buffer(my_ws, Field.DUALS)
559525

560526
return
561527

@@ -623,7 +589,7 @@ def send_nonants(self):
623589
ci += 1
624590
logging.debug("hub is sending X nonants={}".format(nonant_send_buffer))
625591

626-
self.hub_to_spoke(nonant_send_buffer, Field.NONANT)
592+
self.put_send_buffer(nonant_send_buffer, Field.NONANT)
627593

628594
return
629595

Diff for: mpisppy/cylinders/spcommunicator.py

+18-10
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@ def __setitem__(self, key, value):
8282

8383
def _next_write_id(self) -> int:
8484
"""
85-
Updates the internal id field to the next write id and returns that id
85+
Updates the internal id field to the next write id, uses that id in the field data,
86+
and returns that id
8687
"""
8788
self._id += 1
89+
self._array[-1] = self._id
8890
return self._id
8991

9092

@@ -154,8 +156,6 @@ def __init__(self, spbase_object, fullcomm, strata_comm, cylinder_comm, communic
154156

155157
self.register_receive_fields()
156158

157-
# TODO: check that we have something in receive_field_spcomms??
158-
159159
return
160160

161161
def _make_key(self, field: Field, origin: int):
@@ -236,13 +236,6 @@ def register_send_field(self, field: Field, length: int = -1) -> SendArray:
236236
assert field not in self.send_buffers, "Field {} is already registered".format(field)
237237
if length == -1:
238238
length = self._field_lengths[field]
239-
# if field in self.send_buffers:
240-
# my_fa = self.send_buffers[field]
241-
# assert(length + 1 == np.size(my_fa.array()))
242-
# else:
243-
# my_fa = SendArray(length)
244-
# self.send_buffers[field] = my_fa
245-
# ## End if else
246239
my_fa = SendArray(length)
247240
self.send_buffers[field] = my_fa
248241
return my_fa
@@ -293,6 +286,10 @@ def register_send_fields(self) -> None:
293286
def register_receive_fields(self) -> None:
294287
# print(f"{self.__class__.__name__}: {self.receive_fields=}")
295288
for field in self.receive_fields:
289+
# NOTE: If this list is empty after this method, it is up
290+
# to the caller to raise an error. Sometimes optional
291+
# receive fields are perfectly sensible, and sometimes
292+
# they are nonsensical.
296293
self.receive_field_spcomms[field] = []
297294
for strata_rank, comm in enumerate(self.communicators):
298295
if strata_rank == self.strata_rank:
@@ -301,3 +298,14 @@ def register_receive_fields(self) -> None:
301298
if field in self.ranks_to_fields[strata_rank]:
302299
buff = self.register_recv_field(field, strata_rank)
303300
self.receive_field_spcomms[field].append((strata_rank, cls, buff))
301+
302+
def put_send_buffer(self, buf: SendArray, field: Field):
303+
""" Put the specified values into the specified locally-owned buffer
304+
for the another cylinder to pick up.
305+
306+
Notes:
307+
This automatically updates handles the write id.
308+
"""
309+
buf._next_write_id()
310+
self.window.put(buf.array(), field)
311+
return

Diff for: mpisppy/cylinders/spoke.py

+1-16
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,6 @@ def __init__(self, spbase_object, fullcomm, strata_comm, cylinder_comm, communic
3131

3232
return
3333

34-
def spoke_to_hub(self, buf: SendArray, field: Field):
35-
""" Put the specified values into the locally-owned buffer for the hub
36-
to pick up.
37-
38-
Notes:
39-
Automatically handles write id updating and setting
40-
"""
41-
return self._spoke_to_hub(buf.array(), field, buf._next_write_id())
42-
43-
def _spoke_to_hub(self, values: np.typing.NDArray, field: Field, write_id: int):
44-
self.cylinder_comm.Barrier()
45-
values[-1] = write_id
46-
self.window.put(values, field)
47-
return
48-
4934
def spoke_from_hub(self,
5035
buf: RecvArray,
5136
field: Field,
@@ -172,7 +157,7 @@ def bound(self):
172157
def bound(self, value):
173158
self._append_trace(value)
174159
self._bound[0] = value
175-
self.spoke_to_hub(self._bound, self.bound_type())
160+
self.put_send_buffer(self._bound, self.bound_type())
176161
return
177162

178163
@property

0 commit comments

Comments
 (0)