Exemplo n.º 1
0
        public FlexibleGmresWithGmresPreconditioner(
            ILogger logger,
            INativeMemoryProvider memoryProvider,
            GmresParams fgmresParams,
            int innerBufferLength)
        {
            var innerParams = new GmresParams(fgmresParams.LocalDimensionSize, innerBufferLength)
            {
                Tolerance             = fgmresParams.Tolerance,
                MaxRepeatNumber       = 1,
                ResidualAtRestart     = fgmresParams.ResidualAtRestart,
                GramSchmidtType       = fgmresParams.GramSchmidtType,
                InitialGuess          = InitialGuess.UserSupplied,
                Preconditioning       = Preconditioning.None,
                BackwardErrorChecking = BackwardErrorChecking.CheckArnoldiOnly
            };

            _classicGmres  = new ClassicGmresSolver(logger, memoryProvider, innerParams);
            _flexibleGmres = new FlexibleGmresSolver(logger, memoryProvider, fgmresParams);

            _classicGmres.DotProductRequest        += (s, a) => OnDotProductRequest(a);
            _flexibleGmres.DotProductRequest       += (s, a) => OnDotProductRequest(a);
            _classicGmres.MatrixVectorMultRequest  += (s, a) => OnMatrixVectorMultRequest(a);
            _flexibleGmres.MatrixVectorMultRequest += (s, a) => OnMatrixVectorMultRequest(a);

            _classicGmres.IterationComplete  += (s, a) => OnInnerIterationComplete(a);
            _flexibleGmres.IterationComplete += (s, a) => OnIterationComplete(a);

            _flexibleGmres.RightPreconditionerRequest += (s, a) => _classicGmres.Solve(a.Src, a.Src, a.Dst);
        }
Exemplo n.º 2
0
        protected GmresSolver(ILogger logger, INativeMemoryProvider memoryProvider, GmresParams parameters)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (memoryProvider == null)
            {
                throw new ArgumentNullException(nameof(memoryProvider));
            }

            Logger     = logger;
            Parameters = parameters;
            _nloc      = Parameters.LocalDimensionSize;
            _m         = Parameters.BufferSize;

            _dotProducts = Parameters.GramSchmidtType == GramSchmidtType.IterativeClassical ?
                           new NativeVector(memoryProvider, _m) :
                           new NativeVector(memoryProvider, 1);

            var krylovSize = Parameters.ResidualAtRestart == ResidualAtRestart.ComputeTheTrue ? _m : _m + 1;

            _krylovBasis = new FortranMatrix(memoryProvider, _nloc, krylovSize);
            _hessenberg  = new FortranMatrix(memoryProvider, _m + 1, _m + 1);

            _w        = new NativeVector(memoryProvider, _nloc);
            _r0       = new NativeVector(memoryProvider, _nloc);
            _xCurrent = new NativeVector(memoryProvider, _nloc);
            _yCurrent = new NativeVector(memoryProvider, _m);

            _givensRotSin = new Complex[_m];
            _givensRotCos = new double[_m];
        }
Exemplo n.º 3
0
        public static ScalarSegments AllocateAndConvert(INativeMemoryProvider memoryProvider, ScalarPlan plan, GreenScalars scalars)
        {
            var segments = AllocateScalarSegments(memoryProvider, plan, scalars);

            ConvertScalarsToSegments(scalars, segments);
            return(segments);
        }
Exemplo n.º 4
0
        private static List <IntPtr> AllocateGiem2gDataBuffers(INativeMemoryProvider memoryProvider, ref giem2g_data giem2g_ie_op, int nz)
        {
            var giem2g_ptrs = new List <IntPtr> ();

//			var tmp1=(memoryProvider.AllocateBytes(giem2g_ie_op.tensor_size));
//			giem2g_ie_op.giem2g_tensor=tmp1;
            var tmp1 = giem2g_ie_op.giem2g_tensor;

            giem2g_ptrs.Add(tmp1);

            var tmp2 = (memoryProvider.AllocateComplex(giem2g_ie_op.ie_kernel_buffer_length));

            giem2g_ptrs.Add(new IntPtr(tmp2));
            giem2g_ie_op.kernel_buffer = tmp2;

            var dz = (memoryProvider.AllocateDouble(nz));

            giem2g_ie_op.dz = dz;
            giem2g_ptrs.Add(new IntPtr(dz));

            var sqsigb = (memoryProvider.AllocateDouble(nz));

            giem2g_ie_op.sqsigb = sqsigb;
            giem2g_ptrs.Add(new IntPtr(sqsigb));

            var csigb = (memoryProvider.AllocateComplex(nz));

            giem2g_ie_op.csigb = csigb;
            giem2g_ptrs.Add(new IntPtr(csigb));
            return(giem2g_ptrs);
        }
