Exemplo n.º 1
0
def initialize(args=None):
    R""" Initialize the execution context

    Args:
        args (str): Arguments to parse. When *None*, parse the arguments passed on the command line.

    :py:func:`hoomd.context.initialize()` parses the command line arguments given, sets the options and initializes MPI and GPU execution
    (if any). By default, :py:func:`hoomd.context.initialize()` reads arguments given on the command line. Provide a string to :py:func:`hoomd.context.initialize()`
    to set the launch configuration within the job script.

    :py:func:`hoomd.context.initialize()` can be called more than once in a script. However, the execution parameters are fixed on the first call
    and *args* is ignored. Subsequent calls to :py:func:`hoomd.context.initialize()` create a new :py:class:`SimulationContext` and set it current. This
    behavior is primarily to support use of hoomd in jupyter notebooks, so that a new clean simulation context is
    set when rerunning the notebook within an existing kernel.

    Example::

        from hoomd import *
        context.initialize();
        context.initialize("--mode=gpu --nrank=64");
        context.initialize("--mode=cpu --nthreads=64");

    """
    global exec_conf, msg, options, current, _prev_args

    if exec_conf is not None:
        if args != _prev_args:
            msg.warning(
                "Ignoring new options, cannot change execution mode after initialization.\n"
            )
        current = SimulationContext()
        return current

    _prev_args = args

    options = hoomd.option.options()
    hoomd.option._parse_command_line(args)

    # output the version info on initialization
    msg.notice(1, _hoomd.output_version_info())

    # ensure creation of global bibliography to print HOOMD base citations
    cite._ensure_global_bib()

    _create_exec_conf()

    current = SimulationContext()
    return current
Exemplo n.º 2
0
def initialize(args=None):
    R""" Initialize the execution context

    Args:
        args (str): Arguments to parse. When *None*, parse the arguments passed on the command line.

    :py:func:`hoomd.context.initialize()` parses the command line arguments given, sets the options and initializes MPI and GPU execution
    (if any). By default, :py:func:`hoomd.context.initialize()` reads arguments given on the command line. Provide a string to :py:func:`hoomd.context.initialize()`
    to set the launch configuration within the job script.

    :py:func:`hoomd.context.initialize()` can be called more than once in a script. However, the execution parameters are fixed on the first call
    and *args* is ignored. Subsequent calls to :py:func:`hoomd.context.initialize()` create a new :py:class:`SimulationContext` and set it current. This
    behavior is primarily to support use of hoomd in jupyter notebooks, so that a new clean simulation context is
    set when rerunning the notebook within an existing kernel.

    Example::

        from hoomd import *
        context.initialize();
        context.initialize("--mode=gpu --nrank=64");

    """
    global exec_conf, msg, options, current, _prev_args

    if exec_conf is not None:
        if args != _prev_args:
            msg.warning("Ignoring new options, cannot change execution mode after initialization.\n");
        current = SimulationContext();
        return current

    _prev_args = args;

    options = hoomd.option.options();
    hoomd.option._parse_command_line(args);

    # output the version info on initialization
    msg.notice(1, _hoomd.output_version_info())

    # ensure creation of global bibliography to print HOOMD base citations
    cite._ensure_global_bib()

    _create_exec_conf();

    current = SimulationContext();
    return current
Exemplo n.º 3
0
def initialize(args=None, device=None):
    R""" Initialize the execution context

    Args:
        args (str): Arguments to parse. When *None*, parse the arguments passed on the command line.
        device (:py:mod:`hoomd.device`): device to use for running the simulations

    :py:func:`hoomd.context.initialize()` parses the command line arguments given, sets the options and initializes MPI and GPU execution
    (if any). By default, :py:func:`hoomd.context.initialize()` reads arguments given on the command line. Provide a string to :py:func:`hoomd.context.initialize()`
    to set the launch configuration within the job script.

    :py:func:`hoomd.context.initialize()` can be called more than once in a script. However, the execution parameters are fixed on the first call
    and *args* is ignored. Subsequent calls to :py:func:`hoomd.context.initialize()` create a new :py:class:`SimulationContext` and set it current. This
    behavior is primarily to support use of hoomd in jupyter notebooks, so that a new clean simulation context is
    set when rerunning the notebook within an existing kernel.

    Example::

        from hoomd import *
        context.initialize();
        context.initialize("--mode=gpu --nrank=64");
        context.initialize("--mode=cpu --nthreads=64");

        world = MPI.COMM_WORLD
        comm = world.Split(world.Get_rank(), 0)
        c = comm.Communicator(mpi_comm=comm)
        hoomd.context.initialize(device=device.GPU(communicator=c))

    """
    global options, current

    options = hoomd.option.options()
    hoomd.option._parse_command_line(args)

    current = SimulationContext(device)

    # ensure creation of global bibliography to print HOOMD base citations
    cite._ensure_global_bib()

    return current
