0% found this document useful (0 votes)
9 views11 pages

Cloud Programming with Aneka Threads

The document outlines a series of programming exercises focused on using the Aneka Thread and Task Programming models for various computational tasks, including printing 'Hello World', mathematical computations, matrix operations, and image processing. Each exercise includes a brief description, a procedure for setting up the project, and sample source code. The exercises aim to illustrate the differences between conventional threading and cloud programming while leveraging the capabilities of the Aneka framework.

Uploaded by

Surya Basnet
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views11 pages

Cloud Programming with Aneka Threads

The document outlines a series of programming exercises focused on using the Aneka Thread and Task Programming models for various computational tasks, including printing 'Hello World', mathematical computations, matrix operations, and image processing. Each exercise includes a brief description, a procedure for setting up the project, and sample source code. The exercises aim to illustrate the differences between conventional threading and cloud programming while leveraging the capabilities of the Aneka framework.

Uploaded by

Surya Basnet
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Cloud Lab Exercises/Experiments

[1] Write a program to understand the differences between conventional Thread


programming and Cloud programming using Aneka Thread Model.
[2] Write a program to print “Hello World” based on Thread model and use exactly five
threads also print the executor node information along with the Submission Time and
Completion Time?
[3] Write a program to compute the following mathematical equation using Aneka
Threads(Note: Consider each trigonometric function in independent thread)?
P= sin(x) + cos(y) + tan(z)
[4] Write a program to compute the matrix addition using Aneka Thread Programming
Model
[5] Write a program for parallel execution of Mandelbrot generation algorithm in parallel
using Aneka Threads
[6] Write a program to compute the matrix multiplication using Aneka Thread
Programming Model
[7] Write a program to decompose the image into 25 parts(5X5) and apply
histogram(dynamic stretch)
[8] Write a program to parse the log files using Map/Reduce or Thread Programming
Model
[9] Write a program using Map/Reduce to count the words in the given input set
[10] Write a program for Image Convolution using Task Programming Model
[11] Write a program for sorting large number of records (say 1000 entries) stored in a
file. You can create N threads (say 4 or 10) and each Thread taking responsibility for
sorting a part of file (e.g., Thread1 can sort first 1000/N record; and Thread 2 can sort
next set and continues) and a Master Thread can merge all these sorted sub-set of
records.
[12] Write a program for the tabulation of the Gaussian function by using simple
threads and the convert it to Aneka threads.
[13] Write a program that executes operations of data mining algorithms in parallel on
Clouds.
[14] Write a program for parallel execution of Ray Tracing operations. You can pick up
sequential Ray tracking programs such as PovRay for rendering and convert it for
parallel execution using Aneka Task programming model.
[15] Write a program for parallel execution of bioinformatics algorithms such as Basic
Local Alignment Search Tool (BLAST) used for comparing primary biological
sequence information. You can select a suitable Cloud programming model and also
implement a graphical user interface for start execution of applications.

1
Answers to Selected Programming Exercises
Thread Model
Qn : Write a program to print “Hello World” using Aneka Thread Programming model use Single Thread?
Procedure
Follow the below mentioned steps to create the project and the necessary references
1. Creating a C# Console Application in .NET 2.0
a. Go to File -> New -> Project.
b. From New Project Dialog select visual C# - > windows .
c. Select .NET 2.0 and Console Application.
d. Enter the Solution Name and press OK.
2. Add References to the project from the following folders under Solution Explorer
a. Right Click on the references
i. Click on Add Reference
ii. Click on Browse Tab
iii. Select the following folders one after the other and add them
 C:\Program Files\Manjrasoft\Aneka.3.0\Tools\SDK\Common
 C:\Program Files\Manjrasoft\Aneka.3.0\Tools\SDK\Runtime
 C:\Program Files\Manjrasoft\Aneka.3.0\Tools\SDK\Thread Model

3. Place the [Link] in the folder and mention the same path in the code.
4. Add the below mentioned code to .CS file by replacing the code in the appropriate place
Source code
using System;
using [Link];
using [Link];
using Aneka;
using [Link];
using [Link];
using [Link];

namespace AnekaThreadPractise1
{
[Serializable]
public class HelloWorld
{
public string result;
public HelloWorld()
{
}
public void PrintHello()
{
result = "HelloWorld";
}
}
class Program
{
static void Main(string[] args)
{
AnekaApplication<AnekaThread, ThreadManager> app = null;
try
{
[Link]();
Configuration conf =
[Link](@"C:\Users\raghav\Documents\
CloudComputing-Lectures\[Link]");

2
app = new AnekaApplication<AnekaThread,
ThreadManager>(conf);
HelloWorld hw = new HelloWorld();

AnekaThread th = new AnekaThread([Link], app);


[Link]();
[Link]();
hw = (HelloWorld)[Link];
[Link]("Value : " + [Link]);
}
finally
{
[Link]();
[Link]();
}
}
}
}

Ouput :
Value : Helloworld
Qn : Write a program to print “Hello World” based on Thread model and use exactly five threads also print the
executor node information along with the Submission Time and Completion Time?
using System;
using [Link];
using [Link];
using Aneka;
using [Link];
using [Link];
using [Link];
namespace AnekaThreadsfive
{
[Serializable]
public class HelloWorld
{
public string result;
public HelloWorld()
{
}
public void PrintHello()
{
result = "HelloWorld";
}
}
class Program
{
static void Main(string[] args)
{
AnekaApplication<AnekaThread, ThreadManager> app = null;
try
{
[Link]();
Configuration conf = [Link](@"C:\Users\
raghav\Documents\CloudComputing-Lectures\[Link]");
app = new AnekaApplication<AnekaThread, ThreadManager>(conf);
HelloWorld hw = new HelloWorld();
AnekaThread[] th = new AnekaThread[5];

3
for (int i = 0; i < 5; i++)
{
th[i] = new AnekaThread([Link], app);
th[i].Start();

}
for (int i = 0; i < 5; i++)
{
th[i].Join();
hw = (HelloWorld)th[i].Target;
[Link]("Value : {0} , NodeId:{1},Submission Time:
{2},Completion Time{3}", [Link],
th[i].NodeId,th[i].SubmissionTime,th[i].CompletionTime);
}
}
finally
{
[Link]();
[Link]();
}
}
}
}
Qn : Write a program to print “Hello World” using Aneka Thread Programming model and
Conventional Thread and Understand the differences?
Procedure
Follow the steps mentioned from 1 to 4 of mentioned in the procedure of the previous Question
Source code
using System;
using [Link];
using [Link];
using Aneka;
using [Link];
using [Link];
using [Link];
namespace AnekaThreadPractise1
{
[Serializable]
public class HelloWorld
{
public string result;
public HelloWorld()
{
}
public void PrintHello()
{
[Link]("inside printHello : HelloWorld");
result = "HelloWorld";
}
}
class Program
{
static void Main(string[] args)
{
AnekaApplication<AnekaThread, ThreadManager> app = null;
try
{

4
[Link]();
Configuration conf =
[Link](@"C:\Users\raghav\Documents\
CloudComputing-Lectures\[Link]");
app = new AnekaApplication<AnekaThread,
ThreadManager>(conf);
HelloWorld hw = new HelloWorld();

AnekaThread th = new AnekaThread([Link], app);


[Link]();
[Link]();
hw = (HelloWorld)[Link];
[Link]("Value : " + [Link]);

HelloWorld conventionalhw = new HelloWorld();


Thread conventionalThread = new
Thread([Link]);
[Link]();

}
finally
{
[Link]();
[Link]();
}
}
}
}

Ouput :
Value : HelloWorld
inside printHello : HelloWorld

Qn : Write a program to print “Hello World” using Aneka Thread Programming model use Five
Threads , also print the NodeIds on which the threads are executed and submission time and
Completion Time of the Threads?
Procedure
[Link] steps mentioned from 1 to 4 of mentioned in the procedure of the previous Question
Source code
using System;
using [Link];
using [Link];
using Aneka;
using [Link];
using [Link];
using [Link];
namespace AnekaThreadsfive
{
[Serializable]
public class HelloWorld
{
public string result;
public HelloWorld()
{
}
public void PrintHello()

5
{
result = "HelloWorld";
}
}
class Program
{
static void Main(string[] args)
{
AnekaApplication<AnekaThread, ThreadManager> app = null;
try
{
[Link]();
Configuration conf = [Link](@"C:\Users\
raghav\Documents\CloudComputing-Lectures\[Link]");
app = new AnekaApplication<AnekaThread, ThreadManager>(conf);
HelloWorld hw = new HelloWorld();
AnekaThread[] th = new AnekaThread[5];
for (int i = 0; i < 5; i++)
{
th[i] = new AnekaThread([Link], app);
th[i].Start();

}
for (int i = 0; i < 5; i++)
{
th[i].Join();
hw = (HelloWorld)th[i].Target;
[Link]("Value : {0} , NodeId:{1},Submission Time:
{2},Completion Time{3}", [Link],
th[i].NodeId,th[i].SubmissionTime,th[i].CompletionTime);
}
}
finally
{
[Link]();
[Link]();
}
}
}
}

output
Value : HelloWorld , NodeId:raghav-PC-9090,Submission Time:20-Nov-12 11:19:45 PM,Completion
Time20-Nov-12 11:19:45 PM
Value : HelloWorld , NodeId:raghav-PC-9090,Submission Time:20-Nov-12 11:19:45 PM,Completion
Time20-Nov-12 11:19:45 PM
Value : HelloWorld , NodeId:raghav-PC-9090,Submission Time:20-Nov-12 11:19:45 PM,Completion
Time20-Nov-12 11:19:45 PM
Value : HelloWorld , NodeId:raghav-PC-9090,Submission Time:20-Nov-12 11:19:45 PM,Completion
Time20-Nov-12 11:19:45 PM
Value : HelloWorld , NodeId:raghav-PC-9090,Submission Time:20-Nov-12 11:19:45 PM,Completion
Time20-Nov-12 11:19:45 PM

Qn : Write a program to compute the following mathematical equation using Aneka Threads(Note: Consider
each trigonometric function in independent thread)?

6
P= sin(x) + cos(y) + tan(z)
Procedure
using System;
using [Link];
using [Link];
using Aneka;
using [Link];
using [Link];

namespace AnekaThreadTrigonometric
{
[Serializable]
public class Sine
{
double x;
public double result;
public Sine(double x)
{
this.x = x;
}
public void sineCompute()
{
result = [Link](x*[Link]/180);
}
}
[Serializable]
public class Cosine
{
double x;
public double result;
public Cosine(double x)
{
this.x = x;
}
public void cosineCompute()
{
result = [Link](x * [Link] / 180);
}
}
[Serializable]
public class Tangent
{
double x;
public double result;
public Tangent(double x)
{
this.x = x;
}
public void tangentCompute()
{
result = [Link](x * [Link] / 180);
}
}
class Program
{
static void Main(string[] args)
{
AnekaApplication<AnekaThread, ThreadManager> app = null;

7
try
{
[Link]();
Configuration conf =
[Link](@"C:\Users\raghav\Documents\
CloudComputing-Lectures\[Link]");
app = new AnekaApplication<AnekaThread,
ThreadManager>(conf);

Sine sine = new Sine(10);


AnekaThread thsine = new
AnekaThread([Link], app);
[Link]();
[Link]();
sine = (Sine)[Link];

Cosine cosine = new Cosine(20);


AnekaThread thcosine = new
AnekaThread([Link], app);
[Link]();
[Link]();
cosine = (Cosine)[Link];

Tangent tanget = new Tangent(20);


AnekaThread thtangent = new
AnekaThread([Link], app);
[Link]();
[Link]();
tanget = (Tangent)[Link];
[Link]("P = sin(10)+cos(20)+tan(20) =
{0}", [Link] + [Link] + [Link]);

}
finally
{
[Link]();
[Link]();
}

}
}
}

Output
P = sin(10)+cos(20)+tan(20) = 1.47731103271904

Task Model
Qn : Write a program to print “Hello World” using Aneka Task Programming model ?
Procedure
Follow the below mentioned steps to create the project and the necessary references
5. Creating a C# Console Application in .NET 2.0
a. Go to File -> New -> Project.
b. From New Project Dialog select visual C# - > windows .
c. Select .NET 2.0 and Console Application.
d. Enter the Solution Name and press OK.
6. Add References to the project from the following folders under Solution Explorer

8
a. Right Click on the references
i. Click on Add Reference
ii. Click on Browse Tab
iii. Select the following folders one after the other and add them
 C:\Program Files\Manjrasoft\Aneka.3.0\Tools\SDK\Common
 C:\Program Files\Manjrasoft\Aneka.3.0\Tools\SDK\Runtime
 C:\Program Files\Manjrasoft\Aneka.3.0\Tools\SDK\TaskModel

7. Place the [Link] in the folder and mention the same path in the code.
8. Add the below mentioned code to .CS file by replacing the code in the appropriate place

Program
using System;
using [Link];
using [Link];
using Aneka;
using [Link];
using [Link];
using [Link];

namespace AnekaTaskDemo
{
[Serializable]
public class HelloTask : ITask
{
public string result;
public void Execute()
{
result = "Hello";
[Link]("Result is set : "+result);
[Link]("HelloWorld");
}
}
class Program
{
static AutoResetEvent semaphore = null;
static AnekaApplication<AnekaTask, TaskManager> app = null;
static void Main(string[] args)
{

try
{
[Link]();
semaphore = new AutoResetEvent(false);
Configuration conf = [Link](@"C:\Users\
raghav\Documents\CloudComputing-Lectures\[Link]");
// [Link] = false;
app = new AnekaApplication<AnekaTask, TaskManager>(conf);
[Link] += new
EventHandler<WorkUnitEventArgs<AnekaTask>>(app_WorkUnitFailed);
[Link] += new
EventHandler<WorkUnitEventArgs<AnekaTask>>(app_WorkUnitFinished);
[Link] += new
EventHandler<ApplicationEventArgs>(app_ApplicationFinished);
HelloTask ht = new HelloTask();
AnekaTask gt = new AnekaTask(ht);
[Link](gt);
[Link]();

9
}
finally
{
[Link]();
}
}

static void app_ApplicationFinished(object sender, ApplicationEventArgs


e)
{
[Link]();
}

static void app_WorkUnitFailed(object sender,


WorkUnitEventArgs<AnekaTask> e)
{
[Link]("WorkUnit Failed");
}

static void app_WorkUnitFinished(object sender,


WorkUnitEventArgs<AnekaTask> e)
{
[Link]("Inside WorkUnit finished");
HelloTask ht = [Link] as HelloTask;
[Link]([Link]);
[Link]();

}
}
}

Qn : Write a program to sum the two numbers using Aneka Task Programming model ?
Program
using System;
using [Link];
using [Link];
using Aneka;
using [Link];
using [Link];
using [Link];
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()
{
[Link]("Inside Execute");
sum = a + b;
}
}
class Program

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

AnekaTask gt = null;
try
{
[Link]();
semaphore = new AutoResetEvent(false);
conf = [Link](@"C:\Users\raghav\
Documents\CloudComputing-Lectures\[Link]");
[Link] = false;
app = new AnekaApplication<AnekaTask, TaskManager>(conf);
[Link] += new
EventHandler<WorkUnitEventArgs<AnekaTask>>(app_WorkUnitFailed);
[Link] += new
EventHandler<WorkUnitEventArgs<AnekaTask>>(app_WorkUnitFinished);
[Link] += new
EventHandler<ApplicationEventArgs>(app_ApplicationFinished);
MyTask task = new MyTask(10,20);
gt = new AnekaTask(task);
[Link](gt);
[Link]();

}
finally
{
[Link]();

}
static void app_ApplicationFinished(object sender, ApplicationEventArgs
e)
{
[Link]();
}

static void app_WorkUnitFinished(object sender,


WorkUnitEventArgs<AnekaTask> e)
{
[Link]("Workunit finished:"+
((MyTask)[Link]).sum);
[Link]();
}

static void app_WorkUnitFailed(object sender,


WorkUnitEventArgs<AnekaTask> e)
{

}
}
}

11

Common questions

Powered by AI

Key steps include setting up a C# Console Application with appropriate references, initializing the Aneka environment using a configuration file, creating threads for execution with the desired method, managing the start and join operations for synchronization, and finally displaying the output with node and execution time details to verify correct execution and management of threads .

Aneka Thread Programming provides a cloud infrastructure that abstracts the underlying hardware, offering features like dynamic scaling and resource management, which leads to better utilization of distributed resources. In contrast, conventional Thread programming typically runs on a local machine and lacks these capabilities, requiring manual management of threads and resources .

When sorting a large dataset, the Aneka Thread Model uses multiple threads to divide and conquer the dataset, with each thread sorting a subset before a master thread merges the results. In contrast, Map/Reduce distributes data across nodes where the map phase sorts the data locally and a reduce phase merges it. Aneka can dynamically allocate resources, while Map/Reduce provides fault tolerance and scalability across distributed systems .

Aneka Tasks improve performance in parallel executions by leveraging distributed computing resources to execute parts of complex algorithms like Ray Tracing concurrently. This parallel execution reduces computation time significantly through load balancing and task scheduling, ensuring efficient resource use and faster completion of computationally intense tasks .

Running each function in an independent thread when computing trigonometric equations using Aneka Threads allows for concurrent processing, reducing total execution time compared to sequential execution. This approach fully utilizes available computational resources but requires careful management of thread lifecycles and results aggregation to ensure correctness and efficiency .

The Aneka Thread Model is advantageous for parallel execution because it allows tasks to be executed concurrently across multiple nodes in a cloud environment, enabling better resource utilization and scalability. This leads to improved performance and efficiency, especially for computationally intensive tasks like the Mandelbrot generation or bioinformatics algorithms such as BLAST .

When using Map/Reduce or Thread programming for log file parsing, developers must consider data partitioning to ensure balanced workload distribution, synchronization mechanisms to handle concurrent writes, error handling for data consistency, and optimization strategies to reduce data shuffling. Choosing between the two models involves evaluating scalability needs, fault tolerance, and environment specifics .

The Configuration object in Aneka Task Programming is crucial for setting up the application environment. It specifies necessary parameters and paths, such as the location of configuration files, to initialize the cloud application, and to manage task execution settings, ensuring the cloud-based tasks are correctly executed and monitored .

Executor node information impacts performance monitoring by providing detailed insights into which nodes execute tasks, submission and completion times, and resource usage. This data enables precise tracking and analysis of task efficiency, helping identify bottlenecks, optimize resource allocation, and improve overall cloud infrastructure performance .

Implementing a multi-threaded matrix multiplication program using Aneka Thread Programming Model involves challenges such as ensuring thread synchronization, managing data dependencies between threads, and optimizing resource distribution across the cloud to achieve efficient computation. Effectively handling these aspects is crucial to prevent performance bottlenecks .

You might also like