def gather(s, nums, source, vanilla=0): """Wrapper for easy MPI Gather receive. Receive data from source with tag. Create appropriate buffer and receive data. """ control_info = get_control_info(s) protocol = control_info[0] typecode = control_info[1] s_size = nums if protocol == 'array': import Numeric x = Numeric.zeros(s_size * size(),typecode) gather_array(s, s_size, x, source) elif protocol == 'string': x = ' '*s_size*size() gather_string(s, s_size, x, source) elif protocol == 'vanilla': raise "Protocol: %s unsupported for gather" %protocol else: raise "Unknown values for protocol: %s" %protocol return x
def gather(s, nums, source, vanilla=0): """Wrapper for easy MPI Gather receive. Receive data from source with tag. Create appropriate buffer and receive data. """ control_info = get_control_info(s) protocol = control_info[0] typecode = control_info[1] s_size = nums if protocol == 'array': import Numeric x = Numeric.zeros(s_size * size(), typecode) gather_array(s, s_size, x, source) elif protocol == 'string': x = ' ' * s_size * size() gather_string(s, s_size, x, source) elif protocol == 'vanilla': raise "Protocol: %s unsupported for gather" % protocol else: raise "Unknown values for protocol: %s" % protocol return x
def reduce(x, op, root, buffer=None, vanilla=0): """Reduce elements in x to buffer (of the same size as x) at root applying operation op elementwise. """ import types from mpiext import size numproc = size() #Needed to determine buffer size #Input check errmsg = 'Root id (%s) must be an integer.' % root assert type(root) == types.IntType, errmsg #Create metadata about object protocol, typecode, size, shape = create_control_info(x) #Reduce if protocol == 'array': if buffer is None: import Numeric buffer = Numeric.zeros(size * numproc, typecode) # Modify shape along axis=0 to match size shape = list(shape) shape[0] *= numproc buffer = Numeric.reshape(buffer, shape) reduce_array(x, buffer, op, root) elif (protocol == 'vanilla' or protocol == 'string'): raise 'Protocol: %s unsupported for reduce' % protocol else: raise 'Unknown protocol: %s' % protocol return buffer
def reduce(x, op, root, buffer=None, vanilla=0, bypass=False): """Reduce elements in x to buffer (of the same size as x) at root applying operation op elementwise. If bypass is True, all admin and error checks get bypassed to reduce the latency. The buffer must be specified explicitly in this case. """ if bypass: reduce_array(x, buffer, op, root) return import types from mpiext import size numproc = size() # Needed to determine buffer size # Input check errmsg = 'Root id (%s) must be an integer.' % root assert type(root) == types.IntType, errmsg # Create metadata about object protocol, typecode, size, shape = create_control_info(x) # Reduce if protocol == 'array': if buffer is None: buffer = zeros(size*numproc, typecode) # Modify shape along axis=0 to match size shape = list(shape) shape[0] *= numproc buffer = reshape(buffer, shape) msg = 'Data array and buffer must have same type ' msg = 'in reduce. I got types "%s" and "%s"' % (x.dtype.char, buffer.dtype.char) assert x.dtype.char == buffer.dtype.char, msg reduce_array(x, buffer, op, root) elif (protocol == 'vanilla' or protocol == 'string'): raise 'Protocol: %s unsupported for reduce' % protocol else: raise 'Unknown protocol: %s' % protocol return buffer
def scatter(x, root, buffer=None, vanilla=False): """Sends data x from process with rank root to all other processes. Create appropriate buffer and receive data. Return scattered result (same type as x) Scatter makes only sense for arrays or strings """ import types from mpiext import size numproc = size() #Needed to determine buffer size #Input check errmsg = 'Root id (%s) must be an integer.' %root assert type(root) == types.IntType, errmsg #Create metadata about object to be sent protocol, typecode, size, shape = create_control_info(x) #Scatter if protocol == 'array': if buffer is None: import Numeric # Modify shape along axis=0 to match size shape = list(shape) shape[0] /= numproc count = Numeric.product(shape) buffer = Numeric.zeros(count, typecode) buffer = Numeric.reshape(buffer, shape) scatter_array(x, buffer, root) elif protocol == 'string': if buffer is None: buffer = ' '*(size/numproc) scatter_string(x, buffer, root) elif protocol == 'vanilla': errmsg = 'Scatter is only supported for Numeric arrays and strings.\n' errmsg += 'If you wish to distribute a general sequence, ' errmsg += 'please use send and receive commands or broadcast.' raise errmsg else: raise 'Unknown protocol: %s' %protocol return buffer
def scatter(x, root, buffer=None, vanilla=False): """Sends data x from process with rank root to all other processes. Create appropriate buffer and receive data. Return scattered result (same type as x) Scatter makes only sense for arrays or strings """ import types from mpiext import size numproc = size() #Needed to determine buffer size #Input check errmsg = 'Root id (%s) must be an integer.' % root assert type(root) == types.IntType, errmsg #Create metadata about object to be sent protocol, typecode, size, shape = create_control_info(x) #Scatter if protocol == 'array': if buffer is None: import Numeric # Modify shape along axis=0 to match size shape = list(shape) shape[0] /= numproc count = Numeric.product(shape) buffer = Numeric.zeros(count, typecode) buffer = Numeric.reshape(buffer, shape) scatter_array(x, buffer, root) elif protocol == 'string': if buffer is None: buffer = ' ' * (size / numproc) scatter_string(x, buffer, root) elif protocol == 'vanilla': errmsg = 'Scatter is only supported for Numeric arrays and strings.\n' errmsg += 'If you wish to distribute a general sequence, ' errmsg += 'please use send and receive commands or broadcast.' raise errmsg else: raise 'Unknown protocol: %s' % protocol return buffer
def reduce(x, op, root, buffer=None, vanilla=0, bypass=False): """Reduce elements in x to buffer (of the same size as x) at root applying operation op elementwise. If bypass is True, all admin and error checks get bypassed to reduce the latency. The buffer must be specified explicitly in this case. """ if bypass: reduce_array(x, buffer, op, root) return import types from mpiext import size numproc = size() # Needed to determine buffer size # Input check errmsg = 'Root id (%s) must be an integer.' % root assert type(root) == types.IntType, errmsg # Create metadata about object protocol, typecode, size, shape = create_control_info(x) # Reduce if protocol == 'array': if buffer is None: buffer = zeros(size * numproc, typecode) # Modify shape along axis=0 to match size shape = list(shape) shape[0] *= numproc buffer = reshape(buffer, shape) msg = 'Data array and buffer must have same type ' msg = 'in reduce. I got types "%s" and "%s"' % (x.dtype.char, buffer.dtype.char) assert x.dtype.char == buffer.dtype.char, msg reduce_array(x, buffer, op, root) elif (protocol == 'vanilla' or protocol == 'string'): raise 'Protocol: %s unsupported for reduce' % protocol else: raise 'Unknown protocol: %s' % protocol return buffer
def gather(x, root, buffer=None, vanilla=0): """Gather values from all processes to root Create appropriate buffer and receive data. Gather only makes sens for arrays or strings """ import types from mpiext import size numproc = size() #Needed to determine buffer size #Input check errmsg = 'Root id (%s) must be an integer.' % root assert type(root) == types.IntType, errmsg #Create metadata about object to be gathered protocol, typecode, size, shape = create_control_info(x) #Gather if protocol == 'array': if buffer is None: import Numeric buffer = Numeric.zeros(size * numproc, typecode) # Modify shape along axis=0 to match size shape = list(shape) shape[0] *= numproc buffer = Numeric.reshape(buffer, shape) gather_array(x, buffer, root) elif protocol == 'string': if buffer is None: buffer = ' ' * size * numproc gather_string(x, buffer, root) elif protocol == 'vanilla': errmsg = 'Gather is only supported for Numeric arrays and strings.\n' errmsg += 'If you wish to distribute a general sequence, ' errmsg += 'please use send and receive commands or broadcast.' raise errmsg else: raise 'Unknown protocol: %s' % protocol return buffer
def gather(x, root, buffer=None, vanilla=0): """Gather values from all processes to root Create appropriate buffer and receive data. Gather only makes sens for arrays or strings """ import types from mpiext import size numproc = size() #Needed to determine buffer size #Input check errmsg = 'Root id (%s) must be an integer.' %root assert type(root) == types.IntType, errmsg #Create metadata about object to be gathered protocol, typecode, size, shape = create_control_info(x) #Gather if protocol == 'array': if buffer is None: import Numeric buffer = Numeric.zeros(size*numproc, typecode) # Modify shape along axis=0 to match size shape = list(shape) shape[0] *= numproc buffer = Numeric.reshape(buffer, shape) gather_array(x, buffer, root) elif protocol == 'string': if buffer is None: buffer = ' '*size*numproc gather_string(x, buffer, root) elif protocol == 'vanilla': errmsg = 'Gather is only supported for Numeric arrays and strings.\n' errmsg += 'If you wish to distribute a general sequence, ' errmsg += 'please use send and receive commands or broadcast.' raise errmsg else: raise 'Unknown protocol: %s' %protocol return buffer
def reduce(x, op, root, buffer=None, vanilla=0): """Reduce elements in x to buffer (of the same size as x) at root applying operation op elementwise. """ import types from mpiext import size numproc = size() #Needed to determine buffer size #Input check errmsg = 'Root id (%s) must be an integer.' %root assert type(root) == types.IntType, errmsg #Create metadata about object protocol, typecode, size, shape = create_control_info(x) #Reduce if protocol == 'array': if buffer is None: import Numeric buffer = Numeric.zeros(size*numproc, typecode) # Modify shape along axis=0 to match size shape = list(shape) shape[0] *= numproc buffer = Numeric.reshape(buffer, shape) reduce_array(x, buffer, op, root) elif (protocol == 'vanilla' or protocol == 'string'): raise 'Protocol: %s unsupported for reduce' %protocol else: raise 'Unknown protocol: %s' %protocol return buffer
# (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License (http://www.gnu.org/copyleft/gpl.html) # for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # # # Contact addresses: [email protected], [email protected] # ============================================================================= """Module pypar.py - Parallel Python using MPI Public functions: size() -- Number of processors rank() -- Id of current processor Get_processor_name() -- Return host name of current node send() -- Blocking send (all types) receive() -- Blocking receive (all types) raw_send() -- Blocking send (Numeric arrays and strings) raw_receive() -- Blocking receive (Numeric arrays and strings) bcast() -- Broadcast Wtime() -- MPI wall time Barrier() -- Synchronisation point. Makes processors wait until all processors have reached this point.
# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License (http://www.gnu.org/copyleft/gpl.html) # for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # # # Contact address: [email protected] # # Version: See pypar.__version__ # ============================================================================= """Module pypar.py - Parallel Python using MPI Public functions: size() -- Number of processors rank() -- Id of current processor get_processor_name() -- Return host name of current node send() -- Blocking send (all types) receive() -- Blocking receive (all types) broadcast() -- Broadcast time() -- MPI wall time barrier() -- Synchronisation point. Makes processors wait until all processors have reached this point. abort() -- Terminate all processes. finalize() -- Cleanup MPI. No parallelism can take place after this point.
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License (http://www.gnu.org/copyleft/gpl.html) # for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # # # Contact address: [email protected] # # Version: See pypar.__version__ # ============================================================================= """Module pypar.py - Parallel Python using MPI Public functions: size() -- Number of processors rank() -- Id of current processor get_processor_name() -- Return host name of current node send() -- Blocking send (all types) receive() -- Blocking receive (all types) broadcast() -- Broadcast time() -- MPI wall time barrier() -- Synchronisation point. Makes processors wait until all processors have reached this point. abort() -- Terminate all processes. finalize() -- Cleanup MPI. No parallelism can take place after this point.
""" Pypar - Parallel Python using MPI Public functions: size() -- Number of processors rank() -- Id of current processor get_processor_name() -- Return host name of current node send() -- Blocking send (all types) receive() -- Blocking receive (all types) broadcast() -- Broadcast time() -- MPI wall time barrier() -- Synchronisation point. Makes processors wait until all processors have reached this point. abort() -- Terminate all processes. finalize() -- Cleanup MPI. No parallelism can take place after this point. See doc strings of individual functions for detailed documentation. """ from numpy import zeros, reshape, product import types import string #---------- # Constants #----------
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License (http://www.gnu.org/copyleft/gpl.html) # for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # # # Contact addresses: [email protected], [email protected] # # version 1.6, 18 October 2002 # ============================================================================= """Module pypar.py - Parallel Python using MPI Public functions: size() -- Number of processors rank() -- Id of current processor Get_processor_name() -- Return host name of current node send() -- Blocking send (all types) receive() -- Blocking receive (all types) raw_send() -- Blocking send (Numeric arrays and strings) raw_receive() -- Blocking receive (Numeric arrays and strings) bcast() -- Broadcast Wtime() -- MPI wall time Barrier() -- Synchronisation point. Makes processors wait until all processors have reached this point.