Creating a Custom User Interface
Applies To: Windows Compute Cluster Server 2003
For most users, the Job Manager and the command line interface (CLI) provide all of the functionality needed to use the Job Scheduler. For some purposes however, users, administrators and developers will want to bypass these interfaces and communicate with the Job Scheduler directly, at the API level. This is performed using the Compute Cluster Pack API (CCPAPI).The CCPAPI is installed with the Compute Cluster Pack and includes the C# and COM API bindings necessary to communicate with the Job Scheduler and other CCP services.
Using CCPAPI
Complete documentation of the CCPAPI can be found online at the MSDN Web site. For more information, see Microsoft Compute Cluster Pack (https://go.microsoft.com/fwlink/?linkid=55873).
The following table shows the five basic steps involved in creating and submitting a job through the CCPAPI and the CCPAPI method used for each.
Step | CCPAPI Method |
---|---|
Connect to the cluster |
ICluster::Connect |
Create a job |
ICluster::CreateJob |
Create a task |
ICluster::CreateTask |
Add the task to the job |
ICluster::AddTask |
Submit the job/task for execution |
ICluster::SubmitJob(). -or- ICluster::QueueJob() (Combines SubmitJob() with another method, AddJob() |
The following examples show how these CCPAPI methods can be used to submit a simple job in three different contexts: a Perl script, a VBS script, and a C# program.
Perl
32::OLE;
$objCluster = Win32::OLE->new("Microsoft.ComputeCluster.Cluster") ||
die "Can't create Cluster object\n";
$objCluster->Connect("localhost");
print "Connected to head node $objCluster->{Name}\n";
$objJob = $objCluster->CreateJob();
$objTask = $objCluster->CreateTask();
$objTask->{CommandLine} = "mpiexec myapp.exe";
$objJob->{MinimumNumberOfProcessors} = 4;
$objTask->{MininumNumberOfProcessors} = 4;
$objJob->{MaximumNumberOfProcessors} = 4;
$objTask->{MaximumNumberOfProcessors} = 4;
$objTask->{Stdin} = "infile.txt";
$objTask->{Stdout} = "outfile.txt";
$objTask->{Stderr} = "errfile.txt";
$objJob->AddTask($objTask);
$objCluster->QueueJob($objJob, "<domain>\\<userid>", "", 1, 0) || die "Failed to submit job:" . $objCluster->{ErrorMessage} . "\n";
print "Job " . $objJob->{Id} . " submitted\n";
exit 0;
$objCluster->QueueJob($objJob, "<domain>\\<userid>", "", 1, 0) ||
die "Failed to submit job:" . $objCluster->{ErrorMessage} . "\n";
print "Job " . $objJob->{Id} . " submitted\n";
exit 0;
Visual Basic Script
strClusterName = "localhost" 'Change to name of cluster if not run locally.
strCommandLine = "mpiexec myapp.exe"
strUsername = "" 'If empty string, script prompts for user name.
strPassword = "" 'If empty string, script prompts for password.
blnIsConsole = True 'True = cmd-line, False = GUI
intHandle = 0
Set objComputeCluster = CreateObject("Microsoft.ComputeCluster.Cluster")
objComputeCluster.Connect(strClusterName)
WScript.Echo "Compute Cluster Name: " & objComputeCluster.Name
Set objJob = objComputeCluster.CreateJob
objJob.MinimumNumberOfProcessors = "4"
objJob.MaximumNumberOfProcessors = "4"
intJobID = objComputeCluster.AddJob((objJob))
WScript.Echo "Job ID: " & intJobID
Set objTask = objComputeCluster.CreateTask
objTask.MinimumNumberOfProcessors = "4"
objTask.MaximumNumberOfProcessors = "4"
objTask.CommandLine = strCommandLine
objTask.Name = "Task1"
objTask.Stdin = "infile.txt"
objTask.Stdout = "outfile.txt"
objTask.Stderr = "errfile.txt"
intTaskID = objComputeCluster.AddTask(objJob.ID, (objTask))
WScript.Echo "Task ID: " & objTask.ID
objComputeCluster.SubmitJob intJobID, strUsername, strPassword, _
blnIsConsole, intHandle
WScript.Echo "Submitted Job " & intJobID
For more information about scripting jobs for Compute Cluster Server, see Compute Cluster Server - Jobs (https://go.microsoft.com/fwlink/?LinkId=71623). The Scripting Center Script Repository contains many scripts for cluster administration and job submission tasks.
C#
Note
To compile and run a C# program using CCPAPI, it is necessary to reference CcpApi.dll, which can be found in the Compute Cluster Pack SDK. For information and to download, see Microsoft Compute Cluster Pack SDK (https://go.microsoft.com/fwlink/?LinkId=71624).
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.ComputeCluster;
namespace SerialJobSub
{
class my_Program
{
static int Main(string[] args)
{
Cluster cluster = new Cluster();
try
{
cluster.Connect("<cluster_name>");
IJob job = cluster.CreateJob();
ITask task = new Task();
job.MinimumNumberOfProcessors = 4;
job.MaximumNumberOfProcessors = 4;
task.MinimumNumberOfProcessors = 4;
task.MaximumNumberOfProcessors = 4;
task.CommandLine = @"mpiexec myapp.exe";
task.Stdin = @"infile.txt";
task.Stdout = @"outfile.txt";
job.AddTask(task);
int jobId = cluster.AddJob(job);
cluster.SubmitJob(jobId, @"mydomain\jsmith", null, true, 0);
Console.WriteLine("Job " + jobId + " submitted successfully");
return 0;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return 1;
}
}
}
}