Ejemplo n.º 1
0
ReturnType SendCouplingMDCommand::executeTransfer ()
{
	SteereoStream resultStream;
	CouplingInformationType* couplingInfo = (CouplingInformationType*) this->getData(0);
	Simulation* theSim = (Simulation*) this->getData(1);
	//ParticleContainer* moleculeContainer = theSim->getMolecules();

	/*int direction = borderToLook / 2;
	int otherdir1 = (direction + 1) % 3;
	int otherdir2 = (direction + 2) % 3;
	resultStream << moleculeContainer->getBoundingBoxMax(direction);
	resultStream << moleculeContainer->getBoundingBoxMax(otherdir1) << moleculeContainer->getBoundingBoxMax(otherdir2);
	logger->debug() << "I will now execute the transfer of the SendCouplingMDCommand" << std::endl;
	logger->debug() << "borderToLook is " << borderToLook << std::endl;*/
	for (int i = 0; i < couplingInfo->numberOfBoundaries; i++)
	{
		logger->debug() << "For boundary " << i << " I will transfer " << transferContainer[i].size() << " molecules" << std::endl;
		std::vector<Molecule>::iterator molIt = transferContainer[i].begin();
		resultStream.allocateMemory(7 * transferContainer[i].size() * sizeof(double) + sizeof(int));
		resultStream << (int) transferContainer[i].size();
		while (molIt != transferContainer[i].end()) {
			resultStream << (theSim->getDomain()->getComponents())[molIt->componentid()].m();
			resultStream << molIt->r(0) << molIt->r(1) << molIt->r(2) << molIt->v(0) << molIt->v(1) << molIt->v(2);
			molIt++;
		}
		transferContainer[i].clear();
	}
	this->getCommunicator()->sendStream (this->getConnection()->getDataConnection(), resultStream);

	return EXECUTED;
}
Ejemplo n.º 2
0
ReturnType SnapshotCommand::execute ()
{
#ifdef ENABLE_MPI
  int myRank, mySize;
  MPI_Comm_size (MPI_COMM_WORLD, &mySize);
  MPI_Comm_rank (MPI_COMM_WORLD, &myRank);

#else
  logger->debug() << "----------------->Not Parallel snapshot " << std::endl;
  //return EXECUTED;
#endif


  Domain* dom = sim -> getDomain ();
  int numberOfComponents = dom -> getComponents().size();
  SteereoStream daStream;
  SteereoStream outStream;
  int counter = 0;
#ifdef ENABLE_MPI
  int* molNumbers = NULL;
  int* dataSizes = NULL;
  int* displ = NULL;
  int baseDispl = 0;
#endif
  int factor = 3 +  sendForces + sendVelocity + sendV2;
  //int offset = sendV2Max;
  // at the moment the simulation area extents need 6 floats
  int offset = 7;

  ParticleContainer* m_molecules = sim -> getMolecules ();
#ifdef ENABLE_MPI
  int anzahl_mol = sim -> getDomain () -> getglobalNumMolecules ();
#endif
  int local_mol = m_molecules->getNumberOfParticles();
#ifdef ENABLE_MPI
  if (myRank == 0)
  {
    outStream.allocateMemory (factor * anzahl_mol * sizeof(float) + offset * sizeof(float));
  }

  // The stream will only be used for sending. And we will send maximally 3*sizeof(float) * local_mol at once
  daStream.allocateMemory (3 * local_mol * sizeof(float));

#else
  daStream.allocateMemory(factor * local_mol * sizeof(float) + offset * sizeof(float));
#endif

  //send the extents of the domain
  daStream << (float) 0.0 << (float) 0.0 << (float) 0.0;
  daStream << (float) dom->getGlobalLength(0) << (float) dom->getGlobalLength(1) << (float) dom->getGlobalLength(2);
  daStream << (int) numberOfComponents;

#ifdef ENABLE_MPI
  if (myRank == 0)
  {
    molNumbers = new int [mySize];
    dataSizes = new int [mySize];
  }
  MPI_Gather (&local_mol, 1, MPI_INT, molNumbers, 1, MPI_INT, 0, MPI_COMM_WORLD );

  if (myRank == 0)
  {
    displ = new int[mySize];
    displ[0] = 0;
    dataSizes[0] = molNumbers[0] * 3 * sizeof(float);
    for (int i = 1; i < mySize; i++)
    {
      displ[i] = displ[i-1] + dataSizes[i-1];
      dataSizes[i] = molNumbers[i] * 3 * sizeof(float);
      std::cout << "MolNumber ["<< i-1 << "]: " << molNumbers[i-1] << std::endl;
    }
    std::cout << "MolNumber ["<< mySize-1 << "]: " << molNumbers[mySize-1] << std::endl;

  }
#endif

  Molecule* pos = NULL;
  double crit = 0.0;
  for (pos = m_molecules->begin (); pos != m_molecules->end (); pos = m_molecules->next ()) {
    //crit = pos->r(0) * pos->r(0) + pos->r(1) * pos->r(1) + pos->r(2) * pos->r(2);
    daStream << (float) pos->r(0);
    daStream << (float) pos->r(1);
    daStream << (float) pos->r(2);
    counter++;
  }

#ifdef ENABLE_MPI
  MPI_Gatherv (daStream.getStream(), local_mol * 3 * sizeof(float), MPI_CHAR, outStream.getStream (), dataSizes, displ, MPI_CHAR, 0, MPI_COMM_WORLD);

  daStream.resetActPos();
  daStream.resetReadPos();
#endif
  float tempF = 0.0;
  if (sendForces)
  {
    for (pos = m_molecules->begin (); pos != m_molecules->end (); pos = m_molecules->next ())
    {
      tempF = pos->F(0) * pos->F(0) + pos->F(1) * pos->F(1) + pos->F(2) * pos->F(2);
      tempF = sqrt(tempF);
      /*daStream << (float) pos->F(0);
      daStream << (float) pos->F(1);
      daStream << (float) pos->F(2);*/
      daStream << tempF;
    }
#ifdef ENABLE_MPI
    if (myRank == 0)
    {
      baseDispl = displ[mySize-1] + dataSizes[mySize-1];
      displ[0] = baseDispl;
      dataSizes[0] = molNumbers[0] * sizeof(float);
      for (int i = 1; i < mySize; i++)
      {
        displ[i] = displ[i-1] + dataSizes[i-1];
        dataSizes[i] = molNumbers[i] * sizeof(float);
      }
    }
    MPI_Gatherv (daStream.getStream(), local_mol * sizeof(float), MPI_CHAR, outStream.getStream (), dataSizes, displ, MPI_CHAR, 0, MPI_COMM_WORLD);
    daStream.resetActPos();
    daStream.resetReadPos();
#endif
  }
  if (sendVelocity)
  {
    float vel = 0;
    for (pos = m_molecules->begin (); pos != m_molecules->end (); pos = m_molecules->next ())
    {
      vel = sqrt (pos->v2());
      /*daStream << (float) pos->v(0);
      daStream << (float) pos->v(1);
      daStream << (float) pos->v(2);*/
      daStream << vel;
    }
#ifdef ENABLE_MPI
    if (myRank == 0)
    {
      baseDispl = displ[mySize-1] + dataSizes[mySize-1];
      displ[0] = baseDispl;
      dataSizes[0] = molNumbers[0] * sizeof(float);
      for (int i = 1; i < mySize; i++)
      {
        displ[i] = displ[i-1] + dataSizes[i-1];
        dataSizes[i] = molNumbers[i] * sizeof(float);
      }
    }
    MPI_Gatherv (daStream.getStream(), local_mol * sizeof(float), MPI_CHAR, outStream.getStream(), dataSizes, displ, MPI_CHAR, 0, MPI_COMM_WORLD);
    daStream.resetActPos();
    daStream.resetReadPos();
#endif
  }
  float v2max = 0;
  if (sendV2)
  {
    float v2 = 0;
    for (pos = m_molecules->begin (); pos != m_molecules->end (); pos = m_molecules->next ())
    {
      v2 = pos->v2();
      v2max = v2 > v2max ? v2 : v2max;
      daStream << v2;

    }
#ifdef ENABLE_MPI
    if (myRank == 0)
    {
      baseDispl = displ[mySize-1] + dataSizes[mySize-1];
      displ[0] = baseDispl;
      std::cout << "0: " << displ[0] << std::endl;
      dataSizes[0] = molNumbers[0] * sizeof(float);
      std::cout << "datasize[0]: " << dataSizes[0] << std::endl;
      for (int i = 1; i < mySize; i++)
      {
        displ[i] = displ[i-1] + dataSizes[i-1];
        dataSizes[i] = molNumbers[i] * sizeof(float);
        std::cout << "i: " << displ[i] << std::endl;
      }
    }
    MPI_Gatherv (daStream.getStream(), local_mol * sizeof(float), MPI_CHAR, outStream.getStream(), dataSizes, displ, MPI_CHAR, 0, MPI_COMM_WORLD);
#endif
    /*if (sendV2Max)
    {
      daStream << v2max;
    }*/
  }
#ifdef ENABLE_MPI
  if (myRank == 0)
  {
 //   std::cout << "snapshotCommand: assembled the data to be sent in a stream: " << outStream.getStreamSize() <<  " "<< counter <<std::endl;
    this->getCommunicator()->sendStream (this->getConnection()->getDataConnection(), outStream);
   // std::cout << "snapshotCommand: sent the stream" << std::endl;
  }
#else
 // std::cout << "snapshotCommand: assembled the data to be sent in a stream: " << daStream.getStreamSize() <<  " "<< counter <<std::endl;
  this->getCommunicator()->sendStream (this->getConnection()->getDataConnection(), daStream);
 // std::cout << "snapshotCommand: sent the stream" << std::endl;
#endif

  if (stepInterval > 0)
  {
    return REPETITION_REQUESTED;
  }
  else
  {
    return EXECUTED;
  }


}