2013-10-14 11:03:46 -04:00
|
|
|
/*
|
|
|
|
|
2015-02-19 03:19:51 -05:00
|
|
|
Copyright (c) 2013, Project OSRM contributors
|
2013-10-14 11:03:46 -04:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
Redistributions of source code must retain the above copyright notice, this list
|
|
|
|
of conditions and the following disclaimer.
|
|
|
|
Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
|
list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2014-11-28 04:29:56 -05:00
|
|
|
#include "contractor/processing_chain.hpp"
|
2015-04-24 08:51:25 -04:00
|
|
|
#include "contractor/contractor_options.hpp"
|
2015-02-09 11:38:40 -05:00
|
|
|
#include "util/simple_logger.hpp"
|
2014-05-06 12:15:45 -04:00
|
|
|
|
2015-02-09 11:38:40 -05:00
|
|
|
#include <boost/program_options/errors.hpp>
|
|
|
|
|
2015-04-24 08:51:25 -04:00
|
|
|
#include <tbb/task_scheduler_init.h>
|
|
|
|
|
2015-10-18 06:19:06 -04:00
|
|
|
#include <cstdlib>
|
2015-02-09 11:38:40 -05:00
|
|
|
#include <exception>
|
|
|
|
#include <ostream>
|
2015-10-18 06:34:42 -04:00
|
|
|
#include <new>
|
2014-05-08 13:40:29 -04:00
|
|
|
|
2015-10-18 06:19:06 -04:00
|
|
|
int main(int argc, char *argv[]) try
|
2014-05-08 13:40:29 -04:00
|
|
|
{
|
2015-10-18 06:19:06 -04:00
|
|
|
LogPolicy::GetInstance().Unmute();
|
|
|
|
ContractorConfig contractor_config;
|
|
|
|
|
|
|
|
const return_code result = ContractorOptions::ParseArguments(argc, argv, contractor_config);
|
|
|
|
|
|
|
|
if (return_code::fail == result)
|
2014-05-08 13:40:29 -04:00
|
|
|
{
|
2015-10-18 06:34:42 -04:00
|
|
|
return EXIT_FAILURE;
|
2014-05-08 13:40:29 -04:00
|
|
|
}
|
2015-10-18 06:19:06 -04:00
|
|
|
|
|
|
|
if (return_code::exit == result)
|
2014-05-08 13:40:29 -04:00
|
|
|
{
|
2015-10-18 06:34:42 -04:00
|
|
|
return EXIT_SUCCESS;
|
2015-10-18 06:19:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ContractorOptions::GenerateOutputFilesNames(contractor_config);
|
|
|
|
|
|
|
|
if (1 > contractor_config.requested_num_threads)
|
|
|
|
{
|
|
|
|
SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger";
|
2015-10-18 06:34:42 -04:00
|
|
|
return EXIT_FAILURE;
|
2013-10-14 11:03:46 -04:00
|
|
|
}
|
2015-10-18 06:19:06 -04:00
|
|
|
|
|
|
|
const unsigned recommended_num_threads = tbb::task_scheduler_init::default_num_threads();
|
|
|
|
|
|
|
|
if (recommended_num_threads != contractor_config.requested_num_threads)
|
|
|
|
{
|
|
|
|
SimpleLogger().Write(logWARNING) << "The recommended number of threads is "
|
|
|
|
<< recommended_num_threads
|
|
|
|
<< "! This setting may have performance side-effects.";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!boost::filesystem::is_regular_file(contractor_config.osrm_input_path))
|
|
|
|
{
|
|
|
|
SimpleLogger().Write(logWARNING)
|
|
|
|
<< "Input file " << contractor_config.osrm_input_path.string() << " not found!";
|
2015-10-18 06:34:42 -04:00
|
|
|
return EXIT_FAILURE;
|
2015-10-18 06:19:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!boost::filesystem::is_regular_file(contractor_config.profile_path))
|
|
|
|
{
|
|
|
|
SimpleLogger().Write(logWARNING) << "Profile " << contractor_config.profile_path.string()
|
|
|
|
<< " not found!";
|
2015-10-18 06:34:42 -04:00
|
|
|
return EXIT_FAILURE;
|
2015-10-18 06:19:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
SimpleLogger().Write() << "Input file: "
|
|
|
|
<< contractor_config.osrm_input_path.filename().string();
|
|
|
|
SimpleLogger().Write() << "Profile: " << contractor_config.profile_path.filename().string();
|
|
|
|
SimpleLogger().Write() << "Threads: " << contractor_config.requested_num_threads;
|
|
|
|
|
|
|
|
tbb::task_scheduler_init init(contractor_config.requested_num_threads);
|
|
|
|
|
|
|
|
return Prepare(contractor_config).Run();
|
|
|
|
}
|
2015-10-18 06:34:42 -04:00
|
|
|
catch (const std::bad_alloc &e)
|
|
|
|
{
|
|
|
|
SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
|
|
|
SimpleLogger().Write(logWARNING)
|
|
|
|
<< "Please provide more memory or consider using a larger swapfile";
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2015-10-18 06:19:06 -04:00
|
|
|
catch (const std::exception &e)
|
|
|
|
{
|
|
|
|
SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
|
|
|
return EXIT_FAILURE;
|
2013-10-14 11:03:46 -04:00
|
|
|
}
|