简体   繁体   English

我需要帮助来访问这个 class

[英]I need help accessing this class

I really need to fix this and I don't have any idea how, so any kind of help would be much appreciated.我真的需要解决这个问题,我不知道如何解决,所以任何形式的帮助都将不胜感激。 I am kind of a newbie to Java, yet I have knowledge in writing code.我是 Java 的新手,但我有编写代码的知识。 I want to add a new thread using the class AddComputeThread, but I am not sure how to access it or call the methods in it.我想使用 class AddComputeThread 添加一个新线程,但我不确定如何访问它或调用其中的方法。 Any idea?任何想法? When trying to create a new instance of the class, it gives me the error that the constructor of the AddComputeThread is not defined.当尝试创建 class 的新实例时,它给了我一个错误,即未定义 AddComputeThread 的构造函数。

Here is the java file这是 java 文件

package pgdp.pingulib.math.matrix;

import java.util.concurrent.atomic.AtomicInteger;

public class SquareMatrixAdd {

    private static final int MIN_DIM = 1 << 1;

    /**
     * Sequential matrix addition of A and B
     * 
     * @param A matrix
     * @param B matrix
     * @return result of the matrix addition in a new matrix
     */
    public static SquareMatrix addSequential(SquareMatrix A, SquareMatrix B) {
        if (A == null) {
            throw new IllegalArgumentException("A can not be null");
        }
        if (B == null) {
            throw new IllegalArgumentException("B can not be null");
        }
        if (A.getDimension() != B.getDimension()) {
            throw new IllegalArgumentException("A and B have different dimensions");
        }
        SquareMatrix C = new SquareMatrix(A.getDimension());
        for (int i = 1; i <= A.getDimension(); i++) {
            for (int j = 1; j <= A.getDimension(); j++) {
                C.set(i, j, A.get(i, j).add(B.get(i, j)));
            }
        }
        return C;
    }

    /**
     * Parallel matrix addition of A and B. If the dimensions are smaller or equal
     * than the default value <MIN_DIM>, the sequential matrix addition will be
     * applied.
     * 
     * @param A matrix
     * @param B matrix
     * @return result of the matrix addition in a new matrix
     */
    public static SquareMatrix addParallel(SquareMatrix A, SquareMatrix B) {
        return addParallel(A, B, MIN_DIM);
    }

    /**
     * Parallel matrix addition of A and B. If <minDim> is smaller than the default
     * value <MIN_DIM>, the default value will be used. If the dimensions are
     * smaller or equal than <minDim>, the sequential matrix addition will be
     * applied.
     * 
     * @param A      matrix
     * @param B      matrix
     * @param minDim dimension
     * @return result of the matrix addition in a new matrix
     */
    public static SquareMatrix addParallel(SquareMatrix A, SquareMatrix B, int minDim) {
        // TODO
        SquareMatrix C = new SquareMatrix(A.getDimension());
        if(minDim < MIN_DIM)
            minDim = MIN_DIM;
        else if (A == null) {
            throw new IllegalArgumentException("A can not be null");
        }
        if (B == null) {
            throw new IllegalArgumentException("B can not be null");
        }
        if (A.getDimension() != B.getDimension()) {
            throw new IllegalArgumentException("A and B have different dimensions");
        }
        if (A.getDimension() <= minDim) {
            C = addSequential(A, B);
        } else {
            for( int i = 1; i < A.getDimension()/2; ++i ) {
                for( int j = 1; j < A.getDimension()/2; ++j ) {
                    AddComputeThread trd = new AddComputeThread(1, A, B, minDim, C);
                }
            }
        }

        return C;
    }

    private static class AddComputeThread extends ComputeThread {

        private static AtomicInteger computeThreadCounter = new AtomicInteger(0);

        /**
         * initialize compute thread for matrix addition.
         * 
         * @param threadID index where result will be stored
         * @param A        first matrix
         * @param B        second matrix
         * @param minDim   threshold for sequential computation
         * @param results  array reference where the result will be stored
         */
        AddComputeThread(int threadID, SquareMatrix A, SquareMatrix B, int minDim, SquareMatrix[] results) {
            super(threadID, A, B, minDim, results);
            this.setName("AddComputeThread-" + computeThreadCounter.incrementAndGet());
        }

        /**
         * resets the thread counter
         */
        public static synchronized void resetThreadCount() {
            computeThreadCounter = new AtomicInteger(0);
        }

        /**
         * retrieves the current thread count
         * 
         * @return thread count
         */
        public static AtomicInteger getThreadCount() {
            return computeThreadCounter;
        }

        @Override
        public void run() {
            // TODO
            this.start();
            
        }
    }
}

Here:这里:

AddComputeThread trd = new AddComputeThread(1, A, B, minDim, C);

you are trying to call this AddComputeThread constructor:您正在尝试调用此 AddComputeThread 构造函数:

AddComputeThread(int threadID, SquareMatrix A, SquareMatrix B, int minDim, SquareMatrix[] results)

But C, the fifth argument you give, is an instance of SquareMatrix, not an array as required.但是您给出的第五个参数 C 是 SquareMatrix 的实例,而不是所需的数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM