Exemple #1
0
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
Exemple #2
0
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  
Exemple #3
0
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  
Exemple #4
0
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
Exemple #5
0
def raw_gather(s, nums, d, source, vanilla=0):
    """Wrapper for MPI gather.
     Gather first nums elements in s to d (of the same 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':
        gather_array(s, nums, d, source)
    elif protocol == 'string':
        gather_string(s, nums, d, source)
    elif protocol == 'vanilla':
        raise "Protocol: %s unsupported for gather" % protocol
    else:
        raise "Unknown values for protocol: %s" % protocol

    return d
Exemple #6
0
def raw_gather(s, nums, d, source, vanilla=0):
  """Wrapper for MPI gather.
     Gather first nums elements in s to d (of the same 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':
    gather_array(s, nums, d, source)    
  elif protocol == 'string':
    gather_string(s, nums, d, source)          
  elif protocol == 'vanilla':
    raise "Protocol: %s unsupported for gather" %protocol
  else:
    raise "Unknown values for protocol: %s" %protocol  
    
  return d