Пример #1
0
        public static unsafe void MultiHilbertPagerank(string filename, float *a, float *b, uint nodes, float reset)
        {
            var stopwatch = System.Diagnostics.Stopwatch.StartNew();

            var degrees = LargePages.AllocateInts(nodes);

            var scanner = new MultiHilbertScanner(filename);

            scanner.Scan((xUpper, yUpper, count, offset, edges) =>
            {
                for (var j = offset; j < offset + count; j++)
                {
                    degrees[xUpper + ((edges[j] & 0xF0) >> 4)]++;
                }
            });

            Console.WriteLine("{0}\tDegrees calculated", stopwatch.Elapsed);

            for (int iteration = 0; iteration < 20; iteration++)
            {
                var startTime = stopwatch.Elapsed;

                for (int i = 0; i < nodes; i++)
                {
                    b[i] = (1.0f - reset) * a[i] / degrees[i];
                    a[i] = reset;
                }

                scanner.Scan((xUpper, yUpper, count, offset, edges) =>
                {
                    for (var j = offset; j < offset + count; j++)
                    {
                        a[yUpper + (edges[j] & 0x0F)] += b[xUpper + ((edges[j] & 0xF0) >> 4)];
                    }
                });

                Console.WriteLine("{0}\tIteration {1} in {2}", stopwatch.Elapsed, iteration, stopwatch.Elapsed - startTime);
            }
        }
Пример #2
0
        public static unsafe void MultiHilbertCC(string filename, uint nodes)
        {
            var stopwatch = System.Diagnostics.Stopwatch.StartNew();

            var roots = LargePages.AllocateInts(nodes);
            var ranks = LargePages.AllocateBytes(nodes);

            for (int i = 0; i < nodes; i++)
            {
                roots[i] = i;
            }

            var scanner = new MultiHilbertScanner(filename);

            scanner.Scan((xUpper, yUpper, count, offset, edges) =>
            {
                for (int j = 0; j < count; j++)
                {
                    var source = (int)(xUpper + ((edges[offset + j] & 0xF0) >> 4));
                    var target = (int)(yUpper + ((edges[offset + j] & 0x0F) >> 0));

                    if (source != target)
                    {
                        while (source != roots[source])
                        {
                            source = roots[source];
                        }

                        while (target != roots[target])
                        {
                            target = roots[target];
                        }

                        // union(source, target)
                        if (source != target)
                        {
                            // there may be a tie in ranks
                            if (ranks[source] == ranks[target])
                            {
                                // break ties towards lower ids
                                if (source < target)
                                {
                                    ranks[source]++;
                                    roots[target] = source;
                                }
                                else
                                {
                                    ranks[target]++;
                                    roots[source] = target;
                                }
                            }
                            else
                            {
                                // attatch lower rank to higher
                                if (ranks[source] < ranks[target])
                                {
                                    roots[source] = target;
                                }
                                else
                                {
                                    roots[target] = source;
                                }
                            }
                        }
                    }
                }
            });

            // path compress all vertices to roots.
            for (int i = 0; i < nodes; i++)
            {
                while (roots[i] != roots[roots[i]])
                {
                    roots[i] = roots[roots[i]];
                }
            }

            var counter = 0;

            for (int i = 0; i < nodes; i++)
            {
                if (roots[i] != i)
                {
                    counter++;
                }
            }

            Console.WriteLine("{1}\tEdges found: {0}", counter, stopwatch.Elapsed);
        }