コード例 #1
0
ファイル: GraphGen.cs プロジェクト: graiul/GraphEngine
        public static void CellCleaningThreadProc(object par)
        {
            CellCleaningThreadObject p = (CellCleaningThreadObject)par;
            long start = -1;
            long end   = -1;
            long ele   = p.nodeNum / p.threadCount;

            if (p.threadCount != p.threadIndex + 1)
            {
                start = p.threadIndex * ele + 1;
                end   = start + ele;
            }
            else
            {
                start = p.threadIndex * ele + 1;
                end   = p.nodeNum + 1;
            }
            for (long i = start; i < end; i++)
            {
                using (var node = Global.LocalStorage.UseGraphNode(i))
                {
                    if (node.EdgeCount < node.Edges.Count)
                    {
                        node.Edges.RemoveRange(node.EdgeCount, node.Edges.Count - node.EdgeCount);
                    }
                }
            }
        }
コード例 #2
0
ファイル: GraphGen.cs プロジェクト: graiul/GraphEngine
        public void CreatGraph()
        {
            int threadCount = Environment.ProcessorCount;

            Thread[] threadNum = new Thread[threadCount];
            ////////////////////////////////PHASE 1///////////////////////////////
            Console.WriteLine("Generating ID values");
            Stopwatch s = new Stopwatch();

            s.Start();
            TrinityConfig.CurrentRunningMode = RunningMode.Embedded;
            TrinityConfig.DefragInterval     = 2500;
            for (int threadIndex = 0; threadIndex < threadCount; threadIndex++)
            {
                NodeCreationThreadObject p = new NodeCreationThreadObject(threadCount, threadIndex);
                threadNum[threadIndex] = new Thread(CreateGraphNodeThreadProc);
                threadNum[threadIndex].Start(p);
            }
            for (int inde = 0; inde < threadCount; inde++)
            {
                threadNum[inde].Join();
            }
            s.Stop();
            Console.WriteLine("add idValue cost time:{0}", s.ElapsedMilliseconds);
            ////////////////////////////////PHASE 2///////////////////////////////
            Console.WriteLine("add edges");
            Stopwatch ss = new Stopwatch();

            ss.Start();
            for (int threadIndex = 0; threadIndex < threadCount; threadIndex++)
            {
                EdgeCreationThreadObject p = new EdgeCreationThreadObject(threadCount, threadIndex);
                threadNum[threadIndex] = new Thread(CreateEdgeThreadProc);
                threadNum[threadIndex].Start(p);
            }
            for (int inde = 0; inde < threadCount; inde++)
            {
                threadNum[inde].Join();
            }
            ss.Stop();
            Console.WriteLine("add outlinks cost time:{0}", ss.ElapsedMilliseconds);

            ///////////////Remove dirty outlinks//////////////
            Stopwatch watch = new Stopwatch();

            watch.Start();
            for (int threadIndex = 0; threadIndex < threadCount; threadIndex++)
            {
                CellCleaningThreadObject p = new CellCleaningThreadObject(threadCount, threadIndex, nodeCount);
                threadNum[threadIndex] = new Thread(CellCleaningThreadProc);
                threadNum[threadIndex].Start(p);
            }
            for (int inde = 0; inde < threadCount; inde++)
            {
                threadNum[inde].Join();
            }
            watch.Stop();
            Console.WriteLine(watch.ElapsedMilliseconds);
            TrinityConfig.DefragInterval = 100;
            ///////////////////////////////////////////////
            Stopwatch sss = new Stopwatch();

            sss.Start();
            Global.LocalStorage.SaveStorage();
            sss.Stop();
            Console.WriteLine("saveStorage cost time:{0}", sss.ElapsedMilliseconds);
            //foreach (var node in Global.LocalStorage.GraphNode_Selector())
            //{
            //    Console.WriteLine(node);
            //}
            //var results = from node in Global.LocalStorage.GraphNode_Accessor_Selector()
            //              select node;
            //Console.WriteLine(results.Distinct());
        }