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(callable, block=True)[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


continue after a pause command

dispatch(block, meth, *args, **kwargs)[source]

execute/queue a command with specified arguments


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 the index of the named particle array


get the names of the particle arrays


get a solver property


get the result of a previously queued command


get the status of the controller


get the Lock instance associated with a command


pause and wait for command on the next control interval


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


send the pending commands to all the procs in parallel run


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


continue solver thread after it has been paused by pause_on_next

call this only after calling the pause_on_next method


get a solver property; returns immediately


get the blocking mode ( True/False )


get the result of a previously queued command


pause the solver thread on next iteration

set(name, value)[source]

set a solver property; returns immediately;


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


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


return the rank of the process (0)


return the size of the comm (1)


bcast (broadcast) implementation for serial run


gather implementation for serial run


dummy recv implementation

send(data, pid)[source]

dummy send implementation


return a list of results of running decorated function on all procs


run the decorated function only on the root proc


decorator for synchronized (thread safe) function


  • sync_func = synchronized(lock)(func) # sync with an existing lock
  • sync_func = synchronized(func) # sync with a new private lock