Пример #1
0
def send(x,
         destination,
         use_buffer=False,
         vanilla=False,
         tag=default_tag,
         bypass=False):
    """Wrapper for easy MPI send.
       Send x to destination.
       
       Automatically determine appropriate protocol
       and call corresponding send function.
       Also passes type and size information on as preceding message to
       simplify the receive call.
       
       The variable x can be any (picklable) type, but
       numpy variables and text strings will most efficient.
       Setting vanilla = 1 forces vanilla mode for any type.

       If use_buffer is True, workspace x will be used for the return value.
       In this case the corresponding receive call must specify a buffer.
       Otherwise a new workspace will be created by receive.

       If bypass is True, all admin and error checks
       get bypassed to reduce the latency. Should only
       be used for sending numpy arrays and should be matched
       with a bypass in the corresponding receive command.

    """
    import types, string

    if bypass:
        send_array(x, destination, tag)
        return

    # Input check
    errmsg = 'Destination id (%s) must be an integer.' % destination
    assert type(destination) == types.IntType, errmsg

    errmsg = 'Tag %d is reserved by pypar - please use another.' % control_tag
    assert tag != control_tag, errmsg

    # Create metadata about object to be sent
    control_info, x = create_control_info(x, vanilla, return_object=True)
    protocol = control_info[0]

    # Possibly transmit control data
    if use_buffer is False:
        send_control_info(control_info, destination)

    # Transmit payload data
    if protocol == 'array':
        send_array(x, destination, tag)
    elif protocol in ['string', 'vanilla']:
        send_string(x, destination, tag)
    else:
        raise 'Unknown protocol: %s' % protocol
Пример #2
0
def send(x, destination, use_buffer=False, vanilla=False,
         tag=default_tag, bypass=False):
    """Wrapper for easy MPI send.
       Send x to destination.

       Automatically determine appropriate protocol
       and call corresponding send function.
       Also passes type and size information on as preceding message to
       simplify the receive call.

       The variable x can be any (picklable) type, but
       numpy variables and text strings will most efficient.
       Setting vanilla = 1 forces vanilla mode for any type.

       If use_buffer is True, workspace x will be used for the return value.
       In this case the corresponding receive call must specify a buffer.
       Otherwise a new workspace will be created by receive.

       If bypass is True, all admin and error checks
       get bypassed to reduce the latency. Should only
       be used for sending numpy arrays and should be matched
       with a bypass in the corresponding receive command.

    """
    import types, string

    if bypass:
        send_array(x, destination, tag)
        return

    # Input check
    errmsg = 'Destination id (%s) must be an integer.' % destination
    assert type(destination) == types.IntType, errmsg

    errmsg = 'Tag %d is reserved by pypar - please use another.' % control_tag
    assert tag != control_tag, errmsg

    # Create metadata about object to be sent
    control_info, x = create_control_info(x, vanilla, return_object=True)
    protocol = control_info[0]


    # Possibly transmit control data
    if use_buffer is False:
        send_control_info(control_info, destination)


    # Transmit payload data
    if protocol == 'array':
        send_array(x, destination, tag)
    elif protocol in ['string', 'vanilla']:
        send_string(x, destination, tag)
    else:
        raise 'Unknown protocol: %s' %protocol
Пример #3
0
def raw_send(x, destination, tag=0, vanilla=0):
    """Wrapper for raw MPI send.
     Send x to destination with tag.
     
     Automatically determine appropriate protocol
     and call corresponding send function.
     
     The variable x 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(x, vanilla)[0]
    if protocol == 'array':
        send_array(x, destination, tag)
    elif protocol == 'string':
        send_string(x, destination, tag)
    else:
        send_vanilla(x, destination, tag)
Пример #4
0
def raw_send(x, destination, tag=0, vanilla=0):
  """Wrapper for raw MPI send.
     Send x to destination with tag.
     
     Automatically determine appropriate protocol
     and call corresponding send function.
     
     The variable x 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(x, vanilla)[0]
  if protocol == 'array':
    send_array(x, destination, tag)  
  elif protocol == 'string':
    send_string(x, destination, tag)            
  else:  
    send_vanilla(x, destination, tag)
Пример #5
0
def send(x, destination, tag=0, vanilla=0):
    """Wrapper for easy MPI send.
     Send x to destination with tag.
     
     Automatically determine appropriate protocol
     and call corresponding send function.
     Also passes type and size information on as preceding message to
     simplify the receive call.
     
     The variable x can be any (picklable) type, but
     Numeric variables and text strings will most efficient.
     Setting vanilla = 1 forces vanilla mode for any type.

  """
    import string

    control_info = get_control_info(x, vanilla)
    protocol = control_info[0]

    if protocol == 'array':
        send_control_info(control_info, destination)

        send_array(x, destination, tag)
    elif protocol == 'string':
        send_control_info(control_info, destination)

        send_string(x, destination, tag)
    elif protocol == 'vanilla':
        from cPickle import dumps
        s = dumps(x, 1)
        control_info[2] = str(len(s))

        send_control_info(control_info, destination)

        send_string(s, destination, tag)
    else:
        raise "Unknown values for protocol: %s" % protocol
Пример #6
0
def send(x, destination, tag=0, vanilla=0):
  """Wrapper for easy MPI send.
     Send x to destination with tag.
     
     Automatically determine appropriate protocol
     and call corresponding send function.
     Also passes type and size information on as preceding message to
     simplify the receive call.
     
     The variable x can be any (picklable) type, but
     Numeric variables and text strings will most efficient.
     Setting vanilla = 1 forces vanilla mode for any type.

  """
  import string

  control_info = get_control_info(x, vanilla)
  protocol = control_info[0]
  
  if protocol == 'array':
    send_control_info(control_info, destination)
    
    send_array(x, destination, tag)    
  elif protocol == 'string':
    send_control_info(control_info, destination)    
    
    send_string(x, destination, tag)          
  elif protocol == 'vanilla':
    from cPickle import dumps     
    s = dumps(x, 1)
    control_info[2] = str(len(s))

    send_control_info(control_info, destination)   
    
    send_string(s, destination, tag)
  else:
    raise "Unknown values for protocol: %s" %protocol