コード例 #1
0
ファイル: pypar.py プロジェクト: AtomAleks/PyProp
def broadcast(buffer, root, vanilla=False, bypass=False):
    """Wrapper for MPI bcast.

       Broadcast buffer from the process with rank root to all other processes.

    
       Automatically determine appropriate protocol
       and call corresponding send function.
       
       The variable buffer can be any (picklable) type, but
       numpy variables and text strings will most efficient.
       Setting vanilla = 1 forces vanilla mode for any type.

       If bypass is True, all admin and error checks
       get bypassed to reduce the latency.

    """

    if bypass:
        broadcast_array(buffer, root)
        return
    

    import types
    
    #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 = create_control_info(buffer, vanilla)[0]


    #Broadcast
    if protocol == 'array':
        broadcast_array(buffer, root)    
    elif protocol == 'string':
        broadcast_string(buffer, root)          
    elif protocol == 'vanilla':
        from cPickle import loads, dumps 
        s = dumps(buffer, 1)
        s = s + ' '*int(0.1*len(s)) #safety
        
        broadcast_string(s, root)
        buffer = loads(s)
    else:
        raise 'Unknown protocol: %s' %protocol  
      
    return buffer         
コード例 #2
0
def broadcast(buffer, root, vanilla=False, bypass=False):
    """Wrapper for MPI bcast.

       Broadcast buffer from the process with rank root to all other processes.

    
       Automatically determine appropriate protocol
       and call corresponding send function.
       
       The variable buffer can be any (picklable) type, but
       numpy variables and text strings will most efficient.
       Setting vanilla = 1 forces vanilla mode for any type.

       If bypass is True, all admin and error checks
       get bypassed to reduce the latency.

    """

    if bypass:
        broadcast_array(buffer, root)
        return

    import types

    #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 = create_control_info(buffer, vanilla)[0]

    #Broadcast
    if protocol == 'array':
        broadcast_array(buffer, root)
    elif protocol == 'string':
        broadcast_string(buffer, root)
    elif protocol == 'vanilla':
        from cPickle import loads, dumps
        s = dumps(buffer, 1)
        s = s + ' ' * int(0.1 * len(s))  #safety

        broadcast_string(s, root)
        buffer = loads(s)
    else:
        raise 'Unknown protocol: %s' % protocol

    return buffer