def scatter(s, nums, source, vanilla=0): """Wrapper for easy MPI Scatter 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] size = nums if protocol == 'array': import Numeric x = Numeric.zeros(size, typecode) scatter_array(s, size, x, source) elif protocol == 'string': x = ' ' * size scatter_string(s, size, x, source) elif protocol == 'vanilla': raise "Protocol: %s unsupported for scatter" % protocol else: raise "Unknown values for protocol: %s" % protocol return x
def raw_scatter(s, nums, d, source, vanilla=0): """Wrapper for MPI scatter. Scatter the first nums elements in s to processor d (of the same nums size) from source. Automatically determine appropriate protocol and call corresponding send function. The variable s can be any (picklable) type, but Numeric variables and text strings will most efficient. Setting vanilla = 1 forces vanilla mode for any type. """ protocol = get_control_info(s, vanilla)[0] if protocol == 'array': scatter_array(s, nums, d, source) elif protocol == 'string': scatter_string(s, nums, d, source) elif protocol == 'vanilla': raise "Protocol: %s unsupported for scatter" % protocol else: raise "Unknown values for protocol: %s" % protocol return d
def scatter(s, nums, source, vanilla=0): """Wrapper for easy MPI Scatter 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] size = nums if protocol == 'array': import Numeric x = Numeric.zeros(size,typecode) scatter_array(s, size, x, source) elif protocol == 'string': x = ' '*size scatter_string(s, size, x, source) elif protocol == 'vanilla': raise "Protocol: %s unsupported for scatter" %protocol else: raise "Unknown values for protocol: %s" %protocol return x
def raw_scatter(s, nums, d, source, vanilla=0): """Wrapper for MPI scatter. Scatter the first nums elements in s to processor d (of the same nums size) from source. Automatically determine appropriate protocol and call corresponding send function. The variable s can be any (picklable) type, but Numeric variables and text strings will most efficient. Setting vanilla = 1 forces vanilla mode for any type. """ protocol = get_control_info(s, vanilla)[0] if protocol == 'array': scatter_array(s, nums, d, source) elif protocol == 'string': scatter_string(s, nums, d, source) elif protocol == 'vanilla': raise "Protocol: %s unsupported for scatter" %protocol else: raise "Unknown values for protocol: %s" %protocol return d
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