Пример #1
0
        public FunctionContext CreateMatrix(FunctionContext ctx)
        {
            var start = Util.GetUnixTimestamp();

            if (ctx.MatrixSize == 0)
            {
                Console.WriteLine("No Size Set. Using Default Size");
                ctx.MatrixSize = 200;
            }

            if (ctx.MaxValue == 0)
            {
                Console.WriteLine("No Max Set. Using Default MaxValue");
                ctx.MaxValue = 150;
            }

            if (ctx.Seed == 0)
            {
                ctx.Seed = -1;
            }

            var id  = handler.CreateMatrix(ctx.MatrixSize, ctx.MaxValue, ctx.Seed);
            var res = new FunctionContext
            {
                Start         = start,
                CalculationID = id,
                MatrixSize    = ctx.MatrixSize,
                MaxValue      = ctx.MaxValue,
                CallbackUrl   = ctx.CallbackUrl
            };

            return(res);
        }
Пример #2
0
        public JObject Main(JObject args)
        {
            try
            {
                var size = args.ContainsKey("size") ? int.Parse(args["size"].ToString()) : 50;
                var max  = args.ContainsKey("max") ? int.Parse(args["max"].ToString()) : 5000;
                var seed = args.ContainsKey("seed") ? int.Parse(args["seed"].ToString()) : -1;
                args["hasCallback"]    = args.ContainsKey("callback");
                args["startTimestamp"] = Util.GetUnixTimestamp();

                var repo  = new CloudObjectStorageRepository(args);
                var hndlr = new FunctionHandler(repo);

                var id = hndlr.CreateMatrix(size, max, seed);

                args["id"]   = id;
                args["size"] = size;
                args["max"]  = max;

                Console.WriteLine(args.ToString());

                return(args);
            }
            catch (Exception e)
            {
                var j = new JObject();
                j["error"] = e.ToString();
                return(j);
            }
        }
Пример #3
0
        public static MatrixCalculation GenerateMatrix([ActivityTrigger] CalculationConfiguration cfg, ILogger log)
        {
            var s = cfg.MatrixSize;

            log.LogInformation($"Creating Two {s}x{s} matrices");
            var repo  = new InMemoryMatrixMulRepository();
            var hndlr = new FunctionHandler(repo);
            var id    = hndlr.CreateMatrix(s, cfg.MaxValue, cfg.Seed);

            log.LogInformation($"Created MatrixCalculations with ID {id}");

            return(repo.GetCalculation(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);
        }