Guest User

Untitled

a guest
May 28th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #include <math.h>
  2. #include "mpi.h"
  3. #include <time.h>
  4. #include <stdbool.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. int main(argc,argv)
  9. int argc;
  10. char *argv[];
  11. {
  12. int i,myid, numprocs;
  13. int source,count;
  14. MPI_Status status;
  15. MPI_Request request;
  16.  
  17. double start_time, end_time;
  18. MPI_Init(&argc,&argv);
  19. MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
  20. MPI_Comm_rank(MPI_COMM_WORLD,&myid);
  21. source=0;
  22.  
  23. if (argc < 2){
  24. printf("Specify data size");
  25. MPI_Finalize();
  26. }
  27. sscanf(argv[1], "%d", &count);
  28. double *buffer = (double *)malloc(sizeof(double) * count);
  29. if(myid == source){
  30. int i;
  31. srand(0xBEEF);
  32. for (i=0; i<count; i++){
  33. buffer[i]=rand();
  34. }
  35. start_time = MPI_Wtime();
  36. }
  37. MPI_Barrier(MPI_COMM_WORLD);
  38. for(int j=0; j<myid; j++){
  39. int root=j;
  40. MPI_Bcast(buffer,count,MPI_INT,root,MPI_COMM_WORLD);
  41. for(int k=0; k<1000000; k++){
  42. ;
  43. }
  44. MPI_Barrier(MPI_COMM_WORLD);
  45. }
  46.  
  47. if (myid == 0){
  48. end_time = MPI_Wtime();
  49. printf("Elapsed time: %.8f\n", end_time-start_time);
  50. }
  51. MPI_Finalize();
  52. }
Add Comment
Please, Sign In to add comment