Skip to content

Commit b509143

Browse files
committed
Merge pull request ComputationalRadiationPhysics#863 from psychocoderHPC/topic-parameterValidation
ArgsParser: add `validate` command line option
2 parents 7f19215 + 3eb9baa commit b509143

File tree

5 files changed

+49
-40
lines changed

5 files changed

+49
-40
lines changed

src/picongpu/ArgsParser.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2013 Axel Huebl, Felix Schmitt, Rene Widera
2+
* Copyright 2013, 2015 Axel Huebl, Felix Schmitt, Rene Widera
33
*
44
* This file is part of PIConGPU.
55
*
@@ -61,7 +61,7 @@ namespace picongpu
6161
return instance;
6262
}
6363

64-
bool ArgsParser::parse( int argc, char** argv )
64+
ArgsParser::ArgsErrorCode ArgsParser::parse( int argc, char** argv )
6565
throw (std::runtime_error )
6666
{
6767
try
@@ -76,7 +76,8 @@ namespace picongpu
7676

7777
// add possible options
7878
desc.add_options()
79-
( "help,h", "print help message" )
79+
( "help,h", "print help message and exit" )
80+
( "validate", "validate command line parameters and exit" )
8081
( "config,c", po::value<std::vector<std::string> > ( &config_files )->multitoken( ), "Config file(s)" )
8182
;
8283

@@ -109,16 +110,23 @@ namespace picongpu
109110
if ( vm.count( "help" ) )
110111
{
111112
std::cerr << desc << "\n";
112-
return false;
113+
return SUCCESS_EXIT;
114+
}
115+
if ( vm.count( "validate" ) )
116+
{
117+
/* if we reach this part of code the parameters are valid
118+
* and the option `validate` is set.
119+
*/
120+
return SUCCESS_EXIT;
113121
}
114122
}
115123
catch ( boost::program_options::error& e )
116124
{
117125
std::cerr << e.what() << std::endl;
118-
return false;
126+
return ERROR;
119127
}
120128

121-
return true;
129+
return SUCCESS;
122130
}
123131

124132
}

src/picongpu/include/ArgsParser.hpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2013 Axel Huebl, Felix Schmitt, Rene Widera
2+
* Copyright 2013, 2015 Axel Huebl, Felix Schmitt, Rene Widera
33
*
44
* This file is part of PIConGPU.
55
*
@@ -19,9 +19,7 @@
1919
*/
2020

2121

22-
23-
#ifndef ARGSPARSER_HPP
24-
#define ARGSPARSER_HPP
22+
#pragma once
2523

2624
#include <boost/program_options/options_description.hpp>
2725

@@ -44,6 +42,7 @@ namespace picongpu
4442
{
4543
public:
4644

45+
enum ArgsErrorCode {SUCCESS=0,SUCCESS_EXIT=1,ERROR=42};
4746
/**
4847
* Returns an instance of ArgsParser
4948
*
@@ -63,7 +62,7 @@ namespace picongpu
6362
* @param argv command line arguments
6463
* @return true if the simulation should proceed, false otherwise
6564
*/
66-
bool parse(int argc, char **argv) throw (std::runtime_error);
65+
ArgsErrorCode parse(int argc, char **argv) throw (std::runtime_error);
6766

6867

6968

@@ -79,6 +78,3 @@ namespace picongpu
7978
};
8079

8180
}
82-
83-
#endif /* ARGSPARSER_HPP */
84-

src/picongpu/include/simulationControl/ISimulationStarter.hpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2013 Rene Widera
2+
* Copyright 2013, 2015 Rene Widera
33
*
44
* This file is part of PIConGPU.
55
*
@@ -19,15 +19,12 @@
1919
*/
2020

2121

22-
23-
#ifndef ISIMULATIONSTARTER_HPP
24-
#define ISIMULATIONSTARTER_HPP
25-
26-
#include "types.h"
27-
#include "simulation_defines.hpp"
28-
22+
#pragma once
2923

3024
#include "pluginSystem/IPlugin.hpp"
25+
#include "ArgsParser.hpp"
26+
#include "simulation_defines.hpp"
27+
#include "types.h"
3128

3229
namespace picongpu
3330
{
@@ -48,7 +45,7 @@ namespace picongpu
4845
*
4946
* @return true if no error else false
5047
*/
51-
virtual bool parseConfigs(int argc, char **argv) = 0;
48+
virtual ArgsParser::ArgsErrorCode parseConfigs(int argc, char **argv) = 0;
5249

5350
/*start simulation
5451
* is called after parsConfig and pluginLoad
@@ -66,6 +63,3 @@ namespace picongpu
6663
}
6764
};
6865
}
69-
70-
#endif /* ISIMULATIONSTARTER_HPP */
71-

src/picongpu/include/simulationControl/SimulationStarter.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2013 Axel Huebl, Rene Widera
2+
* Copyright 2013, 2015 Axel Huebl, Rene Widera
33
*
44
* This file is part of PIConGPU.
55
*
@@ -94,7 +94,7 @@ namespace picongpu
9494
{
9595
}
9696

97-
bool parseConfigs(int argc, char **argv)
97+
ArgsParser::ArgsErrorCode parseConfigs(int argc, char **argv)
9898
{
9999
ArgsParser& ap = ArgsParser::getInstance();
100100
PluginConnector& pluginConnector = Environment<>::get().PluginConnector();

src/picongpu/main.cu

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2013 Axel Huebl, Felix Schmitt, Heiko Burau, Rene Widera
2+
* Copyright 2013-2015 Axel Huebl, Felix Schmitt, Heiko Burau, Rene Widera
33
*
44
* This file is part of PIConGPU.
55
*
@@ -71,9 +71,13 @@ mallocMC::AlignmentPolicies::Shrink<>
7171
//use ScatterAllocator to replace malloc/free
7272
MALLOCMC_SET_ALLOCATOR_TYPE( ScatterAllocator );
7373

74+
#include "ArgsParser.hpp"
75+
#include "communication/manager_common.h"
76+
#include "ArgsParser.hpp"
77+
7478
#include <simulation_defines.hpp>
7579
#include <mpi.h>
76-
#include "communication/manager_common.h"
80+
7781

7882
using namespace PMacc;
7983
using namespace picongpu;
@@ -88,17 +92,24 @@ int main(int argc, char **argv)
8892
MPI_CHECK(MPI_Init(&argc, &argv));
8993

9094
picongpu::simulation_starter::SimStarter sim;
91-
if (!sim.parseConfigs(argc, argv))
92-
{
93-
MPI_CHECK(MPI_Finalize());
94-
return 1;
95-
}
95+
ArgsParser::ArgsErrorCode parserCode = sim.parseConfigs(argc, argv);
96+
int errorCode = 1;
9697

97-
sim.load();
98-
sim.start();
99-
sim.unload();
98+
switch(parserCode)
99+
{
100+
case ArgsParser::ERROR:
101+
errorCode = 1;
102+
break;
103+
case ArgsParser::SUCCESS:
104+
sim.load();
105+
sim.start();
106+
sim.unload();
107+
/*set error code to valid (1) after the simulation terminates*/
108+
case ArgsParser::SUCCESS_EXIT:
109+
errorCode = 0;
110+
break;
111+
};
100112

101113
MPI_CHECK(MPI_Finalize());
102-
103-
return 0;
114+
return errorCode;
104115
}

0 commit comments

Comments
 (0)