Don't like ads? PRO users don't see any ads ;-)
Guest

rehgewrthwr

By: a guest on Apr 24th, 2012  |  syntax: C  |  size: 0.84 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. MPI_Init(&argc,&argv);
  2. MPI_Comm_rank(MPI_COMM_WORLD,&id);
  3. MPI_Comm_size(MPI_COMM_WORLD,&length);
  4. MPI_Status status;
  5.  
  6. time=-MPI_Wtime();
  7. p=length-1;
  8. size=p;
  9. range=1.0/(double)size;
  10.  
  11. while(size<100000000000)
  12. {
  13.         if(id==0)
  14.         {
  15.                 int yes[p];
  16.                 for(int i=1;i<length;i++)
  17.                         MPI_Send(&start,1,MPI_DOUBLE,i,0,MPI_COMM_WORLD);
  18.                 for(int i=0;i<p;i++)
  19.                         MPI_Recv(&yes[i],1,MPI_INT,i+1,0,MPI_COMM_WORLD,&status);
  20.                 for(int i=0;i<p;i++)
  21.                 {
  22.                         if(yes[i]==1)
  23.                         {
  24.                                 start+=i*range;
  25.                                 break;
  26.                         }
  27.         }
  28. //printf("start = %1.12f\n",start);
  29. }
  30. else
  31. {
  32.         double bound1;
  33.         double bound2;
  34.         double begin;
  35.         int right;
  36.         MPI_Recv(&begin,1,MPI_DOUBLE,0,0,MPI_COMM_WORLD,&status);
  37.         bound1=begin+(id-1)*range;
  38.         bound2=bound1+range;
  39.         right=find(f(bound1),f(bound2));
  40.         MPI_Send(&right,1,MPI_INT,0,0,MPI_COMM_WORLD);
  41. }
  42. size*=p;
  43. range=1.0/(double)size;