Faster Way to Cancel HPC Tasks RRS feed

  • Question

  • I'm trying to cancel all the tasks in a job that are currently queued (have not run and are not running).  In order to do this I'm creating a filter collection and grabbing all the Task IDs that match the filter, then finally looping through those IDs and cancelling the individual tasks.  This works fine, except for the fact that this if approach is fairly slow.  So if there are a lot of tasks to cancel, sometimes the queued tasks that weren't running at the start of the loop are running by the time I try to cancel them.

    Is there any way to cancel queued tasks faster?  Either at the Job level, cancel everything that is not running (let the running jobs finish).  Or at the task level pass a IFilterCollection to a CancelTasks method?

    Here is my existing code:

    // define a filter for status
    IFilterCollection filters = scheduler.CreateFilterCollection();
    filters.Add(FilterOperator.Equal, PropId.Task_State, TaskState.Queued);
    // define a sort order to cancel child dependent tasks before parents (task id desc)
    ISortCollection sorts = scheduler.CreateSortCollection();
    sorts.Add(SortProperty.SortOrder.Descending, Microsoft.Hpc.Scheduler.PropId.Task_Name);
    // loop through all the tasks that are queued (not running) and cancel them
    foreach (ITaskId taskId in hpcJob.GetTaskIdList(filters, sorts, true))
    	hpcJob.CancelTask(taskId, "Cancelling all queued tasks.");


    Monday, June 14, 2010 7:34 PM


  • Hi Scott,

    What you are doing is the right way. There is no alternative, faster way to cancel tasks in a running job now.


    • Marked as answer by Don Pattee Friday, February 4, 2011 10:27 PM
    Wednesday, June 23, 2010 5:34 PM