From 3eb9baa1469a6de95d927ed3a7430121aacb1b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Widera?= Date: Fri, 8 May 2015 14:08:23 +0200 Subject: [PATCH] add `validate` command line option - add command line option `validate` - `ArgsParser`: - add enum `ArgsErrorCode` - change return code of parse from `bool` to `ArgsErrorCode` - `main.cu`: handle ArgsParser error codes `validate` validates the command line options without starting the simulation --- src/picongpu/ArgsParser.cpp | 20 +++++++---- src/picongpu/include/ArgsParser.hpp | 12 +++---- .../simulationControl/ISimulationStarter.hpp | 18 ++++------ .../simulationControl/SimulationStarter.hpp | 4 +-- src/picongpu/main.cu | 35 ++++++++++++------- 5 files changed, 49 insertions(+), 40 deletions(-) diff --git a/src/picongpu/ArgsParser.cpp b/src/picongpu/ArgsParser.cpp index 768ac7747f..c7d5223166 100644 --- a/src/picongpu/ArgsParser.cpp +++ b/src/picongpu/ArgsParser.cpp @@ -1,5 +1,5 @@ /** - * Copyright 2013 Axel Huebl, Felix Schmitt, Rene Widera + * Copyright 2013, 2015 Axel Huebl, Felix Schmitt, Rene Widera * * This file is part of PIConGPU. * @@ -61,7 +61,7 @@ namespace picongpu return instance; } - bool ArgsParser::parse( int argc, char** argv ) + ArgsParser::ArgsErrorCode ArgsParser::parse( int argc, char** argv ) throw (std::runtime_error ) { try @@ -76,7 +76,8 @@ namespace picongpu // add possible options desc.add_options() - ( "help,h", "print help message" ) + ( "help,h", "print help message and exit" ) + ( "validate", "validate command line parameters and exit" ) ( "config,c", po::value > ( &config_files )->multitoken( ), "Config file(s)" ) ; @@ -109,16 +110,23 @@ namespace picongpu if ( vm.count( "help" ) ) { std::cerr << desc << "\n"; - return false; + return SUCCESS_EXIT; + } + if ( vm.count( "validate" ) ) + { + /* if we reach this part of code the parameters are valid + * and the option `validate` is set. + */ + return SUCCESS_EXIT; } } catch ( boost::program_options::error& e ) { std::cerr << e.what() << std::endl; - return false; + return ERROR; } - return true; + return SUCCESS; } } \ No newline at end of file diff --git a/src/picongpu/include/ArgsParser.hpp b/src/picongpu/include/ArgsParser.hpp index 035402de0d..3551036558 100644 --- a/src/picongpu/include/ArgsParser.hpp +++ b/src/picongpu/include/ArgsParser.hpp @@ -1,5 +1,5 @@ /** - * Copyright 2013 Axel Huebl, Felix Schmitt, Rene Widera + * Copyright 2013, 2015 Axel Huebl, Felix Schmitt, Rene Widera * * This file is part of PIConGPU. * @@ -19,9 +19,7 @@ */ - -#ifndef ARGSPARSER_HPP -#define ARGSPARSER_HPP +#pragma once #include @@ -44,6 +42,7 @@ namespace picongpu { public: + enum ArgsErrorCode {SUCCESS=0,SUCCESS_EXIT=1,ERROR=42}; /** * Returns an instance of ArgsParser * @@ -63,7 +62,7 @@ namespace picongpu * @param argv command line arguments * @return true if the simulation should proceed, false otherwise */ - bool parse(int argc, char **argv) throw (std::runtime_error); + ArgsErrorCode parse(int argc, char **argv) throw (std::runtime_error); @@ -79,6 +78,3 @@ namespace picongpu }; } - -#endif /* ARGSPARSER_HPP */ - diff --git a/src/picongpu/include/simulationControl/ISimulationStarter.hpp b/src/picongpu/include/simulationControl/ISimulationStarter.hpp index d3efd8a1eb..09224b7339 100644 --- a/src/picongpu/include/simulationControl/ISimulationStarter.hpp +++ b/src/picongpu/include/simulationControl/ISimulationStarter.hpp @@ -1,5 +1,5 @@ /** - * Copyright 2013 Rene Widera + * Copyright 2013, 2015 Rene Widera * * This file is part of PIConGPU. * @@ -19,15 +19,12 @@ */ - -#ifndef ISIMULATIONSTARTER_HPP -#define ISIMULATIONSTARTER_HPP - -#include "types.h" -#include "simulation_defines.hpp" - +#pragma once #include "pluginSystem/IPlugin.hpp" +#include "ArgsParser.hpp" +#include "simulation_defines.hpp" +#include "types.h" namespace picongpu { @@ -48,7 +45,7 @@ namespace picongpu * * @return true if no error else false */ - virtual bool parseConfigs(int argc, char **argv) = 0; + virtual ArgsParser::ArgsErrorCode parseConfigs(int argc, char **argv) = 0; /*start simulation * is called after parsConfig and pluginLoad @@ -66,6 +63,3 @@ namespace picongpu } }; } - -#endif /* ISIMULATIONSTARTER_HPP */ - diff --git a/src/picongpu/include/simulationControl/SimulationStarter.hpp b/src/picongpu/include/simulationControl/SimulationStarter.hpp index 1f12722843..4441ea5e78 100644 --- a/src/picongpu/include/simulationControl/SimulationStarter.hpp +++ b/src/picongpu/include/simulationControl/SimulationStarter.hpp @@ -1,5 +1,5 @@ /** - * Copyright 2013 Axel Huebl, Rene Widera + * Copyright 2013, 2015 Axel Huebl, Rene Widera * * This file is part of PIConGPU. * @@ -94,7 +94,7 @@ namespace picongpu { } - bool parseConfigs(int argc, char **argv) + ArgsParser::ArgsErrorCode parseConfigs(int argc, char **argv) { ArgsParser& ap = ArgsParser::getInstance(); PluginConnector& pluginConnector = Environment<>::get().PluginConnector(); diff --git a/src/picongpu/main.cu b/src/picongpu/main.cu index 3ad7fe21f6..2b604df206 100644 --- a/src/picongpu/main.cu +++ b/src/picongpu/main.cu @@ -1,5 +1,5 @@ /** - * Copyright 2013 Axel Huebl, Felix Schmitt, Heiko Burau, Rene Widera + * Copyright 2013-2015 Axel Huebl, Felix Schmitt, Heiko Burau, Rene Widera * * This file is part of PIConGPU. * @@ -71,9 +71,13 @@ mallocMC::AlignmentPolicies::Shrink<> //use ScatterAllocator to replace malloc/free MALLOCMC_SET_ALLOCATOR_TYPE( ScatterAllocator ); +#include "ArgsParser.hpp" +#include "communication/manager_common.h" +#include "ArgsParser.hpp" + #include #include -#include "communication/manager_common.h" + using namespace PMacc; using namespace picongpu; @@ -88,17 +92,24 @@ int main(int argc, char **argv) MPI_CHECK(MPI_Init(&argc, &argv)); picongpu::simulation_starter::SimStarter sim; - if (!sim.parseConfigs(argc, argv)) - { - MPI_CHECK(MPI_Finalize()); - return 1; - } + ArgsParser::ArgsErrorCode parserCode = sim.parseConfigs(argc, argv); + int errorCode = 1; - sim.load(); - sim.start(); - sim.unload(); + switch(parserCode) + { + case ArgsParser::ERROR: + errorCode = 1; + break; + case ArgsParser::SUCCESS: + sim.load(); + sim.start(); + sim.unload(); + /*set error code to valid (1) after the simulation terminates*/ + case ArgsParser::SUCCESS_EXIT: + errorCode = 0; + break; + }; MPI_CHECK(MPI_Finalize()); - - return 0; + return errorCode; }