0

I have a project to run a matrix-multiplication demo via Java networking.

I am getting the following error when I run Eclipse :

'Error: Could not find or load main class Coordinator.java'

But the class I am running does have a main method. I'm not sure what is going on with this.

I include screenshot here of the Eclipse screen where I was : https://i.stack.imgur.com/T8zqI.png

I realize it's most likely an eclipse/configuration error ,but anyway I include here below the Worker.java and DataIO.java code , altogether it is 5 classes, and the other 3 I put into a jsfiddle , though its not Java ( MatrixMultiple.java Connection.java Coordinator.java DataIO.java, and Worker.java - Coordinator.java is which runs the java code ; )

package socket_example_1row;

import java.io.*;
import java.util.Scanner; 

import java.net.InetAddress;
import java.util.Arrays;

import matrix.*;

public class Worker {

    int nodeNum;
    int localPort;
    Connection conn;
    int dim; 
    int width; 
    int[][] a;
    int[][] b;
    int[][] c;
    DataInputStream disCoor;
    DataOutputStream dosCoor;
    DataOutputStream dosLeft;
    DataInputStream disRight;

    public Worker(int nodeNum, int localPort) {
        this.nodeNum = nodeNum;
        this.localPort = localPort;
    }

    void configurate(String coorIP, int coorPort) {
        try {
            conn = new Connection(localPort); 
            DataIO dio = conn.connectIO(coorIP, coorPort); 
            dosCoor = dio.getDos();  
            dosCoor.writeInt(nodeNum);
            dosCoor.writeUTF(InetAddress.getLocalHost().getHostAddress());
            dosCoor.writeInt(localPort);
            disCoor = dio.getDis();
            dim = disCoor.readInt();                //get matrix dimension from coordinator
            width = disCoor.readInt();
            a = new int[dim][width];
            b = new int[dim][width];
            c = new int[dim][width];
            String ipLeft = disCoor.readUTF();      //left block connection info
            int portLeft = disCoor.readInt();
            String ipRight = disCoor.readUTF();     //right block connection info 
            int portRight = disCoor.readInt();
            if (nodeNum%2==0) {     // Even # worker connecting manner
                dosLeft = conn.connect2write(ipLeft, portLeft);
                disRight = conn.accept2read();   
            } else {                // Odd # worker connecting manner
                disRight = conn.accept2read();  
                dosLeft = conn.connect2write(ipRight, portRight);
            }
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } 
        System.out.println("Configuration done."); 
    }

    // shift matrix a toward left, even # worker send before receive
    void shiftLeftSend1st(int[][] mat, DataOutputStream dosL, DataInputStream disR) {
        // send leftmost column 
        for (int i = 0; i < dim; i++) {
            try {
                dosLeft.writeInt(mat[i][0]);
            } catch (IOException ioe) {
                System.out.println("error in sending to left, row=" + i);
                ioe.printStackTrace();
            }
        }
        // local shift
        for (int i = 0; i < dim; i++) {
            for (int j = 1; j < width; j++) {
                mat[i][j - 1] = mat[i][j];
            }
        }
        // receive the rightmost column
        for (int i = 0; i < dim; i++) {
            try {
                mat[i][width - 1] = disRight.readInt();
            } catch (IOException ioe) {
                System.out.println("error in receiving from right, row=" + i);
                ioe.printStackTrace();
            }
        }
    }

    // shift matrix a toward left, odd # worker receive before send
    void shiftLeftReceive1st(int[][] mat, DataOutputStream dosL, DataInputStream disR) {
        int[] tempIn = new int[dim];
        int[] tempOut = new int[dim];
        for (int i = 0; i < dim; i++) { // receive a column from right
            try {
                tempIn[i] = disRight.readInt();
            } catch (IOException ioe) {
                System.out.println("error in receiving from right, row=" + i);
                ioe.printStackTrace();
            }
        }
        for (int i = 0; i < dim; i++) { // local shift
            tempOut[i] = a[i][0];
        }
        for (int i = 0; i < dim; i++) {
            for (int j = 1; j < width; j++) {
                a[i][j - 1] = a[i][j];
            }
        }
        for (int i = 0; i < dim; i++) {
            a[i][width - 1] = tempIn[i];
        }
        for (int i = 0; i < dim; i++) { // send leftmost column to left node
            try {
                dosLeft.writeInt(tempOut[i]);
            } catch (IOException ioe) {
                System.out.println("error in sending left, row=" + i);
                ioe.printStackTrace();
            }
        }
    }

    // shift matrix upward 
    void shiftUp(int[][] mat) { 
        // copy top row 
        int[] tempTop = new int[mat[0].length]; 
        for (int j = 0; j < tempTop.length; j++) {
            tempTop[j] = mat[0][j]; 
        }
        // local shift
        for (int i = 0; i < mat.length-1; i++) {
            for (int j = 0; j < mat[0].length; j++) {
                mat[i][j] = mat[i+1][j];
            }
        } 
        for (int j = 0; j < tempTop.length; j++) {
            mat[mat.length-1][j] = tempTop[j]; 
        }
    }

