예제 #1
0
        /// <summary>
        /// Computes the permutation for the given <paramref name="RowMap"/>
        /// </summary>
        /// <param name="RowMap"></param>
        /// <param name="grd"></param>
        /// <returns></returns>
        public static int[] ComputePermutation(UnsetteledCoordinateMapping RowMap, GridData grd)
        {
            int J = grd.Grid.NoOfUpdateCells;

            int[] N         = RowMap.BasisS.Select(x => x.MaximalLength).ToArray();
            int   NT        = N.Sum();
            int   Gamma     = RowMap.BasisS.Count;
            var   GlobalIDs = grd.CurrentGlobalIdPermutation.Values;

            int[] PermutationTable;
            PermutationTable = new int[RowMap.LocalLength];
            Debug.Assert(PermutationTable.Length == J * NT);
            for (int j = 0; j < J; j++)
            {
                int gid    = (int)GlobalIDs[j];
                int iTarg0 = gid * NT;

                int i0 = (int)RowMap.LocalUniqueCoordinateIndex(0, j, 0);
                for (int f = 0; f < Gamma; f++)
                {
                    for (int n = 0; n < N[f]; n++)
                    {
                        int i     = (int)RowMap.LocalUniqueCoordinateIndex(f, j, n);
                        int iTarg = iTarg0 + (i - i0);
                        PermutationTable[i] = iTarg;
                    }
                }
            }


            int[] globalPermutationTable = new int[grd.Grid.NumberOfCells * NT];
            unsafe {
                int[] displ  = RowMap.GetI0s().Select(x => (int)x).ToArray();
                int[] rcvCnt = new int[RowMap.MpiSize];
                for (int i = 0; i < RowMap.MpiSize; i++)
                    rcvCnt[i] = displ[i + 1] - displ[i];

                fixed(int *pSnd = PermutationTable, pRcv = globalPermutationTable, pDispl = displ, pRcvCnt = rcvCnt)
                {
                    csMPI.Raw.Allgatherv((IntPtr)pSnd, PermutationTable.Length, csMPI.Raw._DATATYPE.INT,
                                         (IntPtr)pRcv, (IntPtr)pRcvCnt, (IntPtr)pDispl, csMPI.Raw._DATATYPE.INT,
                                         csMPI.Raw._COMM.WORLD);
                }
            }

            return(globalPermutationTable);
        }