Exemplo n.º 5
0
 public AtoAGreenTensorCalculator(
     ILogger logger,
     OmegaModel model,
     INativeMemoryProvider memoryProvider) :
     base(logger, model, memoryProvider)
 {
 }
Exemplo n.º 6
0
 private ScalarSegments(INativeMemoryProvider memoryProvider, Complex *ptr, double[] radii, SingleScalarSegment[] segment)
 {
     _memoryProvider = memoryProvider;
     Ptr             = ptr;
     Radii           = radii;
     SingleSegment   = segment;
 }
Exemplo n.º 7
0
 public FortranMatrix(INativeMemoryProvider memoryProvider, int nx, int ny)
 {
     _ptr            = memoryProvider.AllocateComplex(((long)nx) * ny);
     Nx              = nx;
     Ny              = ny;
     _memoryProvider = memoryProvider;
 }
Exemplo n.º 8
0
        public static void PrintMemoryReport(string message, ILogger logger, INativeMemoryProvider memoryProvider)
        {
            var linux   = LinuxMemoryFileReader.GetTotalMemoryInMiB();
            var native  = (memoryProvider as MemoryProvider).GetAllocatedMemorySizeInBytes() / (1024 * 1024M);
            var managed = GC.GetTotalMemory(false) / (1024 * 1024M);

            //   logger.WriteStatus($"[{message.PadRight(15)}]: linux:{linux:0.000}, native:{native:0.000}, managed:{managed:0.000}, n+m:{native + managed:0.000}");
        }
Exemplo n.º 9
0
        public FftBuffer(INativeMemoryProvider memoryProvider, IProfiler profiler = null)
        {
            if (memoryProvider == null)
            {
                throw new ArgumentNullException(nameof(memoryProvider));
            }

            _memoryProvider = memoryProvider;
            _profiler       = profiler;
        }
Exemplo n.º 10
0
        public static GreenTensor CreateGiem2gTensor(INativeMemoryProvider memoryProvider, int nx, int ny, int nTr, int nRc, List <IntPtr> giem2g_ptrs)
        {
            var gt   = new GreenTensor(memoryProvider, nx, ny, nTr, nRc);
            var dict = new Dictionary <string, Component>();

            dict.Add("giem2g", new Component(gt, (Complex *)giem2g_ptrs[0]));
            gt._components = dict;
            gt._basePtrs.AddRange(giem2g_ptrs);
            return(gt);
        }
Exemplo n.º 11
0
        private GreenTensor(INativeMemoryProvider memoryProvider, int nx, int ny, int nTr, int nRc)
        {
            if (memoryProvider == null)
            {
                throw new ArgumentNullException(nameof(memoryProvider));
            }

            _memoryProvider = memoryProvider;
            Nx  = nx;
            Ny  = ny;
            NTr = nTr;
            NRc = nRc;
        }
