Beispiel #1
0
        void Pump()
        {
            try
            {
                var numProcessors = Environment.ProcessorCount;
                while (true)
                {
                    var next       = _logEventsQueue.Take(_cancelToken.Token);
                    var workerTask = Task.Factory.StartNew((t) =>
                    {
                        WriteLogEvent(t as LogEvent);
                    }, next);

                    _workerTasks.Add(workerTask);
                    if (_workerTasks.Count >= numProcessors)
                    {
                        Task.WaitAll(_workerTasks.ToArray());
                        _workerTasks.Clear();
                    }
                }
            }
            catch (OperationCanceledException)
            {
                Task.WaitAll(_workerTasks.ToArray());
                _logEventsQueue.AsParallel().ForAll(item => WriteLogEvent(item));
            }
            catch (Exception ex)
            {
                SelfLog.WriteLine("{0} fatal error in worker thread: {1}", typeof(AzureDocumentDBSink), ex);
            }
        }
Beispiel #2
0
        static int ParallelBFS(IGraph graph, IVertex root)
        {
            int[] distances       = new int[graph.Vertices.Count * 2];
            int   numVisitedNodes = 0;
            //ConcurrentQueue<IVertex> queue = new ConcurrentQueue<IVertex>();

            BlockingCollection <IVertex> queue = new BlockingCollection <IVertex>();


            Parallel.ForEach(graph.Vertices, vertex =>
            {
                vertex.Visited       = false;
                distances[vertex.ID] = -1;
            }
                             );

            root.Visited       = true;
            distances[root.ID] = 0;
            numVisitedNodes++;

            //queue.Enqueue(root);
            queue.Add(root);
            int index = 0;

            int[]   sums        = new int[graph.Vertices.Count * 2];
            IVertex currentNode = null;
            object  lockObject  = new object();

            while (queue.Count != 0)
            {
                Interlocked.Add(ref numVisitedNodes, queue.AsParallel <IVertex>().Sum(node => parallelDequeue(queue, distances, lockObject)));
            }

            return(numVisitedNodes);
        }
Beispiel #3
0
        public static BlockingCollection <FolderInfo> GetFolderInfos(IEnumerable <string> seekStrings, IEnumerable <string> foldersPath, IEnumerable <string> exts, IEnumerable <string> excludedFolders, bool recursive)
        {
            var infos = new BlockingCollection <FolderInfo>();

            for (var order = 0; order < foldersPath.Count(); order++)
            {
                infos.Add(FileUtils.GetFolderInfo(seekStrings, order, foldersPath.ElementAt(order), exts, excludedFolders, recursive));
            }
            infos.AsParallel().ForAll(folerInfo => FileUtils.GetFiles(folerInfo));
            return(infos);
        }