int CommandLineModuleManager::run(int argc, char *argv[]) { int argOffset = 0; CommandLineModuleMap::const_iterator module = impl_->findModuleFromBinaryName(impl_->programInfo_); if (!impl_->bQuiet_) { printBinaryInformation(stderr, impl_->programInfo_); } if (module == impl_->modules_.end()) { if (argc < 2) { impl_->helpModule_->printUsage(); if (!impl_->bQuiet_) { gmx_thanx(stderr); } return 2; } module = impl_->findModuleByName(argv[1]); argOffset = 1; } if (module == impl_->modules_.end()) { fprintf(stderr, "Unknown command: '%s'\n\n", argv[1]); impl_->helpModule_->printUsage(); if (!impl_->bQuiet_) { gmx_thanx(stderr); } return 2; } int rc = module->second->run(argc - argOffset, argv + argOffset); if (!impl_->bQuiet_) { gmx_thanx(stderr); } return rc; }
void printBinaryInformation(FILE *fp, const ProgramContextInterface &programContext) { printBinaryInformation(fp, programContext, BinaryInformationSettings()); }
int CommandLineModuleManager::run(int argc, char *argv[]) { CommandLineModuleInterface *module; const bool bMaster = (gmx_node_rank() == 0); bool bQuiet = impl_->bQuiet_ || !bMaster; CommandLineCommonOptionsHolder optionsHolder; try { optionsHolder.initOptions(); module = impl_->processCommonOptions(&optionsHolder, &argc, &argv); } catch (const std::exception &) { bQuiet |= optionsHolder.shouldBeQuiet(); if (!bQuiet) { printBinaryInformation(stderr, impl_->programContext_, optionsHolder.binaryInfoSettings()); } throw; } bQuiet |= optionsHolder.shouldBeQuiet(); if (!bQuiet) { FILE *out = optionsHolder.startupInfoFile(); printBinaryInformation(out, impl_->programContext_, optionsHolder.binaryInfoSettings()); fprintf(out, "\n"); } if (module == NULL) { return 0; } CommandLineModuleSettings settings; module->init(&settings); optionsHolder.adjustFromSettings(settings); gmx_set_max_backup_count(optionsHolder.shouldBackup() ? -1 : 0); // Open the debug file. if (optionsHolder.debugLevel() > 0) { std::string filename(impl_->programContext_.programName()); if (gmx_node_num() > 1) { filename.append(formatString("%d", gmx_node_rank())); } filename.append(".debug"); fprintf(stderr, "Will write debug log file: %s\n", filename.c_str()); gmx_init_debug(optionsHolder.debugLevel(), filename.c_str()); } // Set the nice level unless disabled in the configuration. if (optionsHolder.niceLevel() != 0) { static bool bNiceSet = false; // Only set it once. if (!bNiceSet) { // TODO: Diagnostic if this fails and the user explicitly requested it. gmx_set_nice(optionsHolder.niceLevel()); bNiceSet = true; } } if (optionsHolder.enableFPExceptions()) { //TODO: currently it is always enabled for mdrun (verlet) and tests. gmx_feenableexcept(); } int rc = 0; if (!(module == impl_->helpModule_ && !bMaster)) { rc = module->run(argc, argv); } if (!bQuiet) { gmx_thanx(stderr); } return rc; }