Exemplo n.º 12
0
        public static void ExportMemoryUsage(string resultPath, Mpi mpi, INativeMemoryProvider memoryProvider, double frequency)
        {
            Complex localNativeMemory = (memoryProvider as MemoryProvider)?.GetAllocatedMemorySizeInBytes() / (1024 * 1024.0) ?? 0;
            var     nativeMemory      = new Complex[mpi?.Size ?? 1];

            Complex localManagedMemory = GC.GetTotalMemory(false) / (1024 * 1024.0);
            var     managedMemory      = new Complex[mpi?.Size ?? 1];

            Complex localLinuxMemory = (double)LinuxMemoryFileReader.GetTotalMemoryInMiB();
            var     linuxMemory      = new Complex[mpi?.Size ?? 1];

            mpi?.Gather(nativeMemory, localNativeMemory);
            mpi?.Gather(managedMemory, localManagedMemory);
            mpi?.Gather(linuxMemory, localLinuxMemory);

            if (mpi?.IsMaster ?? true)
            {
                string path = Path.Combine(resultPath, $"mem_info_mpi{mpi?.Size:0000}_freq{frequency}.dat");

                Func <Complex, string> pr = v => $"{v.Real / 1024:######0.0000} GiB".PadLeft(16);

                using (var sw = new StreamWriter(path))
                {
                    sw.WriteLine($"MPI_proc\t\tNATIVE\t\tMANAGED\t\tSUMM\t\tLINUX");

                    sw.Write($"Total".PadRight(16));
                    sw.Write(pr(nativeMemory.Sum(c => c.Real)));
                    sw.Write(pr(managedMemory.Sum(c => c.Real)));
                    sw.Write(pr(nativeMemory.Sum(c => c.Real) + managedMemory.Sum(c => c.Real)));
                    sw.Write(pr(linuxMemory.Sum(c => c.Real)));
                    sw.WriteLine();


                    for (int i = 0; i < nativeMemory.Length; i++)
                    {
                        sw.Write($"{i}".PadRight(16));
                        sw.Write(pr(nativeMemory[i]));
                        sw.Write(pr(managedMemory[i]));
                        sw.Write(pr(nativeMemory[i] + managedMemory[i]));
                        sw.Write(pr(linuxMemory[i]));
                        sw.WriteLine();
                    }
                }
            }
        }
Exemplo n.º 13
0
        protected ForwardSolver(ILogger logger, INativeMemoryProvider memoryProvider, ForwardSettings settings, bool store = false)
            : base(logger, memoryProvider)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            Settings  = settings;
            StoreAtoA = store;
            if (Settings.NumberOfHankels <= 0)
            {
                Engine = ForwardSolverEngine.Giem2g;

                SetGiem2gLogger();

                StoreAtoA = true;
            }
        }
Exemplo n.º 14
0
        public static ScalarSegments AllocateScalarSegments(INativeMemoryProvider memoryProvider, ScalarPlan plan, GreenScalars scalars, int length)
        {
            var radii    = scalars.Radii;
            int nRho     = radii.Length - 1;
            var segments = new SingleScalarSegment[nRho];

            int nComp = scalars.GetNumberOfAvailableIs(plan);
            var ptr   = memoryProvider.AllocateComplex(length * nComp * 2L * nRho);

            long oneSegmentSize = length * nComp * 2L;

            for (int i = 0; i < segments.Length; i++)
            {
                var startPtr = ptr + oneSegmentSize * i;
                segments[i] = new SingleScalarSegment(plan, startPtr, length, nComp);
            }

            return(new ScalarSegments(memoryProvider, ptr, radii, segments));
        }
Exemplo n.º 15
0
        public ExtremeMtSolverRunner(ForwardProject project, INativeMemoryProvider memoryProvider, Mpi mpi = null)
        {
            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }
            if (memoryProvider == null)
            {
                throw new ArgumentNullException(nameof(memoryProvider));
            }

            _project        = project;
            _memoryProvider = memoryProvider;
            _mpi            = mpi;
            _logger         = (_mpi == null || !_mpi.IsParallel) ?
                              (ILogger) new ConsoleLogger() :
                              new ParallelConsoleLogger(_mpi);

            _solver = new Mt3DForwardSolver(_logger, memoryProvider, _project.ForwardSettings);
            _solver.SetProfiler(_profiler);
        }
Exemplo n.º 16
0
        protected GreenTensorCalculator(
            ILogger logger,
            OmegaModel model,
            INativeMemoryProvider memoryProvider)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (memoryProvider == null)
            {
                throw new ArgumentNullException(nameof(memoryProvider));
            }
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            Logger         = logger;
            MemoryProvider = memoryProvider;
            Model          = model;
        }
Exemplo n.º 17
0
        private static void PrepareBuffersForModel(ModelSize ms, INativeMemoryProvider memoryProvider, Mpi mpi, IProfiler profiler)
        {
            if (Buffers.ContainsKey(ms))
            {
                throw new InvalidOperationException("Buffer for such model size is already created");
            }

            using (profiler?.StartAuto(ProfilerEvent.FftwPlanCalculation))
            {
                var buffer = new FftBuffer(memoryProvider, profiler);

                if (IsParallel(mpi))
                {
                    buffer.AllocateBuffersAndCreatePlansParallel(ms.Nx, ms.Ny, ms.Nz, mpi);
                }
                else
                {
                    buffer.AllocateBuffersAndCreatePlansLocal(ms.Nx, ms.Ny, ms.Nz);
                }

                Buffers.Add(ms, buffer);
            }
        }
