| 1 | /*
 | 
|---|
| 2 |  * MPQCCommandFragmentController.hpp
 | 
|---|
| 3 |  *
 | 
|---|
| 4 |  *  Created on: Apr 14, 2014
 | 
|---|
| 5 |  *      Author: heber
 | 
|---|
| 6 |  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | #ifndef MPQCCOMMANDFRAGMENTCONTROLLER_HPP_
 | 
|---|
| 9 | #define MPQCCOMMANDFRAGMENTCONTROLLER_HPP_
 | 
|---|
| 10 | 
 | 
|---|
| 11 | 
 | 
|---|
| 12 | // include config.h
 | 
|---|
| 13 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 14 | #include <config.h>
 | 
|---|
| 15 | #endif
 | 
|---|
| 16 | 
 | 
|---|
| 17 | #include <boost/filesystem/path.hpp>
 | 
|---|
| 18 | 
 | 
|---|
| 19 | #include <list>
 | 
|---|
| 20 | #include <map>
 | 
|---|
| 21 | #include <string>
 | 
|---|
| 22 | #include <vector>
 | 
|---|
| 23 | 
 | 
|---|
| 24 | #include "Fragmentation/Summation/Containers/MPQCData.hpp"
 | 
|---|
| 25 | #include "Fragmentation/Automation/ResultContainer.hpp"
 | 
|---|
| 26 | 
 | 
|---|
| 27 | /** This class mimics the interface of SpecificFragmentController derived from
 | 
|---|
| 28 |  * JobMarket's FragmentController but without using JobMarket.
 | 
|---|
| 29 |  *
 | 
|---|
| 30 |  * This is for calculating fragments via MPQCCommandJobs when JobMarket is not
 | 
|---|
| 31 |  * available.
 | 
|---|
| 32 |  */
 | 
|---|
| 33 | class MPQCCommandFragmentController
 | 
|---|
| 34 | {
 | 
|---|
| 35 | public:
 | 
|---|
| 36 |   MPQCCommandFragmentController() :
 | 
|---|
| 37 |           exitflag(0)
 | 
|---|
| 38 |   {}
 | 
|---|
| 39 |   ~MPQCCommandFragmentController()
 | 
|---|
| 40 |   {}
 | 
|---|
| 41 | 
 | 
|---|
| 42 |   /** Command Controller to fill its hold of jobs from FragmentJobQueue.
 | 
|---|
| 43 |    *
 | 
|---|
| 44 |    * \param _DoSampleDensity whether to actually sample the resulting electronic density
 | 
|---|
| 45 |    * \param _DoValenceOnly whether to sample just the valence or the total elctron and nuclei density
 | 
|---|
| 46 |    * \return true - jobs obtained, false - queue empty
 | 
|---|
| 47 |    */
 | 
|---|
| 48 |   bool addJobsFromQueue(
 | 
|---|
| 49 |       const MPQCData::DoLongrange_t _DoLongrange,
 | 
|---|
| 50 |       const MPQCData::DoValenceOnly_t _DoValenceOnly
 | 
|---|
| 51 |       );
 | 
|---|
| 52 | 
 | 
|---|
| 53 |   /** Mimicks waitforResults but actually does nothing.
 | 
|---|
| 54 |    *
 | 
|---|
| 55 |    */
 | 
|---|
| 56 |   void waitforResults(const size_t NoExpectedResults)
 | 
|---|
| 57 |   { return; }
 | 
|---|
| 58 | 
 | 
|---|
| 59 |   /** Get results map of calculated jobs.
 | 
|---|
| 60 |    *
 | 
|---|
| 61 |    * \param fragmentData contains map of results on output
 | 
|---|
| 62 |    */
 | 
|---|
| 63 |   void getResults(std::map<JobId_t, MPQCData> &fragmentData) {
 | 
|---|
| 64 |     fragmentData.insert(results.IdData.begin(), results.IdData.end());
 | 
|---|
| 65 |     results.clear();
 | 
|---|
| 66 |   }
 | 
|---|
| 67 | 
 | 
|---|
| 68 |   /** Runs the service.
 | 
|---|
| 69 |    *
 | 
|---|
| 70 |    * Here, we finalize each job's id and push them to the server.
 | 
|---|
| 71 |    */
 | 
|---|
| 72 |   void run();
 | 
|---|
| 73 | 
 | 
|---|
| 74 |   /** Mimicks a (unlimited) pool of requested ids that are served by this function.
 | 
|---|
| 75 |    *
 | 
|---|
| 76 |    * \return next unique job id to use
 | 
|---|
| 77 |    */
 | 
|---|
| 78 |   unsigned int getAvailableId()
 | 
|---|
| 79 |   {
 | 
|---|
| 80 |           return nextid++;
 | 
|---|
| 81 |   }
 | 
|---|
| 82 | 
 | 
|---|
| 83 |   /** Getter for exitflag.
 | 
|---|
| 84 |    *
 | 
|---|
| 85 |    * \return exitflag
 | 
|---|
| 86 |    */
 | 
|---|
| 87 |   int getExitflag() const
 | 
|---|
| 88 |   { return exitflag; }
 | 
|---|
| 89 | 
 | 
|---|
| 90 | private:
 | 
|---|
| 91 |   //!> static member variable to count individual job ids
 | 
|---|
| 92 |   static unsigned int nextid;
 | 
|---|
| 93 | 
 | 
|---|
| 94 |   //!> overall exit flag of jobs
 | 
|---|
| 95 |   int exitflag;
 | 
|---|
| 96 | 
 | 
|---|
| 97 |   //!> queue with all jobs to calculate serially
 | 
|---|
| 98 |   std::list<MPQCCommandJob *> queue;
 | 
|---|
| 99 | 
 | 
|---|
| 100 |   //!> type-specific result container
 | 
|---|
| 101 |   ResultContainer<MPQCData> results;
 | 
|---|
| 102 | };
 | 
|---|
| 103 | 
 | 
|---|
| 104 | 
 | 
|---|
| 105 | #endif /* MPQCCOMMANDFRAGMENTCONTROLLER_HPP_ */
 | 
|---|