public FunctionContext MultiplyTasksWorker(FunctionContext ctx) { int workerId = int.Parse(ctx.WorkerID); handler.ParallelMultiplyWorker(ctx.CalculationID, workerId); return(ctx); }
public static ComputationResult[] ParallelMultiply([ActivityTrigger] ParallelWorkerContext ctx, ILogger log) { var repo = new InMemoryMatrixMulRepository(); repo.StoreCalculation("an_id", ctx.Calculation); repo.StoreComputationTasksForWorker("an_id", ctx.WorkerID, ctx.Tasks); var hndlr = new FunctionHandler(repo); log.LogInformation($"Worker #{ctx.WorkerID} Running parallel Multiplication tasks"); hndlr.ParallelMultiplyWorker("an_id", ctx.WorkerID); return(repo.GetComputationResults("an_id", ctx.WorkerID)); }
public void TestParallelMulBySeed() { var start = Util.GetUnixTimestamp(); _out.WriteLine($"Creating 2 {Size}x{Size} Matrices with Max Value {Max} based on seed {Seed}"); var id = hndlr.CreateMatrix(Size, Max, Seed); _out.WriteLine($"Got ID {id}"); _out.WriteLine($"Running parallel Multiply"); hndlr.ScheduleMultiplicationTasks(id, 5); var tasks = new List <Task>(); for (int i = 0; i < 5; i++) { _out.WriteLine($"Running Worker #{i}"); hndlr.ParallelMultiplyWorker(id, i); } _out.WriteLine("Building Result"); hndlr.BuildResultMatrix(id, 5); _out.WriteLine("Creating Report"); var report = hndlr.GenerateReport(null, start, id, 0); _out.WriteLine(report.ToString()); _out.WriteLine("A:"); _out.WriteLine(repo.GetCalculation(id).A.ToString()); _out.WriteLine("B:"); _out.WriteLine(repo.GetCalculation(id).B.ToString()); _out.WriteLine("Result:"); _out.WriteLine(repo.GetResultMatrix(id).ToString()); Assert.Equal(121672, report.ResultMatrix.Average); Assert.Equal(78312, report.ResultMatrix.Minimum); Assert.Equal(168397, report.ResultMatrix.Maximum); }
public JObject Main(JObject args) { try { var repo = new CloudObjectStorageRepository(args); var hndlr = new FunctionHandler(repo); hndlr.ParallelMultiplyWorker(args["id"].ToString(), int.Parse(args["worker_id"].ToString())); Console.WriteLine(args.ToString()); return(args); } catch (Exception e) { var j = new JObject(); j["error"] = e.ToString(); return(j); } }