Commit 6f3e5559 authored by Antoine Martin's avatar Antoine Martin Committed by Etienne Renault

mc: implement CNDFS

* spot/mc/Makefile.am: add cndfs.hh
* spot/mc/cndfs.hh, spot/mc/mc.hh: implementation here
* tests/ltsmin/check.test: test CNDFS
* tests/ltsmin/modelcheck.cc: add CNDFS option
parent c4c151e8
......@@ -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 bloemen.hh
mc.hh deadlock.hh bloemen.hh cndfs.hh
noinst_LTLIBRARIES = libmc.la
......
This diff is collapsed.
......@@ -28,6 +28,7 @@
#include <spot/kripke/kripke.hh>
#include <spot/mc/ec.hh>
#include <spot/mc/deadlock.hh>
#include <spot/mc/cndfs.hh>
#include <spot/mc/bloemen.hh>
#include <spot/mc/bloemen_ec.hh>
#include <spot/misc/common.hh>
......@@ -327,4 +328,89 @@ namespace spot
}
return std::make_tuple(is_empty, trace, stats, tm);
}
/// \brief CNDFS
template<typename kripke_ptr, typename State,
typename Iterator, typename Hash, typename Equal>
static std::tuple<bool,
std::string,
std::vector<cndfs_stats>,
spot::timer_map>
cndfs(kripke_ptr sys, twacube_ptr prop, bool compute_ctrx = false)
{
spot::timer_map tm;
using algo_name = spot::swarmed_cndfs<State, Iterator, Hash, Equal>;
unsigned nbth = sys->get_threads();
typename algo_name::shared_map map;
std::atomic<bool> stop(false);
tm.start("Initialisation");
std::vector<algo_name*> swarmed(nbth);
for (unsigned i = 0; i < nbth; ++i)
swarmed[i] = new algo_name(*sys, prop, map, i, stop);
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::string trace;
std::vector<cndfs_stats> stats;
bool is_empty = true;
for (unsigned i = 0; i < sys->get_threads(); ++i)
{
if (!swarmed[i]->is_empty())
{
is_empty = false;
if (compute_ctrx)
trace = swarmed[i]->trace();
}
stats.push_back(swarmed[i]->stats());
}
for (unsigned i = 0; i < nbth; ++i)
delete swarmed[i];
return std::make_tuple(is_empty, trace, stats, tm);
}
}
#!/bin/sh
# -*- coding: utf-8 -*-
# Copyright (C) 2011, 2012, 2014, 2015, 2016, 2017, 2019 Laboratoire de Recherche
# et Développement de l'Epita (LRDE).
# Copyright (C) 2011, 2012, 2014, 2015, 2016, 2017, 2019 Laboratoire
# de Recherche et Développement de l'Epita (LRDE).
#
# This file is part of Spot, a model checking library.
#
......@@ -93,3 +93,7 @@ test `grep "#" stdout | awk -F',' '{print $7}'` -eq 29115
run 0 ../modelcheck --model beem-peterson.4.dve2C \
--formula '!GF(P_0.CS|P_1.CS|P_2.CS|P_3.CS)' --csv --bloemen-ec -p 3 >stdout
# Test CNDFS
run 0 ../modelcheck --model beem-peterson.4.dve2C \
--formula '!GF(P_0.CS|P_1.CS|P_2.CS|P_3.CS)' --csv --cndfs -p 3 >stdout
......@@ -31,6 +31,7 @@
#include <spot/twaalgos/translate.hh>
#include <spot/twaalgos/emptiness.hh>
#include <spot/twaalgos/postproc.hh>
#include <spot/twaalgos/degen.hh>
#include <spot/twaalgos/are_isomorphic.hh>
#include <spot/twa/twaproduct.hh>
#include <spot/misc/timer.hh>
......@@ -75,6 +76,7 @@ struct mc_options_
bool has_deadlock = false;
bool bloemen = false;
bool bloemen_ec = false;
bool cndfs = false;
} mc_options;
......@@ -96,6 +98,9 @@ parse_opt_finput(int key, char* arg, struct argp_state*)
case 'c':
mc_options.compute_counterexample = true;
break;
case 'C':
mc_options.cndfs = true;
break;
case 'd':
if (strcmp(arg, "model") == 0)
mc_options.dot_output |= DOT_MODEL;
......@@ -158,6 +163,8 @@ static const argp_option options[] =
"run the SCC computation of Bloemen et al. (PPOPP'16) with EC", 0},
{ "bloemen", 'b', nullptr, 0,
"run the SCC computation of Bloemen et al. (PPOPP'16)", 0 },
{ "cndfs", 'C', nullptr, 0,
"run CNDFS", 0 },
{ "counterexample", 'c', nullptr, 0,
"compute an accepting counterexample (if it exists)", 0 },
{ "is-empty", 'e', nullptr, 0,
......@@ -304,7 +311,8 @@ static int checked_main()
if (mc_options.nb_threads == 1 &&
mc_options.formula != nullptr &&
mc_options.model != nullptr &&
!mc_options.bloemen_ec)
!mc_options.bloemen_ec &&
!mc_options.cndfs)
{
product = spot::otf_product(model, prop);
......@@ -417,7 +425,8 @@ static int checked_main()
if (mc_options.nb_threads != 1 &&
mc_options.formula != nullptr &&
mc_options.model != nullptr &&
!mc_options.bloemen_ec)
!mc_options.bloemen_ec &&
!mc_options.cndfs)
{
unsigned int hc = std::thread::hardware_concurrency();
if (mc_options.nb_threads > hc)
......@@ -623,6 +632,117 @@ static int checked_main()
}
}
if (mc_options.cndfs &&
mc_options.model != nullptr && mc_options.formula != 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";
// Only support Single Acceptance Conditions
tm.start("degeneralize");
auto prop_degen = spot::degeneralize_tba(prop);
tm.stop("degeneralize");
tm.start("twa to twacube");
auto propcube = spot::twa_to_twacube(prop_degen);
tm.stop("twa to twacube");
tm.start("load kripkecube");
spot::ltsmin_kripkecube_ptr modelcube = nullptr;
try
{
modelcube = spot::ltsmin_model::load(mc_options.model)
.kripkecube(propcube->get_ap(), deadf, mc_options.compress,
mc_options.nb_threads);
}
catch (const std::runtime_error& e)
{
std::cerr << e.what() << '\n';
}
tm.stop("load kripkecube");
int memused = spot::memusage();
tm.start("cndfs");
auto res = spot::cndfs<spot::ltsmin_kripkecube_ptr,
spot::cspins_state,
spot::cspins_iterator,
spot::cspins_state_hash,
spot::cspins_state_equal>
(modelcube, propcube, mc_options.compute_counterexample);
tm.stop("cndfs");
memused = spot::memusage() - memused;
if (!modelcube)
{
exit_code = 2;
goto safe_exit;
}
// Display statistics
unsigned smallest = 0;
for (unsigned i = 0; i < std::get<2>(res).size(); ++i)
{
if (std::get<2>(res)[i].states < std::get<2>(res)[smallest].states)
smallest = i;
std::cout << "\n---- Thread number : " << i << '\n';
std::cout << std::get<2>(res)[i].states << " unique states visited\n";
std::cout << std::get<2>(res)[i].transitions
<< " transitions explored\n";
std::cout << std::get<2>(res)[i].instack_dfs
<< " items max in DFS search stack\n";
std::cout << std::get<2>(res)[i].walltime
<< " milliseconds\n";
if (mc_options.csv)
{
std::cout << "Find following the csv: "
<< "thread_id,walltimems,type,"
<< "states,transitions\n";
std::cout << "@th_" << i << ','
<< std::get<2>(res)[i].walltime << ','
<< (std::get<2>(res)[i].is_empty ?
"EMPTY," : "NONEMPTY,")
<< std::get<2>(res)[i].states << ','
<< std::get<2>(res)[i].transitions
<< std::endl;
}
}
if (mc_options.csv)
{
std::cout << "\nSummary :\n";
if (std::get<0>(res))
std::cout << "no accepting run found\n";
else if (!mc_options.compute_counterexample)
{
std::cout << "an accepting run exists "
<< "(use -c to print it)" << std::endl;
exit_code = 1;
}
else
std::cout << "an accepting run exists\n"
<< std::get<1>(res) << '\n';
std::cout << "Find following the csv: "
<< "model,walltimems,memused,type,"
<< "states,transitions\n";
std::cout << '#'
<< split_filename(mc_options.model)
<< ','
<< tm.timer("cndfs").walltime() << ','
<< memused << ','
<< (std::get<0>(res) ? "EMPTY," : "NONEMPTY,")
<< std::get<2>(res)[smallest].states << ','
<< std::get<2>(res)[smallest].transitions
<< '\n';
}
}
if (mc_options.bloemen && mc_options.model != nullptr)
{
unsigned int hc = std::thread::hardware_concurrency();
......
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