001 /*
002 * $Id: HelloMPP.java,v 1.5 2002/08/03 17:17:42 kredel Exp $
003 */
004 import java.io.IOException;
005 import mpp.Communicator;
006 import mpp.BlockCommunicator;
007 import mpp.StreamCommunicator;
008
009 /**
010 * HelloMPP.
011 * @author from the MPI examples, adapted for MPP.
012 */
013 public class HelloMPP {
014
015 static public void main(String[] args) throws IOException {
016
017 //MPI.Init(args) ;
018 Communicator mpi_comm_world = new BlockCommunicator();
019 //Communicator mpi_comm_world = new StreamCommunicator();
020
021 int myrank = mpi_comm_world.rank();
022 int size = mpi_comm_world.size();
023
024 int msglength = "Hello, there".length();
025 if(myrank == 0) {
026 char [] message = "Hello, there".toCharArray() ;
027 System.out.println("send("+myrank+"|"+size+"): " + new String(message) + " :");
028
029 mpi_comm_world.send(message, 0, msglength, size-1);
030 }
031 else {
032 char [] mymessage = new char [20];
033 System.out.print("receive("+myrank+"|"+size+")");
034
035 mpi_comm_world.recv(mymessage, 0, msglength/*-5*/, 0);
036 System.out.println(": " + new String(mymessage) + ":") ;
037 }
038
039 //MPI.Finalize();
040 mpi_comm_world.close();
041 }
042
043 }