Пример #1
0
        public int GetNumberOfAvailableIs(ScalarPlan plan)
        {
            int counter = 0;

            if (plan.CalculateI1)
            {
                counter++;
            }
            if (plan.CalculateI2)
            {
                counter++;
            }
            if (plan.CalculateI3)
            {
                counter++;
            }
            if (plan.CalculateI4)
            {
                counter++;
            }
            if (plan.CalculateI5)
            {
                counter++;
            }

            return(counter);
        }
        private ScalarSegments CalculateParallelScalars(ScalarPlan plan, Transceiver[] transceivers)
        {
            var pm = new ParallelManager <Transceiver>(Mpi).WithTasks(transceivers);

            GreenScalars   gs            = null;
            ScalarSegments localSegments = null;

            pm.Run(tasks =>
            {
                using (Profiler?.StartAuto(ProfilerEvent.GreenScalarAtoACalc))
                {
                    gs = _scalarCalc.Calculate(plan, tasks, Profiler);
                }

                using (Profiler?.StartAuto(ProfilerEvent.GreenScalarAtoASegments))
                {
                    localSegments = ScalarSegments.AllocateAndConvert(MemoryProvider, plan, gs);
                }
            });

            using (Profiler?.StartAuto(ProfilerEvent.GreenScalarAtoACommunicate))
            {
                var allSegments1 = ScalarSegments.AllocateScalarSegments(MemoryProvider, plan, gs, transceivers.Length);
                var allSegments2 = ScalarSegments.AllocateScalarSegments(MemoryProvider, plan, gs, transceivers.Length);

                DistributeSegments(plan, pm, gs, localSegments, allSegments1, allSegments2);
                localSegments.Dispose();

                allSegments1.Dispose();
                return(allSegments2);
            }
        }
 private ScalarSegments CalculateScalars(ScalarPlan plan, Transceiver[] transceivers)
 {
     using (Profiler?.StartAuto(ProfilerEvent.GreenScalarAtoA))
     {
         if (Solver.IsParallel)
         {
             return(CalculateParallelScalars(plan, transceivers));
         }
         else
         {
             return(CalculateLocalScalars(plan, transceivers));
         }
     }
 }
        private ScalarSegments CalculateLocalScalars(ScalarPlan plan, Transceiver[] transceivers)
        {
            GreenScalars gs;

            using (Profiler?.StartAuto(ProfilerEvent.GreenScalarAtoACalc))
            {
                gs = _scalarCalc.Calculate(plan, transceivers, Profiler);
            }

            using (Profiler?.StartAuto(ProfilerEvent.GreenScalarAtoASegments))
            {
                var segments = ScalarSegments.AllocateAndConvert(MemoryProvider, plan, gs);
                return(segments);
            }
        }
        public AtoAGreenTensorCalculatorComponent(ForwardSolver solver) : base(solver)
        {
            if (Solver.Engine == ForwardSolverEngine.Giem2g)
            {
                if (!Solver.IsParallel)
                {
                    throw new NotImplementedException("GIEM2G works only in parallel mode!");
                }
                _plan            = null;
                _scalarCalc      = null;
                _tensorCalc      = null;
                _mirroringX      = false;
                _realCalcNxStart = -1;
                _totalNxLength   = -1;
                _calcNxLength    = -1;
                return;
            }

            _plan = new ScalarPlansCreater(Model.LateralDimensions, HankelCoefficients.LoadN40(), Solver.Settings.NumberOfHankels)
                    .CreateForAnomalyToAnomaly();

            _scalarCalc = GreenScalarCalculator.NewAtoACalculator(Logger, Model);
            _tensorCalc = new AtoAGreenTensorCalculator(Logger, Model, MemoryProvider);

            if (Solver.IsParallel)
            {
                var localNxStart = Mpi.CalcLocalNxStart(Model.LateralDimensions);
                _totalNxLength = Mpi.CalcLocalNxLength(Model.LateralDimensions);

                _mirroringX      = localNxStart >= Model.Nx;
                _realCalcNxStart = _mirroringX ? 2 * Model.Nx - localNxStart - _totalNxLength + 1 : localNxStart;

                _calcNxLength = _totalNxLength;
                if (_realCalcNxStart + _totalNxLength == Model.Nx + 1)
                {
                    _calcNxLength--;
                }
            }
            else
            {
                _mirroringX      = false;
                _realCalcNxStart = 0;
                _totalNxLength   = 2 * Model.Nx;
                _calcNxLength    = Model.Nx;
            }
        }
Пример #6
0
        public static InnerResultsCombiner CreateFromSample(ScalarPlan plan, InnerResult[] sample)
        {
            var sorted = new SortedList <double, AuxIndecies>();

            for (int i = 0; i < sample.Length; i++)
            {
                var rho = sample[i].Rho;

                for (int j = 0; j < rho.Length; j++)
                {
                    if (!sorted.ContainsKey(rho[j]))
                    {
                        sorted.Add(rho[j], new AuxIndecies(i, j));
                    }
                }
            }

            return(new InnerResultsCombiner(plan, sorted));
        }
Пример #7
0
 private InnerResultsCombiner(ScalarPlan plan, SortedList <double, AuxIndecies> sortedIndecies)
 {
     _plan           = plan;
     _sortedIndecies = sortedIndecies;
 }
        private void DistributeSegments(ScalarPlan plan, ParallelManager <Transceiver> pm, GreenScalars gs, ScalarSegments local, ScalarSegments all, ScalarSegments result)
        {
            var starts     = pm.GetAllStartIndecies();
            var lengths    = pm.GetAllLength();
            var fullStarts = new int[lengths.Length];
            var fullLength = new int[lengths.Length];

            var localLength = gs.SingleScalars.Length;

            int nComp = gs.GetNumberOfAvailableIs(plan);
            int nRho  = local.Radii.Length - 1;

            var localSize = localLength * nComp * 2 * nRho;

            for (int i = 0; i < starts.Length; i++)
            {
                fullStarts[i] = starts[i] * nComp * 2 * nRho;
                fullLength[i] = lengths[i] * nComp * 2 * nRho;
            }

            Mpi.AllGatherV(local.Ptr, localSize, all.Ptr, fullLength, fullStarts);

            using (Profiler?.StartAuto(ProfilerEvent.GreenScalarAtoATrans))
            {
                for (int i = 0; i < starts.Length; i++)
                {
                    int start  = starts[i];
                    int length = lengths[i];

                    var tmp = ScalarSegments.ReUseScalarSegments(all.Ptr + fullStarts[i], plan, gs, length);

                    for (int j = 0; j < result.SingleSegment.Length; j++)
                    {
                        var src = tmp.SingleSegment[j];
                        var dst = result.SingleSegment[j];

                        if (src.I1A != null)
                        {
                            for (int k = 0; k < length; k++)
                            {
                                dst.I1A[k + start] = src.I1A[k];
                            }
                        }
                        if (src.I2A != null)
                        {
                            for (int k = 0; k < length; k++)
                            {
                                dst.I2A[k + start] = src.I2A[k];
                            }
                        }
                        if (src.I3A != null)
                        {
                            for (int k = 0; k < length; k++)
                            {
                                dst.I3A[k + start] = src.I3A[k];
                            }
                        }
                        if (src.I4A != null)
                        {
                            for (int k = 0; k < length; k++)
                            {
                                dst.I4A[k + start] = src.I4A[k];
                            }
                        }
                        if (src.I5A != null)
                        {
                            for (int k = 0; k < length; k++)
                            {
                                dst.I5A[k + start] = src.I5A[k];
                            }
                        }

                        if (src.I1B != null)
                        {
                            for (int k = 0; k < length; k++)
                            {
                                dst.I1B[k + start] = src.I1B[k];
                            }
                        }
                        if (src.I2B != null)
                        {
                            for (int k = 0; k < length; k++)
                            {
                                dst.I2B[k + start] = src.I2B[k];
                            }
                        }
                        if (src.I3B != null)
                        {
                            for (int k = 0; k < length; k++)
                            {
                                dst.I3B[k + start] = src.I3B[k];
                            }
                        }
                        if (src.I4B != null)
                        {
                            for (int k = 0; k < length; k++)
                            {
                                dst.I4B[k + start] = src.I4B[k];
                            }
                        }
                        if (src.I5B != null)
                        {
                            for (int k = 0; k < length; k++)
                            {
                                dst.I5B[k + start] = src.I5B[k];
                            }
                        }
                    }
                }
            }
        }