| 1 | /*
|
|---|
| 2 | * Project: MoleCuilder
|
|---|
| 3 | * Description: creates and alters molecular systems
|
|---|
| 4 | * Copyright (C) 2011 University of Bonn. All rights reserved.
|
|---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | /*
|
|---|
| 9 | * \file controller.cpp
|
|---|
| 10 | *
|
|---|
| 11 | * This file strongly follows the Serialization example from the boost::asio
|
|---|
| 12 | * library (see client.cpp)
|
|---|
| 13 | *
|
|---|
| 14 | * Created on: Nov 27, 2011
|
|---|
| 15 | * Author: heber
|
|---|
| 16 | */
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 | // include config.h
|
|---|
| 20 | #ifdef HAVE_CONFIG_H
|
|---|
| 21 | #include <config.h>
|
|---|
| 22 | #endif
|
|---|
| 23 |
|
|---|
| 24 | // boost asio needs specific operator new
|
|---|
| 25 | #include <boost/asio.hpp>
|
|---|
| 26 |
|
|---|
| 27 | #include "CodePatterns/MemDebug.hpp"
|
|---|
| 28 |
|
|---|
| 29 | #include <boost/archive/text_oarchive.hpp>
|
|---|
| 30 | #include <boost/archive/text_iarchive.hpp>
|
|---|
| 31 | #include <fstream>
|
|---|
| 32 | #include <iostream>
|
|---|
| 33 | #include <map>
|
|---|
| 34 | #include <sstream>
|
|---|
| 35 | #include <streambuf>
|
|---|
| 36 | #include <vector>
|
|---|
| 37 |
|
|---|
| 38 | #include "atexit.hpp"
|
|---|
| 39 | #include "CodePatterns/Info.hpp"
|
|---|
| 40 | #include "CodePatterns/Log.hpp"
|
|---|
| 41 | #include "Fragmentation/EnergyMatrix.hpp"
|
|---|
| 42 | #include "Fragmentation/ForceMatrix.hpp"
|
|---|
| 43 | #include "Fragmentation/KeySetsContainer.hpp"
|
|---|
| 44 | #include "FragmentController.hpp"
|
|---|
| 45 | #include "Helpers/defs.hpp"
|
|---|
| 46 | #include "Jobs/MPQCCommandJob.hpp"
|
|---|
| 47 | #include "Jobs/MPQCCommandJob_MPQCData.hpp"
|
|---|
| 48 | #include "Jobs/SystemCommandJob.hpp"
|
|---|
| 49 | #include "Results/FragmentResult.hpp"
|
|---|
| 50 |
|
|---|
| 51 | enum CommandIndices {
|
|---|
| 52 | UnknownCommandIndex = 0,
|
|---|
| 53 | AddJobsIndex = 1,
|
|---|
| 54 | CreateJobsIndex = 2,
|
|---|
| 55 | CheckResultsIndex = 3,
|
|---|
| 56 | ReceiveResultsIndex = 4,
|
|---|
| 57 | ReceiveMPQCIndex = 5,
|
|---|
| 58 | RemoveAllIndex = 6,
|
|---|
| 59 | ShutdownIndex = 7,
|
|---|
| 60 | };
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 | /** Creates a SystemCommandJob out of give \a command with \a argument.
|
|---|
| 64 | *
|
|---|
| 65 | * @param jobs created job is added to this vector
|
|---|
| 66 | * @param command command to execute for SystemCommandJob
|
|---|
| 67 | * @param argument argument for command to execute
|
|---|
| 68 | * @param nextid id for this job
|
|---|
| 69 | */
|
|---|
| 70 | void createjobs(
|
|---|
| 71 | std::vector<FragmentJob::ptr> &jobs,
|
|---|
| 72 | const std::string &command,
|
|---|
| 73 | const std::string &argument,
|
|---|
| 74 | const JobId_t nextid)
|
|---|
| 75 | {
|
|---|
| 76 |
|
|---|
| 77 | FragmentJob::ptr testJob( new SystemCommandJob(command, argument, nextid) );
|
|---|
| 78 | jobs.push_back(testJob);
|
|---|
| 79 | LOG(1, "INFO: Added one SystemCommandJob.");
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | /** Creates a MPQCCommandJob with argument \a filename.
|
|---|
| 83 | *
|
|---|
| 84 | * @param jobs created job is added to this vector
|
|---|
| 85 | * @param command mpqc command to execute
|
|---|
| 86 | * @param filename filename being argument to job
|
|---|
| 87 | * @param nextid id for this job
|
|---|
| 88 | */
|
|---|
| 89 | void parsejob(
|
|---|
| 90 | std::vector<FragmentJob::ptr> &jobs,
|
|---|
| 91 | const std::string &command,
|
|---|
| 92 | const std::string &filename,
|
|---|
| 93 | const JobId_t nextid)
|
|---|
| 94 | {
|
|---|
| 95 | std::ifstream file;
|
|---|
| 96 | file.open(filename.c_str());
|
|---|
| 97 | ASSERT( file.good(), "parsejob() - file "+filename+" does not exist.");
|
|---|
| 98 | std::string output((std::istreambuf_iterator<char>(file)),
|
|---|
| 99 | std::istreambuf_iterator<char>());
|
|---|
| 100 | FragmentJob::ptr testJob( new MPQCCommandJob(output, nextid, command) );
|
|---|
| 101 | jobs.push_back(testJob);
|
|---|
| 102 | file.close();
|
|---|
| 103 | LOG(1, "INFO: Added MPQCCommandJob from file "+filename+".");
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | /** Print received results.
|
|---|
| 107 | *
|
|---|
| 108 | * @param results received results to print
|
|---|
| 109 | */
|
|---|
| 110 | void printReceivedResults(std::vector<FragmentResult::ptr> &results)
|
|---|
| 111 | {
|
|---|
| 112 | for (std::vector<FragmentResult::ptr>::const_iterator iter = results.begin();
|
|---|
| 113 | iter != results.end(); ++iter)
|
|---|
| 114 | LOG(1, "RESULT: job #"+toString((*iter)->getId())+": "+toString((*iter)->result));
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | /** Print MPQCData from received results.
|
|---|
| 118 | *
|
|---|
| 119 | * @param results received results to extract MPQCData from
|
|---|
| 120 | * @param KeySetFilename filename with keysets to associate forces correctly
|
|---|
| 121 | * @param NoAtoms total number of atoms
|
|---|
| 122 | */
|
|---|
| 123 | bool printReceivedMPQCResults(
|
|---|
| 124 | const std::vector<FragmentResult::ptr> &results,
|
|---|
| 125 | const std::string &KeySetFilename,
|
|---|
| 126 | size_t NoAtoms)
|
|---|
| 127 | {
|
|---|
| 128 | EnergyMatrix Energy;
|
|---|
| 129 | EnergyMatrix EnergyFragments;
|
|---|
| 130 | ForceMatrix Force;
|
|---|
| 131 | ForceMatrix ForceFragments;
|
|---|
| 132 | KeySetsContainer KeySet;
|
|---|
| 133 |
|
|---|
| 134 | // align fragments
|
|---|
| 135 | std::map< JobId_t, size_t > MatrixNrLookup;
|
|---|
| 136 | size_t FragmentCounter = 0;
|
|---|
| 137 | {
|
|---|
| 138 | // bring ids in order ...
|
|---|
| 139 | typedef std::map< JobId_t, FragmentResult::ptr> IdResultMap_t;
|
|---|
| 140 | IdResultMap_t IdResultMap;
|
|---|
| 141 | for (std::vector<FragmentResult::ptr>::const_iterator iter = results.begin();
|
|---|
| 142 | iter != results.end(); ++iter) {
|
|---|
| 143 | #ifndef NDEBUG
|
|---|
| 144 | std::pair< IdResultMap_t::iterator, bool> inserter =
|
|---|
| 145 | #endif
|
|---|
| 146 | IdResultMap.insert( make_pair((*iter)->getId(), *iter) );
|
|---|
| 147 | ASSERT( inserter.second,
|
|---|
| 148 | "printReceivedMPQCResults() - two results have same id "
|
|---|
| 149 | +toString((*iter)->getId())+".");
|
|---|
| 150 | }
|
|---|
| 151 | // ... and fill lookup
|
|---|
| 152 | for(IdResultMap_t::const_iterator iter = IdResultMap.begin();
|
|---|
| 153 | iter != IdResultMap.end(); ++iter)
|
|---|
| 154 | MatrixNrLookup.insert( make_pair(iter->first, FragmentCounter++) );
|
|---|
| 155 | }
|
|---|
| 156 | LOG(1, "INFO: There are " << FragmentCounter << " fragments.");
|
|---|
| 157 |
|
|---|
| 158 | // extract results
|
|---|
| 159 | std::vector<MPQCData> fragmentData(results.size());
|
|---|
| 160 | MPQCData combinedData;
|
|---|
| 161 |
|
|---|
| 162 | LOG(2, "DEBUG: Parsing now through " << results.size() << " results.");
|
|---|
| 163 | for (std::vector<FragmentResult::ptr>::const_iterator iter = results.begin();
|
|---|
| 164 | iter != results.end(); ++iter) {
|
|---|
| 165 | LOG(1, "RESULT: job #"+toString((*iter)->getId())+": "+toString((*iter)->result));
|
|---|
| 166 | MPQCData extractedData;
|
|---|
| 167 | std::stringstream inputstream((*iter)->result);
|
|---|
| 168 | LOG(2, "DEBUG: First 50 characters FragmentResult's string: "+(*iter)->result.substr(0, 50));
|
|---|
| 169 | boost::archive::text_iarchive ia(inputstream);
|
|---|
| 170 | ia >> extractedData;
|
|---|
| 171 | LOG(1, "INFO: extracted data is " << extractedData << ".");
|
|---|
| 172 |
|
|---|
| 173 | // place results into EnergyMatrix ...
|
|---|
| 174 | {
|
|---|
| 175 | MatrixContainer::MatrixArray matrix;
|
|---|
| 176 | matrix.resize(1);
|
|---|
| 177 | matrix[0].resize(1, extractedData.energy);
|
|---|
| 178 | if (!Energy.AddMatrix(
|
|---|
| 179 | std::string("MPQCJob ")+toString((*iter)->getId()),
|
|---|
| 180 | matrix,
|
|---|
| 181 | MatrixNrLookup[(*iter)->getId()])) {
|
|---|
| 182 | ELOG(1, "Adding energy matrix failed.");
|
|---|
| 183 | return false;
|
|---|
| 184 | }
|
|---|
| 185 | }
|
|---|
| 186 | // ... and ForceMatrix (with two empty columns in front)
|
|---|
| 187 | {
|
|---|
| 188 | MatrixContainer::MatrixArray matrix;
|
|---|
| 189 | const size_t rows = extractedData.forces.size();
|
|---|
| 190 | matrix.resize(rows);
|
|---|
| 191 | for (size_t i=0;i<rows;++i) {
|
|---|
| 192 | const size_t columns = 2+extractedData.forces[i].size();
|
|---|
| 193 | matrix[i].resize(columns, 0.);
|
|---|
| 194 | // for (size_t j=0;j<2;++j)
|
|---|
| 195 | // matrix[i][j] = 0.;
|
|---|
| 196 | for (size_t j=2;j<columns;++j)
|
|---|
| 197 | matrix[i][j] = extractedData.forces[i][j-2];
|
|---|
| 198 | }
|
|---|
| 199 | if (!Force.AddMatrix(
|
|---|
| 200 | std::string("MPQCJob ")+toString((*iter)->getId()),
|
|---|
| 201 | matrix,
|
|---|
| 202 | MatrixNrLookup[(*iter)->getId()])) {
|
|---|
| 203 | ELOG(1, "Adding force matrix failed.");
|
|---|
| 204 | return false;
|
|---|
| 205 | }
|
|---|
| 206 | }
|
|---|
| 207 | }
|
|---|
| 208 | // add one more matrix (not required for energy)
|
|---|
| 209 | MatrixContainer::MatrixArray matrix;
|
|---|
| 210 | matrix.resize(1);
|
|---|
| 211 | matrix[0].resize(1, 0.);
|
|---|
| 212 | if (!Energy.AddMatrix(std::string("MPQCJob total"), matrix, FragmentCounter))
|
|---|
| 213 | return false;
|
|---|
| 214 | // but for energy because we need to know total number of atoms
|
|---|
| 215 | matrix.resize(NoAtoms);
|
|---|
| 216 | for (size_t i = 0; i< NoAtoms; ++i)
|
|---|
| 217 | matrix[i].resize(2+NDIM, 0.);
|
|---|
| 218 | if (!Force.AddMatrix(std::string("MPQCJob total"), matrix, FragmentCounter))
|
|---|
| 219 | return false;
|
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 | // combine all found data
|
|---|
| 223 | if (!Energy.InitialiseIndices()) return false;
|
|---|
| 224 |
|
|---|
| 225 | if (!Force.ParseIndices(KeySetFilename.c_str())) return false;
|
|---|
| 226 |
|
|---|
| 227 | if (!KeySet.ParseKeySets(KeySetFilename.c_str(), Force.RowCounter, Force.MatrixCounter)) return false;
|
|---|
| 228 |
|
|---|
| 229 | if (!KeySet.ParseManyBodyTerms()) return false;
|
|---|
| 230 |
|
|---|
| 231 | if (!EnergyFragments.AllocateMatrix(Energy.Header, Energy.MatrixCounter, Energy.RowCounter, Energy.ColumnCounter)) return false;
|
|---|
| 232 | if (!ForceFragments.AllocateMatrix(Force.Header, Force.MatrixCounter, Force.RowCounter, Force.ColumnCounter)) return false;
|
|---|
| 233 |
|
|---|
| 234 | if(!Energy.SetLastMatrix(0., 0)) return false;
|
|---|
| 235 | if(!Force.SetLastMatrix(0., 2)) return false;
|
|---|
| 236 |
|
|---|
| 237 | for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
|
|---|
| 238 | // --------- sum up energy --------------------
|
|---|
| 239 | LOG(1, "INFO: Summing energy of order " << BondOrder+1 << " ...");
|
|---|
| 240 | if (!EnergyFragments.SumSubManyBodyTerms(Energy, KeySet, BondOrder)) return false;
|
|---|
| 241 | if (!Energy.SumSubEnergy(EnergyFragments, NULL, KeySet, BondOrder, 1.)) return false;
|
|---|
| 242 |
|
|---|
| 243 | // --------- sum up Forces --------------------
|
|---|
| 244 | LOG(1, "INFO: Summing forces of order " << BondOrder+1 << " ...");
|
|---|
| 245 | if (!ForceFragments.SumSubManyBodyTerms(Force, KeySet, BondOrder)) return false;
|
|---|
| 246 | if (!Force.SumSubForces(ForceFragments, KeySet, BondOrder, 1.)) return false;
|
|---|
| 247 | }
|
|---|
| 248 |
|
|---|
| 249 | // for debugging print resulting energy and forces
|
|---|
| 250 | LOG(1, "INFO: Resulting energy is " << Energy.Matrix[ FragmentCounter ][0][0]);
|
|---|
| 251 | std::stringstream output;
|
|---|
| 252 | for (int i=0; i< Force.RowCounter[FragmentCounter]; ++i) {
|
|---|
| 253 | for (int j=0; j< Force.ColumnCounter[FragmentCounter]; ++j)
|
|---|
| 254 | output << Force.Matrix[ FragmentCounter ][i][j] << " ";
|
|---|
| 255 | output << "\n";
|
|---|
| 256 | }
|
|---|
| 257 | LOG(1, "INFO: Resulting forces are " << std::endl << output.str());
|
|---|
| 258 |
|
|---|
| 259 | return true;
|
|---|
| 260 | }
|
|---|
| 261 |
|
|---|
| 262 | /** Helper function to get number of atoms somehow.
|
|---|
| 263 | *
|
|---|
| 264 | * Here, we just parse the number of lines in the adjacency file as
|
|---|
| 265 | * it should correspond to the number of atoms, except when some atoms
|
|---|
| 266 | * are not bonded, but then fragmentation makes no sense.
|
|---|
| 267 | *
|
|---|
| 268 | * @param path path to the adjacency file
|
|---|
| 269 | */
|
|---|
| 270 | size_t getNoAtomsFromAdjacencyFile(const std::string &path)
|
|---|
| 271 | {
|
|---|
| 272 | size_t NoAtoms = 0;
|
|---|
| 273 |
|
|---|
| 274 | // parse in special file to get atom count (from line count)
|
|---|
| 275 | std::string filename(path);
|
|---|
| 276 | filename += FRAGMENTPREFIX;
|
|---|
| 277 | filename += ADJACENCYFILE;
|
|---|
| 278 | std::ifstream adjacency(filename.c_str());
|
|---|
| 279 | if (adjacency.fail()) {
|
|---|
| 280 | LOG(0, endl << "getNoAtomsFromAdjacencyFile() - Unable to open " << filename << ", is the directory correct?");
|
|---|
| 281 | return false;
|
|---|
| 282 | }
|
|---|
| 283 | std::string buffer;
|
|---|
| 284 | while (getline(adjacency, buffer))
|
|---|
| 285 | NoAtoms++;
|
|---|
| 286 | LOG(1, "INFO: There are " << NoAtoms << " atoms.");
|
|---|
| 287 |
|
|---|
| 288 | return NoAtoms;
|
|---|
| 289 | }
|
|---|
| 290 |
|
|---|
| 291 |
|
|---|
| 292 | /** Returns a unique index for every command to allow switching over it.
|
|---|
| 293 | *
|
|---|
| 294 | * \param &commandmap map with command strings
|
|---|
| 295 | * \param &cmd command string
|
|---|
| 296 | * \return index from CommandIndices: UnkownCommandIndex - unknown command, else - command index
|
|---|
| 297 | */
|
|---|
| 298 | CommandIndices getCommandIndex(std::map<std::string, CommandIndices> &commandmap, const std::string &cmd)
|
|---|
| 299 | {
|
|---|
| 300 | std::map<std::string, CommandIndices>::const_iterator iter = commandmap.find(cmd);
|
|---|
| 301 | if (iter != commandmap.end())
|
|---|
| 302 | return iter->second;
|
|---|
| 303 | else
|
|---|
| 304 | return UnknownCommandIndex;
|
|---|
| 305 | }
|
|---|
| 306 |
|
|---|
| 307 |
|
|---|
| 308 | int main(int argc, char* argv[])
|
|---|
| 309 | {
|
|---|
| 310 | // from this moment on, we need to be sure to deeinitialize in the correct order
|
|---|
| 311 | // this is handled by the cleanup function
|
|---|
| 312 | atexit(cleanUp);
|
|---|
| 313 |
|
|---|
| 314 | setVerbosity(3);
|
|---|
| 315 |
|
|---|
| 316 | size_t Exitflag = 0;
|
|---|
| 317 | typedef std::map<std::string, CommandIndices> CommandsMap_t;
|
|---|
| 318 | CommandsMap_t CommandsMap;
|
|---|
| 319 | CommandsMap.insert( std::make_pair("addjobs", AddJobsIndex) );
|
|---|
| 320 | CommandsMap.insert( std::make_pair("createjobs", CreateJobsIndex) );
|
|---|
| 321 | CommandsMap.insert( std::make_pair("checkresults", CheckResultsIndex) );
|
|---|
| 322 | CommandsMap.insert( std::make_pair("receiveresults", ReceiveResultsIndex) );
|
|---|
| 323 | CommandsMap.insert( std::make_pair("receivempqc", ReceiveMPQCIndex) );
|
|---|
| 324 | CommandsMap.insert( std::make_pair("removeall", RemoveAllIndex) );
|
|---|
| 325 | CommandsMap.insert( std::make_pair("shutdown", ShutdownIndex) );
|
|---|
| 326 | try
|
|---|
| 327 | {
|
|---|
| 328 | // Check command line arguments.
|
|---|
| 329 | if (argc < 4)
|
|---|
| 330 | {
|
|---|
| 331 | std::cerr << "Usage: " << argv[0] << " <host> <port> <command> [options to command]" << std::endl;
|
|---|
| 332 | std::cerr << "List of available commands:" << std::endl;
|
|---|
| 333 | for(CommandsMap_t::const_iterator iter = CommandsMap.begin();
|
|---|
| 334 | iter != CommandsMap.end(); ++iter) {
|
|---|
| 335 | std::cerr << "\t" << iter->first << std::endl;
|
|---|
| 336 | }
|
|---|
| 337 | return false;
|
|---|
| 338 | }
|
|---|
| 339 |
|
|---|
| 340 | boost::asio::io_service io_service;
|
|---|
| 341 | FragmentController controller(io_service);
|
|---|
| 342 |
|
|---|
| 343 | // Initial phase: information gathering from server
|
|---|
| 344 |
|
|---|
| 345 | switch(getCommandIndex(CommandsMap, argv[3])) {
|
|---|
| 346 | case AddJobsIndex:
|
|---|
| 347 | {
|
|---|
| 348 | if (argc < 6) {
|
|---|
| 349 | ELOG(1, "'addjobs' requires at least two options: [mpqc] [list of input files ...].");
|
|---|
| 350 | } else {
|
|---|
| 351 | // get an id for every filename
|
|---|
| 352 | controller.requestIds(argv[1], argv[2], argc-5);
|
|---|
| 353 | }
|
|---|
| 354 | break;
|
|---|
| 355 | }
|
|---|
| 356 | case CreateJobsIndex:
|
|---|
| 357 | {
|
|---|
| 358 | std::vector<FragmentJob::ptr> jobs;
|
|---|
| 359 | if (argc < 6) {
|
|---|
| 360 | ELOG(1, "'createjobs' requires two options: [command] [argument].");
|
|---|
| 361 | } else {
|
|---|
| 362 | controller.requestIds(argv[1], argv[2], 1);
|
|---|
| 363 | }
|
|---|
| 364 | break;
|
|---|
| 365 | }
|
|---|
| 366 | case CheckResultsIndex:
|
|---|
| 367 | break;
|
|---|
| 368 | case ReceiveResultsIndex:
|
|---|
| 369 | break;
|
|---|
| 370 | case ReceiveMPQCIndex:
|
|---|
| 371 | break;
|
|---|
| 372 | case RemoveAllIndex:
|
|---|
| 373 | break;
|
|---|
| 374 | case ShutdownIndex:
|
|---|
| 375 | break;
|
|---|
| 376 | case UnknownCommandIndex:
|
|---|
| 377 | default:
|
|---|
| 378 | ELOG(1, "Unrecognized command '"+toString(argv[3])+"'.");
|
|---|
| 379 | break;
|
|---|
| 380 | }
|
|---|
| 381 |
|
|---|
| 382 | {
|
|---|
| 383 | io_service.reset();
|
|---|
| 384 | Info info("io_service: Phase One");
|
|---|
| 385 | io_service.run();
|
|---|
| 386 | }
|
|---|
| 387 |
|
|---|
| 388 | // Second phase: Building jobs and sending information to server
|
|---|
| 389 |
|
|---|
| 390 | switch(getCommandIndex(CommandsMap, argv[3])) {
|
|---|
| 391 | case AddJobsIndex:
|
|---|
| 392 | {
|
|---|
| 393 | std::vector<FragmentJob::ptr> jobs;
|
|---|
| 394 | if (argc < 6) {
|
|---|
| 395 | ELOG(1, "Please add a filename for the MPQCCommandJob.");
|
|---|
| 396 | } else {
|
|---|
| 397 | const std::string command(argv[4]);
|
|---|
| 398 | for (int argcount = 5; argcount < argc; ++argcount) {
|
|---|
| 399 | const JobId_t next_id = controller.getAvailableId();
|
|---|
| 400 | const std::string filename(argv[argcount]);
|
|---|
| 401 | LOG(1, "INFO: Creating MPQCCommandJob with filename'"
|
|---|
| 402 | +filename+"', and id "+toString(next_id)+".");
|
|---|
| 403 | parsejob(jobs, command, filename, next_id);
|
|---|
| 404 | }
|
|---|
| 405 | controller.addJobs(jobs);
|
|---|
| 406 | controller.sendJobs(argv[1], argv[2]);
|
|---|
| 407 | }
|
|---|
| 408 | break;
|
|---|
| 409 | }
|
|---|
| 410 | case CreateJobsIndex:
|
|---|
| 411 | {
|
|---|
| 412 | std::vector<FragmentJob::ptr> jobs;
|
|---|
| 413 | if (argc < 6) {
|
|---|
| 414 | ELOG(1, "'createjobs' requires two options: [command] [argument].");
|
|---|
| 415 | } else {
|
|---|
| 416 | const JobId_t next_id = controller.getAvailableId();
|
|---|
| 417 | createjobs(jobs, argv[4], argv[5], next_id);
|
|---|
| 418 | controller.addJobs(jobs);
|
|---|
| 419 | controller.sendJobs(argv[1], argv[2]);
|
|---|
| 420 | }
|
|---|
| 421 | break;
|
|---|
| 422 | }
|
|---|
| 423 | case CheckResultsIndex:
|
|---|
| 424 | {
|
|---|
| 425 | controller.checkResults(argv[1], argv[2]);
|
|---|
| 426 | break;
|
|---|
| 427 | }
|
|---|
| 428 | case ReceiveResultsIndex:
|
|---|
| 429 | {
|
|---|
| 430 | controller.receiveResults(argv[1], argv[2]);
|
|---|
| 431 | break;
|
|---|
| 432 | }
|
|---|
| 433 | case ReceiveMPQCIndex:
|
|---|
| 434 | {
|
|---|
| 435 | controller.receiveResults(argv[1], argv[2]);
|
|---|
| 436 | break;
|
|---|
| 437 | }
|
|---|
| 438 | case RemoveAllIndex:
|
|---|
| 439 | {
|
|---|
| 440 | controller.removeall(argv[1], argv[2]);
|
|---|
| 441 | break;
|
|---|
| 442 | }
|
|---|
| 443 | case ShutdownIndex:
|
|---|
| 444 | {
|
|---|
| 445 | controller.shutdown(argv[1], argv[2]);
|
|---|
| 446 | break;
|
|---|
| 447 | }
|
|---|
| 448 | case UnknownCommandIndex:
|
|---|
| 449 | default:
|
|---|
| 450 | ELOG(0, "Unrecognized command '"+toString(argv[3])+"'.");
|
|---|
| 451 | break;
|
|---|
| 452 | }
|
|---|
| 453 |
|
|---|
| 454 | {
|
|---|
| 455 | io_service.reset();
|
|---|
| 456 | Info info("io_service: Phase Two");
|
|---|
| 457 | io_service.run();
|
|---|
| 458 | }
|
|---|
| 459 |
|
|---|
| 460 | // Final phase: Print result of command
|
|---|
| 461 |
|
|---|
| 462 | switch(getCommandIndex(CommandsMap, argv[3])) {
|
|---|
| 463 | case AddJobsIndex:
|
|---|
| 464 | case CreateJobsIndex:
|
|---|
| 465 | break;
|
|---|
| 466 | case CheckResultsIndex:
|
|---|
| 467 | {
|
|---|
| 468 | controller.printDoneJobs();
|
|---|
| 469 | break;
|
|---|
| 470 | }
|
|---|
| 471 | case ReceiveResultsIndex:
|
|---|
| 472 | {
|
|---|
| 473 | std::vector<FragmentResult::ptr> results = controller.getReceivedResults();
|
|---|
| 474 | printReceivedResults(results);
|
|---|
| 475 | break;
|
|---|
| 476 | }
|
|---|
| 477 | case ReceiveMPQCIndex:
|
|---|
| 478 | {
|
|---|
| 479 | if (argc < 5) {
|
|---|
| 480 | ELOG(1, "'receivempqc' require one option: [path to fragment files].");
|
|---|
| 481 | } else {
|
|---|
| 482 | const std::string path = argv[4];
|
|---|
| 483 | LOG(1, "INFO: Parsing fragment files from " << path << ".");
|
|---|
| 484 | std::vector<FragmentResult::ptr> results = controller.getReceivedResults();
|
|---|
| 485 | printReceivedMPQCResults(
|
|---|
| 486 | results,
|
|---|
| 487 | path,
|
|---|
| 488 | getNoAtomsFromAdjacencyFile(path));
|
|---|
| 489 | }
|
|---|
| 490 | break;
|
|---|
| 491 | }
|
|---|
| 492 | case RemoveAllIndex:
|
|---|
| 493 | break;
|
|---|
| 494 | case ShutdownIndex:
|
|---|
| 495 | break;
|
|---|
| 496 | case UnknownCommandIndex:
|
|---|
| 497 | default:
|
|---|
| 498 | ELOG(0, "Unrecognized command '"+toString(argv[3])+"'.");
|
|---|
| 499 | break;
|
|---|
| 500 | }
|
|---|
| 501 | Exitflag = controller.getExitflag();
|
|---|
| 502 | }
|
|---|
| 503 | catch (std::exception& e)
|
|---|
| 504 | {
|
|---|
| 505 | std::cerr << e.what() << std::endl;
|
|---|
| 506 | }
|
|---|
| 507 |
|
|---|
| 508 | return Exitflag;
|
|---|
| 509 | }
|
|---|
| 510 |
|
|---|