Skip to content

Commit

Permalink
Merge pull request #23 from tskisner/fix_tests
Browse files Browse the repository at this point in the history
Attempt to catch unit test failures more reliably
  • Loading branch information
tskisner authored Mar 14, 2024
2 parents 7dbb4ed + 7a265c3 commit 2ca8e38
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
29 changes: 15 additions & 14 deletions pshmem/shmem.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,21 @@ def __init__(self, shape, dtype, comm, comm_node=None, comm_node_rank=None):
print(msg, flush=True)
raise

# Wait for other processes to attach
# Create a numpy array which acts as a view of the buffer.
self._flat = np.ndarray(
self._n,
dtype=self._dtype,
buffer=self._shmem,
)

# Initialize to zero.
if self._noderank == 0:
self._flat[:] = 0

# Wrap
self.data = self._flat.reshape(self._shape)

# Wait for other processes to attach and wrap
if self._nodecomm is not None:
self._nodecomm.barrier()

Expand All @@ -229,19 +243,6 @@ def __init__(self, shape, dtype, comm, comm_node=None, comm_node_rank=None):
print(msg, flush=True)
raise

# Create a numpy array which acts as a view of the buffer.
self._flat = np.ndarray(
self._n,
dtype=self._dtype,
buffer=self._shmem,
)
# Initialize to zero.
if self._noderank == 0:
self._flat[:] = 0

# Wrap
self.data = self._flat.reshape(self._shape)

def __del__(self):
self.close()

Expand Down
18 changes: 17 additions & 1 deletion pshmem/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,25 @@ def test_lock(self):


def run():
comm = None
if MPI is not None:
comm = MPI.COMM_WORLD

suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(LockTest))
suite.addTest(unittest.makeSuite(ShmemTest))
runner = unittest.TextTestRunner()
runner.run(suite)

ret = 0
_ret = runner.run(suite)
if not _ret.wasSuccessful():
ret += 1

if comm is not None:
ret = comm.allreduce(ret, op=MPI.SUM)

if ret > 0:
print(f"{ret} Processes had failures")
sys.exit(6)

return

0 comments on commit 2ca8e38

Please sign in to comment.