fork download
  1. package myproj;
  2. import mpi.*;
  3. public class lab8 {
  4. public static void main(String[] args) throws MPIException {
  5. // Initialize MPI
  6. MPI.Init(args);
  7.  
  8. int MyRank = MPI.COMM_WORLD.Rank(); // Get the rank of the current process
  9. int Numprocs = MPI.COMM_WORLD.Size(); // Get the number of processes
  10. int tag = 100;
  11.  
  12. // Message buffers
  13. String send_message = MyRank + ": Hello";
  14. String recv_message = new String(new char[50]); // Buffer to receive message
  15.  
  16. // Send message to all other processes
  17. for (int i = 0; i < Numprocs; i++) {
  18. if (MyRank != i) {
  19. // Send message to process i
  20. MPI.COMM_WORLD.Send(send_message.getBytes(), send_message.length(), MPI.BYTE, i, tag);
  21. }
  22. }
  23.  
  24. // Receive message from all other processes
  25. for (int i = 0; i < Numprocs; i++) {
  26. if (MyRank != i) {
  27. // Receive message from process i
  28. MPI.COMM_WORLD.Recv(recv_message.getBytes(), 50, MPI.BYTE, i, tag);
  29. System.out.println("Process " + MyRank + " received message from process " + i + ": " + new String(recv_message));
  30. }
  31. }
  32.  
  33. // Finalize MPI
  34. MPI.Finalize();
  35. }
  36. }
  37.  
  38.  
Success #stdin #stdout #stderr 0.27s 40644KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "package myproj"
Execution halted