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