public FunctionContext BuildResultMatrix(FunctionContext ctx) { int workerCnt = int.Parse(ctx.WorkerCount); handler.BuildResultMatrix(ctx.CalculationID, workerCnt); return(ctx); }
public static Matrix BuildResultMatrix([ActivityTrigger] BuildResultContext ctx, ILogger log) { var repo = new InMemoryMatrixMulRepository(); repo.StoreCalculation("an_id", ctx.Calculation); repo.WorkerResults.Add("an_id", ctx.Results); var hndlr = new FunctionHandler(repo); log.LogInformation($"Building Result Matrix"); hndlr.BuildResultMatrix("an_id", ctx.Results.Count); return(repo.GetResultMatrix("an_id")); }
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.BuildResultMatrix(args["id"].ToString(), int.Parse(args["worker_count"].ToString())); Console.WriteLine(args.ToString()); return(args); } catch (Exception e) { var j = new JObject(); j["error"] = e.ToString(); return(j); } }