fork download
  1. from mpi4py import MPI
  2.  
  3. # Initialize MPI
  4. comm = MPI.COMM_WORLD
  5. rank = comm.Get_rank()
  6. size = comm.Get_size()
  7.  
  8. # Coordonatele punctelor A și B
  9. A = (2, -1)
  10. B = (1, -2)
  11.  
  12. # Funcția pentru calculul pantei și interceptării
  13. def calculate_slope_intercept(A, B):
  14. x1, y1 = A
  15. x2, y2 = B
  16. slope = (y2 - y1) / (x2 - x1)
  17. intercept = y1 - slope * x1
  18. return slope, intercept
  19.  
  20. # Determinarea pantei și interceptării în paralel
  21. if rank == 0:
  22. slope, intercept = calculate_slope_intercept(A, B)
  23. data = {"slope": slope, "intercept": intercept}
  24. else:
  25. data = None
  26.  
  27. data = comm.bcast(data, root=0)
  28.  
  29. # Afisarea ecuatiei dreptei
  30. if rank != 0:
  31. print(f"Ecuatia dreptei este: y = {data['slope']}x + {data['intercept']}")
Success #stdin #stdout #stderr 0.3s 40676KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "from mpi4py"
Execution halted