Exemplo n.º 4
0
def initialize(args=None, memory_traceback=False, mpi_comm=None):
    R""" Initialize the execution context

    Args:
        args (str): Arguments to parse. When *None*, parse the arguments passed on the command line.
        memory_traceback (bool): If true, enable memory allocation tracking (*only for debugging/profiling purposes*)
        mpi_comm: Accepts an mpi4py communicator. Use this argument to perform many independent hoomd simulations
                  where you communicate between those simulations using your own mpi4py code.

    :py:func:`hoomd.context.initialize()` parses the command line arguments given, sets the options and initializes MPI and GPU execution
    (if any). By default, :py:func:`hoomd.context.initialize()` reads arguments given on the command line. Provide a string to :py:func:`hoomd.context.initialize()`
    to set the launch configuration within the job script.

    :py:func:`hoomd.context.initialize()` can be called more than once in a script. However, the execution parameters are fixed on the first call
    and *args* is ignored. Subsequent calls to :py:func:`hoomd.context.initialize()` create a new :py:class:`SimulationContext` and set it current. This
    behavior is primarily to support use of hoomd in jupyter notebooks, so that a new clean simulation context is
    set when rerunning the notebook within an existing kernel.

    Example::

        from hoomd import *
        context.initialize();
        context.initialize("--mode=gpu --nrank=64");
        context.initialize("--mode=cpu --nthreads=64");

        world = MPI.COMM_WORLD
        comm = world.Split(world.Get_rank(), 0)
        hoomd.context.initialize(mpi_comm=comm)

    """
    global mpi_conf, exec_conf, msg, options, current, _prev_args

    if mpi_conf is not None or exec_conf is not None:
        if args != _prev_args:
            msg.warning("Ignoring new options, cannot change execution mode after initialization.\n");
        current = SimulationContext();
        return current

    _prev_args = args;

    options = hoomd.option.options();
    hoomd.option._parse_command_line(args);

    # Check to see if we are built without MPI support and the user used mpirun
    if (not _hoomd.is_MPI_available() and not options.single_mpi
        and (    'OMPI_COMM_WORLD_RANK' in os.environ
              or 'MV2_COMM_WORLD_LOCAL_RANK' in os.environ
              or 'PMI_RANK' in os.environ
              or 'ALPS_APP_PE' in os.environ)
       ):
        print('HOOMD-blue is built without MPI support, but seems to have been launched with mpirun');
        print('exiting now to prevent many sequential jobs from starting');
        raise RuntimeError('Error launching hoomd')

    # create the MPI configuration
    mpi_conf = _create_mpi_conf(mpi_comm, options)

    # set options on messenger object
    msg = _create_messenger(mpi_conf, options)

    # output the version info on initialization
    msg.notice(1, _hoomd.output_version_info())

    # ensure creation of global bibliography to print HOOMD base citations
    cite._ensure_global_bib()

    # create the parallel execution configuration
    exec_conf = _create_exec_conf(mpi_conf, msg, options);

    # set memory tracing option
    exec_conf.setMemoryTracing(memory_traceback)

    current = SimulationContext();
    return current
Exemplo n.º 5
0
def initialize(args=None, memory_traceback=False, mpi_comm=None):
    R""" Initialize the execution context

    Args:
        args (str): Arguments to parse. When *None*, parse the arguments passed on the command line.
        memory_traceback (bool): If true, enable memory allocation tracking (*only for debugging/profiling purposes*)
        mpi_comm: Accepts an mpi4py communicator. Use this argument to perform many independent hoomd simulations
                  where you communicate between those simulations using your own mpi4py code.

    :py:func:`hoomd.context.initialize()` parses the command line arguments given, sets the options and initializes MPI and GPU execution
    (if any). By default, :py:func:`hoomd.context.initialize()` reads arguments given on the command line. Provide a string to :py:func:`hoomd.context.initialize()`
    to set the launch configuration within the job script.

    :py:func:`hoomd.context.initialize()` can be called more than once in a script. However, the execution parameters are fixed on the first call
    and *args* is ignored. Subsequent calls to :py:func:`hoomd.context.initialize()` create a new :py:class:`SimulationContext` and set it current. This
    behavior is primarily to support use of hoomd in jupyter notebooks, so that a new clean simulation context is
    set when rerunning the notebook within an existing kernel.

    Example::

        from hoomd import *
        context.initialize();
        context.initialize("--mode=gpu --nrank=64");
        context.initialize("--mode=cpu --nthreads=64");

        world = MPI.COMM_WORLD
        comm = world.Split(world.Get_rank(), 0)
        hoomd.context.initialize(mpi_comm=comm)

    """
    global exec_conf, msg, options, current, _prev_args

    if exec_conf is not None:
        if args != _prev_args:
            msg.warning("Ignoring new options, cannot change execution mode after initialization.\n");
        current = SimulationContext();
        return current

    _prev_args = args;

    options = hoomd.option.options();
    hoomd.option._parse_command_line(args);

    # Check to see if we are built without MPI support and the user used mpirun
    if (not _hoomd.is_MPI_available() and not options.single_mpi
        and (    'OMPI_COMM_WORLD_RANK' in os.environ
              or 'MV2_COMM_WORLD_LOCAL_RANK' in os.environ
              or 'PMI_RANK' in os.environ
              or 'ALPS_APP_PE' in os.environ)
       ):
        print('HOOMD-blue is built without MPI support, but seems to have been launched with mpirun');
        print('exiting now to prevent many sequential jobs from starting');
        raise RuntimeError('Error launching hoomd')

    # output the version info on initialization
    msg.notice(1, _hoomd.output_version_info())

    # ensure creation of global bibliography to print HOOMD base citations
    cite._ensure_global_bib()

    exec_conf = _create_exec_conf(mpi_comm);

    # set memory tracing option
    exec_conf.setMemoryTracing(memory_traceback)

    current = SimulationContext();
    return current