Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/picongpu/ArgsParser.cpp
Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down Expand Up @@ -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
Expand All @@ -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<std::vector<std::string> > ( &config_files )->multitoken( ), "Config file(s)" )
;

Expand Down Expand Up @@ -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;
}

}
12 changes: 4 additions & 8 deletions src/picongpu/include/ArgsParser.hpp
Original file line number Diff line number Diff line change
@@ -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.
*
Expand All @@ -19,9 +19,7 @@
*/



#ifndef ARGSPARSER_HPP
#define ARGSPARSER_HPP
#pragma once

#include <boost/program_options/options_description.hpp>

Expand All @@ -44,6 +42,7 @@ namespace picongpu
{
public:

enum ArgsErrorCode {SUCCESS=0,SUCCESS_EXIT=1,ERROR=42};
/**
* Returns an instance of ArgsParser
*
Expand All @@ -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);



Expand All @@ -79,6 +78,3 @@ namespace picongpu
};

}

#endif /* ARGSPARSER_HPP */

18 changes: 6 additions & 12 deletions src/picongpu/include/simulationControl/ISimulationStarter.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2013 Rene Widera
* Copyright 2013, 2015 Rene Widera
*
* This file is part of PIConGPU.
*
Expand All @@ -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
{
Expand All @@ -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
Expand All @@ -66,6 +63,3 @@ namespace picongpu
}
};
}

#endif /* ISIMULATIONSTARTER_HPP */

4 changes: 2 additions & 2 deletions src/picongpu/include/simulationControl/SimulationStarter.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2013 Axel Huebl, Rene Widera
* Copyright 2013, 2015 Axel Huebl, Rene Widera
*
* This file is part of PIConGPU.
*
Expand Down Expand Up @@ -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();
Expand Down
35 changes: 23 additions & 12 deletions src/picongpu/main.cu
Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down Expand Up @@ -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 <simulation_defines.hpp>
#include <mpi.h>
#include "communication/manager_common.h"


using namespace PMacc;
using namespace picongpu;
Expand All @@ -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;
}