Guest User

Untitled

a guest
Feb 16th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | None | 0 0
  1. <% Simulation.cpp>
  2.  
  3. #include"Simulation.h"
  4.  
  5. Simulation::Simulation() {}
  6. Simulation::~Simulation() {}
  7.  
  8. void Simulation::setParticles( double *x, double *y, double *z, int numberOfParticles )
  9. {
  10.   this->x = x;
  11.   this->y = y;
  12.   this->z = z;
  13.   this->numberOfParticles = numberOfParticles;
  14. }
  15.  
  16. double Simulation::getAvgMinDistance( void )
  17. {
  18.   return 0.0;
  19. }
  20.  
  21.  
  22. void Simulation::remove( int numberOfPairsToRemove )
  23. {
  24.   int myid, numproc;
  25.   MPI_Comm_rank(MPI_COMM_WORLD, &myid);
  26.   MPI_Comm_size(MPI_COMM_WORLD, &numproc);
  27.  
  28.   MPI_Bcast(numberOfParticles, 1, MPI_INT, 0, MPI_COMM_WORLD);
  29.   MPI_Bcast(x, numberOfParticles, MPI_DOUBLE, 0, MPI_COMM_WORLD);
  30.   MPI_Bcast(y, numberOfParticles, MPI_DOUBLE, 0, MPI_COMM_WORLD);
  31.   MPI_Bcast(z, numberOfParticles, MPI_DOUBLE, 0, MPI_COMM_WORLD);
  32.  
  33.   double local_min_dist=1000.0;
  34.   double global_min_dist=1000.0;
  35.   double min_dist;
  36.   int A, B;
  37.  
  38.   if(numberOfPairsToRemove)
  39.   {
  40.     //for
  41.      // for
  42.       {
  43.     min_dist = Helper::getDistance(x,y,z,i,j);
  44.    
  45.     if(min_dist < local_min_dist)
  46.     {
  47.      A=i;
  48.      B=j;
  49.      local_min_dist = min_dist;
  50.     }
  51.    
  52.       }
  53.  
  54.     MPI_Reduce(&local_min_dist, &global_min_dist, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD);
  55.     {//remove
  56.      
  57.     }
  58.    
  59.     --numberOfPairsToRemove;
  60.     --numberOfParticles;
  61.   }
  62. }
  63.  
  64. void Simulation::calcAvgMinDistance( void ) {
  65.  
  66.   int myid, numproc;
  67.   MPI_Comm_rank(MPI_COMM_WORLD, &myid);
  68.   MPI_Comm_size(MPI_COMM_WORLD, &numproc);
  69.  
  70.   MPI_Bcast(numberOfParticles, 1, MPI_INT, 0, MPI_COMM_WORLD);
  71.   MPI_Bcast(x, numberOfParticles, MPI_DOUBLE, 0, MPI_COMM_WORLD);
  72.   MPI_Bcast(y, numberOfParticles, MPI_DOUBLE, 0, MPI_COMM_WORLD);
  73.   MPI_Bcast(z, numberOfParticles, MPI_DOUBLE, 0, MPI_COMM_WORLD);
  74.  
  75.   double local_min_dist=1000.0;
  76.   double global_min_dist=1000.0;
  77.   double avg_min_dist, min_dist;
  78.  
  79.  
  80.   //for
  81.     //for
  82.       {
  83.     min_dist = Helper::getDistance(x,y,z,i,j);
  84.    
  85.     if(min_dist < local_min_dist)
  86.     {
  87.      local_min_dist = min_dist;
  88.     }
  89.    
  90.       }
  91.  
  92.     MPI_Reduce(&local_min_dist, &avg_min_dist, MPI_DOUBLE, MPI_AVG, 0, MPI_COMM_WORLD);
  93.  
  94. }
Add Comment
Please, Sign In to add comment