GridLINQ and Digipede

In a little over an hour last night I had a (very) basic GridLINQ working on Digipede. The code isn’t beautiful, but it effectively does what it says on the side of the tin 🙂 I couldn’t have got this working without Nathan @ Digipede. The code below currently assumes a Digipede Worker pattern and comments have been removed to save space.

using System; using System.Collections.Generic; using System.Linq; using Digipede.Framework.Api; namespace GridLinqTest { sealed class Program { static readonly string mUsage = "Usage: GridLinqTest {0}"; static int Main(string[] args) { DigipedeClient client = new DigipedeClient(); client.ProcessArguments(args, true); if (!client.IsInitialized) { Console.WriteLine(mUsage, DigipedeClient.UsageSummary); return -1; } IList<MonteCarloPiWorker> mcpis = new List<MonteCarloPiWorker>() { new MonteCarloPiWorker(100), new MonteCarloPiWorker(200) }; var values = mcpis.OnGrid(client).Select(t => t.Pi); foreach (double d in values) { Console.WriteLine(d); } Console.ReadLine(); return 0; } } }

The C# extension methods and Digipede specific code is below:

using System; using System.Collections; using System.Collections.Generic; using System.Linq; using Digipede.Framework; using Digipede.Framework.Api; namespace GridLinqTest { public static class GridLinq { public interface IGridEnumerable<T> : IEnumerable<T> { } public static IGridEnumerable<T> OnGrid<T>(this IEnumerable<T> source, DigipedeClient client) { return DigipedeGridEnumerable<T>.Create(source, client); } public class GridEnumerable<T> : IGridEnumerable<T> { private readonly IEnumerable<T> _data; protected IEnumerable<T> Data { get { return _data; } } public GridEnumerable(IEnumerable<T> data) { _data = data; } IEnumerator<T> IEnumerable<T>.GetEnumerator() { return _data.GetEnumerator(); } public IEnumerator GetEnumerator() { return ((IEnumerable<T>)this).GetEnumerator(); } } public class DigipedeGridEnumerable<T> : GridEnumerable<T> { private readonly DigipedeClient _client; private readonly List<T> _results = new List<T>(); private DigipedeGridEnumerable(IEnumerable<T> data, DigipedeClient client) : base(data) { _client = client; SendDataToDigipede(); } public static GridEnumerable<T> Create(IEnumerable<T> data, DigipedeClient client) { return new DigipedeGridEnumerable<T>(data, client).Results; } private GridEnumerable<T> Results { get { return new GridEnumerable<T>(_results); } } private void SendDataToDigipede() { JobTemplate jobTemplate = JobTemplate.NewWorkerJobTemplate(typeof(Worker)); jobTemplate.Name = "GridLINQ"; jobTemplate.DiscardAfterUse = false; Job job = new Job(); foreach (T obj in Data) { Task task = new Task(); task.Worker = obj as Worker; job.Tasks.Add(task); } job.TaskFinished += TaskFinished; job.Name = "GridLINQWorker"; _client.SubmitJob(1, jobTemplate, job, SubmissionOptions.SubmitJobTemplateIfNecessary); _client.WaitForJob(job); } private void TaskFinished(object objectSender, TaskStatusEventArgs e) { if (e.TaskStatus == TaskStatus.Completed) { object o = e.Worker; T ReturnedWorker = (T)o; _results.Add(ReturnedWorker); } else if (e.TaskStatus == TaskStatus.Failed) { throw new Exception(string.Format("Task {0} failed on {1}", e.TaskId, e.TaskStatusSummary.ComputeResourceName)); } } } } }

It’s a shame DataSynapse doesn’t allow its software to be downloaded else I would attempt GridLINQ in their world as well 😦 I can’t even seen a download for Platform either 😦 Net out, Digipede rocks.

Sidebar: SyncLINQ source is available.

~ by mdavey on October 25, 2007.

2 Responses to “GridLINQ and Digipede”

  1. […] A pleasant surprise this morning: Matt Davey posted a code sample on his blog: GridLINQ and Digipede. […]

  2. […] also been checking periodically for the PLINQ/PFX/System.Concurrency release.  I follow the GridLINQ developments, and other easy-to-use tools direct or tangential to concurrency, parallel programming […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

<span>%d</span> bloggers like this: