Advertisement
Guest User

Untitled

a guest
May 21st, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <mpi.h>
  3. #include <iostream>
  4.  
  5. struct Liczba {
  6. int cal;
  7. float dzie;
  8. };
  9.  
  10.  
  11. int main(int argc, char *argv[]) {
  12. int npes;
  13. int myrank;
  14. double start, end;
  15.  
  16. MPI_Init(&argc, &argv);
  17.  
  18. const int nitems = 2;
  19. int blocklengths[2] = {1, 1};
  20. MPI_Datatype types[2] = {MPI_INT, MPI_INT};
  21. MPI_Datatype mpi_liczba;
  22. MPI_Aint offsets[2];
  23.  
  24. offsets[0] = offsetof(Liczba, cal);
  25. offsets[1] = offsetof(Liczba, dzie);
  26.  
  27. MPI_Type_create_struct(nitems, blocklengths, offsets, types, &mpi_liczba);
  28. MPI_Type_commit(&mpi_liczba);
  29.  
  30. start = MPI_Wtime();
  31. MPI_Comm_size(MPI_COMM_WORLD, &npes);
  32. MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
  33.  
  34. const int LICZBY_COUNT = 1;
  35. Liczba liczba;
  36. liczba.cal = 3;
  37. liczba.dzie = 4;
  38. if (myrank == 0) {
  39. MPI_Ssend(&liczba, LICZBY_COUNT, mpi_liczba, 1, 13, MPI_COMM_WORLD);
  40. } else if (myrank == 1) {
  41. MPI_Status status;
  42. Liczba liczbaRecv;
  43. MPI_Recv(&liczbaRecv, LICZBY_COUNT, mpi_liczba, 0, 13, MPI_COMM_WORLD, &status);
  44. // for (int i = 0; i < LICZBY_COUNT; i++) {
  45. std::cout << liczbaRecv.cal << "." << liczbaRecv.dzie << std::endl;
  46. // }
  47. }
  48.  
  49. end = MPI_Wtime();
  50. MPI_Finalize();
  51.  
  52. if (myrank == 0) {
  53. printf("end of process %lf\n", end - start);
  54. }
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement