Example #1
1
        public void ItFetchesEnrollmentStatus()
        {
            var mpi = new MPI(apiKey, Constants.MPITestURL);

            var builder = new EnrollCheckBuilder {
                amount              = "100",
                currency            = "DKK",
                orderID             = "1241249814",
                merchantName        = this.merchantName,
                merchantID          = this.merchantID,
                merchantAcquirerBin = this.merchantAcquirerBin,
                merchantCountry     = "DK",
                merchantUrl         = this.merchantUrl,
                cardholderIP        = "1.1.1.1",
                cardNumber          = this.cardNumber,
                cardExpireMonth     = this.cardExpireMonth,
                cardExpireYear      = this.cardExpireYear
            };

            var status = mpi.EnrollCheck(builder);

            // Most of the time the testing directory servers are offline.
            Assert.True(status.error?.message == "Directory server timeout or connection error" || status.enrolled == "Y",
                        "Status: '" + status.enrolled + "', Error: " + status.error?.message);
        }
Example #2
1
        public void ItChecksPARes()
        {
            var mpi = new MPI(apiKey, Constants.MPITestURL);

            var checkresponse = mpi.CheckPARes(pares);

            Assert.Equal("Y", checkresponse.status);
        }
Example #3
1
 public void EndGameResponse(Communication com)
 {
     if (com.PlayerId == game.LocalPlayerId)
     {
         ThreadPool.QueueUserWorkItem(delegate { Context.Post(delegate { MPI.PlayerWin(); }, null); });
     }
     else
     {
         ThreadPool.QueueUserWorkItem(delegate { Context.Post(delegate { MPI.PlayerLose(); }, null); });
     }
 }
Example #4
1
        protected void InsertRecord(object sender, GridRecordEventArgs e)
        {
            var db       = new SerializationDataContext();
            var username = User.Identity.Name;
            //            int tId = Convert.ToInt32(e.Record["ID"]);
            bool   smartCodeBool = false;
            bool   noSerialBool  = false;
            string noSerial      = e.Record["NOSERIALIZATION"].ToString();
            string smartCode     = e.Record["SMARTCODEONLY"].ToString();

            if (noSerial == "true" || noSerial == "True")
            {
                noSerialBool = true;
            }

            if (smartCode == "true" || smartCode == "True")
            {
                smartCodeBool = true;
            }

            //Add new record.
            var product = new MPI()
            {
                PRODUCTID       = e.Record["PRODUCTID"].ToString(),
                ITEMCODE        = e.Record["ITEMCODE"].ToString().ToUpper(),
                COLOR           = e.Record["COLOR"].ToString().ToUpper(),
                NOSERIALIZATION = noSerialBool,
                SMARTCODEONLY   = smartCodeBool
            };


            var productHistoryInsert = new MPI_History();

            productHistoryInsert.DATE            = DateTime.Now;
            productHistoryInsert.PRODUCTID       = product.PRODUCTID;
            productHistoryInsert.ITEMCODE        = product.ITEMCODE;
            productHistoryInsert.COLOR           = product.COLOR;
            productHistoryInsert.NOSERIALIZATION = product.NOSERIALIZATION;
            productHistoryInsert.SMARTCODEONLY   = product.SMARTCODEONLY;
            productHistoryInsert.TYPE            = "INSERT";
            productHistoryInsert.USERNAME        = username;

            //Insert new record on MPI DB.
            db.MPIs.InsertOnSubmit(product);
            //Insert new Insert record on MPI_Histories DB.
            db.MPI_Histories.InsertOnSubmit(productHistoryInsert);
            db.SubmitChanges();
        }
        public ResultOption Solve(MPI.Intracommunicator mpi)
        {
            IsMaster = mpi.Rank == 0;

            mpi.Broadcast(ref n, Root);

            Validate(mpi);

            int n_block = N / mpi.Size;

            double[] aFlattened = null;
            if (IsMaster)
            {
                aFlattened = new double[N * N];
                ToArray(a, ref aFlattened);
            }

            if (!IsMaster) b = new double[N];
            // send B across all processes
            mpi.Broadcast(ref b, Root);

            // send A
            double[] a_block = new double[n_block];
            mpi.ScatterFromFlattened(aFlattened, N * n_block, Root, ref a_block);

            // x0 = (0, 0, ..., 0)
            double[] x = new double[N];

            // r = b - A*x0;
            double[] residual_block = new double[n_block];
            CalculateResidue(ref residual_block, b, a_block, x, mpi.Rank);

            double[] p_block = new double[n_block];
            Array.Copy(residual_block, p_block, n_block);

            double residualOld_block = MatrixUtil.DotProduct(residual_block, residual_block);
            double residualOld = mpi.Allreduce(residualOld_block, MPI.Operation<double>.Add);

            double rsnew;
            double[] x_block = new double[n_block];
            double[] p = new double[N];

            var stopwatch = new Stopwatch();
            stopwatch.Start();

            double[] Ap;
            double pAp_block;
            double pAp;
            double alpha;
            double rsnew_block;

            int iteration;
            for (iteration = 0; iteration < N; iteration++)
            {
                ToArray(mpi.Allgather(p_block), ref p);

                Ap = MultiDotProduct(a_block, p);

                pAp_block = MatrixUtil.DotProduct(p_block, Ap);

                pAp = mpi.Allreduce(pAp_block, MPI.Operation<double>.Add);

                alpha = residualOld / pAp;

                MatrixUtil.Add(ref x_block, p_block, 1, alpha);

                MatrixUtil.Add(ref residual_block, Ap, 1, -alpha);

                rsnew_block = MatrixUtil.DotProduct(residual_block, residual_block);
                rsnew = mpi.Allreduce(rsnew_block, MPI.Operation<double>.Add);

                if (rsnew <= 1e-15)
                {
                    break;
                }

                MatrixUtil.Add(ref p_block, residual_block, rsnew / residualOld, 1);

                residualOld = rsnew;
            }

            ToArray(mpi.Allgather(x_block), ref x);
            X = x;

            stopwatch.Stop();

            return new ResultOption { ConvergenceIteration = iteration, SolveTime = stopwatch.ElapsedMilliseconds };
        }
 private void Validate(MPI.Intracommunicator mpi)
 {
     if (N % mpi.Size != 0)
     {
         throw new InvalidOperationException("The matrix size should be divisible by the number of processes used by MPI.");
     }
 }
Example #7
0
 public void ConnexionResponse(Communication com)
 {
     if (com.PlayerId != 0)
     {
         game.LocalPlayerId = com.PlayerId;
         ThreadPool.QueueUserWorkItem(delegate { Context.Post(delegate { MPI.ServerAcceptConnexion(); }, null); });
     }
 }