How to submit multiple jobs and capture job_OnJobState event RRS feed

  • Question

  •  Hi All,

    I am new to HPC. Please help me on this.

    How submit multiple jobs, after submitting I want to know the status of submitted jobs as I have to update some table after finishing the each job.

    Please see below code. I am able to see the state of last job, but I want to know state of each job which I have submitted.

    I want to submit multiple jobs at the same time as I have many cores available. I can not submit one by one as first job may take 30min-40min to run.

    Thanks for reading.

    private static ManualResetEvent jobFinishEvt = new ManualResetEvent(false);

    static void Main(string[] args)


    Scheduler scheduler = new Scheduler();


    for (int j = 1; j <= 2; j++)

    ISchedulerJob job = scheduler.CreateJob();

    job.AutoCalculateMin = true; 

    // disable so we can manually set number of resources:
                            job.AutoCalculateMax = true;

    ISchedulerTask task = job.CreateTask();

    task.CommandLine = "ComputeTask.exe";

    task.WorkDirectory = @"\\filer\appData";


    job.OnJobState += new EventHandler<JobStateEventArg>(job_OnJobState);

    scheduler.SubmitJob(job, null, null);





    static void job_OnJobState(object sender, JobStateEventArg e)
                if (e.NewState == JobState.Finished) //the job is finished
                    //task.Refresh(); // update the task object with updates from the scheduler

                    Console.WriteLine("Job completed." + e.JobId);
                    //Console.WriteLine("Output: " + task.Output); //print the task's output
                else if (e.NewState == JobState.Canceled || e.NewState == JobState.Failed)
                    Console.WriteLine("Job did not finish." + e.JobId);
                else if (e.NewState == JobState.Queued && e.PreviousState != JobState.Validating)
                    Console.WriteLine("The job is currently queued." + e.JobId);
                    Console.WriteLine("Waiting for job to start...");


    • Edited by NagAsnp Thursday, September 11, 2014 9:28 PM
    Thursday, September 11, 2014 9:13 PM

All replies

  • Any job completes will set the jobFinishEvt, and your main thread exits once this event set, thus the whole process ends. That's why you can only see one job's callback. You can add a Console.ReadKey() at the end of Main method and try.

    Friday, September 12, 2014 6:55 AM
  • Thank you so much for your reply. Can you please provide sample code to run multiple jobs and read the state of job.

    Thanks Evan!!

    Friday, September 12, 2014 2:01 PM