예제 #1
0
파일: mtVector.cs 프로젝트: xyuan/BoSSS
        /// <summary>
        /// For each <em>j</em>, <br/>
        /// this[j] = this[j]*<paramref name="other"/>[j]
        /// </summary>
        /// <param name="other"></param>
        public override void MultiplyElementWise(VectorBase other)
        {
            if (!m_IsLocked)
            {
                throw new ApplicationException("works only in locked mode.");
            }
            if (!other.IsLocked)
            {
                throw new ArgumentException("other object must be locked.", "other");
            }
            int N = this.m_Part.LocalLength;

            if (other.Part.LocalLength != N)
            {
                throw new ArgumentException("mismatch in vector size.");
            }

            MtVector o = (other as MtVector);

            ilPSP.Threading.Paralleism.For(0, N, delegate(int i0, int iE) {
                for (int i = i0; i < iE; i++)
                {
                    this.m_Storage[i] *= o.m_Storage[i];
                }
            });
        }
예제 #2
0
파일: mtVector.cs 프로젝트: xyuan/BoSSS
            internal RefCommVector(MatrixBase M, MtVector v)
                : base(M, v)
            {
                m_Owner = v;

                // allocate send buffers
                foreach (int proc in Mtx._SpmvCommPattern.ComLists.Keys)
                {
                    int    len     = Mtx._SpmvCommPattern.ComLists[proc].Length;
                    IntPtr pBuffer = Marshal.AllocHGlobal(len * sizeof(double));
                    SendBuffers.Add(proc, pBuffer);
                    SendBuffersLengths.Add(proc, len);
                }
            }
예제 #3
0
파일: mtMatrix.cs 프로젝트: xyuan/BoSSS
        override internal void SpMV_Local_Middle(double alpha, VectorBase a, double beta, VectorBase acc)
        {
            {
                MtVector __a   = a as MtVector;
                MtVector __acc = acc as MtVector;
                if (__a == null)
                {
                    throw new ArgumentException("a must be of type RefVector.", "a");
                }
                if (__acc == null)
                {
                    throw new ArgumentException("acc must be of type RefVector.", "acc");
                }
            }


            //int[] TouchCount = new int[NoOfRows];

            // reference version:
            //{
            //    double[] _a_stor = _a.Storage;
            //    double[] _acc_stor = _acc.Storage;

            //    for (int Row = 0; Row < NoOfRows; Row++) {
            //        int RowStart = loaclPart.RowStart[Row];
            //        int RowEnd = loaclPart.RowStart[Row + 1];

            //        double rowacc = 0;
            //        for (int i = RowStart; i < RowEnd; i++) {
            //            int Col = loaclPart.ColInd[i];
            //            double MtxEntry = loaclPart.Val[i];

            //            rowacc += MtxEntry * _a_stor[Col];
            //        }

            //        _acc_stor[Row] = _acc_stor[Row] * beta + rowacc * alpha;
            //    }
            //}

            //// test code
            //double[] a_clone = (double[])_a.Storage.Clone();
            //double[] acc_clone = (double[])_acc.Storage.Clone();
            // test code end

            // unsafe optimized version
            MtVector _a   = a as MtVector;
            MtVector _acc = acc as MtVector;

            //MatrixBase.CSR loaclPart = (MatrixBase.CSR)this.m_LocalMtx;
            unsafe {
                double *_a_stor   = _a.StorageAddr;
                double *_acc_stor = _acc.StorageAddr;
                int *   _rowStart = this.LocalMatrixPin.pRowStart;
                int *   ColInd    = this.LocalMatrixPin.pColInd;
                double *_val      = this.LocalMatrixPin.pVal;


                int NoOfRows = m_RowPart.LocalLength;
                ilPSP.Threading.Paralleism.For(0, NoOfRows, delegate(int i0, int iE) {
                    double *MtxEntry = _val + _rowStart[i0];
                    int *__ColInd    = ColInd + _rowStart[i0];
                    for (int Row = i0; Row < iE; Row++)
                    {
                        int RowStart = _rowStart[Row];
                        int RowEnd   = _rowStart[Row + 1];

                        double rowacc = 0;
                        for (int i = RowStart; i < RowEnd; i++)
                        {
                            rowacc += *MtxEntry * _a_stor[*__ColInd];
                            __ColInd++;
                            MtxEntry++;
                        }

                        _acc_stor[Row] = _acc_stor[Row] * beta + rowacc * alpha;
                    }
                });
            }

            //// Test code: test ok 05aug10, 16:36
            //base.m_LocalMtx.RefSpMv(alpha, a_clone, beta, acc_clone);
            //double err = 0;
            //for (int i = 0; i < this.RowPart.LocalLength; i++) {
            //    err += Math.Abs(acc_clone[i] - _acc.Storage[i]);
            //}
            //Console.WriteLine("err = " + err);
            //Console.WriteLine();
            //// test code end;
        }