The following procedure describes how to create a sample application that sets the Progress and Progress Message job properties.
The sample application uses classes in the
Microsoft.Hpc.Scheduler
namespace to modify the job
properties. For more information, see the HPC Class Library on MSDN
(http://go.microsoft.com/fwlink/?LinkID=167944).
![]() |
To create the sample project |
-
Run Visual Studio 2008.
-
Create a new Visual C# Console Application that is named ProgressSample as follows:
- On the File menu, point to New, and then click
Project.
- In the New Project dialog box, in Project Types,
select Visual C#.
- In the list of templates, select Console
Application.
- For the project name, type: ProgressSample.
- Click OK to close the dialog box and create the new
project.
- On the File menu, point to New, and then click
Project.
-
Add a reference to the
Microsoft.Hpc.Scheduler
dynamic-link library (DLL) as follows:- On the View menu, click Solution Explorer.
- In Solution Explorer, right-click References, and
then click Add Reference.
- In the Add Reference dialog box, click the Browse
tab.
- In the Look in drop-down menu, select the Bin
folder for the HPC Pack 2008 R2 SDK. This is typically located
at C:\Program Files\Microsoft HPC Pack 2008 R2 SDK\Bin.
- Select Microsoft.Hpc.Scheduler.dll.
- Click OK to add the reference and close the dialog
box.
- In Solution Explorer, in References, verify that
Microsoft.Hpc.Scheduler appears.
- On the View menu, click Solution Explorer.
-
In the main source file, select all the code and then delete it.
-
Paste the following code sample into the empty source file.
using System; using System.Threading; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Hpc.Scheduler; namespace ProgressSample { class Program { static void Main(string[] args) { // Initialize variables double progress = 0; int iterations = 20; int iterationMilliseconds = 500; if (args.Count() == 2) { iterations = System.Convert.ToInt32(args[0]); iterationMilliseconds = System.Convert.ToInt32(args[1]); } else { System.Console.Error.WriteLine("USAGE: ProgressSample.exe <NUM_ITERATIONS> <ITERATION_MILLISECONDS>"); } // Discover the job's context from the environment String headNodeName = System.Environment.GetEnvironmentVariable("CCP_CLUSTER_NAME"); int jobId = System.Convert.ToInt32(System.Environment.GetEnvironmentVariable("CCP_JOBID")); // Connect to the head node and get the job IScheduler scheduler = new Scheduler(); scheduler.Connect(headNodeName); ISchedulerJob job = scheduler.OpenJob(jobId); // Run iterations and set progress for (int i = 1; i <= iterations; i++) { // Do some work Thread.Sleep(iterationMilliseconds); // Set the progress // Calculate the progress percentage progress = (System.Convert.ToDouble(i) / System.Convert.ToDouble(iterations)) * 100; // Set the progress percentage (must be an int between 0 - 100) job.Progress = System.Convert.ToInt32(progress); // Set a custom progress message (up to 80 chars) job.ProgressMessage = i + " out of " + iterations + " steps complete."; // Commit the change job.Commit(); } } } }
-
On the File menu, click Save All.
-
On the Build menu, click Build ProgressSample.
Continue to Step 2: Submit a Job that Runs ProgressSample.exe.