    void compute() {
        // get the block of a from coordinator 
        for (int i = 0; i < dim; i++) {
            for (int j = 0; j <width; j++) {
                try {
                    a[i][j] = disCoor.readInt();
                } catch (IOException ioe) {
                    System.out.println("error: matrix a " + i + ", " + j);
                    ioe.printStackTrace();
                }
            }
        }
        MatrixMultiple.displayMatrix(a);
        // get the block of b from coordinator 
        for (int i = 0; i < dim; i++) {
            for (int j = 0; j <width; j++) {
                try {
                    b[i][j] = disCoor.readInt();
                } catch (IOException ioe) {
                    System.out.println("error: matrix b " + i + ", " + j);
                    ioe.printStackTrace();
                }
            }
        } 
        MatrixMultiple.displayMatrix(b); 
        c = new int[a.length][a[0].length]; 
        for (int i=0; i < a.length; i++) {
            Arrays.fill(c[i], 0);
        }
        // multiplication 
        for (int r = 0; r < a.length; r++) {
            // computer one term in c
            for (int i = 0; i < a.length; i++) {
                for (int j = 0; j <a[0].length; j++) {
                    c[i][j] = c[i][j] + a[i][j] * b[i][j];
                }
            } 
            System.out.println("Matrix c"); 
            MatrixMultiple.displayMatrix(c, 8);
            // shift matrix a toward left 
            if (nodeNum%2==0) {         // Even # worker shifting procedure 
                shiftLeftSend1st(a, dosLeft, disRight); 
            } else {                    // Odd # worker shifting procedure
                shiftLeftReceive1st(a, dosLeft, disRight); 
            } 
            shiftUp(b);
            System.out.println("Shifted matrix a, r=" + r); 
            MatrixMultiple.displayMatrix(a);
            System.out.println("Shifted matrix b"); 
            MatrixMultiple.displayMatrix(b);
        }
        System.out.println("Matrix c"); 
        MatrixMultiple.displayMatrix(c, 8);

    }

    public static void main(String[] args) {
        if (args.length != 4) {
            System.out.println("usage: java Worker workerID worker-port-num coordinator-ip coordinator-port-num");
        }
        int workerID = Integer.parseInt(args[0]);
        int portNum = Integer.parseInt(args[1]);
        Worker worker = new Worker(workerID, portNum);
        worker.configurate(args[2], Integer.parseInt(args[3]));
        worker.compute();
        try {
            Thread.sleep(6000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("Press the enter key to exit."); 
        try {
            new BufferedReader(new InputStreamReader(System.in)).readLine();
        } catch (IOException ioe) {ioe.printStackTrace();}
    }
}

DataIO.java

package socket_example_1row;

import java.io.*; 

public class DataIO {
    DataInputStream dis; 
    DataOutputStream dos; 

    public DataIO(DataInputStream dis, DataOutputStream dos) { 
        this.dis = dis; 
        this.dos = dos; 
    }

    public DataInputStream getDis() {
        return dis;
    }

    public void setDis(DataInputStream dis) {
        this.dis = dis;
    }

    public DataOutputStream getDos() {
        return dos;
    }

    public void setDos(DataOutputStream dos) {
        this.dos = dos;
    } 
}

jsfiddle with the rest of Java code in it = Coordinator.java ; MatrixMultiple.java ; Connection.java :

http://jsfiddle.net/31y0ehep/

thanks so much

  • 1
    Could it be that in your Run Configuration you have as a main class Coordinator.java? It shall be socket_example_1row.Coordinator - Btw, you can also fix the usage System.out. – Michal Nov 30 '14 at 22:42
  • 1
    In Run Configuration there is also a browse button. On hitting it eclipse figures out the classes which qualify as main and lets you choose, thus minimizing the place for typos an other errors. If eclipse offers you no classes upon hitting the browse then your project ist not java project. – Michal Nov 30 '14 at 22:51
  • test1 - http://stackoverflow.com/questions/4952394/check-what-ports-are-being-used test2 - http://stackoverflow.com/questions/4952394/check-what-ports-are-being-used – Dizzleros Fardoodas Dec 18 '14 at 02:40

1 Answers1

0

I can't really tell why you also have a main method in your Worker class, but to make sure it isn't an Eclipse related error try the following:

  1. Right click your project;

  2. At Run As, go to Run Configurations;

  3. Delete every run configuration related to your project.

pietv8x
  • 248
  • 1
  • 9
  • Hmm so I went into the `Run Configurations` screen , for some reason e clipse hangs on me. I was only able to delete one of about 10 configuration – Dizzleros Fardoodas Dec 02 '14 at 01:02