/*
 MPI-Java version :
    Sang Lim (slim@npac.syr.edu)
    Northeast Parallel Architectures Center at Syracuse University
    12/2/98
*/

import mpi.*;

class scattervO {
  static public void main(String[] args) throws MPIException {
    
    final int MAXLEN = 10;

    int myself,tasks;
    MPI.Init(args);
    myself = MPI.COMM_WORLD.Rank();
    tasks = MPI.COMM_WORLD.Size();

    int root,i=0,j,k,stride=15;
    test out[] = new test[tasks*stride];
    test in[]  = new test[MAXLEN];
    int dis[] = new int[tasks];
    int scount[] = new int[tasks];

    
    for(i = 0; i < MAXLEN;i++){
       in[i] = new test();
       in[i].a = 0;
    }
    for(i=0;i<tasks;i++){
       dis[i] = i*stride;
       scount[i] = 5;
    }

    scount[0] = 10;
    
    for (i = 0;i < tasks*stride;i++){
       out[i] = new test();
       out[i].a = i;
    }
    
    MPI.COMM_WORLD.Scatterv(out, 0, scount, dis   , MPI.OBJECT,
                            in , 0, scount[myself], MPI.OBJECT, 0);

    if(myself==0){
       System.out.println("Original array on root...");
       for(i=0; i<tasks*stride; i++)
          System.out.print(out[i].a+" ");
       System.out.println();
       System.out.println();

       System.out.println("Result on proc 0...");
       System.out.println("Stride = 15 "+"Count = "+scount[0]);
       for(i=0; i<MAXLEN; i++)
          System.out.print(in[i].a+" ");
       System.out.println();
       System.out.println();
    }
    
    MPI.COMM_WORLD.Barrier();

    if(myself==1){
       System.out.println("Result on proc 1...");
       System.out.println("Stride = 15 "+"Count = "+scount[1]);
       for(i=0; i<MAXLEN; i++)
          System.out.print(in[i].a+" ");
       System.out.println();
       System.out.println();
    }
    MPI.COMM_WORLD.Barrier();

    if(myself==2){
       System.out.println("Result on proc 2...");
       System.out.println("Stride = 15 "+"Count = "+scount[2]);
       for(i=0; i<MAXLEN; i++)
          System.out.print(in[i].a+" ");
       System.out.println();
    }
    MPI.COMM_WORLD.Barrier();
    if(myself == 0)  System.out.println("ScattervO TEST COMPLETE\n");
    MPI.Finalize();
  }
}

// Things to do
//
//   Make output deterministic by gathering and printing from root.

