Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def libE_mpi_manager(mpi_comm, sim_specs, gen_specs, exit_criteria, persis_info,
alloc_specs, libE_specs, H0):
"Manager routine run at rank 0."
from libensemble.comms.mpi import MainMPIComm
hist = History(alloc_specs, sim_specs, gen_specs, exit_criteria, H0)
# Lauch worker team
wcomms = [MainMPIComm(mpi_comm, w) for w in
range(1, mpi_comm.Get_size())]
manager_logging_config()
# Set up abort handler
def on_abort():
"Shut down MPI on error."
comms_abort(mpi_comm)
# Run generic manager
return libE_manager(wcomms, sim_specs, gen_specs, exit_criteria,
persis_info, alloc_specs, libE_specs, hist,
on_abort=on_abort)
workers = None
nworkers = libE_specs['nprocesses']
elif 'workers' in libE_specs:
workers = libE_specs['workers']
nworkers = len(workers)
ip = libE_specs.get('ip', None) or get_ip()
port = libE_specs.get('port', 0)
authkey = libE_specs.get('authkey', libE_tcp_authkey())
with ServerQCommManager(port, authkey.encode('utf-8')) as manager:
# Get port if needed because of auto-assignment
if port == 0:
_, port = manager.address
manager_logging_config()
logger.info("Launched server at ({}, {})".format(ip, port))
# Launch worker team and set up logger
worker_procs, wcomms =\
libE_tcp_start_team(manager, nworkers, workers,
ip, port, authkey, launchf)
def cleanup():
"Handler to clean up launched team."
for wp in worker_procs:
launcher.cancel(wp, timeout=libE_specs.get('worker_timeout'))
# Run generic manager
return libE_manager(wcomms, sim_specs, gen_specs, exit_criteria,
persis_info, alloc_specs, libE_specs, hist,
on_cleanup=cleanup)
workers = None
nworkers = libE_specs['nworkers']
elif 'workers' in libE_specs:
workers = libE_specs['workers']
nworkers = len(workers)
ip = libE_specs.get('ip', None) or get_ip()
port = libE_specs.get('port', 0)
authkey = libE_specs.get('authkey', libE_tcp_authkey())
with ServerQCommManager(port, authkey.encode('utf-8')) as manager:
# Get port if needed because of auto-assignment
if port == 0:
_, port = manager.address
manager_logging_config()
logger.info("Launched server at ({}, {})".format(ip, port))
# Launch worker team and set up logger
worker_procs, wcomms =\
libE_tcp_start_team(manager, nworkers, workers,
ip, port, authkey, launchf)
def cleanup():
"Handler to clean up launched team."
for wp in worker_procs:
launcher.cancel(wp, timeout=libE_specs.get('worker_timeout'))
# Run generic manager
return libE_manager(wcomms, sim_specs, gen_specs, exit_criteria,
persis_info, alloc_specs, libE_specs, hist,
on_cleanup=cleanup)
persis_info, alloc_specs, libE_specs, H0):
"Main routine for thread/process launch of libE."
nworkers = libE_specs['nworkers']
check_inputs(libE_specs, alloc_specs, sim_specs, gen_specs, exit_criteria, H0)
exctr = Executor.executor
if exctr is not None:
local_host = socket.gethostname()
exctr.add_comm_info(libE_nodes=local_host, serial_setup=True)
hist = History(alloc_specs, sim_specs, gen_specs, exit_criteria, H0)
# Launch worker team and set up logger
wcomms = start_proc_team(nworkers, sim_specs, gen_specs, libE_specs)
manager_logging_config()
# Set up cleanup routine to shut down worker team
def cleanup():
"Handler to clean up comms team."
kill_proc_team(wcomms, timeout=libE_specs.get('worker_timeout'))
# Run generic manager
return libE_manager(wcomms, sim_specs, gen_specs, exit_criteria,
persis_info, alloc_specs, libE_specs, hist,
on_cleanup=cleanup)
def libE_mpi_manager(mpi_comm, sim_specs, gen_specs, exit_criteria, persis_info,
alloc_specs, libE_specs, H0):
"Manager routine run at rank 0."
from libensemble.comms.mpi import MainMPIComm
hist = History(alloc_specs, sim_specs, gen_specs, exit_criteria, H0)
# Lauch worker team
wcomms = [MainMPIComm(mpi_comm, w) for w in
range(1, mpi_comm.Get_size())]
manager_logging_config()
# Set up abort handler
def on_abort():
"Shut down MPI on error."
comms_abort(mpi_comm)
# Run generic manager
return libE_manager(wcomms, sim_specs, gen_specs, exit_criteria,
persis_info, alloc_specs, libE_specs, hist,
on_abort=on_abort)
persis_info, alloc_specs, libE_specs, H0):
"Main routine for thread/process launch of libE."
nworkers = libE_specs['nprocesses']
check_inputs(libE_specs, alloc_specs, sim_specs, gen_specs, exit_criteria, H0)
jobctl = JobController.controller
if jobctl is not None:
local_host = socket.gethostname()
jobctl.add_comm_info(libE_nodes=local_host, serial_setup=True)
hist = History(alloc_specs, sim_specs, gen_specs, exit_criteria, H0)
# Launch worker team and set up logger
wcomms = start_proc_team(nworkers, sim_specs, gen_specs)
manager_logging_config()
# Set up cleanup routine to shut down worker team
def cleanup():
"Handler to clean up comms team."
kill_proc_team(wcomms, timeout=libE_specs.get('worker_timeout'))
# Run generic manager
return libE_manager(wcomms, sim_specs, gen_specs, exit_criteria,
persis_info, alloc_specs, libE_specs, hist,
on_cleanup=cleanup)