Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. void ParallelPulseShapingOptimizerChirp::sendParentsToSlaves(Population &parents) {
  2. const int tag = 0;
  3. //Send parents to children
  4.  
  5. std::vector<double> parentsSend, parentsReceive;
  6.  
  7. if (isMaster()) {
  8. std::cout << "Master " << rank << " sending parents to slaves";
  9. parentsSend.reserve(parents.size() * ParamsOptimizationPulseShapingChirp::getNumParameters());
  10.  
  11. for(unsigned long j = 0; parents.size(); j++) {
  12. Ps_Individual ind = std::static_pointer_cast<ParamsOptimizationPulseShapingChirp>(parents.at(j));
  13. auto mat = ind->pulseParameters.data();
  14. //Note that insert() resizes the vector accordingly, so it's important we called reserve() instead of resize() above!
  15. parentsSend.insert(parentsSend.end(), &mat[0], &mat[ParamsOptimizationPulseShapingChirp::getNumParameters()]);
  16. }
  17.  
  18. std::cout << "sending parents ";
  19. for(double d : parentsSend)
  20. std::cout << d << " ";
  21. std::cout << " to all slaves." << std::endl;
  22. } else {
  23. parentsReceive.resize(parents.size() * ParamsOptimizationPulseShapingChirp::getNumParameters());
  24. }
  25.  
  26. MPI_Bcast(parentsSend.data(), parentsSend.size(), MPI_DOUBLE, 0, masterSlaveComm);
  27.  
  28. MPI_Recv(parentsReceive.data(), parentsReceive.size(), MPI_DOUBLE, getMasterIndex(), tag, comm, MPI_STATUS_IGNORE);
  29. std::cout << "Hello, I am the slave " << getSlaveIndex() << " of master rank " << getMasterIndex() << " and my rank is " << rank;
  30. std::cout << " - I got ";
  31. for(double d : parentsReceive)
  32. std::cout << d << " ";
  33. std::cout << std::endl;
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement