fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <mpi.h>
  4.  
  5. int main(int argc, char *argv[]) {
  6. int rank, size;
  7. double serial_time = 10.0; // Example serial execution time in seconds
  8. double parallel_time; // Example parallel execution time
  9. double speedup, efficiency;
  10.  
  11. MPI_Init(&argc, &argv);
  12. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  13. MPI_Comm_size(MPI_COMM_WORLD, &size);
  14.  
  15. // Assume parallel_time is measured differently for each process
  16. // Example: divide the serial time by the rank
  17. parallel_time = serial_time / (rank + 1);
  18.  
  19. // Calculate speedup
  20. MPI_Reduce(&parallel_time, &speedup, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD);
  21. speedup = serial_time / speedup;
  22.  
  23. // Calculate efficiency
  24. efficiency = speedup / size;
  25.  
  26. if (rank == 0) {
  27. printf("Speedup: %lf\n", speedup);
  28. printf("Efficiency: %lf\n", efficiency);
  29. }
  30.  
  31. MPI_Finalize();
  32. return 0;
  33. }
Success #stdin #stdout #stderr 0.26s 40260KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "int main"
Execution halted