Advertisement
Guest User

Untitled

a guest
May 16th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <mpi.h>
  4. #include <vector>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. class Rekord
  10. {
  11. public:
  12. Rekord()
  13. {
  14. for (int i = 0; i < 100; i++)
  15. {
  16. vec.push_back(i);
  17. }
  18.  
  19. string2 = "Ala ma kota";
  20.  
  21. }
  22. void show()
  23. {
  24.  
  25. for (int j = 0; j < 100; j++)
  26. {
  27. cout << "zawartosc wektora" << vec[j] << endl;
  28. }
  29.  
  30. cout << "Zawartosc stringa: " << string2 << endl;
  31. }
  32.  
  33. void set_vec(int n)
  34. {
  35. vec.push_back(n);
  36.  
  37.  
  38.  
  39. }
  40. void set_string(string k)
  41. {
  42. string2 = k;
  43.  
  44. }
  45.  
  46. vector<int> get_vec()
  47. {
  48.  
  49. return vec;
  50. }
  51.  
  52. string get_string()
  53. {
  54.  
  55. return string2;
  56.  
  57. }
  58. void send(int odbiorca)
  59. {
  60. int vecsize = vec.size();
  61. int strsize = string2.length();
  62. MPI::COMM_WORLD.Send(&vecsize, 1, MPI::INT, odbiorca, 0);
  63. MPI::COMM_WORLD.Send(&(vec[0]), vecsize, MPI::INT, odbiorca, 0);
  64. MPI::COMM_WORLD.Send(&strsize, 1, MPI::INT, odbiorca, 0);
  65. MPI::COMM_WORLD.Send(&(string2[0]), 1, MPI::CHAR, odbiorca, 0);
  66.  
  67.  
  68.  
  69.  
  70.  
  71. }
  72.  
  73. void recv(int nadawca)
  74. {
  75. string tempString;
  76.  
  77.  
  78.  
  79. int vecsize;
  80. int strsize;
  81.  
  82. MPI::COMM_WORLD.Recv(&vecsize, 1, MPI::INT, nadawca, 0);
  83. vec.resize(vecsize);
  84. MPI::COMM_WORLD.Recv(&(vec[0]), vecsize, MPI::INT, nadawca, 0);
  85. MPI::COMM_WORLD.Recv(&strsize, 1, MPI::INT, nadawca, 0);
  86. char *buff = new char[strsize + 1];
  87. MPI::COMM_WORLD.Recv(buff, strsize, MPI::CHAR, nadawca, 0);
  88. buff[size] = "\0";
  89. string2.clear();
  90. string2 += buff;
  91.  
  92.  
  93.  
  94.  
  95.  
  96. }
  97.  
  98. private:
  99. vector<int> vec;
  100. string string2;
  101.  
  102. };
  103.  
  104.  
  105.  
  106.  
  107.  
  108. void stringsend(const string &s, int odbiorca)
  109. {
  110. int size = s.length();
  111. MPI::COMM_WORLD.Send(&size, 1, MPI::INT, odbiorca, 0);
  112. MPI::COMM_WORLD.Send(&(s[0]), size, MPI::CHAR, odbiorca, 1);
  113. }
  114.  
  115. string stringrecv(int nadawca)
  116. {
  117. string s;
  118. int size;
  119. MPI::COMM_WORLD.Recv(&size, 1, MPI::INT, nadawca, 0);
  120. char*buff = new char[size + 1];
  121. MPI::COMM_WORLD.Recv(buff, size, MPI::CHAR, nadawca, 1);
  122. buff[size] = '\0';
  123. s.append(buff);
  124. return s;
  125. }
  126.  
  127. int main(int argc, char **argv) {
  128.  
  129.  
  130.  
  131.  
  132.  
  133. MPI::Init(argc, argv);
  134. int rank = MPI::COMM_WORLD.Get_rank();
  135. if (rank == 0)
  136. {
  137. Rekord rek1;
  138. rek1.send(1);
  139.  
  140. }
  141. else if (rank == 1)
  142. {
  143.  
  144.  
  145. }
  146. MPI::Finalize();
  147. return 0;
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement