Guest User

Untitled

a guest
May 27th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #define A 10.0 // Integral starting position
  2. #define B 22.0 // Integral ending position
  3. #define W .1 // Integral step size
  4.  
  5. #include <stdio.h>
  6. #include <mpi.h>
  7. #define round(v) (float)(int)(v / W) * W
  8.  
  9. double f(double x) {
  10. return x * x;
  11. }
  12.  
  13. int main(int argc, char* argv[]) {
  14. int i;
  15. int id, p;
  16. MPI_Init(&argc, &argv);
  17. MPI_Comm_size(MPI_COMM_WORLD, &p);
  18. MPI_Comm_rank(MPI_COMM_WORLD, &id);
  19.  
  20. // Calculate job boundaries and print them in order
  21. double a, b, da, db, wpp;
  22. wpp = (B - A) / p;
  23. da = wpp * id;
  24. db = wpp * (id + 1);
  25. a = A + round(da);
  26. b = A + round(db);
  27. for (i = 0; i < p; i++) {
  28. if (i == id)
  29. printf("Process #%d: f(%f) to f(%f)\n", id, a, b);
  30. MPI_Barrier(MPI_COMM_WORLD);
  31. }
  32.  
  33. MPI_Finalize();
  34. }
Add Comment
Please, Sign In to add comment