Exemplo n.º 18
0
        public static GreenTensor AllocateNew(INativeMemoryProvider memoryProvider,
                                              int nx, int ny, int nTr, int nRc, long compSize, params string[] components)
        {
            var gt       = new GreenTensor(memoryProvider, nx, ny, nTr, nRc);
            var fullSize = compSize * components.Length;

            var ptr = memoryProvider.AllocateComplex(fullSize);

            UNM.ClearBuffer(ptr, fullSize);


            var dict = new Dictionary <string, Component>();

            for (int i = 0; i < components.Length; i++)
            {
                var nextPtr = ptr + i * compSize;
                dict.Add(components[i], new Component(gt, nextPtr));
            }

            gt._basePtrs.Add(new IntPtr(ptr));
            gt._components = dict;

            return(gt);
        }
Exemplo n.º 19
0
 public FlexibleGmresSolver(ILogger logger, INativeMemoryProvider memoryProvider, GmresParams parameters) :
     base(logger, memoryProvider, parameters)
 {
     _precondKrylovBasis = new FortranMatrix(memoryProvider, Parameters.LocalDimensionSize, Parameters.BufferSize);
 }
Exemplo n.º 20
0
        public static unsafe double *AllocateDouble(this INativeMemoryProvider memoryProvider, long numberOfElements)
        {
            var ptr = (double *)memoryProvider.AllocateBytes(numberOfElements * sizeof(double)).ToPointer();

            return(ptr);
        }
Exemplo n.º 21
0
 public static unsafe void Release(this INativeMemoryProvider memoryProvider, void *data)
 {
     memoryProvider.ReleaseMemory(new IntPtr(data));
 }
Exemplo n.º 22
0
 public NativeVector(INativeMemoryProvider memoryProvider, int length)
 {
     _memoryProvider = memoryProvider;
     _ptr            = memoryProvider.AllocateComplex(length);
     Length          = length;
 }
Exemplo n.º 23
0
        public static unsafe Complex *AllocateComplex(this INativeMemoryProvider memoryProvider, long numberOfElements)
        {
            var ptr = (Complex *)memoryProvider.AllocateComplexIntPtr(numberOfElements).ToPointer();

            return(ptr);
        }
Exemplo n.º 24
0
 protected ForwardSolverGenerics(ILogger logger, INativeMemoryProvider memoryProvider)
 {
     MemoryProvider = memoryProvider;
     Logger         = logger;
 }
Exemplo n.º 25
0
 private static ScalarSegments AllocateScalarSegments(INativeMemoryProvider memoryProvider, ScalarPlan plan, GreenScalars scalars)
 => AllocateScalarSegments(memoryProvider, plan, scalars, scalars.SingleScalars.Length);
Exemplo n.º 26
0
        public static void PrepareBuffersForModel(CartesianModel model, INativeMemoryProvider memoryProvider, Mpi mpi = null, IProfiler profiler = null)
        {
            var modelSize = new ModelSize(model.Nx, model.Ny, model.Nz);

            PrepareBuffersForModel(modelSize, memoryProvider, mpi, profiler);
        }
Exemplo n.º 27
0
 public Mt3DForwardSolver(ILogger logger, INativeMemoryProvider memoryProvider, ForwardSettings settings, bool store = false)
     : base(logger, memoryProvider, settings, store)
 {
     _eFields = new List <MtFieldsAtLevelCalculatedEventArgs>();
     _hFields = new List <MtFieldsAtLevelCalculatedEventArgs>();
 }
Exemplo n.º 28
0
 public ClassicGmresSolver(ILogger logger, INativeMemoryProvider memoryProvider, GmresParams parameters) :
     base(logger, memoryProvider, parameters)
 {
 }
Exemplo n.º 29
0
        private static unsafe IntPtr AllocateComplexIntPtr(this INativeMemoryProvider memoryProvider, long numberOfElements)
        {
            var ptr = memoryProvider.AllocateBytes(numberOfElements * sizeof(Complex));

            return(ptr);
        }