Create a OneCompute job for execution on OneCompute Platform
When creating a Job for execution on OneCompute Platform, the following job properties are essential and must be assigned prior to job submission:
- Work: The workflow of the job
- ServiceName: Name of the OneCompute application that must run the job
Some additional properties are worth setting, but are not essential for the job to execute:
- ClientReference: This is a reference the client application may set to associate the job with an application object, such as e.g. a user workspace. This reference will also appear in the jobs list int the OneCompute Portal, and makes it easier for the user to identify the job.
- SchedulingOptions: This enables application to change the default FailureStrategy from FailOnError to ContinueOnError.
- PoolId: If set, the job will be specified to run on the specified Azure Batch pool. Notice that the default pool for the application is set by the Application Owner through the OneCompute Portal, but this property will override that setting.
- DeploymentModel: Specifies additional applications, if any, that should be deployed to each compute node.
Code Example
The following code example illustrates the basic steps in defining a OneCompute Job that can be submitted for execution on OneCompute Platform.
The example used is the following:
- Generate a set of random number, each serving as input to a WorkUnit
- Taking the input, the example worker squares the number and returns the square
- In a separate reduction step, all results of the preceding calculations are summed and the sum of squares is returned
The purpose of this simple example is, using a very simple example, to demonstrate how to set up a typical workflow; parallel execution of numerous work items followed by a reduction step that aggregates the preceding results.
Before proceeding, the following sections should be reviewed:
- Understanding the Flow of Application Data between Client and Worker
- How to create an Application Worker
Defining the Workflow
The first step in defining a OneCompute Job is to define its workflow. The workflow is represented as a composition of OneCompute work items and contains the essential computational steps of the job and how they are related.
In the example below, we will create a job that first squares a set of numbers in parallel, then computes the sum of the squares in a subsequent reduction step.
var random = new Random();
var workItems = new List<WorkItem>();
for (var i = 0; i < 10; i++)
{
// Create a WorkUnit with the input to the worker
var wu = new WorkUnit(
new CalcInput
{
Input = random.NextDouble()
});
workItems.Add(wu);
}
var work = new ParallelWork
{
WorkItems = workItems,
ReductionTask = new WorkUnit()
};
Create the Job
When creating the OneCompute Job, two properties are essential to set, namely the ServiceName and Work. The former specifies which OneCompute application contains the worker that should execute the work units of the job. The latter must contain the prescribed the workflow.
var job = new Job
{
ServiceName = "CalcWorker", // Name of the OneCompute Application
Work = work
};
This job is now ready to be submitted to OneCompute Platform.
See also
Concepts:
Types: