Introduction:
Grid computing has become necessary with increase in need for computing power. Grid computing primarily allows us to delegate the processing to idle nodes. Several embarrassingly parallel applications which run poorly in uni-processor machines can be run on computational grids. Several middleware are available. Prominent ones for .NET 2.0 platform are Digipede and Alchemi.
Here I am going to demonstrate a powerful application written in C# which makes use of Alchemi middleware. The application is written primarily to digitally sign a document using SHA512 authentication. Normally it will take a long amount of time but if written in a parallel fashion speedup will be significant.
The entire document/file to be processed is split into several blocks based on its size and the number of nodes available. Now digital signing (using .NET in-built System.Cryptography) is done. The output of this parallel processing is sent to a file.
Code:
using System;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Security.Permissions;
using System.Threading;
// Referring the Alchemi libraries
using Alchemi.Core;
using Alchemi.Core.Owner;
namespace Grypto
{
namespace Crypt
{
internal static class Grypto
{
private static Process p;
public static StringBuilder sb;
public static FileStream fs;
public static string fname;
public static StreamWriter sw;
public static FileStream output;
// The Grid Application domain in which Grid threads are created
private static GApplication Main_ga = new GApplication();
[STAThread()]
public static void
{
p = new Process();
int i = 1;
int proc = 1;
int execount = 0;
double factor = 0.2;
int numblocks = 50;
char[] feed = new char[100001];
output = new FileStream("output.txt", FileMode.Create, FileAccess.Write);
sb = new StringBuilder();
sw = new StreamWriter(output);
// Name of the file to be signed
Console.WriteLine("Enter the name of file");
fname = Console.ReadLine();
try
{
fs = new FileStream(fname, FileMode.Open, FileAccess.Read);
}
catch (Exception ex)
{
Console.WriteLine("File could not be read");
return;
}
StreamReader fr = new StreamReader(fs);
Console.WriteLine("Welcome to Grid Framework");
Console.ReadLine();
//Connection is established
GConnection gc = new GConnection("localhost", 9000, "user", "user");
Main_ga.Connection = gc;
// The processing class is added to the manifest
Main_ga.Manifest.Add(new ModuleDependency(typeof(NCrypt).Module));
Console.WriteLine("Connecting to the server....");
// Event handlers when Gthreads and GApplication finish
Main_ga.ThreadFinish += new GThreadFinish(tfin);
Main_ga.ApplicationFinish += new GApplicationFinish(appfin);
// Reading the document in blocks and adding Gthreads
Join the conversation! Your thoughts help the community grow.