/// <summary> /// Calculates number of threads to use. /// If count is not Automatic, simply returns count casted to an int. /// Returns: An int specifying how many threads to use, 0 means a coroutine should be used for pathfinding instead of a separate thread. /// /// If count is set to Automatic it will return a value based on the number of processors and memory for the current system. /// If memory is <= 512MB or logical cores are <= 1, it will return 0. If memory is <= 1024 it will clamp threads to max 2. /// Otherwise it will return the number of logical cores clamped to 6. /// /// When running on WebGL this method always returns 0 /// </summary> public static int CalculateThreadCount(ThreadCount count) { #if UNITY_WEBGL return(0); #else if (count == ThreadCount.AutomaticLowLoad || count == ThreadCount.AutomaticHighLoad) { int logicalCores = Mathf.Max(1, SystemInfo.processorCount); int memory = SystemInfo.systemMemorySize; if (memory <= 0) { Debug.LogError("Machine reporting that is has <= 0 bytes of RAM. This is definitely not true, assuming 1 GiB"); memory = 1024; } if (logicalCores <= 1) { return(0); } if (memory <= 512) { return(0); } return(1); } else { return((int)count > 0 ? 1 : 0); } #endif }
public IConfiguration ToIConfiguration() { var config = new MutableConfiguration("rhino.esb"); var busConfig = config.CreateChild("bus") .Attribute("endpoint", Endpoint) .Attribute("threadCount", ThreadCount.ToString()) .Attribute("numberOfRetries", NumberOfRetries.ToString()); if (string.IsNullOrEmpty(Name) == false) { busConfig.Attribute("name", Name); } if (string.IsNullOrEmpty(LoadBalancerEndpoint) == false) { busConfig.Attribute("loadBalancerEndpoint", LoadBalancerEndpoint); } if (string.IsNullOrEmpty(LogEndpoint) == false) { busConfig.Attribute("logEndpoint", LogEndpoint); } var messagesConfig = config.CreateChild("messages"); foreach (var message in Messages) { messagesConfig.CreateChild("add") .Attribute("name", message.Key) .Attribute("endpoint", message.Value); } return(config); }
protected virtual void ResetParameters() { m_threadCount = ThreadCount.T32; size = outOffset = inOffset = 0; segments = 1; segmented = false; }
public MyParallelKernel(MyNode owner, int nGPU, ParallelKernelDescriptor descriptor, int bufferSize) { m_owner = owner; m_nGPU = nGPU; m_threadCount = ThreadCount.T32; m_outTypeSize = descriptor.outTypeSize; m_inTypeSize = descriptor.inTypeSize; m_TSize = Marshal.SizeOf(typeof(T)); if (m_TSize > m_inTypeSize || m_TSize > m_outTypeSize || m_inTypeSize % m_TSize != 0 || m_outTypeSize % m_TSize != 0 || m_inTypeSize == 0 || m_outTypeSize == 0) { MyLog.Writer.WriteLine(MyLogLevel.WARNING, "MyReduction.cs: MemoryBlock type can be incompatible with reduction in/out types."); } Array threadCountValues = Enum.GetValues(typeof(ThreadCount)); m_kernels = new Dictionary <ThreadCount, MyCudaKernel>(); foreach (ThreadCount threadCount in Enum.GetValues(typeof(ThreadCount))) { string kernelName = descriptor.GetKernelName(threadCount); m_kernels.Add(threadCount, MyKernelFactory.Instance.Kernel(owner.GPU, @"Common\Reduction\Reduction", kernelName)); } m_buffer = MyMemoryManager.Instance.CreateMemoryBlock <float>(owner); m_buffer.Name = "Buffer(" + descriptor.modeName + ")"; m_buffer.Count = bufferSize; m_blockDims = new dim3((int)m_threadCount, 1, 1); m_gridDims = new dim3(1, 1, 1); }
public override string ToString() { return(ProcessName + "|" + PID.ToString() + "|" + UserName + "|" + CPUTime + "|" + NumBytes.ToString() + "|" + HandleCount.ToString() + "|" + ThreadCount.ToString() + "|" + CommandLineArgs); }
/// <summary>Initializes the <see cref="pathProcessor"/> field</summary> void InitializePathProcessor() { int numThreads = CalculateThreadCount(threadCount); // Outside of play mode everything is synchronous, so no threads are used. if (!Application.isPlaying) { numThreads = 0; } // Trying to prevent simple modding to add support for more than one thread if (numThreads > 1) { threadCount = ThreadCount.One; numThreads = 1; } int numProcessors = Mathf.Max(numThreads, 1); bool multithreaded = numThreads > 0; pathProcessor = new PathProcessor(this, pathReturnQueue, numProcessors, multithreaded); pathProcessor.OnPathPreSearch += path => { var tmp = OnPathPreSearch; if (tmp != null) { tmp(path); } }; pathProcessor.OnPathPostSearch += path => { LogPathResults(path); var tmp = OnPathPostSearch; if (tmp != null) { tmp(path); } }; // Sent every time the path queue is unblocked pathProcessor.OnQueueUnblocked += () => { if (euclideanEmbedding.dirty) { euclideanEmbedding.RecalculateCosts(); } }; if (multithreaded) { graphUpdates.EnableMultithreading(); } }
public TreeFactory(Dictionary <int, Point> coordinates) { this.visitors = new List <IVisitor>(); this.coordinates = coordinates; var space = new Space(coordinates); this.sumCalculator = new SumOfSquareCalculator(space); this.prune = new Prune(space.PointMapping.Count); this.nodeProcessor = new NodeProcessor(coordinates.Keys, sumCalculator); this.threadCount = new ThreadCount(); this.searchCollection = new DfsSearch <NodeModel>(); }
public string[] ToStringArray() { return(new string[] { ProcessShortName, PID.ToString(), UserName, CPUTime, new FileSystemHelper(null).BytesToReadableValue(NumBytes), HandleCount.ToString(), ThreadCount.ToString(), ProcessName + " " + CommandLineArgs }); }
public async Task ThreadCountTest() { var widget = new ThreadCount(); var request = MetricQueryRequest.Create(widget); var handler = new ThreadCountQuery(); await handler.Handle(request, CancellationToken.None).ConfigureAwait(false); Assert.AreEqual(State.Ok, widget.State); Assert.IsTrue(widget.Value > 0); }
public static int CalculateThreadCount(ThreadCount count) { if (count != ThreadCount.AutomaticLowLoad && count != ThreadCount.AutomaticHighLoad) { return((int)count); } int num = Mathf.Max(1, SystemInfo.processorCount); int num2 = SystemInfo.systemMemorySize; if (num2 <= 0) { UnityEngine.Debug.LogError("Machine reporting that is has <= 0 bytes of RAM. This is definitely not true, assuming 1 GiB"); num2 = 1024; } if (num <= 1) { return(0); } if (num2 <= 512) { return(0); } if (count == ThreadCount.AutomaticHighLoad) { if (num2 <= 1024) { num = Math.Min(num, 2); } } else { num /= 2; num = Mathf.Max(1, num); if (num2 <= 1024) { num = Math.Min(num, 2); } num = Math.Min(num, 6); } return(num); }
protected virtual void PopulateBusConfiguration(MutableConfiguration busConfig) { busConfig .Attribute("endpoint", Endpoint) .Attribute("threadCount", ThreadCount.ToString()) .Attribute("numberOfRetries", NumberOfRetries.ToString()); if (string.IsNullOrEmpty(Name) == false) { busConfig.Attribute("name", Name); } if (string.IsNullOrEmpty(LoadBalancerEndpoint) == false) { busConfig.Attribute("loadBalancerEndpoint", LoadBalancerEndpoint); } if (string.IsNullOrEmpty(LogEndpoint) == false) { busConfig.Attribute("logEndpoint", LogEndpoint); } }
/** Calculates number of threads to use. * If \a count is not Automatic, simply returns \a count casted to an int. * \returns An int specifying how many threads to use, 0 means a coroutine should be used for pathfinding instead of a separate thread. * * If \a count is set to Automatic it will return a value based on the number of processors and memory for the current system. * If memory is <= 512MB or logical cores are <= 1, it will return 0. If memory is <= 1024 it will clamp threads to max 2. * Otherwise it will return the number of logical cores clamped to 6. */ public static int CalculateThreadCount (ThreadCount count) { if (count == ThreadCount.Automatic) { int logicalCores = SystemInfo.processorCount; int memory = SystemInfo.systemMemorySize; if (logicalCores <= 1) return 0; if (memory <= 512) return 0; if (memory <= 1024) logicalCores = System.Math.Min (logicalCores,2); logicalCores = System.Math.Min (logicalCores,6); return logicalCores; } else { int val = (int)count; return val; } }
public override void WriterAddAttribute(XmlWriter writer) { writer.WriteAttributeString("ThreadCount", ThreadCount.ToString()); base.WriterAddAttribute(writer); }
/** Sets up all needed variables and scans the graphs. * Calls Initialize, starts the ReturnPaths coroutine and scans all graphs. * Also starts threads if using multithreading * \see #OnAwakeSettings */ public void Awake () { //Very important to set this. Ensures the singleton pattern holds active = this; if (FindObjectsOfType (typeof(AstarPath)).Length > 1) { Debug.LogError ("You should NOT have more than one AstarPath component in the scene at any time.\n" + "This can cause serious errors since the AstarPath component builds around a singleton pattern."); } //Disable GUILayout to gain some performance, it is not used in the OnGUI call useGUILayout = false; isEditor = Application.isEditor; if (OnAwakeSettings != null) { OnAwakeSettings (); } //To make sure all graph modifiers have been enabled before scan (to avoid script run order issues) GraphModifier.FindAllModifiers (); RelevantGraphSurface.FindAllGraphSurfaces (); int numThreads = CalculateThreadCount (threadCount); // Trying to prevent simple modding to add support for more than one thread if ( numThreads > 1 ) { threadCount = ThreadCount.One; numThreads = 1; } threads = new Thread[numThreads]; //Thread info, will contain at least one item since the coroutine "thread" is thought of as a real thread in this case threadInfos = new PathThreadInfo[System.Math.Max(numThreads,1)]; //Set up path queue with the specified number of receivers pathQueue = new ThreadControlQueue(threadInfos.Length); for (int i=0;i<threadInfos.Length;i++) { threadInfos[i] = new PathThreadInfo(i,this,new PathHandler()); } for (int i=0;i<threads.Length;i++) { threads[i] = new Thread (new ParameterizedThreadStart (CalculatePathsThreaded)); threads[i].Name = "Pathfinding Thread " + i; threads[i].IsBackground = true; } //Start coroutine if not using multithreading if (numThreads == 0) { threadEnumerator = CalculatePaths (threadInfos[0]); } else { threadEnumerator = null; } //Start pathfinding threads for (int i=0;i<threads.Length;i++) { if (logPathResults == PathLog.Heavy) Debug.Log ("Starting pathfinding thread "+i); threads[i].Start (threadInfos[i]); } Thread graphUpdateThread = new Thread (new ParameterizedThreadStart(ProcessGraphUpdatesAsync)); graphUpdateThread.IsBackground = true; graphUpdateThread.Start (this); Initialize (); // Flush work items, possibly added in initialize to load graph data FlushWorkItems(); if (scanOnStartup) { if (!astarData.cacheStartup || astarData.data_cachedStartup == null) { Scan (); } } }
/** Calculates number of threads to use. * If \a count is not Automatic, simply returns \a count casted to an int. * \returns An int specifying how many threads to use, 0 means a coroutine should be used for pathfinding instead of a separate thread. * * If \a count is set to Automatic it will return a value based on the number of processors and memory for the current system. * If memory is <= 512MB or logical cores are <= 1, it will return 0. If memory is <= 1024 it will clamp threads to max 2. * Otherwise it will return the number of logical cores clamped to 6. */ public static int CalculateThreadCount (ThreadCount count) { if (count == ThreadCount.AutomaticLowLoad || count == ThreadCount.AutomaticHighLoad) { #if ASTARDEBUG Debug.Log (SystemInfo.systemMemorySize + " " + SystemInfo.processorCount + " " + SystemInfo.processorType); #endif int logicalCores = Mathf.Max (1,SystemInfo.processorCount); int memory = SystemInfo.systemMemorySize; if ( memory <= 0 ) { Debug.LogError ("Machine reporting that is has <= 0 bytes of RAM. This is definitely not true, assuming 1 GiB"); memory = 1024; } if (logicalCores <= 1) return 0; if (memory <= 512) return 0; if (count == ThreadCount.AutomaticHighLoad) { if (memory <= 1024) logicalCores = System.Math.Min (logicalCores,2); } else { //Always run at at most processorCount-1 threads (one core reserved for unity thread). // Many computers use hyperthreading, so dividing by two is used to remove the hyperthreading cores, pathfinding // doesn't scale well past the number of physical cores anyway logicalCores /= 2; logicalCores = Mathf.Max (1, logicalCores); if (memory <= 1024) logicalCores = System.Math.Min (logicalCores,2); logicalCores = System.Math.Min (logicalCores,6); } return logicalCores; } else { int val = (int)count; return val; } }
/** Calculates number of threads to use. * If \a count is not Automatic, simply returns \a count casted to an int. * \returns An int specifying how many threads to use, 0 means a coroutine should be used for pathfinding instead of a separate thread. * * If \a count is set to Automatic it will return a value based on the number of processors and memory for the current system. * If memory is <= 512MB or logical cores are <= 1, it will return 0. If memory is <= 1024 it will clamp threads to max 2. * Otherwise it will return the number of logical cores clamped to 6. */ public static int CalculateThreadCount (ThreadCount count) { int logicalCores = Mathf.Max (1,SystemInfo.processorCount); return logicalCores * 2; }
/** Calculates number of threads to use. * If \a count is not Automatic, simply returns \a count casted to an int. * \returns An int specifying how many threads to use, 0 means a coroutine should be used for pathfinding instead of a separate thread. * * If \a count is set to Automatic it will return a value based on the number of processors and memory for the current system. * If memory is <= 512MB or logical cores are <= 1, it will return 0. If memory is <= 1024 it will clamp threads to max 2. * Otherwise it will return the number of logical cores clamped to 6. */ public static int CalculateThreadCount (ThreadCount count) { if (count == ThreadCount.AutomaticLowLoad || count == ThreadCount.AutomaticHighLoad) { int logicalCores = Mathf.Max (1,SystemInfo.processorCount); int memory = SystemInfo.systemMemorySize; if ( memory <= 0 ) { Debug.LogError ("Machine reporting that is has <= 0 bytes of RAM. This is definitely not true, assuming 1 GiB"); memory = 1024; } if ( logicalCores <= 1) return 0; if ( memory <= 512) return 0; return 1; } else { return (int)count > 0 ? 1 : 0; } }
public string GetKernelName(ThreadCount threads) { return(nameFirstHalf + ((int)threads).ToString() + nameSecondHalf); }
/// <summary> /// 线程传递参数方法: /// 1.使用ParameterParameterizedThreadStart+t.start(Object para)传递1个object类型的参数 /// </summary> public static void TransParameter() { // 1.使用ParameterParameterizedThreadStart + t.start(Object para)传递1个object类型的参数 Thread t1 = new Thread(Tester01Base.ParaCounte); t1.Start(5); //2.定义线程环境类 ThreadCount tc = new ThreadCount(10); Thread t = new Thread(tc.Count); t.Start(); int len = 5; //3.使用lambda表达式:使用变量则是闭包:多个线程则是共享的这个变量;(尽量使用常量) Thread tlam = new Thread(() => { for (int i = 0; i < len; i++) { Thread.Sleep(300); Console.WriteLine("para by lambda1:" + i); } }); tlam.Start();//********线程启动过后,更改了len的值,线程1还是会依照修改后的变量: len = 10; // tlam.Start(); Thread tlam2 = new Thread(() => { for (int i = 0; i < len; i++) { Thread.Sleep(300); Console.WriteLine("para by lambda2:" + i); } }); tlam2.Start(); }
public string[] ForProcessAdvList() { return(new string[] { ProcessName, PID.ToString(), StartTime.ToShortTimeString(), TotalProcessorTime.Duration().Hours.ToString() + ":" + TotalProcessorTime.Duration().Minutes.ToString() + ":" + TotalProcessorTime.Duration().Seconds.ToString() + "." + TotalProcessorTime.Duration().Milliseconds.ToString() , (WorkingSet64 / 1024) + " K", (PeakWorkingSet64 / 1024) + " K", HandleCount.ToString(), ThreadCount.ToString(), status, user, FileDescription }); }