Module controller
Implement infrastructure for the solver to add various interfaces
-
class pysph.solver.controller.CommandManager(solver, comm=None)[source]
Bases: object
Class to manage and synchronize commands from various Controllers
-
add_function(callable, interval=1)[source]
add a function to to be called every interval iterations
-
add_interface(*args, **kwds)[source]
Add a callable interface to the controller
The callable must accept an Controller instance argument.
The callable is called in a new thread of its own and it can
do various actions with methods defined on the Controller
instance passed to it
The new created thread is set to daemon mode and returned
-
cont()[source]
continue after a pause command
-
dispatch(*args, **kwargs)[source]
execute/queue a command with specified arguments
-
execute_commands(solver)[source]
called by the solver after each timestep
-
get_particle_array_combined(idx, procs=None)[source]
get a single particle array with combined data from all procs
specifying processes is currently not implemented
-
get_particle_array_from_procs(idx, procs=None)[source]
get particle array at index from all processes
specifying processes is currently not implemented
-
get_particle_array_index(name)[source]
get the index of the named particle array
-
get_particle_array_names()[source]
get the names of the particle arrays
-
get_prop(name)[source]
get a solver property
-
get_result(lock_id)[source]
get the result of a previously queued command
-
get_status()[source]
get the status of the controller
-
get_task_lock(lock_id)[source]
get the Lock instance associated with a command
-
pause_on_next()[source]
pause and wait for command on the next control interval
-
set_log_level(level)[source]
set the logging level
-
set_prop(name, value)[source]
set a solver property
-
solver_method(name, *args, **kwargs)[source]
execute a method on the solver
-
sync_commands()[source]
send the pending commands to all the procs in parallel run
-
wait_for_cmd()[source]
wait for command from any interface
-
class pysph.solver.controller.Controller(command_manager, block=True)[source]
Bases: object
Controller class acts a a proxy to control the solver
This is passed as an argument to the interface
Methods available:
- get – get the value of a solver parameter
- set – set the value of a solver parameter
- get_result – return result of a queued command
- pause_on_next – pause solver thread on next iteration
- wait – wait (block) calling thread till solver is paused
(call after pause_on_next)
- cont – continue solver thread (call after pause_on_next)
Various other methods are also available as listed in
CommandManager.dispatch_dict which perform different functions.
- The methods in CommandManager.active_methods do their operation and return
the result (if any) immediately
- The methods in CommandManager.lazy_methods do their later when solver
thread is available and return a task-id. The result of the task can be
obtained later using the blocking call get_result() which waits till
result is available and returns the result.
The availability of the result can be checked using the lock returned
by get_task_lock() method
FIXME: wait/cont currently do not work in parallel
-
cont()[source]
continue solver thread after it has been paused by pause_on_next
call this only after calling the pause_on_next method
-
get(name)[source]
get a solver property; returns immediately
-
get_blocking()[source]
get the blocking mode ( True/False )
-
get_result(task_id)[source]
get the result of a previously queued command
-
pause_on_next()[source]
pause the solver thread on next iteration
-
set(name, value)[source]
set a solver property; returns immediately;
-
set_blocking(block)[source]
set the blocking mode to True/False
In blocking mode (block=True) all methods other than getting of
solver properties block until the command is executed by the solver
and return the results. The blocking time can vary depending on the
time taken by solver per iteration and the command_interval
In non-blocking mode, these methods queue the command for later
and return a string corresponding to the task_id of the operation.
The result can be later obtained by a (blocking) call to get_result
with the task_id as argument
-
wait()[source]
block the calling thread until the solver thread pauses
call this only after calling the pause_on_next method to tell
the controller to pause the solver thread
-
class pysph.solver.controller.DummyComm[source]
Bases: object
A dummy MPI.Comm implementation as placeholder for for serial runs
-
Get_rank()[source]
return the rank of the process (0)
-
Get_size()[source]
return the size of the comm (1)
-
bcast(data)[source]
bcast (broadcast) implementation for serial run
-
gather(data)[source]
gather implementation for serial run
-
recv(pid)[source]
dummy recv implementation
-
send(data, pid)[source]
dummy send implementation
-
pysph.solver.controller.in_parallel(f)[source]
return a list of results of running decorated function on all procs
-
pysph.solver.controller.on_root_proc(f)[source]
run the decorated function only on the root proc
-
pysph.solver.controller.synchronized(lock_or_func)[source]
decorator for synchronized (thread safe) function
Usage:
- sync_func = synchronized(lock)(func) # sync with an existing lock
- sync_func = synchronized(func) # sync with a new private lock