Skip to content

Commit

Permalink
refactor: remove print statements in favour of logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jrs65 committed Mar 11, 2020
1 parent 6743098 commit e9a355c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 26 deletions.
12 changes: 6 additions & 6 deletions caput/mpiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
for ri in range(mpiutil.size):
if ri == mpiutil.rank:
print ri, arr
print(ri, arr)
mpiutil.barrier()
# Use a global index to assign to the array
Expand All @@ -87,7 +87,7 @@
# This should be the third column of the array
for ri in range(mpiutil.size):
if ri == mpiutil.rank:
print ri, arr2
print(ri, arr2)
mpiutil.barrier()
# Fetch a view of the whole array with a partial slice
Expand All @@ -96,7 +96,7 @@
# The final two ranks should be None
for ri in range(mpiutil.size):
if ri == mpiutil.rank:
print ri, arr3
print(ri, arr3)
mpiutil.barrier()
"""
Expand Down Expand Up @@ -518,7 +518,7 @@ def redistribute(self, axis):
request.Wait(status=stat)

if stat.error != mpiutil.MPI.SUCCESS:
print(
logger.error(
"**** ERROR in MPI SEND (r: %i c: %i rank: %i) *****".format(
ir, ic, self.comm.rank
)
Expand All @@ -535,7 +535,7 @@ def redistribute(self, axis):
request.Wait(status=stat)

if stat.error != mpiutil.MPI.SUCCESS:
print(
logger.error(
"**** ERROR in MPI RECV (r: %i c: %i rank: %i) *****".format(
ir, ir, self.comm.rank
)
Expand Down Expand Up @@ -875,7 +875,7 @@ def gather(self, rank=0):
request.Wait(status=stat)

if stat.error != mpiutil.MPI.SUCCESS:
print(
logger.error(
"**** ERROR in MPI RECV (source: %i, dest rank: %i) *****"
% (ri, rank)
)
Expand Down
23 changes: 6 additions & 17 deletions caput/mpiutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

# === End Python 2/3 compatibility

import logging
import sys
import time
import warnings
Expand All @@ -55,6 +56,8 @@
world = None
rank0 = True

logger = logging.getLogger(__name__)

## Try to setup MPI and get the comm, rank and size.
## If not they should end up as rank=0, size=1.
try:
Expand All @@ -67,7 +70,7 @@
size = _comm.Get_size()

if _comm is not None and size > 1:
print("Starting MPI rank=%i [size=%i]" % (rank, size))
logger.debug("Starting MPI rank=%i [size=%i]", rank, size)

rank0 = True if rank == 0 else False

Expand Down Expand Up @@ -514,8 +517,6 @@ def transpose_blocks(row_array, shape, comm=_comm):
par, sar, ear = split_all(nr, comm=comm) * nm
pac, sac, eac = split_all(nc, comm=comm)

# print pr, nc, shape, row_array.shape

row_array = row_array[:nr, ..., :nc].reshape(pr, nc)

requests_send = []
Expand Down Expand Up @@ -546,7 +547,6 @@ def transpose_blocks(row_array, shape, comm=_comm):
# Construct the block to send by cutting out the correct
# columns
block = row_array[:, sic:eic].copy()
# print ir, ic, comm.rank, block.shape

# Send the message
request = comm.Isend([block, mpitype], dest=ic, tag=tag)
Expand All @@ -559,7 +559,6 @@ def transpose_blocks(row_array, shape, comm=_comm):
[recv_buffer[sir:eir], mpitype], source=ir, tag=tag
)
requests_recv.append([ir, ic, request])
# print ir, ic, comm.rank, recv_buffer[sir:eir].shape

# Wait for all processes to have started their messages
comm.Barrier()
Expand All @@ -569,34 +568,25 @@ def transpose_blocks(row_array, shape, comm=_comm):

stat = MPI.Status()

# try:
request.Wait(status=stat)
# except MPI.Exception:
# print comm.rank, ir, ic, sar[ir], ear[ir], sac[ic], eac[ic], shape

if stat.error != MPI.SUCCESS:
print(
logger.error(
"**** ERROR in MPI SEND (r: %i c: %i rank: %i) *****"
% (ir, ic, comm.rank)
)

# print "rank %i: Done waiting on MPI SEND" % comm.rank

comm.Barrier()

# For each frequency iterate over all receives and wait until completion
for ir, ic, request in requests_recv:

stat = MPI.Status()

# try:
request.Wait(status=stat)
# except MPI.Exception:
# print comm.rank, (ir, ic), (ear[ir]-sar[ir], eac[ic]-sac[ic]),
# shape, recv_buffer[sar[ir]:ear[ir]].shape, recv_buffer.dtype, row_array.dtype

if stat.error != MPI.SUCCESS:
print(
logger.error(
"**** ERROR in MPI RECV (r: %i c: %i rank: %i) *****"
% (ir, ir, comm.rank)
)
Expand Down Expand Up @@ -742,7 +732,6 @@ def __getattr__(self, name):
raise AttributeError("module 'mpiutil' has no attribute '%s'" % name)

def __call__(self, **kwargs):
# print 'here'
return SelfWrapper(self.self_module, kwargs)


Expand Down
3 changes: 0 additions & 3 deletions caput/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,9 +857,6 @@ def _pipeline_advance_state(self):
# can be queued.
for in_, in_key in zip(self._in, self._in_keys):
if not in_.empty():
# XXX Clean up.
print("Something left: %i" % in_.qsize())

msg = (
"Task finished %s iterating `next()` but input queue '%s' isn't empty."
% (self.__class__.__name__, in_key)
Expand Down

0 comments on commit e9a355c

Please sign in to comment.