Documentation: http://radicalpilot.readthedocs.org/en/stable/machconf.html#preconfigured-resources
First, we will import the necessary dependencies.
import os, sys
import radical.pilot as rp
print rp.version
session = rp.Session()
pmgr = rp.PilotManager(session=session)
umgr = rp.UnitManager (session=session,scheduler=rp.SCHED_ROUND_ROBIN)
print "Session id: %s \n \
Pilot Manager: %s \n \
Unit Manager: %s" % (session.uid, pmgr.uid, umgr.uid)
pdesc = rp.ComputePilotDescription()
pdesc.resource = "local.localhost"
pdesc.runtime = 10 # minutes
pdesc.cores = 2
pilot = pmgr.submit_pilots(pdesc)
umgr.add_pilots(pilot)
The umgr.add_pilot(pilot)
binds a Pilot to a Unit Manager. This informs the Unit Manager that the resources of the Pilot can be used for exeuction of Units. Multiple Pilots can be bound to a Unit Manager, and later be removed via umgr.remove_pilot()
. The Unit Manager will schedule incoming Compute Units across all available Pilots.
print "uid: ", pilot.uid
print "resource: ", pilot.resource
print "sandbox: ", pilot.sandbox
print "state: ", pilot.state
cudesc1 = rp.ComputeUnitDescription()
cudesc1.environment = {'CU_NO': 1}
cudesc1.executable = "/bin/echo"
cudesc1.arguments = ['I am CU number $CU_NO']
cudesc1.cores = 1
cudesc2 = rp.ComputeUnitDescription()
cudesc2.environment = {'CU_NO': 2}
cudesc2.executable = "/bin/echo"
cudesc2.arguments = ['I am CU number $CU_NO']
cudesc2.cores = 1
Submit the previously created Compute Unit descriptions to the Unit Manager. This will trigger the selected scheduler (in this case the Round-Robin scheduler) to start assigning Compute Units to the Pilots.
print "Submit Compute Units to Unit Manager ..."
cu_set = umgr.submit_units([cudesc1, cudesc2])
print "Waiting for CUs to complete ..."
umgr.wait_units()
print "All CUs completed successfully!"
Inspect the output of the CUs
print cu_set[0].stdout
print cu_set[1].stdout
session.close()