0% found this document useful (0 votes)
5 views2 pages

Aneka Program

The document outlines a program that utilizes the Aneka Task Programming model to sum two numbers. It defines a MyTask class that implements the ITask interface, where the Execute method computes the sum of two integers. The main program sets up an Aneka application, executes the MyTask, and handles events for work unit completion and failure.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Aneka Program

The document outlines a program that utilizes the Aneka Task Programming model to sum two numbers. It defines a MyTask class that implements the ITask interface, where the Execute method computes the sum of two integers. The main program sets up an Aneka application, executes the MyTask, and handles events for work unit completion and failure.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

HelloTask ht = new HelloTask();

AnekaTask gt = new AnekaTask(ht);


app.ExecuteWorkUnit(gt);
semaphore.WaitOne();

}
finally
{
Logger.Stop();
}
}

static void app_ApplicationFinished(object sender, ApplicationEventArgs e)


{
semaphore.Set();
}

static void app_WorkUnitFailed(object sender, WorkUnitEventArgs<AnekaTask> e)


{
Console.WriteLine("WorkUnit Failed");
}

static void app_WorkUnitFinished(object sender, WorkUnitEventArgs<AnekaTask> e)


{
Console.WriteLine("Inside WorkUnit finished");
HelloTask ht = e.WorkUnit.UserTask as HelloTask;
Console.WriteLine(ht.result);
app.StopExecution();

}
}
}

Qn : Write a program to sum the two numbers using Aneka Task Programming model ?
Program
using System;
using System.Collections.Generic;
using System.Text;
using Aneka;
using Aneka.Entity;
using Aneka.Tasks;
using System.Threading;
namespace AnekaTaskPractise
{
[Serializable]
public class MyTask : ITask
{
public int a, b;
public int sum;
public MyTask(int a, int b) { this.a = a; this.b = b; }
public void Execute()
{
Console.WriteLine("Inside Execute");
sum = a + b;
}
}

9
class Program
{
static AutoResetEvent semaphore = null;
static AnekaApplication<AnekaTask, TaskManager> app = null;
static void Main(string[] args)
{
Configuration conf=null;

AnekaTask gt = null;
try
{
Logger.Start();
semaphore = new AutoResetEvent(false);
conf =
Configuration.GetConfiguration(@"C:\Users\raghav\Documents\CloudComputing-
Lectures\conf.xml");
conf.SingleSubmission = false;
app = new AnekaApplication<AnekaTask, TaskManager>(conf);
app.WorkUnitFailed += new
EventHandler<WorkUnitEventArgs<AnekaTask>>(app_WorkUnitFailed);
app.WorkUnitFinished += new
EventHandler<WorkUnitEventArgs<AnekaTask>>(app_WorkUnitFinished);
app.ApplicationFinished += new
EventHandler<ApplicationEventArgs>(app_ApplicationFinished);
MyTask task = new MyTask(10,20);
gt = new AnekaTask(task);
app.ExecuteWorkUnit(gt);
semaphore.WaitOne();

}
finally
{
Logger.Stop();

}
static void app_ApplicationFinished(object sender, ApplicationEventArgs e)
{
semaphore.Set();
}

static void app_WorkUnitFinished(object sender, WorkUnitEventArgs<AnekaTask> e)


{
Console.WriteLine("Workunit finished:"+((MyTask)e.WorkUnit.UserTask).sum);
app.StopExecution();
}

static void app_WorkUnitFailed(object sender, WorkUnitEventArgs<AnekaTask> e)


{

}
}
}

10

You might also like