def Sendrecv(self, sendbuf, dest=0, sendtag=0, recvbuf=None, source=0, recvtag=0, status=None): sendbuf, sfastmode = _mpi.make_buf(sendbuf) recvbuf, rfastmode = _mpi.make_buf(recvbuf) if sfastmode or rfastmode: _mpi.sendrecv(sendbuf, dest, sendtag, recvbuf, source, recvtag, self, status) return else: serializer = self.SERIALIZER if dest != _mpi.PROC_NULL: sendbuf = serializer.dump(sendbuf) else: sendbuf = None recvbuf = _mpi.sendrecv_string(sendbuf, dest, sendtag, recvbuf, source, recvtag, self, status) if recvbuf is not None: recvbuf = serializer.load(recvbuf) return recvbuf
def Alltoall(self, sendbuf, recvbuf=None): sendbuf, sfastmode = _mpi.make_buf(sendbuf) recvbuf, rfastmode = _mpi.make_buf(recvbuf) if sfastmode or rfastmode: _mpi.alltoall(sendbuf, recvbuf, self) return None else: serializer = self.SERIALIZER sendbuf = map(serializer.dump, sendbuf) recvbuf = _mpi.alltoall_string(sendbuf, recvbuf, self) recvbuf = map(serializer.load, recvbuf) return recvbuf
def Alltoall(self, sendbuf, recvbuf = None): sendbuf, sfastmode = _mpi.make_buf(sendbuf) recvbuf, rfastmode = _mpi.make_buf(recvbuf) if sfastmode or rfastmode: _mpi.alltoall(sendbuf, recvbuf, self) return None else: serializer = self.SERIALIZER sendbuf = map(serializer.dump, sendbuf) recvbuf = _mpi.alltoall_string(sendbuf, recvbuf, self) recvbuf = map(serializer.load, recvbuf) return recvbuf
def Reduce(self, sendbuf, recvbuf=None, op=SUM, root=0): sendbuf, sfastmode = _mpi.make_buf(sendbuf) recvbuf, rfastmode = _mpi.make_buf(recvbuf) if sfastmode or rfastmode: _mpi.reduce(sendbuf, recvbuf, op, root, self) return else: recvbuf = self.Gather(sendbuf, None, root) if recvbuf is not None: if op in (MAXLOC, MINLOC): recvbuf = zip(recvbuf, xrange(len(recvbuf))) recvbuf = reduce(op, recvbuf) return recvbuf
def Reduce(self, sendbuf, recvbuf = None, op = SUM, root = 0): sendbuf, sfastmode = _mpi.make_buf(sendbuf) recvbuf, rfastmode = _mpi.make_buf(recvbuf) if sfastmode or rfastmode: _mpi.reduce(sendbuf, recvbuf, op, root, self) return else: recvbuf = self.Gather(sendbuf, None, root) if recvbuf is not None: if op in (MAXLOC, MINLOC): recvbuf = zip(recvbuf, xrange(len(recvbuf))) recvbuf = reduce(op, recvbuf) return recvbuf
def Allreduce(self, sendbuf, recvbuf = None, op = SUM): sendbuf, sfastmode = _mpi.make_buf(sendbuf) recvbuf, rfastmode = _mpi.make_buf(recvbuf) if sfastmode or rfastmode: _mpi.allreduce(sendbuf, recvbuf, op, self) return None else: serializer = self.SERIALIZER sendbuf = serializer.dump(sendbuf) recvbuf = _mpi.allgather_string(sendbuf, recvbuf, self) recvbuf = map(serializer.load, recvbuf) if op in (MAXLOC, MINLOC): recvbuf = zip(recvbuf, xrange(len(recvbuf))) recvbuf = reduce(op, recvbuf) return recvbuf
def Allreduce(self, sendbuf, recvbuf=None, op=SUM): sendbuf, sfastmode = _mpi.make_buf(sendbuf) recvbuf, rfastmode = _mpi.make_buf(recvbuf) if sfastmode or rfastmode: _mpi.allreduce(sendbuf, recvbuf, op, self) return None else: serializer = self.SERIALIZER sendbuf = serializer.dump(sendbuf) recvbuf = _mpi.allgather_string(sendbuf, recvbuf, self) recvbuf = map(serializer.load, recvbuf) if op in (MAXLOC, MINLOC): recvbuf = zip(recvbuf, xrange(len(recvbuf))) recvbuf = reduce(op, recvbuf) return recvbuf
def Scan(self, sendbuf, recvbuf = None, op = SUM): sendbuf, sfastmode = _mpi.make_buf(sendbuf) recvbuf, rfastmode = _mpi.make_buf(recvbuf) if sfastmode or rfastmode: _mpi.scan(sendbuf, recvbuf, op, self) return None else: recvbuf = self.Gather(sendbuf, root=0) if _mpi.comm_rank(self) == 0: if op in (MAXLOC, MINLOC): recvbuf = zip(recvbuf, xrange(len(recvbuf))) for i in xrange(1, len(recvbuf)): recvbuf[i] = op(recvbuf[i - 1], recvbuf[i]) recvbuf = self.Scatter(recvbuf, root=0) return recvbuf
def Sendrecv(self, sendbuf, dest = 0, sendtag = 0, recvbuf = None, source = 0, recvtag = 0, status = None): sendbuf, sfastmode = _mpi.make_buf(sendbuf) recvbuf, rfastmode = _mpi.make_buf(recvbuf) if sfastmode or rfastmode: _mpi.sendrecv(sendbuf, dest, sendtag, recvbuf, source, recvtag, self, status) return else: serializer = self.SERIALIZER if dest != _mpi.PROC_NULL: sendbuf = serializer.dump(sendbuf) else: sendbuf = None recvbuf = _mpi.sendrecv_string(sendbuf, dest, sendtag, recvbuf, source, recvtag, self, status) if recvbuf is not None: recvbuf = serializer.load(recvbuf) return recvbuf
def Scan(self, sendbuf, recvbuf=None, op=SUM): sendbuf, sfastmode = _mpi.make_buf(sendbuf) recvbuf, rfastmode = _mpi.make_buf(recvbuf) if sfastmode or rfastmode: _mpi.scan(sendbuf, recvbuf, op, self) return None else: recvbuf = self.Gather(sendbuf, root=0) if _mpi.comm_rank(self) == 0: if op in (MAXLOC, MINLOC): recvbuf = zip(recvbuf, xrange(len(recvbuf))) for i in xrange(1, len(recvbuf)): recvbuf[i] = op(recvbuf[i - 1], recvbuf[i]) recvbuf = self.Scatter(recvbuf, root=0) return recvbuf
def Gather(self, sendbuf, recvbuf=None, root=0): sendbuf, sfastmode = _mpi.make_buf(sendbuf) recvbuf, rfastmode = _mpi.make_buf(recvbuf) if sfastmode or rfastmode: _mpi.gather(sendbuf, recvbuf, root, self) return else: serializer = self.SERIALIZER if _mpi.comm_test_inter(self): if root != _mpi.ROOT and root != _mpi.PROC_NULL: sendbuf = serializer.dump(sendbuf) else: sendbuf = None else: sendbuf = serializer.dump(sendbuf) recvbuf = _mpi.gather_string(sendbuf, recvbuf, root, self) if recvbuf is not None: recvbuf = map(serializer.load, recvbuf) return recvbuf
def Recv(self, buf=None, source=0, tag=0, status=None): buf, fastmode = _mpi.make_buf(buf) if fastmode: _mpi.recv(buf, source, tag, self, status) return None else: buf = _mpi.recv_string(buf, source, tag, self, status) if source != _mpi.PROC_NULL: buf = self.SERIALIZER.load(buf) return buf
def Recv(self, buf = None, source = 0, tag = 0, status = None): buf, fastmode = _mpi.make_buf(buf) if fastmode: _mpi.recv(buf, source, tag, self, status) return None else: buf = _mpi.recv_string(buf, source, tag, self, status) if source != _mpi.PROC_NULL: buf = self.SERIALIZER.load(buf) return buf
def Gather(self, sendbuf, recvbuf = None, root = 0): sendbuf, sfastmode = _mpi.make_buf(sendbuf) recvbuf, rfastmode = _mpi.make_buf(recvbuf) if sfastmode or rfastmode: _mpi.gather(sendbuf, recvbuf, root, self) return else: serializer = self.SERIALIZER if _mpi.comm_test_inter(self): if root != _mpi.ROOT and root != _mpi.PROC_NULL: sendbuf = serializer.dump(sendbuf) else: sendbuf = None else: sendbuf = serializer.dump(sendbuf) recvbuf = _mpi.gather_string(sendbuf, recvbuf, root, self) if recvbuf is not None: recvbuf = map(serializer.load, recvbuf) return recvbuf
def Scatter(self, sendbuf=None, recvbuf=None, root=0): sendbuf, sfastmode = _mpi.make_buf(sendbuf) recvbuf, rfastmode = _mpi.make_buf(recvbuf) if sfastmode or rfastmode: _mpi.scatter(sendbuf, recvbuf, root, self) return else: serializer = self.SERIALIZER if _mpi.comm_test_inter(self): if root == _mpi.ROOT: sendbuf = map(serializer.dump, sendbuf) else: sendbuf = None elif root == _mpi.comm_rank(self): sendbuf = map(serializer.dump, sendbuf) else: sendbuf = None recvbuf = _mpi.scatter_string(sendbuf, recvbuf, root, self) if recvbuf is not None: recvbuf = serializer.load(recvbuf) return recvbuf
def Scatter(self, sendbuf = None, recvbuf = None, root = 0): sendbuf, sfastmode = _mpi.make_buf(sendbuf) recvbuf, rfastmode = _mpi.make_buf(recvbuf) if sfastmode or rfastmode: _mpi.scatter(sendbuf, recvbuf, root, self) return else: serializer = self.SERIALIZER if _mpi.comm_test_inter(self): if root == _mpi.ROOT: sendbuf = map(serializer.dump, sendbuf) else: sendbuf = None elif root == _mpi.comm_rank(self): sendbuf = map(serializer.dump, sendbuf) else: sendbuf = None recvbuf = _mpi.scatter_string(sendbuf, recvbuf, root, self) if recvbuf is not None: recvbuf = serializer.load(recvbuf) return recvbuf
def Send(self, buf, dest=0, tag=0): buf, fastmode = _mpi.make_buf(buf) if fastmode: _mpi.send(buf, dest, tag, self) return else: if dest != _mpi.PROC_NULL: buf = self.SERIALIZER.dump(buf) else: buf = None _mpi.send_string(buf, dest, tag, self) return
def Send(self, buf, dest = 0, tag = 0): buf, fastmode = _mpi.make_buf(buf) if fastmode: _mpi.send(buf, dest, tag, self) return else: if dest != _mpi.PROC_NULL: buf = self.SERIALIZER.dump(buf) else: buf = None _mpi.send_string(buf, dest, tag, self) return
def Bcast(self, buf = None, root = 0): buf, fastmode = _mpi.make_buf(buf) if fastmode: _mpi.bcast(buf, root, self) return else: serializer = self.SERIALIZER if _mpi.comm_test_inter(self): if root == _mpi.ROOT: buf = serializer.dump(buf) else: buf = None elif root == _mpi.comm_rank(self): buf = serializer.dump(buf) else: buf = None buf = _mpi.bcast_string(buf, root, self) if buf is not None: buf = serializer.load(buf) return buf
def Bcast(self, buf=None, root=0): buf, fastmode = _mpi.make_buf(buf) if fastmode: _mpi.bcast(buf, root, self) return else: serializer = self.SERIALIZER if _mpi.comm_test_inter(self): if root == _mpi.ROOT: buf = serializer.dump(buf) else: buf = None elif root == _mpi.comm_rank(self): buf = serializer.dump(buf) else: buf = None buf = _mpi.bcast_string(buf, root, self) if buf is not None: buf = serializer.load(buf) return buf