Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include "mpi.h"
  2. #include <stdio.h>
  3. #define MSG_HELLO 100
  4. #define MSG_SIZE 100
  5. int x = 250;
  6. int main(int argc, char **argv)
  7. {
  8. int rank,size,receiver=0;
  9. int msg[MSG_SIZE];
  10. int division[MSG_SIZE];
  11. for(int i =0; i< MSG_SIZE; i++) {
  12. division[i] = -1;
  13. }
  14. int counter = 0;
  15. MPI_Status status;
  16.  
  17. MPI_Init(&argc, &argv);
  18.  
  19. MPI_Comm_rank( MPI_COMM_WORLD, &rank );
  20. MPI_Comm_size( MPI_COMM_WORLD, &size );
  21.  
  22. for(int i= (x/size)*rank; i< ((x/size))*(rank+1); i++) {
  23. int reszta = 0;
  24. if(i != 0) {
  25. reszta = x%i;
  26. }
  27. if(reszta == 0) {
  28. division[counter] = i;
  29. counter++;
  30. }
  31. }
  32.  
  33. if ( rank == receiver)
  34. {
  35. for(int i=0; i <size-1; i++) {
  36. MPI_Recv(msg, MSG_SIZE, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
  37. for(int j =0; j < MSG_SIZE; j++) {
  38. if(msg[j] != -1) {
  39. division[counter] = msg[j];
  40. counter++;
  41. }
  42. }
  43. }
  44. for(int i=0; i< counter; i++) {
  45. printf("dzielnik %d\n ", division[i]);
  46. }
  47. }
  48. else
  49. {
  50. MPI_Send(division, MSG_SIZE, MPI_INT, receiver, MSG_HELLO, MPI_COMM_WORLD );
  51. }
  52. MPI_Finalize();
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement