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