[7ca772] | 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 |
|
---|
[986885] | 29 | #include <boost/archive/text_oarchive.hpp>
|
---|
| 30 | #include <boost/archive/text_iarchive.hpp>
|
---|
[ff60cfa] | 31 | #include <fstream>
|
---|
[7ca772] | 32 | #include <iostream>
|
---|
| 33 | #include <map>
|
---|
[ff60cfa] | 34 | #include <sstream>
|
---|
| 35 | #include <streambuf>
|
---|
| 36 | #include <vector>
|
---|
[7ca772] | 37 |
|
---|
| 38 | #include "atexit.hpp"
|
---|
| 39 | #include "CodePatterns/Info.hpp"
|
---|
| 40 | #include "CodePatterns/Log.hpp"
|
---|
[d7bb9b1] | 41 | #include "Fragmentation/EnergyMatrix.hpp"
|
---|
| 42 | #include "Fragmentation/ForceMatrix.hpp"
|
---|
| 43 | #include "Fragmentation/KeySetsContainer.hpp"
|
---|
[d4885d] | 44 | #include "FragmentController.hpp"
|
---|
[5a8512] | 45 | #include "Helpers/defs.hpp"
|
---|
[ff60cfa] | 46 | #include "Jobs/MPQCCommandJob.hpp"
|
---|
[d7bb9b1] | 47 | #include "Jobs/MPQCCommandJob_MPQCData.hpp"
|
---|
[d920b9] | 48 | #include "Jobs/SystemCommandJob.hpp"
|
---|
[7670865] | 49 | #include "Results/FragmentResult.hpp"
|
---|
[7ca772] | 50 |
|
---|
| 51 | enum CommandIndices {
|
---|
| 52 | UnknownCommandIndex = 0,
|
---|
[ff60cfa] | 53 | AddJobsIndex = 1,
|
---|
| 54 | CreateJobsIndex = 2,
|
---|
| 55 | CheckResultsIndex = 3,
|
---|
| 56 | ReceiveResultsIndex = 4,
|
---|
[986885] | 57 | ReceiveMPQCIndex = 5,
|
---|
[b15c4f] | 58 | RemoveAllIndex = 6,
|
---|
| 59 | ShutdownIndex = 7,
|
---|
[7ca772] | 60 | };
|
---|
| 61 |
|
---|
[ff60cfa] | 62 |
|
---|
[4dd16e] | 63 | /** Creates a SystemCommandJob out of give \a command with \a argument.
|
---|
[d1dbfc] | 64 | *
|
---|
[4dd16e] | 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
|
---|
[d1dbfc] | 69 | */
|
---|
[554809] | 70 | void createjobs(
|
---|
| 71 | std::vector<FragmentJob::ptr> &jobs,
|
---|
| 72 | const std::string &command,
|
---|
| 73 | const std::string &argument,
|
---|
| 74 | const JobId_t nextid)
|
---|
[d1dbfc] | 75 | {
|
---|
[4dd16e] | 76 |
|
---|
[554809] | 77 | FragmentJob::ptr testJob( new SystemCommandJob(command, argument, nextid) );
|
---|
[7ca772] | 78 | jobs.push_back(testJob);
|
---|
[554809] | 79 | LOG(1, "INFO: Added one SystemCommandJob.");
|
---|
[7ca772] | 80 | }
|
---|
| 81 |
|
---|
[d1dbfc] | 82 | /** Creates a MPQCCommandJob with argument \a filename.
|
---|
| 83 | *
|
---|
| 84 | * @param jobs created job is added to this vector
|
---|
[917be8] | 85 | * @param command mpqc command to execute
|
---|
[d1dbfc] | 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,
|
---|
[917be8] | 91 | const std::string &command,
|
---|
[d1dbfc] | 92 | const std::string &filename,
|
---|
| 93 | const JobId_t nextid)
|
---|
[ff60cfa] | 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>());
|
---|
[917be8] | 100 | FragmentJob::ptr testJob( new MPQCCommandJob(output, nextid, command) );
|
---|
[ff60cfa] | 101 | jobs.push_back(testJob);
|
---|
| 102 | file.close();
|
---|
| 103 | LOG(1, "INFO: Added MPQCCommandJob from file "+filename+".");
|
---|
| 104 | }
|
---|
| 105 |
|
---|
[d1dbfc] | 106 | /** Print received results.
|
---|
| 107 | *
|
---|
[4dd16e] | 108 | * @param results received results to print
|
---|
[d1dbfc] | 109 | */
|
---|
[4dd16e] | 110 | void printReceivedResults(std::vector<FragmentResult::ptr> &results)
|
---|
[7ca772] | 111 | {
|
---|
[35f587] | 112 | for (std::vector<FragmentResult::ptr>::const_iterator iter = results.begin();
|
---|
[7ca772] | 113 | iter != results.end(); ++iter)
|
---|
[35f587] | 114 | LOG(1, "RESULT: job #"+toString((*iter)->getId())+": "+toString((*iter)->result));
|
---|
[7ca772] | 115 | }
|
---|
| 116 |
|
---|
[d7bb9b1] | 117 | /** Print MPQCData from received results.
|
---|
[986885] | 118 | *
|
---|
[5a8512] | 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
|
---|
[986885] | 122 | */
|
---|
[d7bb9b1] | 123 | bool printReceivedMPQCResults(
|
---|
[5a8512] | 124 | const std::vector<FragmentResult::ptr> &results,
|
---|
| 125 | const std::string &KeySetFilename,
|
---|
| 126 | size_t NoAtoms)
|
---|
[986885] | 127 | {
|
---|
[d7bb9b1] | 128 | EnergyMatrix Energy;
|
---|
| 129 | EnergyMatrix EnergyFragments;
|
---|
| 130 | ForceMatrix Force;
|
---|
| 131 | ForceMatrix ForceFragments;
|
---|
| 132 | KeySetsContainer KeySet;
|
---|
| 133 |
|
---|
[5a8512] | 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
|
---|
[986885] | 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);
|
---|
[5a8512] | 168 | LOG(2, "DEBUG: First 50 characters FragmentResult's string: "+(*iter)->result.substr(0, 50));
|
---|
[986885] | 169 | boost::archive::text_iarchive ia(inputstream);
|
---|
| 170 | ia >> extractedData;
|
---|
| 171 | LOG(1, "INFO: extracted data is " << extractedData << ".");
|
---|
[5a8512] | 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 | }
|
---|
[986885] | 207 | }
|
---|
[5a8512] | 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;
|
---|
[d7bb9b1] | 220 |
|
---|
[5a8512] | 221 |
|
---|
| 222 | // combine all found data
|
---|
[d7bb9b1] | 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 |
|
---|
[5a8512] | 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 |
|
---|
[d7bb9b1] | 259 | return true;
|
---|
[986885] | 260 | }
|
---|
| 261 |
|
---|
[5a8512] | 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 |
|
---|
[d7bb9b1] | 291 |
|
---|
[7ca772] | 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;
|
---|
[ff60cfa] | 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) );
|
---|
[7ca772] | 321 | CommandsMap.insert( std::make_pair("checkresults", CheckResultsIndex) );
|
---|
| 322 | CommandsMap.insert( std::make_pair("receiveresults", ReceiveResultsIndex) );
|
---|
[986885] | 323 | CommandsMap.insert( std::make_pair("receivempqc", ReceiveMPQCIndex) );
|
---|
[b15c4f] | 324 | CommandsMap.insert( std::make_pair("removeall", RemoveAllIndex) );
|
---|
[7ca772] | 325 | CommandsMap.insert( std::make_pair("shutdown", ShutdownIndex) );
|
---|
| 326 | try
|
---|
| 327 | {
|
---|
| 328 | // Check command line arguments.
|
---|
[ff60cfa] | 329 | if (argc < 4)
|
---|
[7ca772] | 330 | {
|
---|
[ff60cfa] | 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 | }
|
---|
[d7bb9b1] | 337 | return false;
|
---|
[7ca772] | 338 | }
|
---|
| 339 |
|
---|
| 340 | boost::asio::io_service io_service;
|
---|
| 341 | FragmentController controller(io_service);
|
---|
| 342 |
|
---|
[d1dbfc] | 343 | // Initial phase: information gathering from server
|
---|
| 344 |
|
---|
| 345 | switch(getCommandIndex(CommandsMap, argv[3])) {
|
---|
| 346 | case AddJobsIndex:
|
---|
| 347 | {
|
---|
[917be8] | 348 | if (argc < 6) {
|
---|
| 349 | ELOG(1, "'addjobs' requires at least two options: [mpqc] [list of input files ...].");
|
---|
[d1dbfc] | 350 | } else {
|
---|
| 351 | // get an id for every filename
|
---|
[917be8] | 352 | controller.requestIds(argv[1], argv[2], argc-5);
|
---|
[d1dbfc] | 353 | }
|
---|
| 354 | break;
|
---|
| 355 | }
|
---|
| 356 | case CreateJobsIndex:
|
---|
| 357 | {
|
---|
[554809] | 358 | std::vector<FragmentJob::ptr> jobs;
|
---|
| 359 | if (argc < 6) {
|
---|
| 360 | ELOG(1, "'createjobs' requires two options: [command] [argument].");
|
---|
| 361 | } else {
|
---|
[c4f43e] | 362 | controller.requestIds(argv[1], argv[2], 1);
|
---|
[554809] | 363 | }
|
---|
[d1dbfc] | 364 | break;
|
---|
| 365 | }
|
---|
| 366 | case CheckResultsIndex:
|
---|
| 367 | break;
|
---|
| 368 | case ReceiveResultsIndex:
|
---|
| 369 | break;
|
---|
[986885] | 370 | case ReceiveMPQCIndex:
|
---|
| 371 | break;
|
---|
[b15c4f] | 372 | case RemoveAllIndex:
|
---|
| 373 | break;
|
---|
[d1dbfc] | 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 |
|
---|
[7ca772] | 390 | switch(getCommandIndex(CommandsMap, argv[3])) {
|
---|
[ff60cfa] | 391 | case AddJobsIndex:
|
---|
| 392 | {
|
---|
| 393 | std::vector<FragmentJob::ptr> jobs;
|
---|
[917be8] | 394 | if (argc < 6) {
|
---|
[ff60cfa] | 395 | ELOG(1, "Please add a filename for the MPQCCommandJob.");
|
---|
| 396 | } else {
|
---|
[917be8] | 397 | const std::string command(argv[4]);
|
---|
| 398 | for (int argcount = 5; argcount < argc; ++argcount) {
|
---|
[4dd16e] | 399 | const JobId_t next_id = controller.getAvailableId();
|
---|
[d1dbfc] | 400 | const std::string filename(argv[argcount]);
|
---|
| 401 | LOG(1, "INFO: Creating MPQCCommandJob with filename'"
|
---|
| 402 | +filename+"', and id "+toString(next_id)+".");
|
---|
[917be8] | 403 | parsejob(jobs, command, filename, next_id);
|
---|
[ff60cfa] | 404 | }
|
---|
[4dd16e] | 405 | controller.addJobs(jobs);
|
---|
| 406 | controller.sendJobs(argv[1], argv[2]);
|
---|
[ff60cfa] | 407 | }
|
---|
| 408 | break;
|
---|
| 409 | }
|
---|
| 410 | case CreateJobsIndex:
|
---|
[7ca772] | 411 | {
|
---|
[78ad7d] | 412 | std::vector<FragmentJob::ptr> jobs;
|
---|
[554809] | 413 | if (argc < 6) {
|
---|
[4dd16e] | 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]);
|
---|
[554809] | 420 | }
|
---|
[7ca772] | 421 | break;
|
---|
| 422 | }
|
---|
| 423 | case CheckResultsIndex:
|
---|
| 424 | {
|
---|
[4dd16e] | 425 | controller.checkResults(argv[1], argv[2]);
|
---|
[7ca772] | 426 | break;
|
---|
| 427 | }
|
---|
| 428 | case ReceiveResultsIndex:
|
---|
| 429 | {
|
---|
[4dd16e] | 430 | controller.receiveResults(argv[1], argv[2]);
|
---|
[7ca772] | 431 | break;
|
---|
| 432 | }
|
---|
[986885] | 433 | case ReceiveMPQCIndex:
|
---|
| 434 | {
|
---|
[4dd16e] | 435 | controller.receiveResults(argv[1], argv[2]);
|
---|
[986885] | 436 | break;
|
---|
| 437 | }
|
---|
[b15c4f] | 438 | case RemoveAllIndex:
|
---|
| 439 | {
|
---|
| 440 | controller.removeall(argv[1], argv[2]);
|
---|
| 441 | break;
|
---|
| 442 | }
|
---|
[7ca772] | 443 | case ShutdownIndex:
|
---|
| 444 | {
|
---|
[4dd16e] | 445 | controller.shutdown(argv[1], argv[2]);
|
---|
[7ca772] | 446 | break;
|
---|
| 447 | }
|
---|
| 448 | case UnknownCommandIndex:
|
---|
| 449 | default:
|
---|
| 450 | ELOG(0, "Unrecognized command '"+toString(argv[3])+"'.");
|
---|
| 451 | break;
|
---|
| 452 | }
|
---|
| 453 |
|
---|
| 454 | {
|
---|
[d1dbfc] | 455 | io_service.reset();
|
---|
| 456 | Info info("io_service: Phase Two");
|
---|
[7ca772] | 457 | io_service.run();
|
---|
| 458 | }
|
---|
| 459 |
|
---|
[d1dbfc] | 460 | // Final phase: Print result of command
|
---|
| 461 |
|
---|
[7ca772] | 462 | switch(getCommandIndex(CommandsMap, argv[3])) {
|
---|
[ff60cfa] | 463 | case AddJobsIndex:
|
---|
| 464 | case CreateJobsIndex:
|
---|
[7ca772] | 465 | break;
|
---|
| 466 | case CheckResultsIndex:
|
---|
| 467 | {
|
---|
[4dd16e] | 468 | controller.printDoneJobs();
|
---|
[7ca772] | 469 | break;
|
---|
| 470 | }
|
---|
| 471 | case ReceiveResultsIndex:
|
---|
| 472 | {
|
---|
[4dd16e] | 473 | std::vector<FragmentResult::ptr> results = controller.getReceivedResults();
|
---|
| 474 | printReceivedResults(results);
|
---|
[7ca772] | 475 | break;
|
---|
| 476 | }
|
---|
[986885] | 477 | case ReceiveMPQCIndex:
|
---|
| 478 | {
|
---|
[5a8512] | 479 | if (argc < 5) {
|
---|
| 480 | ELOG(1, "'receivempqc' require one option: [path to fragment files].");
|
---|
[986885] | 481 | } else {
|
---|
[5a8512] | 482 | const std::string path = argv[4];
|
---|
| 483 | LOG(1, "INFO: Parsing fragment files from " << path << ".");
|
---|
[4dd16e] | 484 | std::vector<FragmentResult::ptr> results = controller.getReceivedResults();
|
---|
[5a8512] | 485 | printReceivedMPQCResults(
|
---|
| 486 | results,
|
---|
| 487 | path,
|
---|
| 488 | getNoAtomsFromAdjacencyFile(path));
|
---|
[986885] | 489 | }
|
---|
| 490 | break;
|
---|
| 491 | }
|
---|
[b15c4f] | 492 | case RemoveAllIndex:
|
---|
| 493 | break;
|
---|
[7ca772] | 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 | }
|
---|
[4dd16e] | 510 |
|
---|