Skip to content

Commit 62a3da9

Browse files
committed
cleaning up windows; errata
1 parent 3948b2f commit 62a3da9

File tree

5 files changed

+12
-29
lines changed

5 files changed

+12
-29
lines changed

Diff for: mpisppy/cylinders/cross_scen_spoke.py

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def register_send_fields(self) -> None:
4848

4949
def register_receive_fields(self):
5050
super().register_receive_fields()
51+
# TODO: look up rank
5152
self.all_nonants = self.register_recv_field(Field.NONANT, 0)
5253
self.all_etas = self.register_recv_field(Field.CROSS_SCENARIO_COST, 0)
5354

Diff for: mpisppy/cylinders/reduced_costs_spoke.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
class ReducedCostsSpoke(LagrangianOuterBound):
1717

18-
send_fields = (*LagrangianOuterBound.send_fields, Field.EXPECTED_REDUCED_COST, Field.SCENARIO_REDUCED_COST ,)
18+
send_fields = (*LagrangianOuterBound.send_fields, Field.EXPECTED_REDUCED_COST, Field.SCENARIO_REDUCED_COST,)
1919
receive_fields = (*LagrangianOuterBound.receive_fields,)
2020

2121
converger_spoke_char = 'R'

Diff for: mpisppy/cylinders/spcommunicator.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ def __setitem__(self, key, value):
8383

8484
def _next_write_id(self) -> int:
8585
"""
86-
Updates the internal id field to the next write id, uses that id in the field data,
87-
and returns that id
86+
Updates the internal id field to the next write id, sets that id in the
87+
field data array, and returns that id
8888
"""
8989
self._id += 1
9090
self._array[-1] = self._id
@@ -220,13 +220,6 @@ def _validate_recv_field(self, field: Field, origin: int, length: int):
220220

221221
def register_recv_field(self, field: Field, origin: int, length: int = -1) -> RecvArray:
222222
# print(f"{self.__class__.__name__}.register_recv_field, {field=}, {origin=}")
223-
# TODO: better handle this case...
224-
if origin == -1:
225-
origin = self.fields_to_ranks[field][0]
226-
if len(self.fields_to_ranks[field]) > 1:
227-
raise RuntimeError(f"Non-unique origin for {field=}. Possible "
228-
f"origins are {self.fields_to_ranks[field]=}.")
229-
230223
key = self._make_key(field, origin)
231224
if length == -1:
232225
length = self._field_lengths[field]

Diff for: mpisppy/cylinders/spwindow.py

+3-16
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import numpy.typing as nptyping
1414

1515
import enum
16+
import weakref
1617

1718
import pyomo.environ as pyo
1819

@@ -110,6 +111,8 @@ def __init__(self, my_fields: dict, strata_comm: MPI.Comm, field_order=None):
110111

111112
self.buffer_length = total_buffer_length
112113
self.window = MPI.Win.Allocate(window_size_bytes, MPI.DOUBLE.size, comm=strata_comm)
114+
# ensure the memory allocated for the window is freed
115+
self._window_finalizer = weakref.finalize(self, self.window.free)
113116
self.buff = np.ndarray(dtype="d", shape=(total_buffer_length,), buffer=self.window.tomemory())
114117
self.buff[:] = np.nan
115118

@@ -121,22 +124,6 @@ def __init__(self, my_fields: dict, strata_comm: MPI.Comm, field_order=None):
121124

122125
self.strata_buffer_layouts = strata_comm.allgather(self.buffer_layout)
123126

124-
self.window_constructed = True
125-
126-
return
127-
128-
def free(self):
129-
130-
if self.window_constructed:
131-
self.window.Free()
132-
self.buff = None
133-
self.buffer_layout = None
134-
self.buffer_length = 0
135-
self.window = None
136-
self.strata_buffer_layouts = None
137-
self.window_constructed = False
138-
## End if
139-
140127
return
141128

142129
#### Functions ####

Diff for: mpisppy/extensions/reduced_costs_fixer.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,15 @@ def register_receive_fields(self):
109109
Field.OBJECTIVE_OUTER_BOUND,
110110
self.reduced_costs_spoke_index,
111111
)
112-
## End if
113112

114113
return
115114

116115
def sync_with_spokes(self, pre_iter0 = False):
117-
# TODO: if we calculate the new bounds in the spoke we don't need to check if the buffers
118-
# have the same ID
116+
# TODO: If we calculate the new bounds in the spoke we don't need to
117+
# check if the buffers have the same ID.
118+
# NOTE: If we do this, then the heuristic reduced cost fixing might fix
119+
# different variables in different subproblems. But this might be
120+
# fine.
119121
self.opt.spcomm.get_receive_buffer(
120122
self.reduced_cost_buf,
121123
Field.EXPECTED_REDUCED_COST,

0 commit comments

Comments
 (0)