Changeset 78ad7d for src/Fragmentation


Ignore:
Timestamp:
Jun 22, 2012, 3:21:25 PM (13 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
f0834d
Parents:
142ff5
git-author:
Frederik Heber <heber@…> (02/06/12 08:43:07)
git-committer:
Frederik Heber <heber@…> (06/22/12 15:21:25)
Message:

FragmentJob is now passed inside boost::shared_ptr.

  • FragmentJob is to become just an abstract interface to a variety of jobs and we cannot instantiate this interface. We can only pass it around via ptrs. Therefore, we need this switch to shared_ptrs.
  • We now require CodePatterns 1.2.2 due to boost/archive/iserializer.hpp fix.
Location:
src/Fragmentation/Automation
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Automation/Controller/Commands/ReceiveJobsOperation.cpp

    r142ff5 r78ad7d  
    114114 * \param _jobs jobs to add
    115115 */
    116 void ReceiveJobsOperation::addJobs(const std::vector<FragmentJob> &_jobs)
     116void ReceiveJobsOperation::addJobs(const std::vector<FragmentJob::ptr> &_jobs)
    117117{
    118118  jobs.reserve(jobs.size()+_jobs.size());
    119   BOOST_FOREACH(FragmentJob job, _jobs) {
     119  BOOST_FOREACH(FragmentJob::ptr job, _jobs) {
    120120    jobs.push_back(job);
    121121  }
  • src/Fragmentation/Automation/Controller/Commands/ReceiveJobsOperation.hpp

    r142ff5 r78ad7d  
    4040
    4141  /// Setter for jobs
    42   void addJobs(const std::vector<FragmentJob> &jobs);
     42  void addJobs(const std::vector<FragmentJob::ptr> &jobs);
    4343
    4444  /** Getter for number of jobs present in the queue.
     
    5555
    5656  /// bunch of jobs
    57   std::vector<FragmentJob> jobs;
     57  std::vector<FragmentJob::ptr> jobs;
    5858};
    5959
  • src/Fragmentation/Automation/FragmentJob.hpp

    r142ff5 r78ad7d  
    1616#include <string>
    1717
    18 #include "boost/serialization/array.hpp"
     18#include "boost/shared_ptr.hpp"
     19#include "boost/serialization/access.hpp"
     20#include "boost/serialization/shared_ptr.hpp"
    1921
    2022#include "FragmentResult.hpp"
     
    3941  friend class FragmentJobTest;
    4042public:
     43  typedef boost::shared_ptr<FragmentJob> ptr;
     44
    4145  FragmentJob();
    4246  FragmentJob(const std::string &_command, const std::string &_outputfile, const JobId_t _JobId);
  • src/Fragmentation/Automation/FragmentQueue.cpp

    r142ff5 r78ad7d  
    3838 */
    3939FragmentQueue::~FragmentQueue()
    40 {}
     40{
     41  jobs.clear();
     42  results.clear();
     43}
    4144
    4245/** Checks whether there are jobs in the queue at all.
     
    5457 * \param job job to enter into queue
    5558 */
    56 void FragmentQueue::pushJob(FragmentJob &job)
    57 {
    58   ASSERT(job.getId() != JobId::IllegalJob,
     59void FragmentQueue::pushJob(FragmentJob::ptr job)
     60{
     61  ASSERT(job->getId() != JobId::IllegalJob,
    5962      "FragmentQueue::pushJob() - job to push has IllegalJob id.");
    60   ASSERT(!results.count(job.getId()),
    61       "FragmentQueue::pushJob() - job id "+toString(job.getId())+" has already been used.");
    62   results.insert( std::make_pair(job.getId(), NoResult));
     63  ASSERT(!results.count(job->getId()),
     64      "FragmentQueue::pushJob() - job id "+toString(job->getId())+" has already been used.");
     65  results.insert( std::make_pair(job->getId(), NoResult));
    6366  jobs.push_back(job);
    6467}
     
    7275 * \param _jobs jobs to enter into queue
    7376 */
    74 void FragmentQueue::pushJobs(std::vector<FragmentJob> &_jobs)
    75 {
    76   for (std::vector<FragmentJob>::iterator iter = _jobs.begin();
     77void FragmentQueue::pushJobs(std::vector<FragmentJob::ptr> &_jobs)
     78{
     79  for (std::vector<FragmentJob::ptr>::iterator iter = _jobs.begin();
    7780      iter != _jobs.end(); ++iter)
    7881    pushJob(*iter);
     
    8588 * \return job topmost job from queue
    8689 */
    87 FragmentJob FragmentQueue::popJob()
     90FragmentJob::ptr FragmentQueue::popJob()
    8891{
    8992  ASSERT(jobs.size(),
    9093      "FragmentQueue::popJob() - there are no jobs on the queue.");
    91   FragmentJob job = jobs.front();
    92   ResultMap::iterator iter = results.find(job.getId());
     94  FragmentJob::ptr job = jobs.front();
     95  ResultMap::iterator iter = results.find(job->getId());
    9396  ASSERT(iter != results.end(),
    94       "FragmentQueue::popJob() - for job "+toString(job.getId())+" no result place has been stored.");
     97      "FragmentQueue::popJob() - for job "+toString(job->getId())+" no result place has been stored.");
    9598  iter->second = NoResultQueued;
    9699  jobs.pop_front();
  • src/Fragmentation/Automation/FragmentQueue.hpp

    r142ff5 r78ad7d  
    3636
    3737  // entering jobs into queue
    38   void pushJob(FragmentJob &job);
    39   void pushJobs(std::vector<FragmentJob> &_jobs);
    40   FragmentJob popJob();
     38  void pushJob(FragmentJob::ptr job);
     39  void pushJobs(std::vector<FragmentJob::ptr> &_jobs);
     40  FragmentJob::ptr popJob();
    4141  bool isJobPresent() const;
    4242
     
    5959  static FragmentResult ResultDelivered;
    6060
    61   typedef std::deque<FragmentJob> JobQueue;
     61  typedef std::deque<FragmentJob::ptr> JobQueue;
    6262  typedef std::map<JobId_t, FragmentResult> ResultMap;
    6363
  • src/Fragmentation/Automation/FragmentScheduler.cpp

    r142ff5 r78ad7d  
    3939#include "FragmentScheduler.hpp"
    4040
    41 FragmentJob FragmentScheduler::NoJob(std::string("/bin/false"), std::string("NoJob"), JobId::NoJob);
     41FragmentJob::ptr FragmentScheduler::NoJob(new FragmentJob(std::string("/bin/false"), std::string("NoJob"), JobId::NoJob));
    4242
    4343/** Constructor of class FragmentScheduler.
     
    115115    if (JobsQueue.isJobPresent()) {
    116116      // pop a job and send it to the client.
    117       FragmentJob job(JobsQueue.popJob());
     117      FragmentJob::ptr job(JobsQueue.popJob());
    118118      // The connection::async_write() function will automatically
    119119      // serialize the data structure for us.
    120       LOG(1, "INFO: Sending job #" << job.getId() << ".");
     120      LOG(1, "INFO: Sending job #" << job->getId() << ".");
    121121      conn->async_write(job,
    122122        boost::bind(&FragmentScheduler::handle_SendJobtoWorker, this,
  • src/Fragmentation/Automation/FragmentScheduler.hpp

    r142ff5 r78ad7d  
    9494
    9595  /// bunch of jobs received from controller before placed in JobsQueue
    96   std::vector<FragmentJob> jobs;
     96  std::vector<FragmentJob::ptr> jobs;
    9797
    9898  /// number of jobs that are calculated, required for returning status
     
    106106
    107107  // static entity to indicate to clients that the queue is empty.
    108   static FragmentJob NoJob;
     108  static FragmentJob::ptr NoJob;
    109109
    110110  // Exit flag on program exit
  • src/Fragmentation/Automation/FragmentWorker.cpp

    r142ff5 r78ad7d  
    9999  if (!e)
    100100  {
    101     LOG(1, "INFO: Received job #" << job.getId() << ".");
    102     if (job.getId() != JobId::NoJob) {
     101    LOG(1, "INFO: Received job #" << job->getId() << ".");
     102    if (job->getId() != JobId::NoJob) {
    103103      // Print out the data that was received.
    104       std::cout << "Job output: " << job.outputfile << "\n";
    105       std::cout << "Job id: " << job.getId() << "\n";
     104      std::cout << "Job output: " << job->outputfile << "\n";
     105      std::cout << "Job id: " << job->getId() << "\n";
    106106
    107107      // do something .. right now: wait
    108       LOG(1, "INFO: Calculating job #" << job.getId() << " ...");
    109       FragmentResult result(job.Work());
     108      LOG(1, "INFO: Calculating job #" << job->getId() << " ...");
     109      FragmentResult result(job->Work());
    110110
    111111      // write the result to the server
    112       LOG(1, "INFO: Sending result for job #" << job.getId() << " ...");
     112      LOG(1, "INFO: Sending result for job #" << job->getId() << " ...");
    113113      connection_.async_write(result,
    114114        boost::bind(&FragmentWorker::handle_SendResult, this,
     
    141141  Info info(__FUNCTION__);
    142142  // Nothing to do.
    143   LOG(1, "INFO: Job #" << job.getId() << " calculated and sent.");
     143  LOG(1, "INFO: Job #" << job->getId() << " calculated and sent.");
    144144  // erase job
    145   job = FragmentJob();
     145  job = FragmentJob::ptr(new FragmentJob());
    146146}
    147147
  • src/Fragmentation/Automation/FragmentWorker.hpp

    r142ff5 r78ad7d  
    6262
    6363  /// The data received from the server.
    64   FragmentJob job;
     64  FragmentJob::ptr job;
    6565
    6666  /// The result created to be sent to the server.
  • src/Fragmentation/Automation/controller.cpp

    r142ff5 r78ad7d  
    5050};
    5151
    52 void createjobs(std::vector<FragmentJob> &jobs)
    53 {
    54   FragmentJob testJob(std::string("cat"), std::string("Nothing"), 1);
    55   FragmentJob othertestJob(std::string("cat"), std::string("Nothing"), 2);
     52void createjobs(std::vector<FragmentJob::ptr> &jobs)
     53{
     54  FragmentJob::ptr testJob( new FragmentJob( std::string("cat"), std::string("Nothing"), 1) );
     55  FragmentJob::ptr othertestJob( new FragmentJob( std::string("cat"), std::string("Nothing"), 2) );
    5656  jobs.push_back(testJob);
    5757  jobs.push_back(othertestJob);
    5858}
    5959
    60 void addjobs(FragmentController &controller, std::vector<FragmentJob> &jobs)
     60void addjobs(FragmentController &controller, std::vector<FragmentJob::ptr> &jobs)
    6161{
    6262  ReceiveJobsOperation *recjobs = static_cast<ReceiveJobsOperation *>(
     
    156156      case SendJobsIndex:
    157157      {
    158         std::vector<FragmentJob> jobs;
     158        std::vector<FragmentJob::ptr> jobs;
    159159        createjobs(jobs);
    160160        addjobs(controller, jobs);
  • src/Fragmentation/Automation/unittests/FragmentJobUnitTest.cpp

    r142ff5 r78ad7d  
    6262void FragmentJobTest::equalityTest()
    6363{
    64   FragmentJob testJob(command, outputfile, 1);
    65   FragmentJob sameIdJob(command, outputfile, 1);
    66   FragmentJob otherIdJob(command, outputfile, 2);
    67   FragmentJob copiedJob(testJob);
    68   FragmentJob copiedchangedJob(testJob);
    69   copiedchangedJob.setId(3);
     64  FragmentJob::ptr testJob(new FragmentJob(command, outputfile, 1));
     65  FragmentJob::ptr sameIdJob(new FragmentJob(command, outputfile, 1));
     66  FragmentJob::ptr otherIdJob(new FragmentJob(command, outputfile, 2));
     67  FragmentJob::ptr copiedJob(new FragmentJob(*testJob));
     68  FragmentJob::ptr copiedchangedJob(new FragmentJob(*testJob));
     69  copiedchangedJob->setId(3);
    7070
    71   CPPUNIT_ASSERT( testJob == sameIdJob );
    72   CPPUNIT_ASSERT( testJob != otherIdJob );
    73   CPPUNIT_ASSERT( testJob == copiedJob );
    74   CPPUNIT_ASSERT( testJob != copiedchangedJob );
     71  CPPUNIT_ASSERT( *testJob == *sameIdJob );
     72  CPPUNIT_ASSERT( *testJob != *otherIdJob );
     73  CPPUNIT_ASSERT( *testJob == *copiedJob );
     74  CPPUNIT_ASSERT( *testJob != *copiedchangedJob );
    7575}
    7676
     
    7979void FragmentJobTest::WorkTest()
    8080{
    81   FragmentJob testJob(command, outputfile, 1);
    82   FragmentJob othertestJob(command, outputfile, 2);
     81  FragmentJob::ptr testJob(new FragmentJob(command, outputfile, 1));
     82  FragmentJob::ptr othertestJob(new FragmentJob(command, outputfile, 2));
    8383
    84   FragmentResult testResult(testJob.Work());
    85   FragmentResult othertestResult(othertestJob.Work());
     84  FragmentResult testResult(testJob->Work());
     85  FragmentResult othertestResult(othertestJob->Work());
    8686
    8787  CPPUNIT_ASSERT_EQUAL( (JobId_t)1, testResult.getId() );
     
    9393void FragmentJobTest::serializationTest()
    9494{
    95   FragmentJob testJob(command, outputfile, 1);
     95  FragmentJob::ptr testJob(new FragmentJob(command, outputfile, 1));
    9696  // write element to stream
    9797  std::stringstream stream;
     
    104104  boost::archive::text_iarchive ia(stream);
    105105  // read class state from archive
    106   FragmentJob otherJob;
     106  FragmentJob::ptr otherJob;
    107107
    108108  ia >> otherJob;
    109109
    110   CPPUNIT_ASSERT (testJob == otherJob);
     110  CPPUNIT_ASSERT (*testJob == *otherJob);
    111111}
    112112
  • src/Fragmentation/Automation/unittests/FragmentQueueUnitTest.cpp

    r142ff5 r78ad7d  
    5858void FragmentQueueTest::JobTest()
    5959{
    60   FragmentJob testJob;
     60  FragmentJob::ptr testJob(new FragmentJob);
    6161  /// check for illegal id
    6262#ifndef NDEBUG
     
    6565#endif
    6666  // set to valid id
    67   testJob.setId(1);
    68   testJob.outputfile = std::string("do something");
     67  testJob->setId(1);
     68  testJob->outputfile = std::string("do something");
    6969
    7070  CPPUNIT_ASSERT_EQUAL(false, queue->isJobPresent() );
     
    9494  CPPUNIT_ASSERT_EQUAL((size_t)1, queue->results.size());
    9595
    96   FragmentJob poppedJob;
     96  FragmentJob::ptr poppedJob;
    9797#ifndef NDEBUG
    9898  CPPUNIT_ASSERT_NO_THROW( poppedJob = queue->popJob() );
     
    122122{
    123123  // prepare some jobs
    124   FragmentJob testJob;
    125   testJob.setId((JobId_t)1);
    126   testJob.outputfile = std::string("do something");
    127   FragmentJob anothertestJob;
    128   anothertestJob.setId((JobId_t)2);
    129   anothertestJob.outputfile = std::string("do something else");
     124  FragmentJob::ptr testJob(new FragmentJob);
     125  testJob->setId((JobId_t)1);
     126  testJob->outputfile = std::string("do something");
     127  FragmentJob::ptr anothertestJob(new FragmentJob);
     128  anothertestJob->setId((JobId_t)2);
     129  anothertestJob->outputfile = std::string("do something else");
    130130
    131131  // prepare a vector of them
    132   std::vector<FragmentJob> testjobs;
     132  std::vector<FragmentJob::ptr> testjobs;
    133133  testjobs.push_back(testJob);
    134134  testjobs.push_back(anothertestJob);
    135135
    136136  // prepare another vector of them
    137   std::vector<FragmentJob> sametestjobs;
     137  std::vector<FragmentJob::ptr> sametestjobs;
    138138  sametestjobs.push_back(testJob);
    139139  sametestjobs.push_back(anothertestJob);
     
    173173{
    174174  // prepare a job
    175   FragmentJob testJob;
    176   testJob.setId(1);
    177   testJob.outputfile = std::string("do something");
     175  FragmentJob::ptr testJob(new FragmentJob);
     176  testJob->setId(1);
     177  testJob->outputfile = std::string("do something");
    178178#ifndef NDEBUG
    179179  CPPUNIT_ASSERT_NO_THROW( queue->pushJob(testJob) );
     
    240240{
    241241  // prepare a job
    242   FragmentJob testJob;
    243   testJob.setId(1);
    244   testJob.outputfile = std::string("do something");
    245   FragmentJob anothertestJob;
    246   anothertestJob.setId(2);
    247   anothertestJob.outputfile = std::string("do something else");
     242  FragmentJob::ptr testJob( new FragmentJob );
     243  testJob->setId(1);
     244  testJob->outputfile = std::string("do something");
     245  FragmentJob::ptr anothertestJob( new FragmentJob );
     246  anothertestJob->setId(2);
     247  anothertestJob->outputfile = std::string("do something else");
    248248
    249249#ifndef NDEBUG
Note: See TracChangeset for help on using the changeset viewer.