Commit 34bac21f authored by Etienne Renault's avatar Etienne Renault

mc: sequential version of Bloemen

* spot/mc/Makefile.am, spot/mc/bloemen.hh,
spot/mc/mc.hh, tests/ltsmin/modelcheck.cc: here.
parent 33f30786
## -*- coding: utf-8 -*-
## Copyright (C) 2015, 2016 Laboratoire de Recherche et Développement de
## Copyright (C) 2015, 2016, 2017 Laboratoire de Recherche et Développement de
## l'Epita (LRDE).
##
## This file is part of Spot, a model checking library.
......@@ -22,7 +22,7 @@ AM_CXXFLAGS = $(WARNING_CXXFLAGS)
mcdir = $(pkgincludedir)/mc
mc_HEADERS = reachability.hh intersect.hh ec.hh unionfind.hh utils.hh\
mc.hh deadlock.hh
mc.hh deadlock.hh bloemen.hh
noinst_LTLIBRARIES = libmc.la
......
This diff is collapsed.
......@@ -24,9 +24,11 @@
#include <thread>
#include <tuple>
#include <vector>
#include <utility>
#include <spot/kripke/kripke.hh>
#include <spot/mc/ec.hh>
#include <spot/mc/deadlock.hh>
#include <spot/mc/bloemen.hh>
#include <spot/misc/common.hh>
#include <spot/misc/timer.hh>
......@@ -152,4 +154,80 @@ namespace spot
return std::make_tuple(has_deadlock, stats, tm);
}
/// \brief Perform the SCC computation algorithm of bloemen.16.ppopp
template<typename kripke_ptr, typename State,
typename Iterator, typename Hash, typename Equal>
static std::pair<std::vector<bloemen_stats>, spot::timer_map>
bloemen(kripke_ptr sys)
{
spot::timer_map tm;
using algo_name = spot::swarmed_bloemen<State, Iterator, Hash, Equal>;
using uf_name = spot::iterable_uf<State, Hash, Equal>;
unsigned nbth = sys->get_threads();
typename uf_name::shared_map map;
tm.start("Initialisation");
std::vector<algo_name*> swarmed(nbth);
std::vector<uf_name*> ufs(nbth);
for (unsigned i = 0; i < nbth; ++i)
{
ufs[i] = new uf_name(map, i);
swarmed[i] = new algo_name(*sys, *ufs[i],i);
}
tm.stop("Initialisation");
std::mutex iomutex;
std::atomic<bool> barrier(true);
std::vector<std::thread> threads(nbth);
for (unsigned i = 0; i < nbth; ++i)
{
threads[i] = std::thread ([&swarmed, &iomutex, i, & barrier]
{
#if defined(unix) || defined(__unix__) || defined(__unix)
{
std::lock_guard<std::mutex> iolock(iomutex);
std::cout << "Thread #" << i
<< ": on CPU " << sched_getcpu() << '\n';
}
#endif
// Wait all threads to be instanciated.
while (barrier)
continue;
swarmed[i]->run();
});
#if defined(unix) || defined(__unix__) || defined(__unix)
// Pins threads to a dedicated core.
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(i, &cpuset);
int rc = pthread_setaffinity_np(threads[i].native_handle(),
sizeof(cpu_set_t), &cpuset);
if (rc != 0)
{
std::lock_guard<std::mutex> iolock(iomutex);
std::cerr << "Error calling pthread_setaffinity_np: " << rc << '\n';
}
#endif
}
tm.start("Run");
barrier.store(false);
for (auto& t : threads)
t.join();
tm.stop("Run");
std::vector<bloemen_stats> stats;
for (unsigned i = 0; i < sys->get_threads(); ++i)
stats.push_back(swarmed[i]->stats());
for (unsigned i = 0; i < nbth; ++i)
delete swarmed[i];
return std::make_pair(stats, tm);
}
}
......@@ -73,6 +73,7 @@ struct mc_options_
unsigned nb_threads = 1;
bool csv = false;
bool has_deadlock = false;
bool bloemen = false;
} mc_options;
......@@ -85,6 +86,9 @@ parse_opt_finput(int key, char* arg, struct argp_state*)
case CSV:
mc_options.csv = true;
break;
case 'b':
mc_options.bloemen = true;
break;
case 'c':
mc_options.compute_counterexample = true;
break;
......@@ -146,6 +150,8 @@ static const argp_option options[] =
{ "model", 'm', "STRING", 0, "use the model stored in file STRING", 0 },
// ------------------------------------------------------------
{ nullptr, 0, nullptr, 0, "Process options:", 2 },
{ "bloemen", 'b', nullptr, 0,
"run the SCC computation of Bloemen et al. (PPOPP'16)", 0 },
{ "counterexample", 'c', nullptr, 0,
"compute an accepting counterexample (if it exists)", 0 },
{ "is-empty", 'e', nullptr, 0,
......@@ -609,6 +615,92 @@ static int checked_main()
}
}
if (mc_options.bloemen && mc_options.model != nullptr)
{
unsigned int hc = std::thread::hardware_concurrency();
if (mc_options.nb_threads > hc)
std::cerr << "Warning: you require " << mc_options.nb_threads
<< " threads, but your computer only support " << hc
<< ". This could slow down parallel algorithms.\n";
tm.start("load kripkecube");
spot::ltsmin_kripkecube_ptr modelcube = nullptr;
try
{
modelcube = spot::ltsmin_model::load(mc_options.model)
.kripkecube({}, deadf, mc_options.compress,
mc_options.nb_threads);
}
catch (std::runtime_error& e)
{
std::cerr << e.what() << '\n';
}
tm.stop("load kripkecube");
int memused = spot::memusage();
tm.start("bloemen");
auto res = spot::bloemen<spot::ltsmin_kripkecube_ptr,
spot::cspins_state,
spot::cspins_iterator,
spot::cspins_state_hash,
spot::cspins_state_equal>(modelcube);
tm.stop("bloemen");
memused = spot::memusage() - memused;
if (!modelcube)
{
exit_code = 2;
goto safe_exit;
}
// Display statistics
unsigned greatest = 0;
for (unsigned i = 0; i < res.first.size(); ++i)
{
if (res.first[i].states < res.first[greatest].states)
greatest = i;
std::cout << "\n---- Thread number : " << i << '\n';
std::cout << res.first[i].states << " unique states visited\n";
std::cout << res.first[i].transitions
<< " transitions explored\n";
std::cout << res.first[i].sccs << " sccs found\n";
std::cout << res.first[i].walltime
<< " milliseconds\n";
if (mc_options.csv)
{
std::cout << "Find following the csv: "
<< "thread_id,walltimems,"
<< "states,transitions,sccs\n";
std::cout << "@th_" << i << ','
<< res.first[i].walltime << ','
<< res.first[i].states << ','
<< res.first[i].transitions << ','
<< res.first[i].sccs
<< std::endl;
}
}
if (mc_options.csv)
{
std::cout << "\nSummary :\n";
std::cout << "Find following the csv: "
<< "model,walltimems,memused,type,"
<< "states,transitions,sccs\n";
std::cout << '#'
<< split_filename(mc_options.model)
<< ','
<< tm.timer("bloemen").walltime() << ','
<< memused << ','
<< res.first[greatest].states << ','
<< res.first[greatest].transitions << ','
<< res.first[greatest].sccs << ','
<< '\n';
}
}
safe_exit:
if (mc_options.use_timer)
tm.print(std::cout);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment