public void Run(ModuleInfo info, CancellationToken token = default(CancellationToken))
        {
            double a = 0;
            double b = Math.PI/2;
            double h = 0.00000001;
            const int pointsNum = 2;
            var points = new IPoint[pointsNum];
            var channels = new IChannel[pointsNum];
            for (int i = 0; i < pointsNum; ++i)
            {
                points[i] = info.CreatePoint();
                channels[i] = points[i].CreateChannel();
                points[i].ExecuteClass("FirstModule.IntegralModule");
            }

            double y = a;
            for (int i = 0; i < pointsNum; ++i)
            {
                channels[i].WriteData(y);
                channels[i].WriteData(y + (b - a) / pointsNum);
                channels[i].WriteData(h);
                y += (b - a) / pointsNum;
            }
            DateTime time = DateTime.Now;            
            Console.WriteLine("Waiting for result...");

            double res = 0;
            for (int i = pointsNum - 1; i >= 0; --i)
            {
                res += channels[i].ReadData(typeof(double));
            }

            Console.WriteLine("Result found: res = {0}, time = {1}", res, Math.Round((DateTime.Now - time).TotalSeconds,3));
            
        }
        public void Run(ModuleInfo info, CancellationToken token = default(CancellationToken))
        {
            double a = info.Parent.ReadData(typeof(double));
            double b = info.Parent.ReadData(typeof(double));
            double h = info.Parent.ReadData(typeof(double));
            var func = new Func<double, double>(x => Math.Cos(x));

            double res = Integral(a, b, h, func);
            info.Parent.WriteData(res);
        }
        public override void Run(ModuleInfo info, CancellationToken token = default(CancellationToken))
        {
            string file1 = options.File1;
            string file2 = options.File2;
            Matrix a, b;

            try
            {
                a = Matrix.LoadFromFile(file1);
                b = Matrix.LoadFromFile(file2);
            }

            catch (FileNotFoundException ex)
            {
                _log.Error("File with a given fileName not found, stopping the application...", ex);
                return;
            }

            int[] possibleValues = { 1, 2, 4, 8, 16, 32 };
            
            int pointsNum = options.PointsNum;

            if (!possibleValues.Contains(pointsNum))
            {
                _log.ErrorFormat("Cannot start module with given number of points. Possible usages: {0}", string.Join(" ", possibleValues));
                return;
            }

            _log.InfoFormat("Starting Matrixes Module on {0} points", pointsNum);

            var points = new IPoint[pointsNum];
            var channels = new IChannel[pointsNum];
            for (int i = 0; i < pointsNum; ++i)
            {
                points[i] = info.CreatePoint();
                channels[i] = points[i].CreateChannel();
                points[i].ExecuteClass("NewMatrixModule.MultMatrix");
            }

            var resMatrix = new Matrix(a.Height, b.Width);
            DateTime time = DateTime.Now;
            _log.Info("Waiting for a result...");

            switch (pointsNum)
            {
                case 1:
                    channels[0].WriteObject(a);
                    channels[0].WriteObject(b);
                    resMatrix = (Matrix)channels[0].ReadObject(typeof(Matrix));
                    break;
                case 2:
                    {
                        var matrixPairs = Divide2(a, b).ToArray();
                        channels[0].WriteObject(matrixPairs[0].Item1);
                        channels[0].WriteObject(matrixPairs[0].Item2);
                        channels[1].WriteObject(matrixPairs[1].Item1);
                        channels[1].WriteObject(matrixPairs[1].Item2);

                        LogSendingTime(time);

                        Join2(resMatrix, channels.Select(c => new Lazy<Matrix>(c.ReadObject<Matrix>)).ToArray());
                    }
                    break;
                case 4:
                    {
                        var matrixPairs = Divide4(a, b).ToArray();
                        for (int i = 0; i < matrixPairs.Length; i++)
                        {
                            channels[i].WriteObject(matrixPairs[i].Item1);
                            channels[i].WriteObject(matrixPairs[i].Item2);
                        }

                        LogSendingTime(time);

                        Join4(resMatrix, channels.Select(c => new Lazy<Matrix>(c.ReadObject<Matrix>)).ToArray());
                    }
                    break;
                case 8:
                    {
                        var matrixPairs = Divide8(a, b).ToArray();
                        for (int i = 0; i < matrixPairs.Length; i++)
                        {
                            channels[i].WriteObject(matrixPairs[i].Item1);
                            channels[i].WriteObject(matrixPairs[i].Item2);
                        }

                        LogSendingTime(time);

                        Join8(resMatrix, channels.Select(c => new Lazy<Matrix>(c.ReadObject<Matrix>)).ToArray());
                    }
                    break;
                case 16:
                    {
                        var matrixPairs8 = Divide8(a, b).ToArray();
                        for (int i = 0; i < 8; i++)
                        {
                            var m2 = Divide2(matrixPairs8[i].Item1, matrixPairs8[i].Item2).ToArray();
                            channels[i * 2].WriteObject(m2[0].Item1);
                            channels[i * 2].WriteObject(m2[0].Item2);
                            channels[i * 2 + 1].WriteObject(m2[1].Item1);
                            channels[i * 2 + 1].WriteObject(m2[1].Item2);
                        }

                        LogSendingTime(time);

                        var resMatrix8 =
                            Enumerable.Range(0, 8)
                                .Select(i => new Matrix(matrixPairs8[i].Item1.Height, matrixPairs8[i].Item2.Width))
                                .ToArray();
                        for (int i = 0; i < 8; i++)
                        {
                            Join2(
                                resMatrix8[i],
                                new[] { channels[2 * i], channels[2 * i + 1] }.Select(
                                    c => new Lazy<Matrix>(c.ReadObject<Matrix>)).ToArray());
                        }

                        Join8(resMatrix, resMatrix8.Select(m => new Lazy<Matrix>(() => m)).ToArray());
                            //not nice, probably create overload
                    }
                    break;
                case 32:
                    {
                        var matrixPairs8 = Divide8(a, b).ToArray();
                        for (int i = 0; i < 8; i++)
                        {
                            var m4 = Divide4(matrixPairs8[i].Item1, matrixPairs8[i].Item2).ToArray();

                            for (int j = 0; j < 4; j++)
                            {
                                channels[i * 4 + j].WriteObject(m4[j].Item1);
                                channels[i * 4 + j].WriteObject(m4[j].Item2);
                            }
                        }

                        LogSendingTime(time);

                        var resMatrix8 =
                            Enumerable.Range(0, 8)
                                .Select(i => new Matrix(matrixPairs8[i].Item1.Height, matrixPairs8[i].Item2.Width))
                                .ToArray();
                        for (int i = 0; i < 8; i++)
                        {
                            Join4(
                                resMatrix8[i],
                                Enumerable.Range(0, 4)
                                    .Select(j => channels[4 * i + j])
                                    .Select(c => new Lazy<Matrix>(c.ReadObject<Matrix>))
                                    .ToArray());
                        }

                        Join8(resMatrix, resMatrix8.Select(m => new Lazy<Matrix>(() => m)).ToArray());
                            //not nice, probably create overload
                    }
                    break;
                default:
                    _log.Error("Unexpected error.");
                    return;
            }

            LogResultFoundTime(time);
            SaveMatrix(resMatrix);
        }
Exemple #4
0
 public void Run(ModuleInfo info, CancellationToken token = default(CancellationToken))
 {
     Matrix m = (Matrix)info.Parent.ReadObject(typeof(Matrix));
     Matrix m1 = (Matrix)info.Parent.ReadObject(typeof(Matrix));
     info.Parent.WriteObject(m.MultiplyBy(m1, token));
 }
Exemple #5
0
 public abstract void Run(ModuleInfo info, CancellationToken token = default(CancellationToken));