-1
    package msj;
    import mpi.*;
    public class HelloWorld2 {

    public static final int N = 10;

    public static void main(String[] args) {

        MPI.Init(args);

        long startTime = System.currentTimeMillis();

        int rank = MPI.COMM_WORLD.Rank();
        int size = MPI.COMM_WORLD.Size();
        int tag = 10, peer = (rank==0) ? 1:0;

        if(rank == 0) {
        double [][] a = new double [N][N];

        for(int i = 0; i < N; i++)
            for(int j = 0; j < N; j++)
             a[i][j] = 10.0;

        Object[] sendObjectArray = new Object[1];
        sendObjectArray[0] = (Object) a;
        MPI.COMM_WORLD.Send(sendObjectArray, 0, 1, MPI.OBJECT, peer, tag);
        } else if(rank == 1){
        double [][] b = new double [N][N];

        for(int i = 0; i < N; i++)
        for(int j = 0; j < N; i++)
        b[i][j] = 0;

        Object[] recvObjectArray = new Object[1];
        MPI.COMM_WORLD.Recv(recvObjectArray, 0, 1, MPI.OBJECT, peer, tag);
        b = (double[][]) recvObjectArray[0];

        for(int i = 0; i < 4; i++){
        for(int j = 0; j < N; i++)

        //long endTime = System.currentTimeMillis();

        //long endTime = System.currentTimeMillis();

        System.out.print(b[i][j]+"\t");
        System.out.println("\n");
        //System.out.println("Calculated in " +
                                  // (endTime - startTime) + " milliseconds");
            }
            }
                  MPI.Finalize() ;
                }

} 

I couldn't run this program.
I get an error when I do not write an int before the variables in the for loop: for( int i = 0; i < N; i++).

Is the problem related to this ?
Do you have any idea, There is no problem in the code

Louys Patrice Bessette
  • 33,375
  • 6
  • 36
  • 64
drorhun
  • 13
  • 4
  • What error do you get? – David Glickman Feb 27 '17 at 17:24
  • java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at runtime.starter.MulticoreStarter$1.run(MulticoreStarter.java:281) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.NullPointerException at msj.HelloWorld2.fillToken(HelloWorld2.java:272) at msj.HelloWorld2.main(HelloWorld2.java:40) ... 6 more – drorhun Feb 27 '17 at 17:58

1 Answers1

0

You get "java.lang.ArrayIndexOutOfBoundsException: 10" if "rank ==1" becomes true. This is because in your nested for-loop you wrote

"for(int j = 0; j < N; i++)" instead of "for(int j = 0; j < N; j++)".

You increment i twice. This Exceptions stops your method.

Mr. Copy and Mr Paste send Greetings. ;o)