Esempio n. 1
0
        public DefaultCounts(int threads)
        {
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: _counts = new long[Enum.GetValues(typeof(Counts_Type)).length][threads];
            _counts = RectangularArrays.RectangularLongArray(Enum.GetValues(typeof(Counts_Type)).length, threads);
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private long[][] sortRadix() throws InterruptedException
        private long[][] SortRadix()
        {
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: long[][] rangeParams = new long[_threads][2];
            long[][] rangeParams = RectangularArrays.RectangularLongArray(_threads, 2);
            int[]    bucketRange = new int[_threads];
            Workers <TrackerInitializer> initializers = new Workers <TrackerInitializer>("TrackerInitializer");

//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: _sortBuckets = new long[_threads][2];
            _sortBuckets = RectangularArrays.RectangularLongArray(_threads, 2);
            long dataSize   = _highestSetIndex + 1;
            long bucketSize = dataSize / _threads;
            long count      = 0;
            long fullCount  = 0;

            _progress.started("SPLIT");
            for (int i = 0, threadIndex = 0; i < _radixIndexCount.Length && threadIndex < _threads; i++)
            {
                if ((count + _radixIndexCount[i]) > bucketSize)
                {
                    bucketRange[threadIndex]    = count == 0 ? i : i - 1;
                    rangeParams[threadIndex][0] = fullCount;
                    if (count != 0)
                    {
                        rangeParams[threadIndex][1] = count;
                        fullCount += count;
                        _progress.add(count);
                        count = _radixIndexCount[i];
                    }
                    else
                    {
                        rangeParams[threadIndex][1] = _radixIndexCount[i];
                        fullCount += _radixIndexCount[i];
                        _progress.add(_radixIndexCount[i]);
                    }
                    initializers.Start(new TrackerInitializer(this, threadIndex, rangeParams[threadIndex], threadIndex > 0 ? bucketRange[threadIndex - 1] : -1, bucketRange[threadIndex], _sortBuckets[threadIndex]));
                    threadIndex++;
                }
                else
                {
                    count += _radixIndexCount[i];
                }
                if (threadIndex == _threads - 1 || i == _radixIndexCount.Length - 1)
                {
                    bucketRange[threadIndex]    = _radixIndexCount.Length;
                    rangeParams[threadIndex][0] = fullCount;
                    rangeParams[threadIndex][1] = dataSize - fullCount;
                    initializers.Start(new TrackerInitializer(this, threadIndex, rangeParams[threadIndex], threadIndex > 0 ? bucketRange[threadIndex - 1] : -1, bucketRange[threadIndex], _sortBuckets[threadIndex]));
                    break;
                }
            }
            _progress.done();

            // In the loop above where we split up radixes into buckets, we start one thread per bucket whose
            // job is to populate trackerCache and sortBuckets where each thread will not touch the same
            // data indexes as any other thread. Here we wait for them all to finish.
            Exception error = initializers.Await();

            long[] bucketIndex = new long[_threads];
            int    i           = 0;

            foreach (TrackerInitializer initializer in initializers)
            {
                bucketIndex[i++] = initializer.BucketIndex;
            }
            if (error != null)
            {
                throw new AssertionError(error.Message + "\n" + DumpBuckets(rangeParams, bucketRange, bucketIndex), error);
            }
            return(rangeParams);
        }