Example #1
0
        public bool StartProc()
        {
            if (tmp == null)
            {
                return(false);
            }
            uint MemRequested, MemLockRequested;

            t = new Thread(new ThreadStart(tmp.ForeWork));
            t.Start();
            t.Join();
            if (!tmp.ForeWorkResult)
            {
                return(false);
            }
            MemRequested     = tmp.MemRequested();
            MemLockRequested = tmp.MemLockRequested();

            MemMan.Compact();
            MemMan.MEMORYSTATUSEX MS;
            MS = MemMan.MemoryStatus();
            try
            {
                MemMan.curProc.MaxWorkingSet = (IntPtr)MS.TotalPhys;
                MemMan.curProc.MinWorkingSet = (IntPtr)(MemLockRequested + 0x800000);
            }
            catch (Exception e)
            {
                Console.WriteLine("\n>>>>>>> " + e.Message);
                Console.WriteLine(">>>>>>> Can't take the ownership on " + ((MemLockRequested + 0x800000) / (1024 * 1024)).ToString("####0.0") + "Mb RAM");
                Console.WriteLine(">>>>>>> Probably the progamm is running not under an administrative account,\n>>>>>>> or too many other applications are running");
                Console.WriteLine(">>>>>>> or too many other applications are running.");
                Console.WriteLine(">>>>>>> Calculations will continue, but may slow down.");
            }


            if (!MM.Allocate(MemRequested))
            {
                Console.WriteLine(ExI + " ----> virtual allocation failed for " + MemRequested.ToString() + " bytes");
                return(false);
            }

            // optionally lock the memory
            if (!MM.Lock(0, MemLockRequested))
            {
                Console.WriteLine(">>>>>>> Unable to lock the memory.");
                Console.WriteLine(">>>>>>> Calculations will continue, but will slow down.");
            }
            unsafe
            {
                tmp.data = (double *)MM.BaseAddress;
            }
            t = new Thread(new ThreadStart(tmp.StartCalculations));
            t.Start();
            t.Join();
            MM.Free();
            return(true);
        }
Example #2
0
        public bool StartProc()
        {
            if (tmp == null)
            {
                return(false);
            }
            uint MemRequested, MemSupplied;

            unsafe  { MemRequested = tmp.M * tmp.N * (uint)2 * sizeof(double); }

            if (!MM.Allocate(MemRequested))
            {
                Console.WriteLine(ExI + " ----> virtual allocation failed for " + MemRequested.ToString() + " bytes");
                return(false);
                // тут зацикливается на светофор, если память занята просто другими экзекуторами
                // if(MemAlloc>=MemRequest) ....
            }
            Console.WriteLine(ExI + " ----> allocated " + MemRequested + " bytes, total " + MemMan.MemAlloc);

            if ((MemSupplied = MM.LockAtLeast(0, MinWorkingMem, MemRequested)) >= MemRequested)
            {               // установить параметры памяти в tmp
                Console.WriteLine(ExI + " ----> locked " + MemSupplied + " bytes, total " + MemMan.MemLock);
                unsafe
                {
                    tmp.sli = (double *)MM.LockAddress;
                }
                t = new Thread(new ThreadStart(tmp.StartCalculations));
                t.Start();
                t.Join();
                tmp.FlushOld();
                MM.Free();
                return(true);
            }
            Console.WriteLine(ExI + " ----> failed to lock at least 16M out of " + MemRequested + " bytes");
            //здесь семафор, если память просто заблокирована другими экзекуторами
            // if(MemLock>=MinWorkingMem) ....
            return(false);
        }