def __init__(self, communicator, notice_level, msg_file, shared_msg_file): # metadata stuff hoomd.meta._metadata.__init__(self) self.metadata_fields = ['gpu_ids', 'mode', 'num_ranks'] if _hoomd.is_TBB_available(): self.metadata_fields.append('num_threads') # check shared_msg_file if shared_msg_file is not None: if not _hoomd.is_MPI_available(): raise RuntimeError( "Shared log files are only available in MPI builds.\n") # MPI communicator if communicator is None: self._comm = hoomd.comm.Communicator() else: self._comm = communicator # c++ messenger object self.cpp_msg = _create_messenger(self.comm.cpp_mpi_conf, notice_level, msg_file, shared_msg_file) # output the version info on initialization self.cpp_msg.notice(1, _hoomd.output_version_info()) # c++ execution configuration mirror class self.cpp_exec_conf = None # name of the message file self._msg_file = msg_file
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
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
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
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